Rx reordering buffer for TCP. More...
#include "tcp-rx-buffer.h"
Public Member Functions | |
TcpRxBuffer (uint32_t n=0) | |
Constructor. | |
~TcpRxBuffer () override | |
bool | Add (Ptr< Packet > p, const TcpHeader &tcph) |
Insert a packet into the buffer and update the availBytes counter to reflect the number of bytes ready to send to the application. | |
uint32_t | Available () const |
Get the actual number of bytes available to be read. | |
Ptr< Packet > | Extract (uint32_t maxSize) |
Extract data from the head of the buffer as indicated by nextRxSeq. | |
bool | Finished () |
Check if the buffer did receive all the data (and the connection is closed) | |
TcpOptionSack::SackList | GetSackList () const |
Get the sack list. | |
uint32_t | GetSackListSize () const |
Get the size of Sack list. | |
bool | GotFin () const |
Says if a FIN bit has been received. | |
void | IncNextRxSequence () |
Increment the Next Sequence number. | |
uint32_t | MaxBufferSize () const |
Get the Maximum buffer size. | |
SequenceNumber32 | MaxRxSequence () const |
Get the lowest sequence number that this TcpRxBuffer cannot accept. | |
SequenceNumber32 | NextRxSequence () const |
Get Next Rx Sequence number. | |
void | SetFinSequence (const SequenceNumber32 &s) |
Set the FIN Sequence number (i.e., the one closing the connection) | |
void | SetMaxBufferSize (uint32_t s) |
Set the Maximum buffer size. | |
void | SetNextRxSequence (const SequenceNumber32 &s) |
Set the Next Sequence number. | |
uint32_t | Size () const |
Get the actual buffer occupancy. | |
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< Object > | GetObject () 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< Object > | GetObject (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. | |
SimpleRefCount & | operator= (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::map< SequenceNumber32, Ptr< Packet > >::iterator | BufIterator |
container for data stored in the buffer | |
Private Member Functions | |
void | ClearSackList (const SequenceNumber32 &seq) |
Remove old blocks from the sack list. | |
void | UpdateSackList (const SequenceNumber32 &head, const SequenceNumber32 &tail) |
Update the sack list, with the block seq starting at the beginning. | |
Private Attributes | |
uint32_t | m_availBytes |
Number of bytes available to read, i.e. | |
std::map< SequenceNumber32, Ptr< Packet > > | m_data |
Corresponding data (may be null) | |
SequenceNumber32 | m_finSeq |
Seqnum of the FIN packet. | |
bool | m_gotFin |
Did I received FIN packet? | |
uint32_t | m_maxBuffer |
Upper bound of the number of data bytes in buffer (RCV.WND) | |
TracedValue< SequenceNumber32 > | m_nextRxSeq |
Seqnum of the first missing byte in data (RCV.NXT) | |
TcpOptionSack::SackList | m_sackList |
Sack list (updated constantly) | |
uint32_t | m_size |
Number of total data bytes in the buffer, not necessarily contiguous. | |
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. | |
Related Symbols inherited from ns3::ObjectBase | |
static TypeId | GetObjectIid () |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. | |
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.
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.
Definition at line 64 of file tcp-rx-buffer.h.
|
private |
container for data stored in the buffer
Definition at line 215 of file tcp-rx-buffer.h.
ns3::TcpRxBuffer::TcpRxBuffer | ( | uint32_t | n = 0 | ) |
Constructor.
n | initial Sequence number to be received |
Definition at line 42 of file tcp-rx-buffer.cc.
|
override |
Definition at line 51 of file tcp-rx-buffer.cc.
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 trimming the head of the inputted packet and removing data from the buffer that overlaps the tail of the inputted packet
p | packet |
tcph | packet's TCP header |
Definition at line 136 of file tcp-rx-buffer.cc.
References ClearSackList(), ns3::TcpHeader::GetSequenceNumber(), m_availBytes, m_data, m_finSeq, m_gotFin, m_maxBuffer, m_nextRxSeq, m_size, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_LOGIC, pktSize, and UpdateSackList().
Referenced by TcpRxBufferTestCase::TestUpdateSACKList().
uint32_t ns3::TcpRxBuffer::Available | ( | ) | const |
Get the actual number of bytes available to be read.
Definition at line 86 of file tcp-rx-buffer.cc.
References m_availBytes.
|
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.
seq | Last sequence to remove |
Definition at line 341 of file tcp-rx-buffer.cc.
References m_sackList, NS_ASSERT, and NS_LOG_FUNCTION.
Referenced by Add().
Extract data from the head of the buffer as indicated by nextRxSeq.
The extracted data is going to be forwarded to the application.
maxSize | maximum number of bytes to extract |
Definition at line 368 of file tcp-rx-buffer.cc.
References ns3::Create(), m_availBytes, m_data, m_nextRxSeq, m_size, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_LOGIC, and pktSize.
bool ns3::TcpRxBuffer::Finished | ( | ) |
Check if the buffer did receive all the data (and the connection is closed)
Definition at line 130 of file tcp-rx-buffer.cc.
References m_finSeq, m_gotFin, and m_nextRxSeq.
TcpOptionSack::SackList ns3::TcpRxBuffer::GetSackList | ( | ) | 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.
Definition at line 362 of file tcp-rx-buffer.cc.
References m_sackList.
Referenced by TcpRxBufferTestCase::TestUpdateSACKList().
uint32_t ns3::TcpRxBuffer::GetSackListSize | ( | ) | const |
Get the size of Sack list.
Definition at line 236 of file tcp-rx-buffer.cc.
References m_sackList, and NS_LOG_FUNCTION.
|
static |
Get the type ID.
Definition at line 22 of file tcp-rx-buffer.cc.
References m_nextRxSeq, ns3::MakeTraceSourceAccessor(), and ns3::TypeId::SetParent().
|
inline |
Says if a FIN bit has been received.
Definition at line 173 of file tcp-rx-buffer.h.
References m_gotFin.
void ns3::TcpRxBuffer::IncNextRxSequence | ( | ) |
Increment the Next Sequence number.
Definition at line 92 of file tcp-rx-buffer.cc.
References m_nextRxSeq, m_size, NS_ASSERT, and NS_LOG_FUNCTION.
uint32_t ns3::TcpRxBuffer::MaxBufferSize | ( | ) | const |
Get the Maximum buffer size.
Definition at line 68 of file tcp-rx-buffer.cc.
References m_maxBuffer.
SequenceNumber32 ns3::TcpRxBuffer::MaxRxSequence | ( | ) | const |
Get the lowest sequence number that this TcpRxBuffer cannot accept.
Definition at line 103 of file tcp-rx-buffer.cc.
References m_data, m_finSeq, m_gotFin, m_maxBuffer, and m_nextRxSeq.
SequenceNumber32 ns3::TcpRxBuffer::NextRxSequence | ( | ) | const |
Get Next Rx Sequence number.
Definition at line 56 of file tcp-rx-buffer.cc.
References m_nextRxSeq.
Referenced by TcpRxBufferTestCase::TestUpdateSACKList().
void ns3::TcpRxBuffer::SetFinSequence | ( | const SequenceNumber32 & | s | ) |
Set the FIN Sequence number (i.e., the one closing the connection)
s | the Sequence number |
Definition at line 117 of file tcp-rx-buffer.cc.
References m_finSeq, m_gotFin, m_nextRxSeq, and NS_LOG_FUNCTION.
void ns3::TcpRxBuffer::SetMaxBufferSize | ( | uint32_t | s | ) |
Set the Maximum buffer size.
s | the Maximum buffer size |
Definition at line 74 of file tcp-rx-buffer.cc.
References m_maxBuffer.
void ns3::TcpRxBuffer::SetNextRxSequence | ( | const SequenceNumber32 & | s | ) |
Set the Next Sequence number.
s | the Sequence number |
Definition at line 62 of file tcp-rx-buffer.cc.
References m_nextRxSeq.
Referenced by TcpRxBufferTestCase::TestUpdateSACKList().
uint32_t ns3::TcpRxBuffer::Size | ( | ) | const |
Get the actual buffer occupancy.
Definition at line 80 of file tcp-rx-buffer.cc.
References m_size.
|
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.
head | sequence number of the block at the beginning |
tail | sequence number of the block at the end |
Definition at line 244 of file tcp-rx-buffer.cc.
References m_nextRxSeq, m_sackList, NS_ASSERT, and NS_LOG_FUNCTION.
Referenced by Add().
|
private |
Number of bytes available to read, i.e.
contiguous block at head
Definition at line 222 of file tcp-rx-buffer.h.
Referenced by Add(), Available(), and Extract().
|
private |
Corresponding data (may be null)
Definition at line 223 of file tcp-rx-buffer.h.
Referenced by Add(), Extract(), and MaxRxSequence().
|
private |
Seqnum of the FIN packet.
Definition at line 218 of file tcp-rx-buffer.h.
Referenced by Add(), Finished(), MaxRxSequence(), and SetFinSequence().
|
private |
Did I received FIN packet?
Definition at line 219 of file tcp-rx-buffer.h.
Referenced by Add(), Finished(), GotFin(), MaxRxSequence(), and SetFinSequence().
|
private |
Upper bound of the number of data bytes in buffer (RCV.WND)
Definition at line 221 of file tcp-rx-buffer.h.
Referenced by Add(), MaxBufferSize(), MaxRxSequence(), and SetMaxBufferSize().
|
private |
Seqnum of the first missing byte in data (RCV.NXT)
Definition at line 217 of file tcp-rx-buffer.h.
Referenced by Add(), Extract(), Finished(), GetTypeId(), IncNextRxSequence(), MaxRxSequence(), NextRxSequence(), SetFinSequence(), SetNextRxSequence(), and UpdateSackList().
|
private |
Sack list (updated constantly)
Definition at line 212 of file tcp-rx-buffer.h.
Referenced by ClearSackList(), GetSackList(), GetSackListSize(), and UpdateSackList().
|
private |
Number of total data bytes in the buffer, not necessarily contiguous.
Definition at line 220 of file tcp-rx-buffer.h.
Referenced by Add(), Extract(), IncNextRxSequence(), and Size().