#include <OSPFArea.h>
|
00008 : 00009 areaID (id), 00010 transitCapability (false), 00011 externalRoutingCapability (true), 00012 stubDefaultCost (1), 00013 spfTreeRoot (NULL), 00014 parentRouter (NULL) 00015 { 00016 }
|
|
00019 { 00020 int interfaceNum = associatedInterfaces.size (); 00021 for (int i = 0; i < interfaceNum; i++) { 00022 delete (associatedInterfaces[i]); 00023 } 00024 long lsaCount = routerLSAs.size (); 00025 for (long j = 0; j < lsaCount; j++) { 00026 delete routerLSAs[j]; 00027 } 00028 routerLSAs.clear (); 00029 lsaCount = networkLSAs.size (); 00030 for (long k = 0; k < lsaCount; k++) { 00031 delete networkLSAs[k]; 00032 } 00033 networkLSAs.clear (); 00034 lsaCount = summaryLSAs.size (); 00035 for (long m = 0; m < lsaCount; m++) { 00036 delete summaryLSAs[m]; 00037 } 00038 summaryLSAs.clear (); 00039 }
|
|
00040 { areaAddressRanges.push_back (addressRange); advertiseAddressRanges[addressRange] = advertise; }
|
|
00043 { hostRoutes.push_back (hostRouteParameters); }
|
|
00042 { 00043 intf->SetArea (this); 00044 associatedInterfaces.push_back (intf); 00045 }
|
|
00328 { 00329 long lsaCount = routerLSAs.size (); 00330 bool rebuildRoutingTable = false; 00331 long i; 00332 00333 for (i = 0; i < lsaCount; i++) { 00334 unsigned short lsAge = routerLSAs[i]->getHeader ().getLsAge (); 00335 bool selfOriginated = (routerLSAs[i]->getHeader ().getAdvertisingRouter ().getInt () == parentRouter->GetRouterID ()); 00336 bool unreachable = parentRouter->DestinationIsUnreachable (routerLSAs[i]); 00337 OSPF::RouterLSA* lsa = routerLSAs[i]; 00338 00339 if ((selfOriginated && (lsAge < (LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) { 00340 lsa->getHeader ().setLsAge (lsAge + 1); 00341 if ((lsAge + 1) % CHECK_AGE == 0) { 00342 if (!lsa->ValidateLSChecksum ()) { 00343 EV << "Invalid LS checksum. Memory error detected!\n"; 00344 } 00345 } 00346 lsa->IncrementInstallTime (); 00347 } 00348 if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))) { 00349 if (unreachable) { 00350 lsa->getHeader ().setLsAge (MAX_AGE); 00351 FloodLSA (lsa); 00352 lsa->IncrementInstallTime (); 00353 } else { 00354 long sequenceNumber = lsa->getHeader ().getLsSequenceNumber (); 00355 if (sequenceNumber == MAX_SEQUENCE_NUMBER) { 00356 lsa->getHeader ().setLsAge (MAX_AGE); 00357 FloodLSA (lsa); 00358 lsa->IncrementInstallTime (); 00359 } else { 00360 OSPF::RouterLSA* newLSA = OriginateRouterLSA (); 00361 00362 newLSA->getHeader ().setLsSequenceNumber (sequenceNumber + 1); 00363 newLSA->getHeader ().setLsChecksum (0); // TODO: calculate correct LS checksum 00364 rebuildRoutingTable |= lsa->Update (newLSA); 00365 delete newLSA; 00366 00367 FloodLSA (lsa); 00368 } 00369 } 00370 } 00371 if (!selfOriginated && (lsAge == MAX_AGE - 1)) { 00372 lsa->getHeader ().setLsAge (MAX_AGE); 00373 FloodLSA (lsa); 00374 lsa->IncrementInstallTime (); 00375 } 00376 if (lsAge == MAX_AGE) { 00377 OSPF::LSAKeyType lsaKey; 00378 00379 lsaKey.linkStateID = lsa->getHeader ().getLinkStateID (); 00380 lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ().getInt (); 00381 00382 if (!IsOnAnyRetransmissionList (lsaKey) && 00383 !AnyNeighborInStates (OSPF::Neighbor::ExchangeState | OSPF::Neighbor::LoadingState)) 00384 { 00385 if (!selfOriginated || unreachable) { 00386 routerLSAsByID.erase (lsa->getHeader ().getLinkStateID ()); 00387 delete lsa; 00388 routerLSAs[i] = NULL; 00389 rebuildRoutingTable = true; 00390 } else { 00391 OSPF::RouterLSA* newLSA = OriginateRouterLSA (); 00392 long sequenceNumber = lsa->getHeader ().getLsSequenceNumber (); 00393 00394 newLSA->getHeader ().setLsSequenceNumber ((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1); 00395 newLSA->getHeader ().setLsChecksum (0); // TODO: calculate correct LS checksum 00396 rebuildRoutingTable |= lsa->Update (newLSA); 00397 delete newLSA; 00398 00399 FloodLSA (lsa); 00400 } 00401 } 00402 } 00403 } 00404 00405 std::vector<RouterLSA*>::iterator routerIt = routerLSAs.begin (); 00406 while (routerIt != routerLSAs.end ()) { 00407 if ((*routerIt) == NULL) { 00408 routerIt = routerLSAs.erase (routerIt); 00409 } else { 00410 routerIt++; 00411 } 00412 } 00413 00414 lsaCount = networkLSAs.size (); 00415 for (i = 0; i < lsaCount; i++) { 00416 unsigned short lsAge = networkLSAs[i]->getHeader ().getLsAge (); 00417 bool unreachable = parentRouter->DestinationIsUnreachable (networkLSAs[i]); 00418 OSPF::NetworkLSA* lsa = networkLSAs[i]; 00419 OSPF::Interface* localIntf = GetInterface (IPv4AddressFromULong (lsa->getHeader ().getLinkStateID ())); 00420 bool selfOriginated = false; 00421 00422 if ((localIntf != NULL) && 00423 (localIntf->GetState () == OSPF::Interface::DesignatedRouterState) && 00424 (localIntf->GetNeighborCount () > 0) && 00425 (localIntf->AnyNeighborInStates (OSPF::Neighbor::FullState))) 00426 { 00427 selfOriginated = true; 00428 } 00429 00430 if ((selfOriginated && (lsAge < (LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) { 00431 lsa->getHeader ().setLsAge (lsAge + 1); 00432 if ((lsAge + 1) % CHECK_AGE == 0) { 00433 if (!lsa->ValidateLSChecksum ()) { 00434 EV << "Invalid LS checksum. Memory error detected!\n"; 00435 } 00436 } 00437 lsa->IncrementInstallTime (); 00438 } 00439 if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))) { 00440 if (unreachable) { 00441 lsa->getHeader ().setLsAge (MAX_AGE); 00442 FloodLSA (lsa); 00443 lsa->IncrementInstallTime (); 00444 } else { 00445 long sequenceNumber = lsa->getHeader ().getLsSequenceNumber (); 00446 if (sequenceNumber == MAX_SEQUENCE_NUMBER) { 00447 lsa->getHeader ().setLsAge (MAX_AGE); 00448 FloodLSA (lsa); 00449 lsa->IncrementInstallTime (); 00450 } else { 00451 OSPF::NetworkLSA* newLSA = OriginateNetworkLSA (localIntf); 00452 00453 if (newLSA != NULL) { 00454 newLSA->getHeader ().setLsSequenceNumber (sequenceNumber + 1); 00455 newLSA->getHeader ().setLsChecksum (0); // TODO: calculate correct LS checksum 00456 rebuildRoutingTable |= lsa->Update (newLSA); 00457 delete newLSA; 00458 } else { // no neighbors on the network -> old NetworkLSA must be flushed 00459 lsa->getHeader ().setLsAge (MAX_AGE); 00460 lsa->IncrementInstallTime (); 00461 } 00462 00463 FloodLSA (lsa); 00464 } 00465 } 00466 } 00467 if (!selfOriginated && (lsAge == MAX_AGE - 1)) { 00468 lsa->getHeader ().setLsAge (MAX_AGE); 00469 FloodLSA (lsa); 00470 lsa->IncrementInstallTime (); 00471 } 00472 if (lsAge == MAX_AGE) { 00473 OSPF::LSAKeyType lsaKey; 00474 00475 lsaKey.linkStateID = lsa->getHeader ().getLinkStateID (); 00476 lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ().getInt (); 00477 00478 if (!IsOnAnyRetransmissionList (lsaKey) && 00479 !AnyNeighborInStates (OSPF::Neighbor::ExchangeState | OSPF::Neighbor::LoadingState)) 00480 { 00481 if (!selfOriginated || unreachable) { 00482 networkLSAsByID.erase (lsa->getHeader ().getLinkStateID ()); 00483 delete lsa; 00484 networkLSAs[i] = NULL; 00485 rebuildRoutingTable = true; 00486 } else { 00487 OSPF::NetworkLSA* newLSA = OriginateNetworkLSA (localIntf); 00488 long sequenceNumber = lsa->getHeader ().getLsSequenceNumber (); 00489 00490 if (newLSA != NULL) { 00491 newLSA->getHeader ().setLsSequenceNumber ((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1); 00492 newLSA->getHeader ().setLsChecksum (0); // TODO: calculate correct LS checksum 00493 rebuildRoutingTable |= lsa->Update (newLSA); 00494 delete newLSA; 00495 00496 FloodLSA (lsa); 00497 } else { // no neighbors on the network -> old NetworkLSA must be deleted 00498 delete networkLSAs[i]; 00499 } 00500 } 00501 } 00502 } 00503 } 00504 00505 std::vector<NetworkLSA*>::iterator networkIt = networkLSAs.begin (); 00506 while (networkIt != networkLSAs.end ()) { 00507 if ((*networkIt) == NULL) { 00508 networkIt = networkLSAs.erase (networkIt); 00509 } else { 00510 networkIt++; 00511 } 00512 } 00513 00514 lsaCount = summaryLSAs.size (); 00515 for (i = 0; i < lsaCount; i++) { 00516 unsigned short lsAge = summaryLSAs[i]->getHeader ().getLsAge (); 00517 bool selfOriginated = (summaryLSAs[i]->getHeader ().getAdvertisingRouter ().getInt () == parentRouter->GetRouterID ()); 00518 bool unreachable = parentRouter->DestinationIsUnreachable (summaryLSAs[i]); 00519 OSPF::SummaryLSA* lsa = summaryLSAs[i]; 00520 00521 if ((selfOriginated && (lsAge < (LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) { 00522 lsa->getHeader ().setLsAge (lsAge + 1); 00523 if ((lsAge + 1) % CHECK_AGE == 0) { 00524 if (!lsa->ValidateLSChecksum ()) { 00525 EV << "Invalid LS checksum. Memory error detected!\n"; 00526 } 00527 } 00528 lsa->IncrementInstallTime (); 00529 } 00530 if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))) { 00531 if (unreachable) { 00532 lsa->getHeader ().setLsAge (MAX_AGE); 00533 FloodLSA (lsa); 00534 lsa->IncrementInstallTime (); 00535 } else { 00536 long sequenceNumber = lsa->getHeader ().getLsSequenceNumber (); 00537 if (sequenceNumber == MAX_SEQUENCE_NUMBER) { 00538 lsa->getHeader ().setLsAge (MAX_AGE); 00539 FloodLSA (lsa); 00540 lsa->IncrementInstallTime (); 00541 } else { 00542 OSPF::SummaryLSA* newLSA = OriginateSummaryLSA (lsa); 00543 00544 if (newLSA != NULL) { 00545 newLSA->getHeader ().setLsSequenceNumber (sequenceNumber + 1); 00546 newLSA->getHeader ().setLsChecksum (0); // TODO: calculate correct LS checksum 00547 rebuildRoutingTable |= lsa->Update (newLSA); 00548 delete newLSA; 00549 00550 FloodLSA (lsa); 00551 } else { 00552 lsa->getHeader ().setLsAge (MAX_AGE); 00553 FloodLSA (lsa); 00554 lsa->IncrementInstallTime (); 00555 } 00556 } 00557 } 00558 } 00559 if (!selfOriginated && (lsAge == MAX_AGE - 1)) { 00560 lsa->getHeader ().setLsAge (MAX_AGE); 00561 FloodLSA (lsa); 00562 lsa->IncrementInstallTime (); 00563 } 00564 if (lsAge == MAX_AGE) { 00565 OSPF::LSAKeyType lsaKey; 00566 00567 lsaKey.linkStateID = lsa->getHeader ().getLinkStateID (); 00568 lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ().getInt (); 00569 00570 if (!IsOnAnyRetransmissionList (lsaKey) && 00571 !AnyNeighborInStates (OSPF::Neighbor::ExchangeState | OSPF::Neighbor::LoadingState)) 00572 { 00573 if (!selfOriginated || unreachable) { 00574 summaryLSAsByID.erase (lsaKey); 00575 delete lsa; 00576 summaryLSAs[i] = NULL; 00577 rebuildRoutingTable = true; 00578 } else { 00579 OSPF::SummaryLSA* newLSA = OriginateSummaryLSA (lsa); 00580 if (newLSA != NULL) { 00581 long sequenceNumber = lsa->getHeader ().getLsSequenceNumber (); 00582 00583 newLSA->getHeader ().setLsSequenceNumber ((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1); 00584 newLSA->getHeader ().setLsChecksum (0); // TODO: calculate correct LS checksum 00585 rebuildRoutingTable |= lsa->Update (newLSA); 00586 delete newLSA; 00587 00588 FloodLSA (lsa); 00589 } else { 00590 summaryLSAsByID.erase (lsaKey); 00591 delete lsa; 00592 summaryLSAs[i] = NULL; 00593 rebuildRoutingTable = true; 00594 } 00595 } 00596 } 00597 } 00598 } 00599 00600 std::vector<SummaryLSA*>::iterator summaryIt = summaryLSAs.begin (); 00601 while (summaryIt != summaryLSAs.end ()) { 00602 if ((*summaryIt) == NULL) { 00603 summaryIt = summaryLSAs.erase (summaryIt); 00604 } else { 00605 summaryIt++; 00606 } 00607 } 00608 00609 long interfaceCount = associatedInterfaces.size (); 00610 for (long m = 0; m < interfaceCount; m++) { 00611 associatedInterfaces[m]->AgeTransmittedLSALists (); 00612 } 00613 00614 if (rebuildRoutingTable) { 00615 parentRouter->RebuildRoutingTable (); 00616 } 00617 }
|
|
00620 { 00621 long interfaceCount = associatedInterfaces.size (); 00622 for (long i = 0; i < interfaceCount; i++) { 00623 if (associatedInterfaces[i]->AnyNeighborInStates (states)) { 00624 return true; 00625 } 00626 } 00627 return false; 00628 }
|
|
02194 { 02195 unsigned long i = 0; 02196 unsigned long j = 0; 02197 unsigned long lsaCount = summaryLSAs.size (); 02198 02199 for (i = 0; i < lsaCount; i++) { 02200 OSPF::SummaryLSA* currentLSA = summaryLSAs[i]; 02201 OSPFLSAHeader& currentHeader = currentLSA->getHeader (); 02202 02203 unsigned long routeCost = currentLSA->getRouteCost (); 02204 unsigned short lsAge = currentHeader.getLsAge (); 02205 RouterID originatingRouter = currentHeader.getAdvertisingRouter ().getInt (); 02206 bool selfOriginated = (originatingRouter == parentRouter->GetRouterID ()); 02207 02208 if ((routeCost == LS_INFINITY) || (lsAge == MAX_AGE) || (selfOriginated)) { // (1) and (2) 02209 continue; 02210 } 02211 02212 char lsType = currentHeader.getLsType (); 02213 unsigned long routeCount = newRoutingTable.size (); 02214 OSPF::IPv4AddressRange destination; 02215 02216 destination.address = IPv4AddressFromULong (currentHeader.getLinkStateID ()); 02217 destination.mask = IPv4AddressFromULong (currentLSA->getNetworkMask ().getInt ()); 02218 02219 if ((lsType == SummaryLSA_NetworksType) && (parentRouter->HasAddressRange (destination))) { // (3) 02220 bool foundIntraAreaRoute = false; 02221 02222 // look for an "Active" IntraArea route 02223 for (j = 0; j < routeCount; j++) { 02224 OSPF::RoutingTableEntry* routingEntry = newRoutingTable[j]; 02225 02226 if ((routingEntry->GetDestinationType () == OSPF::RoutingTableEntry::NetworkDestination) && 02227 (routingEntry->GetPathType () == OSPF::RoutingTableEntry::IntraArea) && 02228 ((routingEntry->GetDestinationID ().getInt () & 02229 routingEntry->GetAddressMask ().getInt () & 02230 ULongFromIPv4Address (destination.mask) ) == ULongFromIPv4Address (destination.address & 02231 destination.mask))) 02232 { 02233 foundIntraAreaRoute = true; 02234 break; 02235 } 02236 } 02237 if (foundIntraAreaRoute) { 02238 continue; 02239 } 02240 } 02241 02242 OSPF::RoutingTableEntry* borderRouterEntry = NULL; 02243 02244 // The routingEntry describes a route to an other area -> look for the border router originating it 02245 for (j = 0; j < routeCount; j++) { // (4) N == destination, BR == borderRouterEntry 02246 OSPF::RoutingTableEntry* routingEntry = newRoutingTable[j]; 02247 02248 if ((routingEntry->GetArea () == areaID) && 02249 (((routingEntry->GetDestinationType () & OSPF::RoutingTableEntry::AreaBorderRouterDestination) != 0) || 02250 ((routingEntry->GetDestinationType () & OSPF::RoutingTableEntry::ASBoundaryRouterDestination) != 0)) && 02251 (routingEntry->GetDestinationID ().getInt () == originatingRouter)) 02252 { 02253 borderRouterEntry = routingEntry; 02254 break; 02255 } 02256 } 02257 if (borderRouterEntry == NULL) { 02258 continue; 02259 } else { // (5) 02260 /* "Else, this LSA describes an inter-area path to destination N, 02261 * whose cost is the distance to BR plus the cost specified in the LSA. 02262 * Call the cost of this inter-area path IAC." 02263 */ 02264 bool destinationInRoutingTable = true; 02265 unsigned short currentCost = routeCost + borderRouterEntry->GetCost (); 02266 std::list<OSPF::RoutingTableEntry*> sameOrWorseCost; 02267 02268 if (FindSameOrWorseCostRoute (newRoutingTable, 02269 *currentLSA, 02270 currentCost, 02271 destinationInRoutingTable, 02272 sameOrWorseCost)) 02273 { 02274 continue; 02275 } 02276 02277 if (destinationInRoutingTable && (sameOrWorseCost.size () > 0)) { 02278 OSPF::RoutingTableEntry* equalEntry = NULL; 02279 02280 /* Look for an equal cost entry in the sameOrWorseCost list, and 02281 * also clear the more expensive entries from the newRoutingTable. 02282 */ 02283 for (std::list<OSPF::RoutingTableEntry*>::iterator it = sameOrWorseCost.begin (); it != sameOrWorseCost.end (); it++) { 02284 OSPF::RoutingTableEntry* checkedEntry = (*it); 02285 02286 if (checkedEntry->GetCost () > currentCost) { 02287 for (std::vector<OSPF::RoutingTableEntry*>::iterator entryIt = newRoutingTable.begin (); entryIt != newRoutingTable.end (); entryIt++) { 02288 if (checkedEntry == (*entryIt)) { 02289 newRoutingTable.erase (entryIt); 02290 break; 02291 } 02292 } 02293 } else { // EntryCost == currentCost 02294 equalEntry = checkedEntry; // should be only one - if there are more they are ignored 02295 } 02296 } 02297 02298 unsigned long nextHopCount = borderRouterEntry->GetNextHopCount (); 02299 02300 if (equalEntry != NULL) { 02301 /* Add the next hops of the border router advertising this destination 02302 * to the equal entry. 02303 */ 02304 for (unsigned long j = 0; j < nextHopCount; j++) { 02305 equalEntry->AddNextHop (borderRouterEntry->GetNextHop (j)); 02306 } 02307 } else { 02308 OSPF::RoutingTableEntry* newEntry = CreateRoutingTableEntryFromSummaryLSA (*currentLSA, currentCost, *borderRouterEntry); 02309 ASSERT (newEntry != NULL); 02310 newRoutingTable.push_back (newEntry); 02311 } 02312 } else { 02313 OSPF::RoutingTableEntry* newEntry = CreateRoutingTableEntryFromSummaryLSA (*currentLSA, currentCost, *borderRouterEntry); 02314 ASSERT (newEntry != NULL); 02315 newRoutingTable.push_back (newEntry); 02316 } 02317 } 02318 } 02319 }
|
|
01926 { 01927 std::vector<OSPF::NextHop>* hops = new std::vector<OSPF::NextHop>; 01928 unsigned long i; 01929 01930 OSPF::RouterLSA* routerLSA = check_and_cast<OSPF::RouterLSA*> (parent); 01931 if (routerLSA != spfTreeRoot) { 01932 unsigned int nextHopCount = routerLSA->GetNextHopCount (); 01933 for (i = 0; i < nextHopCount; i++) { 01934 hops->push_back (routerLSA->GetNextHop (i)); 01935 } 01936 return hops; 01937 } else { 01938 unsigned long interfaceNum = associatedInterfaces.size (); 01939 for (i = 0; i < interfaceNum; i++) { 01940 OSPF::Interface::OSPFInterfaceType intfType = associatedInterfaces[i]->GetType (); 01941 01942 if ((intfType == OSPF::Interface::PointToPoint) || 01943 ((intfType == OSPF::Interface::Virtual) && 01944 (associatedInterfaces[i]->GetState () > OSPF::Interface::LoopbackState))) 01945 { 01946 OSPF::Neighbor* neighbor = (associatedInterfaces[i]->GetNeighborCount () > 0) ? associatedInterfaces[i]->GetNeighbor (0) : NULL; 01947 if (neighbor != NULL) { 01948 OSPF::IPv4Address neighborAddress = neighbor->GetAddress (); 01949 if (((neighborAddress != OSPF::NullIPv4Address) && 01950 (ULongFromIPv4Address (neighborAddress) == destination.getLinkID ().getInt ())) || 01951 ((neighborAddress == OSPF::NullIPv4Address) && 01952 (ULongFromIPv4Address (associatedInterfaces[i]->GetAddressRange ().address) == destination.getLinkID ().getInt ()) && 01953 (ULongFromIPv4Address (associatedInterfaces[i]->GetAddressRange ().mask) == destination.getLinkData ()))) 01954 { 01955 NextHop nextHop; 01956 nextHop.ifIndex = associatedInterfaces[i]->GetIfIndex (); 01957 nextHop.hopAddress = neighborAddress; 01958 nextHop.advertisingRouter = parentRouter->GetRouterID (); 01959 hops->push_back (nextHop); 01960 break; 01961 } 01962 } 01963 } 01964 if ((intfType == OSPF::Interface::Broadcast) || 01965 (intfType == OSPF::Interface::NBMA)) 01966 { 01967 if ((destination.getLinkID ().getInt () == ULongFromIPv4Address (associatedInterfaces[i]->GetAddressRange ().address & associatedInterfaces[i]->GetAddressRange ().mask)) && 01968 (destination.getLinkData () == ULongFromIPv4Address (associatedInterfaces[i]->GetAddressRange ().mask))) 01969 { 01970 NextHop nextHop; 01971 nextHop.ifIndex = associatedInterfaces[i]->GetIfIndex (); 01972 nextHop.hopAddress = IPv4AddressFromULong (destination.getLinkID ().getInt ()); 01973 nextHop.advertisingRouter = parentRouter->GetRouterID (); 01974 hops->push_back (nextHop); 01975 break; 01976 } 01977 } 01978 if (intfType == OSPF::Interface::PointToMultiPoint) { 01979 if (destination.getType () == StubLink) { 01980 if (destination.getLinkID ().getInt () == ULongFromIPv4Address (associatedInterfaces[i]->GetAddressRange ().address)) { 01981 // The link contains the router's own interface address and a full mask, 01982 // so we insert a next hop pointing to the interface itself. Kind of pointless, but 01983 // not much else we could do... 01984 // TODO: check what other OSPF implementations do in this situation 01985 NextHop nextHop; 01986 nextHop.ifIndex = associatedInterfaces[i]->GetIfIndex (); 01987 nextHop.hopAddress = associatedInterfaces[i]->GetAddressRange ().address; 01988 nextHop.advertisingRouter = parentRouter->GetRouterID (); 01989 hops->push_back (nextHop); 01990 break; 01991 } 01992 } 01993 if (destination.getType () == PointToPointLink) { 01994 OSPF::Neighbor* neighbor = associatedInterfaces[i]->GetNeighborByID (destination.getLinkID ().getInt ()); 01995 if (neighbor != NULL) { 01996 NextHop nextHop; 01997 nextHop.ifIndex = associatedInterfaces[i]->GetIfIndex (); 01998 nextHop.hopAddress = neighbor->GetAddress (); 01999 nextHop.advertisingRouter = parentRouter->GetRouterID (); 02000 hops->push_back (nextHop); 02001 break; 02002 } 02003 } 02004 } 02005 // next hops for virtual links are generated later, after examining transit areas' SummaryLSAs 02006 } 02007 02008 if (hops->size () == 0) { 02009 unsigned long hostRouteCount = hostRoutes.size (); 02010 for (i = 0; i < hostRouteCount; i++) { 02011 if ((destination.getLinkID ().getInt () == ULongFromIPv4Address (hostRoutes[i].address)) && 02012 (destination.getLinkData () == 0xFFFFFFFF)) 02013 { 02014 NextHop nextHop; 02015 nextHop.ifIndex = hostRoutes[i].ifIndex; 02016 nextHop.hopAddress = hostRoutes[i].address; 02017 nextHop.advertisingRouter = parentRouter->GetRouterID (); 02018 hops->push_back (nextHop); 02019 break; 02020 } 02021 } 02022 } 02023 } 02024 02025 return hops; 02026 }
|
|
01798 { 01799 std::vector<OSPF::NextHop>* hops = new std::vector<OSPF::NextHop>; 01800 unsigned long i, j; 01801 01802 OSPF::RouterLSA* routerLSA = dynamic_cast<OSPF::RouterLSA*> (parent); 01803 if (routerLSA != NULL) { 01804 if (routerLSA != spfTreeRoot) { 01805 unsigned int nextHopCount = routerLSA->GetNextHopCount (); 01806 for (i = 0; i < nextHopCount; i++) { 01807 hops->push_back (routerLSA->GetNextHop (i)); 01808 } 01809 return hops; 01810 } else { 01811 OSPF::RouterLSA* destinationRouterLSA = dynamic_cast<OSPF::RouterLSA*> (destination); 01812 if (destinationRouterLSA != NULL) { 01813 unsigned long interfaceNum = associatedInterfaces.size (); 01814 for (i = 0; i < interfaceNum; i++) { 01815 OSPF::Interface::OSPFInterfaceType intfType = associatedInterfaces[i]->GetType (); 01816 if ((intfType == OSPF::Interface::PointToPoint) || 01817 ((intfType == OSPF::Interface::Virtual) && 01818 (associatedInterfaces[i]->GetState () > OSPF::Interface::LoopbackState))) 01819 { 01820 OSPF::Neighbor* ptpNeighbor = associatedInterfaces[i]->GetNeighbor (0); 01821 if (ptpNeighbor != NULL) { 01822 if (ptpNeighbor->GetNeighborID () == destinationRouterLSA->getHeader ().getLinkStateID ()) { 01823 NextHop nextHop; 01824 nextHop.ifIndex = associatedInterfaces[i]->GetIfIndex (); 01825 nextHop.hopAddress = ptpNeighbor->GetAddress (); 01826 nextHop.advertisingRouter = destinationRouterLSA->getHeader ().getAdvertisingRouter ().getInt (); 01827 hops->push_back (nextHop); 01828 break; 01829 } 01830 } 01831 } 01832 if (intfType == OSPF::Interface::PointToMultiPoint) { 01833 OSPF::Neighbor* ptmpNeighbor = associatedInterfaces[i]->GetNeighborByID (destinationRouterLSA->getHeader ().getLinkStateID ()); 01834 if (ptmpNeighbor != NULL) { 01835 unsigned int linkCount = destinationRouterLSA->getLinksArraySize (); 01836 OSPF::RouterID rootID = parentRouter->GetRouterID (); 01837 for (j = 0; j < linkCount; j++) { 01838 Link& link = destinationRouterLSA->getLinks (j); 01839 if (link.getLinkID () == rootID) { 01840 NextHop nextHop; 01841 nextHop.ifIndex = associatedInterfaces[i]->GetIfIndex (); 01842 nextHop.hopAddress = IPv4AddressFromULong (link.getLinkData ()); 01843 nextHop.advertisingRouter = destinationRouterLSA->getHeader ().getAdvertisingRouter ().getInt (); 01844 hops->push_back (nextHop); 01845 } 01846 } 01847 break; 01848 } 01849 } 01850 } 01851 } else { 01852 OSPF::NetworkLSA* destinationNetworkLSA = dynamic_cast<OSPF::NetworkLSA*> (destination); 01853 if (destinationNetworkLSA != NULL) { 01854 OSPF::IPv4Address networkDesignatedRouter = IPv4AddressFromULong (destinationNetworkLSA->getHeader ().getLinkStateID ()); 01855 unsigned long interfaceNum = associatedInterfaces.size (); 01856 for (i = 0; i < interfaceNum; i++) { 01857 OSPF::Interface::OSPFInterfaceType intfType = associatedInterfaces[i]->GetType (); 01858 if (((intfType == OSPF::Interface::Broadcast) || 01859 (intfType == OSPF::Interface::NBMA)) && 01860 (associatedInterfaces[i]->GetDesignatedRouter ().ipInterfaceAddress == networkDesignatedRouter)) 01861 { 01862 OSPF::IPv4AddressRange range = associatedInterfaces[i]->GetAddressRange (); 01863 NextHop nextHop; 01864 01865 nextHop.ifIndex = associatedInterfaces[i]->GetIfIndex (); 01866 nextHop.hopAddress = (range.address & range.mask); 01867 nextHop.advertisingRouter = destinationNetworkLSA->getHeader ().getAdvertisingRouter ().getInt (); 01868 hops->push_back (nextHop); 01869 } 01870 } 01871 } 01872 } 01873 } 01874 } else { 01875 OSPF::NetworkLSA* networkLSA = dynamic_cast<OSPF::NetworkLSA*> (parent); 01876 if (networkLSA != NULL) { 01877 if (networkLSA->GetParent () != spfTreeRoot) { 01878 unsigned int nextHopCount = networkLSA->GetNextHopCount (); 01879 for (i = 0; i < nextHopCount; i++) { 01880 hops->push_back (networkLSA->GetNextHop (i)); 01881 } 01882 return hops; 01883 } else { 01884 unsigned long parentLinkStateID = parent->getHeader ().getLinkStateID (); 01885 01886 OSPF::RouterLSA* destinationRouterLSA = dynamic_cast<OSPF::RouterLSA*> (destination); 01887 if (destinationRouterLSA != NULL) { 01888 OSPF::RouterID destinationRouterID = destinationRouterLSA->getHeader ().getLinkStateID (); 01889 unsigned int linkCount = destinationRouterLSA->getLinksArraySize (); 01890 for (i = 0; i < linkCount; i++) { 01891 Link& link = destinationRouterLSA->getLinks (i); 01892 NextHop nextHop; 01893 01894 if (((link.getType () == TransitLink) && 01895 (link.getLinkID ().getInt () == parentLinkStateID)) || 01896 ((link.getType () == StubLink) && 01897 ((link.getLinkID ().getInt () & link.getLinkData ()) == (parentLinkStateID & networkLSA->getNetworkMask ().getInt ())))) 01898 { 01899 unsigned long interfaceNum = associatedInterfaces.size (); 01900 for (j = 0; j < interfaceNum; j++) { 01901 OSPF::Interface::OSPFInterfaceType intfType = associatedInterfaces[j]->GetType (); 01902 if (((intfType == OSPF::Interface::Broadcast) || 01903 (intfType == OSPF::Interface::NBMA)) && 01904 (associatedInterfaces[j]->GetDesignatedRouter ().ipInterfaceAddress == IPv4AddressFromULong (parentLinkStateID))) 01905 { 01906 OSPF::Neighbor* nextHopNeighbor = associatedInterfaces[j]->GetNeighborByID (destinationRouterID); 01907 if (nextHopNeighbor != NULL) { 01908 nextHop.ifIndex = associatedInterfaces[j]->GetIfIndex (); 01909 nextHop.hopAddress = nextHopNeighbor->GetAddress (); 01910 nextHop.advertisingRouter = destinationRouterLSA->getHeader ().getAdvertisingRouter ().getInt (); 01911 hops->push_back (nextHop); 01912 } 01913 } 01914 } 01915 } 01916 } 01917 } 01918 } 01919 } 01920 } 01921 01922 return hops; 01923 }
|
|
01321 { 01322 OSPF::RouterID routerID = parentRouter->GetRouterID (); 01323 bool finished = false; 01324 std::vector<OSPFLSA*> treeVertices; 01325 OSPFLSA* justAddedVertex; 01326 std::vector<OSPFLSA*> candidateVertices; 01327 unsigned long i, j, k; 01328 unsigned long lsaCount; 01329 01330 if (spfTreeRoot == NULL) { 01331 OSPF::RouterLSA* newLSA = OriginateRouterLSA (); 01332 01333 InstallRouterLSA (newLSA); 01334 01335 OSPF::RouterLSA* routerLSA = FindRouterLSA (routerID); 01336 01337 spfTreeRoot = routerLSA; 01338 FloodLSA (newLSA); 01339 delete newLSA; 01340 } 01341 if (spfTreeRoot == NULL) { 01342 return; 01343 } 01344 01345 lsaCount = routerLSAs.size (); 01346 for (i = 0; i < lsaCount; i++) { 01347 routerLSAs[i]->ClearNextHops (); 01348 } 01349 lsaCount = networkLSAs.size (); 01350 for (i = 0; i < lsaCount; i++) { 01351 networkLSAs[i]->ClearNextHops (); 01352 } 01353 spfTreeRoot->SetDistance (0); 01354 treeVertices.push_back (spfTreeRoot); 01355 justAddedVertex = spfTreeRoot; // (1) 01356 01357 do { 01358 LSAType vertexType = static_cast<LSAType> (justAddedVertex->getHeader ().getLsType ()); 01359 01360 if ((vertexType == RouterLSAType)) { 01361 OSPF::RouterLSA* routerVertex = check_and_cast<OSPF::RouterLSA*> (justAddedVertex); 01362 if (routerVertex->getV_VirtualLinkEndpoint ()) { // (2) 01363 transitCapability = true; 01364 } 01365 01366 unsigned int linkCount = routerVertex->getLinksArraySize (); 01367 for (i = 0; i < linkCount; i++) { 01368 Link& link = routerVertex->getLinks (i); 01369 LinkType linkType = static_cast<LinkType> (link.getType ()); 01370 OSPFLSA* joiningVertex; 01371 LSAType joiningVertexType; 01372 01373 if (linkType == StubLink) { // (2) (a) 01374 continue; 01375 } 01376 01377 if (linkType == TransitLink) { 01378 joiningVertex = FindNetworkLSA (link.getLinkID ().getInt ()); 01379 joiningVertexType = NetworkLSAType; 01380 } else { 01381 joiningVertex = FindRouterLSA (link.getLinkID ().getInt ()); 01382 joiningVertexType = RouterLSAType; 01383 } 01384 01385 if ((joiningVertex == NULL) || 01386 (joiningVertex->getHeader ().getLsAge () == MAX_AGE) || 01387 (!HasLink (joiningVertex, justAddedVertex))) // (from, to) (2) (b) 01388 { 01389 continue; 01390 } 01391 01392 unsigned int treeSize = treeVertices.size (); 01393 bool alreadyOnTree = false; 01394 01395 for (j = 0; j < treeSize; j++) { 01396 if (treeVertices[j] == joiningVertex) { 01397 alreadyOnTree = true; 01398 break; 01399 } 01400 } 01401 if (alreadyOnTree) { // (2) (c) 01402 continue; 01403 } 01404 01405 unsigned long linkStateCost = routerVertex->GetDistance () + link.getLinkCost (); 01406 unsigned int candidateCount = candidateVertices.size (); 01407 OSPFLSA* candidate = NULL; 01408 01409 for (j = 0; j < candidateCount; j++) { 01410 if (candidateVertices[j] == joiningVertex) { 01411 candidate = candidateVertices[j]; 01412 } 01413 } 01414 if (candidate != NULL) { // (2) (d) 01415 OSPF::RoutingInfo* routingInfo = check_and_cast<OSPF::RoutingInfo*> (candidate); 01416 unsigned long candidateDistance = routingInfo->GetDistance (); 01417 01418 if (linkStateCost > candidateDistance) { 01419 continue; 01420 } 01421 if (linkStateCost < candidateDistance) { 01422 routingInfo->SetDistance (linkStateCost); 01423 routingInfo->ClearNextHops (); 01424 } 01425 std::vector<OSPF::NextHop>* newNextHops = CalculateNextHops (joiningVertex, justAddedVertex); // (destination, parent) 01426 unsigned int nextHopCount = newNextHops->size (); 01427 for (k = 0; k < nextHopCount; k++) { 01428 routingInfo->AddNextHop ((*newNextHops)[k]); 01429 } 01430 delete newNextHops; 01431 } else { 01432 if (joiningVertexType == RouterLSAType) { 01433 OSPF::RouterLSA* joiningRouterVertex = check_and_cast<OSPF::RouterLSA*> (joiningVertex); 01434 joiningRouterVertex->SetDistance (linkStateCost); 01435 std::vector<OSPF::NextHop>* newNextHops = CalculateNextHops (joiningVertex, justAddedVertex); // (destination, parent) 01436 unsigned int nextHopCount = newNextHops->size (); 01437 for (k = 0; k < nextHopCount; k++) { 01438 joiningRouterVertex->AddNextHop ((*newNextHops)[k]); 01439 } 01440 delete newNextHops; 01441 OSPF::RoutingInfo* vertexRoutingInfo = check_and_cast<OSPF::RoutingInfo*> (joiningRouterVertex); 01442 vertexRoutingInfo->SetParent (justAddedVertex); 01443 01444 candidateVertices.push_back (joiningRouterVertex); 01445 } else { 01446 OSPF::NetworkLSA* joiningNetworkVertex = check_and_cast<OSPF::NetworkLSA*> (joiningVertex); 01447 joiningNetworkVertex->SetDistance (linkStateCost); 01448 std::vector<OSPF::NextHop>* newNextHops = CalculateNextHops (joiningVertex, justAddedVertex); // (destination, parent) 01449 unsigned int nextHopCount = newNextHops->size (); 01450 for (k = 0; k < nextHopCount; k++) { 01451 joiningNetworkVertex->AddNextHop ((*newNextHops)[k]); 01452 } 01453 delete newNextHops; 01454 OSPF::RoutingInfo* vertexRoutingInfo = check_and_cast<OSPF::RoutingInfo*> (joiningNetworkVertex); 01455 vertexRoutingInfo->SetParent (justAddedVertex); 01456 01457 candidateVertices.push_back (joiningNetworkVertex); 01458 } 01459 } 01460 } 01461 } 01462 01463 if ((vertexType == NetworkLSAType)) { 01464 OSPF::NetworkLSA* networkVertex = check_and_cast<OSPF::NetworkLSA*> (justAddedVertex); 01465 unsigned int routerCount = networkVertex->getAttachedRoutersArraySize (); 01466 01467 for (i = 0; i < routerCount; i++) { // (2) 01468 OSPF::RouterLSA* joiningVertex = FindRouterLSA (networkVertex->getAttachedRouters (i).getInt ()); 01469 if ((joiningVertex == NULL) || 01470 (joiningVertex->getHeader ().getLsAge () == MAX_AGE) || 01471 (!HasLink (joiningVertex, justAddedVertex))) // (from, to) (2) (b) 01472 { 01473 continue; 01474 } 01475 01476 unsigned int treeSize = treeVertices.size (); 01477 bool alreadyOnTree = false; 01478 01479 for (j = 0; j < treeSize; j++) { 01480 if (treeVertices[j] == joiningVertex) { 01481 alreadyOnTree = true; 01482 break; 01483 } 01484 } 01485 if (alreadyOnTree) { // (2) (c) 01486 continue; 01487 } 01488 01489 unsigned long linkStateCost = networkVertex->GetDistance (); // link cost from network to router is always 0 01490 unsigned int candidateCount = candidateVertices.size (); 01491 OSPFLSA* candidate = NULL; 01492 01493 for (j = 0; j < candidateCount; j++) { 01494 if (candidateVertices[j] == joiningVertex) { 01495 candidate = candidateVertices[j]; 01496 } 01497 } 01498 if (candidate != NULL) { // (2) (d) 01499 OSPF::RoutingInfo* routingInfo = check_and_cast<OSPF::RoutingInfo*> (candidate); 01500 unsigned long candidateDistance = routingInfo->GetDistance (); 01501 01502 if (linkStateCost > candidateDistance) { 01503 continue; 01504 } 01505 if (linkStateCost < candidateDistance) { 01506 routingInfo->SetDistance (linkStateCost); 01507 routingInfo->ClearNextHops (); 01508 } 01509 std::vector<OSPF::NextHop>* newNextHops = CalculateNextHops (joiningVertex, justAddedVertex); // (destination, parent) 01510 unsigned int nextHopCount = newNextHops->size (); 01511 for (k = 0; k < nextHopCount; k++) { 01512 routingInfo->AddNextHop ((*newNextHops)[k]); 01513 } 01514 delete newNextHops; 01515 } else { 01516 joiningVertex->SetDistance (linkStateCost); 01517 std::vector<OSPF::NextHop>* newNextHops = CalculateNextHops (joiningVertex, justAddedVertex); // (destination, parent) 01518 unsigned int nextHopCount = newNextHops->size (); 01519 for (k = 0; k < nextHopCount; k++) { 01520 joiningVertex->AddNextHop ((*newNextHops)[k]); 01521 } 01522 delete newNextHops; 01523 OSPF::RoutingInfo* vertexRoutingInfo = check_and_cast<OSPF::RoutingInfo*> (joiningVertex); 01524 vertexRoutingInfo->SetParent (justAddedVertex); 01525 01526 candidateVertices.push_back (joiningVertex); 01527 } 01528 } 01529 } 01530 01531 if (candidateVertices.empty ()) { // (3) 01532 finished = true; 01533 } else { 01534 unsigned int candidateCount = candidateVertices.size (); 01535 unsigned long minDistance = LS_INFINITY; 01536 OSPFLSA* closestVertex = candidateVertices[0]; 01537 01538 for (i = 0; i < candidateCount; i++) { 01539 OSPF::RoutingInfo* routingInfo = check_and_cast<OSPF::RoutingInfo*> (candidateVertices[i]); 01540 unsigned long currentDistance = routingInfo->GetDistance (); 01541 01542 if (currentDistance < minDistance) { 01543 closestVertex = candidateVertices[i]; 01544 minDistance = currentDistance; 01545 } else { 01546 if (currentDistance == minDistance) { 01547 if ((closestVertex->getHeader ().getLsType () == RouterLSAType) && 01548 (candidateVertices[i]->getHeader ().getLsType () == NetworkLSAType)) 01549 { 01550 closestVertex = candidateVertices[i]; 01551 } 01552 } 01553 } 01554 } 01555 01556 treeVertices.push_back (closestVertex); 01557 01558 for (std::vector<OSPFLSA*>::iterator it = candidateVertices.begin (); it != candidateVertices.end (); it++) { 01559 if ((*it) == closestVertex) { 01560 candidateVertices.erase (it); 01561 break; 01562 } 01563 } 01564 01565 if (closestVertex->getHeader ().getLsType () == RouterLSAType) { 01566 OSPF::RouterLSA* routerLSA = check_and_cast<OSPF::RouterLSA*> (closestVertex); 01567 if (routerLSA->getB_AreaBorderRouter () || routerLSA->getE_ASBoundaryRouter ()) { 01568 OSPF::RoutingTableEntry* entry = new OSPF::RoutingTableEntry; 01569 OSPF::RouterID destinationID = routerLSA->getHeader ().getLinkStateID (); 01570 unsigned int nextHopCount = routerLSA->GetNextHopCount (); 01571 OSPF::RoutingTableEntry::RoutingDestinationType destinationType = OSPF::RoutingTableEntry::NetworkDestination; 01572 01573 entry->SetDestinationID (destinationID); 01574 entry->SetLinkStateOrigin (routerLSA); 01575 entry->SetArea (areaID); 01576 entry->SetPathType (OSPF::RoutingTableEntry::IntraArea); 01577 entry->SetCost (routerLSA->GetDistance ()); 01578 if (routerLSA->getB_AreaBorderRouter ()) { 01579 destinationType |= OSPF::RoutingTableEntry::AreaBorderRouterDestination; 01580 } 01581 if (routerLSA->getE_ASBoundaryRouter ()) { 01582 destinationType |= OSPF::RoutingTableEntry::ASBoundaryRouterDestination; 01583 } 01584 entry->SetDestinationType (destinationType); 01585 entry->SetOptionalCapabilities (routerLSA->getHeader ().getLsOptions ()); 01586 for (i = 0; i < nextHopCount; i++) { 01587 entry->AddNextHop (routerLSA->GetNextHop (i)); 01588 } 01589 01590 newRoutingTable.push_back (entry); 01591 01592 OSPF::Area* backbone; 01593 if (areaID != OSPF::BackboneAreaID) { 01594 backbone = parentRouter->GetArea (OSPF::BackboneAreaID); 01595 } else { 01596 backbone = this; 01597 } 01598 if (backbone != NULL) { 01599 OSPF::Interface* virtualIntf = backbone->FindVirtualLink (destinationID); 01600 if ((virtualIntf != NULL) && (virtualIntf->GetTransitAreaID () == areaID)) { 01601 OSPF::IPv4AddressRange range; 01602 range.address = GetInterface (routerLSA->GetNextHop (0).ifIndex)->GetAddressRange ().address; 01603 range.mask = IPv4AddressFromULong (0xFFFFFFFF); 01604 virtualIntf->SetAddressRange (range); 01605 virtualIntf->SetIfIndex (routerLSA->GetNextHop (0).ifIndex); 01606 virtualIntf->SetOutputCost (routerLSA->GetDistance ()); 01607 OSPF::Neighbor* virtualNeighbor = virtualIntf->GetNeighbor (0); 01608 if (virtualNeighbor != NULL) { 01609 unsigned int linkCount = routerLSA->getLinksArraySize (); 01610 OSPF::RouterLSA* toRouterLSA = dynamic_cast<OSPF::RouterLSA*> (justAddedVertex); 01611 if (toRouterLSA != NULL) { 01612 for (i = 0; i < linkCount; i++) { 01613 Link& link = routerLSA->getLinks (i); 01614 01615 if ((link.getType () == PointToPointLink) && 01616 (link.getLinkID () == toRouterLSA->getHeader ().getLinkStateID ()) && 01617 (virtualIntf->GetState () < OSPF::Interface::WaitingState)) 01618 { 01619 virtualNeighbor->SetAddress (IPv4AddressFromULong (link.getLinkData ())); 01620 virtualIntf->ProcessEvent (OSPF::Interface::InterfaceUp); 01621 break; 01622 } 01623 } 01624 } else { 01625 OSPF::NetworkLSA* toNetworkLSA = dynamic_cast<OSPF::NetworkLSA*> (justAddedVertex); 01626 if (toNetworkLSA != NULL) { 01627 for (i = 0; i < linkCount; i++) { 01628 Link& link = routerLSA->getLinks (i); 01629 01630 if ((link.getType () == TransitLink) && 01631 (link.getLinkID () == toNetworkLSA->getHeader ().getLinkStateID ()) && 01632 (virtualIntf->GetState () < OSPF::Interface::WaitingState)) 01633 { 01634 virtualNeighbor->SetAddress (IPv4AddressFromULong (link.getLinkData ())); 01635 virtualIntf->ProcessEvent (OSPF::Interface::InterfaceUp); 01636 break; 01637 } 01638 } 01639 } 01640 } 01641 } 01642 } 01643 } 01644 } 01645 } 01646 01647 if (closestVertex->getHeader ().getLsType () == NetworkLSAType) { 01648 OSPF::NetworkLSA* networkLSA = check_and_cast<OSPF::NetworkLSA*> (closestVertex); 01649 unsigned long destinationID = (networkLSA->getHeader().getLinkStateID () & networkLSA->getNetworkMask ().getInt ()); 01650 unsigned int nextHopCount = networkLSA->GetNextHopCount (); 01651 bool overWrite = false; 01652 OSPF::RoutingTableEntry* entry = NULL; 01653 unsigned long routeCount = newRoutingTable.size (); 01654 unsigned long longestMatch = 0; 01655 01656 for (i = 0; i < routeCount; i++) { 01657 if (newRoutingTable[i]->GetDestinationType () == OSPF::RoutingTableEntry::NetworkDestination) { 01658 OSPF::RoutingTableEntry* routingEntry = newRoutingTable[i]; 01659 unsigned long entryAddress = routingEntry->GetDestinationID ().getInt (); 01660 unsigned long entryMask = routingEntry->GetAddressMask ().getInt (); 01661 01662 if ((entryAddress & entryMask) == (destinationID & entryMask)) { 01663 if ((destinationID & entryMask) > longestMatch) { 01664 longestMatch = (destinationID & entryMask); 01665 entry = routingEntry; 01666 } 01667 } 01668 } 01669 } 01670 if (entry != NULL) { 01671 const OSPFLSA* entryOrigin = entry->GetLinkStateOrigin (); 01672 if ((entry->GetCost () != networkLSA->GetDistance ()) || 01673 (entryOrigin->getHeader ().getLinkStateID () >= networkLSA->getHeader().getLinkStateID ())) 01674 { 01675 overWrite = true; 01676 } 01677 } 01678 01679 if ((entry == NULL) || (overWrite)) { 01680 if (entry == NULL) { 01681 entry = new OSPF::RoutingTableEntry; 01682 } 01683 01684 entry->SetDestinationID (destinationID); 01685 entry->SetAddressMask (networkLSA->getNetworkMask ()); 01686 entry->SetLinkStateOrigin (networkLSA); 01687 entry->SetArea (areaID); 01688 entry->SetPathType (OSPF::RoutingTableEntry::IntraArea); 01689 entry->SetCost (networkLSA->GetDistance ()); 01690 entry->SetDestinationType (OSPF::RoutingTableEntry::NetworkDestination); 01691 entry->SetOptionalCapabilities (networkLSA->getHeader ().getLsOptions ()); 01692 for (i = 0; i < nextHopCount; i++) { 01693 entry->AddNextHop (networkLSA->GetNextHop (i)); 01694 } 01695 01696 if (!overWrite) { 01697 newRoutingTable.push_back (entry); 01698 } 01699 } 01700 } 01701 01702 justAddedVertex = closestVertex; 01703 } 01704 } while (!finished); 01705 01706 unsigned int treeSize = treeVertices.size (); 01707 for (i = 0; i < treeSize; i++) { 01708 OSPF::RouterLSA* routerVertex = dynamic_cast<OSPF::RouterLSA*> (treeVertices[i]); 01709 if (routerVertex == NULL) { 01710 continue; 01711 } 01712 01713 unsigned int linkCount = routerVertex->getLinksArraySize (); 01714 for (j = 0; j < linkCount; j++) { 01715 Link& link = routerVertex->getLinks (j); 01716 if (link.getType () != StubLink) { 01717 continue; 01718 } 01719 01720 unsigned long distance = routerVertex->GetDistance () + link.getLinkCost (); 01721 unsigned long destinationID = (link.getLinkID ().getInt () & link.getLinkData ()); 01722 OSPF::RoutingTableEntry* entry = NULL; 01723 unsigned long routeCount = newRoutingTable.size (); 01724 unsigned long longestMatch = 0; 01725 01726 for (k = 0; k < routeCount; k++) { 01727 if (newRoutingTable[k]->GetDestinationType () == OSPF::RoutingTableEntry::NetworkDestination) { 01728 OSPF::RoutingTableEntry* routingEntry = newRoutingTable[k]; 01729 unsigned long entryAddress = routingEntry->GetDestinationID ().getInt (); 01730 unsigned long entryMask = routingEntry->GetAddressMask ().getInt (); 01731 01732 if ((entryAddress & entryMask) == (destinationID & entryMask)) { 01733 if ((destinationID & entryMask) > longestMatch) { 01734 longestMatch = (destinationID & entryMask); 01735 entry = routingEntry; 01736 } 01737 } 01738 } 01739 } 01740 01741 if (entry != NULL) { 01742 Metric entryCost = entry->GetCost (); 01743 01744 if (distance > entryCost) { 01745 continue; 01746 } 01747 if (distance < entryCost) { 01748 //FIXME remove 01749 //if (parentRouter->GetRouterID () == 0xC0A80302) { 01750 // EV << "CHEAPER STUB LINK FOUND TO " << IPAddress (destinationID).str () << "\n"; 01751 //} 01752 entry->SetCost (distance); 01753 entry->ClearNextHops (); 01754 entry->SetLinkStateOrigin (routerVertex); 01755 } 01756 if (distance == entryCost) { 01757 // no const version from check_and_cast 01758 OSPF::RouterLSA* routerOrigin = check_and_cast<OSPF::RouterLSA*> (const_cast<OSPFLSA*> (entry->GetLinkStateOrigin ())); 01759 if (routerOrigin->getHeader ().getLinkStateID () < routerVertex->getHeader ().getLinkStateID ()) { 01760 entry->SetLinkStateOrigin (routerVertex); 01761 } 01762 } 01763 std::vector<OSPF::NextHop>* newNextHops = CalculateNextHops (link, routerVertex); // (destination, parent) 01764 unsigned int nextHopCount = newNextHops->size (); 01765 for (k = 0; k < nextHopCount; k++) { 01766 entry->AddNextHop ((*newNextHops)[k]); 01767 } 01768 delete newNextHops; 01769 } else { 01770 //FIXME remove 01771 //if (parentRouter->GetRouterID () == 0xC0A80302) { 01772 // EV << "STUB LINK FOUND TO " << IPAddress (destinationID).str () << "\n"; 01773 //} 01774 entry = new OSPF::RoutingTableEntry; 01775 01776 entry->SetDestinationID (destinationID); 01777 entry->SetAddressMask (link.getLinkData ()); 01778 entry->SetLinkStateOrigin (routerVertex); 01779 entry->SetArea (areaID); 01780 entry->SetPathType (OSPF::RoutingTableEntry::IntraArea); 01781 entry->SetCost (distance); 01782 entry->SetDestinationType (OSPF::RoutingTableEntry::NetworkDestination); 01783 entry->SetOptionalCapabilities (routerVertex->getHeader ().getLsOptions ()); 01784 std::vector<OSPF::NextHop>* newNextHops = CalculateNextHops (link, routerVertex); // (destination, parent) 01785 unsigned int nextHopCount = newNextHops->size (); 01786 for (k = 0; k < nextHopCount; k++) { 01787 entry->AddNextHop ((*newNextHops)[k]); 01788 } 01789 delete newNextHops; 01790 01791 newRoutingTable.push_back (entry); 01792 } 01793 } 01794 } 01795 }
|
|
00101 { 00102 int addressRangeNum = areaAddressRanges.size (); 00103 for (int i = 0; i < addressRangeNum; i++) { 00104 if ((areaAddressRanges[i].address & areaAddressRanges[i].mask) == (address & areaAddressRanges[i].mask)) { 00105 return true; 00106 } 00107 } 00108 return false; 00109 }
|
|
Returns a new RoutingTableEntry based on the input SummaryLSA, with the input cost and the borderRouterEntry's next hops. 02156 { 02157 OSPF::IPv4AddressRange destination; 02158 02159 destination.address = IPv4AddressFromULong (summaryLSA.getHeader ().getLinkStateID ()); 02160 destination.mask = IPv4AddressFromULong (summaryLSA.getNetworkMask ().getInt ()); 02161 02162 OSPF::RoutingTableEntry* newEntry = new OSPF::RoutingTableEntry; 02163 02164 if (summaryLSA.getHeader ().getLsType () == SummaryLSA_NetworksType) { 02165 newEntry->SetDestinationID (ULongFromIPv4Address (destination.address & destination.mask)); 02166 newEntry->SetAddressMask (ULongFromIPv4Address (destination.mask)); 02167 newEntry->SetDestinationType (OSPF::RoutingTableEntry::NetworkDestination); 02168 } else { 02169 newEntry->SetDestinationID (ULongFromIPv4Address (destination.address)); 02170 newEntry->SetAddressMask (0xFFFFFFFF); 02171 newEntry->SetDestinationType (OSPF::RoutingTableEntry::ASBoundaryRouterDestination); 02172 } 02173 newEntry->SetArea (areaID); 02174 newEntry->SetPathType (OSPF::RoutingTableEntry::InterArea); 02175 newEntry->SetCost (entryCost); 02176 newEntry->SetOptionalCapabilities (summaryLSA.getHeader ().getLsOptions ()); 02177 newEntry->SetLinkStateOrigin (&summaryLSA); 02178 02179 unsigned int nextHopCount = borderRouterEntry.GetNextHopCount (); 02180 for (unsigned int j = 0; j < nextHopCount; j++) { 02181 newEntry->AddNextHop (borderRouterEntry.GetNextHop (j)); 02182 } 02183 02184 return newEntry; 02185 }
|
|
00056 { 00057 std::stringstream out; 00058 char addressString[16]; 00059 int i; 00060 out << "\n areaID: " << AddressStringFromULong (addressString, 16, areaID) << ", "; 00061 out << "transitCapability: " << (transitCapability ? "true" : "false") << ", "; 00062 out << "externalRoutingCapability: " << (externalRoutingCapability ? "true" : "false") << ", "; 00063 out << "stubDefaultCost: " << stubDefaultCost << "\n"; 00064 int addressRangeNum = areaAddressRanges.size (); 00065 for (i = 0; i < addressRangeNum; i++) { 00066 out << " addressRanges[" << i << "]: "; 00067 out << AddressStringFromIPv4Address (addressString, 16, areaAddressRanges[i].address); 00068 out << "/" << AddressStringFromIPv4Address (addressString, 16, areaAddressRanges[i].mask) << "\n"; 00069 } 00070 int interfaceNum = associatedInterfaces.size (); 00071 for (i = 0; i < interfaceNum; i++) { 00072 out << " interface[" << i << "]: addressRange: "; 00073 out << AddressStringFromIPv4Address (addressString, 16, associatedInterfaces[i]->GetAddressRange ().address); 00074 out << "/" << AddressStringFromIPv4Address (addressString, 16, associatedInterfaces[i]->GetAddressRange ().mask) << "\n"; 00075 } 00076 00077 out << "\n"; 00078 out << " Database:\n"; 00079 out << " RouterLSAs:\n"; 00080 long lsaCount = routerLSAs.size (); 00081 for (i = 0; i < lsaCount; i++) { 00082 out << " " << *routerLSAs[i] << "\n"; 00083 } 00084 out << " NetworkLSAs:\n"; 00085 lsaCount = networkLSAs.size (); 00086 for (i = 0; i < lsaCount; i++) { 00087 out << " " << *networkLSAs[i] << "\n"; 00088 } 00089 out << " SummaryLSAs:\n"; 00090 lsaCount = summaryLSAs.size (); 00091 for (i = 0; i < lsaCount; i++) { 00092 out << " " << *summaryLSAs[i] << "\n"; 00093 } 00094 00095 out << "--------------------------------------------------------------------------------"; 00096 00097 return out.str(); 00098 }
|
|
00298 { 00299 std::map<OSPF::LinkStateID, OSPF::NetworkLSA*>::const_iterator lsaIt = networkLSAsByID.find (linkStateID); 00300 if (lsaIt != networkLSAsByID.end ()) { 00301 return lsaIt->second; 00302 } else { 00303 return NULL; 00304 } 00305 }
|
|
00288 { 00289 std::map<OSPF::LinkStateID, OSPF::NetworkLSA*>::iterator lsaIt = networkLSAsByID.find (linkStateID); 00290 if (lsaIt != networkLSAsByID.end ()) { 00291 return lsaIt->second; 00292 } else { 00293 return NULL; 00294 } 00295 }
|
|
00278 { 00279 std::map<OSPF::LinkStateID, OSPF::RouterLSA*>::const_iterator lsaIt = routerLSAsByID.find (linkStateID); 00280 if (lsaIt != routerLSAsByID.end ()) { 00281 return lsaIt->second; 00282 } else { 00283 return NULL; 00284 } 00285 }
|
|
00268 { 00269 std::map<OSPF::LinkStateID, OSPF::RouterLSA*>::iterator lsaIt = routerLSAsByID.find (linkStateID); 00270 if (lsaIt != routerLSAsByID.end ()) { 00271 return lsaIt->second; 00272 } else { 00273 return NULL; 00274 } 00275 }
|
|
Browse through the newRoutingTable looking for entries describing the same destination as the currentLSA. If a cheaper route is found then skip this LSA (return true), else note those which are of equal or worse cost than the currentCost. 02095 { 02096 destinationInRoutingTable = false; 02097 sameOrWorseCost.clear (); 02098 02099 long routeCount = newRoutingTable.size (); 02100 OSPF::IPv4AddressRange destination; 02101 02102 destination.address = IPv4AddressFromULong (summaryLSA.getHeader ().getLinkStateID ()); 02103 destination.mask = IPv4AddressFromULong (summaryLSA.getNetworkMask ().getInt ()); 02104 02105 for (long j = 0; j < routeCount; j++) { 02106 OSPF::RoutingTableEntry* routingEntry = newRoutingTable[j]; 02107 bool foundMatching = false; 02108 02109 if (summaryLSA.getHeader ().getLsType () == SummaryLSA_NetworksType) { 02110 if ((routingEntry->GetDestinationType () == OSPF::RoutingTableEntry::NetworkDestination) && 02111 (ULongFromIPv4Address (destination.address & destination.mask) == routingEntry->GetDestinationID ().getInt ())) 02112 { 02113 foundMatching = true; 02114 } 02115 } else { 02116 if ((((routingEntry->GetDestinationType () & OSPF::RoutingTableEntry::AreaBorderRouterDestination) != 0) || 02117 ((routingEntry->GetDestinationType () & OSPF::RoutingTableEntry::ASBoundaryRouterDestination) != 0)) && 02118 (ULongFromIPv4Address (destination.address) == routingEntry->GetDestinationID ().getInt ())) 02119 { 02120 foundMatching = true; 02121 } 02122 } 02123 02124 if (foundMatching) { 02125 destinationInRoutingTable = true; 02126 02127 /* If the matching entry is an IntraArea route (intra-area paths are 02128 * always preferred to other paths of any cost), or it's a cheaper InterArea 02129 * route, then skip this LSA. 02130 */ 02131 if ((routingEntry->GetPathType () == OSPF::RoutingTableEntry::IntraArea) || 02132 ((routingEntry->GetPathType () == OSPF::RoutingTableEntry::InterArea) && 02133 (routingEntry->GetCost () < currentCost))) 02134 { 02135 return true; 02136 } else { 02137 // if it's an other InterArea path 02138 if ((routingEntry->GetPathType () == OSPF::RoutingTableEntry::InterArea) && 02139 (routingEntry->GetCost () >= currentCost)) 02140 { 02141 sameOrWorseCost.push_back (routingEntry); 02142 } // else it's external -> same as if not in the table 02143 } 02144 } 02145 } 02146 return false; 02147 }
|
|
00318 { 00319 std::map<OSPF::LSAKeyType, OSPF::SummaryLSA*, OSPF::LSAKeyType_Less>::const_iterator lsaIt = summaryLSAsByID.find (lsaKey); 00320 if (lsaIt != summaryLSAsByID.end ()) { 00321 return lsaIt->second; 00322 } else { 00323 return NULL; 00324 } 00325 }
|
|
00308 { 00309 std::map<OSPF::LSAKeyType, OSPF::SummaryLSA*, OSPF::LSAKeyType_Less>::iterator lsaIt = summaryLSAsByID.find (lsaKey); 00310 if (lsaIt != summaryLSAsByID.end ()) { 00311 return lsaIt->second; 00312 } else { 00313 return NULL; 00314 } 00315 }
|
|
00191 { 00192 int interfaceNum = associatedInterfaces.size (); 00193 for (int i = 0; i < interfaceNum; i++) { 00194 if ((associatedInterfaces[i]->GetType () == OSPF::Interface::Virtual) && 00195 (associatedInterfaces[i]->GetNeighborByID (routerID) != NULL)) 00196 { 00197 return associatedInterfaces[i]; 00198 } 00199 } 00200 return NULL; 00201 }
|
|
00650 { 00651 bool floodedBackOut = false; 00652 long interfaceCount = associatedInterfaces.size (); 00653 00654 for (long i = 0; i < interfaceCount; i++) { 00655 if (associatedInterfaces[i]->FloodLSA (lsa, intf, neighbor)) { 00656 floodedBackOut = true; 00657 } 00658 } 00659 00660 return floodedBackOut; 00661 }
|
|
00042 { return areaAddressRanges[index]; }
|
|
00041 { return areaAddressRanges.size (); }
|
|
00039 { return areaID; }
|
|
00125 { 00126 int addressRangeNum = areaAddressRanges.size (); 00127 for (int i = 0; i < addressRangeNum; i++) { 00128 if ((areaAddressRanges[i].address & areaAddressRanges[i].mask) == (addressRange.address & areaAddressRanges[i].mask)) { 00129 if (advertise != NULL) { 00130 std::map<OSPF::IPv4AddressRange, bool, OSPF::IPv4AddressRange_Less>::const_iterator rangeIt = advertiseAddressRanges.find (areaAddressRanges[i]); 00131 if (rangeIt != advertiseAddressRanges.end ()) { 00132 *advertise = rangeIt->second; 00133 } else { 00134 *advertise = true; 00135 } 00136 } 00137 return areaAddressRanges[i]; 00138 } 00139 } 00140 if (advertise != NULL) { 00141 *advertise = false; 00142 } 00143 return NullIPv4AddressRange; 00144 }
|
|
00047 { return externalRoutingCapability; }
|
|
00160 { 00161 int interfaceNum = associatedInterfaces.size (); 00162 for (int i = 0; i < interfaceNum; i++) { 00163 if ((associatedInterfaces[i]->GetType () != OSPF::Interface::Virtual) && 00164 (associatedInterfaces[i]->GetAddressRange ().address == address)) 00165 { 00166 return associatedInterfaces[i]; 00167 } 00168 } 00169 return NULL; 00170 }
|
|
00147 { 00148 int interfaceNum = associatedInterfaces.size (); 00149 for (int i = 0; i < interfaceNum; i++) { 00150 if ((associatedInterfaces[i]->GetType () != OSPF::Interface::Virtual) && 00151 (associatedInterfaces[i]->GetIfIndex () == ifIndex)) 00152 { 00153 return associatedInterfaces[i]; 00154 } 00155 } 00156 return NULL; 00157 }
|
|
00063 { return networkLSAs[i]; }
|
|
00062 { return networkLSAs[i]; }
|
|
00061 { return networkLSAs.size (); }
|
|
00056 { return parentRouter; }
|
|
00055 { return parentRouter; }
|
|
00060 { return routerLSAs[i]; }
|
|
00059 { return routerLSAs[i]; }
|
|
00058 { return routerLSAs.size (); }
|
|
00052 { return spfTreeRoot; }
|
|
00051 { return spfTreeRoot; }
|
|
00049 { return stubDefaultCost; }
|
|
00066 { return summaryLSAs[i]; }
|
|
00065 { return summaryLSAs[i]; }
|
|
00064 { return summaryLSAs.size (); }
|
|
00045 { return transitCapability; }
|
|
Returns a link state ID for the input destination. If this router hasn't originated a Summary LSA for the input destination then the function returs the destination address as link state ID. If it has originated a Summary LSA for the input destination then the function checks which LSA would contain the longer netmask. If the two masks are equal then this means thet we're updating an LSA already in the database, so the function returns the destination address as link state ID. If the input destination netmask is longer then the one already in the database, then the returned link state ID is the input destination address ORed together with the inverse of the input destination mask. If the input destination netmask is shorter, then the Summary LSA already in the database has to be replaced by the current destination. In this case the lsaToReoriginate parameter is filled with a copy of the Summary LSA in the database with it's mask replaced by the destination mask and the cost replaced by the input destination cost; the returned link state ID is the input destination address ORed together with the inverse of the mask stored in the Summary LSA in the database. This means that if the lsaToReoriginate parameter is not NULL on return then another lookup in the database is needed with the same LSAKey as used here (input destination address and the router's own routerID) and the resulting Summary LSA's link state ID should be changed to the one returned by this function. 00978 { 00979 if (lsaToReoriginate != NULL) { 00980 delete lsaToReoriginate; 00981 lsaToReoriginate = NULL; 00982 } 00983 00984 OSPF::LSAKeyType lsaKey; 00985 00986 lsaKey.linkStateID = ULongFromIPv4Address (destination.address); 00987 lsaKey.advertisingRouter = parentRouter->GetRouterID (); 00988 00989 const OSPF::SummaryLSA* foundLSA = FindSummaryLSA (lsaKey); 00990 00991 if (foundLSA == NULL) { 00992 return lsaKey.linkStateID; 00993 } else { 00994 OSPF::IPv4Address existingMask = IPv4AddressFromULong (foundLSA->getNetworkMask ().getInt ()); 00995 00996 if (destination.mask == existingMask) { 00997 return lsaKey.linkStateID; 00998 } else { 00999 if (destination.mask >= existingMask) { 01000 return (lsaKey.linkStateID | (~(ULongFromIPv4Address (destination.mask)))); 01001 } else { 01002 OSPF::SummaryLSA* summaryLSA = new OSPF::SummaryLSA (*foundLSA); 01003 01004 long sequenceNumber = summaryLSA->getHeader ().getLsSequenceNumber (); 01005 01006 summaryLSA->getHeader ().setLsAge (0); 01007 summaryLSA->getHeader ().setLsSequenceNumber ((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1); 01008 summaryLSA->setNetworkMask (ULongFromIPv4Address (destination.mask)); 01009 summaryLSA->setRouteCost (destinationCost); 01010 summaryLSA->getHeader ().setLsChecksum (0); // TODO: calculate correct LS checksum 01011 01012 lsaToReoriginate = summaryLSA; 01013 01014 return (lsaKey.linkStateID | (~(ULongFromIPv4Address (existingMask)))); 01015 } 01016 } 01017 } 01018 }
|
|
00112 { 00113 int addressRangeNum = areaAddressRanges.size (); 00114 for (int i = 0; i < addressRangeNum; i++) { 00115 if ((areaAddressRanges[i].address == addressRange.address) && 00116 (areaAddressRanges[i].mask == addressRange.mask)) 00117 { 00118 return true; 00119 } 00120 } 00121 return false; 00122 }
|
|
02029 { 02030 unsigned int i; 02031 02032 OSPF::RouterLSA* fromRouterLSA = dynamic_cast<OSPF::RouterLSA*> (fromLSA); 02033 if (fromRouterLSA != NULL) { 02034 unsigned int linkCount = fromRouterLSA->getLinksArraySize (); 02035 OSPF::RouterLSA* toRouterLSA = dynamic_cast<OSPF::RouterLSA*> (toLSA); 02036 if (toRouterLSA != NULL) { 02037 for (i = 0; i < linkCount; i++) { 02038 Link& link = fromRouterLSA->getLinks (i); 02039 LinkType linkType = static_cast<LinkType> (link.getType ()); 02040 02041 if (((linkType == PointToPointLink) || 02042 (linkType == VirtualLink)) && 02043 (link.getLinkID ().getInt () == toRouterLSA->getHeader ().getLinkStateID ())) 02044 { 02045 return true; 02046 } 02047 } 02048 } else { 02049 OSPF::NetworkLSA* toNetworkLSA = dynamic_cast<OSPF::NetworkLSA*> (toLSA); 02050 if (toNetworkLSA != NULL) { 02051 for (i = 0; i < linkCount; i++) { 02052 Link& link = fromRouterLSA->getLinks (i); 02053 02054 if ((link.getType () == TransitLink) && 02055 (link.getLinkID ().getInt () == toNetworkLSA->getHeader ().getLinkStateID ())) 02056 { 02057 return true; 02058 } 02059 if ((link.getType () == StubLink) && 02060 ((link.getLinkID ().getInt () & link.getLinkData ()) == (toNetworkLSA->getHeader ().getLinkStateID () & toNetworkLSA->getNetworkMask ().getInt ()))) 02061 { 02062 return true; 02063 } 02064 } 02065 } 02066 } 02067 } else { 02068 OSPF::NetworkLSA* fromNetworkLSA = dynamic_cast<OSPF::NetworkLSA*> (fromLSA); 02069 if (fromNetworkLSA != NULL) { 02070 unsigned int routerCount = fromNetworkLSA->getAttachedRoutersArraySize (); 02071 OSPF::RouterLSA* toRouterLSA = dynamic_cast<OSPF::RouterLSA*> (toLSA); 02072 if (toRouterLSA != NULL) { 02073 for (i = 0; i < routerCount; i++) { 02074 if (fromNetworkLSA->getAttachedRouters (i).getInt () == toRouterLSA->getHeader ().getLinkStateID ()) { 02075 return true; 02076 } 02077 } 02078 } 02079 } 02080 } 02081 02082 return false; 02083 }
|
|
00173 { 00174 if ((areaID != OSPF::BackboneAreaID) || (withTransitArea == OSPF::BackboneAreaID)) { 00175 return false; 00176 } 00177 00178 int interfaceNum = associatedInterfaces.size (); 00179 for (int i = 0; i < interfaceNum; i++) { 00180 if ((associatedInterfaces[i]->GetType () == OSPF::Interface::Virtual) && 00181 (associatedInterfaces[i]->GetTransitAreaID () == withTransitArea)) 00182 { 00183 return true; 00184 } 00185 } 00186 return false; 00187 }
|
|
00048 { 00049 std::stringstream out; 00050 char areaString[16]; 00051 out << "areaID: " << AddressStringFromULong (areaString, 16, areaID); 00052 strcpy(buffer, out.str().c_str()); 00053 }
|
|
00224 { 00225 OSPF::LinkStateID linkStateID = lsa->getHeader ().getLinkStateID (); 00226 std::map<OSPF::LinkStateID, OSPF::NetworkLSA*>::iterator lsaIt = networkLSAsByID.find (linkStateID); 00227 if (lsaIt != networkLSAsByID.end ()) { 00228 OSPF::LSAKeyType lsaKey; 00229 00230 lsaKey.linkStateID = lsa->getHeader ().getLinkStateID (); 00231 lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ().getInt (); 00232 00233 RemoveFromAllRetransmissionLists (lsaKey); 00234 return lsaIt->second->Update (lsa); 00235 } else { 00236 OSPF::NetworkLSA* lsaCopy = new OSPF::NetworkLSA (*lsa); 00237 networkLSAsByID[linkStateID] = lsaCopy; 00238 networkLSAs.push_back (lsaCopy); 00239 return true; 00240 } 00241 }
|
|
00204 { 00205 OSPF::LinkStateID linkStateID = lsa->getHeader ().getLinkStateID (); 00206 std::map<OSPF::LinkStateID, OSPF::RouterLSA*>::iterator lsaIt = routerLSAsByID.find (linkStateID); 00207 if (lsaIt != routerLSAsByID.end ()) { 00208 OSPF::LSAKeyType lsaKey; 00209 00210 lsaKey.linkStateID = lsa->getHeader ().getLinkStateID (); 00211 lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ().getInt (); 00212 00213 RemoveFromAllRetransmissionLists (lsaKey); 00214 return lsaIt->second->Update (lsa); 00215 } else { 00216 OSPF::RouterLSA* lsaCopy = new OSPF::RouterLSA (*lsa); 00217 routerLSAsByID[linkStateID] = lsaCopy; 00218 routerLSAs.push_back (lsaCopy); 00219 return true; 00220 } 00221 }
|
|
00244 { 00245 OSPF::LSAKeyType lsaKey; 00246 00247 lsaKey.linkStateID = lsa->getHeader ().getLinkStateID (); 00248 lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ().getInt (); 00249 00250 std::map<OSPF::LSAKeyType, OSPF::SummaryLSA*, OSPF::LSAKeyType_Less>::iterator lsaIt = summaryLSAsByID.find (lsaKey); 00251 if (lsaIt != summaryLSAsByID.end ()) { 00252 OSPF::LSAKeyType lsaKey; 00253 00254 lsaKey.linkStateID = lsa->getHeader ().getLinkStateID (); 00255 lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ().getInt (); 00256 00257 RemoveFromAllRetransmissionLists (lsaKey); 00258 return lsaIt->second->Update (lsa); 00259 } else { 00260 OSPF::SummaryLSA* lsaCopy = new OSPF::SummaryLSA (*lsa); 00261 summaryLSAsByID[lsaKey] = lsaCopy; 00262 summaryLSAs.push_back (lsaCopy); 00263 return true; 00264 } 00265 }
|
|
00664 { 00665 long interfaceCount = associatedInterfaces.size (); 00666 for (long i = 0; i < interfaceCount; i++) { 00667 if (associatedInterfaces[i]->GetAddressRange ().address == address) { 00668 return true; 00669 } 00670 } 00671 return false; 00672 }
|
|
00639 { 00640 long interfaceCount = associatedInterfaces.size (); 00641 for (long i = 0; i < interfaceCount; i++) { 00642 if (associatedInterfaces[i]->IsOnAnyRetransmissionList (lsaKey)) { 00643 return true; 00644 } 00645 } 00646 return false; 00647 }
|
|
00916 { 00917 if (intf->AnyNeighborInStates (OSPF::Neighbor::FullState)) { 00918 OSPF::NetworkLSA* networkLSA = new OSPF::NetworkLSA; 00919 OSPFLSAHeader& lsaHeader = networkLSA->getHeader (); 00920 long neighborCount = intf->GetNeighborCount (); 00921 OSPFOptions lsOptions; 00922 00923 lsaHeader.setLsAge (0); 00924 memset (&lsOptions, 0, sizeof (OSPFOptions)); 00925 lsOptions.E_ExternalRoutingCapability = externalRoutingCapability; 00926 lsaHeader.setLsOptions (lsOptions); 00927 lsaHeader.setLsType (NetworkLSAType); 00928 lsaHeader.setLinkStateID (ULongFromIPv4Address (intf->GetAddressRange ().address)); 00929 lsaHeader.setAdvertisingRouter (parentRouter->GetRouterID ()); 00930 lsaHeader.setLsSequenceNumber (INITIAL_SEQUENCE_NUMBER); 00931 00932 networkLSA->setNetworkMask (ULongFromIPv4Address (intf->GetAddressRange ().mask)); 00933 00934 for (long j = 0; j < neighborCount; j++) { 00935 const OSPF::Neighbor* neighbor = intf->GetNeighbor (j); 00936 if (neighbor->GetState () == OSPF::Neighbor::FullState) { 00937 unsigned short netIndex = networkLSA->getAttachedRoutersArraySize (); 00938 networkLSA->setAttachedRoutersArraySize (netIndex + 1); 00939 networkLSA->setAttachedRouters (netIndex, neighbor->GetNeighborID ()); 00940 } 00941 } 00942 unsigned short netIndex = networkLSA->getAttachedRoutersArraySize (); 00943 networkLSA->setAttachedRoutersArraySize (netIndex + 1); 00944 networkLSA->setAttachedRouters (netIndex, parentRouter->GetRouterID ()); 00945 00946 lsaHeader.setLsChecksum (0); // TODO: calculate correct LS checksum 00947 00948 return networkLSA; 00949 } else { 00950 return NULL; 00951 } 00952 }
|
|
00675 { 00676 OSPF::RouterLSA* routerLSA = new OSPF::RouterLSA; 00677 OSPFLSAHeader& lsaHeader = routerLSA->getHeader (); 00678 long interfaceCount = associatedInterfaces.size (); 00679 OSPFOptions lsOptions; 00680 long i; 00681 00682 lsaHeader.setLsAge (0); 00683 memset (&lsOptions, 0, sizeof (OSPFOptions)); 00684 lsOptions.E_ExternalRoutingCapability = externalRoutingCapability; 00685 lsaHeader.setLsOptions (lsOptions); 00686 lsaHeader.setLsType (RouterLSAType); 00687 lsaHeader.setLinkStateID (parentRouter->GetRouterID ()); 00688 lsaHeader.setAdvertisingRouter (parentRouter->GetRouterID ()); 00689 lsaHeader.setLsSequenceNumber (INITIAL_SEQUENCE_NUMBER); 00690 00691 routerLSA->setB_AreaBorderRouter (parentRouter->GetAreaCount () > 1); 00692 routerLSA->setE_ASBoundaryRouter ((externalRoutingCapability && parentRouter->GetASBoundaryRouter ()) ? true : false); 00693 OSPF::Area* backbone = parentRouter->GetArea (OSPF::BackboneAreaID); 00694 routerLSA->setV_VirtualLinkEndpoint ((backbone == NULL) ? false : backbone->HasVirtualLink (areaID)); 00695 00696 routerLSA->setNumberOfLinks (0); 00697 routerLSA->setLinksArraySize (0); 00698 for (i = 0; i < interfaceCount; i++) { 00699 OSPF::Interface* intf = associatedInterfaces[i]; 00700 00701 if (intf->GetState () == OSPF::Interface::DownState) { 00702 continue; 00703 } 00704 if ((intf->GetState () == OSPF::Interface::LoopbackState) && 00705 ((intf->GetType () != OSPF::Interface::PointToPoint) || 00706 (intf->GetAddressRange ().address != OSPF::NullIPv4Address))) 00707 { 00708 Link stubLink; 00709 stubLink.setType (StubLink); 00710 stubLink.setLinkID (ULongFromIPv4Address (intf->GetAddressRange ().address)); 00711 stubLink.setLinkData (0xFFFFFFFF); 00712 stubLink.setLinkCost (0); 00713 stubLink.setNumberOfTOS (0); 00714 stubLink.setTosDataArraySize (0); 00715 00716 unsigned short linkIndex = routerLSA->getLinksArraySize (); 00717 routerLSA->setLinksArraySize (linkIndex + 1); 00718 routerLSA->setNumberOfLinks (linkIndex + 1); 00719 routerLSA->setLinks (linkIndex, stubLink); 00720 } 00721 if (intf->GetState () > OSPF::Interface::LoopbackState) { 00722 switch (intf->GetType ()) { 00723 case OSPF::Interface::PointToPoint: 00724 { 00725 OSPF::Neighbor* neighbor = (intf->GetNeighborCount () > 0) ? intf->GetNeighbor (0) : NULL; 00726 if (neighbor != NULL) { 00727 if (neighbor->GetState () == OSPF::Neighbor::FullState) { 00728 Link link; 00729 link.setType (PointToPointLink); 00730 link.setLinkID (neighbor->GetNeighborID ()); 00731 if (intf->GetAddressRange ().address != OSPF::NullIPv4Address) { 00732 link.setLinkData (ULongFromIPv4Address (intf->GetAddressRange ().address)); 00733 } else { 00734 link.setLinkData (intf->GetIfIndex ()); 00735 } 00736 link.setLinkCost (intf->GetOutputCost ()); 00737 link.setNumberOfTOS (0); 00738 link.setTosDataArraySize (0); 00739 00740 unsigned short linkIndex = routerLSA->getLinksArraySize (); 00741 routerLSA->setLinksArraySize (linkIndex + 1); 00742 routerLSA->setNumberOfLinks (linkIndex + 1); 00743 routerLSA->setLinks (linkIndex, link); 00744 } 00745 if (intf->GetState () == OSPF::Interface::PointToPointState) { 00746 if (neighbor->GetAddress () != OSPF::NullIPv4Address) { 00747 Link stubLink; 00748 stubLink.setType (StubLink); 00749 stubLink.setLinkID (ULongFromIPv4Address (neighbor->GetAddress ())); 00750 stubLink.setLinkData (0xFFFFFFFF); 00751 stubLink.setLinkCost (intf->GetOutputCost ()); 00752 stubLink.setNumberOfTOS (0); 00753 stubLink.setTosDataArraySize (0); 00754 00755 unsigned short linkIndex = routerLSA->getLinksArraySize (); 00756 routerLSA->setLinksArraySize (linkIndex + 1); 00757 routerLSA->setNumberOfLinks (linkIndex + 1); 00758 routerLSA->setLinks (linkIndex, stubLink); 00759 } else { 00760 if (ULongFromIPv4Address (intf->GetAddressRange ().mask) != 0xFFFFFFFF) { 00761 Link stubLink; 00762 stubLink.setType (StubLink); 00763 stubLink.setLinkID (ULongFromIPv4Address (intf->GetAddressRange ().address & 00764 intf->GetAddressRange ().mask)); 00765 stubLink.setLinkData (ULongFromIPv4Address (intf->GetAddressRange ().mask)); 00766 stubLink.setLinkCost (intf->GetOutputCost ()); 00767 stubLink.setNumberOfTOS (0); 00768 stubLink.setTosDataArraySize (0); 00769 00770 unsigned short linkIndex = routerLSA->getLinksArraySize (); 00771 routerLSA->setLinksArraySize (linkIndex + 1); 00772 routerLSA->setNumberOfLinks (linkIndex + 1); 00773 routerLSA->setLinks (linkIndex, stubLink); 00774 } 00775 } 00776 } 00777 } 00778 } 00779 break; 00780 case OSPF::Interface::Broadcast: 00781 case OSPF::Interface::NBMA: 00782 { 00783 if (intf->GetState () == OSPF::Interface::WaitingState) { 00784 Link stubLink; 00785 stubLink.setType (StubLink); 00786 stubLink.setLinkID (ULongFromIPv4Address (intf->GetAddressRange ().address & 00787 intf->GetAddressRange ().mask)); 00788 stubLink.setLinkData (ULongFromIPv4Address (intf->GetAddressRange ().mask)); 00789 stubLink.setLinkCost (intf->GetOutputCost ()); 00790 stubLink.setNumberOfTOS (0); 00791 stubLink.setTosDataArraySize (0); 00792 00793 unsigned short linkIndex = routerLSA->getLinksArraySize (); 00794 routerLSA->setLinksArraySize (linkIndex + 1); 00795 routerLSA->setNumberOfLinks (linkIndex + 1); 00796 routerLSA->setLinks (linkIndex, stubLink); 00797 } else { 00798 OSPF::Neighbor* dRouter = intf->GetNeighborByAddress (intf->GetDesignatedRouter ().ipInterfaceAddress); 00799 if (((dRouter != NULL) && (dRouter->GetState () == OSPF::Neighbor::FullState)) || 00800 ((intf->GetDesignatedRouter ().routerID == parentRouter->GetRouterID ()) && 00801 (intf->AnyNeighborInStates (OSPF::Neighbor::FullState)))) 00802 { 00803 Link link; 00804 link.setType (TransitLink); 00805 link.setLinkID (ULongFromIPv4Address (intf->GetDesignatedRouter ().ipInterfaceAddress)); 00806 link.setLinkData (ULongFromIPv4Address (intf->GetAddressRange ().address)); 00807 link.setLinkCost (intf->GetOutputCost ()); 00808 link.setNumberOfTOS (0); 00809 link.setTosDataArraySize (0); 00810 00811 unsigned short linkIndex = routerLSA->getLinksArraySize (); 00812 routerLSA->setLinksArraySize (linkIndex + 1); 00813 routerLSA->setNumberOfLinks (linkIndex + 1); 00814 routerLSA->setLinks (linkIndex, link); 00815 } else { 00816 Link stubLink; 00817 stubLink.setType (StubLink); 00818 stubLink.setLinkID (ULongFromIPv4Address (intf->GetAddressRange ().address & 00819 intf->GetAddressRange ().mask)); 00820 stubLink.setLinkData (ULongFromIPv4Address (intf->GetAddressRange ().mask)); 00821 stubLink.setLinkCost (intf->GetOutputCost ()); 00822 stubLink.setNumberOfTOS (0); 00823 stubLink.setTosDataArraySize (0); 00824 00825 unsigned short linkIndex = routerLSA->getLinksArraySize (); 00826 routerLSA->setLinksArraySize (linkIndex + 1); 00827 routerLSA->setNumberOfLinks (linkIndex + 1); 00828 routerLSA->setLinks (linkIndex, stubLink); 00829 } 00830 } 00831 } 00832 break; 00833 case OSPF::Interface::Virtual: 00834 { 00835 OSPF::Neighbor* neighbor = (intf->GetNeighborCount () > 0) ? intf->GetNeighbor (0) : NULL; 00836 if ((neighbor != NULL) && (neighbor->GetState () == OSPF::Neighbor::FullState)) { 00837 Link link; 00838 link.setType (VirtualLink); 00839 link.setLinkID (neighbor->GetNeighborID ()); 00840 link.setLinkData (ULongFromIPv4Address (intf->GetAddressRange ().address)); 00841 link.setLinkCost (intf->GetOutputCost ()); 00842 link.setNumberOfTOS (0); 00843 link.setTosDataArraySize (0); 00844 00845 unsigned short linkIndex = routerLSA->getLinksArraySize (); 00846 routerLSA->setLinksArraySize (linkIndex + 1); 00847 routerLSA->setNumberOfLinks (linkIndex + 1); 00848 routerLSA->setLinks (linkIndex, link); 00849 } 00850 } 00851 break; 00852 case OSPF::Interface::PointToMultiPoint: 00853 { 00854 Link stubLink; 00855 stubLink.setType (StubLink); 00856 stubLink.setLinkID (ULongFromIPv4Address (intf->GetAddressRange ().address)); 00857 stubLink.setLinkData (0xFFFFFFFF); 00858 stubLink.setLinkCost (0); 00859 stubLink.setNumberOfTOS (0); 00860 stubLink.setTosDataArraySize (0); 00861 00862 unsigned short linkIndex = routerLSA->getLinksArraySize (); 00863 routerLSA->setLinksArraySize (linkIndex + 1); 00864 routerLSA->setNumberOfLinks (linkIndex + 1); 00865 routerLSA->setLinks (linkIndex, stubLink); 00866 00867 long neighborCount = intf->GetNeighborCount (); 00868 for (long i = 0; i < neighborCount; i++) { 00869 OSPF::Neighbor* neighbor = intf->GetNeighbor (i); 00870 if (neighbor->GetState () == OSPF::Neighbor::FullState) { 00871 Link link; 00872 link.setType (PointToPointLink); 00873 link.setLinkID (neighbor->GetNeighborID ()); 00874 link.setLinkData (ULongFromIPv4Address (intf->GetAddressRange ().address)); 00875 link.setLinkCost (intf->GetOutputCost ()); 00876 link.setNumberOfTOS (0); 00877 link.setTosDataArraySize (0); 00878 00879 unsigned short linkIndex = routerLSA->getLinksArraySize (); 00880 routerLSA->setLinksArraySize (linkIndex + 1); 00881 routerLSA->setNumberOfLinks (linkIndex + 1); 00882 routerLSA->setLinks (linkIndex, stubLink); 00883 } 00884 } 00885 } 00886 break; 00887 default: break; 00888 } 00889 } 00890 } 00891 00892 long hostRouteCount = hostRoutes.size (); 00893 for (i = 0; i < hostRouteCount; i++) { 00894 Link stubLink; 00895 stubLink.setType (StubLink); 00896 stubLink.setLinkID (ULongFromIPv4Address (hostRoutes[i].address)); 00897 stubLink.setLinkData (0xFFFFFFFF); 00898 stubLink.setLinkCost (hostRoutes[i].linkCost); 00899 stubLink.setNumberOfTOS (0); 00900 stubLink.setTosDataArraySize (0); 00901 00902 unsigned short linkIndex = routerLSA->getLinksArraySize (); 00903 routerLSA->setLinksArraySize (linkIndex + 1); 00904 routerLSA->setNumberOfLinks (linkIndex + 1); 00905 routerLSA->setLinks (linkIndex, stubLink); 00906 } 00907 00908 lsaHeader.setLsChecksum (0); // TODO: calculate correct LS checksum 00909 00910 routerLSA->SetSource (OSPF::LSATrackingInfo::Originated); 00911 00912 return routerLSA; 00913 }
|
|
01279 { 01280 const std::map<OSPF::LSAKeyType, bool, OSPF::LSAKeyType_Less> emptyMap; 01281 OSPF::SummaryLSA* dontReoriginate = NULL; 01282 01283 const OSPFLSAHeader& lsaHeader = summaryLSA->getHeader (); 01284 unsigned long entryCount = parentRouter->GetRoutingTableEntryCount (); 01285 01286 for (unsigned long i = 0; i < entryCount; i++) { 01287 const OSPF::RoutingTableEntry* entry = parentRouter->GetRoutingTableEntry (i); 01288 01289 if ((lsaHeader.getLsType () == SummaryLSA_ASBoundaryRoutersType) && 01290 ((((entry->GetDestinationType () & OSPF::RoutingTableEntry::AreaBorderRouterDestination) != 0) || 01291 ((entry->GetDestinationType () & OSPF::RoutingTableEntry::ASBoundaryRouterDestination) != 0)) && 01292 ((entry->GetDestinationID ().getInt () == lsaHeader.getLinkStateID ()) && 01293 (entry->GetAddressMask () == summaryLSA->getNetworkMask ())))) 01294 { 01295 OSPF::SummaryLSA* returnLSA = OriginateSummaryLSA (entry, emptyMap, dontReoriginate); 01296 if (dontReoriginate != NULL) { 01297 delete dontReoriginate; 01298 } 01299 return returnLSA; 01300 } 01301 01302 unsigned long lsaMask = summaryLSA->getNetworkMask ().getInt (); 01303 01304 if ((lsaHeader.getLsType () == SummaryLSA_NetworksType) && 01305 (entry->GetDestinationType () == OSPF::RoutingTableEntry::NetworkDestination) && 01306 (entry->GetAddressMask ().getInt () == lsaMask) && 01307 (entry->GetDestinationID ().getInt () & lsaMask == lsaHeader.getLinkStateID () & lsaMask)) 01308 { 01309 OSPF::SummaryLSA* returnLSA = OriginateSummaryLSA (entry, emptyMap, dontReoriginate); 01310 if (dontReoriginate != NULL) { 01311 delete dontReoriginate; 01312 } 01313 return returnLSA; 01314 } 01315 } 01316 01317 return NULL; 01318 }
|
|
01023 { 01024 if (((entry->GetDestinationType () & OSPF::RoutingTableEntry::AreaBorderRouterDestination) != 0) || 01025 (entry->GetPathType () == OSPF::RoutingTableEntry::Type1External) || 01026 (entry->GetPathType () == OSPF::RoutingTableEntry::Type2External) || 01027 (entry->GetArea () == areaID)) 01028 { 01029 return NULL; 01030 } 01031 01032 bool allNextHopsInThisArea = true; 01033 unsigned int nextHopCount = entry->GetNextHopCount (); 01034 01035 for (unsigned int i = 0; i < nextHopCount; i++) { 01036 OSPF::Interface* nextHopInterface = parentRouter->GetNonVirtualInterface (entry->GetNextHop (i).ifIndex); 01037 if ((nextHopInterface != NULL) && (nextHopInterface->GetAreaID () != areaID)) { 01038 allNextHopsInThisArea = false; 01039 break; 01040 } 01041 } 01042 if ((allNextHopsInThisArea) || (entry->GetCost () >= LS_INFINITY)){ 01043 return NULL; 01044 } 01045 01046 if ((entry->GetDestinationType () & OSPF::RoutingTableEntry::ASBoundaryRouterDestination) != 0) { 01047 OSPF::RoutingTableEntry* preferredEntry = parentRouter->GetPreferredEntry (*(entry->GetLinkStateOrigin ()), false); 01048 if ((preferredEntry != NULL) && (*preferredEntry == *entry) && (externalRoutingCapability)) { 01049 OSPF::SummaryLSA* summaryLSA = new OSPF::SummaryLSA; 01050 OSPFLSAHeader& lsaHeader = summaryLSA->getHeader (); 01051 OSPFOptions lsOptions; 01052 01053 lsaHeader.setLsAge (0); 01054 memset (&lsOptions, 0, sizeof (OSPFOptions)); 01055 lsOptions.E_ExternalRoutingCapability = externalRoutingCapability; 01056 lsaHeader.setLsOptions (lsOptions); 01057 lsaHeader.setLsType (SummaryLSA_ASBoundaryRoutersType); 01058 lsaHeader.setLinkStateID (entry->GetDestinationID ().getInt ()); 01059 lsaHeader.setAdvertisingRouter (parentRouter->GetRouterID ()); 01060 lsaHeader.setLsSequenceNumber (INITIAL_SEQUENCE_NUMBER); 01061 01062 summaryLSA->setNetworkMask (entry->GetAddressMask ()); 01063 summaryLSA->setRouteCost (entry->GetCost ()); 01064 summaryLSA->setTosDataArraySize (0); 01065 01066 lsaHeader.setLsChecksum (0); // TODO: calculate correct LS checksum 01067 01068 summaryLSA->SetSource (OSPF::LSATrackingInfo::Originated); 01069 01070 return summaryLSA; 01071 } 01072 } else { // entry->GetDestinationType () == OSPF::RoutingTableEntry::NetworkDestination 01073 if (entry->GetPathType () == OSPF::RoutingTableEntry::InterArea) { 01074 OSPF::IPv4AddressRange destinationRange; 01075 01076 destinationRange.address = IPv4AddressFromULong (entry->GetDestinationID ().getInt ()); 01077 destinationRange.mask = IPv4AddressFromULong (entry->GetAddressMask ().getInt ()); 01078 01079 OSPF::LinkStateID newLinkStateID = GetUniqueLinkStateID (destinationRange, entry->GetCost (), lsaToReoriginate); 01080 01081 if (lsaToReoriginate != NULL) { 01082 OSPF::LSAKeyType lsaKey; 01083 01084 lsaKey.linkStateID = entry->GetDestinationID ().getInt (); 01085 lsaKey.advertisingRouter = parentRouter->GetRouterID (); 01086 01087 std::map<OSPF::LSAKeyType, OSPF::SummaryLSA*, OSPF::LSAKeyType_Less>::iterator lsaIt = summaryLSAsByID.find (lsaKey); 01088 if (lsaIt == summaryLSAsByID.end ()) { 01089 delete (lsaToReoriginate); 01090 lsaToReoriginate = NULL; 01091 return NULL; 01092 } else { 01093 OSPF::SummaryLSA* summaryLSA = new OSPF::SummaryLSA (*(lsaIt->second)); 01094 OSPFLSAHeader& lsaHeader = summaryLSA->getHeader (); 01095 01096 lsaHeader.setLsAge (0); 01097 lsaHeader.setLsSequenceNumber (INITIAL_SEQUENCE_NUMBER); 01098 lsaHeader.setLinkStateID (newLinkStateID); 01099 lsaHeader.setLsChecksum (0); // TODO: calculate correct LS checksum 01100 01101 return summaryLSA; 01102 } 01103 } else { 01104 OSPF::SummaryLSA* summaryLSA = new OSPF::SummaryLSA; 01105 OSPFLSAHeader& lsaHeader = summaryLSA->getHeader (); 01106 OSPFOptions lsOptions; 01107 01108 lsaHeader.setLsAge (0); 01109 memset (&lsOptions, 0, sizeof (OSPFOptions)); 01110 lsOptions.E_ExternalRoutingCapability = externalRoutingCapability; 01111 lsaHeader.setLsOptions (lsOptions); 01112 lsaHeader.setLsType (SummaryLSA_NetworksType); 01113 lsaHeader.setLinkStateID (newLinkStateID); 01114 lsaHeader.setAdvertisingRouter (parentRouter->GetRouterID ()); 01115 lsaHeader.setLsSequenceNumber (INITIAL_SEQUENCE_NUMBER); 01116 01117 summaryLSA->setNetworkMask (entry->GetAddressMask ()); 01118 summaryLSA->setRouteCost (entry->GetCost ()); 01119 summaryLSA->setTosDataArraySize (0); 01120 01121 lsaHeader.setLsChecksum (0); // TODO: calculate correct LS checksum 01122 01123 summaryLSA->SetSource (OSPF::LSATrackingInfo::Originated); 01124 01125 return summaryLSA; 01126 } 01127 } else { // entry->GetPathType () == OSPF::RoutingTableEntry::IntraArea 01128 OSPF::IPv4AddressRange destinationAddressRange; 01129 01130 destinationAddressRange.address = IPv4AddressFromULong (entry->GetDestinationID ().getInt ()); 01131 destinationAddressRange.mask = IPv4AddressFromULong (entry->GetAddressMask ().getInt ()); 01132 01133 bool doAdvertise = false; 01134 OSPF::IPv4AddressRange containingAddressRange = parentRouter->GetContainingAddressRange (destinationAddressRange, &doAdvertise); 01135 if (((entry->GetArea () == OSPF::BackboneAreaID) && // the backbone's configured ranges should be ignored 01136 (transitCapability)) || // when originating Summary LSAs into transit areas 01137 (containingAddressRange == OSPF::NullIPv4AddressRange)) 01138 { 01139 OSPF::LinkStateID newLinkStateID = GetUniqueLinkStateID (destinationAddressRange, entry->GetCost (), lsaToReoriginate); 01140 01141 if (lsaToReoriginate != NULL) { 01142 OSPF::LSAKeyType lsaKey; 01143 01144 lsaKey.linkStateID = entry->GetDestinationID ().getInt (); 01145 lsaKey.advertisingRouter = parentRouter->GetRouterID (); 01146 01147 std::map<OSPF::LSAKeyType, OSPF::SummaryLSA*, OSPF::LSAKeyType_Less>::iterator lsaIt = summaryLSAsByID.find (lsaKey); 01148 if (lsaIt == summaryLSAsByID.end ()) { 01149 delete (lsaToReoriginate); 01150 lsaToReoriginate = NULL; 01151 return NULL; 01152 } else { 01153 OSPF::SummaryLSA* summaryLSA = new OSPF::SummaryLSA (*(lsaIt->second)); 01154 OSPFLSAHeader& lsaHeader = summaryLSA->getHeader (); 01155 01156 lsaHeader.setLsAge (0); 01157 lsaHeader.setLsSequenceNumber (INITIAL_SEQUENCE_NUMBER); 01158 lsaHeader.setLinkStateID (newLinkStateID); 01159 lsaHeader.setLsChecksum (0); // TODO: calculate correct LS checksum 01160 01161 return summaryLSA; 01162 } 01163 } else { 01164 OSPF::SummaryLSA* summaryLSA = new OSPF::SummaryLSA; 01165 OSPFLSAHeader& lsaHeader = summaryLSA->getHeader (); 01166 OSPFOptions lsOptions; 01167 01168 lsaHeader.setLsAge (0); 01169 memset (&lsOptions, 0, sizeof (OSPFOptions)); 01170 lsOptions.E_ExternalRoutingCapability = externalRoutingCapability; 01171 lsaHeader.setLsOptions (lsOptions); 01172 lsaHeader.setLsType (SummaryLSA_NetworksType); 01173 lsaHeader.setLinkStateID (newLinkStateID); 01174 lsaHeader.setAdvertisingRouter (parentRouter->GetRouterID ()); 01175 lsaHeader.setLsSequenceNumber (INITIAL_SEQUENCE_NUMBER); 01176 01177 summaryLSA->setNetworkMask (entry->GetAddressMask ()); 01178 summaryLSA->setRouteCost (entry->GetCost ()); 01179 summaryLSA->setTosDataArraySize (0); 01180 01181 lsaHeader.setLsChecksum (0); // TODO: calculate correct LS checksum 01182 01183 summaryLSA->SetSource (OSPF::LSATrackingInfo::Originated); 01184 01185 return summaryLSA; 01186 } 01187 } else { 01188 if (doAdvertise) { 01189 Metric maxRangeCost = 0; 01190 unsigned long entryCount = parentRouter->GetRoutingTableEntryCount (); 01191 01192 for (unsigned long i = 0; i < entryCount; i++) { 01193 const OSPF::RoutingTableEntry* routingEntry = parentRouter->GetRoutingTableEntry (i); 01194 01195 if ((routingEntry->GetDestinationType () == OSPF::RoutingTableEntry::NetworkDestination) && 01196 (routingEntry->GetPathType () == OSPF::RoutingTableEntry::IntraArea) && 01197 ((routingEntry->GetDestinationID ().getInt () & routingEntry->GetAddressMask ().getInt () & ULongFromIPv4Address (containingAddressRange.mask)) == 01198 ULongFromIPv4Address (containingAddressRange.address & containingAddressRange.mask)) && 01199 (routingEntry->GetCost () > maxRangeCost)) 01200 { 01201 maxRangeCost = routingEntry->GetCost (); 01202 } 01203 } 01204 01205 OSPF::LinkStateID newLinkStateID = GetUniqueLinkStateID (containingAddressRange, maxRangeCost, lsaToReoriginate); 01206 OSPF::LSAKeyType lsaKey; 01207 01208 if (lsaToReoriginate != NULL) { 01209 lsaKey.linkStateID = lsaToReoriginate->getHeader ().getLinkStateID (); 01210 lsaKey.advertisingRouter = parentRouter->GetRouterID (); 01211 01212 std::map<OSPF::LSAKeyType, bool, OSPF::LSAKeyType_Less>::const_iterator originatedIt = originatedLSAs.find (lsaKey); 01213 if (originatedIt != originatedLSAs.end ()) { 01214 delete (lsaToReoriginate); 01215 lsaToReoriginate = NULL; 01216 return NULL; 01217 } 01218 01219 lsaKey.linkStateID = entry->GetDestinationID ().getInt (); 01220 lsaKey.advertisingRouter = parentRouter->GetRouterID (); 01221 01222 std::map<OSPF::LSAKeyType, OSPF::SummaryLSA*, OSPF::LSAKeyType_Less>::iterator lsaIt = summaryLSAsByID.find (lsaKey); 01223 if (lsaIt == summaryLSAsByID.end ()) { 01224 delete (lsaToReoriginate); 01225 lsaToReoriginate = NULL; 01226 return NULL; 01227 } 01228 01229 OSPF::SummaryLSA* summaryLSA = new OSPF::SummaryLSA (*(lsaIt->second)); 01230 OSPFLSAHeader& lsaHeader = summaryLSA->getHeader (); 01231 01232 lsaHeader.setLsAge (0); 01233 lsaHeader.setLsSequenceNumber (INITIAL_SEQUENCE_NUMBER); 01234 lsaHeader.setLinkStateID (newLinkStateID); 01235 lsaHeader.setLsChecksum (0); // TODO: calculate correct LS checksum 01236 01237 return summaryLSA; 01238 } else { 01239 lsaKey.linkStateID = newLinkStateID; 01240 lsaKey.advertisingRouter = parentRouter->GetRouterID (); 01241 01242 std::map<OSPF::LSAKeyType, bool, OSPF::LSAKeyType_Less>::const_iterator originatedIt = originatedLSAs.find (lsaKey); 01243 if (originatedIt != originatedLSAs.end ()) { 01244 return NULL; 01245 } 01246 01247 OSPF::SummaryLSA* summaryLSA = new OSPF::SummaryLSA; 01248 OSPFLSAHeader& lsaHeader = summaryLSA->getHeader (); 01249 OSPFOptions lsOptions; 01250 01251 lsaHeader.setLsAge (0); 01252 memset (&lsOptions, 0, sizeof (OSPFOptions)); 01253 lsOptions.E_ExternalRoutingCapability = externalRoutingCapability; 01254 lsaHeader.setLsOptions (lsOptions); 01255 lsaHeader.setLsType (SummaryLSA_NetworksType); 01256 lsaHeader.setLinkStateID (newLinkStateID); 01257 lsaHeader.setAdvertisingRouter (parentRouter->GetRouterID ()); 01258 lsaHeader.setLsSequenceNumber (INITIAL_SEQUENCE_NUMBER); 01259 01260 summaryLSA->setNetworkMask (entry->GetAddressMask ()); 01261 summaryLSA->setRouteCost (entry->GetCost ()); 01262 summaryLSA->setTosDataArraySize (0); 01263 01264 lsaHeader.setLsChecksum (0); // TODO: calculate correct LS checksum 01265 01266 summaryLSA->SetSource (OSPF::LSATrackingInfo::Originated); 01267 01268 return summaryLSA; 01269 } 01270 } 01271 } 01272 } 01273 } 01274 01275 return NULL; 01276 }
|
|
02322 { 02323 unsigned long i = 0; 02324 unsigned long j = 0; 02325 unsigned long lsaCount = summaryLSAs.size (); 02326 02327 for (i = 0; i < lsaCount; i++) { 02328 OSPF::SummaryLSA* currentLSA = summaryLSAs[i]; 02329 OSPFLSAHeader& currentHeader = currentLSA->getHeader (); 02330 02331 unsigned long routeCost = currentLSA->getRouteCost (); 02332 unsigned short lsAge = currentHeader.getLsAge (); 02333 RouterID originatingRouter = currentHeader.getAdvertisingRouter ().getInt (); 02334 bool selfOriginated = (originatingRouter == parentRouter->GetRouterID ()); 02335 02336 if ((routeCost == LS_INFINITY) || (lsAge == MAX_AGE) || (selfOriginated)) { // (1) and (2) 02337 continue; 02338 } 02339 02340 unsigned long routeCount = newRoutingTable.size (); 02341 char lsType = currentHeader.getLsType (); 02342 OSPF::RoutingTableEntry* destinationEntry = NULL; 02343 OSPF::IPv4AddressRange destination; 02344 02345 destination.address = IPv4AddressFromULong (currentHeader.getLinkStateID ()); 02346 destination.mask = IPv4AddressFromULong (currentLSA->getNetworkMask ().getInt ()); 02347 02348 for (j = 0; j < routeCount; j++) { // (3) 02349 OSPF::RoutingTableEntry* routingEntry = newRoutingTable[j]; 02350 bool foundMatching = false; 02351 02352 if (lsType == SummaryLSA_NetworksType) { 02353 if ((routingEntry->GetDestinationType () == OSPF::RoutingTableEntry::NetworkDestination) && 02354 (ULongFromIPv4Address (destination.address & destination.mask) == routingEntry->GetDestinationID ().getInt ())) 02355 { 02356 foundMatching = true; 02357 } 02358 } else { 02359 if ((((routingEntry->GetDestinationType () & OSPF::RoutingTableEntry::AreaBorderRouterDestination) != 0) || 02360 ((routingEntry->GetDestinationType () & OSPF::RoutingTableEntry::ASBoundaryRouterDestination) != 0)) && 02361 (ULongFromIPv4Address (destination.address) == routingEntry->GetDestinationID ().getInt ())) 02362 { 02363 foundMatching = true; 02364 } 02365 } 02366 02367 if (foundMatching) { 02368 OSPF::RoutingTableEntry::RoutingPathType pathType = routingEntry->GetPathType (); 02369 02370 if ((pathType == OSPF::RoutingTableEntry::Type1External) || 02371 (pathType == OSPF::RoutingTableEntry::Type2External) || 02372 (routingEntry->GetArea () != OSPF::BackboneAreaID)) 02373 { 02374 break; 02375 } else { 02376 destinationEntry = routingEntry; 02377 break; 02378 } 02379 } 02380 } 02381 if (destinationEntry == NULL) { 02382 continue; 02383 } 02384 02385 OSPF::RoutingTableEntry* borderRouterEntry = NULL; 02386 unsigned short currentCost = routeCost; 02387 02388 for (j = 0; j < routeCount; j++) { // (4) BR == borderRouterEntry 02389 OSPF::RoutingTableEntry* routingEntry = newRoutingTable[j]; 02390 02391 if ((routingEntry->GetArea () == areaID) && 02392 (((routingEntry->GetDestinationType () & OSPF::RoutingTableEntry::AreaBorderRouterDestination) != 0) || 02393 ((routingEntry->GetDestinationType () & OSPF::RoutingTableEntry::ASBoundaryRouterDestination) != 0)) && 02394 (routingEntry->GetDestinationID ().getInt () == originatingRouter)) 02395 { 02396 borderRouterEntry = routingEntry; 02397 currentCost += borderRouterEntry->GetCost (); 02398 break; 02399 } 02400 } 02401 if (borderRouterEntry == NULL) { 02402 continue; 02403 } else { // (5) 02404 if (currentCost <= destinationEntry->GetCost ()) { 02405 if (currentCost < destinationEntry->GetCost ()) { 02406 destinationEntry->ClearNextHops (); 02407 } 02408 02409 unsigned long nextHopCount = borderRouterEntry->GetNextHopCount (); 02410 02411 for (j = 0; j < nextHopCount; j++) { 02412 destinationEntry->AddNextHop (borderRouterEntry->GetNextHop (j)); 02413 } 02414 } 02415 } 02416 } 02417 }
|
|
00631 { 00632 long interfaceCount = associatedInterfaces.size (); 00633 for (long i = 0; i < interfaceCount; i++) { 00634 associatedInterfaces[i]->RemoveFromAllRetransmissionLists (lsaKey); 00635 } 00636 }
|
|
00038 { areaID = areaId; }
|
|
00046 { externalRoutingCapability = flooded; }
|
|
00054 { parentRouter = router; }
|
|
00050 { spfTreeRoot = root; }
|
|
00048 { stubDefaultCost = cost; }
|
|
00044 { transitCapability = transit; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|