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

Send queue that manages "objects". More...

#include <TcpLwipMsgBasedQueues.h>

Inheritance diagram for inet::tcp::TcpLwipMsgBasedSendQueue:
inet::tcp::TcpLwipSendQueue

Classes

struct  Payload
 

Public Member Functions

 TcpLwipMsgBasedSendQueue ()
 Ctor. More...
 
virtual ~TcpLwipMsgBasedSendQueue ()
 Virtual dtor. More...
 
virtual void setConnection (TcpLwipConnection *connP) override
 set connection queue. More...
 
virtual void enqueueAppData (cPacket *msgP) override
 Called on SEND app command, it inserts in the queue the data the user wants to send. More...
 
virtual unsigned int getBytesForTcpLayer (void *bufferP, unsigned int bufferLengthP) const override
 Copy data to the buffer for send to LWIP. More...
 
virtual void dequeueTcpLayerMsg (unsigned int msgLengthP) override
 Remove msgLengthP bytes from TCP Layer queue. More...
 
unsigned long getBytesAvailable () const override
 Utility function: returns how many bytes are available in the queue. More...
 
virtual TCPSegmentcreateSegmentWithBytes (const void *tcpDataP, unsigned int tcpLengthP) 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 discardAckedBytes ()
 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::TcpLwipSendQueue
 TcpLwipSendQueue ()
 Ctor. More...
 
virtual ~TcpLwipSendQueue ()
 Virtual dtor. More...
 

Protected Types

typedef std::list< PayloadPayloadQueue
 

Protected Attributes

PayloadQueue payloadQueueM
 
uint32 beginM
 
uint32 endM
 
bool isValidSeqNoM
 
unsigned long int unsentTcpLayerBytesM
 
- Protected Attributes inherited from inet::tcp::TcpLwipSendQueue
TcpLwipConnectionconnM
 

Detailed Description

Send queue that manages "objects".

Member Typedef Documentation

Constructor & Destructor Documentation

inet::tcp::TcpLwipMsgBasedSendQueue::TcpLwipMsgBasedSendQueue ( )

Ctor.

35  :
36  beginM(0),
37  endM(0),
39 {
40 }
uint32 endM
Definition: TcpLwipMsgBasedQueues.h:48
unsigned long int unsentTcpLayerBytesM
Definition: TcpLwipMsgBasedQueues.h:50
uint32 beginM
Definition: TcpLwipMsgBasedQueues.h:47
inet::tcp::TcpLwipMsgBasedSendQueue::~TcpLwipMsgBasedSendQueue ( )
virtual

Virtual dtor.

43 {
44  while (!payloadQueueM.empty()) {
45  EV_TRACE << "SendQueue Destructor: Drop msg from " << connM->tcpLwipM.getFullPath()
46  << " Queue: seqno=" << payloadQueueM.front().endSequenceNo
47  << ", length=" << payloadQueueM.front().msg->getByteLength() << endl;
48  delete payloadQueueM.front().msg;
49  payloadQueueM.pop_front();
50  }
51 }
PayloadQueue payloadQueueM
Definition: TcpLwipMsgBasedQueues.h:45
TcpLwipConnection * connM
Definition: TcpLwipQueues.h:145
TCP_lwIP & tcpLwipM
Definition: TcpLwipConnection.h:116

Member Function Documentation

TCPSegment * inet::tcp::TcpLwipMsgBasedSendQueue::createSegmentWithBytes ( const void *  tcpDataP,
unsigned int  tcpLengthP 
)
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 then maxNumBytes bytes if the subclass wants to reproduce the original segment boundaries when retransmitting.

called from inside of send_callback() called before called the send() to IP layer

Parameters
tcpDataPthe tcp segment (with tcp header) created by LWIP
tcpLenthPthe length of tcp segment.

Implements inet::tcp::TcpLwipSendQueue.

