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