312 TCP_NSC_Connection::SockPair nscSockPair, inetSockPair, inetSockPairAny;
314 cObject *ctrl = tcpsegP->removeControlInfo();
316 throw cRuntimeError(
"(%s)%s arrived without control info", tcpsegP->getClassName(), tcpsegP->getName());
318 INetworkProtocolControlInfo *controlInfo = check_and_cast<INetworkProtocolControlInfo *>(ctrl);
319 inetSockPair.remoteM.ipAddrM = controlInfo->getSourceAddress();
320 inetSockPair.localM.ipAddrM = controlInfo->getDestinationAddress();
323 if (dynamic_cast<IPv6ControlInfo *>(ctrl) !=
nullptr) {
327 unsigned short numOptions = tcpsegP->getHeaderOptionArraySize();
328 for (
unsigned short i = 0; i < numOptions; i++) {
329 TCPOption* option = tcpsegP->getHeaderOption(i);
331 TCPOptionMaxSegmentSize *mssOption =
dynamic_cast<TCPOptionMaxSegmentSize *
>(option);
333 unsigned int value = mssOption->getMaxSegmentSize();
334 value -=
sizeof(
struct nsc_ipv6hdr) - sizeof(struct nsc_iphdr);
335 mssOption->setMaxSegmentSize(value);
350 inetSockPair.remoteM.portM = tcpsegP->getSrcPort();
351 inetSockPair.localM.portM = tcpsegP->getDestPort();
352 nscSockPair.remoteM.portM = tcpsegP->getSrcPort();
353 nscSockPair.localM.portM = tcpsegP->getDestPort();
354 inetSockPairAny.localM = inetSockPair.localM;
357 size_t ipHdrLen =
sizeof(nsc_iphdr);
358 size_t const maxBufferSize = 4096;
359 char *data =
new char[maxBufferSize];
360 memset(data, 0, maxBufferSize);
361 uint32_t nscSrcAddr =
mapRemote2Nsc(inetSockPair.remoteM.ipAddrM);
363 nscSockPair.remoteM.ipAddrM.
set(IPv4Address(nscSrcAddr));
365 EV_DETAIL <<
this <<
": data arrived for interface of stack " <<
pStackM <<
"\n" 366 <<
" src:" << inetSockPair.remoteM.ipAddrM <<
",dest:" << inetSockPair.localM.ipAddrM <<
"\n";
368 nsc_iphdr *ih = (nsc_iphdr *)data;
369 tcphdr *tcph = (tcphdr *)(data + ipHdrLen);
372 ih->ihl = ipHdrLen / 4;
374 ih->id =
htons(tcpsegP->getSequenceNo());
375 ih->frag_off =
htons(0x4000);
379 ih->saddr =
htonl(nscSrcAddr);
382 EV_DEBUG <<
this <<
": modified to: IP " << ih->version <<
" len " << ih->ihl
383 <<
" protocol " << (
unsigned int)(ih->protocol)
384 <<
" saddr " << (ih->saddr)
385 <<
" daddr " << (ih->daddr)
388 size_t totalTcpLen = maxBufferSize - ipHdrLen;
389 TCP_NSC_Connection *conn;
397 Buffer
b(tcph, totalTcpLen);
399 c.l3AddressesPtr = &ih->saddr;
400 c.l3AddressesLength = 8;
401 TCPSerializer().serializePacket(tcpsegP,
b, c);
402 totalTcpLen =
b.getPos();
406 conn->receiveQueueM->notifyAboutIncomingSegmentProcessing(tcpsegP);
409 size_t totalIpLen = ipHdrLen + totalTcpLen;
410 ih->tot_len =
htons(totalIpLen);
416 pStackM->if_receive_packet(0, data, totalIpLen);
422 TCP_NSC_Connection& c = elem.second;
424 if (c.pNscSocketM && c.isListenerM) {
426 EV_DETAIL <<
this <<
": NSC: attempting to accept:\n";
428 INetStreamSocket *sock =
nullptr;
431 err = c.pNscSocketM->accept(&sock);
433 EV_DETAIL <<
this <<
": accept returned " << err <<
" , sock is " << sock
434 <<
" socket" << c.pNscSocketM <<
"\n";
437 ASSERT(changes == 0);
438 ASSERT(c.inetSockPairM.localM.portM == inetSockPair.localM.portM);
441 int newConnId = getEnvir()->getUniqueNumber();
443 TCP_NSC_Connection *conn = &tcpAppConnMapM[newConnId];
444 conn->tcpNscM =
this;
445 conn->connIdM = newConnId;
446 conn->appGateIndexM = c.appGateIndexM;
447 conn->pNscSocketM = sock;
453 const char *sendQueueClass = c.sendQueueM->getClassName();
455 conn->sendQueueM->setConnection(conn);
457 const char *receiveQueueClass = c.receiveQueueM->getClassName();
459 conn->receiveQueueM->setConnection(conn);
460 EV_DETAIL <<
this <<
": NSC: got accept!\n";
465 else if (c.pNscSocketM && !c.disconnectCalledM && c.pNscSocketM->is_connected()) {
466 bool hasData =
false;
467 int err = NSC_EAGAIN;
468 EV_DEBUG <<
this <<
": NSC: attempting to read from socket " << c.pNscSocketM <<
"\n";
470 if ((!c.sentEstablishedM) && c.pNscSocketM->is_connected()) {
471 ASSERT(changes == 0);
478 static char buf[4096];
480 int buflen =
sizeof(buf);
482 err = c.pNscSocketM->read_data(buf, &buflen);
484 EV_DEBUG <<
this <<
": NSC: read: err " << err <<
" , buflen " << buflen <<
"\n";
486 if (err == 0 && buflen > 0) {
487 ASSERT(changes == 0);
492 c.receiveQueueM->enqueueNscData(buf, buflen);
Definition: TCPSegment_m.h:114
TCP_NSC_Connection * findConnByInetSockPair(TCP_NSC_Connection::SockPair const &sockPairP)
Definition: TCP_NSC.cc:704
INetStack * pStackM
Definition: TCP_NSC.h:161
cOutVector * rcvSeqVector
Definition: TCP_NSC.h:182
static const L3Address localInnerIpS
Definition: TCP_NSC.h:171
void set(AddressType type, uint64 lo)
Definition: L3Address.cc:37
static uint16_t checksum(const void *addr, unsigned int count)
Definition: TCPIPchecksum.h:44
void changeAddresses(TCP_NSC_Connection &connP, const TCP_NSC_Connection::SockPair &inetSockPairP, const TCP_NSC_Connection::SockPair &nscSockPairP)
Definition: TCP_NSC.cc:287
cObject * createOne(const char *className, const char *defaultNamespace)
Like cObjectFactory::createOne(), except it starts searching for the class in the given namespace...
Definition: INETUtils.cc:105
void sendDataToApp(TCP_NSC_Connection &c)
Definition: TCP_NSC.cc:521
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
cOutVector * rcvAckVector
Definition: TCP_NSC.h:183
void sendErrorNotificationToApp(TCP_NSC_Connection &c, int err)
Definition: TCP_NSC.cc:538
u_int32_t mapRemote2Nsc(L3Address const &addrP)
Definition: TCP_NSC.cc:170
uint32 getInt() const
Returns the address as an int.
Definition: IPv4Address.h:197
IPv4Address toIPv4() const
Definition: L3Address.h:76
value< double, units::m > b
Definition: Units.h:1054
void sendEstablishedMsg(TCP_NSC_Connection &connP)
Definition: TCP_NSC.cc:269
TcpAppConnMap tcpAppConnMapM
Definition: TCP_NSC.h:154