95 {
96  ASSERT(tcpDataP);
97 
98  TCPSegment *tcpseg = serializer::TCPSerializer().deserialize((const unsigned char *)tcpDataP, tcpLengthP, false);
99 
100  uint32 fromSeq = tcpseg->getSequenceNo();
101  uint32 numBytes = tcpseg->getPayloadLength();
102  uint32 toSeq = fromSeq + numBytes;
103 
104  if ((!isValidSeqNoM) && (numBytes > 0)) {
105  for (auto & elem : payloadQueueM) {
106  elem.endSequenceNo += fromSeq;
107  }
108 
109  beginM += fromSeq;
110  endM += fromSeq;
111  isValidSeqNoM = true;
112  }
113 
114  if (numBytes && !seqLE(toSeq, endM))
115  throw cRuntimeError("Implementation bug");
116 
117  EV_DEBUG << "sendQueue: " << connM->connIdM << ": [" << fromSeq << ":" << toSeq
118  << ",l=" << numBytes << "] (unsent bytes:" << unsentTcpLayerBytesM << "\n";
119 
120  for (auto & elem : payloadQueueM) {
121  EV_DEBUG << " buffered msg: endseq=" << elem.endSequenceNo
122  << ", length=" << elem.msg->getByteLength() << endl;
123  }
124 
125  const char *payloadName = nullptr;
126 
127  if (numBytes > 0) {
128  // add payload messages whose endSequenceNo is between fromSeq and fromSeq+numBytes
129  auto i = payloadQueueM.begin();
130 
131  while (i != payloadQueueM.end() && seqLE(i->endSequenceNo, fromSeq))
132  ++i;
133 
134  while (i != payloadQueueM.end() && seqLE(i->endSequenceNo, toSeq)) {
135  if (!payloadName)
136  payloadName = i->msg->getName();
137 
138  cPacket *msg = i->msg->dup();
139  tcpseg->addPayloadMessage(msg, i->endSequenceNo);
140  ++i;
141  }
142  }
143 
144  // give segment a name
145  char msgname[80];
146  sprintf(msgname, "%.10s%s%s%s(l=%lu,%dmsg)",
147  (payloadName ? payloadName : "tcpseg"),
148  tcpseg->getSynBit() ? " SYN" : "",
149  tcpseg->getFinBit() ? " FIN" : "",
150  (tcpseg->getAckBit() && 0 == numBytes) ? " ACK" : "",
151  (unsigned long)numBytes,
152  tcpseg->getPayloadArraySize());
153  tcpseg->setName(msgname);
154 
156 
157  return tcpseg;
158 }
uint32 endM
Definition: TcpLwipMsgBasedQueues.h:48
bool isValidSeqNoM
Definition: TcpLwipMsgBasedQueues.h:49
unsigned long int unsentTcpLayerBytesM
Definition: TcpLwipMsgBasedQueues.h:50
PayloadQueue payloadQueueM
Definition: TcpLwipMsgBasedQueues.h:45
int connIdM
Definition: TcpLwipConnection.h:111
virtual void discardAckedBytes()
Tells the queue that bytes up to (but NOT including) seqNum have been transmitted and ACKed...
Definition: TcpLwipMsgBasedQueues.cc:160
bool seqLE(uint32 a, uint32 b)
Definition: TCPSegment.h:33
uint32_t uint32
Definition: Compat.h:30
uint32 beginM
Definition: TcpLwipMsgBasedQueues.h:47
TcpLwipConnection * connM
Definition: TcpLwipQueues.h:145
void inet::tcp::TcpLwipMsgBasedSendQueue::dequeueTcpLayerMsg ( unsigned int  msgLengthP)
overridevirtual

Remove msgLengthP bytes from TCP Layer queue.

called with return value of socket->send_data() if larger than 0

Implements inet::tcp::TcpLwipSendQueue.

83 {
84  ASSERT(msgLengthP <= unsentTcpLayerBytesM);
85 
86  unsentTcpLayerBytesM -= msgLengthP;
87 }
unsigned long int unsentTcpLayerBytesM
Definition: TcpLwipMsgBasedQueues.h:50
void inet::tcp::TcpLwipMsgBasedSendQueue::discardAckedBytes ( )
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.

Referenced by createSegmentWithBytes().

161 {
162  if (isValidSeqNoM) {
163  uint32 seqNum = connM->pcbM->lastack;
164 
165  if (seqLE(beginM, seqNum) && seqLE(seqNum, endM)) {
166  beginM = seqNum;
167 
168  // remove payload messages whose endSequenceNo is below seqNum
169  while (!payloadQueueM.empty() && seqLE(payloadQueueM.front().endSequenceNo, seqNum)) {
170  delete payloadQueueM.front().msg;
171  payloadQueueM.pop_front();
172  }
173  }
174  }
175 }
uint32 endM
Definition: TcpLwipMsgBasedQueues.h:48
bool isValidSeqNoM
Definition: TcpLwipMsgBasedQueues.h:49
PayloadQueue payloadQueueM
Definition: TcpLwipMsgBasedQueues.h:45
LwipTcpLayer::tcp_pcb * pcbM
Definition: TcpLwipConnection.h:113
bool seqLE(uint32 a, uint32 b)
Definition: TCPSegment.h:33
uint32_t uint32
Definition: Compat.h:30
uint32 beginM
Definition: TcpLwipMsgBasedQueues.h:47
TcpLwipConnection * connM
Definition: TcpLwipQueues.h:145
void inet::tcp::TcpLwipMsgBasedSendQueue::enqueueAppData ( cPacket *  msgP)
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::TcpLwipSendQueue.

62 {
63  ASSERT(msgP);
64 
65  uint32 bytes = msgP->getByteLength();
66  endM += bytes;
67  unsentTcpLayerBytesM += bytes;
68 
69  Payload payload;
70  payload.endSequenceNo = endM;
71  payload.msg = msgP;
72  payloadQueueM.push_back(payload);
73 }
uint32 endM
Definition: TcpLwipMsgBasedQueues.h:48
unsigned long int unsentTcpLayerBytesM
Definition: TcpLwipMsgBasedQueues.h:50
PayloadQueue payloadQueueM
Definition: TcpLwipMsgBasedQueues.h:45
uint32_t uint32
Definition: Compat.h:30
unsigned long inet::tcp::TcpLwipMsgBasedSendQueue::getBytesAvailable ( ) const
overridevirtual

Utility function: returns how many bytes are available in the queue.

Implements inet::tcp::TcpLwipSendQueue.

90 {
91  return unsentTcpLayerBytesM;
92 }
unsigned long int unsentTcpLayerBytesM
Definition: TcpLwipMsgBasedQueues.h:50
unsigned int inet::tcp::TcpLwipMsgBasedSendQueue::getBytesForTcpLayer ( void *  bufferP,
unsigned int  bufferLengthP 
) const
overridevirtual

Copy data to the buffer for send to LWIP.

returns lengh of copied data. create msg for socket->send_data()

called before called socket->send_data()

Implements inet::tcp::TcpLwipSendQueue.

76 {
77  ASSERT(bufferP);
78 
79  return (unsentTcpLayerBytesM > bufferLengthP) ? bufferLengthP : unsentTcpLayerBytesM;
80 }
unsigned long int unsentTcpLayerBytesM
Definition: TcpLwipMsgBasedQueues.h:50
void inet::tcp::TcpLwipMsgBasedSendQueue::setConnection ( TcpLwipConnection connP)
overridevirtual

set connection queue.

Reimplemented from inet::tcp::TcpLwipSendQueue.

54 {
56  endM = beginM = 0;
57  isValidSeqNoM = false;
59 }
uint32 endM
Definition: TcpLwipMsgBasedQueues.h:48
bool isValidSeqNoM
Definition: TcpLwipMsgBasedQueues.h:49
unsigned long int unsentTcpLayerBytesM
Definition: TcpLwipMsgBasedQueues.h:50
virtual void setConnection(TcpLwipConnection *connP)
set connection queue, and initialise queue variables.
Definition: TcpLwipQueues.h:101
uint32 beginM
Definition: TcpLwipMsgBasedQueues.h:47

Member Data Documentation

uint32 inet::tcp::TcpLwipMsgBasedSendQueue::beginM
protected
uint32 inet::tcp::TcpLwipMsgBasedSendQueue::endM
protected
bool inet::tcp::TcpLwipMsgBasedSendQueue::isValidSeqNoM
protected
PayloadQueue inet::tcp::TcpLwipMsgBasedSendQueue::payloadQueueM
protected
unsigned long int inet::tcp::TcpLwipMsgBasedSendQueue::unsentTcpLayerBytesM
protected

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