#include <TCPMsgBasedSendQueue.h>
Inheritance diagram for TCPMsgBasedSendQueue:
Public Member Functions | |
TCPMsgBasedSendQueue () | |
virtual | ~TCPMsgBasedSendQueue () |
virtual void | init (uint32 startSeq) |
virtual std::string | info () const |
virtual void | enqueueAppData (cMessage *msg) |
virtual uint32 | bufferEndSeq () |
virtual TCPSegment * | createSegmentWithBytes (uint32 fromSeq, ulong numBytes) |
virtual void | discardUpTo (uint32 seqNum) |
Protected Types | |
typedef std::list< Payload > | PayloadQueue |
Protected Attributes | |
PayloadQueue | payloadQueue |
uint32 | begin |
uint32 | end |
Classes | |
struct | Payload |
typedef std::list<Payload> TCPMsgBasedSendQueue::PayloadQueue [protected] |
TCPMsgBasedSendQueue::TCPMsgBasedSendQueue | ( | ) |
TCPMsgBasedSendQueue::~TCPMsgBasedSendQueue | ( | ) | [virtual] |
Virtual dtor.
00030 { 00031 for (PayloadQueue::iterator it=payloadQueue.begin(); it!=payloadQueue.end(); ++it) 00032 delete it->msg; 00033 }
uint32 TCPMsgBasedSendQueue::bufferEndSeq | ( | ) | [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.)
Implements TCPSendQueue.
00060 { 00061 return end; 00062 }
TCPSegment * TCPMsgBasedSendQueue::createSegmentWithBytes | ( | uint32 | fromSeq, | |
ulong | 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 then maxNumBytes bytes if the subclass wants to reproduce the original segment boundaries when retransmitting.
Implements TCPSendQueue.
00065 { 00066 //tcpEV << "sendQ: " << info() << " createSeg(seq=" << fromSeq << " len=" << numBytes << ")\n"; 00067 ASSERT(seqLE(begin,fromSeq) && seqLE(fromSeq+numBytes,end)); 00068 00069 TCPSegment *tcpseg = new TCPSegment(); 00070 tcpseg->setSequenceNo(fromSeq); 00071 tcpseg->setPayloadLength(numBytes); 00072 00073 // add payload messages whose endSequenceNo is between fromSeq and fromSeq+numBytes 00074 PayloadQueue::iterator i = payloadQueue.begin(); 00075 while (i!=payloadQueue.end() && seqLE(i->endSequenceNo, fromSeq)) 00076 ++i; 00077 uint32 toSeq = fromSeq+numBytes; 00078 const char *payloadName = NULL; 00079 while (i!=payloadQueue.end() && seqLE(i->endSequenceNo, toSeq)) 00080 { 00081 if (!payloadName) payloadName = i->msg->name(); 00082 tcpseg->addPayloadMessage((cMessage *)i->msg->dup(), i->endSequenceNo); 00083 ++i; 00084 } 00085 00086 // give segment a name 00087 char msgname[80]; 00088 if (!payloadName) 00089 sprintf(msgname, "tcpseg(l=%lu,%dmsg)", numBytes, tcpseg->payloadArraySize()); 00090 else 00091 sprintf(msgname, "%.10s(l=%lu,%dmsg)", payloadName, numBytes, tcpseg->payloadArraySize()); 00092 tcpseg->setName(msgname); 00093 00094 return tcpseg; 00095 }
void TCPMsgBasedSendQueue::discardUpTo | ( | uint32 | 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.
Implements TCPSendQueue.
00098 { 00099 //tcpEV << "sendQ: " << info() << " discardUpTo(seq=" << seqNum << ")\n"; 00100 ASSERT(seqLE(begin,seqNum) && seqLE(seqNum,end)); 00101 begin = seqNum; 00102 00103 // remove payload messages whose endSequenceNo is below seqNum 00104 while (!payloadQueue.empty() && seqLE(payloadQueue.front().endSequenceNo, seqNum)) 00105 { 00106 delete payloadQueue.front().msg; 00107 payloadQueue.pop_front(); 00108 } 00109 }
void TCPMsgBasedSendQueue::enqueueAppData | ( | cMessage * | 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.)
Implements TCPSendQueue.
00049 { 00050 //tcpEV << "sendQ: " << info() << " enqueueAppData(bytes=" << msg->byteLength() << ")\n"; 00051 end += msg->byteLength(); 00052 00053 Payload payload; 00054 payload.endSequenceNo = end; 00055 payload.msg = msg; 00056 payloadQueue.push_back(payload); 00057 }
std::string TCPMsgBasedSendQueue::info | ( | ) | const [virtual] |
Returns a string with the region stored.
00042 { 00043 std::stringstream out; 00044 out << "[" << begin << ".." << end << "), " << payloadQueue.size() << " packets"; 00045 return out.str(); 00046 }
void TCPMsgBasedSendQueue::init | ( | uint32 | 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.
Implements TCPSendQueue.
uint32 TCPMsgBasedSendQueue::begin [protected] |
uint32 TCPMsgBasedSendQueue::end [protected] |
PayloadQueue TCPMsgBasedSendQueue::payloadQueue [protected] |