SimpleUDP.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00025
00026
00027
00028
00029
00030
00031 #ifndef __SIMPLEUDP_H__
00032 #define __SIMPLEUDP_H__
00033
00034 #include <map>
00035 #include <list>
00036
00037 #include <InitStages.h>
00038
00039
00040
00041
00042 #include "UDPControlInfo_m.h"
00043
00044 class SimpleUDPPacket;
00045 class GlobalNodeList;
00046 class SimpleNodeEntry;
00047 class GlobalStatistics;
00048
00049 class IPControlInfo;
00050 class IPv6ControlInfo;
00051 class ICMP;
00052 class ICMPv6;
00053
00054
00055 const int UDP_HEADER_BYTES = 8;
00063 class INET_API SimpleUDP : public cSimpleModule
00064 {
00065 public:
00066
00070 struct SockDesc
00071 {
00072 int sockId;
00073 int userId;
00074 int appGateIndex;
00075 bool onlyLocalPortIsSet;
00076 IPvXAddress localAddr;
00077 IPvXAddress remoteAddr;
00078 ushort localPort;
00079 ushort remotePort;
00080
00081 int interfaceId;
00082 };
00083
00084 typedef std::list<SockDesc *> SockDescList;
00085 typedef std::map<int,SockDesc *> SocketsByIdMap;
00086 typedef std::map<int,SockDescList> SocketsByPortMap;
00088
00089 static std::string delayFaultTypeString;
00090 enum delayFaultTypeNum {
00091 delayFaultUndefined,
00092 delayFaultLiveAll,
00093 delayFaultLivePlanetlab,
00094 delayFaultSimulation
00095 };
00096 static std::map<std::string, delayFaultTypeNum> delayFaultTypeMap;
00097
00098 protected:
00099
00100 SocketsByIdMap socketsByIdMap;
00101 SocketsByPortMap socketsByPortMap;
00103
00104 short lastEphemeralPort;
00105 ICMP *icmp;
00106 ICMPv6 *icmpv6;
00108
00109 int numSent;
00110 int numPassedUp;
00111 int numDroppedWrongPort;
00112 int numDroppedBadChecksum;
00113 int numQueueLost;
00114 int numPartitionLost;
00115 int numDestUnavailableLost;
00116 simtime_t delay;
00118 simtime_t constantDelay;
00119 bool useCoordinateBasedDelay;
00120 double jitter;
00121 bool faultyDelay;
00122 GlobalNodeList* globalNodeList;
00123 GlobalStatistics* globalStatistics;
00124 SimpleNodeEntry* nodeEntry;
00126 public:
00132 void setNodeEntry(SimpleNodeEntry* entry);
00133
00134 protected:
00138 void updateDisplayString();
00139
00146 void bind(int gateIndex, UDPControlInfo *ctrl);
00147
00155 void connect(int sockId, IPvXAddress addr, int port);
00156
00162 void unbind(int sockId);
00163
00169 short getEphemeralPort();
00170
00179 bool matchesSocket(SockDesc *sd, SimpleUDPPacket *udp, IPControlInfo *ctrl);
00180
00189 bool matchesSocket(SockDesc *sd, SimpleUDPPacket *udp, IPv6ControlInfo *ctrl);
00190
00200 bool matchesSocket(SockDesc *sd, const IPvXAddress& localAddr, const IPvXAddress& remoteAddr, short remotePort);
00201
00210 void sendUp(cMessage *payload, SimpleUDPPacket *udpHeader, IPControlInfo *ctrl, SockDesc *sd);
00211
00220 void sendUp(cMessage *payload, SimpleUDPPacket *udpHeader, IPv6ControlInfo *ctrl, SockDesc *sd);
00221
00228 void processUndeliverablePacket(SimpleUDPPacket *udpPacket, cPolymorphic *ctrl);
00229
00239 void sendUpErrorNotification(SockDesc *sd, int msgkind, const IPvXAddress& localAddr, const IPvXAddress& remoteAddr, short remotePort);
00240
00246 virtual void processICMPError(cMessage *icmpErrorMsg);
00247
00253 virtual void processUDPPacket(SimpleUDPPacket *udpPacket);
00254
00260 virtual void processMsgFromApp(cPacket *appData);
00261
00267 virtual void processCommandFromApp(cMessage *msg);
00268
00269 public:
00270 SimpleUDP();
00271
00273 virtual ~SimpleUDP();
00274
00275 protected:
00281 virtual void initialize(int stage);
00282
00288 virtual int numInitStages() const
00289 {
00290 return MAX_STAGE_UNDERLAY + 1;
00291 }
00297 virtual void handleMessage(cMessage *msg);
00298
00299 void finish();
00300 };
00301
00302 #endif
00303