SimpleUDP.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2000 Institut fuer Telematik, Universitaet Karlsruhe
00003 // Copyright (C) 2004,2005 Andras Varga
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU 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 General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 
00025 //
00026 // Author: Jochen Reber
00027 // Rewrite: Andras Varga 2004,2005
00028 // Modifikations: Stephan Krause
00029 //
00030 
00031 #ifndef __SIMPLEUDP_H__
00032 #define __SIMPLEUDP_H__
00033 
00034 #include <map>
00035 #include <list>
00036 
00037 #include <InitStages.h>
00038 //#include <SimpleNodeEntry.h>
00039 //#include <GlobalNodeList.h>
00040 //#include <SimpleInfo.h>
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 //const char *ERROR_IP_ADDRESS = "10.0.0.255";
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         // FIXME do real sockets allow filtering by input interface?? - no they dont :)
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     // delay fault type string and corresponding map for switch..case
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     // sockets
00100     SocketsByIdMap socketsByIdMap; 
00101     SocketsByPortMap socketsByPortMap; 
00103     // other state vars
00104     short lastEphemeralPort; 
00105     ICMP *icmp; 
00106     ICMPv6 *icmpv6; 
00108     // statistics
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); // TODO use ICMPMessage
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 
Generated on Wed May 26 16:21:15 2010 for OverSim by  doxygen 1.6.3