INET Framework for OMNeT++/OMNEST
queues/TCPVirtualDataSendQueue.cc
Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2004 Andras Varga
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 
00019 #include "TCPVirtualDataSendQueue.h"
00020 
00021 Register_Class(TCPVirtualDataSendQueue);
00022 
00023 TCPVirtualDataSendQueue::TCPVirtualDataSendQueue() : TCPSendQueue()
00024 {
00025     begin = end = 0;
00026 }
00027 
00028 TCPVirtualDataSendQueue::~TCPVirtualDataSendQueue()
00029 {
00030 }
00031 
00032 void TCPVirtualDataSendQueue::init(uint32 startSeq)
00033 {
00034     begin = startSeq;
00035     end = startSeq;
00036 }
00037 
00038 std::string TCPVirtualDataSendQueue::info() const
00039 {
00040     std::stringstream out;
00041     out << "[" << begin << ".." << end << ")";
00042     return out.str();
00043 }
00044 
00045 void TCPVirtualDataSendQueue::enqueueAppData(cPacket *msg)
00046 {
00047     //tcpEV << "sendQ: " << info() << " enqueueAppData(bytes=" << msg->getByteLength() << ")\n";
00048     end += msg->getByteLength();
00049     delete msg;
00050 }
00051 
00052 uint32 TCPVirtualDataSendQueue::getBufferStartSeq()
00053 {
00054     return begin;
00055 }
00056 
00057 uint32 TCPVirtualDataSendQueue::getBufferEndSeq()
00058 {
00059     return end;
00060 }
00061 
00062 TCPSegment *TCPVirtualDataSendQueue::createSegmentWithBytes(uint32 fromSeq, ulong numBytes)
00063 {
00064     //tcpEV << "sendQ: " << info() << " createSeg(seq=" << fromSeq << " len=" << numBytes << ")\n";
00065     ASSERT(seqLE(begin,fromSeq) && seqLE(fromSeq+numBytes,end));
00066 
00067     char msgname[32];
00068     sprintf(msgname, "tcpseg(l=%lu)", numBytes);
00069 
00070     TCPSegment *tcpseg = conn->createTCPSegment(msgname);
00071     tcpseg->setSequenceNo(fromSeq);
00072     tcpseg->setPayloadLength(numBytes);
00073     return tcpseg;
00074 }
00075 
00076 void TCPVirtualDataSendQueue::discardUpTo(uint32 seqNum)
00077 {
00078     //tcpEV << "sendQ: " << info() << " discardUpTo(seq=" << seqNum << ")\n";
00079     ASSERT(seqLE(begin,seqNum) && seqLE(seqNum,end));
00080     begin = seqNum;
00081 }
00082