INET Framework for OMNeT++/OMNEST
inet::tcp::TcpSendQueue Class Reference

Send queue that manages Chunks. More...

#include <TcpSendQueue.h>

Inheritance diagram for inet::tcp::TcpSendQueue:

Public Member Functions

 TcpSendQueue ()
 Ctor. More...
 
virtual ~TcpSendQueue ()
 Virtual dtor. More...
 
virtual ChunkQueuegetDataBuffer ()
 
virtual void setConnection (TcpConnection *_conn)
 Set the connection that owns this queue. More...
 
virtual void init (uint32_t startSeq)
 Initialize the object. More...
 
virtual std::string str () const override
 Returns a string with the region stored. More...
 
virtual void enqueueAppData (Packet *msg)
 Called on SEND app command, it inserts in the queue the data the user wants to send. More...
 
virtual uint32_t getBufferStartSeq () const
 Returns the sequence number of the first byte stored in the buffer. More...
 
virtual uint32_t getBufferEndSeq () const
 Returns the sequence number of the last byte stored in the buffer plus one. More...
 
virtual uint32_t getBytesAvailable (uint32_t fromSeq) const
 Utility function: returns how many bytes are available in the queue, from (and including) the given sequence number. More...
 
virtual PacketcreateSegmentWithBytes (uint32_t fromSeq, uint32_t numBytes)
 Called when the TCP wants to send or retransmit data, it constructs a TCP segment which contains the data from the requested sequence number range. More...
 
virtual void discardUpTo (uint32_t seqNum)
 Tells the queue that bytes up to (but NOT including) seqNum have been transmitted and ACKed, so they can be removed from the queue. More...
 

Protected Attributes

TcpConnectionconn = nullptr
 
uint32_t begin = 0
 
uint32_t end = 0
 
ChunkQueue dataBuffer
 

Detailed Description

Send queue that manages Chunks.

See also
TCPRcvQueue

Constructor & Destructor Documentation

◆ TcpSendQueue()

inet::tcp::TcpSendQueue::TcpSendQueue ( )

Ctor.

17 {
18 }

◆ ~TcpSendQueue()

inet::tcp::TcpSendQueue::~TcpSendQueue ( )
virtual

Virtual dtor.

21 {
22 }

Member Function Documentation

◆ createSegmentWithBytes()

Packet * inet::tcp::TcpSendQueue::createSegmentWithBytes ( uint32_t  fromSeq,
uint32_t  numBytes 
)
virtual

Called when the TCP wants to send or retransmit data, it constructs a TCP segment which contains the data from the requested sequence number range.

The actually returned segment may contain less than maxNumBytes bytes if the subclass wants to reproduce the original segment boundaries when retransmitting.

63 {
64  ASSERT(seqLE(begin, fromSeq) && seqLE(fromSeq + numBytes, end));
65 
66  char msgname[32];
67  sprintf(msgname, "tcpseg(l=%u)", (unsigned int)numBytes);
68 
69  Packet *tcpSegment = new Packet(msgname);
70  const auto& payload = dataBuffer.peekAt(B(fromSeq - begin), B(numBytes)); // get data from buffer
71  tcpSegment->insertAtBack(payload);
72  return tcpSegment;
73 }

Referenced by inet::tcp::TcpConnection::sendSegment().

◆ discardUpTo()

void inet::tcp::TcpSendQueue::discardUpTo ( uint32_t  seqNum)
virtual

Tells the queue that bytes up to (but NOT including) seqNum have been transmitted and ACKed, so they can be removed from the queue.

76 {
77  ASSERT(seqLE(begin, seqNum) && seqLE(seqNum, end));
78 
79  if (seqNum != begin) {
80  dataBuffer.pop(B(seqNum - begin));
81  begin = seqNum;
82  }
83 }

Referenced by inet::tcp::TcpConnection::processAckInEstabEtc(), inet::tcp::TcpConnection::processRstInSynReceived(), and inet::tcp::TcpConnection::processSegmentInSynSent().

◆ enqueueAppData()

void inet::tcp::TcpSendQueue::enqueueAppData ( Packet msg)
virtual

Called on SEND app command, it inserts in the queue the data the user wants to send.

Implementations of this abstract class will decide what this means: copying actual bytes, just increasing the "last byte queued" variable, or storing cMessage object(s). The msg object should not be referenced after this point (sendQueue may delete it.)

39 {
40  dataBuffer.push(msg->peekDataAt(B(0), msg->getDataLength()));
41  end += msg->getByteLength();
42  if (seqLess(end, begin))
43  throw cRuntimeError("Send queue is full");
44  delete msg;
45 }

