A Discrete-Event Network Simulator
API
ns3::TcpRxBuffer Class Reference

Rx reordering buffer for TCP. More...

#include "tcp-rx-buffer.h"

+ Inheritance diagram for ns3::TcpRxBuffer:
+ Collaboration diagram for ns3::TcpRxBuffer:

Public Member Functions

 TcpRxBuffer (uint32_t n=0)
 Constructor. More...
 
virtual ~TcpRxBuffer ()
 
bool Add (Ptr< Packet > p, TcpHeader const &tcph)
 Insert a packet into the buffer and update the availBytes counter to reflect the number of bytes ready to send to the application. More...
 
uint32_t Available () const
 Get the actual number of bytes available to be read. More...
 
Ptr< PacketExtract (uint32_t maxSize)
 Extract data from the head of the buffer as indicated by nextRxSeq. More...
 
bool Finished (void)
 Check if the buffer did receive all the data (and the connection is closed) More...
 
TcpOptionSack::SackList GetSackList () const
 Get the sack list. More...
 
uint32_t GetSackListSize () const
 Get the size of Sack list. More...
 
bool GotFin () const
 Says if a FIN bit has been received. More...
 
void IncNextRxSequence (void)
 Increment the Next Sequence number. More...
 
uint32_t MaxBufferSize (void) const
 Get the Maximum buffer size. More...
 
SequenceNumber32 MaxRxSequence (void) const
 Get the lowest sequence number that this TcpRxBuffer cannot accept. More...
 
SequenceNumber32 NextRxSequence (void) const
 Get Next Rx Sequence number. More...
 
void SetFinSequence (const SequenceNumber32 &s)
 Set the FIN Sequence number (i.e., the one closing the connection) More...
 
void SetMaxBufferSize (uint32_t s)
 Set the Maximum buffer size. More...
 
void SetNextRxSequence (const SequenceNumber32 &s)
 Set the Next Sequence number. More...
 
uint32_t Size (void) const
 Get the actual buffer occupancy. More...
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor. More...
 
virtual ~Object ()
 Destructor. More...
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together. More...
 
void Dispose (void)
 Dispose of this Object. More...
 
AggregateIterator GetAggregateIterator (void) const
 Get an iterator to the Objects aggregated to this one. More...
 
virtual TypeId GetInstanceTypeId (void) const
 Get the most derived TypeId for this Object. More...
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object. More...
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId. More...
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object. More...
 
template<typename T >
Ptr< T > GetObject (void) const
 Get a pointer to the requested aggregated Object. More...
 
void Initialize (void)
 Invoke DoInitialize on all Objects aggregated to this one. More...
 
bool IsInitialized (void) const
 Check if the object has been initialized. More...
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor. More...
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor. More...
 
uint32_t GetReferenceCount (void) const
 Get the reference count of the object. More...
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator. More...
 
void Ref (void) const
 Increment the reference count. More...
 
void Unref (void) const
 Decrement the reference count. More...
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor. More...
 
void GetAttribute (std::string name, AttributeValue &value) const
 Get the value of an attribute, raising fatal errors if unsuccessful. More...
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising erros. More...
 
virtual TypeId GetInstanceTypeId (void) const =0
 Get the most derived TypeId for this Object. More...
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful. More...
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors. More...
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context. More...
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context. More...
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context. More...
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context. More...
 

Static Public Member Functions

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

Private Types

typedef std::map< SequenceNumber32, Ptr< Packet > >::iterator BufIterator
 container for data stored in the buffer More...
 

Private Member Functions

void ClearSackList (const SequenceNumber32 &seq)
 Remove old blocks from the sack list. More...
 
void UpdateSackList (const SequenceNumber32 &head, const SequenceNumber32 &tail)
 Update the sack list, with the block seq starting at the beginning. More...
 

Private Attributes

uint32_t m_availBytes
 Number of bytes available to read, i.e. More...
 
std::map< SequenceNumber32, Ptr< Packet > > m_data
 Corresponding data (may be null) More...
 
SequenceNumber32 m_finSeq
 Seqnum of the FIN packet. More...
 
bool m_gotFin
 Did I received FIN packet? More...
 
