|
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 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 // Author: Jochen Reber 00022 // Date: 18.5.00 00023 // On Linux: 19.5.00 - 29.5.00 00024 // Modified by Vincent Oberle 00025 // Date: 1.2.2001 00026 // Cleanup and rewrite: Andras Varga, 2004 00027 // 00028 00029 #ifndef __ANSAROUTINGTABLE_H 00030 #define __ANSAROUTINGTABLE_H 00031 00032 #include <vector> 00033 #include <omnetpp.h> 00034 #include <map> 00035 #include <sstream> 00036 #include "INETDefs.h" 00037 #include "IPAddress.h" 00038 #include "IInterfaceTable.h" 00039 #include "NotificationBoard.h" 00040 #include "IRoutingTable.h" 00041 00042 class RoutingTableXmlParser; 00043 00044 00075 class INET_API AnsaRoutingTable: public cSimpleModule, public IRoutingTable, protected INotifiable 00076 { 00077 protected: 00078 IInterfaceTable *ift; // cached pointer 00079 NotificationBoard *nb; // cached pointer 00080 00081 IPAddress routerId; 00082 bool IPForward; 00083 00084 // DSDV parameters 00085 simtime_t timetolive_routing_entry; 00086 // 00087 // Routes: 00088 // 00089 typedef std::vector<IPRoute *> RouteVector; 00090 RouteVector routes; // Unicast route array 00091 RouteVector multicastRoutes; // Multicast route array 00092 00093 // routing cache: maps destination address to the route 00094 typedef std::map<IPAddress, const IPRoute *> RoutingCache; 00095 mutable RoutingCache routingCache; 00096 00097 // local addresses cache (to speed up isLocalAddress()) 00098 typedef std::set<IPAddress> AddressSet; 00099 mutable AddressSet localAddresses; 00100 00101 std::map<IPRoute::RouteSource,int> ADmap; 00102 std::vector<std::string> showIPRoute; 00103 00104 protected: 00105 // set IP address etc on local loopback 00106 virtual void configureLoopbackForIPv4(); 00107 00108 // check if a route table entry corresponds to the following parameters 00109 virtual bool routeMatches(const IPRoute *entry, 00110 const IPAddress& target, const IPAddress& nmask, const IPAddress& gw, 00111 int metric, const char *dev) const; 00112 00113 // set router Id 00114 virtual void configureRouterId(); 00115 00116 // adjust routes with src=IFACENETMASK to actual interface netmasks 00117 virtual void updateNetmaskRoutes(); 00118 00119 // displays summary above the icon 00120 virtual void updateDisplayString(); 00121 00122 // delete routes for the given interface 00123 virtual void deleteInterfaceRoutes(InterfaceEntry *entry); 00124 00125 // invalidates routing cache and local addresses cache 00126 virtual void invalidateCache(); 00127 00128 void initializeAD(); 00129 00130 bool checkRoute(const IPRoute* entry); 00131 00132 bool matchHostMask(const IPRoute* entry, const IPAddress& target, const IPAddress& nmask); 00133 00134 void generateShowIPRoute(); 00135 00136 public: 00137 AnsaRoutingTable(); 00138 virtual ~AnsaRoutingTable(); 00139 00140 protected: 00141 virtual int numInitStages() const {return 4;} 00142 virtual void initialize(int stage); 00143 00147 virtual void handleMessage(cMessage *); 00148 00153 virtual void receiveChangeNotification(int category, const cPolymorphic *details); 00154 00155 public: 00156 //Time of routing table entry creation 00157 simtime_t installtime; 00158 simtime_t getInstallTime() const {return installtime;} 00159 void setInstallTime(simtime_t time) {installtime = time;} 00163 virtual void printRoutingTable() const; 00164 00167 virtual void configureInterfaceForIPv4(InterfaceEntry *ie); 00168 00172 virtual InterfaceEntry *getInterfaceByAddress(const IPAddress& address) const; 00174 00178 virtual bool isIPForwardingEnabled() {return IPForward;} 00179 00183 virtual IPAddress getRouterId() {return routerId;} 00184 00188 virtual void setRouterId(IPAddress a) {routerId = a;} 00189 00195 virtual bool isLocalAddress(const IPAddress& dest) const; 00196 00200 virtual const IPRoute *findBestMatchingRoute(const IPAddress& dest) const; 00201 00208 virtual InterfaceEntry *getInterfaceForDestAddr(const IPAddress& dest) const; 00209 00217 virtual IPAddress getGatewayForDestAddr(const IPAddress& dest) const; 00219 00222 00227 virtual bool isLocalMulticastAddress(const IPAddress& dest) const; 00228 00232 virtual MulticastRoutes getMulticastRoutesFor(const IPAddress& dest) const; 00234 00237 00242 virtual int getNumRoutes() const; 00243 00249 virtual const IPRoute *getRoute(int k) const; 00250 00254 virtual const IPRoute *findRoute(const IPAddress& target, const IPAddress& netmask, 00255 const IPAddress& gw, int metric = 0, const char *dev = NULL) const; 00256 00260 virtual const IPRoute *getDefaultRoute() const; 00261 00266 virtual void addRoute(const IPRoute *entry); 00267 00273 virtual bool deleteRoute(const IPRoute *entry); 00274 00278 virtual std::vector<IPAddress> gatherAddresses() const; 00280 virtual void setTimeToLiveRoutingEntry(simtime_t a){timetolive_routing_entry = a;} 00281 virtual simtime_t getTimeToLiveRoutingEntry(){return timetolive_routing_entry;} 00282 // Dsdv time to live test entry 00283 virtual void dsdvTestAndDelete(); 00284 virtual const bool testValidity(const IPRoute *entry) const; 00285 std::string directIPRouteFormat(const IPRoute* entry); 00286 std::string otherIPRouteFormat(const IPRoute* entry); 00287 00288 }; 00289 00290 #endif 00291