A Discrete-Event Network Simulator
API
tcp-tx-buffer.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010-2015 Adrian Sai-wah Tam
4  * Copyright (c) 2016 Natale Patriciello <natale.patriciello@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Original author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
20  */
21 
22 #ifndef TCP_TX_BUFFER_H
23 #define TCP_TX_BUFFER_H
24 
25 #include "ns3/object.h"
26 #include "ns3/traced-value.h"
27 #include "ns3/sequence-number.h"
28 #include "ns3/tcp-option-sack.h"
29 #include "ns3/tcp-tx-item.h"
30 
31 namespace ns3 {
32 class Packet;
33 
122 class TcpTxBuffer : public Object
123 {
124 public:
129  static TypeId GetTypeId (void);
134  TcpTxBuffer (uint32_t n = 0);
135  virtual ~TcpTxBuffer (void);
136 
137  // Accessors
138 
143  SequenceNumber32 HeadSequence (void) const;
144 
149  SequenceNumber32 TailSequence (void) const;
150 
155  uint32_t Size (void) const;
156 
161  uint32_t MaxBufferSize (void) const;
162 
167  void SetMaxBufferSize (uint32_t n);
168 
173  bool IsSackEnabled (void) const;
174 
180  void SetSackEnabled (bool enabled);
181 
186  uint32_t Available (void) const;
187 
192  void SetDupAckThresh (uint32_t dupAckThresh);
193 
198  void SetSegmentSize (uint32_t segmentSize);
199 
209  uint32_t GetRetransmitsCount (void) const;
210 
217  uint32_t GetLost (void) const;
218 
223  uint32_t GetSacked (void) const;
224 
231  bool Add (Ptr<Packet> p);
232 
239  uint32_t SizeFromSequence (const SequenceNumber32& seq) const;
240 
261  TcpTxItem* CopyFromSequence (uint32_t numBytes, const SequenceNumber32& seq);
262 
270  void SetHeadSequence (const SequenceNumber32& seq);
271 
278  bool IsRetransmittedDataAcked (const SequenceNumber32& ack) const;
279 
288  void DiscardUpTo (const SequenceNumber32& seq,
289  const Callback<void, TcpTxItem *> &beforeDelCb = m_nullCb);
290 
298  uint32_t Update (const TcpOptionSack::SackList &list,
299  const Callback<void, TcpTxItem *> &sackedCb = m_nullCb);
300 
310  bool IsLost (const SequenceNumber32 &seq) const;
311 
320  bool NextSeg (SequenceNumber32 *seq, SequenceNumber32 *seqHigh, bool isRecovery) const;
321 
338  uint32_t BytesInFlight () const;
339 
350  void SetSentListLost (bool resetSack = false);
351 
358  bool IsHeadRetransmitted () const;
359 
364 
369  void ResetSentList ();
370 
375  void ResetLastSegmentSent ();
376 
380  void MarkHeadAsLost ();
381 
394  void AddRenoSack ();
395 
402  void ResetRenoSack ();
403 
408  void SetRWndCallback (Callback<uint32_t> rWndCallback);
409 
410 private:
411  friend std::ostream & operator<< (std::ostream & os, TcpTxBuffer const & tcpTxBuf);
412 
413  typedef std::list<TcpTxItem*> PacketList;
414 
434  void UpdateLostCount ();
435 
444  void RemoveFromCounts (TcpTxItem *item, uint32_t size);
445 
452  bool IsLostRFC (const SequenceNumber32 &seq, const PacketList::const_iterator &segment) const;
453 
458  uint32_t BytesInFlightRFC () const;
459 
474  TcpTxItem* GetNewSegment (uint32_t numBytes);
475 
490  TcpTxItem* GetTransmittedSegment (uint32_t numBytes, const SequenceNumber32 &seq);
491 
563  uint32_t numBytes, const SequenceNumber32 &requestedSeq,
564  bool *listEdited = nullptr) const;
565 
576  void MergeItems (TcpTxItem *t1, TcpTxItem *t2) const;
577 
588  void SplitItems (TcpTxItem *t1, TcpTxItem *t2, uint32_t size) const;
589 
594  void ConsistencyCheck () const;
595 
600  std::pair <TcpTxBuffer::PacketList::const_iterator, SequenceNumber32>
601  FindHighestSacked () const;
602 
605  uint32_t m_maxBuffer;
606  uint32_t m_size;
607  uint32_t m_sentSize;
609 
611  std::pair <PacketList::const_iterator, SequenceNumber32> m_highestSack;
612 
613  uint32_t m_lostOut {0};
614  uint32_t m_sackedOut {0};
615  uint32_t m_retrans {0};
616 
617  uint32_t m_dupAckThresh {0};
618  uint32_t m_segmentSize {0};
619  bool m_renoSack {false};
620  bool m_sackEnabled {true};
621 
623 };
624 
631 std::ostream & operator<< (std::ostream & os, TcpTxBuffer const & tcpTxBuf);
632 
639 std::ostream & operator<< (std::ostream & os, TcpTxItem const & item);
640 
641 } // namespace ns3
642 
643 #endif /* TCP_TX_BUFFER_H */
ns3::TcpTxBuffer::m_dupAckThresh
uint32_t m_dupAckThresh
Duplicate Ack threshold from TcpSocketBase.
Definition: tcp-tx-buffer.h:617
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::TcpTxBuffer::SizeFromSequence
uint32_t SizeFromSequence(const SequenceNumber32 &seq) const
Returns the number of bytes from the buffer in the range [seq, tailSequence)
Definition: tcp-tx-buffer.cc:204
ns3::TcpTxBuffer::SetSentListLost
void SetSentListLost(bool resetSack=false)
Set the entire sent list as lost (typically after an RTO)
Definition: tcp-tx-buffer.cc:1279
ns3::TcpTxBuffer::SetSegmentSize
void SetSegmentSize(uint32_t segmentSize)
Set the segment size.
Definition: tcp-tx-buffer.cc:140
ns3::TcpTxBuffer::ResetSentList
void ResetSentList()
Reset the sent list.
Definition: tcp-tx-buffer.cc:1238
ns3::TcpTxBuffer::Size
uint32_t Size(void) const
Returns total number of bytes in this buffer.
Definition: tcp-tx-buffer.cc:98
ns3::TcpTxBuffer::UpdateLostCount
void UpdateLostCount()
Update the lost count.
Definition: tcp-tx-buffer.cc:880
ns3::TcpTxBuffer::SetSackEnabled
void SetSackEnabled(bool enabled)
tell tx-buffer whether SACK is used on this TCP socket
Definition: tcp-tx-buffer.cc:122
ns3::Callback
Callback template class.
Definition: callback.h:1279
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TcpTxBuffer::m_sentSize
uint32_t m_sentSize
Size of sent (and not discarded) segments.
Definition: tcp-tx-buffer.h:607
ns3::TcpTxBuffer::TcpTxBuffer
TcpTxBuffer(uint32_t n=0)
Constructor.
Definition: tcp-tx-buffer.cc:60
ns3::TcpTxBuffer::MergeItems
void MergeItems(TcpTxItem *t1, TcpTxItem *t2) const
Merge two TcpTxItem.
Definition: tcp-tx-buffer.cc:586
ns3::TcpTxBuffer::PacketList
std::list< TcpTxItem * > PacketList
container for data stored in the buffer
Definition: tcp-tx-buffer.h:413
ns3::TcpTxBuffer::MarkHeadAsLost
void MarkHeadAsLost()
Mark the head of the sent list as lost.
Definition: tcp-tx-buffer.cc:1357
ns3::TcpTxBuffer::ConsistencyCheck
void ConsistencyCheck() const
Check if the values of sacked, lost, retrans, are in sync with the sent list.
Definition: tcp-tx-buffer.cc:1428
ns3::TcpTxBuffer::GetLost
uint32_t GetLost(void) const
Get the number of segments that we believe are lost in the network.
Definition: tcp-tx-buffer.cc:152
ns3::TcpTxBuffer::m_sentList
PacketList m_sentList
Buffer for sent (but not acked) data.
Definition: tcp-tx-buffer.h:604
ns3::TcpTxBuffer
Tcp sender buffer.
Definition: tcp-tx-buffer.h:123
ns3::TcpTxBuffer::DiscardUpTo
void DiscardUpTo(const SequenceNumber32 &seq, const Callback< void, TcpTxItem * > &beforeDelCb=m_nullCb)
Discard data up to but not including this sequence number.
Definition: tcp-tx-buffer.cc:666
ns3::TcpTxBuffer::Available
uint32_t Available(void) const
Returns the available capacity of this buffer.
Definition: tcp-tx-buffer.cc:128
ns3::TcpTxBuffer::m_segmentSize
uint32_t m_segmentSize
Segment size from TcpSocketBase.
Definition: tcp-tx-buffer.h:618
ns3::TcpTxBuffer::AddRenoSack
void AddRenoSack()
Emulate SACKs for SACKless connection: account for a new dupack.
Definition: tcp-tx-buffer.cc:1386
ns3::Ptr< Packet >
ns3::TcpTxBuffer::~TcpTxBuffer
virtual ~TcpTxBuffer(void)
Definition: tcp-tx-buffer.cc:66
ns3::TcpTxBuffer::IsSackEnabled
bool IsSackEnabled(void) const
check whether SACK is used on the corresponding TCP socket
Definition: tcp-tx-buffer.cc:116
ns3::TcpTxBuffer::m_renoSack
bool m_renoSack
Indicates if AddRenoSack was called.
Definition: tcp-tx-buffer.h:619
ns3::TcpTxBuffer::SplitItems
void SplitItems(TcpTxItem *t1, TcpTxItem *t2, uint32_t size) const
Split one TcpTxItem.
Definition: tcp-tx-buffer.cc:381
ns3::TcpTxBuffer::SetMaxBufferSize
void SetMaxBufferSize(uint32_t n)
Set the maximum buffer size.
Definition: tcp-tx-buffer.cc:110
ns3::TcpTxBuffer::MaxBufferSize
uint32_t MaxBufferSize(void) const
Get the maximum buffer size.
Definition: tcp-tx-buffer.cc:104
ns3::TcpTxBuffer::m_lostOut
uint32_t m_lostOut
Number of lost bytes.
Definition: tcp-tx-buffer.h:613
ns3::TcpTxBuffer::GetSacked
uint32_t GetSacked(void) const
Get the number of segments that have been explicitly sacked by the receiver.
Definition: tcp-tx-buffer.cc:158
ns3::Object
A base class which provides memory management and object aggregation.
Definition: object.h:88
ns3::TcpTxBuffer::operator<<
friend std::ostream & operator<<(std::ostream &os, TcpTxBuffer const &tcpTxBuf)
Output operator.
Definition: tcp-tx-buffer.cc:1473
ns3::TcpTxBuffer::m_nullCb
static Callback< void, TcpTxItem * > m_nullCb
Null callback for an item.
Definition: tcp-tx-buffer.h:622
ns3::TcpTxBuffer::BytesInFlightRFC
uint32_t BytesInFlightRFC() const
Calculate the number of bytes in flight per RFC 6675.
Definition: tcp-tx-buffer.cc:1096
ns3::TcpTxBuffer::m_maxBuffer
uint32_t m_maxBuffer
Max number of data bytes in buffer (SND.WND)
Definition: tcp-tx-buffer.h:605
ns3::TcpTxBuffer::TailSequence
SequenceNumber32 TailSequence(void) const
Get the sequence number of the buffer tail (plus one)
Definition: tcp-tx-buffer.cc:92
ns3::TcpTxBuffer::m_size
uint32_t m_size
Size of all data in this buffer.
Definition: tcp-tx-buffer.h:606
ns3::TcpTxBuffer::GetNewSegment
TcpTxItem * GetNewSegment(uint32_t numBytes)
Get a block of data not transmitted yet and move it into SentList.
Definition: tcp-tx-buffer.cc:281
ns3::TcpTxBuffer::IsHeadRetransmitted
bool IsHeadRetransmitted() const
Check if the head is retransmitted.
Definition: tcp-tx-buffer.cc:1326
list
#define list
Definition: openflow-interface.h:47
ns3::TcpTxBuffer::m_highestSack
std::pair< PacketList::const_iterator, SequenceNumber32 > m_highestSack
Highest SACK byte.
Definition: tcp-tx-buffer.h:611
ns3::TcpTxBuffer::ResetLastSegmentSent
void ResetLastSegmentSent()
Take the last segment sent and put it back into the un-sent list (at the beginning)
Definition: tcp-tx-buffer.cc:1260
ns3::TcpTxBuffer::GetPacketFromList
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.
Definition: tcp-tx-buffer.cc:401
ns3::TcpTxBuffer::IsLost
bool IsLost(const SequenceNumber32 &seq) const
Check if a segment is lost.
Definition: tcp-tx-buffer.cc:929
ns3::TcpTxBuffer::Update
uint32_t Update(const TcpOptionSack::SackList &list, const Callback< void, TcpTxItem * > &sackedCb=m_nullCb)
Update the scoreboard.
Definition: tcp-tx-buffer.cc:784
ns3::TcpTxItem
Item that encloses the application packet and some flags for it.
Definition: tcp-tx-item.h:33
ns3::TcpTxBuffer::ResetRenoSack
void ResetRenoSack()
Reset the SACKs.
Definition: tcp-tx-buffer.cc:1217
ns3::TcpTxBuffer::CopyFromSequence
TcpTxItem * CopyFromSequence(uint32_t numBytes, const SequenceNumber32 &seq)
Copy data from the range [seq, seq+numBytes) into a packet.
Definition: tcp-tx-buffer.cc:221
ns3::TracedValue< SequenceNumber32 >
ns3::TcpTxBuffer::SetRWndCallback
void SetRWndCallback(Callback< uint32_t > rWndCallback)
Set callback to obtain receiver window value.
Definition: tcp-tx-buffer.cc:1231
ns3::TcpTxBuffer::SetDupAckThresh
void SetDupAckThresh(uint32_t dupAckThresh)
Set the DupAckThresh.
Definition: tcp-tx-buffer.cc:134
ns3::TcpTxBuffer::GetTransmittedSegment
TcpTxItem * GetTransmittedSegment(uint32_t numBytes, const SequenceNumber32 &seq)
Get a block of data previously transmitted.
Definition: tcp-tx-buffer.cc:306
ns3::TcpTxBuffer::m_rWndCallback
Callback< uint32_t > m_rWndCallback
Callback to obtain RCV.WND value.
Definition: tcp-tx-buffer.h:608
segmentSize
uint32_t segmentSize
Definition: tcp-linux-reno.cc:53
ns3::TcpTxBuffer::IsLostRFC
bool IsLostRFC(const SequenceNumber32 &seq, const PacketList::const_iterator &segment) const
Decide if a segment is lost based on RFC 6675 algorithm.
Definition: tcp-tx-buffer.cc:1160
ns3::TcpTxBuffer::FindHighestSacked
std::pair< TcpTxBuffer::PacketList::const_iterator, SequenceNumber32 > FindHighestSacked() const
Find the highest SACK byte.
Definition: tcp-tx-buffer.cc:358
ns3::TcpTxBuffer::IsRetransmittedDataAcked
bool IsRetransmittedDataAcked(const SequenceNumber32 &ack) const
Checks whether the ack corresponds to retransmitted data.
Definition: tcp-tx-buffer.cc:650
ns3::TcpTxBuffer::GetRetransmitsCount
uint32_t GetRetransmitsCount(void) const
Return the number of segments in the sent list that have been transmitted more than once,...
Definition: tcp-tx-buffer.cc:146
ns3::TcpTxBuffer::m_appList
PacketList m_appList
Buffer for application data.
Definition: tcp-tx-buffer.h:603
ns3::TcpTxBuffer::Add
bool Add(Ptr< Packet > p)
Append a data packet to the end of the buffer.
Definition: tcp-tx-buffer.cc:180
ns3::TcpTxBuffer::m_firstByteSeq
TracedValue< SequenceNumber32 > m_firstByteSeq
Sequence number of the first byte in data (SND.UNA)
Definition: tcp-tx-buffer.h:610
ns3::TcpTxBuffer::DeleteRetransmittedFlagFromHead
void DeleteRetransmittedFlagFromHead()
DeleteRetransmittedFlagFromHead.
Definition: tcp-tx-buffer.cc:1339
ns3::TcpTxBuffer::BytesInFlight
uint32_t BytesInFlight() const
Return total bytes in flight.
Definition: tcp-tx-buffer.cc:1074
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137
ns3::TcpTxBuffer::NextSeg
bool NextSeg(SequenceNumber32 *seq, SequenceNumber32 *seqHigh, bool isRecovery) const
Get the next sequence number to transmit, according to RFC 6675.
Definition: tcp-tx-buffer.cc:968
ns3::SequenceNumber< uint32_t, int32_t >
ns3::TcpTxBuffer::SetHeadSequence
void SetHeadSequence(const SequenceNumber32 &seq)
Set the head sequence of the buffer.
Definition: tcp-tx-buffer.cc:164
ns3::TcpTxBuffer::m_sackedOut
uint32_t m_sackedOut
Number of sacked bytes.
Definition: tcp-tx-buffer.h:614
ns3::TcpTxBuffer::RemoveFromCounts
void RemoveFromCounts(TcpTxItem *item, uint32_t size)
Remove the size specified from the lostOut, retrans, sacked count.
Definition: tcp-tx-buffer.cc:628
ns3::TcpTxBuffer::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-tx-buffer.cc:39
ns3::TcpTxBuffer::HeadSequence
SequenceNumber32 HeadSequence(void) const
Get the sequence number of the buffer head.
Definition: tcp-tx-buffer.cc:86
sample-rng-plot.n
n
Definition: sample-rng-plot.py:37
ns3::TcpOptionSack::SackList
std::list< SackBlock > SackList
SACK list definition.
Definition: tcp-option-sack.h:60
ns3::TcpTxBuffer::m_retrans
uint32_t m_retrans
Number of retransmitted bytes.
Definition: tcp-tx-buffer.h:615
ns3::TcpTxBuffer::m_sackEnabled
bool m_sackEnabled
Indicates if SACK is enabled on this connection.
Definition: tcp-tx-buffer.h:620