A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::TcpTxBuffer Class Reference

Tcp sender buffer. More...

#include "tcp-tx-buffer.h"

+ Inheritance diagram for ns3::TcpTxBuffer:
+ Collaboration diagram for ns3::TcpTxBuffer:

Public Member Functions

 TcpTxBuffer (uint32_t n=0)
 Constructor.
 
 ~TcpTxBuffer () override
 
bool Add (Ptr< Packet > p)
 Append a data packet to the end of the buffer.
 
void AddRenoSack ()
 Emulate SACKs for SACKless connection: account for a new dupack.
 
uint32_t Available () const
 Returns the available capacity of this buffer.
 
uint32_t BytesInFlight () const
 Return total bytes in flight.
 
TcpTxItemCopyFromSequence (uint32_t numBytes, const SequenceNumber32 &seq)
 Copy data from the range [seq, seq+numBytes) into a packet.
 
void DeleteRetransmittedFlagFromHead ()
 DeleteRetransmittedFlagFromHead.
 
void DiscardUpTo (const SequenceNumber32 &seq, const Callback< void, TcpTxItem * > &beforeDelCb=m_nullCb)
 Discard data up to but not including this sequence number.
 
uint32_t GetLost () const
 Get the number of segments that we believe are lost in the network.
 
uint32_t GetRetransmitsCount () const
 Return the number of segments in the sent list that have been transmitted more than once, without acknowledgment.
 
uint32_t GetSacked () const
 Get the number of segments that have been explicitly sacked by the receiver.
 
SequenceNumber32 HeadSequence () const
 Get the sequence number of the buffer head.
 
bool IsHeadRetransmitted () const
 Check if the head is retransmitted.
 
bool IsLost (const SequenceNumber32 &seq) const
 Check if a segment is lost.
 
bool IsRetransmittedDataAcked (const SequenceNumber32 &ack) const
 Checks whether the ack corresponds to retransmitted data.
 
bool IsSackEnabled () const
 check whether SACK is used on the corresponding TCP socket
 
void MarkHeadAsLost ()
 Mark the head of the sent list as lost.
 
uint32_t MaxBufferSize () const
 Get the maximum buffer size.
 
bool NextSeg (SequenceNumber32 *seq, SequenceNumber32 *seqHigh, bool isRecovery) const
 Get the next sequence number to transmit, according to RFC 6675.
 
void ResetLastSegmentSent ()
 Take the last segment sent and put it back into the un-sent list (at the beginning)
 
void ResetRenoSack ()
 Reset the SACKs.
 
void ResetSentList ()
 Reset the sent list.
 
void SetDupAckThresh (uint32_t dupAckThresh)
 Set the DupAckThresh.
 
void SetHeadSequence (const SequenceNumber32 &seq)
 Set the head sequence of the buffer.
 
void SetMaxBufferSize (uint32_t n)
 Set the maximum buffer size.
 
void SetRWndCallback (Callback< uint32_t > rWndCallback)
 Set callback to obtain receiver window value.
 
void SetSackEnabled (bool enabled)
 tell tx-buffer whether SACK is used on this TCP socket
 
void SetSegmentSize (uint32_t segmentSize)
 Set the segment size.
 
void SetSentListLost (bool resetSack=false)
 Set the entire sent list as lost (typically after an RTO)
 
uint32_t Size () const
 Returns total number of bytes in this buffer.
 
uint32_t SizeFromSequence (const SequenceNumber32 &seq) const
 Returns the number of bytes from the buffer in the range [seq, tailSequence)
 
SequenceNumber32 TailSequence () const
 Get the sequence number of the buffer tail (plus one)
 
uint32_t Update (const TcpOptionSack::SackList &list, const Callback< void, TcpTxItem * > &sackedCb=m_nullCb)
 Update the scoreboard.
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor.
 
 ~Object () override
 Destructor.
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together.
 
void Dispose ()
 Dispose of this Object.
 
AggregateIterator GetAggregateIterator () const
 Get an iterator to the Objects aggregated to this one.
 
TypeId GetInstanceTypeId () const override
 Get the most derived TypeId for this Object.
 
template<typename T >
Ptr< T > GetObject () const
 Get a pointer to the requested aggregated Object.
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object.
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId.
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object.
 
void Initialize ()
 Invoke DoInitialize on all Objects aggregated to this one.
 
bool IsInitialized () const
 Check if the object has been initialized.
 
void UnidirectionalAggregateObject (Ptr< Object > other)
 Aggregate an Object to another Object.
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor.
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor.
 
uint32_t GetReferenceCount () const
 Get the reference count of the object.
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator.
 
void Ref () const
 Increment the reference count.
 
void Unref () const
 Decrement the reference count.
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor.
 
void GetAttribute (std::string name, AttributeValue &value, bool permissive=false) const
 Get the value of an attribute, raising fatal errors if unsuccessful.
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising errors.
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful.
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors.
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context.
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context.
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context.
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context.
 

Static Public Member Functions

static TypeId GetTypeId ()
 Get the type ID.
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId ()
 Register this type.
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId ()
 Get the type ID.
 

Private Types

typedef std::list< TcpTxItem * > PacketList
 container for data stored in the buffer
 

Private Member Functions

uint32_t BytesInFlightRFC () const
 Calculate the number of bytes in flight per RFC 6675.
 
void ConsistencyCheck () const
 Check if the values of sacked, lost, retrans, are in sync with the sent list.
 
std::pair< TcpTxBuffer::PacketList::const_iterator, SequenceNumber32FindHighestSacked () const
 Find the highest SACK byte.
 
TcpTxItemGetNewSegment (uint32_t numBytes)
 Get a block of data not transmitted yet and move it into SentList.
 
