|
INET Framework for OMNeT++/OMNEST
|
00001 #ifndef __INET_OSPFROUTER_H 00002 #define __INET_OSPFROUTER_H 00003 00004 #include "AnsaOSPFcommon.h" 00005 #include "AnsaOSPFArea.h" 00006 #include "AnsaMessageHandler.h" 00007 #include "AnsaOSPFInterface.h" 00008 #include "AnsaLSA.h" 00009 #include "AnsaStat.h" 00010 #include "AnsaOSPFRoutingTableEntry.h" 00011 #include <map> 00012 #include <fstream> 00013 00017 namespace AnsaOSPF { 00018 00022 class Router { 00023 private: 00024 RouterID routerID; 00025 std::map<AreaID, Area*> areasByID; 00026 std::vector<Area*> areas; 00027 std::map<LSAKeyType, ASExternalLSA*, LSAKeyType_Less> asExternalLSAsByID; 00028 std::vector<ASExternalLSA*> asExternalLSAs; 00029 std::map<IPv4Address, OSPFASExternalLSAContents, IPv4Address_Less> externalRoutes; 00030 OSPFTimer* ageTimer; 00031 std::vector<RoutingTableEntry*> routingTable; 00032 MessageHandler* messageHandler; 00033 bool rfc1583Compatibility; 00034 00035 public: 00036 Router(RouterID id, cSimpleModule* containingModule); 00037 virtual ~Router(void); 00038 00039 void SetRouterID (RouterID id) { routerID = id; } 00040 RouterID GetRouterID (void) const { return routerID; } 00041 void SetRFC1583Compatibility (bool compatibility) { rfc1583Compatibility = compatibility; } 00042 bool GetRFC1583Compatibility (void) const { return rfc1583Compatibility; } 00043 unsigned long GetAreaCount (void) const { return areas.size(); } 00044 00045 MessageHandler* GetMessageHandler (void) { return messageHandler; } 00046 00047 unsigned long GetASExternalLSACount (void) const { return asExternalLSAs.size(); } 00048 ASExternalLSA* GetASExternalLSA (unsigned long i) { return asExternalLSAs[i]; } 00049 const ASExternalLSA* GetASExternalLSA (unsigned long i) const { return asExternalLSAs[i]; } 00050 bool GetASBoundaryRouter (void) const { return (externalRoutes.size() > 0); } 00051 00052 unsigned long GetRoutingTableEntryCount(void) const { return routingTable.size(); } 00053 RoutingTableEntry* GetRoutingTableEntry (unsigned long i) { return routingTable[i]; } 00054 const RoutingTableEntry* GetRoutingTableEntry (unsigned long i) const { return routingTable[i]; } 00055 void AddRoutingTableEntry (RoutingTableEntry* entry) { routingTable.push_back(entry); } 00056 00057 void AddWatches (void); 00058 00059 void AddArea (Area* area); 00060 Area* GetArea (AreaID areaID); 00061 Area* GetArea (IPv4Address address); 00062 Interface* GetNonVirtualInterface (unsigned char ifIndex); 00063 00064 bool InstallLSA (OSPFLSA* lsa, AreaID areaID = BackboneAreaID); 00065 OSPFLSA* FindLSA (LSAType lsaType, LSAKeyType lsaKey, AreaID areaID); 00066 void AgeDatabase (void); 00067 bool HasAnyNeighborInStates (int states) const; 00068 void RemoveFromAllRetransmissionLists (LSAKeyType lsaKey); 00069 bool IsOnAnyRetransmissionList (LSAKeyType lsaKey) const; 00070 bool FloodLSA (OSPFLSA* lsa, AreaID areaID = BackboneAreaID, Interface* intf = NULL, Neighbor* neighbor = NULL); 00071 bool IsLocalAddress (IPv4Address address) const; 00072 bool HasAddressRange (IPv4AddressRange addressRange) const; 00073 bool IsDestinationUnreachable (OSPFLSA* lsa) const; 00074 RoutingTableEntry* Lookup (IPAddress destination, std::vector<RoutingTableEntry*>* table = NULL) const; 00075 void RebuildRoutingTable (void); 00076 IPv4AddressRange GetContainingAddressRange (IPv4AddressRange addressRange, bool* advertise = NULL) const; 00077 void UpdateExternalRoute (IPv4Address networkAddress, const OSPFASExternalLSAContents& externalRouteContents, int ifIndex); 00078 void RemoveExternalRoute (IPv4Address networkAddress); 00079 RoutingTableEntry* GetPreferredEntry (const OSPFLSA& lsa, bool skipSelfOriginated, std::vector<RoutingTableEntry*>* fromRoutingTable = NULL); 00080 00081 Stat stat; 00082 private: 00083 bool InstallASExternalLSA (OSPFASExternalLSA* lsa); 00084 ASExternalLSA* FindASExternalLSA (LSAKeyType lsaKey); 00085 const ASExternalLSA* FindASExternalLSA (LSAKeyType lsaKey) const; 00086 ASExternalLSA* OriginateASExternalLSA (ASExternalLSA* lsa); 00087 LinkStateID GetUniqueLinkStateID (IPv4AddressRange destination, 00088 Metric destinationCost, 00089 AnsaOSPF::ASExternalLSA*& lsaToReoriginate, 00090 bool externalMetricIsType2 = false) const; 00091 void CalculateASExternalRoutes (std::vector<RoutingTableEntry*>& newRoutingTable); 00092 void NotifyAboutRoutingTableChanges (std::vector<RoutingTableEntry*>& oldRoutingTable); 00093 bool HasRouteToASBoundaryRouter (const std::vector<RoutingTableEntry*>& inRoutingTable, AnsaOSPF::RouterID routerID) const; 00094 std::vector<RoutingTableEntry*> 00095 GetRoutesToASBoundaryRouter (const std::vector<RoutingTableEntry*>& fromRoutingTable, AnsaOSPF::RouterID routerID) const; 00096 void PruneASBoundaryRouterEntries (std::vector<RoutingTableEntry*>& asbrEntries) const; 00097 RoutingTableEntry* SelectLeastCostRoutingEntry (std::vector<RoutingTableEntry*>& entries) const; 00098 }; 00099 00100 } // namespace AnsaOSPF 00101 00102 #endif // __INET_OSPFROUTER_H