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 protected:
00089     // sockets
00090     SocketsByIdMap socketsByIdMap; 
00091     SocketsByPortMap socketsByPortMap; 
00093     // other state vars
00094     short lastEphemeralPort; 
00095     ICMP *icmp; 
00096     ICMPv6 *icmpv6; 
00098     // statistics
00099     int numSent; 
00100     int numPassedUp; 
00101     int numDroppedWrongPort; 
00102     int numDroppedBadChecksum; 
00103     int numQueueLost; 
00104     int numPartitionLost; 
00105     int numDestUnavailableLost; 
00106     simtime_t delay; 
00108     simtime_t constantDelay; 
00109     bool useCoordinateBasedDelay; 
00110     double jitter; 
00111     GlobalNodeList* globalNodeList; 
00112     GlobalStatistics* globalStatistics; 
00113     SimpleNodeEntry* nodeEntry; 
00115 public:
00121     void setNodeEntry(SimpleNodeEntry* entry);
00122 
00123 protected:
00127     void updateDisplayString();
00128 
00135     void bind(int gateIndex, UDPControlInfo *ctrl);
00136 
00144     void connect(int sockId, IPvXAddress addr, int port);
00145 
00151     void unbind(int sockId);
00152 
00158     short getEphemeralPort();
00159 
00168     bool matchesSocket(SockDesc *sd, SimpleUDPPacket *udp, IPControlInfo *ctrl);
00169 
00178     bool matchesSocket(SockDesc *sd, SimpleUDPPacket *udp, IPv6ControlInfo *ctrl);
00179 
00189     bool matchesSocket(SockDesc *sd, const IPvXAddress& localAddr, const IPvXAddress& remoteAddr, short remotePort);
00190 
00199     void sendUp(cMessage *payload, SimpleUDPPacket *udpHeader, IPControlInfo *ctrl, SockDesc *sd);
00200 
00209     void sendUp(cMessage *payload, SimpleUDPPacket *udpHeader, IPv6ControlInfo *ctrl, SockDesc *sd);
00210 
00217     void processUndeliverablePacket(SimpleUDPPacket *udpPacket, cPolymorphic *ctrl);
00218 
00228     void sendUpErrorNotification(SockDesc *sd, int msgkind, const IPvXAddress& localAddr, const IPvXAddress& remoteAddr, short remotePort);
00229 
00235     virtual void processICMPError(cMessage *icmpErrorMsg); // TODO use ICMPMessage
00236 
00242     virtual void processUDPPacket(SimpleUDPPacket *udpPacket);
00243 
00249     virtual void processMsgFromApp(cPacket *appData);
00250 
00256     virtual void processCommandFromApp(cMessage *msg);
00257 
00258 public:
00259     SimpleUDP();
00260 
00262     virtual ~SimpleUDP();
00263 
00264 protected:
00270     virtual void initialize(int stage);
00271 
00277     virtual int numInitStages() const
00278     {
00279         return MAX_STAGE_UNDERLAY + 1;
00280     }
00286     virtual void handleMessage(cMessage *msg);
00287 
00288     void finish();
00289 };
00290 
00291 #endif
00292 

Generated on Wed Mar 25 16:32:50 2009 for OverSim by  doxygen 1.5.5