TcpTxItemGetPacketFromList (PacketList &list, const SequenceNumber32 &startingSeq, uint32_t numBytes, const SequenceNumber32 &requestedSeq, bool *listEdited=nullptr) const
 Get a block (which is returned as Packet) from a list.
 
TcpTxItemGetTransmittedSegment (uint32_t numBytes, const SequenceNumber32 &seq)
 Get a block of data previously transmitted.
 
bool IsLostRFC (const SequenceNumber32 &seq, const PacketList::const_iterator &segment) const
 Decide if a segment is lost based on RFC 6675 algorithm.
 
void MergeItems (TcpTxItem *t1, TcpTxItem *t2) const
 Merge two TcpTxItem.
 
void RemoveFromCounts (TcpTxItem *item, uint32_t size)
 Remove the size specified from the lostOut, retrans, sacked count.
 
void SplitItems (TcpTxItem *t1, TcpTxItem *t2, uint32_t size) const
 Split one TcpTxItem.
 
void UpdateLostCount ()
 Update the lost count.
 

Private Attributes

PacketList m_appList
 Buffer for application data.
 
uint32_t m_dupAckThresh {0}
 Duplicate Ack threshold from TcpSocketBase.
 
TracedValue< SequenceNumber32m_firstByteSeq
 Sequence number of the first byte in data (SND.UNA)
 
std::pair< PacketList::const_iterator, SequenceNumber32m_highestSack
 Highest SACK byte.
 
uint32_t m_lostOut {0}
 Number of lost bytes.
 
uint32_t m_maxBuffer
 Max number of data bytes in buffer (SND.WND)
 
bool m_renoSack {false}
 Indicates if AddRenoSack was called.
 
uint32_t m_retrans {0}
 Number of retransmitted bytes.
 
Callback< uint32_tm_rWndCallback
 Callback to obtain RCV.WND value.
 
uint32_t m_sackedOut {0}
 Number of sacked bytes.
 
bool m_sackEnabled {true}
 Indicates if SACK is enabled on this connection.
 
bool m_sackSeen {false}
 Indicates if a SACK was received.
 
uint32_t m_segmentSize {0}
 Segment size from TcpSocketBase.
 
PacketList m_sentList
 Buffer for sent (but not acked) data.
 
uint32_t m_sentSize
 Size of sent (and not discarded) segments.
 
uint32_t m_size
 Size of all data in this buffer.
 

Static Private Attributes

static Callback< void, TcpTxItem * > m_nullCb = MakeNullCallback<void, TcpTxItem*>()
 Null callback for an item.
 

Friends

std::ostream & operator<< (std::ostream &os, const TcpTxBuffer &tcpTxBuf)
 Output operator.
 

Additional Inherited Members

- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object.
 
virtual void DoDispose ()
 Destructor implementation.
 
virtual void DoInitialize ()
 Initialize() implementation.
 
virtual void NotifyNewAggregate ()
 Notify all Objects aggregated to this one of a new Object being aggregated.
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes.
 
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed.
 

Detailed Description

Tcp sender buffer.

The class keeps track of all data that the application wishes to transmit to the other end. When the data is acknowledged, it is removed from the buffer. The buffer has a maximum size, and data is not saved if the amount exceeds the limit. Packets can be added to the class through the method Add(). An important thing to remember is that all the data managed is strictly sequential. It can be divided into blocks, but all the data follow a strict ordering. That order is managed through SequenceNumber.

In other words, this buffer contains numbered bytes (e.g., 1,2,3), and the class is allowed to return only ordered (using "<" as operator) subsets (e.g. 1,2 or 2,3 or 1,2,3).

The data structure underlying this is composed by two distinct packet lists. The first (SentList) is initially empty, and it contains the packets returned by the method CopyFromSequence. The second (AppList) is initially empty, and it contains the packets coming from the applications, but that are not transmitted yet as segments. To discover how the chunks are managed and retrieved from these lists, check CopyFromSequence documentation.

The head of the data is represented by m_firstByteSeq, and it is returned by HeadSequence(). The last byte is returned by TailSequence(). In this class, we also store the size (in bytes) of the packets inside the SentList in the variable m_sentSize.

SACK management

The SACK information is usually saved in a data structure referred as scoreboard. In this implementation, the scoreboard is developed on top of the existing classes. In particular, instead of keeping raw pointers to packets in TcpTxBuffer we added the capability to store some flags associated with every segment sent. This is done through the use of the class TcpTxItem: instead of storing a list of packets, we store a list of TcpTxItem. Each item has different flags (check the corresponding documentation) and maintaining the scoreboard is a matter of travelling the list and set the SACK flag on the corresponding segment sent.

Item properties

An item (that represent a segment in flight) is not considered in flight anymore when it is marked lost or sacked. A sacked item represents an item which is received by the other end, but it is still impossible to delete from the list because other pieces are missing at the other end. A lost item never reached the other end, and retransmission is probably needed. Other properties are retransmitted, that indicates if an item was retransmitted, and the sequence number of the first byte of the packet. When a segment is sent for the first time, only the sequence number is set, and all the remaining properties are set to false. If an item is explicitly sacked by the receiver, we mark it as such. Each time we receive updated sack information from the other end, we perform a check to evaluate the segments that can be lost (

See also
UpdateLostCount), and we set the flags accordingly.

Management of bytes in flight

Since this class manages all the output segments and the scoreboard, we can do calculations about the number of bytes in flights. Earlier versions of this class used algorithms copied from RFC 6675. They were inefficient because they required a complete walk into the list of sent segments each time a simple question, such as "Is this sequence lost?" or "How many bytes are in flight?". Therefore, the class has been updated keeping in consideration the RFCs (including RFC 4898) and the Linux operating system. As a reference, we kept the older methods for calculating the bytes in flight and if a segment is lost, renaming them as "RFC" version of the methods. To have a look how the calculations are made, please see BytesInFlight method.

