|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright (C) 2006 Andras Babos and 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_OSPFROUTER_H 00019 #define __INET_OSPFROUTER_H 00020 00021 #include "OSPFcommon.h" 00022 #include "OSPFArea.h" 00023 #include "MessageHandler.h" 00024 #include "OSPFInterface.h" 00025 #include "LSA.h" 00026 #include "OSPFRoutingTableEntry.h" 00027 #include <map> 00028 00032 namespace OSPF { 00033 00037 class Router { 00038 private: 00039 RouterID routerID; 00040 std::map<AreaID, Area*> areasByID; 00041 std::vector<Area*> areas; 00042 std::map<LSAKeyType, ASExternalLSA*, LSAKeyType_Less> asExternalLSAsByID; 00043 std::vector<ASExternalLSA*> asExternalLSAs; 00044 std::map<IPv4Address, OSPFASExternalLSAContents, IPv4Address_Less> externalRoutes; 00045 OSPFTimer* ageTimer; 00046 std::vector<RoutingTableEntry*> routingTable; 00047 MessageHandler* messageHandler; 00048 bool rfc1583Compatibility; 00049 00050 public: 00051 Router(RouterID id, cSimpleModule* containingModule); 00052 virtual ~Router(void); 00053 00054 void SetRouterID (RouterID id) { routerID = id; } 00055 RouterID GetRouterID (void) const { return routerID; } 00056 void SetRFC1583Compatibility (bool compatibility) { rfc1583Compatibility = compatibility; } 00057 bool GetRFC1583Compatibility (void) const { return rfc1583Compatibility; } 00058 unsigned long GetAreaCount (void) const { return areas.size(); } 00059 00060 MessageHandler* GetMessageHandler (void) { return messageHandler; } 00061 00062 unsigned long GetASExternalLSACount (void) const { return asExternalLSAs.size(); } 00063 ASExternalLSA* GetASExternalLSA (unsigned long i) { return asExternalLSAs[i]; } 00064 const ASExternalLSA* GetASExternalLSA (unsigned long i) const { return asExternalLSAs[i]; } 00065 bool GetASBoundaryRouter (void) const { return (externalRoutes.size() > 0); } 00066 00067 unsigned long GetRoutingTableEntryCount(void) const { return routingTable.size(); } 00068 RoutingTableEntry* GetRoutingTableEntry (unsigned long i) { return routingTable[i]; } 00069 const RoutingTableEntry* GetRoutingTableEntry (unsigned long i) const { return routingTable[i]; } 00070 void AddRoutingTableEntry (RoutingTableEntry* entry) { routingTable.push_back(entry); } 00071 00072 void AddWatches (void); 00073 00074 void AddArea (Area* area); 00075 Area* GetArea (AreaID areaID); 00076 Area* GetArea (IPv4Address address); 00077 Interface* GetNonVirtualInterface (unsigned char ifIndex); 00078 00079 bool InstallLSA (OSPFLSA* lsa, AreaID areaID = BackboneAreaID); 00080 OSPFLSA* FindLSA (LSAType lsaType, LSAKeyType lsaKey, AreaID areaID); 00081 void AgeDatabase (void); 00082 bool HasAnyNeighborInStates (int states) const; 00083 void RemoveFromAllRetransmissionLists (LSAKeyType lsaKey); 00084 bool IsOnAnyRetransmissionList (LSAKeyType lsaKey) const; 00085 bool FloodLSA (OSPFLSA* lsa, AreaID areaID = BackboneAreaID, Interface* intf = NULL, Neighbor* neighbor = NULL); 00086 bool IsLocalAddress (IPv4Address address) const; 00087 bool HasAddressRange (IPv4AddressRange addressRange) const; 00088 bool IsDestinationUnreachable (OSPFLSA* lsa) const; 00089 RoutingTableEntry* Lookup (IPAddress destination, std::vector<RoutingTableEntry*>* table = NULL) const; 00090 void RebuildRoutingTable (void); 00091 IPv4AddressRange GetContainingAddressRange (IPv4AddressRange addressRange, bool* advertise = NULL) const; 00092 void UpdateExternalRoute (IPv4Address networkAddress, const OSPFASExternalLSAContents& externalRouteContents, int ifIndex); 00093 void RemoveExternalRoute (IPv4Address networkAddress); 00094 RoutingTableEntry* GetPreferredEntry (const OSPFLSA& lsa, bool skipSelfOriginated, std::vector<RoutingTableEntry*>* fromRoutingTable = NULL); 00095 00096 private: 00097 bool InstallASExternalLSA (OSPFASExternalLSA* lsa); 00098 ASExternalLSA* FindASExternalLSA (LSAKeyType lsaKey); 00099 const ASExternalLSA* FindASExternalLSA (LSAKeyType lsaKey) const; 00100 ASExternalLSA* OriginateASExternalLSA (ASExternalLSA* lsa); 00101 LinkStateID GetUniqueLinkStateID (IPv4AddressRange destination, 00102 Metric destinationCost, 00103 OSPF::ASExternalLSA*& lsaToReoriginate, 00104 bool externalMetricIsType2 = false) const; 00105 void CalculateASExternalRoutes (std::vector<RoutingTableEntry*>& newRoutingTable); 00106 void NotifyAboutRoutingTableChanges (std::vector<RoutingTableEntry*>& oldRoutingTable); 00107 bool HasRouteToASBoundaryRouter (const std::vector<RoutingTableEntry*>& inRoutingTable, OSPF::RouterID routerID) const; 00108 std::vector<RoutingTableEntry*> 00109 GetRoutesToASBoundaryRouter (const std::vector<RoutingTableEntry*>& fromRoutingTable, OSPF::RouterID routerID) const; 00110 void PruneASBoundaryRouterEntries (std::vector<RoutingTableEntry*>& asbrEntries) const; 00111 RoutingTableEntry* SelectLeastCostRoutingEntry (std::vector<RoutingTableEntry*>& entries) const; 00112 }; 00113 00114 } // namespace OSPF 00115 00116 #endif // __INET_OSPFROUTER_H