Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(291)

Unified Diff: src/ltp-protocol/model/ltp-session-state-record.cc

Issue 105340046: Ltp Protocol mid-term
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/ltp-protocol/model/ltp-session-state-record.cc
===================================================================
new file mode 100755
--- /dev/null
+++ b/src/ltp-protocol/model/ltp-session-state-record.cc
@@ -0,0 +1,503 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014 Universitat Autònoma de Barcelona
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Rubén Martínez <rmartinez@deic.uab.cat>
+ */
+
+#include "ltp-session-state-record.h"
+#include "ns3/log.h"
+
+
+
+NS_LOG_COMPONENT_DEFINE ("SessionStateRecord");
+
+namespace ns3 {
+namespace ltp {
+
+LtpEngineConfigParameters::LtpEngineConfigParameters ()
+ : m_localEngineId (0),
+ m_cpRtxLimit (0),
+ m_rpRtxLimit (0),
+ m_rxProblemLimit (0),
+ m_cxRtxLimit (0),
+ m_rtxCycleLimit (0)
+{
+ NS_LOG_FUNCTION (this);
+}
+
+LtpEngineConfigParameters::LtpEngineConfigParameters
+ (uint64_t engineId,uint32_t cpLimit,uint32_t rpLimit,uint32_t problemLimit,
+ uint32_t cancelLimit,uint32_t cycleLimit)
+ : m_localEngineId (engineId),
+ m_cpRtxLimit (cpLimit),
+ m_rpRtxLimit (rpLimit),
+ m_rxProblemLimit (problemLimit),
+ m_cxRtxLimit (cancelLimit),
+ m_rtxCycleLimit (cycleLimit)
+{
+ NS_LOG_FUNCTION (this);
+}
+
+LtpEngineConfigParameters::~LtpEngineConfigParameters ()
+{
+ NS_LOG_FUNCTION (this);
+}
+
+uint64_t
+LtpEngineConfigParameters::GetLocalEngineId () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_localEngineId;
+}
+
+uint32_t LtpEngineConfigParameters::GetCheckPointRetransLimit () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_cpRtxLimit;
+}
+uint32_t LtpEngineConfigParameters::GetReportRetransLimit () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_rpRtxLimit;
+}
+
+uint32_t LtpEngineConfigParameters::GetReceptionProblemLimit () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_rxProblemLimit;
+}
+
+uint32_t LtpEngineConfigParameters::GetCancellationRetransLimit () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_cxRtxLimit;
+}
+
+uint32_t LtpEngineConfigParameters::GetRetransCycleLimit () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_rtxCycleLimit;
+}
+
+
+SessionStateRecord::SessionStateRecord ()
+ : m_config (),
+ m_sessionId (),
+ m_txQueue (),
+ m_peerLtpEngine (),
+ m_CpTimer (Timer::CANCEL_ON_DESTROY),
+ m_RsTimer (Timer::CANCEL_ON_DESTROY),
+ m_CxTimer (Timer::CANCEL_ON_DESTROY),
+ m_rcvSegments (),
+ m_redpartSucces (false),
+ m_redpartAckSuccess (false),
+ m_blockSuccess (false),
+ m_rTxCnt (0),
+ m_canceled (NOT_CANCELED),
+ m_canceledReason (RESERVED),
+ m_suspended (false)
+{
+ NS_LOG_FUNCTION (this);
+}
+
+
+SessionStateRecord::SessionStateRecord (LtpEngineConfigParameters config,
+ uint64_t localClientServiceId,
+ uint64_t peerLtpEngineId)
+ : m_config (config),
+ m_sessionId (),
+ m_txQueue (),
+ m_peerLtpEngine (peerLtpEngineId),
+ m_localClientService (localClientServiceId),
+ m_CpTimer (Timer::CANCEL_ON_DESTROY),
+ m_RsTimer (Timer::CANCEL_ON_DESTROY),
+ m_CxTimer (Timer::CANCEL_ON_DESTROY),
+ m_rcvSegments (),
+ m_redpartSucces (false),
+ m_redpartAckSuccess (false),
+ m_blockSuccess (false),
+ m_rTxCnt (0),
+ m_canceled (NOT_CANCELED),
+ m_canceledReason (RESERVED),
+ m_suspended (false)
+
+{
+ NS_LOG_FUNCTION (this);
+}
+
+
+SenderSessionStateRecord::SenderSessionStateRecord ()
+ : SessionStateRecord (),
+ m_destinationClientServiceId (0)
+{
+ NS_LOG_FUNCTION (this);
+}
+
+SenderSessionStateRecord::SenderSessionStateRecord ( LtpEngineConfigParameters config,
+ uint64_t localClientServiceId,
+ uint64_t destinationClientService,
+ uint64_t destinationLtpEngine,
+ Ptr<UniformRandomVariable> number)
+ : SessionStateRecord (config,localClientServiceId,destinationLtpEngine),
+ m_destinationClientServiceId (destinationClientService)
+{
+ NS_LOG_FUNCTION (this);
+ m_sessionId = SessionId (m_config.GetLocalEngineId (),
+ number->GetInteger (SessionId::MIN_SESSION_NUMBER,SessionId::MAX_SESSION_NUMBER)) ;
+
+ m_firstCpSerialNumber = number->GetInteger (MIN_INITIAL_SERIAL_NUMBER,MAX_INITIAL_SERIAL_NUMBER);
+ m_currentCpSerialNumber = m_firstCpSerialNumber;
+ m_firstRpSerialNumber = 0;
+ m_currentRpSerialNumber = 0;
+}
+ReceiverSessionStateRecord::ReceiverSessionStateRecord ()
+ : SessionStateRecord (),
+ m_rcvCheckpoints ()
+{
+ NS_LOG_FUNCTION (this);
+}
+
+ReceiverSessionStateRecord::ReceiverSessionStateRecord (LtpEngineConfigParameters config, uint64_t localClientServiceId, SessionId id, Ptr<UniformRandomVariable> number )
+ : SessionStateRecord (config,localClientServiceId,id.GetSessionOriginator ()),
+ m_rcvCheckpoints ()
+{
+ NS_LOG_FUNCTION (this);
+
+ m_sessionId = id;
+
+ m_firstCpSerialNumber = 0;
+ m_currentCpSerialNumber = 0;
+ m_firstRpSerialNumber = number->GetInteger (MIN_INITIAL_SERIAL_NUMBER,MAX_INITIAL_SERIAL_NUMBER);
+ m_currentRpSerialNumber = m_firstRpSerialNumber;
+}
+
+
+SessionStateRecord::~SessionStateRecord ()
+{
+ NS_LOG_FUNCTION (this);
+}
+ReceiverSessionStateRecord::~ReceiverSessionStateRecord ()
+{
+ NS_LOG_FUNCTION (this);
+}
+SenderSessionStateRecord::~SenderSessionStateRecord ()
+{
+ NS_LOG_FUNCTION (this);
+}
+
+TypeId
+SessionStateRecord::GetTypeId ()
+{
+ static TypeId tid = TypeId ("ns3::SessionStateRecord")
+ .SetParent<Object> ()
+ .AddConstructor<SessionStateRecord> ()
+ ;
+ return tid;
+}
+
+TypeId
+SessionStateRecord::GetInstanceTypeId (void) const
+{
+ NS_LOG_FUNCTION (this);
+ return GetTypeId ();
+}
+
+TypeId
+SenderSessionStateRecord::GetTypeId ()
+{
+ static TypeId tid = TypeId ("ns3::SenderSessionStateRecord")
+ .SetParent<SessionStateRecord> ()
+ .AddConstructor<SenderSessionStateRecord> ()
+ ;
+ return tid;
+}
+
+TypeId
+SenderSessionStateRecord::GetInstanceTypeId (void) const
+{
+ NS_LOG_FUNCTION (this);
+ return GetTypeId ();
+}
+
+TypeId
+ReceiverSessionStateRecord::GetTypeId ()
+{
+ static TypeId tid = TypeId ("ns3::ReceiverSessionStateRecord")
+ .SetParent<SessionStateRecord> ()
+ .AddConstructor<ReceiverSessionStateRecord> ()
+ ;
+ return tid;
+}
+
+TypeId
+ReceiverSessionStateRecord::GetInstanceTypeId (void) const
+{
+ NS_LOG_FUNCTION (this);
+ return GetTypeId ();
+}
+
+
+SessionId
+SessionStateRecord::GetSessionId () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_sessionId;
+}
+
+void
+SessionStateRecord::SuspendTimer (TimerCode type)
+{
+ NS_LOG_FUNCTION (this << type);
+ switch (type)
+ {
+ case CHECKPOINT:
+ m_CpTimer.Suspend ();
+ break;
+ case REPORT:
+ m_RsTimer.Suspend ();
+ break;
+ case CANCEL:
+ m_CxTimer.Suspend ();
+ break;
+ default:
+ break;
+ }
+}
+void
+SessionStateRecord::ResumeTimer (TimerCode type)
+{
+ NS_LOG_FUNCTION (this << type);
+ switch (type)
+ {
+ case CHECKPOINT:
+ m_CpTimer.Resume ();
+ break;
+ case REPORT:
+ m_RsTimer.Resume ();
+ break;
+ case CANCEL:
+ m_CxTimer.Resume ();
+ break;
+ default:
+ break;
+ }
+}
+
+uint64_t
+SessionStateRecord::GetCpStartSerialNumber () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_firstCpSerialNumber;
+}
+
+uint64_t
+SessionStateRecord::GetRpStartSerialNumber () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_firstRpSerialNumber;
+}
+
+uint64_t
+SessionStateRecord::GetCpCurrentSerialNumber () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_currentCpSerialNumber;
+}
+
+uint64_t
+SessionStateRecord::GetRpCurrentSerialNumber () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_currentRpSerialNumber;
+}
+
+
+uint64_t
+SessionStateRecord::GetPeerLtpEngineId () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_peerLtpEngine;
+}
+
+uint64_t
+SessionStateRecord::GetLocalClientServiceId () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_localClientService;
+}
+
+uint64_t
+SessionStateRecord::IncrementCpCurrentSerialNumber ()
+{
+ NS_LOG_FUNCTION (this);
+ return m_currentCpSerialNumber++;
+}
+
+uint64_t
+SessionStateRecord::IncrementRpCurrentSerialNumber ()
+{
+ NS_LOG_FUNCTION (this);
+ return m_currentRpSerialNumber++;
+}
+
+bool
+SessionStateRecord::Enqueue (Ptr<Packet> p)
+{
+ NS_LOG_FUNCTION (this << p);
+ return m_txQueue.Enqueue (p);
+}
+
+Ptr<Packet>
+SessionStateRecord::Dequeue (void)
+{
+ NS_LOG_FUNCTION (this);
+ return m_txQueue.Dequeue ();
+}
+uint32_t
+SessionStateRecord::GetNPackets () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_txQueue.GetNPackets ();
+}
+uint64_t
+SenderSessionStateRecord::GetDestination () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_destinationClientServiceId;
+}
+
+bool
+SessionStateRecord::IsRedPartFinished () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_redpartSucces;
+}
+
+void
+SessionStateRecord::SetRedPartFinished ()
+{
+ NS_LOG_FUNCTION (this);
+ m_redpartSucces = true;
+}
+
+bool
+SessionStateRecord::IsRedPartAck () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_redpartAckSuccess;
+}
+
+void
+SessionStateRecord::SetRedPartAck ()
+{
+ NS_LOG_FUNCTION (this);
+ m_redpartAckSuccess = true;
+}
+
+bool
+SessionStateRecord::IsBlockFinished () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_blockSuccess;
+}
+
+void
+SessionStateRecord::SetBlockFinished ()
+{
+ NS_LOG_FUNCTION (this);
+ m_blockSuccess = true;
+}
+
+uint64_t
+SessionStateRecord::GetRTxNumber () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_rTxCnt;
+}
+
+void
+SessionStateRecord::IncrementRtxNumber ()
+{
+ NS_LOG_FUNCTION (this);
+ m_rTxCnt++;
+}
+
+bool
+SessionStateRecord::IsCanceled () const
+{
+ NS_LOG_FUNCTION (this);
+ return ((m_canceled == NOT_CANCELED) ? false : true);
+}
+
+void
+SessionStateRecord::Cancel (CancellationState s, CxReasonCode r)
+{
+ NS_LOG_FUNCTION (this << r << s);
+ m_canceled = s;
+ m_canceledReason = r;
+}
+
+CxReasonCode
+SessionStateRecord::GetCancellationReason () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_canceledReason;
+}
+
+bool
+SessionStateRecord::IsSuspended () const
+{
+ NS_LOG_FUNCTION (this);
+ return m_suspended;
+}
+void
+SessionStateRecord::Suspend ()
+{
+ NS_LOG_FUNCTION (this);
+ m_suspended = true;
+}
+
+void
+SessionStateRecord::Resume ()
+{
+ NS_LOG_FUNCTION (this);
+ m_suspended = false;
+}
+
+bool
+SessionStateRecord::InsertClaim (LtpContentHeader::ReceptionClaim claim)
+{
+ NS_LOG_FUNCTION (this << claim.offset << " " << claim.length);
+
+ std::pair<uint64_t,uint64_t> key;
+ std::pair<std::pair<uint64_t,uint64_t>,LtpContentHeader::ReceptionClaim> ack;
+
+ key = std::make_pair (m_currentRpSerialNumber,claim.offset);
+ ack = std::make_pair (key,claim);
+ return m_rcvSegments.insert (ack).second;
+}
+
+bool
+ReceiverSessionStateRecord::InsertCheckpoint ()
+{
+ NS_LOG_FUNCTION (this);
+ return m_rcvCheckpoints.insert (m_currentCpSerialNumber).second;
+
+}
+
+} // namespace ltp
+} // namespace ns3
« no previous file with comments | « src/ltp-protocol/model/ltp-session-state-record.h ('k') | src/ltp-protocol/model/ltp-session-state-record-impl.h » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b