|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright (C) 2004 Andras Varga 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License 00006 // as published by the Free Software Foundation; either version 2 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU Lesser General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU Lesser General Public License 00015 // along with this program; if not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #ifndef __INET_IP_H 00019 #define __INET_IP_H 00020 00021 #include "QueueBase.h" 00022 #include "InterfaceTableAccess.h" 00023 #include "RoutingTableAccess.h" 00024 #include "IRoutingTable.h" 00025 #include "ICMPAccess.h" 00026 #include "IPControlInfo.h" 00027 #include "IPDatagram.h" 00028 #include "IPFragBuf.h" 00029 #include "ProtocolMap.h" 00030 00031 00032 class ARPPacket; 00033 class ICMPMessage; 00034 00035 // ICMP type 2, code 4: fragmentation needed, but don't-fragment bit set 00036 const int ICMP_FRAGMENTATION_ERROR_CODE = 4; 00037 00038 00042 class INET_API IP : public QueueBase 00043 { 00044 protected: 00045 IRoutingTable *rt; 00046 IInterfaceTable *ift; 00047 ICMPAccess icmpAccess; 00048 cGate *queueOutGate; // the most frequently used output gate 00049 00050 // config 00051 int defaultTimeToLive; 00052 int defaultMCTimeToLive; 00053 simtime_t fragmentTimeoutTime; 00054 00055 // working vars 00056 long curFragmentId; // counter, used to assign unique fragmentIds to datagrams 00057 IPFragBuf fragbuf; // fragmentation reassembly buffer 00058 simtime_t lastCheckTime; // when fragbuf was last checked for state fragments 00059 ProtocolMapping mapping; // where to send packets after decapsulation 00060 00061 // statistics 00062 int numMulticast; 00063 int numLocalDeliver; 00064 int numDropped; 00065 int numUnroutable; 00066 int numForwarded; 00067 00068 protected: 00069 // utility: look up interface from getArrivalGate() 00070 virtual InterfaceEntry *getSourceInterfaceFrom(cPacket *msg); 00071 00072 // utility: show current statistics above the icon 00073 virtual void updateDisplayString(); 00074 00079 virtual IPDatagram *encapsulate(cPacket *transportPacket, InterfaceEntry *&destIE); 00080 00086 virtual IPDatagram *encapsulate(cPacket *transportPacket, InterfaceEntry *&destIE, IPControlInfo *controlInfo); 00087 00091 virtual IPDatagram *createIPDatagram(const char *name); 00092 00097 virtual void handlePacketFromNetwork(IPDatagram *datagram); 00098 00103 virtual void handleMessageFromHL(cPacket *msg); 00104 00108 virtual void handleARP(ARPPacket *msg); 00109 00113 virtual void handleReceivedICMP(ICMPMessage *msg); 00114 00121 virtual void routePacket(IPDatagram *datagram, InterfaceEntry *destIE, bool fromHL); 00122 00126 virtual void routeMulticastPacket(IPDatagram *datagram, InterfaceEntry *destIE, InterfaceEntry *fromIE); 00127 00132 virtual void reassembleAndDeliver(IPDatagram *datagram); 00133 00137 virtual cPacket *decapsulateIP(IPDatagram *datagram); 00138 00143 virtual void fragmentAndSend(IPDatagram *datagram, InterfaceEntry *ie, IPAddress nextHopAddr); 00144 00148 virtual void sendDatagramToOutput(IPDatagram *datagram, InterfaceEntry *ie, IPAddress nextHopAddr); 00149 00150 public: 00151 IP() {} 00152 00153 protected: 00157 virtual void initialize(); 00158 00163 virtual void endService(cPacket *msg); 00164 }; 00165 00166 #endif 00167