Lost segments

After the sender receives a new SACK block, it updates the amount of segment that it considers as lost, following the specifications made in RFC 6675 (for more detail please see the method UpdateLostCount). In case of SACKless connection, the TcpSocketImplementation should provide hints through the MarkHeadAsLost and AddRenoSack methods.

See also
BytesInFlight
Size
SizeFromSequence
CopyFromSequence

Config Paths

ns3::TcpTxBuffer is accessible through the following paths with Config::Set and Config::Connect:

  • "/NodeList/[i]/$ns3::TcpL4Protocol/SocketList/[i]/TxBuffer"

No Attributes are defined for this type.

TraceSources

  • UnackSequence: First unacknowledged sequence number (SND.UNA)
    • Callback signature: ns3::SequenceNumber32TracedValueCallback
    • Support level: SUPPORTED

Group: Internet

Size of this type is 200 bytes (on a 64-bit architecture).

Definition at line 112 of file tcp-tx-buffer.h.

Member Typedef Documentation

◆ PacketList

typedef std::list<TcpTxItem*> ns3::TcpTxBuffer::PacketList
private

container for data stored in the buffer

Definition at line 403 of file tcp-tx-buffer.h.

Constructor & Destructor Documentation

◆ TcpTxBuffer()

ns3::TcpTxBuffer::TcpTxBuffer ( uint32_t n = 0)

Constructor.

Parameters
ninitial Sequence number to be transmitted

Definition at line 49 of file tcp-tx-buffer.cc.

References m_rWndCallback, and ns3::MakeNullCallback().

+ Here is the call graph for this function:

◆ ~TcpTxBuffer()

ns3::TcpTxBuffer::~TcpTxBuffer ( )
override

Definition at line 58 of file tcp-tx-buffer.cc.

References ns3::Packet::GetSize(), m_appList, ns3::TcpTxItem::m_packet, m_sentList, m_sentSize, and m_size.

+ Here is the call graph for this function:

Member Function Documentation

◆ Add()

bool ns3::TcpTxBuffer::Add ( Ptr< Packet > p)

Append a data packet to the end of the buffer.

Parameters
pThe packet to be appended to the Tx buffer
Returns
Boolean to indicate success

Definition at line 171 of file tcp-tx-buffer.cc.

References Available(), m_appList, m_firstByteSeq, m_size, NS_LOG_FUNCTION, and NS_LOG_LOGIC.

Referenced by TcpTxBufferTestCase::TestMergeItemsWhenGetTransmittedSegment(), and TcpRateLinuxWithBufferTest::TestWithSackBlocks().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddRenoSack()

void ns3::TcpTxBuffer::AddRenoSack ( )

Emulate SACKs for SACKless connection: account for a new dupack.

The method walk the list of the sent segment until it finds a segment that was not accounted in the sackedOut count. The head will never be included. To reset the information added with this function (e.g., after an RTO) please use ResetRenoSack.

The method DiscardUpTo, when invoked, will make sure to properly clean any flag on the discarded item. As example, if the implementation discard an item that is marked as sacked, the sackedOut count is decreased accordingly.

Definition at line 1370 of file tcp-tx-buffer.cc.

References ConsistencyCheck(), m_highestSack, m_renoSack, m_sackedOut, m_sackEnabled, m_sackSeen, m_sentList, NS_ASSERT, NS_LOG_FUNCTION, and NS_LOG_INFO.

Referenced by DiscardUpTo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Available()

uint32_t ns3::TcpTxBuffer::Available ( ) const

Returns the available capacity of this buffer.

Returns
available capacity in this Tx window

Definition at line 118 of file tcp-tx-buffer.cc.

References m_maxBuffer, and m_size.

Referenced by Add().

+ Here is the caller graph for this function:

◆ BytesInFlight()

uint32_t ns3::TcpTxBuffer::BytesInFlight ( ) const

Return total bytes in flight.

Counting packets in flight is pretty simple:

$in_flight = sentSize - leftOut + retrans$

sentsize is SND.NXT-SND.UNA, retrans is the number of retransmitted segments. leftOut is the number of segment that left the network without being ACKed:

$leftOut = sacked_out + lost_out$

To see how we define the lost packets, look at the method UpdateLostCount.

Returns
total bytes in flight

Definition at line 1057 of file tcp-tx-buffer.cc.

References m_lostOut, m_retrans, m_sackedOut, m_sentSize, NS_ASSERT_MSG, and NS_LOG_INFO.

Referenced by TcpRateLinuxWithBufferTest::TestWithSackBlocks().

+ Here is the caller graph for this function:

◆ BytesInFlightRFC()

uint32_t ns3::TcpTxBuffer::BytesInFlightRFC ( ) const
private

Calculate the number of bytes in flight per RFC 6675.

Returns
the number of bytes in flight

Definition at line 1078 of file tcp-tx-buffer.cc.

References ns3::Packet::GetSize(), IsLostRFC(), m_firstByteSeq, m_lostOut, ns3::TcpTxItem::m_packet, m_retrans, ns3::TcpTxItem::m_retrans, ns3::TcpTxItem::m_sacked, m_sackedOut, m_sentList, m_sentSize, and NS_ASSERT_MSG.

+ Here is the call graph for this function:

◆ ConsistencyCheck()

void ns3::TcpTxBuffer::ConsistencyCheck ( ) const
private

Check if the values of sacked, lost, retrans, are in sync with the sent list.

Definition at line 1413 of file tcp-tx-buffer.cc.

References m_lostOut, m_retrans, m_sackedOut, m_sentList, and NS_ASSERT_MSG.

