|
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 #include "ansaOspfRouter6.h" 00017 00022 AnsaOspf6::Router::Router(ProcessID pid, RouterID id, cSimpleModule* containingModule) : 00023 routerID(id), 00024 processID(pid){ 00025 00026 messageHandler = new AnsaOspf6::MessageHandler(this, containingModule); 00027 /* 00028 ageTimer = new OspfTimer6; 00029 ageTimer->setTimerKind(DatabaseAgeTimer); 00030 ageTimer->setContextPointer(this); 00031 ageTimer->setName("AnsaOspf6::Router::DatabaseAgeTimer"); 00032 messageHandler->StartTimer(ageTimer, 1.0); 00033 */ 00034 } 00035 00040 AnsaOspf6::Router::~Router(void) { 00041 long areaCount = areas.size(); 00042 for (long i = 0; i < areaCount; i++){ 00043 delete areas[i]; 00044 } 00045 long lsaCount = asExternalLSAs.size(); 00046 for (long j = 0; j < lsaCount; j++){ 00047 delete asExternalLSAs[j]; 00048 } 00049 long routeCount = routingTable.size(); 00050 for (long k = 0; k < routeCount; k++){ 00051 delete routingTable[k]; 00052 } 00053 00054 /* TODO 00055 messageHandler->ClearTimer(ageTimer); 00056 delete ageTimer; 00057 */ 00058 delete messageHandler; 00059 } 00060 00061 00066 void AnsaOspf6::Router::AddArea(AnsaOspf6::Area* area) { 00067 area->SetRouter(this); 00068 areasByID[area->GetAreaID()] = area; 00069 areas.push_back(area); 00070 } 00071 00072 00078 AnsaOspf6::Area* AnsaOspf6::Router::GetArea(AnsaOspf6::AreaID areaID) { 00079 std::map<AnsaOspf6::AreaID, AnsaOspf6::Area*>::iterator areaIt = areasByID.find(areaID); 00080 if (areaIt != areasByID.end()){ 00081 return (areaIt->second); 00082 }else{ 00083 return NULL; 00084 } 00085 } 00086 00087 AnsaOspf6::Area* AnsaOspf6::Router::GetAreaByIndex(int index) { 00088 if (index < areas.size()){ 00089 return areas[index]; 00090 }else{ 00091 return NULL; 00092 } 00093 } 00094 00095 00096 00102 AnsaOspf6::Interface* AnsaOspf6::Router::GetNonVirtualInterface(unsigned char ifIndex) { 00103 long areaCount = areas.size(); 00104 for (long i = 0; i < areaCount; i++){ 00105 AnsaOspf6::Interface* intf = areas[i]->GetInterface(ifIndex); 00106 if (intf != NULL){ 00107 return intf; 00108 } 00109 } 00110 return NULL; 00111 } 00112 00113 00122 bool AnsaOspf6::Router::InstallLSA(OspfLsa6* lsa, AnsaOspf6::AreaID areaID) { 00123 switch (lsa->getHeader().getLsType()){ 00124 case RouterLsaType: { 00125 std::map<AnsaOspf6::AreaID, AnsaOspf6::Area*>::iterator areaIt = areasByID.find(areaID); 00126 if (areaIt != areasByID.end()){ 00127 OspfRouterLsa6* ospfRouterLSA = check_and_cast<OspfRouterLsa6*> (lsa); 00128 return areaIt->second->InstallRouterLSA(ospfRouterLSA); 00129 } 00130 } 00131 break; 00132 case NetworkLsaType: { 00133 std::map<AnsaOspf6::AreaID, AnsaOspf6::Area*>::iterator areaIt = areasByID.find(areaID); 00134 if (areaIt != areasByID.end()){ 00135 OspfNetworkLsa6* ospfNetworkLSA = check_and_cast<OspfNetworkLsa6*> (lsa); 00136 return areaIt->second->InstallNetworkLSA(ospfNetworkLSA); 00137 } 00138 } 00139 00140 case InterAreaPrefixLsaType: { 00141 std::map<AnsaOspf6::AreaID, AnsaOspf6::Area*>::iterator areaIt = areasByID.find(areaID); 00142 if (areaIt != areasByID.end()){ 00143 OspfInterAreaPrefixLsa6* ospfInterAreaPrefixLSA = check_and_cast<OspfInterAreaPrefixLsa6*> (lsa); 00144 return areaIt->second->InstallInterAreaPrefixLSA(ospfInterAreaPrefixLSA); 00145 } 00146 } 00147 00148 case InterAreaRouterLsaType: { 00149 std::map<AnsaOspf6::AreaID, AnsaOspf6::Area*>::iterator areaIt = areasByID.find(areaID); 00150 if (areaIt != areasByID.end()){ 00151 OspfInterAreaRouterLsa6* ospfInterAreaRouterLSA = check_and_cast<OspfInterAreaRouterLsa6*> (lsa); 00152 return areaIt->second->InstallInterAreaRouterLSA(ospfInterAreaRouterLSA); 00153 } 00154 } 00155 00156 case AsExternalLsaType: { 00157 OspfAsExternalLsa6* ospfASExternalLSA = check_and_cast<OspfAsExternalLsa6*> (lsa); 00158 return InstallASExternalLSA(ospfASExternalLSA); 00159 } 00160 00161 case LinkLsaType: { 00162 // TODO 00163 } 00164 00165 case IntraAreaPrefixLsaType: { 00166 std::map<AnsaOspf6::AreaID, AnsaOspf6::Area*>::iterator areaIt = areasByID.find(areaID); 00167 if (areaIt != areasByID.end()){ 00168 OspfIntraAreaPrefixLsa6* ospfIntraAreaPrefixLSA = check_and_cast<OspfIntraAreaPrefixLsa6*> (lsa); 00169 return areaIt->second->InstallIntraAreaPrefixLSA(ospfIntraAreaPrefixLSA); 00170 } 00171 } 00172 } 00173 return false; 00174 } 00175 00176 00177 00182 void AnsaOspf6::Router::RebuildRoutingTable(void){ 00183 00184 /* 00185 unsigned long areaCount = areas.size(); 00186 bool hasTransitAreas = false; 00187 std::vector<AnsaOspf6::RoutingTableEntry*> newTable; 00188 unsigned long i; 00189 00190 EV << "Rebuilding routing table:\n"; 00191 00192 for (i = 0; i < areaCount; i++) { 00193 areas[i]->CalculateShortestPathTree(newTable); 00194 if (areas[i]->GetTransitCapability()) { 00195 hasTransitAreas = true; 00196 } 00197 } 00198 if (areaCount > 1) { 00199 AnsaOspf6::Area* backbone = GetArea(AnsaOspf6::BackboneAreaID); 00200 if (backbone != NULL) { 00201 backbone->CalculateInterAreaRoutes(newTable); 00202 } 00203 } else { 00204 if (areaCount == 1) { 00205 areas[0]->CalculateInterAreaRoutes(newTable); 00206 } 00207 } 00208 if (hasTransitAreas) { 00209 for (i = 0; i < areaCount; i++) { 00210 if (areas[i]->GetTransitCapability()) { 00211 areas[i]->ReCheckSummaryLSAs(newTable); 00212 } 00213 } 00214 } 00215 CalculateASExternalRoutes(newTable); 00216 00217 // backup the routing table 00218 unsigned long routeCount = routingTable.size(); 00219 std::vector<AnsaOspf6::RoutingTableEntry*> oldTable; 00220 00221 oldTable.assign(routingTable.begin(), routingTable.end()); 00222 routingTable.clear(); 00223 routingTable.assign(newTable.begin(), newTable.end()); 00224 00225 RoutingTableAccess routingTableAccess; 00226 std::vector<const IPRoute*> eraseEntries; 00227 IRoutingTable* simRoutingTable = routingTableAccess.get(); 00228 unsigned long routingEntryNumber = simRoutingTable->getNumRoutes(); 00229 // remove entries from the IP routing table inserted by the OSPF module 00230 for (i = 0; i < routingEntryNumber; i++) { 00231 const IPRoute *entry = simRoutingTable->getRoute(i); 00232 const AnsaOspf6::RoutingTableEntry* ospfEntry = dynamic_cast<const AnsaOspf6::RoutingTableEntry*>(entry); 00233 if (ospfEntry != NULL) { 00234 eraseEntries.push_back(entry); 00235 } 00236 } 00237 00238 unsigned int eraseCount = eraseEntries.size(); 00239 for (i = 0; i < eraseCount; i++) { 00240 simRoutingTable->deleteRoute(eraseEntries[i]); 00241 } 00242 00243 // add the new routing entries 00244 routeCount = routingTable.size(); 00245 for (i = 0; i < routeCount; i++) { 00246 if (routingTable[i]->GetDestinationType() == AnsaOspf6::RoutingTableEntry::NetworkDestination) { 00247 simRoutingTable->addRoute(new AnsaOspf6::RoutingTableEntry(*(routingTable[i]))); 00248 } 00249 } 00250 00251 NotifyAboutRoutingTableChanges(oldTable); 00252 00253 routeCount = oldTable.size(); 00254 for (i = 0; i < routeCount; i++) { 00255 delete(oldTable[i]); 00256 } 00257 00258 EV << "Routing table was rebuilt.\n" 00259 << "Results:\n"; 00260 00261 routeCount = routingTable.size(); 00262 for (i = 0; i < routeCount; i++) { 00263 EV << *routingTable[i] 00264 << "\n"; 00265 } 00266 */ 00267 } 00268 00269 OspfLsa6* AnsaOspf6::Router::FindLSA(LsaType6 lsaType, AnsaOspf6::LsaKeyType6 lsaKey, AnsaOspf6::AreaID areaID) { 00270 /* 00271 switch (lsaType){ 00272 case RouterLSAType: { 00273 std::map<AnsaOspf6::AreaID, AnsaOspf6::Area*>::iterator areaIt = areasByID.find(areaID); 00274 if (areaIt != areasByID.end()){ 00275 return areaIt->second->FindRouterLSA(lsaKey.linkStateID); 00276 } 00277 } 00278 break; 00279 case NetworkLSAType: { 00280 std::map<AnsaOspf6::AreaID, AnsaOspf6::Area*>::iterator areaIt = areasByID.find(areaID); 00281 if (areaIt != areasByID.end()){ 00282 return areaIt->second->FindNetworkLSA(lsaKey.linkStateID); 00283 } 00284 } 00285 break; 00286 case SummaryLSA_NetworksType: 00287 case SummaryLSA_ASBoundaryRoutersType: { 00288 std::map<AnsaOspf6::AreaID, AnsaOspf6::Area*>::iterator areaIt = areasByID.find(areaID); 00289 if (areaIt != areasByID.end()){ 00290 return areaIt->second->FindSummaryLSA(lsaKey); 00291 } 00292 } 00293 break; 00294 case ASExternalLSAType: { 00295 return FindASExternalLSA(lsaKey); 00296 } 00297 break; 00298 default: 00299 ASSERT(false); 00300 break; 00301 } 00302 return NULL; 00303 */ 00304 } 00305 00311 void AnsaOspf6::Router::AgeDatabase(void){ 00312 } 00313 00314 00320 bool AnsaOspf6::Router::HasAnyNeighborInStates(int states) const { 00321 long areaCount = areas.size(); 00322 for (long i = 0; i < areaCount; i++){ 00323 if (areas[i]->HasAnyNeighborInStates(states)){ 00324 return true; 00325 } 00326 } 00327 return false; 00328 } 00329 00335 void AnsaOspf6::Router::RemoveFromAllRetransmissionLists(AnsaOspf6::LsaKeyType6 lsaKey) { 00336 long areaCount = areas.size(); 00337 for (long i = 0; i < areaCount; i++){ 00338 areas[i]->RemoveFromAllRetransmissionLists(lsaKey); 00339 } 00340 } 00341 00347 bool AnsaOspf6::Router::IsOnAnyRetransmissionList(AnsaOspf6::LsaKeyType6 lsaKey) const { 00348 long areaCount = areas.size(); 00349 for (long i = 0; i < areaCount; i++){ 00350 if (areas[i]->IsOnAnyRetransmissionList(lsaKey)){ 00351 return true; 00352 } 00353 } 00354 return false; 00355 } 00356 00366 bool AnsaOspf6::Router::FloodLSA(OspfLsa6* lsa, AnsaOspf6::AreaID areaID, AnsaOspf6::Interface* intf, AnsaOspf6::Neighbor* neighbor){ 00367 } 00368 00369 00370 bool AnsaOspf6::Router::IsDestinationUnreachable(OspfLsa6* lsa) const { 00371 00372 } 00373 00374 00375 bool AnsaOspf6::Router::InstallASExternalLSA(OspfAsExternalLsa6* lsa){ 00376 } 00377 00378 00384 AnsaOspf6::AsExternalLsa* AnsaOspf6::Router::FindASExternalLSA(AnsaOspf6::LsaKeyType6 lsaKey) { 00385 std::map<AnsaOspf6::LsaKeyType6, AnsaOspf6::AsExternalLsa*, AnsaOspf6::LsaKeyType6_Less> 00386 ::iterator lsaIt = asExternalLSAsByID.find(lsaKey); 00387 if (lsaIt != asExternalLSAsByID.end()){ 00388 return lsaIt->second; 00389 }else{ 00390 return NULL; 00391 } 00392 } 00393 00394 00400 const AnsaOspf6::AsExternalLsa* AnsaOspf6::Router::FindASExternalLSA(AnsaOspf6::LsaKeyType6 lsaKey) const { 00401 std::map<AnsaOspf6::LsaKeyType6, AnsaOspf6::AsExternalLsa*, AnsaOspf6::LsaKeyType6_Less> 00402 ::const_iterator lsaIt = asExternalLSAsByID.find(lsaKey); 00403 if (lsaIt != asExternalLSAsByID.end()){ 00404 return lsaIt->second; 00405 }else{ 00406 return NULL; 00407 } 00408 } 00409