25 #include "ns3/packet.h" 27 #include "ns3/abort.h" 28 #include "ns3/tcp-option-ts.h" 43 .SetGroupName (
"Internet")
45 .AddTraceSource (
"UnackSequence",
46 "First unacknowledged sequence number (SND.UNA)",
48 "ns3::SequenceNumber32TracedValueCallback")
61 : m_maxBuffer (32768), m_size (0), m_sentSize (0), m_firstByteSeq (
n)
68 PacketList::iterator it;
199 NS_LOG_LOGIC (
"Rejected. Not enough room to buffer packet.");
212 return static_cast<uint32_t
> (lastSeq - seq);
215 NS_LOG_ERROR (
"Requested a sequence beyond our space (" << seq <<
" > " << lastSeq <<
216 "). Returning 0 for convenience.");
226 "Requested a sequence number which is not in the buffer anymore");
246 NS_LOG_DEBUG (
"Returning already sent item " << *outItem <<
" from " << *
this);
251 "Requesting a piece of new data with an hole");
258 NS_LOG_DEBUG (
"Returning new item " << *outItem <<
" from " << *
this);
274 "Returning an item " << *outItem <<
" with SND.UNA as " <<
287 NS_LOG_INFO (
"AppList start at " << startOfAppList <<
", sentSize = " <<
291 numBytes, startOfAppList);
314 bool listEdited =
false;
315 uint32_t s = numBytes;
321 if ((*it)->m_startSeq == seq)
328 if ((! (*next)->m_sacked) && ((*it)->m_lost == (*next)->m_lost))
330 s =
std::min(s, (*it)->m_packet->GetSize () + (*next)->m_packet->GetSize ());
335 s =
std::min(s, (*it)->m_packet->GetSize ());
340 s =
std::min(s, (*it)->m_packet->GetSize ());
357 std::pair <TcpTxBuffer::PacketList::const_iterator, SequenceNumber32>
371 ret = std::make_pair (it, beginOfCurrentPacket);
383 NS_ASSERT (t1 !=
nullptr && t2 !=
nullptr);
397 NS_LOG_INFO (
"Split of size " << size <<
" result: t1 " << *t1 <<
" t2 " << *t2);
403 bool *listEdited)
const 437 PacketList::iterator it =
list.begin ();
440 while (it !=
list.end ())
443 currentPacket = currentItem->
m_packet;
451 if (seq < beginOfCurrentPacket + currentPacket->
GetSize ())
454 if (seq == beginOfCurrentPacket)
457 outItem = currentItem;
458 NS_LOG_INFO (
"Current packet starts at seq " << seq <<
459 " ends at " << seq + currentPacket->
GetSize ());
461 else if (seq > beginOfCurrentPacket)
466 NS_LOG_INFO (
"we are at " << beginOfCurrentPacket <<
467 " searching for " << seq <<
468 " and now we recurse because packet ends at " 469 << beginOfCurrentPacket + currentPacket->
GetSize ());
471 SplitItems (firstPart, currentItem, seq - beginOfCurrentPacket);
474 list.insert (it, firstPart);
484 NS_FATAL_ERROR (
"seq < beginOfCurrentPacket: our data is before");
490 beginOfCurrentPacket += currentPacket->
GetSize ();
501 if (seq + numBytes <= beginOfCurrentPacket + currentPacket->
GetSize ())
504 if (numBytes == currentPacket->
GetSize ())
532 else if (numBytes < currentPacket->
GetSize ())
537 SplitItems (firstPart, currentItem, numBytes);
540 list.insert (it, firstPart);
553 if (++it ==
list.end ())
557 NS_LOG_WARN (
"Cannot reach the end, but this case is covered " 558 "with conditional statements inside CopyFromSequence." 559 "Something has gone wrong, report a bug");
593 NS_ASSERT (t1 !=
nullptr && t2 !=
nullptr);
595 NS_LOG_INFO (
"Merging " << *t2 <<
" into " << *t1);
598 "Merging one sacked and another not sacked. Impossible");
600 "Merging one lost and another not lost. Impossible");
629 NS_LOG_INFO (
"Situation after the merge: " << *t1);
689 while (
m_size > 0 && offset > 0)
719 ". Remaining data " <<
m_size);
721 if (!beforeDelCb.
IsNull ())
742 NS_LOG_INFO (
"Fragmented one packet by size " << offset <<
743 ", new size=" <<
pktSize <<
" resulting item is " <<
744 *item <<
" status: " << *
this);
765 NS_LOG_INFO (
"Moving the SACK flag from the HEAD to another segment");
771 "While removing up to " << seq <<
" we get SND.UNA to " <<
782 NS_LOG_LOGIC (
"Buffer status after discarding data " << *
this);
793 NS_LOG_INFO (
"Updating scoreboard, got " <<
list.size () <<
" blocks to analyze");
795 uint32_t bytesSacked = 0;
797 for (
auto option_it =
list.begin (); option_it !=
list.end (); ++option_it)
799 PacketList::iterator item_it =
m_sentList.begin ();
804 NS_LOG_INFO (
"Not updating scoreboard, the option block is outside the sent list");
810 uint32_t
pktSize = (*item_it)->m_packet->GetSize ();
817 if (beginOfCurrentPacket >= (*option_it).first
818 && beginOfCurrentPacket +
pktSize <= (*option_it).second)
820 if ((*item_it)->m_sacked)
824 ", checking sentList for block " << *(*item_it) <<
825 ", found in the sackboard already sacked");
829 if ((*item_it)->m_lost)
831 (*item_it)->m_lost =
false;
832 m_lostOut -= (*item_it)->m_packet->GetSize ();
835 (*item_it)->m_sacked =
true;
837 bytesSacked += (*item_it)->m_packet->GetSize ();
842 m_highestSack = std::make_pair (item_it, beginOfCurrentPacket);
846 ", checking sentList for block " << *(*item_it) <<
847 ", found in the sackboard, sacking, current highSack: " <<
856 else if (beginOfCurrentPacket +
pktSize > (*option_it).second)
860 ", checking sentList for block " << *(*item_it) <<
861 "], not found, breaking loop");
865 beginOfCurrentPacket +=
pktSize;
892 NS_LOG_INFO (
"Status before the update: " << *
this <<
893 ", will start from the latest sent item");
897 NS_LOG_INFO (
"Status before the update: " << *
this <<
929 NS_LOG_INFO (
"Status after the update: " << *
this);
939 PacketList::const_iterator it;
951 if (beginOfCurrentPacket >= seq)
953 if ((*it)->m_lost ==
true)
955 NS_LOG_INFO (
"seq=" << seq <<
" is lost because of lost flag");
959 if ((*it)->m_sacked ==
true)
961 NS_LOG_INFO (
"seq=" << seq <<
" is not lost because of sacked flag");
966 beginOfCurrentPacket += (*it)->m_packet->GetSize ();
990 PacketList::const_iterator it;
993 bool isSeqPerRule3Valid =
false;
1005 NS_LOG_INFO(
"IsLost, returning" << beginOfCurrentPkt);
1006 *seq = beginOfCurrentPkt;
1010 else if (seqPerRule3.
GetValue () == 0 && isRecovery)
1012 NS_LOG_INFO (
"Saving for rule 3 the seq " << beginOfCurrentPkt);
1013 isSeqPerRule3Valid =
true;
1014 seqPerRule3 = beginOfCurrentPkt;
1039 NS_LOG_INFO (
"There is no available receiver window to send");
1054 if (isSeqPerRule3Valid)
1083 " is out of sync with sent list size " <<
m_sentSize <<
1089 " retrans: " << retrans);
1090 uint32_t in_flight =
m_sentSize - leftOut + retrans;
1103 PacketList::const_iterator it;
1107 uint32_t sackedOut = 0;
1108 uint32_t lostOut = 0;
1109 uint32_t retrans = 0;
1110 uint32_t totalSize = 0;
1121 bool isLost =
IsLostRFC (beginOfCurrentPkt, it);
1159 "Sent size counted: " << totalSize <<
" " <<
m_sentSize << *
this);
1170 PacketList::const_iterator it;
1175 if ((*segment)->m_sacked ==
true)
1185 for (it = segment; it !=
m_sentList.end (); ++it)
1193 " found to be SACKed while checking for " << seq);
1198 NS_LOG_INFO (
"seq=" << seq <<
" is lost because of 3 sacked blocks ahead");
1208 NS_LOG_INFO (
"seq=" << seq <<
" is not lost because there are no sacked segment ahead");
1212 beginOfCurrentPacket += current->
GetSize ();
1229 (*it)->m_sacked =
false;
1304 (*it)->m_sacked =
false;
1305 (*it)->m_lost =
true;
1312 m_lostOut += (*it)->m_packet->GetSize ();
1314 else if (!(*it)->m_sacked)
1317 (*it)->m_lost =
true;
1318 m_lostOut += (*it)->m_packet->GetSize ();
1322 (*it)->m_retrans =
false;
1325 NS_LOG_INFO (
"Set sent list lost, status: " << *
this);
1410 while (it !=
m_sentList.end () && (*it)->m_sacked)
1418 (*it)->m_sacked =
true;
1421 NS_LOG_INFO (
"Added a Reno SACK, status: " << *
this);
1425 NS_LOG_INFO (
"Can't add a Reno SACK because we miss segments. This dupack" 1426 " should be arrived from spurious retransmissions");
1435 static const bool enable =
false;
1442 uint32_t sacked = 0;
1444 uint32_t retrans = 0;
1448 if ((*it)->m_sacked)
1450 sacked += (*it)->m_packet->GetSize ();
1454 lost += (*it)->m_packet->GetSize ();
1456 if ((*it)->m_retrans)
1458 retrans += (*it)->m_packet->GetSize ();
1480 TcpTxBuffer::PacketList::const_iterator it;
1481 std::stringstream ss;
1483 uint32_t sentSize = 0, appSize = 0;
1488 p = (*it)->GetPacket ();
1493 beginOfCurrentPacket += p->
GetSize ();
1498 appSize += (*it)->GetPacket ()->GetSize ();
1501 os <<
"Sent list: " << ss.str () <<
", size = " << tcpTxBuf.
m_sentList.size () <<
1502 " Total size: " << tcpTxBuf.
m_size <<
1505 " m_retransOut = " << tcpTxBuf.
m_retrans <<
1506 " m_lostOut = " << tcpTxBuf.
m_lostOut <<
Callback< uint32_t > m_rWndCallback
Callback to obtain RCV.WND value.
void AddRenoSack()
Emulate SACKs for SACKless connection: account for a new dupack.
bool m_retrans
Indicates if the segment is retransmitted.
void Print(std::ostream &os) const
Print the packet contents.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint32_t m_retrans
Number of retransmitted bytes.
bool m_sackEnabled
Indicates if SACK is enabled on this connection.
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.
TcpTxItem * GetTransmittedSegment(uint32_t numBytes, const SequenceNumber32 &seq)
Get a block of data previously transmitted.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
std::pair< TcpTxBuffer::PacketList::const_iterator, SequenceNumber32 > FindHighestSacked() const
Find the highest SACK byte.
void ResetLastSegmentSent()
Take the last segment sent and put it back into the un-sent list (at the beginning) ...
PacketList m_appList
Buffer for application data.
uint32_t GetSize(Ptr< const Packet > packet, const WifiMacHeader *hdr, bool isAmpdu)
Return the total size of the packet after WifiMacHeader and FCS trailer have been added...
uint32_t m_lostOut
Number of lost bytes.
std::list< SackBlock > SackList
SACK list definition.
uint32_t GetRetransmitsCount(void) const
Return the number of segments in the sent list that have been transmitted more than once...
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_UNUSED(x)
Mark a local variable as unused.
void DeleteRetransmittedFlagFromHead()
DeleteRetransmittedFlagFromHead.
void RemoveFromCounts(TcpTxItem *item, uint32_t size)
Remove the size specified from the lostOut, retrans, sacked count.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void UpdateLostCount()
Update the lost count.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
bool IsSackEnabled(void) const
check whether SACK is used on the corresponding TCP socket
Item that encloses the application packet and some flags for it.
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
TracedValue< SequenceNumber32 > m_firstByteSeq
Sequence number of the first byte in data (SND.UNA)
Time m_lastSent
Timestamp of the time at which the segment has been sent last time.
SequenceNumber32 m_startSeq
Sequence number of the item (if transmitted)
uint32_t m_sentSize
Size of sent (and not discarded) segments.
void DiscardUpTo(const SequenceNumber32 &seq, const Callback< void, TcpTxItem *> &beforeDelCb=m_nullCb)
Discard data up to but not including this sequence number.
std::list< TcpTxItem * > PacketList
container for data stored in the buffer
static bool AreEquals(const bool &first, const bool &second)
void MergeItems(TcpTxItem *t1, TcpTxItem *t2) const
Merge two TcpTxItem.
uint32_t m_size
Size of all data in this buffer.
TcpTxItem * CopyFromSequence(uint32_t numBytes, const SequenceNumber32 &seq)
Copy data from the range [seq, seq+numBytes) into a packet.
void SetRWndCallback(Callback< uint32_t > rWndCallback)
Set callback to obtain receiver window value.
void ConsistencyCheck() const
Check if the values of sacked, lost, retrans, are in sync with the sent list.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
void SetMaxBufferSize(uint32_t n)
Set the maximum buffer size.
uint32_t SizeFromSequence(const SequenceNumber32 &seq) const
Returns the number of bytes from the buffer in the range [seq, tailSequence)
void SetSentListLost(bool resetSack=false)
Set the entire sent list as lost (typically after an RTO)
std::pair< PacketList::const_iterator, SequenceNumber32 > m_highestSack
Highest SACK byte.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
void ResetSentList()
Reset the sent list.
bool IsRetransmittedDataAcked(const SequenceNumber32 &ack) const
Checks whether the ack corresponds to retransmitted data.
uint32_t GetLost(void) const
Get the number of segments that we believe are lost in the network.
Ptr< Packet > m_packet
Application packet (can be null)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
SequenceNumber32 TailSequence(void) const
Get the sequence number of the buffer tail (plus one)
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
bool Add(Ptr< Packet > p)
Append a data packet to the end of the buffer.
uint32_t m_sackedOut
Number of sacked bytes.
static TypeId GetTypeId(void)
Get the type ID.
void ResetRenoSack()
Reset the SACKs.
static Time Now(void)
Return the current simulation virtual time.
void SetDupAckThresh(uint32_t dupAckThresh)
Set the DupAckThresh.
SequenceNumber32 HeadSequence(void) const
Get the sequence number of the buffer head.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
void MarkHeadAsLost()
Mark the head of the sent list as lost.
bool IsLostRFC(const SequenceNumber32 &seq, const PacketList::const_iterator &segment) const
Decide if a segment is lost based on RFC 6675 algorithm.
TcpTxItem * GetPacketFromList(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
void SetSegmentSize(uint32_t segmentSize)
Set the segment size.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
void SplitItems(TcpTxItem *t1, TcpTxItem *t2, uint32_t size) const
Split one TcpTxItem.
uint32_t Size(void) const
Returns total number of bytes in this buffer.
uint32_t m_dupAckThresh
Duplicate Ack threshold from TcpSocketBase.
Ptr< Packet > GetPacketCopy(void) const
Get a copy of the Packet underlying this item.
bool IsLost(const SequenceNumber32 &seq) const
Check if a segment is lost.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
PacketList m_sentList
Buffer for sent (but not acked) data.
uint32_t BytesInFlightRFC() const
Calculate the number of bytes in flight per RFC 6675.
uint32_t Update(const TcpOptionSack::SackList &list, const Callback< void, TcpTxItem *> &sackedCb=m_nullCb)
Update the scoreboard.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
uint32_t m_maxBuffer
Max number of data bytes in buffer (SND.WND)
T Get(void) const
Get the underlying value.
uint32_t Available(void) const
Returns the available capacity of this buffer.
TcpTxItem * GetNewSegment(uint32_t numBytes)
Get a block of data not transmitted yet and move it into SentList.
void SetSackEnabled(bool enabled)
tell tx-buffer whether SACK is used on this TCP socket
uint32_t m_segmentSize
Segment size from TcpSocketBase.
bool NextSeg(SequenceNumber32 *seq, SequenceNumber32 *seqHigh, bool isRecovery) const
Get the next sequence number to transmit, according to RFC 6675.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
A base class which provides memory management and object aggregation.
bool IsHeadRetransmitted() const
Check if the head is retransmitted.
TcpTxBuffer(uint32_t n=0)
Constructor.
bool IsNull(void) const
Check for null implementation.
uint32_t pktSize
packet size used for the simulation (in bytes)
virtual ~TcpTxBuffer(void)
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
bool m_renoSack
Indicates if AddRenoSack was called.
bool m_sacked
Indicates if the segment has been SACKed.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
uint32_t MaxBufferSize(void) const
Get the maximum buffer size.
uint32_t GetSacked(void) const
Get the number of segments that have been explicitly sacked by the receiver.
void Print(std::ostream &os) const
Print the time.
bool m_lost
Indicates if the segment has been lost (RTO)
uint32_t BytesInFlight() const
Return total bytes in flight.
static Callback< void, TcpTxItem * > m_nullCb
Null callback for an item.
void SetHeadSequence(const SequenceNumber32 &seq)
Set the head sequence of the buffer.