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 
31 namespace ns3 {
32 class Packet;
33 
39 class TcpTxItem
40 {
41 public:
45  TcpTxItem ();
46 
51  TcpTxItem (const TcpTxItem &other);
52 
57  void Print (std::ostream &os) const;
58 
60  bool m_lost;
61  bool m_retrans;
63  // been sent last time
64  bool m_sacked;
65 };
66 
126 class TcpTxBuffer : public Object
127 {
128 public:
133  static TypeId GetTypeId (void);
138  TcpTxBuffer (uint32_t n = 0);
139  virtual ~TcpTxBuffer (void);
140 
141  // Accessors
142 
147  SequenceNumber32 HeadSequence (void) const;
148 
153  SequenceNumber32 TailSequence (void) const;
154 
159  uint32_t Size (void) const;
160 
165  uint32_t MaxBufferSize (void) const;
166 
171  void SetMaxBufferSize (uint32_t n);
172 
177  uint32_t Available (void) const;
178 
185  bool Add (Ptr<Packet> p);
186 
193  uint32_t SizeFromSequence (const SequenceNumber32& seq) const;
194 
214  Ptr<Packet> CopyFromSequence (uint32_t numBytes, const SequenceNumber32& seq);
215 
223  void SetHeadSequence (const SequenceNumber32& seq);
224 
231  void DiscardUpTo (const SequenceNumber32& seq);
232 
238  bool Update (const TcpOptionSack::SackList &list);
239 
247  bool IsLost (const SequenceNumber32 &seq, uint32_t dupThresh, uint32_t segmentSize) const;
248 
258  bool NextSeg (SequenceNumber32 *seq, uint32_t dupThresh, uint32_t segmentSize,
259  bool isRecovery) const;
260 
270  uint32_t GetRetransmitsCount (void) const;
271 
282  uint32_t BytesInFlight (uint32_t dupThresh, uint32_t segmentSize) const;
283 
291  void SetSentListLost ();
292 
296  void ResetScoreboard ();
297 
304  bool IsHeadRetransmitted () const;
305 
316  void ResetSentList (uint32_t keepItems = 1);
317 
322  void ResetLastSegmentSent ();
323 
333  Ptr<const TcpOptionSack> CraftSackOption (const SequenceNumber32 &seq, uint8_t available) const;
334 
335 private:
336  friend std::ostream & operator<< (std::ostream & os, TcpTxBuffer const & tcpTxBuf);
337 
338  typedef std::list<TcpTxItem*> PacketList;
339 
348  bool IsLost (const SequenceNumber32 &seq, const PacketList::const_iterator &segment, uint32_t dupThresh,
349  uint32_t segmentSize) const;
350 
365  TcpTxItem* GetNewSegment (uint32_t numBytes);
366 
381  TcpTxItem* GetTransmittedSegment (uint32_t numBytes, const SequenceNumber32 &seq);
382 
453  TcpTxItem* GetPacketFromList (PacketList &list, const SequenceNumber32 &startingSeq,
454  uint32_t numBytes, const SequenceNumber32 &requestedSeq,
455  bool *listEdited) const;
456 
467  void MergeItems (TcpTxItem &t1, TcpTxItem &t2) const;
468 
478  void SplitItems (TcpTxItem &t1, TcpTxItem &t2, uint32_t size) const;
479 
484  std::pair <TcpTxBuffer::PacketList::const_iterator, SequenceNumber32>
485  GetHighestSacked () const;
486 
487  PacketList m_appList;
488  PacketList m_sentList;
489  uint32_t m_maxBuffer;
490  uint32_t m_size;
491  uint32_t m_sentSize;
492 
494 
495  std::pair <PacketList::const_iterator, SequenceNumber32> m_highestSack;
496 
497 };
498 
505 std::ostream & operator<< (std::ostream & os, TcpTxBuffer const & tcpTxBuf);
506 
507 } // namepsace ns3
508 
509 #endif /* TCP_TX_BUFFER_H */
TcpTxItem()
Constructor.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
bool m_retrans
Indicates if the segment is retransmitted.
Definition: tcp-tx-buffer.h:61
uint32_t Size(void) const
Returns total number of bytes in this buffer.
void ResetSentList(uint32_t keepItems=1)
Reset the sent list.
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 SizeFromSequence(const SequenceNumber32 &seq) const
Returns the number of bytes from the buffer in the range [seq, tailSequence)
void ResetLastSegmentSent()
Take the last segment sent and put it back into the un-sent list (at the beginning) ...
bool IsLost(const SequenceNumber32 &seq, uint32_t dupThresh, uint32_t segmentSize) const
Check if a segment is lost per RFC 6675.
SequenceNumber32 HeadSequence(void) const
Get the sequence number of the buffer head.
PacketList m_appList
Buffer for application data.
std::list< SackBlock > SackList
SACK list definition.
uint32_t MaxBufferSize(void) const
Get the maximum buffer size.
Item that encloses the application packet and some flags for it.
Definition: tcp-tx-buffer.h:39
uint32_t GetRetransmitsCount(void) const
Return the number of segments in the sent list that have been transmitted more than once...
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.
Definition: tcp-tx-buffer.h:62
uint32_t BytesInFlight(uint32_t dupThresh, uint32_t segmentSize) const
Return total bytes in flight.
uint32_t m_sentSize
Size of sent (and not discarded) segments.
void SetSentListLost()
Set the entire sent list as lost (typically after an RTO)
std::list< TcpTxItem * > PacketList
container for data stored in the buffer
uint32_t m_size
Size of all data in this buffer.
Tcp sender buffer.
void SetMaxBufferSize(uint32_t n)
Set the maximum buffer size.
#define list
std::pair< PacketList::const_iterator, SequenceNumber32 > m_highestSack
Highest SACK byte.
uint32_t Available(void) const
Returns the available capacity of this buffer.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
Ptr< Packet > m_packet
Application packet.
Definition: tcp-tx-buffer.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Generic "sequence number" class.
bool NextSeg(SequenceNumber32 *seq, uint32_t dupThresh, uint32_t segmentSize, bool isRecovery) const
Get the next sequence number to transmit, according to RFC 6675.
bool Add(Ptr< Packet > p)
Append a data packet to the end of the buffer.
static TypeId GetTypeId(void)
Get the type ID.
void SplitItems(TcpTxItem &t1, TcpTxItem &t2, uint32_t size) const
Split one TcpTxItem.
bool Update(const TcpOptionSack::SackList &list)
Update the scoreboard.
bool IsHeadRetransmitted() const
Check if the head is retransmitted.
friend std::ostream & operator<<(std::ostream &os, TcpTxBuffer const &tcpTxBuf)
Output operator.
PacketList m_sentList
Buffer for sent (but not acked) data.
uint32_t m_maxBuffer
Max number of data bytes in buffer (SND.WND)
void ResetScoreboard()
Reset the Scoreboard from all SACK informations.
TcpTxItem * GetNewSegment(uint32_t numBytes)
Get a block of data not transmitted yet and move it into SentList.
TcpTxItem * GetPacketFromList(PacketList &list, const SequenceNumber32 &startingSeq, uint32_t numBytes, const SequenceNumber32 &requestedSeq, bool *listEdited) const
Get a block (which is returned as Packet) from a list.
Ptr< const TcpOptionSack > CraftSackOption(const SequenceNumber32 &seq, uint8_t available) const
Craft a SACK block.
A base class which provides memory management and object aggregation.
Definition: object.h:87
TcpTxBuffer(uint32_t n=0)
Constructor.
virtual ~TcpTxBuffer(void)
void MergeItems(TcpTxItem &t1, TcpTxItem &t2) const
Merge two TcpTxItem.
void Print(std::ostream &os) const
Print the time.
bool m_sacked
Indicates if the segment has been SACKed.
Definition: tcp-tx-buffer.h:64
a unique identifier for an interface.
Definition: type-id.h:58
bool m_lost
Indicates if the segment has been lost (RTO)
Definition: tcp-tx-buffer.h:60
SequenceNumber32 TailSequence(void) const
Get the sequence number of the buffer tail (plus one)
std::pair< TcpTxBuffer::PacketList::const_iterator, SequenceNumber32 > GetHighestSacked() const
Find the highest SACK byte.
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.