|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright (C) 2000 Institut fuer Telematik, Universitaet Karlsruhe 00003 // Copyright (C) 2004-2006 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 // Author: Jochen Reber 00021 // Date: 18.5.00 00022 // On Linux: 19.5.00 - 29.5.00 00023 // Modified by Vincent Oberle 00024 // Date: 1.2.2001 00025 // Cleanup and rewrite: Andras Varga, 2004 00026 // 00027 00028 #ifndef __ROUTINGTABLE_H 00029 #define __ROUTINGTABLE_H 00030 00031 #include <vector> 00032 #include <omnetpp.h> 00033 #include "INETDefs.h" 00034 #include "IPAddress.h" 00035 #include "IInterfaceTable.h" 00036 #include "NotificationBoard.h" 00037 #include "IRoutingTable.h" 00038 00039 class RoutingTableParser; 00040 00041 00072 class INET_API RoutingTable: public cSimpleModule, public IRoutingTable, protected INotifiable 00073 { 00074 protected: 00075 IInterfaceTable *ift; // cached pointer 00076 NotificationBoard *nb; // cached pointer 00077 00078 IPAddress routerId; 00079 bool IPForward; 00080 00081 // 00082 // Routes: 00083 // 00084 typedef std::vector<IPRoute *> RouteVector; 00085 RouteVector routes; // Unicast route array 00086 RouteVector multicastRoutes; // Multicast route array 00087 00088 // routing cache: maps destination address to the route 00089 typedef std::map<IPAddress, const IPRoute *> RoutingCache; 00090 mutable RoutingCache routingCache; 00091 00092 // local addresses cache (to speed up isLocalAddress()) 00093 typedef std::set<IPAddress> AddressSet; 00094 mutable AddressSet localAddresses; 00095 00096 protected: 00097 // set IP address etc on local loopback 00098 virtual void configureLoopbackForIPv4(); 00099 00100 // check if a route table entry corresponds to the following parameters 00101 virtual bool routeMatches(const IPRoute *entry, 00102 const IPAddress& target, const IPAddress& nmask, const IPAddress& gw, 00103 int metric, const char *dev) const; 00104 00105 // set router Id 00106 virtual void configureRouterId(); 00107 00108 // adjust routes with src=IFACENETMASK to actual interface netmasks 00109 virtual void updateNetmaskRoutes(); 00110 00111 // displays summary above the icon 00112 virtual void updateDisplayString(); 00113 00114 // delete routes for the given interface 00115 virtual void deleteInterfaceRoutes(InterfaceEntry *entry); 00116 00117 // invalidates routing cache and local addresses cache 00118 virtual void invalidateCache(); 00119 00120 public: 00121 RoutingTable(); 00122 virtual ~RoutingTable(); 00123 00124 protected: 00125 virtual int numInitStages() const {return 4;} 00126 virtual void initialize(int stage); 00127 00131 virtual void handleMessage(cMessage *); 00132 00137 virtual void receiveChangeNotification(int category, const cPolymorphic *details); 00138 00139 public: 00143 virtual void printRoutingTable() const; 00144 00147 virtual void configureInterfaceForIPv4(InterfaceEntry *ie); 00148 00152 virtual InterfaceEntry *getInterfaceByAddress(const IPAddress& address) const; 00154 00158 virtual bool isIPForwardingEnabled() {return IPForward;} 00159 00163 virtual IPAddress getRouterId() {return routerId;} 00164 00168 virtual void setRouterId(IPAddress a) {routerId = a;} 00169 00175 virtual bool isLocalAddress(const IPAddress& dest) const; 00176 00180 virtual const IPRoute *findBestMatchingRoute(const IPAddress& dest) const; 00181 00188 virtual InterfaceEntry *getInterfaceForDestAddr(const IPAddress& dest) const; 00189 00197 virtual IPAddress getGatewayForDestAddr(const IPAddress& dest) const; 00199 00202 00207 virtual bool isLocalMulticastAddress(const IPAddress& dest) const; 00208 00212 virtual MulticastRoutes getMulticastRoutesFor(const IPAddress& dest) const; 00214 00217 00222 virtual int getNumRoutes() const; 00223 00229 virtual const IPRoute *getRoute(int k) const; 00230 00234 virtual const IPRoute *findRoute(const IPAddress& target, const IPAddress& netmask, 00235 const IPAddress& gw, int metric = 0, const char *dev = NULL) const; 00236 00240 virtual const IPRoute *getDefaultRoute() const; 00241 00246 virtual void addRoute(const IPRoute *entry); 00247 00253 virtual bool deleteRoute(const IPRoute *entry); 00254 00258 virtual std::vector<IPAddress> gatherAddresses() const; 00260 00261 }; 00262 00263 #endif 00264