#include <SimpleUDP.h>
More info in the NED file.
Definition at line 63 of file SimpleUDP.h.
Public Types | |
| typedef std::list< SockDesc * > | SockDescList |
| list of socket pointers | |
| typedef std::map< int, SockDesc * > | SocketsByIdMap |
| list of socket ordered by sockId | |
| typedef std::map< int, SockDescList > | SocketsByPortMap |
| list of sockets ordered by localPort | |
Public Member Functions | |
| void | setNodeEntry (SimpleNodeEntry *entry) |
| set or change the nodeEntry of this module | |
| SimpleUDP () | |
| virtual | ~SimpleUDP () |
| destructor | |
Protected Member Functions | |
| void | updateDisplayString () |
| utility: show current statistics above the icon | |
| void | bind (int gateIndex, UDPControlInfo *ctrl) |
| bind socket | |
| void | connect (int sockId, IPvXAddress addr, int port) |
| connect socket | |
| void | unbind (int sockId) |
| unbind socket | |
| short | getEphemeralPort () |
| ephemeral port. | |
| bool | matchesSocket (SockDesc *sd, SimpleUDPPacket *udp, IPControlInfo *ctrl) |
| decides if a received packet (IPv4) belongs to the specified socket | |
| bool | matchesSocket (SockDesc *sd, SimpleUDPPacket *udp, IPv6ControlInfo *ctrl) |
| decides if a received packet (IPv6) belongs to the specified socket | |
| bool | matchesSocket (SockDesc *sd, const IPvXAddress &localAddr, const IPvXAddress &remoteAddr, short remotePort) |
| decides if a socket matches the specified parameters | |
| void | sendUp (cMessage *payload, SimpleUDPPacket *udpHeader, IPControlInfo *ctrl, SockDesc *sd) |
| sends payload up to the application | |
| void | sendUp (cMessage *payload, SimpleUDPPacket *udpHeader, IPv6ControlInfo *ctrl, SockDesc *sd) |
| sends payload up to the application | |
| void | processUndeliverablePacket (SimpleUDPPacket *udpPacket, cPolymorphic *ctrl) |
| handles received packet which destination port is not bound to any socket | |
| void | sendUpErrorNotification (SockDesc *sd, int msgkind, const IPvXAddress &localAddr, const IPvXAddress &remoteAddr, short remotePort) |
| sends an error up to the application | |
| virtual void | processICMPError (cMessage *icmpErrorMsg) |
| process an ICMP error packet | |
| virtual void | processUDPPacket (SimpleUDPPacket *udpPacket) |
| process UDP packets coming from IP | |
| virtual void | processMsgFromApp (cPacket *appData) |
| process packets from application | |
| virtual void | processCommandFromApp (cMessage *msg) |
| process commands from application | |
| virtual void | initialize (int stage) |
| initialise the SimpleUDP module | |
| virtual int | numInitStages () const |
| returns the number of init stages | |
| virtual void | handleMessage (cMessage *msg) |
| process received messages | |
| void | finish () |
Protected Attributes | |
| SocketsByIdMap | socketsByIdMap |
| list of socket ordered by sockId | |
| SocketsByPortMap | socketsByPortMap |
| list of sockets ordered by localPort | |
| short | lastEphemeralPort |
| last used port (all ports above should be free) | |
| ICMP * | icmp |
| pointer to a received icmp (IPv4) message | |
| ICMPv6 * | icmpv6 |
| pointer to a received icmp (IPv6) message | |
| int | numSent |
| number of packets sent to the network | |
| int | numPassedUp |
| number of packet passed up to applications | |
| int | numDroppedWrongPort |
| number of dropped packets due to wrong destination port | |
| int | numDroppedBadChecksum |
| number of dropped packets due to bad checksum | |
| int | numQueueLost |
| number of lost packets due to queue full | |
| int | numPartitionLost |
| number of lost packets due to network partitions | |
| int | numDestUnavailableLost |
| number of lost packets due to unavailable destination | |
| simtime_t | delay |
| simulated delay between sending and receiving udp module | |
| simtime_t | constantDelay |
| constant delay between two peers | |
| bool | useCoordinateBasedDelay |
| delay should be calculated from euklidean distance between two peers | |
| double | jitter |
| amount of jitter in % of total delay | |
| GlobalNodeList * | globalNodeList |
| pointer to GlobalNodeList | |
| GlobalStatistics * | globalStatistics |
| pointer to GlobalStatistics | |
| SimpleNodeEntry * | nodeEntry |
| nodeEntry of the overlay node this module belongs to | |
Classes | |
| struct | SockDesc |
| defines a socket More... | |
| typedef std::list<SockDesc *> SimpleUDP::SockDescList |
| typedef std::map<int,SockDesc *> SimpleUDP::SocketsByIdMap |
| typedef std::map<int,SockDescList> SimpleUDP::SocketsByPortMap |
| SimpleUDP::SimpleUDP | ( | ) |
| SimpleUDP::~SimpleUDP | ( | ) | [virtual] |
destructor
Definition at line 95 of file SimpleUDP.cc.
00096 { 00097 for (SocketsByIdMap::iterator i=socketsByIdMap.begin(); 00098 i!=socketsByIdMap.end(); ++i) 00099 delete i->second; 00100 }
| void SimpleUDP::setNodeEntry | ( | SimpleNodeEntry * | entry | ) |
set or change the nodeEntry of this module
| entry | the new nodeEntry |
Definition at line 729 of file SimpleUDP.cc.
Referenced by SimpleUnderlayConfigurator::createNode(), and SimpleUnderlayConfigurator::migrateNode().
00730 { 00731 nodeEntry = entry; 00732 }
| void SimpleUDP::updateDisplayString | ( | ) | [protected] |
utility: show current statistics above the icon
Definition at line 280 of file SimpleUDP.cc.
Referenced by handleMessage().
00281 { 00282 char buf[80]; 00283 sprintf(buf, "passed up: %d pks\nsent: %d pks", numPassedUp, numSent); 00284 if (numDroppedWrongPort>0) { 00285 sprintf(buf+strlen(buf), "\ndropped (no app): %d pks", numDroppedWrongPort); 00286 getDisplayString().setTagArg("i",1,"red"); 00287 } 00288 if (numQueueLost>0) { 00289 sprintf(buf+strlen(buf), "\nlost (queue overflow): %d pks", numQueueLost); 00290 getDisplayString().setTagArg("i",1,"red"); 00291 } 00292 getDisplayString().setTagArg("t",0,buf); 00293 }
| void SimpleUDP::bind | ( | int | gateIndex, | |
| UDPControlInfo * | ctrl | |||
| ) | [protected] |
bind socket
| gateIndex | application gate connected to the socket | |
| ctrl | control information for communication |
Definition at line 151 of file SimpleUDP.cc.
Referenced by processCommandFromApp().
00152 { 00153 // XXX checks could be added, of when the bind should be allowed to proceed 00154 00155 if (ctrl->getSrcPort() <= 0 || ctrl->getSrcPort() > 65535) 00156 opp_error("bind: invalid src port number %d", ctrl->getSrcPort()); 00157 00158 // create and fill in SockDesc 00159 SockDesc *sd = new SockDesc(); 00160 sd->sockId = ctrl->getSockId(); 00161 sd->userId = ctrl->getUserId(); 00162 sd->appGateIndex = gateIndex; 00163 sd->localAddr = ctrl->getSrcAddr(); 00164 sd->remoteAddr = ctrl->getDestAddr(); 00165 sd->localPort = ctrl->getSrcPort(); 00166 sd->remotePort = ctrl->getDestPort(); 00167 sd->interfaceId = ctrl->getInterfaceId(); 00168 00169 if (sd->sockId==-1) 00170 error("sockId in BIND message not filled in"); 00171 if (sd->localPort==0) 00172 sd->localPort = getEphemeralPort(); 00173 00174 sd->onlyLocalPortIsSet = sd->localAddr.isUnspecified() && 00175 sd->remoteAddr.isUnspecified() && 00176 sd->remotePort==0 && 00177 sd->interfaceId==-1; 00178 00179 cModule *node = getParentModule(); 00180 IPvXAddress ip = IPAddressResolver().addressOf(node); 00181 EV << "[SimpleUDP::bind() @ " << ip << "]\n" 00182 << " Binding socket: " << *sd 00183 << endl; 00184 00185 // add to socketsByIdMap 00186 ASSERT(socketsByIdMap.find(sd->sockId)==socketsByIdMap.end()); 00187 socketsByIdMap[sd->sockId] = sd; 00188 00189 // add to socketsByPortMap 00190 // create if doesn't exist 00191 SockDescList& list = socketsByPortMap[sd->localPort]; 00192 list.push_back(sd); 00193 }
| void SimpleUDP::connect | ( | int | sockId, | |
| IPvXAddress | addr, | |||
| int | port | |||
| ) | [protected] |
connect socket
| sockId | id of the socket to connect | |
| addr | IPvXAddress of the remote socket | |
| port | port of the remote socket |
Definition at line 195 of file SimpleUDP.cc.
Referenced by processCommandFromApp().
00196 { 00197 SocketsByIdMap::iterator it = socketsByIdMap.find(sockId); 00198 if (it==socketsByIdMap.end()) 00199 error("socket id=%d doesn't exist (already closed?)", sockId); 00200 if (addr.isUnspecified()) 00201 opp_error("connect: unspecified remote address"); 00202 if (port<=0 || port>65535) 00203 opp_error("connect: invalid remote port number %d", port); 00204 00205 SockDesc *sd = it->second; 00206 sd->remoteAddr = addr; 00207 sd->remotePort = port; 00208 00209 sd->onlyLocalPortIsSet = false; 00210 00211 EV << "[SimpleUDP::connect() @ " << sd->localAddr << "]\n" 00212 << " Connecting socket: " << *sd 00213 << endl; 00214 }
| void SimpleUDP::unbind | ( | int | sockId | ) | [protected] |
unbind socket
| sockId | id of the socket to unbind |
Definition at line 216 of file SimpleUDP.cc.
Referenced by processCommandFromApp().
00217 { 00218 // remove from socketsByIdMap 00219 SocketsByIdMap::iterator it = socketsByIdMap.find(sockId); 00220 if (it==socketsByIdMap.end()) 00221 error("socket id=%d doesn't exist (already closed?)", sockId); 00222 SockDesc *sd = it->second; 00223 socketsByIdMap.erase(it); 00224 00225 EV << "[SimpleUDP::unbind() @ " << sd->localAddr << "]\n" 00226 << " Unbinding socket: " << *sd 00227 << endl; 00228 00229 // remove from socketsByPortMap 00230 SockDescList& list = socketsByPortMap[sd->localPort]; 00231 for (SockDescList::iterator it=list.begin(); it!=list.end(); ++it) 00232 if (*it == sd) { 00233 list.erase(it); 00234 break; 00235 } 00236 if (list.empty()) 00237 socketsByPortMap.erase(sd->localPort); 00238 delete sd; 00239 }
| short SimpleUDP::getEphemeralPort | ( | ) | [protected] |
ephemeral port.
Definition at line 241 of file SimpleUDP.cc.
Referenced by bind().
00242 { 00243 // start at the last allocated port number + 1, and search for an unused one 00244 short searchUntil = lastEphemeralPort++; 00245 if (lastEphemeralPort == EPHEMERAL_PORTRANGE_END) // wrap 00246 lastEphemeralPort = EPHEMERAL_PORTRANGE_START; 00247 00248 while (socketsByPortMap.find(lastEphemeralPort)!=socketsByPortMap.end()) { 00249 if (lastEphemeralPort == searchUntil) // got back to starting point? 00250 error("Ephemeral port range %d..%d exhausted, all ports occupied", EPHEMERAL_PORTRANGE_START, EPHEMERAL_PORTRANGE_END); 00251 lastEphemeralPort++; 00252 if (lastEphemeralPort == EPHEMERAL_PORTRANGE_END) // wrap 00253 lastEphemeralPort = EPHEMERAL_PORTRANGE_START; 00254 } 00255 00256 // found a free one, return it 00257 return lastEphemeralPort; 00258 }
| bool SimpleUDP::matchesSocket | ( | SockDesc * | sd, | |
| SimpleUDPPacket * | udp, | |||
| IPControlInfo * | ctrl | |||
| ) | [protected] |
decides if a received packet (IPv4) belongs to the specified socket
| sd | the socket | |
| udp | the received SimpleUDPPacket | |
| ctrl | the IPControlInfo of udp |
Definition at line 295 of file SimpleUDP.cc.
Referenced by processICMPError(), and processUDPPacket().
00296 { 00297 // IPv4 version 00298 if (sd->remotePort!=0 && sd->remotePort!=udp->getSourcePort()) 00299 return false; 00300 if (!sd->localAddr.isUnspecified() && sd->localAddr.get4()!=ipCtrl->getDestAddr()) 00301 return false; 00302 if (!sd->remoteAddr.isUnspecified() && sd->remoteAddr.get4()!=ipCtrl->getSrcAddr()) 00303 return false; 00304 if (sd->interfaceId!=-1 && sd->interfaceId!=ipCtrl->getInterfaceId()) 00305 return false; 00306 return true; 00307 }
| bool SimpleUDP::matchesSocket | ( | SockDesc * | sd, | |
| SimpleUDPPacket * | udp, | |||
| IPv6ControlInfo * | ctrl | |||
| ) | [protected] |
decides if a received packet (IPv6) belongs to the specified socket
| sd | the socket | |
| udp | the received SimpleUDPPacket | |
| ctrl | the IPControlInfo of udp |
Definition at line 309 of file SimpleUDP.cc.
00310 { 00311 // IPv6 version 00312 if (sd->remotePort!=0 && sd->remotePort!=udp->getSourcePort()) 00313 return false; 00314 if (!sd->localAddr.isUnspecified() && sd->localAddr.get6()!=ipCtrl->getDestAddr()) 00315 return false; 00316 if (!sd->remoteAddr.isUnspecified() && sd->remoteAddr.get6()!=ipCtrl->getSrcAddr()) 00317 return false; 00318 if (sd->interfaceId!=-1 && sd->interfaceId!=ipCtrl->getInterfaceId()) 00319 return false; 00320 return true; 00321 }
| bool SimpleUDP::matchesSocket | ( | SockDesc * | sd, | |
| const IPvXAddress & | localAddr, | |||
| const IPvXAddress & | remoteAddr, | |||
| short | remotePort | |||
| ) | [protected] |
decides if a socket matches the specified parameters
| sd | the socket | |
| localAddr | the specified localAddr | |
| remoteAddr | the specified remoteAddr | |
| remotePort | the specified remotePort |
Definition at line 323 of file SimpleUDP.cc.
00324 { 00325 return (sd->remotePort==0 || sd->remotePort!=remotePort) && 00326 (sd->localAddr.isUnspecified() || sd->localAddr==localAddr) && 00327 (sd->remoteAddr.isUnspecified() || sd->remoteAddr==remoteAddr); 00328 }
| void SimpleUDP::sendUp | ( | cMessage * | payload, | |
| SimpleUDPPacket * | udpHeader, | |||
| IPControlInfo * | ctrl, | |||
| SockDesc * | sd | |||
| ) | [protected] |
sends payload up to the application
| payload | the payload | |
| udpHeader | the udpHeader of the IPv4 message | |
| ctrl | the IPControlInfo of the IPv4 message | |
| sd | the socket at which the IPv4 message arrived |
Definition at line 330 of file SimpleUDP.cc.
Referenced by processUDPPacket().
00331 { 00332 // send payload with UDPControlInfo up to the application -- IPv4 version 00333 UDPControlInfo *udpCtrl = new UDPControlInfo(); 00334 udpCtrl->setSockId(sd->sockId); 00335 udpCtrl->setUserId(sd->userId); 00336 udpCtrl->setSrcAddr(ipCtrl->getSrcAddr()); 00337 udpCtrl->setDestAddr(ipCtrl->getDestAddr()); 00338 udpCtrl->setSrcPort(udpHeader->getSourcePort()); 00339 udpCtrl->setDestPort(udpHeader->getDestinationPort()); 00340 udpCtrl->setInterfaceId(ipCtrl->getInterfaceId()); 00341 payload->setControlInfo(udpCtrl); 00342 00343 send(payload, "appOut", sd->appGateIndex); 00344 numPassedUp++; 00345 }
| void SimpleUDP::sendUp | ( | cMessage * | payload, | |
| SimpleUDPPacket * | udpHeader, | |||
| IPv6ControlInfo * | ctrl, | |||
| SockDesc * | sd | |||
| ) | [protected] |
sends payload up to the application
| payload | the payload | |
| udpHeader | the udpHeader of the IPv6 message | |
| ctrl | the IPControlInfo of the IPv6 message | |
| sd | the socket at which the IPv6 message arrived |
Definition at line 347 of file SimpleUDP.cc.
00348 { 00349 // send payload with UDPControlInfo up to the application -- IPv6 version 00350 UDPControlInfo *udpCtrl = new UDPControlInfo(); 00351 udpCtrl->setSockId(sd->sockId); 00352 udpCtrl->setUserId(sd->userId); 00353 udpCtrl->setSrcAddr(ipCtrl->getSrcAddr()); 00354 udpCtrl->setDestAddr(ipCtrl->getDestAddr()); 00355 udpCtrl->setSrcPort(udpHeader->getSourcePort()); 00356 udpCtrl->setDestPort(udpHeader->getDestinationPort()); 00357 udpCtrl->setInterfaceId(ipCtrl->getInterfaceId()); 00358 payload->setControlInfo(udpCtrl); 00359 00360 send(payload, "appOut", sd->appGateIndex); 00361 numPassedUp++; 00362 }
| void SimpleUDP::processUndeliverablePacket | ( | SimpleUDPPacket * | udpPacket, | |
| cPolymorphic * | ctrl | |||
| ) | [protected] |
handles received packet which destination port is not bound to any socket
| udpPacket | the SimpleUDPPacket with the wrong port number | |
| ctrl | the IPControlInfo of udpPacket |
Definition at line 364 of file SimpleUDP.cc.
Referenced by processUDPPacket().
00365 { 00366 numDroppedWrongPort++; 00367 00368 // send back ICMP PORT_UNREACHABLE 00369 if (dynamic_cast<IPControlInfo *>(ctrl)!=NULL) { 00370 /* if (!icmp) 00371 icmp = ICMPAccess().get(); 00372 IPControlInfo *ctrl4 = (IPControlInfo *)ctrl; 00373 if (!ctrl4->getDestAddr().isMulticast()) 00374 icmp->sendErrorMessage(udpPacket, ctrl4, ICMP_DESTINATION_UNREACHABLE, ICMP_DU_PORT_UNREACHABLE);*/ 00375 /* TODO: implement icmp module */ 00376 EV << "[SimpleUDP::processUndeliverablePacket()]\n" 00377 << " Dropped packet bound to unreserved port, ignoring ICMP error" 00378 << endl; 00379 } else if (dynamic_cast<IPv6ControlInfo *>(udpPacket->getControlInfo()) 00380 !=NULL) { 00381 /* if (!icmpv6) 00382 icmpv6 = ICMPv6Access().get(); 00383 IPv6ControlInfo *ctrl6 = (IPv6ControlInfo *)ctrl; 00384 if (!ctrl6->getDestAddr().isMulticast()) 00385 icmpv6->sendErrorMessage(udpPacket, ctrl6, ICMPv6_DESTINATION_UNREACHABLE, PORT_UNREACHABLE);*/ 00386 /* TODO: implement icmp module */ 00387 EV << "[SimpleUDP::processUndeliverablePacket()]\n" 00388 << " Dropped packet bound to unreserved port, ignoring ICMP error" 00389 << endl; 00390 } else { 00391 error("(%s)%s arrived from lower layer without control info", udpPacket->getClassName(), udpPacket->getName()); 00392 } 00393 }
| void SimpleUDP::sendUpErrorNotification | ( | SockDesc * | sd, | |
| int | msgkind, | |||
| const IPvXAddress & | localAddr, | |||
| const IPvXAddress & | remoteAddr, | |||
| short | remotePort | |||
| ) | [protected] |
sends an error up to the application
| sd | the socket that received the error | |
| msgkind | the type of the error notification | |
| localAddr | the address from which the faulty message was sent | |
| remoteAddr | the address to which the faulty message was sent | |
| remotePort | the port to which the faulty message was sent |
Definition at line 468 of file SimpleUDP.cc.
Referenced by processICMPError().
00469 { 00470 cMessage *notifyMsg = new cMessage("ERROR", msgkind); 00471 UDPControlInfo *udpCtrl = new UDPControlInfo(); 00472 udpCtrl->setSockId(sd->sockId); 00473 udpCtrl->setUserId(sd->userId); 00474 udpCtrl->setSrcAddr(localAddr); 00475 udpCtrl->setDestAddr(remoteAddr); 00476 udpCtrl->setSrcPort(sd->localPort); 00477 udpCtrl->setDestPort(remotePort); 00478 notifyMsg->setControlInfo(udpCtrl); 00479 00480 send(notifyMsg, "appOut", sd->appGateIndex); 00481 }
| void SimpleUDP::processICMPError | ( | cMessage * | icmpErrorMsg | ) | [protected, virtual] |
process an ICMP error packet
| icmpErrorMsg | the received icmp Message |
Definition at line 395 of file SimpleUDP.cc.
Referenced by handleMessage().
00396 { 00397 // extract details from the error message, then try to notify socket that sent bogus packet 00398 int type = 0; 00399 int code = 0; 00400 IPvXAddress localAddr, remoteAddr; 00401 int localPort = 0; 00402 int remotePort = 0; 00403 00404 if (dynamic_cast<ICMPMessage *>(msg)) { 00405 ICMPMessage *icmpMsg = (ICMPMessage *)msg; 00406 type = icmpMsg->getType(); 00407 code = icmpMsg->getCode(); 00408 icmpMsg->setBitLength(icmpMsg->getEncapsulatedMsg()->getBitLength()); // trick because payload in ICMP is conceptually truncated 00409 IPDatagram *datagram = check_and_cast<IPDatagram *>(icmpMsg->decapsulate()); 00410 localAddr = datagram->getSrcAddress(); 00411 remoteAddr = datagram->getDestAddress(); 00412 SimpleUDPPacket *packet = check_and_cast<SimpleUDPPacket *>(datagram->decapsulate()); 00413 localPort = packet->getSourcePort(); 00414 remotePort = packet->getDestinationPort(); 00415 delete icmpMsg; 00416 delete datagram; 00417 delete packet; 00418 } else if (dynamic_cast<ICMPv6Message *>(msg)) { 00419 ICMPv6Message *icmpMsg = (ICMPv6Message *)msg; 00420 type = icmpMsg->getType(); 00421 code = -1; // FIXME this is dependent on getType()... 00422 IPv6Datagram *datagram = check_and_cast<IPv6Datagram *>(icmpMsg->decapsulate()); 00423 localAddr = datagram->getSrcAddress(); 00424 remoteAddr = datagram->getDestAddress(); 00425 SimpleUDPPacket *packet = check_and_cast<SimpleUDPPacket *>(datagram->decapsulate()); 00426 localPort = packet->getSourcePort(); 00427 remotePort = packet->getDestinationPort(); 00428 delete icmpMsg; 00429 delete datagram; 00430 delete packet; 00431 } 00432 EV << "[SimpleUDP::processICMPError() @ " << localAddr << "]\n" 00433 << " ICMP error received: type=" << type << " code=" << code 00434 << "\n about packet " << localAddr << ":" << localPort << " --> " 00435 << " " << remoteAddr << ":" << remotePort 00436 << endl; 00437 00438 // identify socket and report error to it 00439 SocketsByPortMap::iterator it = socketsByPortMap.find(localPort); 00440 if (it==socketsByPortMap.end()) { 00441 EV << "[SimpleUDP::processICMPError() @ " << localAddr << "]\n" 00442 << " No socket on that local port, ignoring ICMP error" 00443 << endl; 00444 return; 00445 } 00446 SockDescList& list = it->second; 00447 SockDesc *srcSocket = NULL; 00448 for (SockDescList::iterator it=list.begin(); it!=list.end(); ++it) { 00449 SockDesc *sd = *it; 00450 if (sd->onlyLocalPortIsSet || matchesSocket(sd, localAddr, remoteAddr, remotePort)) { 00451 srcSocket = sd; // FIXME what to do if there's more than one matching socket ??? 00452 } 00453 } 00454 if (!srcSocket) { 00455 EV << "[SimpleUDP::processICMPError() @ " << localAddr << "]\n" 00456 << " No matching socket, ignoring ICMP error" 00457 << endl; 00458 return; 00459 } 00460 00461 // send UDP_I_ERROR to socket 00462 EV << "[SimpleUDP::processICMPError() @ " << localAddr << "]\n" 00463 << " Source socket is sockId=" << srcSocket->sockId << ", notifying" 00464 << endl; 00465 sendUpErrorNotification(srcSocket, UDP_I_ERROR, localAddr, remoteAddr, remotePort); 00466 }
| void SimpleUDP::processUDPPacket | ( | SimpleUDPPacket * | udpPacket | ) | [protected, virtual] |
process UDP packets coming from IP
| udpPacket | the received packet |
Definition at line 483 of file SimpleUDP.cc.
Referenced by handleMessage().
00484 { 00485 cModule *node = getParentModule(); 00486 // IPvXAddress ip = IPAddressResolver().addressOf(node); 00487 // Speedhack SK 00488 00489 // simulate checksum: discard packet if it has bit error 00490 EV << "[SimpleUDP::processUDPPacket() @ " << IPAddressResolver().addressOf(node) << "]\n" 00491 << " Packet " << udpPacket->getName() << " received from network, dest port " << udpPacket->getDestinationPort() 00492 << endl; 00493 00494 if (udpPacket->hasBitError()) { 00495 EV << "[SimpleUDP::processUDPPacket() @ " << IPAddressResolver().addressOf(node) << "]\n" 00496 << " Packet has bit error, discarding" 00497 << endl; 00498 delete udpPacket; 00499 numDroppedBadChecksum++; 00500 return; 00501 } 00502 00503 int destPort = udpPacket->getDestinationPort(); 00504 cPolymorphic *ctrl = udpPacket->removeControlInfo(); 00505 00506 // send back ICMP error if no socket is bound to that port 00507 SocketsByPortMap::iterator it = socketsByPortMap.find(destPort); 00508 if (it==socketsByPortMap.end()) { 00509 EV << "[SimpleUDP::processUDPPacket() @ " << IPAddressResolver().addressOf(node) << "]\n" 00510 << " No socket registered on port " << destPort 00511 << endl; 00512 processUndeliverablePacket(udpPacket, ctrl); 00513 return; 00514 } 00515 SockDescList& list = it->second; 00516 00517 int matches = 0; 00518 00519 // deliver a copy of the packet to each matching socket 00520 // cMessage *payload = udpPacket->getEncapsulatedMsg(); 00521 cMessage *payload = udpPacket->decapsulate(); 00522 if (dynamic_cast<IPControlInfo *>(ctrl)!=NULL) { 00523 IPControlInfo *ctrl4 = (IPControlInfo *)ctrl; 00524 for (SockDescList::iterator it=list.begin(); it!=list.end(); ++it) { 00525 SockDesc *sd = *it; 00526 if (sd->onlyLocalPortIsSet || matchesSocket(sd, udpPacket, ctrl4)) { 00527 // EV << "[SimpleUDP::processUDPPacket() @ " << IPAddressResolver().addressOf(node) << "]\n" 00528 // << " Socket sockId=" << sd->sockId << " matches, sending up a copy" 00529 // << endl; 00530 // sendUp((cMessage*)payload->dup(), udpPacket, ctrl4, sd); 00531 // ib: speed hack 00532 00533 if (matches == 0) { 00534 sendUp(payload, udpPacket, ctrl4, sd); 00535 } else 00536 opp_error("Edit SimpleUDP.cc to support multibinding."); 00537 matches++; 00538 } 00539 } 00540 } else if (dynamic_cast<IPv6ControlInfo *>(udpPacket->getControlInfo()) 00541 !=NULL) { 00542 IPv6ControlInfo *ctrl6 = (IPv6ControlInfo *)ctrl; 00543 for (SockDescList::iterator it=list.begin(); it!=list.end(); ++it) { 00544 SockDesc *sd = *it; 00545 if (sd->onlyLocalPortIsSet || matchesSocket(sd, udpPacket, ctrl6)) { 00546 EV << "[SimpleUDP::processUDPPacket() @ " << IPAddressResolver().addressOf(node) << "]\n" 00547 << " Socket sockId=" << sd->sockId << " matches, sending up a copy" 00548 << endl; 00549 sendUp((cMessage*)payload->dup(), udpPacket, ctrl6, sd); 00550 matches++; 00551 } 00552 } 00553 } else { 00554 error("(%s)%s arrived from lower layer without control info", udpPacket->getClassName(), udpPacket->getName()); 00555 } 00556 00557 // send back ICMP error if there is no matching socket 00558 if (matches==0) { 00559 EV << "[SimpleUDP::processUDPPacket() @ " << IPAddressResolver().addressOf(node) << "]\n" 00560 << " None of the sockets on port " << destPort << " matches the packet" 00561 << endl; 00562 processUndeliverablePacket(udpPacket, ctrl) 00563 ; 00564 return; 00565 } 00566 00567 delete udpPacket; 00568 delete ctrl; 00569 }
| void SimpleUDP::processMsgFromApp | ( | cPacket * | appData | ) | [protected, virtual] |
process packets from application
| appData | the data that has to be sent |
Definition at line 572 of file SimpleUDP.cc.
Referenced by handleMessage().
00573 { 00574 cModule *node = getParentModule(); 00575 // IPvXAddress ip = IPAddressResolver().addressOf(node); 00576 // Speedhack SK 00577 00578 IPvXAddress srcAddr, destAddr; 00579 //cGate* destGate; 00580 00581 UDPControlInfo *udpCtrl = check_and_cast<UDPControlInfo *>(appData->removeControlInfo()); 00582 00583 SimpleUDPPacket *udpPacket = new SimpleUDPPacket(appData->getName()); 00584 00585 // 00586 udpPacket->setByteLength(UDP_HEADER_BYTES + IP_HEADER_BYTES); 00587 udpPacket->encapsulate(appData); 00588 00589 // set source and destination port 00590 udpPacket->setSourcePort(udpCtrl->getSrcPort()); 00591 udpPacket->setDestinationPort(udpCtrl->getDestPort()); 00592 00593 srcAddr = udpCtrl->getSrcAddr(); 00594 destAddr = udpCtrl->getDestAddr(); 00595 if (!udpCtrl->getDestAddr().isIPv6()) { 00596 // send to IPv4 00597 //EV << "[SimpleUDP::processMsgFromApp() @ " << IPAddressResolver().addressOf(node) << "]\n" 00598 //<< " Sending app packet " << appData->getName() << " over IPv4" 00599 //<< endl; 00600 IPControlInfo *ipControlInfo = new IPControlInfo(); 00601 ipControlInfo->setProtocol(IP_PROT_UDP); 00602 ipControlInfo->setSrcAddr(srcAddr.get4()); 00603 ipControlInfo->setDestAddr(destAddr.get4()); 00604 ipControlInfo->setInterfaceId(udpCtrl->getInterfaceId()); 00605 udpPacket->setControlInfo(ipControlInfo); 00606 delete udpCtrl; 00607 } else { 00608 // send to IPv6 00609 //EV << "[SimpleUDP::processMsgFromApp() @ " << IPAddressResolver().addressOf(node) << "]\n" 00610 //<< " Sending app packet " << appData->getName() << " over IPv6" 00611 //<< endl; 00612 IPv6ControlInfo *ipControlInfo = new IPv6ControlInfo(); 00613 ipControlInfo->setProtocol(IP_PROT_UDP); 00614 ipControlInfo->setSrcAddr(srcAddr.get6()); 00615 ipControlInfo->setDestAddr(destAddr.get6()); 00616 // ipControlInfo->setInterfaceId(udpCtrl->InterfaceId()); FIXME extend IPv6 with this!!! 00617 udpPacket->setControlInfo(ipControlInfo); 00618 delete udpCtrl; 00619 } 00620 00621 SimpleInfo* info = dynamic_cast<SimpleInfo*>(globalNodeList->getPeerInfo(destAddr)); 00622 numSent++; 00623 00624 if (info == NULL) { 00625 EV << "[SimpleUDP::processMsgFromApp() @ " << IPAddressResolver().addressOf(node) << "]\n" 00626 << " No route to host " << destAddr 00627 << endl; 00628 00629 delete udpPacket; 00630 numDestUnavailableLost++; 00631 return; 00632 } 00633 00634 SimpleNodeEntry* destEntry = info->getEntry(); 00635 00636 // calculate delay 00637 simtime_t totalDelay = 0; 00638 if (srcAddr != destAddr) { 00639 SimpleNodeEntry::SimpleDelay temp = nodeEntry->calcDelay(udpPacket, *destEntry); 00640 if (useCoordinateBasedDelay == false) { 00641 totalDelay = constantDelay; 00642 } else if (temp.second == false) { 00643 EV << "[SimpleUDP::processMsgFromApp() @ " << IPAddressResolver().addressOf(node) << "]\n" 00644 << " Send queue full: packet " << udpPacket << " dropped" 00645 << endl; 00646 delete udpPacket; 00647 numQueueLost++; 00648 return; 00649 } else { 00650 totalDelay = temp.first; 00651 } 00652 } 00653 00654 SimpleInfo* thisInfo = dynamic_cast<SimpleInfo*>(globalNodeList->getPeerInfo(srcAddr)); 00655 00656 if (!globalNodeList->areNodeTypesConnected(thisInfo->getTypeID(), info->getTypeID())) { 00657 EV << "[SimpleUDP::processMsgFromApp() @ " << IPAddressResolver().addressOf(node) << "]\n" 00658 << " Partition " << thisInfo->getTypeID() << "->" << info->getTypeID() 00659 << " is not connected" 00660 << endl; 00661 delete udpPacket; 00662 numPartitionLost++; 00663 return; 00664 } 00665 00666 // jitter 00667 //totalDelay += truncnormal(0, SIMTIME_DBL(totalDelay) * jitter); 00668 00669 //workaround (bug in truncnormal(): sometimes returns inf) 00670 double temp = truncnormal(0, SIMTIME_DBL(totalDelay) * jitter); 00671 while (temp == INFINITY) { 00672 std::cerr << "\n******* SimpleUDP: truncnormal() -> inf !!\n" 00673 << std::endl; 00674 temp = truncnormal(0, SIMTIME_DBL(totalDelay) * jitter); 00675 } 00676 totalDelay += temp; 00677 00678 if (udpPacket != NULL) { 00679 BaseOverlayMessage* temp = NULL; 00680 00681 if (ev.isGUI() && udpPacket->getEncapsulatedMsg()) { 00682 if ((temp = dynamic_cast<BaseOverlayMessage*>(udpPacket 00683 ->getEncapsulatedMsg()))) { 00684 switch (temp->getStatType()) { 00685 case APP_DATA_STAT: 00686 udpPacket->setKind(1); 00687 break; 00688 case APP_LOOKUP_STAT: 00689 udpPacket->setKind(2); 00690 break; 00691 case MAINTENANCE_STAT: 00692 default: 00693 udpPacket->setKind(3); 00694 } 00695 } else { 00696 udpPacket->setKind(1); 00697 } 00698 } 00699 00700 EV << "[SimpleUDP::processMsgFromApp() @ " << IPAddressResolver().addressOf(node) << "]\n" 00701 << " Packet " << udpPacket << " sent with delay = " << totalDelay 00702 << endl; 00703 sendDirect(udpPacket, totalDelay, 0, destEntry->getGate()); 00704 } 00705 }
| void SimpleUDP::processCommandFromApp | ( | cMessage * | msg | ) | [protected, virtual] |
process commands from application
| msg | the command message |
Definition at line 707 of file SimpleUDP.cc.
Referenced by handleMessage().
00708 { 00709 UDPControlInfo *udpCtrl = check_and_cast<UDPControlInfo *>(msg->removeControlInfo()); 00710 switch (msg->getKind()) { 00711 case UDP_C_BIND: 00712 bind(msg->getArrivalGate()->getIndex(), udpCtrl); 00713 break; 00714 case UDP_C_CONNECT: 00715 connect(udpCtrl->getSockId(), udpCtrl->getDestAddr(), udpCtrl->getDestPort()); 00716 break; 00717 case UDP_C_UNBIND: 00718 unbind(udpCtrl->getSockId()); 00719 break; 00720 default: 00721 error("unknown command code (message kind) %d received from app", msg->getKind()); 00722 } 00723 00724 delete udpCtrl; 00725 delete msg; 00726 }
| void SimpleUDP::initialize | ( | int | stage | ) | [protected, virtual] |
initialise the SimpleUDP module
| stage | stage of initialisation phase |
Definition at line 102 of file SimpleUDP.cc.
00103 { 00104 if(stage == MIN_STAGE_UNDERLAY) { 00105 WATCH_PTRMAP(socketsByIdMap); 00106 WATCH_MAP(socketsByPortMap); 00107 00108 lastEphemeralPort = EPHEMERAL_PORTRANGE_START; 00109 icmp = NULL; 00110 icmpv6 = NULL; 00111 00112 numSent = 0; 00113 numPassedUp = 0; 00114 numDroppedWrongPort = 0; 00115 numDroppedBadChecksum = 0; 00116 numQueueLost = 0; 00117 numPartitionLost = 0; 00118 numDestUnavailableLost = 0; 00119 WATCH(numSent); 00120 WATCH(numPassedUp); 00121 WATCH(numDroppedWrongPort); 00122 WATCH(numDroppedBadChecksum); 00123 WATCH(numQueueLost); 00124 WATCH(numPartitionLost); 00125 WATCH(numDestUnavailableLost); 00126 00127 globalNodeList = GlobalNodeListAccess().get(); 00128 globalStatistics = GlobalStatisticsAccess().get(); 00129 constantDelay = par("constantDelay"); 00130 useCoordinateBasedDelay = par("useCoordinateBasedDelay"); 00131 jitter = par("jitter"); 00132 nodeEntry = NULL; 00133 WATCH_PTR(nodeEntry); 00134 } 00135 }
| virtual int SimpleUDP::numInitStages | ( | void | ) | const [inline, protected, virtual] |
returns the number of init stages
Definition at line 277 of file SimpleUDP.h.
00278 { 00279 return MAX_STAGE_UNDERLAY + 1; 00280 }
| void SimpleUDP::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
process received messages
| msg | the received message |
Definition at line 260 of file SimpleUDP.cc.
00261 { 00262 // received from the network layer 00263 if (msg->arrivedOn("network_in")) { 00264 if (dynamic_cast<ICMPMessage *>(msg) || dynamic_cast<ICMPv6Message *>(msg)) 00265 processICMPError(msg); 00266 else 00267 processUDPPacket(check_and_cast<SimpleUDPPacket *>(msg)); 00268 } else // received from application layer 00269 { 00270 if (msg->getKind()==UDP_C_DATA) 00271 processMsgFromApp(check_and_cast<cPacket*>(msg)); 00272 else 00273 processCommandFromApp(msg); 00274 } 00275 00276 if (ev.isGUI()) 00277 updateDisplayString(); 00278 }
| void SimpleUDP::finish | ( | ) | [protected] |
Definition at line 137 of file SimpleUDP.cc.
00138 { 00139 globalStatistics->addStdDev("SimpleUDP: Packets sent", 00140 numSent); 00141 globalStatistics->addStdDev("SimpleUDP: Packets dropped with bad checksum", 00142 numDroppedBadChecksum); 00143 globalStatistics->addStdDev("SimpleUDP: Packets dropped due to queue overflows", 00144 numQueueLost); 00145 globalStatistics->addStdDev("SimpleUDP: Packets dropped due to network partitions", 00146 numPartitionLost); 00147 globalStatistics->addStdDev("SimpleUDP: Packets dropped due to unavailable destination", 00148 numDestUnavailableLost); 00149 }
SocketsByIdMap SimpleUDP::socketsByIdMap [protected] |
list of socket ordered by sockId
Definition at line 90 of file SimpleUDP.h.
Referenced by bind(), connect(), initialize(), unbind(), and ~SimpleUDP().
SocketsByPortMap SimpleUDP::socketsByPortMap [protected] |
list of sockets ordered by localPort
Definition at line 91 of file SimpleUDP.h.
Referenced by bind(), getEphemeralPort(), initialize(), processICMPError(), processUDPPacket(), and unbind().
short SimpleUDP::lastEphemeralPort [protected] |
last used port (all ports above should be free)
Definition at line 94 of file SimpleUDP.h.
Referenced by getEphemeralPort(), and initialize().
ICMP* SimpleUDP::icmp [protected] |
pointer to a received icmp (IPv4) message
Definition at line 95 of file SimpleUDP.h.
Referenced by initialize().
ICMPv6* SimpleUDP::icmpv6 [protected] |
pointer to a received icmp (IPv6) message
Definition at line 96 of file SimpleUDP.h.
Referenced by initialize().
int SimpleUDP::numSent [protected] |
number of packets sent to the network
Definition at line 99 of file SimpleUDP.h.
Referenced by finish(), initialize(), processMsgFromApp(), and updateDisplayString().
int SimpleUDP::numPassedUp [protected] |
number of packet passed up to applications
Definition at line 100 of file SimpleUDP.h.
Referenced by initialize(), sendUp(), and updateDisplayString().
int SimpleUDP::numDroppedWrongPort [protected] |
number of dropped packets due to wrong destination port
Definition at line 101 of file SimpleUDP.h.
Referenced by initialize(), processUndeliverablePacket(), and updateDisplayString().
int SimpleUDP::numDroppedBadChecksum [protected] |
number of dropped packets due to bad checksum
Definition at line 102 of file SimpleUDP.h.
Referenced by finish(), initialize(), and processUDPPacket().
int SimpleUDP::numQueueLost [protected] |
number of lost packets due to queue full
Definition at line 103 of file SimpleUDP.h.
Referenced by finish(), initialize(), processMsgFromApp(), and updateDisplayString().
int SimpleUDP::numPartitionLost [protected] |
number of lost packets due to network partitions
Definition at line 104 of file SimpleUDP.h.
Referenced by finish(), initialize(), and processMsgFromApp().
int SimpleUDP::numDestUnavailableLost [protected] |
number of lost packets due to unavailable destination
Definition at line 105 of file SimpleUDP.h.
Referenced by finish(), initialize(), and processMsgFromApp().
simtime_t SimpleUDP::delay [protected] |
simulated delay between sending and receiving udp module
Definition at line 106 of file SimpleUDP.h.
simtime_t SimpleUDP::constantDelay [protected] |
constant delay between two peers
Definition at line 108 of file SimpleUDP.h.
Referenced by initialize(), and processMsgFromApp().
bool SimpleUDP::useCoordinateBasedDelay [protected] |
delay should be calculated from euklidean distance between two peers
Definition at line 109 of file SimpleUDP.h.
Referenced by initialize(), and processMsgFromApp().
double SimpleUDP::jitter [protected] |
amount of jitter in % of total delay
Definition at line 110 of file SimpleUDP.h.
Referenced by initialize(), and processMsgFromApp().
GlobalNodeList* SimpleUDP::globalNodeList [protected] |
pointer to GlobalNodeList
Definition at line 111 of file SimpleUDP.h.
Referenced by initialize(), and processMsgFromApp().
GlobalStatistics* SimpleUDP::globalStatistics [protected] |
pointer to GlobalStatistics
Definition at line 112 of file SimpleUDP.h.
Referenced by finish(), initialize(), and SimpleUDP().
SimpleNodeEntry* SimpleUDP::nodeEntry [protected] |
nodeEntry of the overlay node this module belongs to
Definition at line 113 of file SimpleUDP.h.
Referenced by initialize(), processMsgFromApp(), and setNodeEntry().
1.5.5