Referenced by AddRenoSack(), CopyFromSequence(), DeleteRetransmittedFlagFromHead(), DiscardUpTo(), MarkHeadAsLost(), ResetLastSegmentSent(), SetSentListLost(), Update(), and UpdateLostCount().

+ Here is the caller graph for this function:

◆ CopyFromSequence()

TcpTxItem * ns3::TcpTxBuffer::CopyFromSequence ( uint32_t numBytes,
const SequenceNumber32 & seq )

Copy data from the range [seq, seq+numBytes) into a packet.

In the following, we refer to the block [seq, seq+numBytes) simply as "block". We check the boundary of the block, and divide the possibilities in three cases:

  • the block have already been transmitted (managed in GetTransmittedSegment)
  • the block have not been transmitted yet (managed in GetNewSegment)

The last case is when the block is partially transmitted and partially not transmitted. We trick this case by requesting the portion not transmitted from GetNewSegment, and then calling GetTransmittedSegment with the full block range.

Parameters
numBytesnumber of bytes to copy
seqstart sequence number to extract
Returns
a pointer to the TcpTxItem that corresponds to what requested. Please do not delete the pointer, nor modify Packet data or sequence numbers.

Definition at line 212 of file tcp-tx-buffer.cc.

References ConsistencyCheck(), CopyFromSequence(), ns3::TracedValue< T >::Get(), GetNewSegment(), GetTransmittedSegment(), ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::GetValue(), m_firstByteSeq, ns3::TcpTxItem::m_lastSent, ns3::TcpTxItem::m_retrans, ns3::TcpTxItem::m_sacked, m_sentSize, ns3::TcpTxItem::m_startSeq, ns3::Simulator::Now(), NS_ABORT_MSG_IF, NS_ABORT_MSG_UNLESS, NS_ASSERT, NS_ASSERT_MSG, NS_LOG_DEBUG, NS_LOG_FUNCTION, and SizeFromSequence().

Referenced by CopyFromSequence(), DiscardUpTo(), TcpTxBufferTestCase::TestMergeItemsWhenGetTransmittedSegment(), and TcpRateLinuxWithBufferTest::TestWithSackBlocks().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DeleteRetransmittedFlagFromHead()

void ns3::TcpTxBuffer::DeleteRetransmittedFlagFromHead ( )

DeleteRetransmittedFlagFromHead.

Definition at line 1323 of file tcp-tx-buffer.cc.

References ConsistencyCheck(), m_retrans, m_sentList, m_sentSize, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ DiscardUpTo()

void ns3::TcpTxBuffer::DiscardUpTo ( const SequenceNumber32 & seq,
const Callback< void, TcpTxItem * > & beforeDelCb = m_nullCb )

Discard data up to but not including this sequence number.

Parameters
seqThe first sequence number to maintain after discarding all the previous sequences.
beforeDelCbCallback invoked, if it is not null, before the deletion of an Item (because it was, probably, ACKed)

Definition at line 656 of file tcp-tx-buffer.cc.

References AddRenoSack(), ConsistencyCheck(), CopyFromSequence(), ns3::Packet::CreateFragment(), ns3::TracedValue< T >::Get(), ns3::TcpTxItem::GetPacketCopy(), ns3::Packet::GetSize(), ns3::Callback< R, UArgs >::IsNull(), m_firstByteSeq, m_highestSack, ns3::TcpTxItem::m_lost, m_lostOut, ns3::TcpTxItem::m_packet, m_retrans, ns3::TcpTxItem::m_sacked, m_sackedOut, m_sackSeen, m_sentList, m_sentSize, m_size, ns3::TcpTxItem::m_startSeq, MarkHeadAsLost(), NS_ASSERT, NS_ASSERT_MSG, NS_LOG_DEBUG, NS_LOG_FUNCTION, NS_LOG_INFO, NS_LOG_LOGIC, pktSize, and RemoveFromCounts().

Referenced by TcpRateLinuxWithBufferTest::TestWithSackBlocks().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindHighestSacked()

std::pair< TcpTxBuffer::PacketList::const_iterator, SequenceNumber32 > ns3::TcpTxBuffer::FindHighestSacked ( ) const
private

Find the highest SACK byte.

Returns
a pair with the highest byte and an iterator inside m_sentList

Definition at line 348 of file tcp-tx-buffer.cc.

References ns3::Packet::GetSize(), m_firstByteSeq, ns3::TcpTxItem::m_packet, ns3::TcpTxItem::m_sacked, m_sentList, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ GetLost()

uint32_t ns3::TcpTxBuffer::GetLost ( ) const

Get the number of segments that we believe are lost in the network.

It is calculated in UpdateLostCount.

Returns
the number of lost segment

Definition at line 142 of file tcp-tx-buffer.cc.

References m_lostOut.

◆ GetNewSegment()

TcpTxItem * ns3::TcpTxBuffer::GetNewSegment ( uint32_t numBytes)
private

Get a block of data not transmitted yet and move it into SentList.

If the block is not yet transmitted, hopefully, seq is exactly the sequence number of the first byte of the first packet inside AppList. We extract the block from AppList and move it into the SentList, before returning the block itself. We manage possible fragmentation (or merges) inside AppList through GetPacketFromList.

See also
GetPacketFromList
Parameters
numBytesnumber of bytes to copy
Returns
the item that contains the right packet

Definition at line 271 of file tcp-tx-buffer.cc.

References GetPacketFromList(), ns3::Packet::GetSize(), m_appList, m_firstByteSeq, ns3::TcpTxItem::m_packet, m_sentList, m_sentSize, ns3::TcpTxItem::m_startSeq, NS_ASSERT, NS_LOG_FUNCTION, and NS_LOG_INFO.