Referenced by inet::tcp::TcpConnection::process_SEND().

◆ getBufferEndSeq()

uint32_t inet::tcp::TcpSendQueue::getBufferEndSeq ( ) const
virtual

Returns the sequence number of the last byte stored in the buffer plus one.

(The first byte of the next send operation would get this sequence number.)

53 {
54  return end;
55 }

Referenced by inet::tcp::TcpConnection::process_CLOSE(), inet::tcp::TcpConnection::processRstInSynReceived(), inet::tcp::TcpConnection::retransmitData(), and inet::tcp::TcpConnection::retransmitOneSegment().

◆ getBufferStartSeq()

uint32_t inet::tcp::TcpSendQueue::getBufferStartSeq ( ) const
virtual

Returns the sequence number of the first byte stored in the buffer.

48 {
49  return begin;
50 }

Referenced by inet::tcp::TcpConnection::sendSegment().

◆ getBytesAvailable()

uint32_t inet::tcp::TcpSendQueue::getBytesAvailable ( uint32_t  fromSeq) const
virtual

◆ getDataBuffer()

virtual ChunkQueue& inet::tcp::TcpSendQueue::getDataBuffer ( )
inlinevirtual
43 { return dataBuffer; }

◆ init()

void inet::tcp::TcpSendQueue::init ( uint32_t  startSeq)
virtual

Initialize the object.

The startSeq parameter tells what sequence number the first byte of app data should get. This is usually ISS + 1 because SYN consumes one byte in the sequence number space.

init() may be called more than once; every call flushes the existing contents of the queue.

25 {
26  begin = startSeq;
27  end = startSeq;
28  dataBuffer.clear(); // clear dataBuffer
29 }

Referenced by inet::tcp::TcpConnection::selectInitialSeqNum().

◆ setConnection()

virtual void inet::tcp::TcpSendQueue::setConnection ( TcpConnection _conn)
inlinevirtual

Set the connection that owns this queue.

48 { conn = _conn; }

Referenced by inet::tcp::TcpConnection::initClonedConnection(), and inet::tcp::TcpConnection::initConnection().

◆ str()

std::string inet::tcp::TcpSendQueue::str ( ) const
overridevirtual

Returns a string with the region stored.

32 {
33  std::stringstream out;
34  out << "[" << begin << ".." << end << ")" << dataBuffer;
35  return out.str();
36 }

Member Data Documentation

◆ begin

uint32_t inet::tcp::TcpSendQueue::begin = 0
protected

◆ conn

TcpConnection* inet::tcp::TcpSendQueue::conn = nullptr
protected

◆ dataBuffer

ChunkQueue inet::tcp::TcpSendQueue::dataBuffer
protected

◆ end

uint32_t inet::tcp::TcpSendQueue::end = 0
protected

The documentation for this class was generated from the following files:
inet::tcp::TcpSendQueue::dataBuffer
ChunkQueue dataBuffer
Definition: TcpSendQueue.h:30
inet::tcp::seqLess
bool seqLess(uint32_t a, uint32_t b)
Definition: TcpHeader.h:21
inet::tcp::seqLE
bool seqLE(uint32_t a, uint32_t b)
Definition: TcpHeader.h:22
inet::tcp::TcpSendQueue::conn
TcpConnection * conn
Definition: TcpSendQueue.h:27
inet::tcp::TcpSendQueue::end
uint32_t end
Definition: TcpSendQueue.h:29
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::tcp::TcpSendQueue::begin
uint32_t begin
Definition: TcpSendQueue.h:28
inet::ChunkQueue::push
void push(const Ptr< const Chunk > &chunk)
Inserts the provided chunk at the tail of the queue.
Definition: ChunkQueue.cc:85
inet::ChunkQueue::str
virtual std::string str() const override
Returns a human readable string representation.
Definition: ChunkQueue.cc:112
inet::ChunkQueue::clear
void clear()
Erases all data from the queue.
Definition: ChunkQueue.cc:78
inet::ChunkQueue::pop
const Ptr< const Chunk > pop(b length=b(-1), int flags=0)
Pops the designated data and returns it as an immutable chunk in its current representation.
Definition: ChunkQueue.cc:69
inet::ChunkQueue::peekAt
const Ptr< const Chunk > peekAt(b offset, b length, int flags=0) const
Returns the designated data at the given offset as an immutable chunk in its current representation.
Definition: ChunkQueue.cc:62