A Discrete-Event Network Simulator
API
tcp-rx-buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Adrian Sai-wah Tam
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
18  */
19 
20 #ifndef TCP_RX_BUFFER_H
21 #define TCP_RX_BUFFER_H
22 
23 #include "tcp-header.h"
24 #include "tcp-option-sack.h"
25 
26 #include "ns3/ptr.h"
27 #include "ns3/sequence-number.h"
28 #include "ns3/trace-source-accessor.h"
29 #include "ns3/traced-value.h"
30 
31 #include <map>
32 
33 namespace ns3
34 {
35 class Packet;
36 
75 class TcpRxBuffer : public Object
76 {
77  public:
82  static TypeId GetTypeId();
87  TcpRxBuffer(uint32_t n = 0);
88  ~TcpRxBuffer() override;
89 
90  // Accessors
104  void IncNextRxSequence();
109  void SetNextRxSequence(const SequenceNumber32& s);
114  void SetFinSequence(const SequenceNumber32& s);
119  uint32_t MaxBufferSize() const;
124  void SetMaxBufferSize(uint32_t s);
129  uint32_t Size() const;
134  uint32_t Available() const;
139  bool Finished();
140 
152  bool Add(Ptr<Packet> p, const TcpHeader& tcph);
153 
161  Ptr<Packet> Extract(uint32_t maxSize);
162 
172 
178  uint32_t GetSackListSize() const;
179 
184  bool GotFin() const
185  {
186  return m_gotFin;
187  }
188 
189  private:
208  void UpdateSackList(const SequenceNumber32& head, const SequenceNumber32& tail);
209 
221  void ClearSackList(const SequenceNumber32& seq);
222 
224 
226  typedef std::map<SequenceNumber32, Ptr<Packet>>::iterator BufIterator;
230  bool m_gotFin;
231  uint32_t m_size;
232  uint32_t m_maxBuffer;
233  uint32_t m_availBytes;
234  std::map<SequenceNumber32, Ptr<Packet>> m_data;
235 };
236 
237 } // namespace ns3
238 
239 #endif /* TCP_RX_BUFFER_H */
A base class which provides memory management and object aggregation.
Definition: object.h:89
Header for the Transmission Control Protocol.
Definition: tcp-header.h:47
std::list< SackBlock > SackList
SACK list definition.
Rx reordering buffer for TCP.
Definition: tcp-rx-buffer.h:76
~TcpRxBuffer() override
uint32_t GetSackListSize() const
Get the size of Sack list.
Ptr< Packet > Extract(uint32_t maxSize)
Extract data from the head of the buffer as indicated by nextRxSeq.
bool Finished()
Check if the buffer did receive all the data (and the connection is closed)
static TypeId GetTypeId()
Get the type ID.
void SetFinSequence(const SequenceNumber32 &s)
Set the FIN Sequence number (i.e., the one closing the connection)
void SetMaxBufferSize(uint32_t s)
Set the Maximum buffer size.
SequenceNumber32 NextRxSequence() const
Get Next Rx Sequence number.
std::map< SequenceNumber32, Ptr< Packet > > m_data
Corresponding data (may be null)
void SetNextRxSequence(const SequenceNumber32 &s)
Set the Next Sequence number.
std::map< SequenceNumber32, Ptr< Packet > >::iterator BufIterator
container for data stored in the buffer
SequenceNumber32 m_finSeq
Seqnum of the FIN packet.
uint32_t m_availBytes
Number of bytes available to read, i.e.
void IncNextRxSequence()
Increment the Next Sequence number.
uint32_t MaxBufferSize() const
Get the Maximum buffer size.
uint32_t Size() const
Get the actual buffer occupancy.
bool Add(Ptr< Packet > p, const TcpHeader &tcph)
Insert a packet into the buffer and update the availBytes counter to reflect the number of bytes read...
uint32_t m_maxBuffer
Upper bound of the number of data bytes in buffer (RCV.WND)
SequenceNumber32 MaxRxSequence() const
Get the lowest sequence number that this TcpRxBuffer cannot accept.
bool GotFin() const
Says if a FIN bit has been received.
TracedValue< SequenceNumber32 > m_nextRxSeq
Seqnum of the first missing byte in data (RCV.NXT)
TcpRxBuffer(uint32_t n=0)
Constructor.
void UpdateSackList(const SequenceNumber32 &head, const SequenceNumber32 &tail)
Update the sack list, with the block seq starting at the beginning.
uint32_t Available() const
Get the actual number of bytes available to be read.
TcpOptionSack::SackList GetSackList() const
Get the sack list.
uint32_t m_size
Number of total data bytes in the buffer, not necessarily contiguous.
void ClearSackList(const SequenceNumber32 &seq)
Remove old blocks from the sack list.
bool m_gotFin
Did I received FIN packet?
TcpOptionSack::SackList m_sackList
Sack list (updated constantly)
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.