uint32_t m_maxBuffer
 Upper bound of the number of data bytes in buffer (RCV.WND) More...
 
TracedValue< SequenceNumber32m_nextRxSeq
 Seqnum of the first missing byte in data (RCV.NXT) More...
 
TcpOptionSack::SackList m_sackList
 Sack list (updated constantly) More...
 
uint32_t m_size
 Number of total data bytes in the buffer, not necessarily contiguous. More...
 

Additional Inherited Members

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

Detailed Description

Rx reordering buffer for TCP.

The class is responsible to safely store the segments, and then returning them in-order to the application, where "in-order" does not means "network-order", but "sender-order" : the bytes should be returned in the same order that the sender application used to push them down on wire.

The first useful sequence that this class is waiting is returned by the method NextRxSequence, and could be set at the beginning through MaxRxSequence.

The max. size of this buffer is managed through SetMaxBufferSize, and could be retrieved using MaxBufferSize. The current size instead is returned by Size, while the amount of in-order data that could be extracted is returned by the method Available.

To store data, use Add; for retrieving a certain amount of ordered data, use the method Extract.

SACK list

An interesting feature of this class is the ability to maintain an ordered SACK list, under the definition of RFC 2018. When a out-of-order segment reaches this buffer, an ACK will be sent out, and the SACK list is generated or updated. From RFC 2018:

‍If sent at all, SACK options SHOULD be included in all ACKs which do not ACK the highest sequence number in the data receiver's queue.

For more information about the SACK list, please check the documentation of the method GetSackList.

See also
GetSackList
UpdateSackList

Config Paths

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

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

No Attributes are defined for this type.

TraceSources

  • NextRxSequence: Next sequence number expected (RCV.NXT)
    Callback signature: ns3::SequenceNumber32TracedValueCallback

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

Definition at line 73 of file tcp-rx-buffer.h.

Member Typedef Documentation

◆ BufIterator

typedef std::map<SequenceNumber32,Ptr<Packet>>::iterator ns3::TcpRxBuffer::BufIterator
private

container for data stored in the buffer

Definition at line 221 of file tcp-rx-buffer.h.

Constructor & Destructor Documentation

◆ TcpRxBuffer()

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

Constructor.

Parameters
ninitial Sequence number to be received

Definition at line 53 of file tcp-rx-buffer.cc.

◆ ~TcpRxBuffer()

ns3::TcpRxBuffer::~TcpRxBuffer ( )
virtual

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

Member Function Documentation

◆ Add()

bool ns3::TcpRxBuffer::Add ( Ptr< Packet p,
TcpHeader const &  tcph 
)

Insert a packet into the buffer and update the availBytes counter to reflect the number of bytes ready to send to the application.

This function handles overlap by triming the head of the inputted packet and removing data from the buffer that overlaps the tail of the inputted packet

Parameters
ppacket
tcphpacket's TCP header
Returns
True when success, false otherwise.

Definition at line 140 of file tcp-rx-buffer.cc.

References ClearSackList(), ns3::Packet::CreateFragment(), ns3::TcpHeader::GetSequenceNumber(), ns3::Packet::GetSize(), m_availBytes, m_data, m_finSeq, m_gotFin, m_maxBuffer, m_nextRxSeq, m_size, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_LOGIC, pktSize, visualizer.core::start(), and UpdateSackList().

Referenced by TcpRxBufferTestCase::TestUpdateSACKList().

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

◆ Available()

uint32_t ns3::TcpRxBuffer::Available ( ) const

Get the actual number of bytes available to be read.

Returns
size of available data (in bytes)

Definition at line 93 of file tcp-rx-buffer.cc.

References m_availBytes.

◆ ClearSackList()

void ns3::TcpRxBuffer::ClearSackList ( const SequenceNumber32 seq)
private

Remove old blocks from the sack list.

Used to remove blocks already delivered to the application.

After this call, in the SACK list there will be only blocks with sequence numbers greater than seq; it is perfectly safe to call this function with an empty sack list.

Parameters
seqLast sequence to remove

Definition at line 336 of file tcp-rx-buffer.cc.

References m_sackList, NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by Add().

