25 #include "ns3/packet.h"
26 #include "ns3/fatal-error.h"
40 .AddConstructor<TcpTxBuffer> ()
41 .AddTraceSource (
"UnackSequence",
42 "First unacknowledged sequence number (SND.UNA)",
56 : m_firstByteSeq (n), m_size (0), m_maxBuffer (32768), m_data (0)
116 NS_LOG_LOGIC (
"Rejected. Not enough room to buffer packet.");
128 ", returns " << lastSeq - seq);
129 return lastSeq - seq;
139 return Create<Packet> ();
143 return Create<Packet> (
s);
149 uint32_t pktSize = 0;
150 bool beginFound =
false;
157 pktSize = (*i)->GetSize ();
160 if (count + pktSize > offset)
162 NS_LOG_LOGIC (
"First byte found in packet #" << pktCount <<
" at buffer offset " << count
163 <<
", packet len=" << pktSize);
165 uint32_t packetOffset = offset - count;
166 uint32_t fragmentLength = count + pktSize - offset;
167 if (fragmentLength >= s)
169 return (*i)->CreateFragment (packetOffset, s);
178 else if (count + pktSize >= offset + s)
180 NS_LOG_LOGIC (
"Last byte found in packet #" << pktCount <<
" at buffer offset " << count
181 <<
", packet len=" << pktSize);
182 uint32_t fragmentLength = offset + s - count;
190 NS_LOG_LOGIC (
"Appending to output the packet #" << pktCount <<
" of offset " << count <<
" len=" << pktSize);
212 <<
", numPkts=" <<
m_data.size ());
221 while (i !=
m_data.end ())
223 if (offset > (*i)->GetSize ())
225 pktSize = (*i)->GetSize ();
230 NS_LOG_LOGIC (
"Removed one packet of size " << pktSize <<
", offset=" << offset);
234 pktSize = (*i)->GetSize () - offset;
235 *i = (*i)->CreateFragment (offset, pktSize);
238 NS_LOG_LOGIC (
"Fragmented one packet by size " << offset <<
", new size=" << pktSize);
248 <<
" numPkts="<<
m_data.size ());
uint32_t Size(void) const
Returns total number of bytes in this Tx buffer.
#define NS_LOG_FUNCTION(parameters)
void DiscardUpTo(const SequenceNumber32 &seq)
Discard data up to but not including this sequence number.
uint32_t SizeFromSequence(const SequenceNumber32 &seq) const
Returns the number of bytes from the buffer in the range [seq, tailSequence)
SequenceNumber32 HeadSequence(void) const
Returns the first byte's sequence number.
#define NS_ASSERT(condition)
uint32_t MaxBufferSize(void) const
Returns the Tx window size.
uint32_t GetSize(void) const
SequenceNumber< uint32_t, int32_t > SequenceNumber32
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
TracedValue< SequenceNumber32 > m_firstByteSeq
Sequence number of the first byte in data (SND.UNA)
uint32_t m_size
Number of data bytes.
NS_LOG_COMPONENT_DEFINE("TcpTxBuffer")
#define NS_LOG_LOGIC(msg)
void SetMaxBufferSize(uint32_t n)
Set the Tx window size.
uint32_t Available(void) const
Returns the available capacity in this Tx window.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
bool Add(Ptr< Packet > p)
Append a data packet to the end of the buffer.
static TypeId GetTypeId(void)
Get the type ID.
uint32_t m_maxBuffer
Max number of data bytes in buffer (SND.WND)
a base class which provides memory management and object aggregation
TcpTxBuffer(uint32_t n=0)
Constructor.
virtual ~TcpTxBuffer(void)
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
std::list< Ptr< Packet > >::iterator BufIterator
container for data stored in the buffer
SequenceNumber32 TailSequence(void) const
Returns the last byte's sequence number + 1.
std::list< Ptr< Packet > > m_data
Corresponding data (may be null)
void SetHeadSequence(const SequenceNumber32 &seq)
Set the m_firstByteSeq to seq.
Ptr< Packet > CopyFromSequence(uint32_t numBytes, const SequenceNumber32 &seq)
Copy data of size numBytes into a packet, data from the range [seq, seq+numBytes) ...