RoutingTable6.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2005 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_ROUTINGTABLE6_H
00019 #define __INET_ROUTINGTABLE6_H
00020 
00021 #include <vector>
00022 #include <omnetpp.h>
00023 #include "INETDefs.h"
00024 #include "IPv6Address.h"
00025 #include "IInterfaceTable.h"
00026 #include "NotificationBoard.h"
00027 
00028 
00033 class INET_API IPv6Route : public cPolymorphic
00034 {
00035   public:
00037     enum RouteSrc
00038     {
00039         FROM_RA,        
00040         OWN_ADV_PREFIX, 
00041         STATIC,         
00042         ROUTING_PROT,   
00043     };
00044 
00045   protected:
00046     IPv6Address _destPrefix;
00047     short _length;
00048     RouteSrc _src;
00049     int _interfaceID;      //XXX IPv4 IRoutingTable uses interface pointer
00050     IPv6Address _nextHop;  // unspecified means "direct"
00051     simtime_t _expiryTime; // if route is an advertised prefix: prefix lifetime
00052     int _metric;
00053 
00054   public:
00059     IPv6Route(IPv6Address destPrefix, int length, RouteSrc src) {
00060         _destPrefix = destPrefix;
00061         _length = length;
00062         _src = src;
00063         _interfaceID = -1;
00064         _expiryTime = 0;
00065         _metric = 0;
00066     }
00067 
00068     virtual std::string info() const;
00069     virtual std::string detailedInfo() const;
00070     static const char *routeSrcName(RouteSrc src);
00071 
00072     void setInterfaceId(int interfaceId)  {_interfaceID = interfaceId;}
00073     void setNextHop(const IPv6Address& nextHop)  {_nextHop = nextHop;}
00074     void setExpiryTime(simtime_t expiryTime)  {_expiryTime = expiryTime;}
00075     void setMetric(int metric)  {_metric = _metric;}
00076 
00077     const IPv6Address& getDestPrefix() const {return _destPrefix;}
00078     int getPrefixLength() const  {return _length;}
00079     RouteSrc getSrc() const  {return _src;}
00080     int getInterfaceId() const  {return _interfaceID;}
00081     const IPv6Address& getNextHop() const  {return _nextHop;}
00082     simtime_t getExpiryTime() const  {return _expiryTime;}
00083     int getMetric() const  {return _metric;}
00084 };
00085 
00086 
00102 class INET_API RoutingTable6 : public cSimpleModule, protected INotifiable
00103 {
00104   protected:
00105     IInterfaceTable *ift; // cached pointer
00106     NotificationBoard *nb; // cached pointer
00107 
00108     bool isrouter;
00109 
00110     // Destination Cache maps dest address to next hop and interfaceId.
00111     // NOTE: nextHop might be a link-local address from which interfaceId cannot be deduced
00112     struct DestCacheEntry
00113     {
00114         int interfaceId;
00115         IPv6Address nextHopAddr;
00116         // more destination specific data may be added here, e.g. path MTU
00117     };
00118     friend std::ostream& operator<<(std::ostream& os, const DestCacheEntry& e);
00119     typedef std::map<IPv6Address,DestCacheEntry> DestCache;
00120     DestCache destCache;
00121 
00122     // RouteList contains local prefixes, and (for routers)
00123     // static, OSPF, RIP etc routes as well
00124     typedef std::vector<IPv6Route*> RouteList;
00125     RouteList routeList;
00126 
00127   protected:
00128     // internal: routes of different type can only be added via well-defined functions
00129     virtual void addRoute(IPv6Route *route);
00130     // helper for addRoute()
00131     static bool routeLessThan(const IPv6Route *a, const IPv6Route *b);
00132     // internal
00133     virtual void configureInterfaceForIPv6(InterfaceEntry *ie);
00139     virtual void assignRequiredNodeAddresses(InterfaceEntry *ie);
00140     // internal
00141     virtual void configureInterfaceFromXML(InterfaceEntry *ie, cXMLElement *cfg);
00142 
00143   protected:
00144     // displays summary above the icon
00145     virtual void updateDisplayString();
00146 
00147   public:
00148     RoutingTable6();
00149     virtual ~RoutingTable6();
00150 
00151   protected:
00152     virtual int numInitStages() const  {return 5;}
00153     virtual void initialize(int stage);
00154     virtual void parseXMLConfigFile();
00155 
00159     virtual void handleMessage(cMessage *);
00160 
00165     virtual void receiveChangeNotification(int category, const cPolymorphic *details);
00166 
00167   public:
00173     virtual InterfaceEntry *getInterfaceByAddress(const IPv6Address& address);
00175 
00179     virtual bool isRouter() const {return isrouter;}
00180 
00187     virtual bool isLocalAddress(const IPv6Address& dest) const;
00188 
00200     const IPv6Address& lookupDestCache(const IPv6Address& dest, int& outInterfaceId) const;
00201 
00206     const IPv6Route *doLongestPrefixMatch(const IPv6Address& dest);
00207 
00211     virtual bool isPrefixPresent(const IPv6Address& prefix) const;
00212 
00213     //TBD multicast delivery
00215 
00220     virtual void updateDestCache(const IPv6Address& dest, const IPv6Address& nextHopAddr, int interfaceId);
00221 
00225     virtual void purgeDestCache();
00226 
00233     virtual void purgeDestCacheEntriesToNeighbour(const IPv6Address& nextHopAddr, int interfaceId);
00235 
00248     virtual void addOrUpdateOnLinkPrefix(const IPv6Address& destPrefix, int prefixLength,
00249                                  int interfaceId, simtime_t expiryTime);
00250 
00258     virtual void removeOnLinkPrefix(const IPv6Address& destPrefix, int prefixLength);
00259 
00264     virtual void addOrUpdateOwnAdvPrefix(const IPv6Address& destPrefix, int prefixLength,
00265                                  int interfaceId, simtime_t expiryTime);
00266 
00271     virtual void addStaticRoute(const IPv6Address& destPrefix, int prefixLength,
00272                         unsigned int interfaceId, const IPv6Address& nextHop,
00273                         int metric=0);
00274 
00279     virtual void addDefaultRoute(const IPv6Address& raSrcAddr, unsigned int ifID,
00280         simtime_t routerLifetime);
00281 
00287     virtual void addRoutingProtocolRoute(IPv6Route *route);
00288 
00292     virtual void removeRoute(IPv6Route *route);
00293 
00297     virtual int getNumRoutes() const;
00298 
00302     virtual IPv6Route *getRoute(int i);
00304 
00305 };
00306 
00307 #endif
00308