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/nstime.h"
29 #include "ns3/tcp-option-sack.h"
30 #include "ns3/packet.h"
31 
32 namespace ns3 {
33 class Packet;
34 
40 class TcpTxItem
41 {
42 public:
43  // Default constructor, copy-constructor, destructor
44 
49  void Print (std::ostream &os) const;
50 
56  uint32_t GetSeqSize (void) const { return m_packet && m_packet->GetSize () > 0 ? m_packet->GetSize () : 1; }
57 
59  Ptr<Packet> m_packet {nullptr};
60  bool m_lost {false};
61  bool m_retrans {false};
63  bool m_sacked {false};
64 };
65 
154 class TcpTxBuffer : public Object
155 {
156 public:
161  static TypeId GetTypeId (void);
166  TcpTxBuffer (uint32_t n = 0);
167  virtual ~TcpTxBuffer (void);
168 
169  // Accessors
170 
175  SequenceNumber32 HeadSequence (void) const;
176 
181  SequenceNumber32 TailSequence (void) const;
182 
187  uint32_t Size (void) const;
188 
193  uint32_t MaxBufferSize (void) const;
194 
199  void SetMaxBufferSize (uint32_t n);
200 
205  uint32_t Available (void) const;
206 
211  void SetDupAckThresh (uint32_t dupAckThresh) { m_dupAckThresh = dupAckThresh; }
212 
217  void SetSegmentSize (uint32_t segmentSize) { m_segmentSize = segmentSize; }
218 
228  uint32_t GetRetransmitsCount (void) const { return m_retrans; }
229 
236  uint32_t GetLost (void) const { return m_lostOut; }
237 
242  uint32_t GetSacked (void) const { return m_sackedOut; }
243 
250  bool Add (Ptr<Packet> p);
251 
258  uint32_t SizeFromSequence (const SequenceNumber32& seq) const;
259 
279  Ptr<Packet> CopyFromSequence (uint32_t numBytes, const SequenceNumber32& seq);
280 
288  void SetHeadSequence (const SequenceNumber32& seq);
289 
296  void DiscardUpTo (const SequenceNumber32& seq);
297 
303  bool Update (const TcpOptionSack::SackList &list);
304 
316  bool IsLost (const SequenceNumber32 &seq) const;
317 
325  bool NextSeg (SequenceNumber32 *seq, bool isRecovery) const;
326 
343  uint32_t BytesInFlight () const;
344 
355  void SetSentListLost (bool resetSack = false);
356 
363  bool IsHeadRetransmitted () const;
364 
369 
374  void ResetSentList ();
375 
380  void ResetLastSegmentSent ();
381 
385  void MarkHeadAsLost ();
386 
399  void AddRenoSack ();
400 
407  void ResetRenoSack ();
408 
409 private:
410  friend std::ostream & operator<< (std::ostream & os, TcpTxBuffer const & tcpTxBuf);
411 
412  typedef std::list<TcpTxItem*> PacketList;
413 
433  void UpdateLostCount ();
434 
443  void RemoveFromCounts (TcpTxItem *item, uint32_t size);
444 
451  bool IsLostRFC (const SequenceNumber32 &seq, const PacketList::const_iterator &segment) const;
452 
457  uint32_t BytesInFlightRFC () const;
458 
473  TcpTxItem* GetNewSegment (uint32_t numBytes);
474 
489  TcpTxItem* GetTransmittedSegment (uint32_t numBytes, const SequenceNumber32 &seq);
490 
562  uint32_t numBytes, const SequenceNumber32 &requestedSeq,
563  bool *listEdited = nullptr) const;
564 
575  void MergeItems (TcpTxItem *t1, TcpTxItem *t2) const;
576 
587  void SplitItems (TcpTxItem *t1, TcpTxItem *t2, uint32_t size) const;
588 
593  void ConsistencyCheck () const;
594 
599  std::pair <TcpTxBuffer::PacketList::const_iterator, SequenceNumber32>
600  FindHighestSacked () const;
601 
604  uint32_t m_maxBuffer;
605  uint32_t m_size;
606  uint32_t m_sentSize;
607 
609  std::pair <PacketList::const_iterator, SequenceNumber32> m_highestSack;
610 
611  uint32_t m_lostOut {0};
612  uint32_t m_sackedOut {0};
613  uint32_t m_retrans {0};
614 
615  uint32_t m_dupAckThresh {0};
616  uint32_t m_segmentSize {0};
617  bool m_renoSack {false};
618 
619 };
620 
627 std::ostream & operator<< (std::ostream & os, TcpTxBuffer const & tcpTxBuf);
628 
635 std::ostream & operator<< (std::ostream & os, TcpTxItem const & item);
636 
637 } // namespace ns3
638 
639 #endif /* TCP_TX_BUFFER_H */
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void AddRenoSack()
Emulate SACKs for SACKless connection: account for a new dupack.
bool m_retrans
Indicates if the segment is retransmitted.
Definition: tcp-tx-buffer.h:61
uint32_t m_retrans
Number of retransmitted bytes.
TcpTxItem * GetTransmittedSegment(uint32_t numBytes, const SequenceNumber32 &seq)
Get a block of data previously transmitted.
void DiscardUpTo(const SequenceNumber32 &seq)
Discard data up to but not including this sequence number.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
static Time Min()
Minimum representable Time.
Definition: nstime.h:268
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 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...
void DeleteRetransmittedFlagFromHead()
DeleteRetransmittedFlagFromHead.
void RemoveFromCounts(TcpTxItem *item, uint32_t size)
Remove the size specified from the lostOut, retrans, sacked count.
uint32_t GetSeqSize(void) const
Get the size in the sequence number space.
Definition: tcp-tx-buffer.h:56
void UpdateLostCount()
Update the lost count.
Item that encloses the application packet and some flags for it.
Definition: tcp-tx-buffer.h:40
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.
Definition: tcp-tx-buffer.h:62
SequenceNumber32 m_startSeq
Sequence number of the item (if transmitted)
Definition: tcp-tx-buffer.h:58
uint32_t m_sentSize
Size of sent (and not discarded) segments.
std::list< TcpTxItem * > PacketList
container for data stored in the buffer
void MergeItems(TcpTxItem *t1, TcpTxItem *t2) const
Merge two TcpTxItem.
uint32_t m_size
Size of all data in this buffer.
Tcp sender buffer.
bool NextSeg(SequenceNumber32 *seq, bool isRecovery) const
Get the next sequence number to transmit, according to RFC 6675.
void ConsistencyCheck() const
Check if the values of sacked, lost, retrans, are in sync with the sent list.
void SetMaxBufferSize(uint32_t n)
Set the maximum buffer size.
#define list
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
Definition: angles.cc:42
void ResetSentList()
Reset the sent list.
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)
Definition: tcp-tx-buffer.h:59
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)
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.
void SetDupAckThresh(uint32_t dupAckThresh)
Set the DupAckThresh.
SequenceNumber32 HeadSequence(void) const
Get the sequence number of the buffer head.
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.
bool Update(const TcpOptionSack::SackList &list)
Update the scoreboard.
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.
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.
bool IsLost(const SequenceNumber32 &seq) const
Check if a segment is lost.
friend std::ostream & operator<<(std::ostream &os, TcpTxBuffer const &tcpTxBuf)
Output operator.
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 m_maxBuffer
Max number of data bytes in buffer (SND.WND)
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.
uint32_t m_segmentSize
Segment size from TcpSocketBase.
A base class which provides memory management and object aggregation.
Definition: object.h:87
bool IsHeadRetransmitted() const
Check if the head is retransmitted.
TcpTxBuffer(uint32_t n=0)
Constructor.
virtual ~TcpTxBuffer(void)
bool m_renoSack
Indicates if AddRenoSack was called.
bool m_sacked
Indicates if the segment has been SACKed.
Definition: tcp-tx-buffer.h:63
a unique identifier for an interface.
Definition: type-id.h:58
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)
Definition: tcp-tx-buffer.h:60
uint32_t BytesInFlight() const
Return total bytes in flight.
void SetHeadSequence(const SequenceNumber32 &seq)
Set the head sequence of the buffer.
Ptr< Packet > CopyFromSequence(uint32_t numBytes, const SequenceNumber32 &seq)
Copy data from the range [seq, seq+numBytes) into a packet.