Referenced by CopyFromSequence().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetPacketFromList()

TcpTxItem * ns3::TcpTxBuffer::GetPacketFromList ( PacketList & list,
const SequenceNumber32 & startingSeq,
uint32_t numBytes,
const SequenceNumber32 & requestedSeq,
bool * listEdited = nullptr ) const
private

Get a block (which is returned as Packet) from a list.

This function extract a block [requestedSeq,numBytes) from the list, which starts at startingSeq.

The cases we need to manage are two, and they are depicted in the following image:

                     |------|     |----|     |----|
              list = |      | --> |    | --> |    |
                     |------|     |----|     |----|

                     ^      ^
                     | ^ ^  |         (1)
                   seq | |  seq + numBytes
                       | |
                       | |
                    seq   seq + numBytes     (2)

The case 1 is easy to manage: the requested block is exactly a packet already stored. If one value (seq or seq + numBytes) does not align to a packet boundary, or when both values does not align (case 2), it is a bit more complex.

Basically, we have two possible operations:

  • fragment : split an existing packet in two
  • merge : merge two existing packets in one

and we reduce case (2) to case (1) through sequentially applying fragment or merge. For instance:

    |------|
    |      |
    |------|

    ^ ^  ^ ^
    | |  | |
start |  | |
      |  | end
     seq |
         seq + numBytes

To reduce to case (1), we need to perform two fragment operations:

  • fragment (start, seq)
  • fragment (seq + numBytes, end)

After these operations, the requested block is exactly the resulting packet. Merge operation is required when the requested block span over two (or more) existing packets.

While this could be extremely slow in the worst possible scenario (one big packet which is split in small packets for transmission, and merged for re-transmission) that scenario is unlikely during a TCP transmission (since MSS can change, but it is stable, and retransmissions do not happen for each segment).

Parameters
listList to extract block from
startingSeqStarting sequence of the list
numBytesBytes to extract, starting from requestedSeq
requestedSeqRequested sequence
listEditedoutput parameter which indicates if the list has been edited
Returns
the item that contains the right packet

Definition at line 390 of file tcp-tx-buffer.cc.

References GetPacketFromList(), ns3::GetSize(), m_firstByteSeq, ns3::TcpTxItem::m_packet, m_sentList, ns3::TcpTxItem::m_startSeq, MergeItems(), NS_ASSERT, NS_ASSERT_MSG, NS_FATAL_ERROR, NS_LOG_FUNCTION, NS_LOG_INFO, NS_LOG_WARN, and SplitItems().

Referenced by GetNewSegment(), GetPacketFromList(), and GetTransmittedSegment().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetRetransmitsCount()

uint32_t ns3::TcpTxBuffer::GetRetransmitsCount ( ) const

Return the number of segments in the sent list that have been transmitted more than once, without acknowledgment.

This method is to support the retransmits count for determining PipeSize in NewReno-style TCP.

Returns
number of segments that have been transmitted more than once, without acknowledgment

Definition at line 136 of file tcp-tx-buffer.cc.

References m_retrans.

◆ GetSacked()

uint32_t ns3::TcpTxBuffer::GetSacked ( ) const

Get the number of segments that have been explicitly sacked by the receiver.

Returns
the number of sacked segment.

Definition at line 148 of file tcp-tx-buffer.cc.

References m_sackedOut.

◆ GetTransmittedSegment()

TcpTxItem * ns3::TcpTxBuffer::GetTransmittedSegment ( uint32_t numBytes,
const SequenceNumber32 & seq )
private

Get a block of data previously transmitted.

This is clearly a retransmission, and if everything is going well, the block requested is matching perfectly with another one requested in the past. If not, fragmentation or merge are required. We manage both inside GetPacketFromList.

See also
GetPacketFromList
Parameters
numBytesnumber of bytes to copy
seqsequence requested
Returns
the item that contains the right packet

Definition at line 295 of file tcp-tx-buffer.cc.

References GetPacketFromList(), ns3::Packet::GetSize(), m_firstByteSeq, ns3::TcpTxItem::m_packet, m_retrans, ns3::TcpTxItem::m_retrans, m_sentList, m_sentSize, NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by CopyFromSequence().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetTypeId()

TypeId ns3::TcpTxBuffer::GetTypeId ( )
static

Get the type ID.

Returns
the object TypeId

Definition at line 29 of file tcp-tx-buffer.cc.

References m_firstByteSeq, ns3::MakeTraceSourceAccessor(), and ns3::TypeId::SetParent().

+ Here is the call graph for this function:

◆ HeadSequence()

SequenceNumber32 ns3::TcpTxBuffer::HeadSequence ( ) const

Get the sequence number of the buffer head.

Returns
the first byte's sequence number

Definition at line 76 of file tcp-tx-buffer.cc.

References m_firstByteSeq.

◆ IsHeadRetransmitted()

bool ns3::TcpTxBuffer::IsHeadRetransmitted ( ) const

Check if the head is retransmitted.

Returns
true if the head is retransmitted, false in all other cases (including no segment sent)

Definition at line 1310 of file tcp-tx-buffer.cc.

References m_sentList, m_sentSize, and NS_LOG_FUNCTION.

◆ IsLost()

bool ns3::TcpTxBuffer::IsLost ( const SequenceNumber32 & seq) const

Check if a segment is lost.

It does a check on the flags to determine if the segment has to be considered as lost for an external class

Parameters
seqsequence to check
Returns
true if the sequence is supposed to be lost, false otherwise

Definition at line 917 of file tcp-tx-buffer.cc.

References m_highestSack, m_sentList, NS_LOG_FUNCTION, and NS_LOG_INFO.

◆ IsLostRFC()

bool ns3::TcpTxBuffer::IsLostRFC ( const SequenceNumber32 & seq,
const PacketList::const_iterator & segment ) const
private

