From b08ce80459528e9ae2cfaecc9f66e95e8cf2f651 Mon Sep 17 00:00:00 2001 From: Natale Patriciello Date: Mon, 18 Jun 2018 22:38:29 +0200 Subject: [PATCH] tcp: Added callbacks for timings in TcpTxBuffer When a SACK is received or when an item is discarded (the segment was fully acked) then fire a callback with the modified item. This will help when we will have some mechanism that will look for the timing of these actions. --- src/internet/model/tcp-tx-buffer.cc | 21 ++++++++++++++++++--- src/internet/model/tcp-tx-buffer.h | 11 +++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/internet/model/tcp-tx-buffer.cc b/src/internet/model/tcp-tx-buffer.cc index 8ea00a543..ba7d93fe5 100644 --- a/src/internet/model/tcp-tx-buffer.cc +++ b/src/internet/model/tcp-tx-buffer.cc @@ -34,6 +34,7 @@ namespace ns3 { NS_LOG_COMPONENT_DEFINE ("TcpTxBuffer"); NS_OBJECT_ENSURE_REGISTERED (TcpTxBuffer); +Callback TcpTxBuffer::m_nullCb = MakeNullCallback (); TypeId TcpTxBuffer::GetTypeId (void) { @@ -587,7 +588,7 @@ TcpTxBuffer::MergeItems (TcpTxItem *t1, TcpTxItem *t2) const // If one is retrans and the other is not, cancel the retransmitted flag. // We are merging this segment for the retransmit, so the count will - // be updated in GetTransmittedSegment. + // be updated in MarkTransmittedSegment. if (! AreEquals (t1->m_retrans, t2->m_retrans)) { if (t1->m_retrans) @@ -637,7 +638,8 @@ TcpTxBuffer::RemoveFromCounts (TcpTxItem *item, uint32_t size) } } void -TcpTxBuffer::DiscardUpTo (const SequenceNumber32& seq) +TcpTxBuffer::DiscardUpTo (const SequenceNumber32& seq, + const Callback &beforeDelCb) { NS_LOG_FUNCTION (this << seq); @@ -685,6 +687,13 @@ TcpTxBuffer::DiscardUpTo (const SequenceNumber32& seq) NS_LOG_INFO ("Removed " << *item << " lost: " << m_lostOut << " retrans: " << m_retrans << " sacked: " << m_sackedOut << ". Remaining data " << m_size); + + if (!beforeDelCb.IsNull ()) + { + // Inform Rate algorithms only when a full packet is ACKed + beforeDelCb (item); + } + delete item; } else if (offset > 0) @@ -747,7 +756,8 @@ TcpTxBuffer::DiscardUpTo (const SequenceNumber32& seq) } uint32_t -TcpTxBuffer::Update (const TcpOptionSack::SackList &list) +TcpTxBuffer::Update (const TcpOptionSack::SackList &list, + const Callback &sackedCb) { NS_LOG_FUNCTION (this); NS_LOG_INFO ("Updating scoreboard, got " << list.size () << " blocks to analyze"); @@ -806,6 +816,11 @@ TcpTxBuffer::Update (const TcpOptionSack::SackList &list) ", checking sentList for block " << *(*item_it) << ", found in the sackboard, sacking, current highSack: " << m_highestSack.second); + + if (!sackedCb.IsNull ()) + { + sackedCb (*item_it); + } } } else if (beginOfCurrentPacket + pktSize > (*option_it).second) diff --git a/src/internet/model/tcp-tx-buffer.h b/src/internet/model/tcp-tx-buffer.h index fd9e96e7e..7474d2b57 100644 --- a/src/internet/model/tcp-tx-buffer.h +++ b/src/internet/model/tcp-tx-buffer.h @@ -261,15 +261,21 @@ public: * * \param seq The first sequence number to maintain after discarding all the * previous sequences. + * \param beforeDelCb Callback invoked, if it is not null, before the deletion + * of an Item (because it was, probably, ACKed) */ - void DiscardUpTo (const SequenceNumber32& seq); + void DiscardUpTo (const SequenceNumber32& seq, + const Callback &beforeDelCb = m_nullCb); /** * \brief Update the scoreboard * \param list list of SACKed blocks + * \param sackedCb Callback invoked, if it is not null, when a segment has been + * SACKed by the receiver. * \returns the number of bytes newly sacked by the list of blocks */ - uint32_t Update (const TcpOptionSack::SackList &list); + uint32_t Update (const TcpOptionSack::SackList &list, + const Callback &sackedCb = m_nullCb); /** * \brief Check if a segment is lost @@ -585,6 +591,7 @@ private: uint32_t m_segmentSize {0}; //!< Segment size from TcpSocketBase bool m_renoSack {false}; //!< Indicates if AddRenoSack was called + static Callback m_nullCb; //!< Null callback for an item }; /**