A Discrete-Event Network Simulator
API
tcp-tx-buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2015 Adrian Sai-wah Tam
3  * Copyright (c) 2016 Natale Patriciello <natale.patriciello@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Original author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
19  */
20 
21 #ifndef TCP_TX_BUFFER_H
22 #define TCP_TX_BUFFER_H
23 
24 #include "ns3/object.h"
25 #include "ns3/sequence-number.h"
26 #include "ns3/tcp-option-sack.h"
27 #include "ns3/tcp-tx-item.h"
28 #include "ns3/traced-value.h"
29 
30 namespace ns3
31 {
32 class Packet;
33 
122 class TcpTxBuffer : public Object
123 {
124  public:
129  static TypeId GetTypeId();
134  TcpTxBuffer(uint32_t n = 0);
135  ~TcpTxBuffer() override;
136 
137  // Accessors
138 
144 
150 
155  uint32_t Size() const;
156 
161  uint32_t MaxBufferSize() const;
162 
167  void SetMaxBufferSize(uint32_t n);
168 
173  bool IsSackEnabled() const;
174 
180  void SetSackEnabled(bool enabled);
181 
186  uint32_t Available() const;
187 
192  void SetDupAckThresh(uint32_t dupAckThresh);
193 
198  void SetSegmentSize(uint32_t segmentSize);
199 
209  uint32_t GetRetransmitsCount() const;
210 
217  uint32_t GetLost() const;
218 
223  uint32_t GetSacked() 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, const TcpTxBuffer& 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  const SequenceNumber32& startingSeq,
564  uint32_t numBytes,
565  const SequenceNumber32& requestedSeq,
566  bool* listEdited = nullptr) const;
567 
578  void MergeItems(TcpTxItem* t1, TcpTxItem* t2) const;
579 
590  void SplitItems(TcpTxItem* t1, TcpTxItem* t2, uint32_t size) const;
591 
596  void ConsistencyCheck() const;
597 
602  std::pair<TcpTxBuffer::PacketList::const_iterator, SequenceNumber32> FindHighestSacked() const;
603 
606  uint32_t m_maxBuffer;
607  uint32_t m_size;
608  uint32_t m_sentSize;
610 
613  std::pair<PacketList::const_iterator, SequenceNumber32> m_highestSack;
614 
615  uint32_t m_lostOut{0};
616  uint32_t m_sackedOut{0};
617  uint32_t m_retrans{0};
618 
619  uint32_t m_dupAckThresh{0};
620  uint32_t m_segmentSize{0};
621  bool m_renoSack{false};
622  bool m_sackEnabled{true};
623 
625 };
626 
633 std::ostream& operator<<(std::ostream& os, const TcpTxBuffer& tcpTxBuf);
634 
641 std::ostream& operator<<(std::ostream& os, const TcpTxItem& item);
642 
643 } // namespace ns3
644 
645 #endif /* TCP_TX_BUFFER_H */
Callback template class.
Definition: callback.h:443
A base class which provides memory management and object aggregation.
Definition: object.h:89
std::list< SackBlock > SackList
SACK list definition.
Tcp sender buffer.
uint32_t m_retrans
Number of retransmitted bytes.
void ResetRenoSack()
Reset the SACKs.
void ConsistencyCheck() const
Check if the values of sacked, lost, retrans, are in sync with the sent list.
bool m_sackEnabled
Indicates if SACK is enabled on this connection.
uint32_t m_lostOut
Number of lost bytes.
bool IsLostRFC(const SequenceNumber32 &seq, const PacketList::const_iterator &segment) const
Decide if a segment is lost based on RFC 6675 algorithm.
std::pair< TcpTxBuffer::PacketList::const_iterator, SequenceNumber32 > FindHighestSacked() const
Find the highest SACK byte.
SequenceNumber32 HeadSequence() const
Get the sequence number of the buffer head.
std::pair< PacketList::const_iterator, SequenceNumber32 > m_highestSack
Highest SACK byte.
bool IsHeadRetransmitted() const
Check if the head is retransmitted.
bool Add(Ptr< Packet > p)
Append a data packet to the end of the buffer.
void SetSegmentSize(uint32_t segmentSize)
Set the segment size.
uint32_t GetRetransmitsCount() const
Return the number of segments in the sent list that have been transmitted more than once,...
bool IsRetransmittedDataAcked(const SequenceNumber32 &ack) const
Checks whether the ack corresponds to retransmitted data.
static TypeId GetTypeId()
Get the type ID.
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.
uint32_t SizeFromSequence(const SequenceNumber32 &seq) const
Returns the number of bytes from the buffer in the range [seq, tailSequence)
friend std::ostream & operator<<(std::ostream &os, const TcpTxBuffer &tcpTxBuf)
Output operator.
TracedValue< SequenceNumber32 > m_firstByteSeq
Sequence number of the first byte in data (SND.UNA)
std::list< TcpTxItem * > PacketList
container for data stored in the buffer
uint32_t MaxBufferSize() const
Get the maximum buffer size.
TcpTxItem * GetTransmittedSegment(uint32_t numBytes, const SequenceNumber32 &seq)
Get a block of data previously transmitted.
uint32_t m_maxBuffer
Max number of data bytes in buffer (SND.WND)
bool m_renoSack
Indicates if AddRenoSack was called.
uint32_t m_dupAckThresh
Duplicate Ack threshold from TcpSocketBase.
uint32_t Size() const
Returns total number of bytes in this buffer.
void SetSackEnabled(bool enabled)
tell tx-buffer whether SACK is used on this TCP socket
static Callback< void, TcpTxItem * > m_nullCb
Null callback for an item.
uint32_t m_sackedOut
Number of sacked bytes.
void ResetLastSegmentSent()
Take the last segment sent and put it back into the un-sent list (at the beginning)
bool IsLost(const SequenceNumber32 &seq) const
Check if a segment is lost.
bool NextSeg(SequenceNumber32 *seq, SequenceNumber32 *seqHigh, bool isRecovery) const
Get the next sequence number to transmit, according to RFC 6675.
void SetDupAckThresh(uint32_t dupAckThresh)
Set the DupAckThresh.
TcpTxItem * CopyFromSequence(uint32_t numBytes, const SequenceNumber32 &seq)
Copy data from the range [seq, seq+numBytes) into a packet.
bool IsSackEnabled() const
check whether SACK is used on the corresponding TCP socket
TcpTxItem * GetNewSegment(uint32_t numBytes)
Get a block of data not transmitted yet and move it into SentList.
uint32_t Available() const
Returns the available capacity of this buffer.
uint32_t m_segmentSize
Segment size from TcpSocketBase.
uint32_t Update(const TcpOptionSack::SackList &list, const Callback< void, TcpTxItem * > &sackedCb=m_nullCb)
Update the scoreboard.
uint32_t GetLost() const
Get the number of segments that we believe are lost in the network.
void AddRenoSack()
Emulate SACKs for SACKless connection: account for a new dupack.
void MarkHeadAsLost()
Mark the head of the sent list as lost.
void UpdateLostCount()
Update the lost count.
SequenceNumber32 TailSequence() const
Get the sequence number of the buffer tail (plus one)
Callback< uint32_t > m_rWndCallback
Callback to obtain RCV.WND value.
void SetRWndCallback(Callback< uint32_t > rWndCallback)
Set callback to obtain receiver window value.
uint32_t BytesInFlight() const
Return total bytes in flight.
void SetSentListLost(bool resetSack=false)
Set the entire sent list as lost (typically after an RTO)
void SplitItems(TcpTxItem *t1, TcpTxItem *t2, uint32_t size) const
Split one TcpTxItem.
void DiscardUpTo(const SequenceNumber32 &seq, const Callback< void, TcpTxItem * > &beforeDelCb=m_nullCb)
Discard data up to but not including this sequence number.
uint32_t BytesInFlightRFC() const
Calculate the number of bytes in flight per RFC 6675.
~TcpTxBuffer() override
PacketList m_appList
Buffer for application data.
uint32_t GetSacked() const
Get the number of segments that have been explicitly sacked by the receiver.
void MergeItems(TcpTxItem *t1, TcpTxItem *t2) const
Merge two TcpTxItem.
uint32_t m_size
Size of all data in this buffer.
void ResetSentList()
Reset the sent list.
void DeleteRetransmittedFlagFromHead()
DeleteRetransmittedFlagFromHead.
void SetMaxBufferSize(uint32_t n)
Set the maximum buffer size.
PacketList m_sentList
Buffer for sent (but not acked) data.
uint32_t m_sentSize
Size of sent (and not discarded) segments.
void RemoveFromCounts(TcpTxItem *item, uint32_t size)
Remove the size specified from the lostOut, retrans, sacked count.
void SetHeadSequence(const SequenceNumber32 &seq)
Set the head sequence of the buffer.
TcpTxBuffer(uint32_t n=0)
Constructor.
Item that encloses the application packet and some flags for it.
Definition: tcp-tx-item.h:33
a unique identifier for an interface.
Definition: type-id.h:60
uint32_t segmentSize
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:129
#define list