Decide if a segment is lost based on RFC 6675 algorithm.

Parameters
seqSequence
segmentIterator to the sequence
Returns
true if seq is lost per RFC 6675, false otherwise

Definition at line 1139 of file tcp-tx-buffer.cc.

References m_dupAckThresh, m_highestSack, ns3::TcpTxItem::m_lost, ns3::TcpTxItem::m_packet, ns3::TcpTxItem::m_retrans, ns3::TcpTxItem::m_sacked, m_segmentSize, m_sentList, NS_LOG_FUNCTION, and NS_LOG_INFO.

Referenced by BytesInFlightRFC().

+ Here is the caller graph for this function:

◆ IsRetransmittedDataAcked()

bool ns3::TcpTxBuffer::IsRetransmittedDataAcked ( const SequenceNumber32 & ack) const

Checks whether the ack corresponds to retransmitted data.

Parameters
ackACK number received
Returns
true if retransmitted data was acked

Definition at line 640 of file tcp-tx-buffer.cc.

References ns3::TcpTxItem::m_packet, ns3::TcpTxItem::m_retrans, ns3::TcpTxItem::m_sacked, m_sentList, ns3::TcpTxItem::m_startSeq, and NS_LOG_FUNCTION.

◆ IsSackEnabled()

bool ns3::TcpTxBuffer::IsSackEnabled ( ) const

check whether SACK is used on the corresponding TCP socket

Returns
true if SACK is used

Definition at line 106 of file tcp-tx-buffer.cc.

References m_sackEnabled.

◆ MarkHeadAsLost()

void ns3::TcpTxBuffer::MarkHeadAsLost ( )

Mark the head of the sent list as lost.

Definition at line 1341 of file tcp-tx-buffer.cc.

References ConsistencyCheck(), m_lostOut, m_retrans, m_sackedOut, and m_sentList.

Referenced by DiscardUpTo(), and TcpTxBufferTestCase::TestMergeItemsWhenGetTransmittedSegment().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MaxBufferSize()

uint32_t ns3::TcpTxBuffer::MaxBufferSize ( ) const

Get the maximum buffer size.

Returns
the Tx window size (in bytes)

Definition at line 94 of file tcp-tx-buffer.cc.

References m_maxBuffer.

◆ MergeItems()

void ns3::TcpTxBuffer::MergeItems ( TcpTxItem * t1,
TcpTxItem * t2 ) const
private

Merge two TcpTxItem.

Merge t2 in t1. It consists in copying the lastSent field if t2 is more recent than t1. Retransmitted field is copied only if it set in t2 but not in t1. Sacked is copied only if it is true in both items.

Parameters
t1first item
t2second item

Definition at line 577 of file tcp-tx-buffer.cc.

References ns3::Packet::AddAtEnd(), ns3::Packet::GetSize(), ns3::TcpTxItem::m_lastSent, ns3::TcpTxItem::m_lost, ns3::TcpTxItem::m_packet, m_retrans, ns3::TcpTxItem::m_retrans, ns3::TcpTxItem::m_sacked, NS_ASSERT, NS_ASSERT_MSG, NS_LOG_FUNCTION, and NS_LOG_INFO.

Referenced by GetPacketFromList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NextSeg()

bool ns3::TcpTxBuffer::NextSeg ( SequenceNumber32 * seq,
SequenceNumber32 * seqHigh,
bool isRecovery ) const

Get the next sequence number to transmit, according to RFC 6675.

Parameters
seqNext sequence number to transmit, based on the scoreboard information
seqHighMaximum sequence number to transmit, based on SMSS and/or receiver window
isRecoverytrue if the socket congestion state is in recovery mode
Returns
true is seq is updated, false otherwise

Definition at line 951 of file tcp-tx-buffer.cc.

References ns3::Packet::GetSize(), ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::GetValue(), m_firstByteSeq, m_highestSack, ns3::TcpTxItem::m_lost, ns3::TcpTxItem::m_packet, ns3::TcpTxItem::m_retrans, m_rWndCallback, ns3::TcpTxItem::m_sacked, m_sackSeen, m_segmentSize, m_sentList, m_sentSize, ns3::TcpTxItem::m_startSeq, NS_LOG_FUNCTION, NS_LOG_INFO, and SizeFromSequence().

+ Here is the call graph for this function:

◆ RemoveFromCounts()

void ns3::TcpTxBuffer::RemoveFromCounts ( TcpTxItem * item,
uint32_t size )
private

Remove the size specified from the lostOut, retrans, sacked count.

Used only in DiscardUpTo

Parameters
itemItem that will be discarded
sizesize to remove (can be different from pktSize because of fragmentation)

Definition at line 618 of file tcp-tx-buffer.cc.

References ns3::TcpTxItem::m_lost, m_lostOut, m_retrans, ns3::TcpTxItem::m_retrans, ns3::TcpTxItem::m_sacked, m_sackedOut, NS_ASSERT, NS_ASSERT_MSG, and NS_LOG_FUNCTION.

Referenced by DiscardUpTo().

+ Here is the caller graph for this function:

◆ ResetLastSegmentSent()

void ns3::TcpTxBuffer::ResetLastSegmentSent ( )

Take the last segment sent and put it back into the un-sent list (at the beginning)

Definition at line 1243 of file tcp-tx-buffer.cc.

References ConsistencyCheck(), ns3::Packet::GetSize(), m_appList, ns3::TcpTxItem::m_packet, m_retrans, ns3::TcpTxItem::m_retrans, m_sentList, m_sentSize, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ ResetRenoSack()

void ns3::TcpTxBuffer::ResetRenoSack ( )

Reset the SACKs.

