|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright (C) 2004 Andras Varga 00003 // 2009 Zoltan Bojthe 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this program; if not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 #ifdef WITH_TCP_NSC 00020 00021 #include <omnetpp.h> 00022 00023 #include "TCP_NSC_VirtualDataQueues.h" 00024 00025 #include "TCPCommand_m.h" 00026 #include "TCP_NSC_Connection.h" 00027 #include "TCPSerializer.h" 00028 00029 00030 Register_Class(TCP_NSC_VirtualDataSendQueue); 00031 00032 Register_Class(TCP_NSC_VirtualDataReceiveQueue); 00033 00034 00038 TCP_NSC_VirtualDataSendQueue::TCP_NSC_VirtualDataSendQueue() 00039 : 00040 unsentNscBytesM(0) 00041 { 00042 } 00043 00047 TCP_NSC_VirtualDataSendQueue::~TCP_NSC_VirtualDataSendQueue() 00048 { 00049 } 00050 00054 void TCP_NSC_VirtualDataSendQueue::setConnection(TCP_NSC_Connection *connP) 00055 { 00056 unsentNscBytesM = 0; 00057 TCP_NSC_SendQueue::setConnection(connP); 00058 } 00059 00068 void TCP_NSC_VirtualDataSendQueue::enqueueAppData(cPacket *msgP) 00069 { 00070 ASSERT(msgP); 00071 00072 int bytes = msgP->getByteLength(); 00073 delete msgP; 00074 00075 unsentNscBytesM += bytes; 00076 } 00077 00085 int TCP_NSC_VirtualDataSendQueue::getNscMsg(void* bufferP, int bufferLengthP) 00086 { 00087 ASSERT(bufferP); 00088 00089 return (unsentNscBytesM > bufferLengthP) ? bufferLengthP : unsentNscBytesM; 00090 } 00091 00099 void TCP_NSC_VirtualDataSendQueue::dequeueNscMsg(int msgLengthP) 00100 { 00101 ASSERT(msgLengthP <= unsentNscBytesM); 00102 00103 unsentNscBytesM -= msgLengthP; 00104 } 00105 00109 ulong TCP_NSC_VirtualDataSendQueue::getBytesAvailable() 00110 { 00111 return unsentNscBytesM; // TODO 00112 } 00113 00124 TCPSegment* TCP_NSC_VirtualDataSendQueue::createSegmentWithBytes( 00125 const void* tcpDataP, int tcpLengthP) 00126 { 00127 ASSERT(tcpDataP); 00128 00129 TCPSegment *tcpseg = new TCPSegment("tcp-segment"); 00130 00131 TCPSerializer().parse((const unsigned char *)tcpDataP, tcpLengthP, tcpseg); 00132 00133 return tcpseg; 00134 } 00135 00140 void TCP_NSC_VirtualDataSendQueue::discardUpTo(uint32 seqNumP) 00141 { 00142 // nothing to do here 00143 } 00144 00148 TCP_NSC_VirtualDataReceiveQueue::TCP_NSC_VirtualDataReceiveQueue() 00149 : 00150 bytesInQueueM(0) 00151 { 00152 } 00153 00157 TCP_NSC_VirtualDataReceiveQueue::~TCP_NSC_VirtualDataReceiveQueue() 00158 { 00159 // nothing to do here 00160 } 00161 00165 void TCP_NSC_VirtualDataReceiveQueue::setConnection(TCP_NSC_Connection *connP) 00166 { 00167 ASSERT(connP); 00168 00169 bytesInQueueM = 0; 00170 TCP_NSC_ReceiveQueue::setConnection(connP); 00171 } 00172 00184 uint32 TCP_NSC_VirtualDataReceiveQueue::insertBytesFromSegment( 00185 const TCPSegment *tcpsegP, void* bufferP, size_t bufferLengthP) 00186 { 00187 ASSERT(tcpsegP); 00188 ASSERT(bufferP); 00189 00190 return TCPSerializer().serialize(tcpsegP, (unsigned char *)bufferP, bufferLengthP); 00191 } 00192 00199 void TCP_NSC_VirtualDataReceiveQueue::enqueueNscData(void* dataP, int dataLengthP) 00200 { 00201 bytesInQueueM += dataLengthP; 00202 } 00203 00211 cPacket* TCP_NSC_VirtualDataReceiveQueue::extractBytesUpTo() 00212 { 00213 ASSERT(connM); 00214 00215 cPacket *dataMsg = NULL; 00216 if(bytesInQueueM) 00217 { 00218 dataMsg = new cPacket("DATA"); 00219 dataMsg->setKind(TCP_I_DATA); 00220 dataMsg->setByteLength(bytesInQueueM); 00221 TCPConnectInfo *tcpConnectInfo = new TCPConnectInfo(); 00222 tcpConnectInfo->setConnId(connM->connIdM); 00223 tcpConnectInfo->setLocalAddr(connM->inetSockPairM.localM.ipAddrM); 00224 tcpConnectInfo->setRemoteAddr(connM->inetSockPairM.remoteM.ipAddrM); 00225 tcpConnectInfo->setLocalPort(connM->inetSockPairM.localM.portM); 00226 tcpConnectInfo->setRemotePort(connM->inetSockPairM.remoteM.portM); 00227 dataMsg->setControlInfo(tcpConnectInfo); 00228 bytesInQueueM -= dataMsg->getByteLength(); 00229 } 00230 return dataMsg; 00231 } 00232 00236 uint32 TCP_NSC_VirtualDataReceiveQueue::getAmountOfBufferedBytes() 00237 { 00238 return bytesInQueueM; 00239 } 00240 00244 uint32 TCP_NSC_VirtualDataReceiveQueue::getQueueLength() 00245 { 00246 return bytesInQueueM ? 1 : 0; 00247 } 00248 00252 void TCP_NSC_VirtualDataReceiveQueue::getQueueStatus() 00253 { 00254 // TODO 00255 } 00256 00263 void TCP_NSC_VirtualDataReceiveQueue::notifyAboutSending(const TCPSegment *tcpsegP) 00264 { 00265 // nothing to do 00266 } 00267 00268 #endif // WITH_TCP_NSC