|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // This program is free software: you can redistribute it and/or modify 00003 // it under the terms of the GNU Lesser General Public License as published by 00004 // the Free Software Foundation, either version 3 of the License, or 00005 // (at your option) any later version. 00006 // 00007 // This program is distributed in the hope that it will be useful, 00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00010 // GNU Lesser General Public License for more details. 00011 // 00012 // You should have received a copy of the GNU Lesser General Public License 00013 // along with this program. If not, see http://www.gnu.org/licenses/. 00014 // 00015 00016 #ifndef ANSAOSPFROUTER6_H_ 00017 #define ANSAOSPFROUTER6_H_ 00018 00019 #include "IPAddress.h" 00020 00021 #include "ansaMessageHandler6.h" 00022 #include "ansaOspfArea6.h" 00023 #include "ansaOspfCommon6.h" 00024 #include "ansaOspfStat6.h" 00025 00026 namespace AnsaOspf6 { 00027 00028 class Router { 00029 private: 00030 RouterID routerID; 00031 ProcessID processID; 00032 std::map<AreaID, Area*> areasByID; 00033 std::vector<Area*> areas; 00034 std::map<LsaKeyType6, AsExternalLsa*, LsaKeyType6_Less> asExternalLSAsByID; 00035 std::vector<AsExternalLsa*> asExternalLSAs; 00036 std::map<IPv6Address, OspfAsExternalLsa6, IPv6Address_Less> externalRoutes; 00037 OspfTimer6* ageTimer; 00038 std::vector<RoutingTableEntry*> routingTable; 00039 MessageHandler* messageHandler; 00040 public: 00041 Stat stat; 00042 00043 public: 00044 Router(ProcessID pid, RouterID id, cSimpleModule* containingModule); 00045 virtual ~Router(void); 00046 00047 void SetRouterID (RouterID id) { routerID = id; } 00048 RouterID GetRouterID (void) const { return routerID; } 00049 void SetProcessID (ProcessID pid) { processID = pid; } 00050 ProcessID GetProcessID (void) const { return processID; } 00051 unsigned long GetAreaCount (void) const { return areas.size(); } 00052 00053 MessageHandler* GetMessageHandler (void) { return messageHandler; } 00054 00055 unsigned long GetASExternalLSACount (void) const { return asExternalLSAs.size(); } 00056 AsExternalLsa* GetASExternalLSA (unsigned long i) { return asExternalLSAs[i]; } 00057 const AsExternalLsa* GetASExternalLSA (unsigned long i) const { return asExternalLSAs[i]; } 00058 bool GetASBoundaryRouter (void) const { return (externalRoutes.size() > 0); } 00059 unsigned long GetRoutingTableEntryCount (void) const { return routingTable.size(); } 00060 RoutingTableEntry* GetRoutingTableEntry (unsigned long i) { return routingTable[i]; } 00061 const RoutingTableEntry* GetRoutingTableEntry (unsigned long i) const { return routingTable[i]; } 00062 void AddRoutingTableEntry (RoutingTableEntry* entry) { routingTable.push_back(entry); } 00063 00064 void AddArea (Area* area); 00065 Area* GetArea (AreaID areaID); 00066 Area* GetAreaByIndex (int index); 00067 Area* GetArea (IPv6Address address); 00068 Interface* GetNonVirtualInterface (unsigned char ifIndex); 00069 00070 bool InstallLSA (OspfLsa6* lsa, AreaID areaID = BackboneAreaID); 00071 OspfLsa6* FindLSA (LsaType6 lsaType, LsaKeyType6 lsaKey, AreaID areaID); 00072 void AgeDatabase (void); 00073 bool HasAnyNeighborInStates (int states) const; 00074 void RemoveFromAllRetransmissionLists (LsaKeyType6 lsaKey); 00075 bool IsOnAnyRetransmissionList (LsaKeyType6 lsaKey) const; 00076 bool FloodLSA (OspfLsa6* lsa, AreaID areaID = BackboneAreaID, Interface* intf = NULL, Neighbor* neighbor = NULL); 00077 00078 bool IsDestinationUnreachable (OspfLsa6* lsa) const; 00079 00080 void RebuildRoutingTable (void); 00081 00082 private: 00083 bool InstallASExternalLSA (OspfAsExternalLsa6* lsa); 00084 AsExternalLsa* FindASExternalLSA (LsaKeyType6 lsaKey); 00085 const AsExternalLsa* FindASExternalLSA (LsaKeyType6 lsaKey) const; 00086 }; 00087 00088 } 00089 00090 00091 inline std::ostream& operator<<(std::ostream& os, AnsaOspf6::Router& r){ 00092 // TODO: sem přijde zhruba obsah metody add watches 00093 // ale taky bych mohl prozkoumat, jak funguje to rozklikávání do dalších 00094 // oken jako je třeba v modulu interface table 00095 00096 os << "Router-ID: " << IPAddress(r.GetRouterID()); 00097 00098 int areaCount = r.GetAreaCount(); 00099 for (int i = 0; i < areaCount; i++){ 00100 os << endl << "Interfaces in area " << r.GetAreaByIndex(i)->GetAreaID() << ":"; 00101 int ifaces = r.GetAreaByIndex(i)->GetNumberOfInterfaces(); 00102 for (int j = 0; j < ifaces; j++){ 00103 AnsaOspf6::Interface *iface = r.GetAreaByIndex(i)->GetInterfaceByIndex(j); 00104 os << endl << "- " << iface->GetIfName(); 00105 os << " (" << iface->GetTypeString(iface->GetType()) << ")"; 00106 //os << ", inst: " << iface->GetInstanceID(); 00107 os << ", cost: " << iface->GetOutputCost(); 00108 os << ", pri: " << iface->GetRouterPriority(); 00109 os << ", hello: " << iface->GetHelloInterval() << "s"; 00110 os << ", dead:" << iface->GetRouterDeadInterval() << "s"; 00111 00112 os << endl << " * state: " << iface->GetStateString(iface->GetState()); 00113 os << ", DR: " << IPAddress(iface->GetDesignatedRouter()); 00114 os << ", BDR: " << IPAddress(iface->GetBackupDesignatedRouter()); 00115 00116 os << endl << " * " << "prefixes: "; 00117 int prefixes = iface->GetAddressPrefixCount(); 00118 for (int k = 0; k < prefixes; k++){ 00119 if (k != 0){ 00120 os << ", "; 00121 } 00122 os << iface->GetAddressPrefix(k).address << "/" << iface->GetAddressPrefix(k).prefixLen; 00123 } 00124 00125 for (int l = 0; l < iface->GetNeighborCount(); l++){ 00126 os << endl << " * neighbor "; 00127 os << IPAddress(iface->GetNeighbor(l)->GetNeighborID()); 00128 os << " (" << iface->GetNeighbor(l)->GetStateString(iface->GetNeighbor(l)->GetState()) << ")"; 00129 os << ", pri: " << iface->GetNeighbor(l)->GetPriority(); 00130 if (iface->GetNeighbor(l)->GetDesignatedRouter() != 0){ 00131 os << endl << " DR: " << IPAddress(iface->GetNeighbor(l)->GetDesignatedRouter()); 00132 } 00133 00134 if (iface->GetNeighbor(l)->GetBackupDesignatedRouter() != 0){ 00135 os << ", BDR:" << IPAddress(iface->GetNeighbor(l)->GetBackupDesignatedRouter()); 00136 } 00137 } 00138 } 00139 } 00140 00141 00142 return os; 00143 } 00144 00145 00146 00147 #endif /* ANSAOSPFROUTER6_H_ */