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

Send queue that manages messages. More...

#include <TCPMsgBasedSendQueue.h>

Inheritance diagram for inet::tcp::TCPMsgBasedSendQueue:
inet::tcp::TCPSendQueue

Classes

struct  Payload
 

Public Member Functions

 TCPMsgBasedSendQueue ()
 Ctor. More...
 
virtual ~TCPMsgBasedSendQueue ()
 Virtual dtor. More...
 
virtual void init (uint32 startSeq) override
 Initialize the object. More...
 
virtual std::string info () const override
 Returns a string with the region stored. More...
 
virtual void enqueueAppData (cPacket *msg) override
 Called on SEND app command, it inserts in the queue the data the user wants to send. More...
 
virtual uint32 getBufferStartSeq () override
 Returns the sequence number of the first byte stored in the buffer. More...
 
virtual uint32 getBufferEndSeq () override
 Returns the sequence number of the last byte stored in the buffer plus one. More...
 
virtual TCPSegmentcreateSegmentWithBytes (uint32 fromSeq, ulong numBytes) override
 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 seqNum) override
 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...
 
- Public Member Functions inherited from inet::tcp::TCPSendQueue
 TCPSendQueue ()
 Ctor. More...
 
virtual ~TCPSendQueue ()
 Virtual dtor. More...
 
virtual void setConnection (TCPConnection *_conn)
 Set the connection that owns this queue. More...
 
ulong getBytesAvailable (uint32 fromSeq)
 Utility function: returns how many bytes are available in the queue, from (and including) the given sequence number. More...
 

Protected Types

typedef std::list< PayloadPayloadQueue
 

Protected Attributes

PayloadQueue payloadQueue
 
uint32 begin
 
uint32 end
 
- Protected Attributes inherited from inet::tcp::TCPSendQueue
TCPConnectionconn
 

Detailed Description

Send queue that manages messages.

See also
TCPMsgBasedRcvQueue

Member Typedef Documentation

Constructor & Destructor Documentation

inet::tcp::TCPMsgBasedSendQueue::TCPMsgBasedSendQueue ( )

Ctor.

28  : TCPSendQueue()
29 {
30  begin = end = 0;
31 }
uint32 end
Definition: TCPMsgBasedSendQueue.h:45
TCPSendQueue()
Ctor.
Definition: TCPSendQueue.h:91
uint32 begin
Definition: TCPMsgBasedSendQueue.h:44
inet::tcp::TCPMsgBasedSendQueue::~TCPMsgBasedSendQueue ( )
virtual

Virtual dtor.

34 {
35  for (auto & elem : payloadQueue)
36  delete elem.msg;
37 }
PayloadQueue payloadQueue
Definition: TCPMsgBasedSendQueue.h:42

Member Function Documentation

TCPSegment * inet::tcp::TCPMsgBasedSendQueue::createSegmentWithBytes ( uint32  fromSeq,
ulong  maxNumBytes 
)
overridevirtual

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.

Implements inet::tcp::TCPSendQueue.

76 {
77  //tcpEV << "sendQ: " << info() << " createSeg(seq=" << fromSeq << " len=" << numBytes << ")\n";
78  ASSERT(seqLE(begin, fromSeq) && seqLE(fromSeq + numBytes, end));
79 
80  TCPSegment *tcpseg = new TCPSegment(nullptr);
81 
82  tcpseg->setSequenceNo(fromSeq);
83  tcpseg->setPayloadLength(numBytes);
84 
85  // add payload messages whose endSequenceNo is between fromSeq and fromSeq + numBytes
86  auto i = payloadQueue.begin();
87 
88  while (i != payloadQueue.end() && seqLE(i->endSequenceNo, fromSeq))
89  ++i;
90 
91  uint32 toSeq = fromSeq + numBytes;
92  const char *payloadName = nullptr;
93 
94  while (i != payloadQueue.end() && seqLE(i->endSequenceNo, toSeq)) {
95  if (!payloadName)
96  payloadName = i->msg->getName();
97 
98  tcpseg->addPayloadMessage(i->msg->dup(), i->endSequenceNo);
99  ++i;
100  }
101 
102  // give segment a name
103  char msgname[80];
104  if (!payloadName)
105  sprintf(msgname, "tcpseg(l=%lu,%dmsg)", numBytes, tcpseg->getPayloadArraySize());
106  else
107  sprintf(msgname, "%.10s(l=%lu,%dmsg)", payloadName, numBytes, tcpseg->getPayloadArraySize());
108  tcpseg->setName(msgname);
109 
110  return tcpseg;
111 }
uint32 end
Definition: TCPMsgBasedSendQueue.h:45
PayloadQueue payloadQueue
Definition: TCPMsgBasedSendQueue.h:42
bool seqLE(uint32 a, uint32 b)
Definition: TCPSegment.h:33
uint32_t uint32
Definition: Compat.h:30
uint32 begin
Definition: TCPMsgBasedSendQueue.h:44
void inet::tcp::TCPMsgBasedSendQueue::discardUpTo ( uint32  seqNum)
overridevirtual

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