+ Here is the caller graph for this function:

◆ Extract()

Ptr< Packet > ns3::TcpRxBuffer::Extract ( uint32_t  maxSize)

Extract data from the head of the buffer as indicated by nextRxSeq.

The extracted data is going to be forwarded to the application.

Parameters
maxSizemaximum number of bytes to extract
Returns
a packet

Definition at line 364 of file tcp-rx-buffer.cc.

References ns3::Packet::AddAtEnd(), ns3::Packet::GetSize(), m_availBytes, m_data, m_nextRxSeq, m_size, min, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_LOGIC, and pktSize.

+ Here is the call graph for this function:

◆ Finished()

bool ns3::TcpRxBuffer::Finished ( void  )

Check if the buffer did receive all the data (and the connection is closed)

Returns
true if all data have been received

Definition at line 134 of file tcp-rx-buffer.cc.

References m_finSeq, m_gotFin, and m_nextRxSeq.

◆ GetSackList()

TcpOptionSack::SackList ns3::TcpRxBuffer::GetSackList ( void  ) const

Get the sack list.

The sack list can be empty, and it is updated each time Add or Extract are called through the private method UpdateSackList.

Returns
a list of isolated blocks

Definition at line 358 of file tcp-rx-buffer.cc.

References m_sackList.

Referenced by TcpRxBufferTestCase::TestUpdateSACKList().

+ Here is the caller graph for this function:

◆ GetSackListSize()

uint32_t ns3::TcpRxBuffer::GetSackListSize ( ) const

Get the size of Sack list.

Returns
the size of the sack block list; can be empty

Definition at line 231 of file tcp-rx-buffer.cc.

References m_sackList, and NS_LOG_FUNCTION.

◆ GetTypeId()

TypeId ns3::TcpRxBuffer::GetTypeId ( void  )
static

Get the type ID.

Returns
the object TypeId

Definition at line 32 of file tcp-rx-buffer.cc.

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

+ Here is the call graph for this function:

◆ GotFin()

bool ns3::TcpRxBuffer::GotFin ( ) const
inline

Says if a FIN bit has been received.

Returns
true if we received a FIN bit

Definition at line 182 of file tcp-rx-buffer.h.

References m_gotFin.

◆ IncNextRxSequence()

void ns3::TcpRxBuffer::IncNextRxSequence ( void  )

Increment the Next Sequence number.

Definition at line 99 of file tcp-rx-buffer.cc.

References m_nextRxSeq, m_size, NS_ASSERT, and NS_LOG_FUNCTION.

◆ MaxBufferSize()

uint32_t ns3::TcpRxBuffer::MaxBufferSize ( void  ) const

Get the Maximum buffer size.

Returns
the Maximum buffer size

Definition at line 75 of file tcp-rx-buffer.cc.

References m_maxBuffer.

◆ MaxRxSequence()

SequenceNumber32 ns3::TcpRxBuffer::MaxRxSequence ( void  ) const

Get the lowest sequence number that this TcpRxBuffer cannot accept.

Returns
the lowest sequence number that this TcpRxBuffer cannot accept

Definition at line 110 of file tcp-rx-buffer.cc.

References m_data, m_finSeq, m_gotFin, m_maxBuffer, and m_nextRxSeq.

◆ NextRxSequence()

SequenceNumber32 ns3::TcpRxBuffer::NextRxSequence ( void  ) const

Get Next Rx Sequence number.

Returns
Next Rx Sequence number

Definition at line 63 of file tcp-rx-buffer.cc.

References m_nextRxSeq.

Referenced by TcpRxBufferTestCase::TestUpdateSACKList().

+ Here is the caller graph for this function:

◆ SetFinSequence()

void ns3::TcpRxBuffer::SetFinSequence ( const SequenceNumber32 s)

Set the FIN Sequence number (i.e., the one closing the connection)

Parameters
sthe Sequence number

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

References m_finSeq, m_gotFin, m_nextRxSeq, and NS_LOG_FUNCTION.

◆ SetMaxBufferSize()

void ns3::TcpRxBuffer::SetMaxBufferSize ( uint32_t  s)

Set the Maximum buffer size.

Parameters
sthe Maximum buffer size

Definition at line 81 of file tcp-rx-buffer.cc.

References m_maxBuffer.

◆ SetNextRxSequence()

void ns3::TcpRxBuffer::SetNextRxSequence ( const SequenceNumber32 s)

Set the Next Sequence number.

Parameters
sthe Sequence number

Definition at line 69 of file tcp-rx-buffer.cc.

References m_nextRxSeq.

Referenced by TcpRxBufferTestCase::TestUpdateSACKList().

+ Here is the caller graph for this function:

◆ Size()

uint32_t ns3::TcpRxBuffer::Size ( void  ) const

Get the actual buffer occupancy.

Returns
buffer occupancy (in bytes)

Definition at line 87 of file tcp-rx-buffer.cc.

References m_size.

◆ UpdateSackList()

void ns3::TcpRxBuffer::UpdateSackList ( const SequenceNumber32 head,
const SequenceNumber32 tail 
)
private

Update the sack list, with the block seq starting at the beginning.

Note: the maximum size of the block list is 4. Caller is free to drop blocks at the end to accommodate header size; from RFC 2018:

‍The data receiver SHOULD include as many distinct SACK blocks as possible in the SACK option. Note that the maximum available option space may not be sufficient to report all blocks present in the receiver's queue.

In fact, the maximum amount of blocks is 4, and if we consider the timestamp (or other) options, it is even less. For more detail about this function, please see the source code and in-line comments.

Parameters
headsequence number of the block at the beginning
tailsequence number of the block at the end

Definition at line 239 of file tcp-rx-buffer.cc.

References m_nextRxSeq, m_sackList, NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by Add().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_availBytes

uint32_t ns3::TcpRxBuffer::m_availBytes
private

Number of bytes available to read, i.e.

contiguous block at head

Definition at line 227 of file tcp-rx-buffer.h.

Referenced by Add(), Available(), and Extract().

◆ m_data

std::map<SequenceNumber32, Ptr<Packet> > ns3::TcpRxBuffer::m_data
private

Corresponding data (may be null)

Definition at line 228 of file tcp-rx-buffer.h.

Referenced by Add(), Extract(), and MaxRxSequence().

◆ m_finSeq

SequenceNumber32 ns3::TcpRxBuffer::m_finSeq
private

Seqnum of the FIN packet.

Definition at line 223 of file tcp-rx-buffer.h.

Referenced by Add(), Finished(), MaxRxSequence(), and SetFinSequence().

◆ m_gotFin

bool ns3::TcpRxBuffer::m_gotFin
private

Did I received FIN packet?

Definition at line 224 of file tcp-rx-buffer.h.

Referenced by Add(), Finished(), GotFin(), MaxRxSequence(), and SetFinSequence().

◆ m_maxBuffer

uint32_t ns3::TcpRxBuffer::m_maxBuffer
private

Upper bound of the number of data bytes in buffer (RCV.WND)

Definition at line 226 of file tcp-rx-buffer.h.

Referenced by Add(), MaxBufferSize(), MaxRxSequence(), and SetMaxBufferSize().

◆ m_nextRxSeq

TracedValue<SequenceNumber32> ns3::TcpRxBuffer::m_nextRxSeq
private

Seqnum of the first missing byte in data (RCV.NXT)

Definition at line 222 of file tcp-rx-buffer.h.

Referenced by Add(), Extract(), Finished(), GetTypeId(), IncNextRxSequence(), MaxRxSequence(), NextRxSequence(), SetFinSequence(), SetNextRxSequence(), and UpdateSackList().

◆ m_sackList

TcpOptionSack::SackList ns3::TcpRxBuffer::m_sackList
private

Sack list (updated constantly)

Definition at line 218 of file tcp-rx-buffer.h.

Referenced by ClearSackList(), GetSackList(), GetSackListSize(), and UpdateSackList().

◆ m_size

uint32_t ns3::TcpRxBuffer::m_size
private

Number of total data bytes in the buffer, not necessarily contiguous.

Definition at line 225 of file tcp-rx-buffer.h.

Referenced by Add(), Extract(), IncNextRxSequence(), and Size().


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