|
INET Framework for OMNeT++/OMNEST
|
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 Lesser 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 Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this program; if not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 00020 // 00021 // Author: Jochen Reber 00022 // Rewrite: Andras Varga 2004,2005 00023 // 00024 00025 #ifndef __INET_UDP_H 00026 #define __INET_UDP_H 00027 00028 #include <map> 00029 #include <list> 00030 #include "UDPControlInfo_m.h" 00031 00032 class IPControlInfo; 00033 class IPv6ControlInfo; 00034 class ICMP; 00035 class ICMPv6; 00036 class UDPPacket; 00037 00038 const int UDP_HEADER_BYTES = 8; 00039 00040 00046 class INET_API UDP : public cSimpleModule 00047 { 00048 public: 00049 struct SockDesc 00050 { 00051 int sockId; // supposed to be unique across apps 00052 int userId; // we just send it back, but don't do anything with it 00053 int appGateIndex; 00054 bool onlyLocalPortIsSet; 00055 IPvXAddress localAddr; 00056 IPvXAddress remoteAddr; 00057 ushort localPort; 00058 ushort remotePort; 00059 int interfaceId; // FIXME do real sockets allow filtering by input interface?? 00060 }; 00061 00062 typedef std::list<SockDesc *> SockDescList; 00063 typedef std::map<int,SockDesc *> SocketsByIdMap; 00064 typedef std::map<int,SockDescList> SocketsByPortMap; 00065 00066 protected: 00067 // sockets 00068 SocketsByIdMap socketsByIdMap; 00069 SocketsByPortMap socketsByPortMap; 00070 00071 // other state vars 00072 ushort lastEphemeralPort; 00073 ICMP *icmp; 00074 ICMPv6 *icmpv6; 00075 00076 // statistics 00077 int numSent; 00078 int numPassedUp; 00079 int numDroppedWrongPort; 00080 int numDroppedBadChecksum; 00081 00082 protected: 00083 // utility: show current statistics above the icon 00084 virtual void updateDisplayString(); 00085 00086 // bind socket 00087 virtual void bind(int gateIndex, UDPControlInfo *ctrl); 00088 00089 // connect socket 00090 virtual void connect(int sockId, IPvXAddress addr, int port); 00091 00092 // unbind socket 00093 virtual void unbind(int sockId); 00094 00095 // ephemeral port 00096 virtual ushort getEphemeralPort(); 00097 00098 virtual bool matchesSocket(SockDesc *sd, UDPPacket *udp, IPControlInfo *ctrl); 00099 virtual bool matchesSocket(SockDesc *sd, UDPPacket *udp, IPv6ControlInfo *ctrl); 00100 virtual bool matchesSocket(SockDesc *sd, const IPvXAddress& localAddr, const IPvXAddress& remoteAddr, ushort remotePort); 00101 virtual void sendUp(cPacket *payload, UDPPacket *udpHeader, IPControlInfo *ctrl, SockDesc *sd); 00102 virtual void sendUp(cPacket *payload, UDPPacket *udpHeader, IPv6ControlInfo *ctrl, SockDesc *sd); 00103 virtual void processUndeliverablePacket(UDPPacket *udpPacket, cPolymorphic *ctrl); 00104 virtual void sendUpErrorNotification(SockDesc *sd, int msgkind, const IPvXAddress& localAddr, const IPvXAddress& remoteAddr, ushort remotePort); 00105 00106 // process an ICMP error packet 00107 virtual void processICMPError(cPacket *icmpErrorMsg); // TODO use ICMPMessage 00108 00109 // process UDP packets coming from IP 00110 virtual void processUDPPacket(UDPPacket *udpPacket); 00111 00112 // process packets from application 00113 virtual void processMsgFromApp(cPacket *appData); 00114 00115 // process commands from application 00116 virtual void processCommandFromApp(cMessage *msg); 00117 00118 // create a blank UDP packet; override to subclass UDPPacket 00119 virtual UDPPacket *createUDPPacket(const char *name); 00120 00121 public: 00122 UDP() {} 00123 virtual ~UDP(); 00124 00125 protected: 00126 virtual void initialize(); 00127 virtual void handleMessage(cMessage *msg); 00128 }; 00129 00130 #endif 00131