38 #include "UDPPacket.h"
40 #include "IPControlInfo.h"
41 #include "IPv6ControlInfo.h"
43 #include "IPAddressResolver.h"
45 #include "IPDatagram_m.h"
46 #include "IPv6Datagram_m.h"
48 #include "ICMPMessage_m.h"
49 #include "ICMPv6Message_m.h"
52 #define EPHEMERAL_PORTRANGE_START 1024
53 #define EPHEMERAL_PORTRANGE_END 5000
63 const SimpleUDP::SockDesc& sd)
65 os <<
"sockId=" << sd.sockId;
66 os <<
" appGateIndex=" << sd.appGateIndex;
67 os <<
" userId=" << sd.userId;
68 os <<
" localPort=" << sd.localPort;
70 os <<
" remotePort=" << sd.remotePort;
71 if (!sd.localAddr.isUnspecified())
72 os <<
" localAddr=" << sd.localAddr;
73 if (!sd.remoteAddr.isUnspecified())
74 os <<
" remoteAddr=" << sd.remoteAddr;
75 if (sd.interfaceId!=-1)
76 os <<
" interfaceId=" << sd.interfaceId;
82 const SimpleUDP::SockDescList& list)
84 for (SimpleUDP::SockDescList::const_iterator i=list.begin();
86 os <<
"sockId=" << (*i)->sockId <<
" ";
106 WATCH_PTRMAP(socketsByIdMap);
107 WATCH_MAP(socketsByPortMap);
115 numDroppedWrongPort = 0;
116 numDroppedBadChecksum = 0;
122 WATCH(numDroppedWrongPort);
123 WATCH(numDroppedBadChecksum);
161 numDroppedBadChecksum);
173 sprintf(buf,
"passed up: %d pks\nsent: %d pks", numPassedUp, numSent);
174 if (numDroppedWrongPort>0) {
175 sprintf(buf+strlen(buf),
"\ndropped (no app): %d pks", numDroppedWrongPort);
176 getDisplayString().setTagArg(
"i",1,
"red");
179 sprintf(buf+strlen(buf),
"\nlost (queue overflow): %d pks",
numQueueLost);
180 getDisplayString().setTagArg(
"i",1,
"red");
182 getDisplayString().setTagArg(
"t",0,buf);
188 udpCtrl->setSockId(sd->sockId);
189 udpCtrl->setUserId(sd->userId);
190 payload->setControlInfo(udpCtrl);
192 send(payload,
"appOut", sd->appGateIndex);
198 numDroppedWrongPort++;
199 EV <<
"[SimpleUDP::processUndeliverablePacket()]\n"
200 <<
" Dropped packet bound to unreserved port, ignoring ICMP error"
209 int srcPort, destPort;
210 IPvXAddress srcAddr, destAddr;
212 UDPControlInfo *ctrl = check_and_cast<UDPControlInfo *>(udpPacket->removeControlInfo());
214 srcPort = ctrl->getSrcPort();
215 destPort = ctrl->getDestPort();
217 srcAddr = ctrl->getSrcAddr();
218 destAddr = ctrl->getDestAddr();
221 EV <<
"Packet " << udpPacket->getName() <<
" received from network, dest port " << destPort <<
"\n";
222 if (udpPacket->hasBitError())
224 EV <<
"Packet has bit error, discarding\n";
226 numDroppedBadChecksum++;
231 SocketsByPortMap::iterator it = socketsByPortMap.find(destPort);
232 if (it==socketsByPortMap.end())
234 EV <<
"No socket registered on port " << destPort <<
"\n";
239 SockDescList& list = it->second;
244 if (destAddr.isIPv6())
247 udpPacket->setByteLength(udpPacket->getByteLength() - UDP_HEADER_BYTES -
IPv6_HEADER_BYTES);
251 udpPacket->setByteLength(udpPacket->getByteLength() - UDP_HEADER_BYTES - IP_HEADER_BYTES);
253 for (SockDescList::iterator it=list.begin(); it!=list.end(); ++it)
256 if (sd->onlyLocalPortIsSet || matchesSocket(sd, destAddr, srcAddr, srcPort))
259 sendUp(udpPacket, ctrl, sd);
261 opp_error(
"Edit SimpleUDP.cc to support multibinding.");
270 EV <<
"None of the sockets on port " << destPort <<
" matches the packet\n";
278 cModule *node = getParentModule();
280 IPvXAddress srcAddr, destAddr;
282 UDPControlInfo *udpCtrl = check_and_cast<UDPControlInfo *>(appData->getControlInfo());
284 srcAddr = udpCtrl->getSrcAddr();
285 destAddr = udpCtrl->getDestAddr();
288 if (destAddr.isIPv6()) {
289 appData->setByteLength(appData->getByteLength() + UDP_HEADER_BYTES +
IPv6_HEADER_BYTES);
291 appData->setByteLength(appData->getByteLength() + UDP_HEADER_BYTES + IP_HEADER_BYTES);
300 EV <<
"[SimpleUDP::processMsgFromApp() @ " << IPAddressResolver().addressOf(node) <<
"]\n"
301 <<
" No route to host " << destAddr
312 simtime_t totalDelay = 0;
313 if (srcAddr != destAddr) {
325 }
else if (temp.second ==
false) {
326 EV <<
"[SimpleUDP::processMsgFromApp() @ " << IPAddressResolver().addressOf(node) <<
"]\n"
327 <<
" Send queue full: packet " << appData <<
" dropped"
334 totalDelay = temp.first;
341 EV <<
"[SimpleUDP::processMsgFromApp() @ " << IPAddressResolver().addressOf(node) <<
"]\n"
343 <<
" is not connected"
356 double temp = truncnormal(0, SIMTIME_DBL(totalDelay) *
jitter);
357 while (temp == INFINITY || temp != temp) {
358 std::cerr <<
"\n******* SimpleUDP: truncnormal() -> inf !!\n"
360 temp = truncnormal(0, SIMTIME_DBL(totalDelay) * jitter);
368 if (ev.isGUI() && appData) {
369 if ((temp = dynamic_cast<BaseOverlayMessage*>(appData))) {
387 EV <<
"[SimpleUDP::processMsgFromApp() @ " << IPAddressResolver().addressOf(node) <<
"]\n"
388 <<
" Packet " << appData <<
" sent with delay = " << SIMTIME_DBL(totalDelay)
395 if (!destAddr.isIPv6()) {
408 if (msg->arrivedOn(
"ipIn") || msg->arrivedOn(
"ipv6In"))
416 if (temp.second ==
false) {
421 if (temp.first > 0) {
422 scheduleAt(simTime() + temp.first, msg);
423 }
else if (dynamic_cast<ICMPMessage *>(msg) || dynamic_cast<ICMPv6Message *>(msg))
424 processICMPError(PK(msg));
428 else if (msg->isSelfMessage())
430 if (dynamic_cast<ICMPMessage *>(msg) ||
dynamic_cast<ICMPv6Message *
>(msg))
431 processICMPError(PK(msg));
438 if (msg->getKind()==UDP_C_DATA)
441 processCommandFromApp(msg);