Reset the Scoreboard from all SACK information. This method also works in case the SACKs are set by the Update method.

Definition at line 1198 of file tcp-tx-buffer.cc.

References m_highestSack, m_sackedOut, m_sackSeen, m_sentList, and NS_LOG_FUNCTION.

◆ ResetSentList()

void ns3::TcpTxBuffer::ResetSentList ( )

◆ SetDupAckThresh()

void ns3::TcpTxBuffer::SetDupAckThresh ( uint32_t dupAckThresh)

Set the DupAckThresh.

Parameters
dupAckThreshthe threshold

Definition at line 124 of file tcp-tx-buffer.cc.

References m_dupAckThresh.

Referenced by TcpRateLinuxWithBufferTest::TestWithSackBlocks().

+ Here is the caller graph for this function:

◆ SetHeadSequence()

void ns3::TcpTxBuffer::SetHeadSequence ( const SequenceNumber32 & seq)

Set the head sequence of the buffer.

Set the head (m_firstByteSeq) to seq. Supposed to be called only when the connection is just set up and we did not send any data out yet.

Parameters
seqThe sequence number of the head byte

Definition at line 154 of file tcp-tx-buffer.cc.

References m_firstByteSeq, m_highestSack, m_sackSeen, m_sentList, NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by TcpTxBufferTestCase::TestMergeItemsWhenGetTransmittedSegment(), and TcpRateLinuxWithBufferTest::TestWithSackBlocks().

+ Here is the caller graph for this function:

◆ SetMaxBufferSize()

void ns3::TcpTxBuffer::SetMaxBufferSize ( uint32_t n)

Set the maximum buffer size.

Parameters
nTx window size (in bytes)

Definition at line 100 of file tcp-tx-buffer.cc.

References m_maxBuffer.

◆ SetRWndCallback()

void ns3::TcpTxBuffer::SetRWndCallback ( Callback< uint32_t > rWndCallback)

Set callback to obtain receiver window value.

Parameters
rWndCallbackreceiver window callback

Definition at line 1213 of file tcp-tx-buffer.cc.

References m_rWndCallback, and NS_LOG_FUNCTION.

◆ SetSackEnabled()

void ns3::TcpTxBuffer::SetSackEnabled ( bool enabled)

tell tx-buffer whether SACK is used on this TCP socket

Parameters
enabledwhether sack is used

Definition at line 112 of file tcp-tx-buffer.cc.

References m_sackEnabled.

◆ SetSegmentSize()

void ns3::TcpTxBuffer::SetSegmentSize ( uint32_t segmentSize)

Set the segment size.

Parameters
segmentSizethe segment size

Definition at line 130 of file tcp-tx-buffer.cc.

References m_segmentSize, and segmentSize.

Referenced by TcpTxBufferTestCase::TestMergeItemsWhenGetTransmittedSegment(), and TcpRateLinuxWithBufferTest::TestWithSackBlocks().

+ Here is the caller graph for this function:

◆ SetSentListLost()

void ns3::TcpTxBuffer::SetSentListLost ( bool resetSack = false)

Set the entire sent list as lost (typically after an RTO)

Used to set all the sent list as lost, so the bytes in flight is not counting them as in flight, but we will continue to use SACK information for recovering the timeout.

Moreover, reset the retransmit flag for every item.

Parameters
resetSackTrue if the function should reset the SACK flags.

Definition at line 1262 of file tcp-tx-buffer.cc.

References ConsistencyCheck(), m_highestSack, m_lostOut, m_retrans, m_sackedOut, m_sackSeen, m_sentList, m_sentSize, NS_ASSERT_MSG, NS_LOG_FUNCTION, and NS_LOG_INFO.

+ Here is the call graph for this function:

◆ Size()

uint32_t ns3::TcpTxBuffer::Size ( ) const

Returns total number of bytes in this buffer.

Returns
total number of bytes in this Tx buffer

Definition at line 88 of file tcp-tx-buffer.cc.

References m_size.

◆ SizeFromSequence()

uint32_t ns3::TcpTxBuffer::SizeFromSequence ( const SequenceNumber32 & seq) const

Returns the number of bytes from the buffer in the range [seq, tailSequence)

Parameters
seqinitial sequence number
Returns
the number of bytes from the buffer in the range

Definition at line 195 of file tcp-tx-buffer.cc.

References NS_LOG_ERROR, NS_LOG_FUNCTION, and TailSequence().

Referenced by CopyFromSequence(), and NextSeg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SplitItems()

void ns3::TcpTxBuffer::SplitItems ( TcpTxItem * t1,
TcpTxItem * t2,
uint32_t size ) const
private

Split one TcpTxItem.

Move "size" bytes from t2 into t1, copying all the fields. Adjust the starting sequence of each item.

Parameters
t1first item
t2second item
sizeSize to split

Definition at line 370 of file tcp-tx-buffer.cc.

References ns3::Packet::CreateFragment(), ns3::TcpTxItem::m_lastSent, ns3::TcpTxItem::m_lost, ns3::TcpTxItem::m_packet, ns3::TcpTxItem::m_retrans, ns3::TcpTxItem::m_sacked, ns3::TcpTxItem::m_startSeq, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_INFO, and ns3::Packet::RemoveAtStart().

Referenced by GetPacketFromList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TailSequence()

SequenceNumber32 ns3::TcpTxBuffer::TailSequence ( ) const

Get the sequence number of the buffer tail (plus one)

Returns
the last byte's sequence number + 1

Definition at line 82 of file tcp-tx-buffer.cc.

References m_firstByteSeq, and m_size.

Referenced by SizeFromSequence().

+ Here is the caller graph for this function:

◆ Update()

uint32_t ns3::TcpTxBuffer::Update ( const TcpOptionSack::SackList & list,
const Callback< void, TcpTxItem * > & sackedCb = m_nullCb )