Implements inet::tcp::TCPSendQueue.

114 {
115  //tcpEV << "sendQ: " << info() << " discardUpTo(seq=" << seqNum << ")\n";
116 
117  ASSERT(seqLE(begin, seqNum) && seqLE(seqNum, end));
118 
119  begin = seqNum;
120 
121  // remove payload messages whose endSequenceNo is below seqNum
122  while (!payloadQueue.empty() && seqLE(payloadQueue.front().endSequenceNo, seqNum)) {
123  delete payloadQueue.front().msg;
124  payloadQueue.pop_front();
125  }
126 }
uint32 end
Definition: TCPMsgBasedSendQueue.h:45
PayloadQueue payloadQueue
Definition: TCPMsgBasedSendQueue.h:42
bool seqLE(uint32 a, uint32 b)
Definition: TCPSegment.h:33
uint32 begin
Definition: TCPMsgBasedSendQueue.h:44
void inet::tcp::TCPMsgBasedSendQueue::enqueueAppData ( cPacket *  msg)
overridevirtual

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.)

Implements inet::tcp::TCPSendQueue.

53 {
54  //tcpEV << "sendQ: " << info() << " enqueueAppData(bytes=" << msg->getByteLength() << ")\n";
55  end += msg->getByteLength();
56  if (seqLess(end, begin))
57  throw cRuntimeError("Send queue is full");
58 
59  Payload payload;
60  payload.endSequenceNo = end;
61  payload.msg = msg;
62  payloadQueue.push_back(payload);
63 }
uint32 end
Definition: TCPMsgBasedSendQueue.h:45
bool seqLess(uint32 a, uint32 b)
Definition: TCPSegment.h:32
PayloadQueue payloadQueue
Definition: TCPMsgBasedSendQueue.h:42
uint32 begin
Definition: TCPMsgBasedSendQueue.h:44
uint32 inet::tcp::TCPMsgBasedSendQueue::getBufferEndSeq ( )
overridevirtual

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.)

Implements inet::tcp::TCPSendQueue.

71 {
72  return end;
73 }
uint32 end
Definition: TCPMsgBasedSendQueue.h:45
uint32 inet::tcp::TCPMsgBasedSendQueue::getBufferStartSeq ( )
overridevirtual

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

Implements inet::tcp::TCPSendQueue.

66 {
67  return begin;
68 }
uint32 begin
Definition: TCPMsgBasedSendQueue.h:44
std::string inet::tcp::TCPMsgBasedSendQueue::info ( ) const
overridevirtual

Returns a string with the region stored.

46 {
47  std::stringstream out;
48  out << "[" << begin << ".." << end << "), " << payloadQueue.size() << " packets";
49  return out.str();
50 }
uint32 end
Definition: TCPMsgBasedSendQueue.h:45
PayloadQueue payloadQueue
Definition: TCPMsgBasedSendQueue.h:42
uint32 begin
Definition: TCPMsgBasedSendQueue.h:44
void inet::tcp::TCPMsgBasedSendQueue::init ( uint32  startSeq)
overridevirtual

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.

Implements inet::tcp::TCPSendQueue.

40 {
41  begin = startSeq;
42  end = startSeq;
43 }
uint32 end
Definition: TCPMsgBasedSendQueue.h:45
uint32 begin
Definition: TCPMsgBasedSendQueue.h:44

Member Data Documentation

uint32 inet::tcp::TCPMsgBasedSendQueue::begin
protected
uint32 inet::tcp::TCPMsgBasedSendQueue::end
protected
PayloadQueue inet::tcp::TCPMsgBasedSendQueue::payloadQueue
protected

The documentation for this class was generated from the following files: