21 #include "ns3/packet.h" 
   22 #include "ns3/fatal-error.h" 
   35     .AddConstructor<TcpRxBuffer> ()
 
   36     .AddTraceSource (
"NextRxSequence",
 
   37                      "Next sequence number expected (RCV.NXT)",
 
   51   : m_nextRxSeq (n), m_gotFin (false), m_size (0), m_maxBuffer (32768), m_availBytes (0)
 
  141   uint32_t pktSize = p->
GetSize ();
 
  144   NS_LOG_LOGIC (
"Add pkt " << p << 
" len=" << pktSize << 
" seq=" << headSeq
 
  152       if (maxSeq < tailSeq) tailSeq = maxSeq;
 
  153       if (tailSeq < headSeq) headSeq = tailSeq;
 
  157   while (i != 
m_data.end () && i->first <= tailSeq)
 
  159       SequenceNumber32 lastByteSeq = i->first + 
SequenceNumber32 (i->second->GetSize ());
 
  160       if (lastByteSeq > headSeq)
 
  162           if (i->first > headSeq && lastByteSeq < tailSeq)
 
  164               m_size -= i->second->GetSize ();
 
  168           if (i->first <= headSeq)
 
  170               headSeq = lastByteSeq;
 
  172           if (lastByteSeq >= tailSeq)
 
  180   if (headSeq >= tailSeq)
 
  188       uint32_t length = tailSeq - headSeq;
 
  198   for (
BufIterator i = m_data.begin (); i != m_data.end (); ++i)
 
  224   uint32_t extractSize = std::min (maxSize, 
m_availBytes);
 
  225   NS_LOG_LOGIC (
"Requested to extract " << extractSize << 
" bytes from TcpRxBuffer of size=" << 
m_size);
 
  226   if (extractSize == 0) 
return 0;  
 
  235       uint32_t pktSize = i->second->GetSize ();
 
  236       if (pktSize <= extractSize)
 
  238           outPkt->AddAtEnd (i->second);
 
  242           extractSize -= pktSize;
 
  246           outPkt->AddAtEnd (i->second->CreateFragment (0, extractSize));
 
  247           m_data[i->first + 
SequenceNumber32 (extractSize)] = i->second->CreateFragment (extractSize, pktSize - extractSize);
 
  254   if (outPkt->GetSize () == 0)
 
  260                              << 
", num pkts in buffer=" << 
m_data.size ());
 
uint32_t m_availBytes
Number of bytes available to read, i.e. 
 
uint32_t m_maxBuffer
Upper bound of the number of data bytes in buffer (RCV.WND) 
 
#define NS_LOG_FUNCTION(parameters)
 
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 read...
 
TracedValue< SequenceNumber32 > m_nextRxSeq
Seqnum of the first missing byte in data (RCV.NXT) 
 
uint32_t Available() const 
Get the actual number of bytes available to be read. 
 
#define NS_ASSERT(condition)
 
uint32_t GetSize(void) const 
 
void SetFinSequence(const SequenceNumber32 &s)
Set the FIN Sequence number (i.e., the one closing the connection) 
 
SequenceNumber32 NextRxSequence(void) const 
Get Next Rx Sequence number. 
 
SequenceNumber< uint32_t, int32_t > SequenceNumber32
 
SequenceNumber32 MaxRxSequence(void) const 
Get the lowest sequence number that this TcpRxBuffer cannot accept. 
 
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const 
Create a new packet which contains a fragment of the original packet. 
 
void IncNextRxSequence(void)
Increment the Next Sequence number. 
 
bool m_gotFin
Did I received FIN packet? 
 
void SetNextRxSequence(const SequenceNumber32 &s)
Set the Next Sequence number. 
 
#define NS_LOG_LOGIC(msg)
 
void SetMaxBufferSize(uint32_t s)
Set the Maximum buffer size. 
 
TcpRxBuffer(uint32_t n=0)
Constructor. 
 
SequenceNumber32 m_finSeq
Seqnum of the FIN packet. 
 
Ptr< Packet > Extract(uint32_t maxSize)
Extract data from the head of the buffer as indicated by nextRxSeq. 
 
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
 
std::map< SequenceNumber32, Ptr< Packet > > m_data
Corresponding data (may be null) 
 
uint32_t MaxBufferSize(void) const 
Get the Maximum buffer size. 
 
uint32_t m_size
Number of total data bytes in the buffer, not necessarily contiguous. 
 
static TypeId GetTypeId(void)
Get the type ID. 
 
a base class which provides memory management and object aggregation 
 
uint32_t Size(void) const 
Get the actual buffer occupancy. 
 
a unique identifier for an interface. 
 
TypeId SetParent(TypeId tid)
 
bool Finished(void)
Check if the buffer did receive all the data (and the connection is closed) 
 
std::map< SequenceNumber32, Ptr< Packet > >::iterator BufIterator
container for data stored in the buffer 
 
NS_LOG_COMPONENT_DEFINE("TcpRxBuffer")