Update the scoreboard.

Parameters
listlist of SACKed blocks
sackedCbCallback 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

Definition at line 773 of file tcp-tx-buffer.cc.

References ConsistencyCheck(), ns3::Callback< R, UArgs >::IsNull(), m_firstByteSeq, m_highestSack, m_lostOut, m_sackedOut, m_sackSeen, m_sentList, m_sentSize, NS_ASSERT, NS_ASSERT_MSG, NS_LOG_FUNCTION, NS_LOG_INFO, pktSize, and UpdateLostCount().

Referenced by TcpRateLinuxWithBufferTest::TestWithSackBlocks().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UpdateLostCount()

void ns3::TcpTxBuffer::UpdateLostCount ( )
private

Update the lost count.

Reset lost to 0, then walk the sent list looking for lost segments. We have two possible algorithms for detecting lost packets:

  • RFC 6675 algorithm, which says that if more than "Dupack thresh" (e.g., 3) sacked segments above the sequence, then we can consider the sequence lost;
  • NewReno (RFC6582): in Recovery we assume that one segment is lost (classic Reno). While we are in Recovery and a partial ACK arrives, we assume that one more packet is lost (NewReno).

The {New}Reno cases, for now, are managed in TcpSocketBase through the call to MarkHeadAsLost. This function is, therefore, called after a SACK option has been received, and updates the lost count. It can be probably optimized by not walking the entire list, but a subset.

Definition at line 868 of file tcp-tx-buffer.cc.

References ConsistencyCheck(), ns3::Packet::GetSize(), m_dupAckThresh, m_highestSack, ns3::TcpTxItem::m_lost, m_lostOut, ns3::TcpTxItem::m_packet, ns3::TcpTxItem::m_sacked, m_sentList, NS_LOG_FUNCTION, and NS_LOG_INFO.

Referenced by Update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const TcpTxBuffer & tcpTxBuf )
friend

Output operator.

Parameters
osThe output stream.
tcpTxBufthe TcpTxBuffer to print.
Returns
The output stream.

Definition at line 1456 of file tcp-tx-buffer.cc.

Member Data Documentation

◆ m_appList

PacketList ns3::TcpTxBuffer::m_appList
private

Buffer for application data.

Definition at line 594 of file tcp-tx-buffer.h.

Referenced by ~TcpTxBuffer(), Add(), GetNewSegment(), ResetLastSegmentSent(), and ResetSentList().

◆ m_dupAckThresh

uint32_t ns3::TcpTxBuffer::m_dupAckThresh {0}
private

Duplicate Ack threshold from TcpSocketBase.

Definition at line 609 of file tcp-tx-buffer.h.

Referenced by IsLostRFC(), SetDupAckThresh(), and UpdateLostCount().

◆ m_firstByteSeq

TracedValue<SequenceNumber32> ns3::TcpTxBuffer::m_firstByteSeq
private

◆ m_highestSack

std::pair<PacketList::const_iterator, SequenceNumber32> ns3::TcpTxBuffer::m_highestSack
private

◆ m_lostOut

uint32_t ns3::TcpTxBuffer::m_lostOut {0}
private

◆ m_maxBuffer

uint32_t ns3::TcpTxBuffer::m_maxBuffer
private

Max number of data bytes in buffer (SND.WND)

Definition at line 596 of file tcp-tx-buffer.h.

Referenced by Available(), MaxBufferSize(), and SetMaxBufferSize().

◆ m_nullCb

Callback< void, TcpTxItem * > ns3::TcpTxBuffer::m_nullCb = MakeNullCallback<void, TcpTxItem*>()
staticprivate

Null callback for an item.

Definition at line 615 of file tcp-tx-buffer.h.

◆ m_renoSack

bool ns3::TcpTxBuffer::m_renoSack {false}
private

Indicates if AddRenoSack was called.

Definition at line 611 of file tcp-tx-buffer.h.

Referenced by AddRenoSack().

◆ m_retrans

◆ m_rWndCallback

Callback<uint32_t> ns3::TcpTxBuffer::m_rWndCallback
private

Callback to obtain RCV.WND value.

Definition at line 599 of file tcp-tx-buffer.h.

Referenced by TcpTxBuffer(), NextSeg(), and SetRWndCallback().

◆ m_sackedOut

uint32_t ns3::TcpTxBuffer::m_sackedOut {0}
private

◆ m_sackEnabled

bool ns3::TcpTxBuffer::m_sackEnabled {true}
private

Indicates if SACK is enabled on this connection.

Definition at line 612 of file tcp-tx-buffer.h.

Referenced by AddRenoSack(), IsSackEnabled(), and SetSackEnabled().

◆ m_sackSeen

bool ns3::TcpTxBuffer::m_sackSeen {false}
private

Indicates if a SACK was received.

Definition at line 613 of file tcp-tx-buffer.h.

Referenced by AddRenoSack(), DiscardUpTo(), NextSeg(), ResetRenoSack(), ResetSentList(), SetHeadSequence(), SetSentListLost(), and Update().

◆ m_segmentSize

uint32_t ns3::TcpTxBuffer::m_segmentSize {0}
private

Segment size from TcpSocketBase.

Definition at line 610 of file tcp-tx-buffer.h.

Referenced by IsLostRFC(), NextSeg(), and SetSegmentSize().

◆ m_sentList

◆ m_sentSize

◆ m_size

uint32_t ns3::TcpTxBuffer::m_size
private

Size of all data in this buffer.

Definition at line 597 of file tcp-tx-buffer.h.

Referenced by ~TcpTxBuffer(), Add(), Available(), DiscardUpTo(), Size(), and TailSequence().


The documentation for this class was generated from the following files: