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

Represents a TCP segment. More...

#include <TCPSegment.h>

Inheritance diagram for inet::tcp::TCPSegment:
inet::tcp::TCPSegment_Base inet::ITransportPacket

Public Member Functions

 TCPSegment (const char *name=nullptr, int kind=0)
 
 TCPSegment (const TCPSegment &other)
 
 ~TCPSegment ()
 
TCPSegmentoperator= (const TCPSegment &other)
 
virtual TCPSegmentdup () const override
 
virtual void parsimPack (cCommBuffer *b) const override
 
virtual void parsimUnpack (cCommBuffer *b) override
 
virtual void setPayloadArraySize (unsigned int size) override
 Generated but unused method, should not be called. More...
 
virtual void setPayload (unsigned int k, const TCPPayloadMessage &payload_var) override
 Generated but unused method, should not be called. More...
 
virtual unsigned int getPayloadArraySize () const override
 Returns the number of payload messages in this TCP segment. More...
 
virtual TCPPayloadMessagegetPayload (unsigned int k) override
 Returns the kth payload message in this TCP segment. More...
 
virtual void addPayloadMessage (cPacket *msg, uint32 endSequenceNo)
 Adds a message object to the TCP segment. More...
 
virtual cPacket * removeFirstPayloadMessage (uint32 &outEndSequenceNo)
 Removes and returns the first message object in this TCP segment. More...
 
virtual uint32_t getSegLen ()
 Returns RFC 793 specified SEG.LEN: SEG.LEN = the number of octets occupied by the data in the segment (counting SYN and FIN) More...
 
virtual void truncateSegment (uint32 firstSeqNo, uint32 endSeqNo)
 Truncate segment. More...
 
virtual unsigned short getHeaderOptionArrayLength ()
 Calculate Length of TCP Options Array in bytes. More...
 
virtual void setHeaderOptionArraySize (unsigned int size) override
 Generated but unused method, should not be called. More...
 
virtual unsigned int getHeaderOptionArraySize () const override
 Returns the number of TCP options in this TCP segment. More...
 
virtual TCPOptionPtrgetHeaderOption (unsigned int k) override
 Returns the kth TCP options in this TCP segment. More...
 
virtual const TCPOptionPtrgetHeaderOption (unsigned int k) const override
 
virtual void setHeaderOption (unsigned int k, const TCPOptionPtr &headerOption) override
 Generated but unused method, should not be called. More...
 
virtual void addHeaderOption (TCPOption *headerOption)
 Adds a TCP option to the TCP segment. More...
 
virtual void dropHeaderOptions ()
 Drops all TCP options of the TCP segment. More...
 
virtual unsigned int getSourcePort () const override
 
virtual void setSourcePort (unsigned int port) override
 
virtual unsigned int getDestinationPort () const override
 
virtual void setDestinationPort (unsigned int port) override
 
- Public Member Functions inherited from inet::tcp::TCPSegment_Base
virtual ~TCPSegment_Base ()
 
virtual void parsimPack (omnetpp::cCommBuffer *b) const override
 
virtual void parsimUnpack (omnetpp::cCommBuffer *b) override
 
virtual unsigned short getSrcPort () const
 
virtual void setSrcPort (unsigned short srcPort)
 
virtual unsigned short getDestPort () const
 
virtual void setDestPort (unsigned short destPort)
 
virtual unsigned int getSequenceNo () const
 
virtual void setSequenceNo (unsigned int sequenceNo)
 
virtual unsigned int getAckNo () const
 
virtual void setAckNo (unsigned int ackNo)
 
virtual unsigned short getHeaderLength () const
 
virtual void setHeaderLength (unsigned short headerLength)
 
virtual bool getUrgBit () const
 
virtual void setUrgBit (bool urgBit)
 
virtual bool getAckBit () const
 
virtual void setAckBit (bool ackBit)
 
virtual bool getPshBit () const
 
virtual void setPshBit (bool pshBit)
 
virtual bool getRstBit () const
 
virtual void setRstBit (bool rstBit)
 
virtual bool getSynBit () const
 
virtual void setSynBit (bool synBit)
 
virtual bool getFinBit () const
 
virtual void setFinBit (bool finBit)
 
virtual unsigned short getWindow () const
 
virtual void setWindow (unsigned short window)
 
virtual unsigned short getUrgentPointer () const
 
virtual void setUrgentPointer (unsigned short urgentPointer)
 
virtual unsigned long getPayloadLength () const
 
virtual void setPayloadLength (unsigned long payloadLength)
 
virtual const TCPPayloadMessagegetPayload (unsigned int k) const
 
virtual ByteArraygetByteArray ()
 
virtual const ByteArraygetByteArray () const
 
virtual void setByteArray (const ByteArray &byteArray)
 
- Public Member Functions inherited from inet::ITransportPacket
virtual ~ITransportPacket ()
 

Protected Types

typedef std::list< TCPPayloadMessagePayloadList
 
typedef std::vector< TCPOption * > OptionList
 

Protected Member Functions

virtual void truncateData (unsigned int truncleft, unsigned int truncright)
 Truncate segment data. More...
 
- Protected Member Functions inherited from inet::tcp::TCPSegment_Base
bool operator== (const TCPSegment_Base &)
 
 TCPSegment_Base (const char *name=nullptr, short kind=0)
 
 TCPSegment_Base (const TCPSegment_Base &other)
 
TCPSegment_Baseoperator= (const TCPSegment_Base &other)
 

Protected Attributes

PayloadList payloadList
 
OptionList headerOptionList
 
- Protected Attributes inherited from inet::tcp::TCPSegment_Base
unsigned short srcPort
 
unsigned short destPort
 
unsigned int sequenceNo
 
unsigned int ackNo
 
unsigned short headerLength
 
bool urgBit
 
bool ackBit
 
bool pshBit
 
bool rstBit
 
bool synBit
 
bool finBit
 
unsigned short window
 
unsigned short urgentPointer
 
unsigned long payloadLength
 
ByteArray byteArray
 

Private Member Functions

void copy (const TCPSegment &other)
 
void clean ()
 

Detailed Description

Represents a TCP segment.

More info in the TCPSegment.msg file (and the documentation generated from it).

Member Typedef Documentation

typedef std::vector<TCPOption *> inet::tcp::TCPSegment::OptionList
protected

Constructor & Destructor Documentation

inet::tcp::TCPSegment::TCPSegment ( const char *  name = nullptr,
int  kind = 0 
)
inline
73 : TCPSegment_Base(name, kind) {}
TCPSegment_Base(const char *name=nullptr, short kind=0)
inet::tcp::TCPSegment::TCPSegment ( const TCPSegment other)
inline
74 : TCPSegment_Base(other) { copy(other); }
void copy(const TCPSegment &other)
Definition: TCPSegment.cc:108
TCPSegment_Base(const char *name=nullptr, short kind=0)
inet::tcp::TCPSegment::~TCPSegment ( )
117 {
118  clean();
119 }
void clean()
Definition: TCPSegment.cc:121

Member Function Documentation

void inet::tcp::TCPSegment::addHeaderOption ( TCPOption headerOption)
virtual
void inet::tcp::TCPSegment::addPayloadMessage ( cPacket *  msg,
uint32  endSequenceNo 
)
virtual

Adds a message object to the TCP segment.

The sequence number + 1 of the last byte of the message should be passed as 2nd argument

Referenced by inet::tcp::TCPMsgBasedSendQueue::createSegmentWithBytes(), and inet::tcp::TcpLwipMsgBasedSendQueue::createSegmentWithBytes().

214 {
215  take(msg);
216 
217  TCPPayloadMessage payload;
218  payload.endSequenceNo = endSequenceNo;
219  payload.msg = msg;
220  payloadList.push_back(payload);
221 }
PayloadList payloadList
Definition: TCPSegment.h:64
void inet::tcp::TCPSegment::clean ( )
private
122 {
124 
125  while (!payloadList.empty()) {
126  cPacket *msg = payloadList.front().msg;
127  payloadList.pop_front();
128  dropAndDelete(msg);
129  }
130 }
PayloadList payloadList
Definition: TCPSegment.h:64
virtual void dropHeaderOptions()
Drops all TCP options of the TCP segment.
Definition: TCPSegment.cc:260
void inet::tcp::TCPSegment::copy ( const TCPSegment other)
private
109 {
110  for (const auto & elem : other.payloadList)
111  addPayloadMessage(elem.msg->dup(), elem.endSequenceNo);
112  for (const auto opt: other.headerOptionList)
113  addHeaderOption(opt->dup());
114 }
virtual void addPayloadMessage(cPacket *msg, uint32 endSequenceNo)
Adds a message object to the TCP segment.
Definition: TCPSegment.cc:213
virtual void addHeaderOption(TCPOption *headerOption)
Adds a TCP option to the TCP segment.
Definition: TCPSegment.cc:235
void inet::tcp::TCPSegment::dropHeaderOptions ( )
virtual

Drops all TCP options of the TCP segment.

Referenced by inet::tcp::TCPConnection::writeHeaderOptions().

261 {
262  for (auto opt : headerOptionList)
263  delete opt;
264  headerOptionList.clear();
265 }
OptionList headerOptionList
Definition: TCPSegment.h:66
virtual TCPSegment* inet::tcp::TCPSegment::dup ( ) const
inlineoverridevirtual

Reimplemented from inet::tcp::TCPSegment_Base.

77 { return new TCPSegment(*this); }
TCPSegment(const char *name=nullptr, int kind=0)
Definition: TCPSegment.h:73
virtual unsigned int inet::tcp::TCPSegment::getDestinationPort ( ) const
inlineoverridevirtual

Implements inet::ITransportPacket.

Referenced by inet::ExampleQoSClassifier::getUserPriority().

151 { return TCPSegment_Base::getDestPort(); }
virtual unsigned short getDestPort() const
virtual const TCPOptionPtr& inet::tcp::TCPSegment::getHeaderOption ( unsigned int  k) const
inlineoverridevirtual

Reimplemented from inet::tcp::TCPSegment_Base.

Referenced by getHeaderOption().

137 {return const_cast<TCPSegment*>(this)->getHeaderOption(k);}
TCPSegment(const char *name=nullptr, int kind=0)
Definition: TCPSegment.h:73
virtual TCPOptionPtr & getHeaderOption(unsigned int k) override
Returns the kth TCP options in this TCP segment.
Definition: TCPSegment.cc:250
const double k
Definition: QAM16Modulation.cc:24
unsigned short inet::tcp::TCPSegment::getHeaderOptionArrayLength ( )
virtual

Calculate Length of TCP Options Array in bytes.

Referenced by inet::tcp::TCPConnection::addSacks(), and inet::tcp::TCPConnection::writeHeaderOptions().

89 {
90  unsigned short usedLength = 0;
91 
92  for (uint i = 0; i < getHeaderOptionArraySize(); i++)
93  usedLength += getHeaderOption(i)->getLength();
94 
95  return usedLength;
96 }
unsigned int uint
Definition: INETDefs.h:63
virtual unsigned short getLength() const
virtual TCPOptionPtr & getHeaderOption(unsigned int k) override
Returns the kth TCP options in this TCP segment.
Definition: TCPSegment.cc:250
virtual unsigned int getHeaderOptionArraySize() const override
Returns the number of TCP options in this TCP segment.
Definition: TCPSegment.cc:245
TCPPayloadMessage & inet::tcp::TCPSegment::getPayload ( unsigned int  k)
overridevirtual

Returns the kth payload message in this TCP segment.

Implements inet::tcp::TCPSegment_Base.

199 {
200  auto i = payloadList.begin();
201  while (k > 0 && i != payloadList.end())
202  (++i, --k);
203  if (i == payloadList.end())
204  throw cRuntimeError("Model error at getPayload(): index out of range");
205  return *i;
206 }
PayloadList payloadList
Definition: TCPSegment.h:64
const double k
Definition: QAM16Modulation.cc:24
unsigned int inet::tcp::TCPSegment::getPayloadArraySize ( ) const
overridevirtual

Returns the number of payload messages in this TCP segment.

Implements inet::tcp::TCPSegment_Base.

Referenced by inet::tcp::TCPMsgBasedSendQueue::createSegmentWithBytes(), and inet::tcp::TcpLwipMsgBasedSendQueue::createSegmentWithBytes().

194 {
195  return payloadList.size();
196 }
PayloadList payloadList
Definition: TCPSegment.h:64
uint32_t inet::tcp::TCPSegment::getSegLen ( )
virtual

Returns RFC 793 specified SEG.LEN: SEG.LEN = the number of octets occupied by the data in the segment (counting SYN and FIN)

Referenced by inet::tcp::TCPConnection::segmentArrivalWhileClosed().

58 {
59  return payloadLength + (finBit ? 1 : 0) + (synBit ? 1 : 0);
60 }
bool finBit
Definition: TCPSegment_m.h:708
unsigned long payloadLength
Definition: TCPSegment_m.h:711
bool synBit
Definition: TCPSegment_m.h:707
virtual unsigned int inet::tcp::TCPSegment::getSourcePort ( ) const
inlineoverridevirtual

Implements inet::ITransportPacket.

Referenced by inet::ExampleQoSClassifier::getUserPriority().

149 { return TCPSegment_Base::getSrcPort(); }
virtual unsigned short getSrcPort() const
TCPSegment & inet::tcp::TCPSegment::operator= ( const TCPSegment other)
99 {
100  if (this == &other)
101  return *this;
102  clean();
104  copy(other);
105  return *this;
106 }
void clean()
Definition: TCPSegment.cc:121
void copy(const TCPSegment &other)
Definition: TCPSegment.cc:108
TCPSegment_Base & operator=(const TCPSegment_Base &other)
void inet::tcp::TCPSegment::parsimPack ( cCommBuffer *  b) const
overridevirtual
157 {
159  b->pack((int)headerOptionList.size());
160  for (const auto opt: headerOptionList) {
161  b->packObject(opt);
162  }
163  b->pack((int)payloadList.size());
164  for (PayloadList::const_iterator it = payloadList.begin(); it != payloadList.end(); it++) {
165  b->pack(it->endSequenceNo);
166  b->packObject(it->msg);
167  }
168 }
PayloadList payloadList
Definition: TCPSegment.h:64
OptionList headerOptionList
Definition: TCPSegment.h:66
value< double, units::m > b
Definition: Units.h:1054
virtual void parsimPack(omnetpp::cCommBuffer *b) const override
void inet::tcp::TCPSegment::parsimUnpack ( cCommBuffer *  b)
overridevirtual
171 {
173  int i, n;
174  b->unpack(n);
175  for (i = 0; i < n; i++) {
176  TCPOption *opt = check_and_cast<TCPOption*>(b->unpackObject());
177  headerOptionList.push_back(opt);
178  }
179  b->unpack(n);
180  for (i = 0; i < n; i++) {
181  TCPPayloadMessage payload;
182  b->unpack(payload.endSequenceNo);
183  payload.msg = check_and_cast<cPacket*>(b->unpackObject());
184  payloadList.push_back(payload);
185  }
186 }
PayloadList payloadList
Definition: TCPSegment.h:64
virtual void parsimUnpack(omnetpp::cCommBuffer *b) override
OptionList headerOptionList
Definition: TCPSegment.h:66
value< double, units::m > b
Definition: Units.h:1054
cPacket * inet::tcp::TCPSegment::removeFirstPayloadMessage ( uint32 outEndSequenceNo)
virtual

Removes and returns the first message object in this TCP segment.

It also returns the sequence number + 1 of its last octet in outEndSequenceNo.

Referenced by inet::tcp::TCPMsgBasedRcvQueue::insertBytesFromSegment(), and inet::tcp::TcpLwipMsgBasedReceiveQueue::notifyAboutIncomingSegmentProcessing().

224 {
225  if (payloadList.empty())
226  return nullptr;
227 
228  cPacket *msg = payloadList.front().msg;
229  endSequenceNo = payloadList.front().endSequenceNo;
230  payloadList.pop_front();
231  drop(msg);
232  return msg;
233 }
PayloadList payloadList
Definition: TCPSegment.h:64
virtual void inet::tcp::TCPSegment::setDestinationPort ( unsigned int  port)
inlineoverridevirtual

Implements inet::ITransportPacket.

virtual void setDestPort(unsigned short destPort)
void inet::tcp::TCPSegment::setHeaderOption ( unsigned int  k,
const TCPOptionPtr headerOption 
)
overridevirtual

Generated but unused method, should not be called.

Implements inet::tcp::TCPSegment_Base.

Referenced by inet::PacketDrillApp::runEvent().

256 {
257  throw cRuntimeError(this, "setHeaderOption() not supported, use addHeaderOption()");
258 }
void inet::tcp::TCPSegment::setHeaderOptionArraySize ( unsigned int  size)
overridevirtual

Generated but unused method, should not be called.

Implements inet::tcp::TCPSegment_Base.

241 {
242  throw cRuntimeError(this, "setHeaderOptionArraySize() not supported, use addHeaderOption()");
243 }
void inet::tcp::TCPSegment::setPayload ( unsigned int  k,
const TCPPayloadMessage payload_var 
)
overridevirtual

Generated but unused method, should not be called.

Implements inet::tcp::TCPSegment_Base.

209 {
210  throw cRuntimeError(this, "setPayload() not supported, use addPayloadMessage()");
211 }
void inet::tcp::TCPSegment::setPayloadArraySize ( unsigned int  size)
overridevirtual

Generated but unused method, should not be called.

Implements inet::tcp::TCPSegment_Base.

189 {
190  throw cRuntimeError(this, "setPayloadArraySize() not supported, use addPayloadMessage()");
191 }
virtual void inet::tcp::TCPSegment::setSourcePort ( unsigned int  port)
inlineoverridevirtual

Implements inet::ITransportPacket.

virtual void setSrcPort(unsigned short srcPort)
void inet::tcp::TCPSegment::truncateData ( unsigned int  truncleft,
unsigned int  truncright 
)
protectedvirtual

Truncate segment data.

Called from truncateSegment().

Parameters
truncleftnumber of bytes for truncate from begin of data
truncrightnumber of bytes for truncate from end of data
133 {
134  ASSERT(payloadLength >= truncleft + truncright);
135 
136  if (0 != byteArray.getDataArraySize())
137  byteArray.truncateData(truncleft, truncright);
138 
139  while (!payloadList.empty() && (payloadList.front().endSequenceNo - sequenceNo) <= truncleft) {
140  cPacket *msg = payloadList.front().msg;
141  payloadList.pop_front();
142  dropAndDelete(msg);
143  }
144 
145  sequenceNo += truncleft;
146  payloadLength -= truncleft + truncright;
147 
148  // truncate payload data correctly
149  while (!payloadList.empty() && (payloadList.back().endSequenceNo - sequenceNo) > payloadLength) {
150  cPacket *msg = payloadList.back().msg;
151  payloadList.pop_back();
152  dropAndDelete(msg);
153  }
154 }
unsigned int sequenceNo
Definition: TCPSegment_m.h:700
ByteArray byteArray
Definition: TCPSegment_m.h:712
PayloadList payloadList
Definition: TCPSegment.h:64
virtual unsigned int getDataArraySize() const
unsigned long payloadLength
Definition: TCPSegment_m.h:711
virtual void truncateData(unsigned int truncleft, unsigned int truncright)
Truncate data content.
Definition: ByteArray.cc:90
void inet::tcp::TCPSegment::truncateSegment ( uint32  firstSeqNo,
uint32  endSeqNo 
)
virtual

Truncate segment.

Parameters
firstSeqNosequence no of new first byte
endSeqNosequence no of new last byte + 1

Referenced by inet::tcp::TCPConnection::processSegment1stThru8th().

63 {
64  ASSERT(payloadLength > 0);
65 
66  // must have common part:
67 #ifndef NDEBUG
68  if (!(seqLess(sequenceNo, endSeqNo) && seqLess(firstSeqNo, sequenceNo + payloadLength))) {
69  throw cRuntimeError(this, "truncateSegment(%u,%u) called on [%u, %u) segment\n",
70  firstSeqNo, endSeqNo, sequenceNo, sequenceNo + payloadLength);
71  }
72 #endif // ifndef NDEBUG
73 
74  unsigned int truncleft = 0;
75  unsigned int truncright = 0;
76 
77  if (seqLess(sequenceNo, firstSeqNo)) {
78  truncleft = firstSeqNo - sequenceNo;
79  }
80 
81  if (seqGreater(sequenceNo + payloadLength, endSeqNo)) {
82  truncright = sequenceNo + payloadLength - endSeqNo;
83  }
84 
85  truncateData(truncleft, truncright);
86 }
unsigned int sequenceNo
Definition: TCPSegment_m.h:700
unsigned long payloadLength
Definition: TCPSegment_m.h:711
bool seqLess(uint32 a, uint32 b)
Definition: TCPSegment.h:32
bool seqGreater(uint32 a, uint32 b)
Definition: TCPSegment.h:34
virtual void truncateData(unsigned int truncleft, unsigned int truncright)
Truncate segment data.
Definition: TCPSegment.cc:132

Member Data Documentation

OptionList inet::tcp::TCPSegment::headerOptionList
protected

Referenced by copy().

PayloadList inet::tcp::TCPSegment::payloadList
protected

Referenced by copy().


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