#include <OSPFArea.h>
OSPF::Area::Area | ( | OSPF::AreaID | id = BackboneAreaID |
) |
00022 : 00023 areaID(id), 00024 transitCapability(false), 00025 externalRoutingCapability(true), 00026 stubDefaultCost(1), 00027 spfTreeRoot(NULL), 00028 parentRouter(NULL) 00029 { 00030 }
OSPF::Area::~Area | ( | void | ) | [virtual] |
00033 { 00034 int interfaceNum = associatedInterfaces.size(); 00035 for (int i = 0; i < interfaceNum; i++) { 00036 delete(associatedInterfaces[i]); 00037 } 00038 long lsaCount = routerLSAs.size(); 00039 for (long j = 0; j < lsaCount; j++) { 00040 delete routerLSAs[j]; 00041 } 00042 routerLSAs.clear(); 00043 lsaCount = networkLSAs.size(); 00044 for (long k = 0; k < lsaCount; k++) { 00045 delete networkLSAs[k]; 00046 } 00047 networkLSAs.clear(); 00048 lsaCount = summaryLSAs.size(); 00049 for (long m = 0; m < lsaCount; m++) { 00050 delete summaryLSAs[m]; 00051 } 00052 summaryLSAs.clear(); 00053 }
AreaID OSPF::Area::GetAreaID | ( | void | ) | const [inline] |
Referenced by OSPF::LinkStateUpdateHandler::AcknowledgeLSA(), OSPF::Router::AddArea(), OSPF::DatabaseDescriptionHandler::ProcessDDPacket(), OSPF::LinkStateRequestHandler::ProcessPacket(), OSPF::Neighbor::RetransmitUpdatePacket(), OSPF::Neighbor::SendDatabaseDescriptionPacket(), OSPF::Interface::SendHelloPacket(), OSPF::Neighbor::SendLinkStateRequestPacket(), and OSPF::Interface::SendLSAcknowledgement().
00056 { return areaID; }
void OSPF::Area::AddAddressRange | ( | IPv4AddressRange | addressRange, | |
bool | advertise | |||
) | [inline] |
Referenced by OSPFRouting::LoadAreaFromXML().
00057 { areaAddressRanges.push_back(addressRange); advertiseAddressRanges[addressRange] = advertise; }
unsigned int OSPF::Area::GetAddressRangeCount | ( | void | ) | const [inline] |
IPv4AddressRange OSPF::Area::GetAddressRange | ( | unsigned int | index | ) | const [inline] |
Referenced by CalculateNextHops(), detailedInfo(), GetInterface(), and IsLocalAddress().
00059 { return areaAddressRanges[index]; }
void OSPF::Area::AddHostRoute | ( | HostRouteParameters & | hostRouteParameters | ) | [inline] |
void OSPF::Area::SetTransitCapability | ( | bool | transit | ) | [inline] |
bool OSPF::Area::GetTransitCapability | ( | void | ) | const [inline] |
void OSPF::Area::SetExternalRoutingCapability | ( | bool | flooded | ) | [inline] |
bool OSPF::Area::GetExternalRoutingCapability | ( | void | ) | const [inline] |
Referenced by OSPF::Neighbor::CreateDatabaseSummary(), OSPF::Interface::FloodLSA(), OSPFRouting::LoadVirtualLink(), OSPF::DatabaseDescriptionHandler::ProcessDDPacket(), OSPF::LinkStateUpdateHandler::ProcessPacket(), OSPF::HelloHandler::ProcessPacket(), OSPF::Neighbor::SendDatabaseDescriptionPacket(), and OSPF::Interface::SendHelloPacket().
00064 { return externalRoutingCapability; }
void OSPF::Area::SetStubDefaultCost | ( | Metric | cost | ) | [inline] |
Metric OSPF::Area::GetStubDefaultCost | ( | void | ) | const [inline] |
void OSPF::Area::SetSPFTreeRoot | ( | RouterLSA * | root | ) | [inline] |
RouterLSA* OSPF::Area::GetSPFTreeRoot | ( | void | ) | [inline] |
const RouterLSA* OSPF::Area::GetSPFTreeRoot | ( | void | ) | const [inline] |
void OSPF::Area::SetRouter | ( | Router * | router | ) | [inline] |
Router* OSPF::Area::GetRouter | ( | void | ) | [inline] |
Referenced by OSPF::InterfaceState::CalculateDesignatedRouter(), OSPF::NeighborState::ChangeState(), OSPF::InterfaceState::ChangeState(), OSPF::Neighbor::ClearRequestRetransmissionTimer(), OSPF::Neighbor::ClearUpdateRetransmissionTimer(), OSPF::Neighbor::CreateDatabaseSummary(), OSPF::Interface::CreateUpdatePacket(), OSPF::Interface::FloodLSA(), OSPF::Neighbor::NeedAdjacency(), OSPF::NeighborStateTwoWay::ProcessEvent(), OSPF::NeighborStateLoading::ProcessEvent(), OSPF::NeighborStateInit::ProcessEvent(), OSPF::NeighborStateFull::ProcessEvent(), OSPF::NeighborStateExchangeStart::ProcessEvent(), OSPF::NeighborStateExchange::ProcessEvent(), OSPF::NeighborStateDown::ProcessEvent(), OSPF::NeighborStateAttempt::ProcessEvent(), OSPF::InterfaceStateWaiting::ProcessEvent(), OSPF::InterfaceStatePointToPoint::ProcessEvent(), OSPF::InterfaceStateNotDesignatedRouter::ProcessEvent(), OSPF::InterfaceStateDown::ProcessEvent(), OSPF::InterfaceStateDesignatedRouter::ProcessEvent(), OSPF::InterfaceStateBackup::ProcessEvent(), OSPF::Neighbor::Reset(), OSPF::Interface::Reset(), OSPF::Neighbor::RetransmitDatabaseDescriptionPacket(), OSPF::Neighbor::RetransmitUpdatePacket(), OSPF::Neighbor::SendDatabaseDescriptionPacket(), OSPF::Interface::SendDelayedAcknowledgements(), OSPF::Interface::SendHelloPacket(), OSPF::Neighbor::SendLinkStateRequestPacket(), OSPF::Interface::SendLSAcknowledgement(), OSPF::Neighbor::StartRequestRetransmissionTimer(), OSPF::Neighbor::StartUpdateRetransmissionTimer(), OSPF::Interface::~Interface(), and OSPF::Neighbor::~Neighbor().
00072 { return parentRouter; }
const Router* OSPF::Area::GetRouter | ( | void | ) | const [inline] |
unsigned long OSPF::Area::GetRouterLSACount | ( | void | ) | const [inline] |
RouterLSA* OSPF::Area::GetRouterLSA | ( | unsigned long | i | ) | [inline] |
const RouterLSA* OSPF::Area::GetRouterLSA | ( | unsigned long | i | ) | const [inline] |
unsigned long OSPF::Area::GetNetworkLSACount | ( | void | ) | const [inline] |
NetworkLSA* OSPF::Area::GetNetworkLSA | ( | unsigned long | i | ) | [inline] |
const NetworkLSA* OSPF::Area::GetNetworkLSA | ( | unsigned long | i | ) | const [inline] |
unsigned long OSPF::Area::GetSummaryLSACount | ( | void | ) | const [inline] |
SummaryLSA* OSPF::Area::GetSummaryLSA | ( | unsigned long | i | ) | [inline] |
const SummaryLSA* OSPF::Area::GetSummaryLSA | ( | unsigned long | i | ) | const [inline] |
bool OSPF::Area::ContainsAddress | ( | OSPF::IPv4Address | address | ) | const |
00115 { 00116 int addressRangeNum = areaAddressRanges.size(); 00117 for (int i = 0; i < addressRangeNum; i++) { 00118 if ((areaAddressRanges[i].address & areaAddressRanges[i].mask) == (address & areaAddressRanges[i].mask)) { 00119 return true; 00120 } 00121 } 00122 return false; 00123 }
bool OSPF::Area::HasAddressRange | ( | OSPF::IPv4AddressRange | addressRange | ) | const |
00126 { 00127 int addressRangeNum = areaAddressRanges.size(); 00128 for (int i = 0; i < addressRangeNum; i++) { 00129 if ((areaAddressRanges[i].address == addressRange.address) && 00130 (areaAddressRanges[i].mask == addressRange.mask)) 00131 { 00132 return true; 00133 } 00134 } 00135 return false; 00136 }
OSPF::IPv4AddressRange OSPF::Area::GetContainingAddressRange | ( | OSPF::IPv4AddressRange | addressRange, | |
bool * | advertise = NULL | |||
) | const |
00139 { 00140 int addressRangeNum = areaAddressRanges.size(); 00141 for (int i = 0; i < addressRangeNum; i++) { 00142 if ((areaAddressRanges[i].address & areaAddressRanges[i].mask) == (addressRange.address & areaAddressRanges[i].mask)) { 00143 if (advertise != NULL) { 00144 std::map<OSPF::IPv4AddressRange, bool, OSPF::IPv4AddressRange_Less>::const_iterator rangeIt = advertiseAddressRanges.find(areaAddressRanges[i]); 00145 if (rangeIt != advertiseAddressRanges.end()) { 00146 *advertise = rangeIt->second; 00147 } else { 00148 *advertise = true; 00149 } 00150 } 00151 return areaAddressRanges[i]; 00152 } 00153 } 00154 if (advertise != NULL) { 00155 *advertise = false; 00156 } 00157 return NullIPv4AddressRange; 00158 }
void OSPF::Area::AddInterface | ( | OSPF::Interface * | intf | ) |
Referenced by OSPFRouting::LoadInterfaceParameters(), and OSPFRouting::LoadVirtualLink().
00056 { 00057 intf->SetArea(this); 00058 associatedInterfaces.push_back(intf); 00059 }
OSPF::Interface * OSPF::Area::GetInterface | ( | unsigned char | ifIndex | ) |
Referenced by AgeDatabase(), and OSPF::MessageHandler::ProcessPacket().
00161 { 00162 int interfaceNum = associatedInterfaces.size(); 00163 for (int i = 0; i < interfaceNum; i++) { 00164 if ((associatedInterfaces[i]->GetType() != OSPF::Interface::Virtual) && 00165 (associatedInterfaces[i]->GetIfIndex() == ifIndex)) 00166 { 00167 return associatedInterfaces[i]; 00168 } 00169 } 00170 return NULL; 00171 }
OSPF::Interface * OSPF::Area::GetInterface | ( | OSPF::IPv4Address | address | ) |
00174 { 00175 int interfaceNum = associatedInterfaces.size(); 00176 for (int i = 0; i < interfaceNum; i++) { 00177 if ((associatedInterfaces[i]->GetType() != OSPF::Interface::Virtual) && 00178 (associatedInterfaces[i]->GetAddressRange().address == address)) 00179 { 00180 return associatedInterfaces[i]; 00181 } 00182 } 00183 return NULL; 00184 }
bool OSPF::Area::HasVirtualLink | ( | OSPF::AreaID | withTransitArea | ) | const |
Referenced by OriginateRouterLSA().
00187 { 00188 if ((areaID != OSPF::BackboneAreaID) || (withTransitArea == OSPF::BackboneAreaID)) { 00189 return false; 00190 } 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]->GetTransitAreaID() == withTransitArea)) 00196 { 00197 return true; 00198 } 00199 } 00200 return false; 00201 }
OSPF::Interface * OSPF::Area::FindVirtualLink | ( | OSPF::RouterID | routerID | ) |
Referenced by OSPF::MessageHandler::ProcessPacket().
00205 { 00206 int interfaceNum = associatedInterfaces.size(); 00207 for (int i = 0; i < interfaceNum; i++) { 00208 if ((associatedInterfaces[i]->GetType() == OSPF::Interface::Virtual) && 00209 (associatedInterfaces[i]->GetNeighborByID(routerID) != NULL)) 00210 { 00211 return associatedInterfaces[i]; 00212 } 00213 } 00214 return NULL; 00215 }
bool OSPF::Area::InstallRouterLSA | ( | OSPFRouterLSA * | lsa | ) |
Referenced by OSPF::InterfaceState::ChangeState().
00218 { 00219 OSPF::LinkStateID linkStateID = lsa->getHeader().getLinkStateID(); 00220 std::map<OSPF::LinkStateID, OSPF::RouterLSA*>::iterator lsaIt = routerLSAsByID.find(linkStateID); 00221 if (lsaIt != routerLSAsByID.end()) { 00222 OSPF::LSAKeyType lsaKey; 00223 00224 lsaKey.linkStateID = lsa->getHeader().getLinkStateID(); 00225 lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter().getInt(); 00226 00227 RemoveFromAllRetransmissionLists(lsaKey); 00228 return lsaIt->second->Update(lsa); 00229 } else { 00230 OSPF::RouterLSA* lsaCopy = new OSPF::RouterLSA(*lsa); 00231 routerLSAsByID[linkStateID] = lsaCopy; 00232 routerLSAs.push_back(lsaCopy); 00233 return true; 00234 } 00235 }
bool OSPF::Area::InstallNetworkLSA | ( | OSPFNetworkLSA * | lsa | ) |
Referenced by OSPF::InterfaceState::ChangeState().
00238 { 00239 OSPF::LinkStateID linkStateID = lsa->getHeader().getLinkStateID(); 00240 std::map<OSPF::LinkStateID, OSPF::NetworkLSA*>::iterator lsaIt = networkLSAsByID.find(linkStateID); 00241 if (lsaIt != networkLSAsByID.end()) { 00242 OSPF::LSAKeyType lsaKey; 00243 00244 lsaKey.linkStateID = lsa->getHeader().getLinkStateID(); 00245 lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter().getInt(); 00246 00247 RemoveFromAllRetransmissionLists(lsaKey); 00248 return lsaIt->second->Update(lsa); 00249 } else { 00250 OSPF::NetworkLSA* lsaCopy = new OSPF::NetworkLSA(*lsa); 00251 networkLSAsByID[linkStateID] = lsaCopy; 00252 networkLSAs.push_back(lsaCopy); 00253 return true; 00254 } 00255 }
bool OSPF::Area::InstallSummaryLSA | ( | OSPFSummaryLSA * | lsa | ) |
00258 { 00259 OSPF::LSAKeyType lsaKey; 00260 00261 lsaKey.linkStateID = lsa->getHeader().getLinkStateID(); 00262 lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter().getInt(); 00263 00264 std::map<OSPF::LSAKeyType, OSPF::SummaryLSA*, OSPF::LSAKeyType_Less>::iterator lsaIt = summaryLSAsByID.find(lsaKey); 00265 if (lsaIt != summaryLSAsByID.end()) { 00266 OSPF::LSAKeyType lsaKey; 00267 00268 lsaKey.linkStateID = lsa->getHeader().getLinkStateID(); 00269 lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter().getInt(); 00270 00271 RemoveFromAllRetransmissionLists(lsaKey); 00272 return lsaIt->second->Update(lsa); 00273 } else { 00274 OSPF::SummaryLSA* lsaCopy = new OSPF::SummaryLSA(*lsa); 00275 summaryLSAsByID[lsaKey] = lsaCopy; 00276 summaryLSAs.push_back(lsaCopy); 00277 return true; 00278 } 00279 }
OSPF::RouterLSA * OSPF::Area::FindRouterLSA | ( | OSPF::LinkStateID | linkStateID | ) |
Referenced by OSPF::NeighborState::ChangeState(), OSPF::InterfaceState::ChangeState(), and OSPF::HelloHandler::ProcessPacket().
00282 { 00283 std::map<OSPF::LinkStateID, OSPF::RouterLSA*>::iterator lsaIt = routerLSAsByID.find(linkStateID); 00284 if (lsaIt != routerLSAsByID.end()) { 00285 return lsaIt->second; 00286 } else { 00287 return NULL; 00288 } 00289 }
const OSPF::RouterLSA * OSPF::Area::FindRouterLSA | ( | OSPF::LinkStateID | linkStateID | ) | const |
00292 { 00293 std::map<OSPF::LinkStateID, OSPF::RouterLSA*>::const_iterator lsaIt = routerLSAsByID.find(linkStateID); 00294 if (lsaIt != routerLSAsByID.end()) { 00295 return lsaIt->second; 00296 } else { 00297 return NULL; 00298 } 00299 }
OSPF::NetworkLSA * OSPF::Area::FindNetworkLSA | ( | OSPF::LinkStateID | linkStateID | ) |
Referenced by OSPF::NeighborState::ChangeState(), and OSPF::InterfaceState::ChangeState().
00302 { 00303 std::map<OSPF::LinkStateID, OSPF::NetworkLSA*>::iterator lsaIt = networkLSAsByID.find(linkStateID); 00304 if (lsaIt != networkLSAsByID.end()) { 00305 return lsaIt->second; 00306 } else { 00307 return NULL; 00308 } 00309 }
const OSPF::NetworkLSA * OSPF::Area::FindNetworkLSA | ( | OSPF::LinkStateID | linkStateID | ) | const |
00312 { 00313 std::map<OSPF::LinkStateID, OSPF::NetworkLSA*>::const_iterator lsaIt = networkLSAsByID.find(linkStateID); 00314 if (lsaIt != networkLSAsByID.end()) { 00315 return lsaIt->second; 00316 } else { 00317 return NULL; 00318 } 00319 }
OSPF::SummaryLSA * OSPF::Area::FindSummaryLSA | ( | OSPF::LSAKeyType | lsaKey | ) |
Referenced by GetUniqueLinkStateID().
00322 { 00323 std::map<OSPF::LSAKeyType, OSPF::SummaryLSA*, OSPF::LSAKeyType_Less>::iterator lsaIt = summaryLSAsByID.find(lsaKey); 00324 if (lsaIt != summaryLSAsByID.end()) { 00325 return lsaIt->second; 00326 } else { 00327 return NULL; 00328 } 00329 }
const OSPF::SummaryLSA * OSPF::Area::FindSummaryLSA | ( | OSPF::LSAKeyType | lsaKey | ) | const |
00332 { 00333 std::map<OSPF::LSAKeyType, OSPF::SummaryLSA*, OSPF::LSAKeyType_Less>::const_iterator lsaIt = summaryLSAsByID.find(lsaKey); 00334 if (lsaIt != summaryLSAsByID.end()) { 00335 return lsaIt->second; 00336 } else { 00337 return NULL; 00338 } 00339 }
void OSPF::Area::AgeDatabase | ( | void | ) |
00342 { 00343 long lsaCount = routerLSAs.size(); 00344 bool rebuildRoutingTable = false; 00345 long i; 00346 00347 for (i = 0; i < lsaCount; i++) { 00348 unsigned short lsAge = routerLSAs[i]->getHeader().getLsAge(); 00349 bool selfOriginated = (routerLSAs[i]->getHeader().getAdvertisingRouter().getInt() == parentRouter->GetRouterID()); 00350 bool unreachable = parentRouter->IsDestinationUnreachable(routerLSAs[i]); 00351 OSPF::RouterLSA* lsa = routerLSAs[i]; 00352 00353 if ((selfOriginated && (lsAge < (LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) { 00354 lsa->getHeader().setLsAge(lsAge + 1); 00355 if ((lsAge + 1) % CHECK_AGE == 0) { 00356 if (!lsa->ValidateLSChecksum()) { 00357 EV << "Invalid LS checksum. Memory error detected!\n"; 00358 } 00359 } 00360 lsa->IncrementInstallTime(); 00361 } 00362 if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))) { 00363 if (unreachable) { 00364 lsa->getHeader().setLsAge(MAX_AGE); 00365 FloodLSA(lsa); 00366 lsa->IncrementInstallTime(); 00367 } else { 00368 long sequenceNumber = lsa->getHeader().getLsSequenceNumber(); 00369 if (sequenceNumber == MAX_SEQUENCE_NUMBER) { 00370 lsa->getHeader().setLsAge(MAX_AGE); 00371 FloodLSA(lsa); 00372 lsa->IncrementInstallTime(); 00373 } else { 00374 OSPF::RouterLSA* newLSA = OriginateRouterLSA(); 00375 00376 newLSA->getHeader().setLsSequenceNumber(sequenceNumber + 1); 00377 newLSA->getHeader().setLsChecksum(0); // TODO: calculate correct LS checksum 00378 rebuildRoutingTable |= lsa->Update(newLSA); 00379 delete newLSA; 00380 00381 FloodLSA(lsa); 00382 } 00383 } 00384 } 00385 if (!selfOriginated && (lsAge == MAX_AGE - 1)) { 00386 lsa->getHeader().setLsAge(MAX_AGE); 00387 FloodLSA(lsa); 00388 lsa->IncrementInstallTime(); 00389 } 00390 if (lsAge == MAX_AGE) { 00391 OSPF::LSAKeyType lsaKey; 00392 00393 lsaKey.linkStateID = lsa->getHeader().getLinkStateID(); 00394 lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter().getInt(); 00395 00396 if (!IsOnAnyRetransmissionList(lsaKey) && 00397 !HasAnyNeighborInStates(OSPF::Neighbor::ExchangeState | OSPF::Neighbor::LoadingState)) 00398 { 00399 if (!selfOriginated || unreachable) { 00400 routerLSAsByID.erase(lsa->getHeader().getLinkStateID()); 00401 delete lsa; 00402 routerLSAs[i] = NULL; 00403 rebuildRoutingTable = true; 00404 } else { 00405 OSPF::RouterLSA* newLSA = OriginateRouterLSA(); 00406 long sequenceNumber = lsa->getHeader().getLsSequenceNumber(); 00407 00408 newLSA->getHeader().setLsSequenceNumber((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1); 00409 newLSA->getHeader().setLsChecksum(0); // TODO: calculate correct LS checksum 00410 rebuildRoutingTable |= lsa->Update(newLSA); 00411 delete newLSA; 00412 00413 FloodLSA(lsa); 00414 } 00415 } 00416 } 00417 } 00418 00419 std::vector<RouterLSA*>::iterator routerIt = routerLSAs.begin(); 00420 while (routerIt != routerLSAs.end()) { 00421 if ((*routerIt) == NULL) { 00422 routerIt = routerLSAs.erase(routerIt); 00423 } else { 00424 routerIt++; 00425 } 00426 } 00427 00428 lsaCount = networkLSAs.size(); 00429 for (i = 0; i < lsaCount; i++) { 00430 unsigned short lsAge = networkLSAs[i]->getHeader().getLsAge(); 00431 bool unreachable = parentRouter->IsDestinationUnreachable(networkLSAs[i]); 00432 OSPF::NetworkLSA* lsa = networkLSAs[i]; 00433 OSPF::Interface* localIntf = GetInterface(IPv4AddressFromULong(lsa->getHeader().getLinkStateID())); 00434 bool selfOriginated = false; 00435 00436 if ((localIntf != NULL) && 00437 (localIntf->GetState() == OSPF::Interface::DesignatedRouterState) && 00438 (localIntf->GetNeighborCount() > 0) && 00439 (localIntf->HasAnyNeighborInStates(OSPF::Neighbor::FullState))) 00440 { 00441 selfOriginated = true; 00442 } 00443 00444 if ((selfOriginated && (lsAge < (LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) { 00445 lsa->getHeader().setLsAge(lsAge + 1); 00446 if ((lsAge + 1) % CHECK_AGE == 0) { 00447 if (!lsa->ValidateLSChecksum()) { 00448 EV << "Invalid LS checksum. Memory error detected!\n"; 00449 } 00450 } 00451 lsa->IncrementInstallTime(); 00452 } 00453 if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))) { 00454 if (unreachable) { 00455 lsa->getHeader().setLsAge(MAX_AGE); 00456 FloodLSA(lsa); 00457 lsa->IncrementInstallTime(); 00458 } else { 00459 long sequenceNumber = lsa->getHeader().getLsSequenceNumber(); 00460 if (sequenceNumber == MAX_SEQUENCE_NUMBER) { 00461 lsa->getHeader().setLsAge(MAX_AGE); 00462 FloodLSA(lsa); 00463 lsa->IncrementInstallTime(); 00464 } else { 00465 OSPF::NetworkLSA* newLSA = OriginateNetworkLSA(localIntf); 00466 00467 if (newLSA != NULL) { 00468 newLSA->getHeader().setLsSequenceNumber(sequenceNumber + 1); 00469 newLSA->getHeader().setLsChecksum(0); // TODO: calculate correct LS checksum 00470 rebuildRoutingTable |= lsa->Update(newLSA); 00471 delete newLSA; 00472 } else { // no neighbors on the network -> old NetworkLSA must be flushed 00473 lsa->getHeader().setLsAge(MAX_AGE); 00474 lsa->IncrementInstallTime(); 00475 } 00476 00477 FloodLSA(lsa); 00478 } 00479 } 00480 } 00481 if (!selfOriginated && (lsAge == MAX_AGE - 1)) { 00482 lsa->getHeader().setLsAge(MAX_AGE); 00483 FloodLSA(lsa); 00484 lsa->IncrementInstallTime(); 00485 } 00486 if (lsAge == MAX_AGE) { 00487 OSPF::LSAKeyType lsaKey; 00488 00489 lsaKey.linkStateID = lsa->getHeader().getLinkStateID(); 00490 lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter().getInt(); 00491 00492 if (!IsOnAnyRetransmissionList(lsaKey) && 00493 !HasAnyNeighborInStates(OSPF::Neighbor::ExchangeState | OSPF::Neighbor::LoadingState)) 00494 { 00495 if (!selfOriginated || unreachable) { 00496 networkLSAsByID.erase(lsa->getHeader().getLinkStateID()); 00497 delete lsa; 00498 networkLSAs[i] = NULL; 00499 rebuildRoutingTable = true; 00500 } else { 00501 OSPF::NetworkLSA* newLSA = OriginateNetworkLSA(localIntf); 00502 long sequenceNumber = lsa->getHeader().getLsSequenceNumber(); 00503 00504 if (newLSA != NULL) { 00505 newLSA->getHeader().setLsSequenceNumber((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1); 00506 newLSA->getHeader().setLsChecksum(0); // TODO: calculate correct LS checksum 00507 rebuildRoutingTable |= lsa->Update(newLSA); 00508 delete newLSA; 00509 00510 FloodLSA(lsa); 00511 } else { // no neighbors on the network -> old NetworkLSA must be deleted 00512 delete networkLSAs[i]; 00513 } 00514 } 00515 } 00516 } 00517 } 00518 00519 std::vector<NetworkLSA*>::iterator networkIt = networkLSAs.begin(); 00520 while (networkIt != networkLSAs.end()) { 00521 if ((*networkIt) == NULL) { 00522 networkIt = networkLSAs.erase(networkIt); 00523 } else { 00524 networkIt++; 00525 } 00526 } 00527 00528 lsaCount = summaryLSAs.size(); 00529 for (i = 0; i < lsaCount; i++) { 00530 unsigned short lsAge = summaryLSAs[i]->getHeader().getLsAge(); 00531 bool selfOriginated = (summaryLSAs[i]->getHeader().getAdvertisingRouter().getInt() == parentRouter->GetRouterID()); 00532 bool unreachable = parentRouter->IsDestinationUnreachable(summaryLSAs[i]); 00533 OSPF::SummaryLSA* lsa = summaryLSAs[i]; 00534 00535 if ((selfOriginated && (lsAge < (LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) { 00536 lsa->getHeader().setLsAge(lsAge + 1); 00537 if ((lsAge + 1) % CHECK_AGE == 0) { 00538 if (!lsa->ValidateLSChecksum()) { 00539 EV << "Invalid LS checksum. Memory error detected!\n"; 00540 } 00541 } 00542 lsa->IncrementInstallTime(); 00543 } 00544 if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))) { 00545 if (unreachable) { 00546 lsa->getHeader().setLsAge(MAX_AGE); 00547 FloodLSA(lsa); 00548 lsa->IncrementInstallTime(); 00549 } else { 00550 long sequenceNumber = lsa->getHeader().getLsSequenceNumber(); 00551 if (sequenceNumber == MAX_SEQUENCE_NUMBER) { 00552 lsa->getHeader().setLsAge(MAX_AGE); 00553 FloodLSA(lsa); 00554 lsa->IncrementInstallTime(); 00555 } else { 00556 OSPF::SummaryLSA* newLSA = OriginateSummaryLSA(lsa); 00557 00558 if (newLSA != NULL) { 00559 newLSA->getHeader().setLsSequenceNumber(sequenceNumber + 1); 00560 newLSA->getHeader().setLsChecksum(0); // TODO: calculate correct LS checksum 00561 rebuildRoutingTable |= lsa->Update(newLSA); 00562 delete newLSA; 00563 00564 FloodLSA(lsa); 00565 } else { 00566 lsa->getHeader().setLsAge(MAX_AGE); 00567 FloodLSA(lsa); 00568 lsa->IncrementInstallTime(); 00569 } 00570 } 00571 } 00572 } 00573 if (!selfOriginated && (lsAge == MAX_AGE - 1)) { 00574 lsa->getHeader().setLsAge(MAX_AGE); 00575 FloodLSA(lsa); 00576 lsa->IncrementInstallTime(); 00577 } 00578 if (lsAge == MAX_AGE) { 00579 OSPF::LSAKeyType lsaKey; 00580 00581 lsaKey.linkStateID = lsa->getHeader().getLinkStateID(); 00582 lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter().getInt(); 00583 00584 if (!IsOnAnyRetransmissionList(lsaKey) && 00585 !HasAnyNeighborInStates(OSPF::Neighbor::ExchangeState | OSPF::Neighbor::LoadingState)) 00586 { 00587 if (!selfOriginated || unreachable) { 00588 summaryLSAsByID.erase(lsaKey); 00589 delete lsa; 00590 summaryLSAs[i] = NULL; 00591 rebuildRoutingTable = true; 00592 } else { 00593 OSPF::SummaryLSA* newLSA = OriginateSummaryLSA(lsa); 00594 if (newLSA != NULL) { 00595 long sequenceNumber = lsa->getHeader().getLsSequenceNumber(); 00596 00597 newLSA->getHeader().setLsSequenceNumber((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1); 00598 newLSA->getHeader().setLsChecksum(0); // TODO: calculate correct LS checksum 00599 rebuildRoutingTable |= lsa->Update(newLSA); 00600 delete newLSA; 00601 00602 FloodLSA(lsa); 00603 } else { 00604 summaryLSAsByID.erase(lsaKey); 00605 delete lsa; 00606 summaryLSAs[i] = NULL; 00607 rebuildRoutingTable = true; 00608 } 00609 } 00610 } 00611 } 00612 } 00613 00614 std::vector<SummaryLSA*>::iterator summaryIt = summaryLSAs.begin(); 00615 while (summaryIt != summaryLSAs.end()) { 00616 if ((*summaryIt) == NULL) { 00617 summaryIt = summaryLSAs.erase(summaryIt); 00618 } else { 00619 summaryIt++; 00620 } 00621 } 00622 00623 long interfaceCount = associatedInterfaces.size(); 00624 for (long m = 0; m < interfaceCount; m++) { 00625 associatedInterfaces[m]->AgeTransmittedLSALists(); 00626 } 00627 00628 if (rebuildRoutingTable) { 00629 parentRouter->RebuildRoutingTable(); 00630 } 00631 }
bool OSPF::Area::HasAnyNeighborInStates | ( | int | states | ) | const |
Referenced by AgeDatabase().
00634 { 00635 long interfaceCount = associatedInterfaces.size(); 00636 for (long i = 0; i < interfaceCount; i++) { 00637 if (associatedInterfaces[i]->HasAnyNeighborInStates(states)) { 00638 return true; 00639 } 00640 } 00641 return false; 00642 }
void OSPF::Area::RemoveFromAllRetransmissionLists | ( | OSPF::LSAKeyType | lsaKey | ) |
Referenced by InstallNetworkLSA(), InstallRouterLSA(), and InstallSummaryLSA().
00645 { 00646 long interfaceCount = associatedInterfaces.size(); 00647 for (long i = 0; i < interfaceCount; i++) { 00648 associatedInterfaces[i]->RemoveFromAllRetransmissionLists(lsaKey); 00649 } 00650 }
bool OSPF::Area::IsOnAnyRetransmissionList | ( | OSPF::LSAKeyType | lsaKey | ) | const |
Referenced by AgeDatabase().
00653 { 00654 long interfaceCount = associatedInterfaces.size(); 00655 for (long i = 0; i < interfaceCount; i++) { 00656 if (associatedInterfaces[i]->IsOnAnyRetransmissionList(lsaKey)) { 00657 return true; 00658 } 00659 } 00660 return false; 00661 }
bool OSPF::Area::FloodLSA | ( | OSPFLSA * | lsa, | |
OSPF::Interface * | intf = NULL , |
|||
OSPF::Neighbor * | neighbor = NULL | |||
) |
Referenced by AgeDatabase(), OSPF::NeighborState::ChangeState(), OSPF::InterfaceState::ChangeState(), and OSPF::HelloHandler::ProcessPacket().
00664 { 00665 bool floodedBackOut = false; 00666 long interfaceCount = associatedInterfaces.size(); 00667 00668 for (long i = 0; i < interfaceCount; i++) { 00669 if (associatedInterfaces[i]->FloodLSA(lsa, intf, neighbor)) { 00670 floodedBackOut = true; 00671 } 00672 } 00673 00674 return floodedBackOut; 00675 }
bool OSPF::Area::IsLocalAddress | ( | OSPF::IPv4Address | address | ) | const |
00678 { 00679 long interfaceCount = associatedInterfaces.size(); 00680 for (long i = 0; i < interfaceCount; i++) { 00681 if (associatedInterfaces[i]->GetAddressRange().address == address) { 00682 return true; 00683 } 00684 } 00685 return false; 00686 }
OSPF::RouterLSA * OSPF::Area::OriginateRouterLSA | ( | void | ) |
Referenced by AgeDatabase(), OSPF::NeighborState::ChangeState(), OSPF::InterfaceState::ChangeState(), and OSPF::HelloHandler::ProcessPacket().
00689 { 00690 OSPF::RouterLSA* routerLSA = new OSPF::RouterLSA; 00691 OSPFLSAHeader& lsaHeader = routerLSA->getHeader(); 00692 long interfaceCount = associatedInterfaces.size(); 00693 OSPFOptions lsOptions; 00694 long i; 00695 00696 lsaHeader.setLsAge(0); 00697 memset(&lsOptions, 0, sizeof(OSPFOptions)); 00698 lsOptions.E_ExternalRoutingCapability = externalRoutingCapability; 00699 lsaHeader.setLsOptions(lsOptions); 00700 lsaHeader.setLsType(RouterLSAType); 00701 lsaHeader.setLinkStateID(parentRouter->GetRouterID()); 00702 lsaHeader.setAdvertisingRouter(parentRouter->GetRouterID()); 00703 lsaHeader.setLsSequenceNumber(INITIAL_SEQUENCE_NUMBER); 00704 00705 routerLSA->setB_AreaBorderRouter(parentRouter->GetAreaCount() > 1); 00706 routerLSA->setE_ASBoundaryRouter((externalRoutingCapability && parentRouter->GetASBoundaryRouter()) ? true : false); 00707 OSPF::Area* backbone = parentRouter->GetArea(OSPF::BackboneAreaID); 00708 routerLSA->setV_VirtualLinkEndpoint((backbone == NULL) ? false : backbone->HasVirtualLink(areaID)); 00709 00710 routerLSA->setNumberOfLinks(0); 00711 routerLSA->setLinksArraySize(0); 00712 for (i = 0; i < interfaceCount; i++) { 00713 OSPF::Interface* intf = associatedInterfaces[i]; 00714 00715 if (intf->GetState() == OSPF::Interface::DownState) { 00716 continue; 00717 } 00718 if ((intf->GetState() == OSPF::Interface::LoopbackState) && 00719 ((intf->GetType() != OSPF::Interface::PointToPoint) || 00720 (intf->GetAddressRange().address != OSPF::NullIPv4Address))) 00721 { 00722 Link stubLink; 00723 stubLink.setType(StubLink); 00724 stubLink.setLinkID(ULongFromIPv4Address(intf->GetAddressRange().address)); 00725 stubLink.setLinkData(0xFFFFFFFF); 00726 stubLink.setLinkCost(0); 00727 stubLink.setNumberOfTOS(0); 00728 stubLink.setTosDataArraySize(0); 00729 00730 unsigned short linkIndex = routerLSA->getLinksArraySize(); 00731 routerLSA->setLinksArraySize(linkIndex + 1); 00732 routerLSA->setNumberOfLinks(linkIndex + 1); 00733 routerLSA->setLinks(linkIndex, stubLink); 00734 } 00735 if (intf->GetState() > OSPF::Interface::LoopbackState) { 00736 switch (intf->GetType()) { 00737 case OSPF::Interface::PointToPoint: 00738 { 00739 OSPF::Neighbor* neighbor = (intf->GetNeighborCount() > 0) ? intf->GetNeighbor(0) : NULL; 00740 if (neighbor != NULL) { 00741 if (neighbor->GetState() == OSPF::Neighbor::FullState) { 00742 Link link; 00743 link.setType(PointToPointLink); 00744 link.setLinkID(neighbor->GetNeighborID()); 00745 if (intf->GetAddressRange().address != OSPF::NullIPv4Address) { 00746 link.setLinkData(ULongFromIPv4Address(intf->GetAddressRange().address)); 00747 } else { 00748 link.setLinkData(intf->GetIfIndex()); 00749 } 00750 link.setLinkCost(intf->GetOutputCost()); 00751 link.setNumberOfTOS(0); 00752 link.setTosDataArraySize(0); 00753 00754 unsigned short linkIndex = routerLSA->getLinksArraySize(); 00755 routerLSA->setLinksArraySize(linkIndex + 1); 00756 routerLSA->setNumberOfLinks(linkIndex + 1); 00757 routerLSA->setLinks(linkIndex, link); 00758 } 00759 if (intf->GetState() == OSPF::Interface::PointToPointState) { 00760 if (neighbor->GetAddress() != OSPF::NullIPv4Address) { 00761 Link stubLink; 00762 stubLink.setType(StubLink); 00763 stubLink.setLinkID(ULongFromIPv4Address(neighbor->GetAddress())); 00764 stubLink.setLinkData(0xFFFFFFFF); 00765 stubLink.setLinkCost(intf->GetOutputCost()); 00766 stubLink.setNumberOfTOS(0); 00767 stubLink.setTosDataArraySize(0); 00768 00769 unsigned short linkIndex = routerLSA->getLinksArraySize(); 00770 routerLSA->setLinksArraySize(linkIndex + 1); 00771 routerLSA->setNumberOfLinks(linkIndex + 1); 00772 routerLSA->setLinks(linkIndex, stubLink); 00773 } else { 00774 if (ULongFromIPv4Address(intf->GetAddressRange().mask) != 0xFFFFFFFF) { 00775 Link stubLink; 00776 stubLink.setType(StubLink); 00777 stubLink.setLinkID(ULongFromIPv4Address(intf->GetAddressRange().address & 00778 intf->GetAddressRange().mask)); 00779 stubLink.setLinkData(ULongFromIPv4Address(intf->GetAddressRange().mask)); 00780 stubLink.setLinkCost(intf->GetOutputCost()); 00781 stubLink.setNumberOfTOS(0); 00782 stubLink.setTosDataArraySize(0); 00783 00784 unsigned short linkIndex = routerLSA->getLinksArraySize(); 00785 routerLSA->setLinksArraySize(linkIndex + 1); 00786 routerLSA->setNumberOfLinks(linkIndex + 1); 00787 routerLSA->setLinks(linkIndex, stubLink); 00788 } 00789 } 00790 } 00791 } 00792 } 00793 break; 00794 case OSPF::Interface::Broadcast: 00795 case OSPF::Interface::NBMA: 00796 { 00797 if (intf->GetState() == OSPF::Interface::WaitingState) { 00798 Link stubLink; 00799 stubLink.setType(StubLink); 00800 stubLink.setLinkID(ULongFromIPv4Address(intf->GetAddressRange().address & 00801 intf->GetAddressRange().mask)); 00802 stubLink.setLinkData(ULongFromIPv4Address(intf->GetAddressRange().mask)); 00803 stubLink.setLinkCost(intf->GetOutputCost()); 00804 stubLink.setNumberOfTOS(0); 00805 stubLink.setTosDataArraySize(0); 00806 00807 unsigned short linkIndex = routerLSA->getLinksArraySize(); 00808 routerLSA->setLinksArraySize(linkIndex + 1); 00809 routerLSA->setNumberOfLinks(linkIndex + 1); 00810 routerLSA->setLinks(linkIndex, stubLink); 00811 } else { 00812 OSPF::Neighbor* dRouter = intf->GetNeighborByAddress(intf->GetDesignatedRouter().ipInterfaceAddress); 00813 if (((dRouter != NULL) && (dRouter->GetState() == OSPF::Neighbor::FullState)) || 00814 ((intf->GetDesignatedRouter().routerID == parentRouter->GetRouterID()) && 00815 (intf->HasAnyNeighborInStates(OSPF::Neighbor::FullState)))) 00816 { 00817 Link link; 00818 link.setType(TransitLink); 00819 link.setLinkID(ULongFromIPv4Address(intf->GetDesignatedRouter().ipInterfaceAddress)); 00820 link.setLinkData(ULongFromIPv4Address(intf->GetAddressRange().address)); 00821 link.setLinkCost(intf->GetOutputCost()); 00822 link.setNumberOfTOS(0); 00823 link.setTosDataArraySize(0); 00824 00825 unsigned short linkIndex = routerLSA->getLinksArraySize(); 00826 routerLSA->setLinksArraySize(linkIndex + 1); 00827 routerLSA->setNumberOfLinks(linkIndex + 1); 00828 routerLSA->setLinks(linkIndex, link); 00829 } else { 00830 Link stubLink; 00831 stubLink.setType(StubLink); 00832 stubLink.setLinkID(ULongFromIPv4Address(intf->GetAddressRange().address & 00833 intf->GetAddressRange().mask)); 00834 stubLink.setLinkData(ULongFromIPv4Address(intf->GetAddressRange().mask)); 00835 stubLink.setLinkCost(intf->GetOutputCost()); 00836 stubLink.setNumberOfTOS(0); 00837 stubLink.setTosDataArraySize(0); 00838 00839 unsigned short linkIndex = routerLSA->getLinksArraySize(); 00840 routerLSA->setLinksArraySize(linkIndex + 1); 00841 routerLSA->setNumberOfLinks(linkIndex + 1); 00842 routerLSA->setLinks(linkIndex, stubLink); 00843 } 00844 } 00845 } 00846 break; 00847 case OSPF::Interface::Virtual: 00848 { 00849 OSPF::Neighbor* neighbor = (intf->GetNeighborCount() > 0) ? intf->GetNeighbor(0) : NULL; 00850 if ((neighbor != NULL) && (neighbor->GetState() == OSPF::Neighbor::FullState)) { 00851 Link link; 00852 link.setType(VirtualLink); 00853 link.setLinkID(neighbor->GetNeighborID()); 00854 link.setLinkData(ULongFromIPv4Address(intf->GetAddressRange().address)); 00855 link.setLinkCost(intf->GetOutputCost()); 00856 link.setNumberOfTOS(0); 00857 link.setTosDataArraySize(0); 00858 00859 unsigned short linkIndex = routerLSA->getLinksArraySize(); 00860 routerLSA->setLinksArraySize(linkIndex + 1); 00861 routerLSA->setNumberOfLinks(linkIndex + 1); 00862 routerLSA->setLinks(linkIndex, link); 00863 } 00864 } 00865 break; 00866 case OSPF::Interface::PointToMultiPoint: 00867 { 00868 Link stubLink; 00869 stubLink.setType(StubLink); 00870 stubLink.setLinkID(ULongFromIPv4Address(intf->GetAddressRange().address)); 00871 stubLink.setLinkData(0xFFFFFFFF); 00872 stubLink.setLinkCost(0); 00873 stubLink.setNumberOfTOS(0); 00874 stubLink.setTosDataArraySize(0); 00875 00876 unsigned short linkIndex = routerLSA->getLinksArraySize(); 00877 routerLSA->setLinksArraySize(linkIndex + 1); 00878 routerLSA->setNumberOfLinks(linkIndex + 1); 00879 routerLSA->setLinks(linkIndex, stubLink); 00880 00881 long neighborCount = intf->GetNeighborCount(); 00882 for (long i = 0; i < neighborCount; i++) { 00883 OSPF::Neighbor* neighbor = intf->GetNeighbor(i); 00884 if (neighbor->GetState() == OSPF::Neighbor::FullState) { 00885 Link link; 00886 link.setType(PointToPointLink); 00887 link.setLinkID(neighbor->GetNeighborID()); 00888 link.setLinkData(ULongFromIPv4Address(intf->GetAddressRange().address)); 00889 link.setLinkCost(intf->GetOutputCost()); 00890 link.setNumberOfTOS(0); 00891 link.setTosDataArraySize(0); 00892 00893 unsigned short linkIndex = routerLSA->getLinksArraySize(); 00894 routerLSA->setLinksArraySize(linkIndex + 1); 00895 routerLSA->setNumberOfLinks(linkIndex + 1); 00896 routerLSA->setLinks(linkIndex, stubLink); 00897 } 00898 } 00899 } 00900 break; 00901 default: break; 00902 } 00903 } 00904 } 00905 00906 long hostRouteCount = hostRoutes.size(); 00907 for (i = 0; i < hostRouteCount; i++) { 00908 Link stubLink; 00909 stubLink.setType(StubLink); 00910 stubLink.setLinkID(ULongFromIPv4Address(hostRoutes[i].address)); 00911 stubLink.setLinkData(0xFFFFFFFF); 00912 stubLink.setLinkCost(hostRoutes[i].linkCost); 00913 stubLink.setNumberOfTOS(0); 00914 stubLink.setTosDataArraySize(0); 00915 00916 unsigned short linkIndex = routerLSA->getLinksArraySize(); 00917 routerLSA->setLinksArraySize(linkIndex + 1); 00918 routerLSA->setNumberOfLinks(linkIndex + 1); 00919 routerLSA->setLinks(linkIndex, stubLink); 00920 } 00921 00922 lsaHeader.setLsChecksum(0); // TODO: calculate correct LS checksum 00923 00924 routerLSA->SetSource(OSPF::LSATrackingInfo::Originated); 00925 00926 return routerLSA; 00927 }
OSPF::NetworkLSA * OSPF::Area::OriginateNetworkLSA | ( | const Interface * | intf | ) |
Referenced by AgeDatabase(), OSPF::NeighborState::ChangeState(), and OSPF::InterfaceState::ChangeState().
00930 { 00931 if (intf->HasAnyNeighborInStates(OSPF::Neighbor::FullState)) { 00932 OSPF::NetworkLSA* networkLSA = new OSPF::NetworkLSA; 00933 OSPFLSAHeader& lsaHeader = networkLSA->getHeader(); 00934 long neighborCount = intf->GetNeighborCount(); 00935 OSPFOptions lsOptions; 00936 00937 lsaHeader.setLsAge(0); 00938 memset(&lsOptions, 0, sizeof(OSPFOptions)); 00939 lsOptions.E_ExternalRoutingCapability = externalRoutingCapability; 00940 lsaHeader.setLsOptions(lsOptions); 00941 lsaHeader.setLsType(NetworkLSAType); 00942 lsaHeader.setLinkStateID(ULongFromIPv4Address(intf->GetAddressRange().address)); 00943 lsaHeader.setAdvertisingRouter(parentRouter->GetRouterID()); 00944 lsaHeader.setLsSequenceNumber(INITIAL_SEQUENCE_NUMBER); 00945 00946 networkLSA->setNetworkMask(ULongFromIPv4Address(intf->GetAddressRange().mask)); 00947 00948 for (long j = 0; j < neighborCount; j++) { 00949 const OSPF::Neighbor* neighbor = intf->GetNeighbor(j); 00950 if (neighbor->GetState() == OSPF::Neighbor::FullState) { 00951 unsigned short netIndex = networkLSA->getAttachedRoutersArraySize(); 00952 networkLSA->setAttachedRoutersArraySize(netIndex + 1); 00953 networkLSA->setAttachedRouters(netIndex, neighbor->GetNeighborID()); 00954 } 00955 } 00956 unsigned short netIndex = networkLSA->getAttachedRoutersArraySize(); 00957 networkLSA->setAttachedRoutersArraySize(netIndex + 1); 00958 networkLSA->setAttachedRouters(netIndex, parentRouter->GetRouterID()); 00959 00960 lsaHeader.setLsChecksum(0); // TODO: calculate correct LS checksum 00961 00962 return networkLSA; 00963 } else { 00964 return NULL; 00965 } 00966 }
SummaryLSA* OSPF::Area::OriginateSummaryLSA | ( | const RoutingTableEntry * | entry, | |
const std::map< LSAKeyType, bool, LSAKeyType_Less > & | originatedLSAs, | |||
SummaryLSA *& | lsaToReoriginate | |||
) |
Referenced by AgeDatabase(), and OriginateSummaryLSA().
void OSPF::Area::CalculateShortestPathTree | ( | std::vector< RoutingTableEntry * > & | newRoutingTable | ) |
void OSPF::Area::CalculateInterAreaRoutes | ( | std::vector< RoutingTableEntry * > & | newRoutingTable | ) |
Referenced by OSPF::Router::RebuildRoutingTable().
void OSPF::Area::ReCheckSummaryLSAs | ( | std::vector< RoutingTableEntry * > & | newRoutingTable | ) |
void OSPF::Area::info | ( | char * | buffer | ) |
00062 { 00063 std::stringstream out; 00064 char areaString[16]; 00065 out << "areaID: " << AddressStringFromULong(areaString, 16, areaID); 00066 strcpy(buffer, out.str().c_str()); 00067 }
std::string OSPF::Area::detailedInfo | ( | void | ) | const |
Referenced by operator<<().
00070 { 00071 std::stringstream out; 00072 char addressString[16]; 00073 int i; 00074 out << "\n areaID: " << AddressStringFromULong(addressString, 16, areaID) << ", "; 00075 out << "transitCapability: " << (transitCapability ? "true" : "false") << ", "; 00076 out << "externalRoutingCapability: " << (externalRoutingCapability ? "true" : "false") << ", "; 00077 out << "stubDefaultCost: " << stubDefaultCost << "\n"; 00078 int addressRangeNum = areaAddressRanges.size(); 00079 for (i = 0; i < addressRangeNum; i++) { 00080 out << " addressRanges[" << i << "]: "; 00081 out << AddressStringFromIPv4Address(addressString, 16, areaAddressRanges[i].address); 00082 out << "/" << AddressStringFromIPv4Address(addressString, 16, areaAddressRanges[i].mask) << "\n"; 00083 } 00084 int interfaceNum = associatedInterfaces.size(); 00085 for (i = 0; i < interfaceNum; i++) { 00086 out << " interface[" << i << "]: addressRange: "; 00087 out << AddressStringFromIPv4Address(addressString, 16, associatedInterfaces[i]->GetAddressRange().address); 00088 out << "/" << AddressStringFromIPv4Address(addressString, 16, associatedInterfaces[i]->GetAddressRange().mask) << "\n"; 00089 } 00090 00091 out << "\n"; 00092 out << " Database:\n"; 00093 out << " RouterLSAs:\n"; 00094 long lsaCount = routerLSAs.size(); 00095 for (i = 0; i < lsaCount; i++) { 00096 out << " " << *routerLSAs[i] << "\n"; 00097 } 00098 out << " NetworkLSAs:\n"; 00099 lsaCount = networkLSAs.size(); 00100 for (i = 0; i < lsaCount; i++) { 00101 out << " " << *networkLSAs[i] << "\n"; 00102 } 00103 out << " SummaryLSAs:\n"; 00104 lsaCount = summaryLSAs.size(); 00105 for (i = 0; i < lsaCount; i++) { 00106 out << " " << *summaryLSAs[i] << "\n"; 00107 } 00108 00109 out << "--------------------------------------------------------------------------------"; 00110 00111 return out.str(); 00112 }
OSPF::SummaryLSA * OSPF::Area::OriginateSummaryLSA | ( | const OSPF::SummaryLSA * | summaryLSA | ) | [private] |
01293 { 01294 const std::map<OSPF::LSAKeyType, bool, OSPF::LSAKeyType_Less> emptyMap; 01295 OSPF::SummaryLSA* dontReoriginate = NULL; 01296 01297 const OSPFLSAHeader& lsaHeader = summaryLSA->getHeader(); 01298 unsigned long entryCount = parentRouter->GetRoutingTableEntryCount(); 01299 01300 for (unsigned long i = 0; i < entryCount; i++) { 01301 const OSPF::RoutingTableEntry* entry = parentRouter->GetRoutingTableEntry(i); 01302 01303 if ((lsaHeader.getLsType() == SummaryLSA_ASBoundaryRoutersType) && 01304 ((((entry->GetDestinationType() & OSPF::RoutingTableEntry::AreaBorderRouterDestination) != 0) || 01305 ((entry->GetDestinationType() & OSPF::RoutingTableEntry::ASBoundaryRouterDestination) != 0)) && 01306 ((entry->GetDestinationID().getInt() == lsaHeader.getLinkStateID()) && 01307 (entry->GetAddressMask() == summaryLSA->getNetworkMask())))) 01308 { 01309 OSPF::SummaryLSA* returnLSA = OriginateSummaryLSA(entry, emptyMap, dontReoriginate); 01310 if (dontReoriginate != NULL) { 01311 delete dontReoriginate; 01312 } 01313 return returnLSA; 01314 } 01315 01316 unsigned long lsaMask = summaryLSA->getNetworkMask().getInt(); 01317 01318 if ((lsaHeader.getLsType() == SummaryLSA_NetworksType) && 01319 (entry->GetDestinationType() == OSPF::RoutingTableEntry::NetworkDestination) && 01320 (entry->GetAddressMask().getInt() == lsaMask) && 01321 (entry->GetDestinationID().getInt() & lsaMask == lsaHeader.getLinkStateID() & lsaMask)) 01322 { 01323 OSPF::SummaryLSA* returnLSA = OriginateSummaryLSA(entry, emptyMap, dontReoriginate); 01324 if (dontReoriginate != NULL) { 01325 delete dontReoriginate; 01326 } 01327 return returnLSA; 01328 } 01329 } 01330 01331 return NULL; 01332 }
bool OSPF::Area::HasLink | ( | OSPFLSA * | fromLSA, | |
OSPFLSA * | toLSA | |||
) | const [private] |
02043 { 02044 unsigned int i; 02045 02046 OSPF::RouterLSA* fromRouterLSA = dynamic_cast<OSPF::RouterLSA*> (fromLSA); 02047 if (fromRouterLSA != NULL) { 02048 unsigned int linkCount = fromRouterLSA->getLinksArraySize(); 02049 OSPF::RouterLSA* toRouterLSA = dynamic_cast<OSPF::RouterLSA*> (toLSA); 02050 if (toRouterLSA != NULL) { 02051 for (i = 0; i < linkCount; i++) { 02052 Link& link = fromRouterLSA->getLinks(i); 02053 LinkType linkType = static_cast<LinkType> (link.getType()); 02054 02055 if (((linkType == PointToPointLink) || 02056 (linkType == VirtualLink)) && 02057 (link.getLinkID().getInt() == toRouterLSA->getHeader().getLinkStateID())) 02058 { 02059 return true; 02060 } 02061 } 02062 } else { 02063 OSPF::NetworkLSA* toNetworkLSA = dynamic_cast<OSPF::NetworkLSA*> (toLSA); 02064 if (toNetworkLSA != NULL) { 02065 for (i = 0; i < linkCount; i++) { 02066 Link& link = fromRouterLSA->getLinks(i); 02067 02068 if ((link.getType() == TransitLink) && 02069 (link.getLinkID().getInt() == toNetworkLSA->getHeader().getLinkStateID())) 02070 { 02071 return true; 02072 } 02073 if ((link.getType() == StubLink) && 02074 ((link.getLinkID().getInt() & link.getLinkData()) == (toNetworkLSA->getHeader().getLinkStateID() & toNetworkLSA->getNetworkMask().getInt()))) 02075 { 02076 return true; 02077 } 02078 } 02079 } 02080 } 02081 } else { 02082 OSPF::NetworkLSA* fromNetworkLSA = dynamic_cast<OSPF::NetworkLSA*> (fromLSA); 02083 if (fromNetworkLSA != NULL) { 02084 unsigned int routerCount = fromNetworkLSA->getAttachedRoutersArraySize(); 02085 OSPF::RouterLSA* toRouterLSA = dynamic_cast<OSPF::RouterLSA*> (toLSA); 02086 if (toRouterLSA != NULL) { 02087 for (i = 0; i < routerCount; i++) { 02088 if (fromNetworkLSA->getAttachedRouters(i).getInt() == toRouterLSA->getHeader().getLinkStateID()) { 02089 return true; 02090 } 02091 } 02092 } 02093 } 02094 } 02095 02096 return false; 02097 }
std::vector< OSPF::NextHop > * OSPF::Area::CalculateNextHops | ( | OSPFLSA * | destination, | |
OSPFLSA * | parent | |||
) | const [private] |
01812 { 01813 std::vector<OSPF::NextHop>* hops = new std::vector<OSPF::NextHop>; 01814 unsigned long i, j; 01815 01816 OSPF::RouterLSA* routerLSA = dynamic_cast<OSPF::RouterLSA*> (parent); 01817 if (routerLSA != NULL) { 01818 if (routerLSA != spfTreeRoot) { 01819 unsigned int nextHopCount = routerLSA->GetNextHopCount(); 01820 for (i = 0; i < nextHopCount; i++) { 01821 hops->push_back(routerLSA->GetNextHop(i)); 01822 } 01823 return hops; 01824 } else { 01825 OSPF::RouterLSA* destinationRouterLSA = dynamic_cast<OSPF::RouterLSA*> (destination); 01826 if (destinationRouterLSA != NULL) { 01827 unsigned long interfaceNum = associatedInterfaces.size(); 01828 for (i = 0; i < interfaceNum; i++) { 01829 OSPF::Interface::OSPFInterfaceType intfType = associatedInterfaces[i]->GetType(); 01830 if ((intfType == OSPF::Interface::PointToPoint) || 01831 ((intfType == OSPF::Interface::Virtual) && 01832 (associatedInterfaces[i]->GetState() > OSPF::Interface::LoopbackState))) 01833 { 01834 OSPF::Neighbor* ptpNeighbor = associatedInterfaces[i]->GetNeighborCount() > 0 ? associatedInterfaces[i]->GetNeighbor(0) : NULL; 01835 if (ptpNeighbor != NULL) { 01836 if (ptpNeighbor->GetNeighborID() == destinationRouterLSA->getHeader().getLinkStateID()) { 01837 NextHop nextHop; 01838 nextHop.ifIndex = associatedInterfaces[i]->GetIfIndex(); 01839 nextHop.hopAddress = ptpNeighbor->GetAddress(); 01840 nextHop.advertisingRouter = destinationRouterLSA->getHeader().getAdvertisingRouter().getInt(); 01841 hops->push_back(nextHop); 01842 break; 01843 } 01844 } 01845 } 01846 if (intfType == OSPF::Interface::PointToMultiPoint) { 01847 OSPF::Neighbor* ptmpNeighbor = associatedInterfaces[i]->GetNeighborByID(destinationRouterLSA->getHeader().getLinkStateID()); 01848 if (ptmpNeighbor != NULL) { 01849 unsigned int linkCount = destinationRouterLSA->getLinksArraySize(); 01850 OSPF::RouterID rootID = parentRouter->GetRouterID(); 01851 for (j = 0; j < linkCount; j++) { 01852 Link& link = destinationRouterLSA->getLinks(j); 01853 if (link.getLinkID() == rootID) { 01854 NextHop nextHop; 01855 nextHop.ifIndex = associatedInterfaces[i]->GetIfIndex(); 01856 nextHop.hopAddress = IPv4AddressFromULong(link.getLinkData()); 01857 nextHop.advertisingRouter = destinationRouterLSA->getHeader().getAdvertisingRouter().getInt(); 01858 hops->push_back(nextHop); 01859 } 01860 } 01861 break; 01862 } 01863 } 01864 } 01865 } else { 01866 OSPF::NetworkLSA* destinationNetworkLSA = dynamic_cast<OSPF::NetworkLSA*> (destination); 01867 if (destinationNetworkLSA != NULL) { 01868 OSPF::IPv4Address networkDesignatedRouter = IPv4AddressFromULong(destinationNetworkLSA->getHeader().getLinkStateID()); 01869 unsigned long interfaceNum = associatedInterfaces.size(); 01870 for (i = 0; i < interfaceNum; i++) { 01871 OSPF::Interface::OSPFInterfaceType intfType = associatedInterfaces[i]->GetType(); 01872 if (((intfType == OSPF::Interface::Broadcast) || 01873 (intfType == OSPF::Interface::NBMA)) && 01874 (associatedInterfaces[i]->GetDesignatedRouter().ipInterfaceAddress == networkDesignatedRouter)) 01875 { 01876 OSPF::IPv4AddressRange range = associatedInterfaces[i]->GetAddressRange(); 01877 NextHop nextHop; 01878 01879 nextHop.ifIndex = associatedInterfaces[i]->GetIfIndex(); 01880 nextHop.hopAddress = (range.address & range.mask); 01881 nextHop.advertisingRouter = destinationNetworkLSA->getHeader().getAdvertisingRouter().getInt(); 01882 hops->push_back(nextHop); 01883 } 01884 } 01885 } 01886 } 01887 } 01888 } else { 01889 OSPF::NetworkLSA* networkLSA = dynamic_cast<OSPF::NetworkLSA*> (parent); 01890 if (networkLSA != NULL) { 01891 if (networkLSA->GetParent() != spfTreeRoot) { 01892 unsigned int nextHopCount = networkLSA->GetNextHopCount(); 01893 for (i = 0; i < nextHopCount; i++) { 01894 hops->push_back(networkLSA->GetNextHop(i)); 01895 } 01896 return hops; 01897 } else { 01898 unsigned long parentLinkStateID = parent->getHeader().getLinkStateID(); 01899 01900 OSPF::RouterLSA* destinationRouterLSA = dynamic_cast<OSPF::RouterLSA*> (destination); 01901 if (destinationRouterLSA != NULL) { 01902 OSPF::RouterID destinationRouterID = destinationRouterLSA->getHeader().getLinkStateID(); 01903 unsigned int linkCount = destinationRouterLSA->getLinksArraySize(); 01904 for (i = 0; i < linkCount; i++) { 01905 Link& link = destinationRouterLSA->getLinks(i); 01906 NextHop nextHop; 01907 01908 if (((link.getType() == TransitLink) && 01909 (link.getLinkID().getInt() == parentLinkStateID)) || 01910 ((link.getType() == StubLink) && 01911 ((link.getLinkID().getInt() & link.getLinkData()) == (parentLinkStateID & networkLSA->getNetworkMask().getInt())))) 01912 { 01913 unsigned long interfaceNum = associatedInterfaces.size(); 01914 for (j = 0; j < interfaceNum; j++) { 01915 OSPF::Interface::OSPFInterfaceType intfType = associatedInterfaces[j]->GetType(); 01916 if (((intfType == OSPF::Interface::Broadcast) || 01917 (intfType == OSPF::Interface::NBMA)) && 01918 (associatedInterfaces[j]->GetDesignatedRouter().ipInterfaceAddress == IPv4AddressFromULong(parentLinkStateID))) 01919 { 01920 OSPF::Neighbor* nextHopNeighbor = associatedInterfaces[j]->GetNeighborByID(destinationRouterID); 01921 if (nextHopNeighbor != NULL) { 01922 nextHop.ifIndex = associatedInterfaces[j]->GetIfIndex(); 01923 nextHop.hopAddress = nextHopNeighbor->GetAddress(); 01924 nextHop.advertisingRouter = destinationRouterLSA->getHeader().getAdvertisingRouter().getInt(); 01925 hops->push_back(nextHop); 01926 } 01927 } 01928 } 01929 } 01930 } 01931 } 01932 } 01933 } 01934 } 01935 01936 return hops; 01937 }
std::vector< OSPF::NextHop > * OSPF::Area::CalculateNextHops | ( | Link & | destination, | |
OSPFLSA * | parent | |||
) | const [private] |
01940 { 01941 std::vector<OSPF::NextHop>* hops = new std::vector<OSPF::NextHop>; 01942 unsigned long i; 01943 01944 OSPF::RouterLSA* routerLSA = check_and_cast<OSPF::RouterLSA*> (parent); 01945 if (routerLSA != spfTreeRoot) { 01946 unsigned int nextHopCount = routerLSA->GetNextHopCount(); 01947 for (i = 0; i < nextHopCount; i++) { 01948 hops->push_back(routerLSA->GetNextHop(i)); 01949 } 01950 return hops; 01951 } else { 01952 unsigned long interfaceNum = associatedInterfaces.size(); 01953 for (i = 0; i < interfaceNum; i++) { 01954 OSPF::Interface::OSPFInterfaceType intfType = associatedInterfaces[i]->GetType(); 01955 01956 if ((intfType == OSPF::Interface::PointToPoint) || 01957 ((intfType == OSPF::Interface::Virtual) && 01958 (associatedInterfaces[i]->GetState() > OSPF::Interface::LoopbackState))) 01959 { 01960 OSPF::Neighbor* neighbor = (associatedInterfaces[i]->GetNeighborCount() > 0) ? associatedInterfaces[i]->GetNeighbor(0) : NULL; 01961 if (neighbor != NULL) { 01962 OSPF::IPv4Address neighborAddress = neighbor->GetAddress(); 01963 if (((neighborAddress != OSPF::NullIPv4Address) && 01964 (ULongFromIPv4Address(neighborAddress) == destination.getLinkID().getInt())) || 01965 ((neighborAddress == OSPF::NullIPv4Address) && 01966 (ULongFromIPv4Address(associatedInterfaces[i]->GetAddressRange().address) == destination.getLinkID().getInt()) && 01967 (ULongFromIPv4Address(associatedInterfaces[i]->GetAddressRange().mask) == destination.getLinkData()))) 01968 { 01969 NextHop nextHop; 01970 nextHop.ifIndex = associatedInterfaces[i]->GetIfIndex(); 01971 nextHop.hopAddress = neighborAddress; 01972 nextHop.advertisingRouter = parentRouter->GetRouterID(); 01973 hops->push_back(nextHop); 01974 break; 01975 } 01976 } 01977 } 01978 if ((intfType == OSPF::Interface::Broadcast) || 01979 (intfType == OSPF::Interface::NBMA)) 01980 { 01981 if ((destination.getLinkID().getInt() == ULongFromIPv4Address(associatedInterfaces[i]->GetAddressRange().address & associatedInterfaces[i]->GetAddressRange().mask)) && 01982 (destination.getLinkData() == ULongFromIPv4Address(associatedInterfaces[i]->GetAddressRange().mask))) 01983 { 01984 NextHop nextHop; 01985 nextHop.ifIndex = associatedInterfaces[i]->GetIfIndex(); 01986 nextHop.hopAddress = IPv4AddressFromULong(destination.getLinkID().getInt()); 01987 nextHop.advertisingRouter = parentRouter->GetRouterID(); 01988 hops->push_back(nextHop); 01989 break; 01990 } 01991 } 01992 if (intfType == OSPF::Interface::PointToMultiPoint) { 01993 if (destination.getType() == StubLink) { 01994 if (destination.getLinkID().getInt() == ULongFromIPv4Address(associatedInterfaces[i]->GetAddressRange().address)) { 01995 // The link contains the router's own interface address and a full mask, 01996 // so we insert a next hop pointing to the interface itself. Kind of pointless, but 01997 // not much else we could do... 01998 // TODO: check what other OSPF implementations do in this situation 01999 NextHop nextHop; 02000 nextHop.ifIndex = associatedInterfaces[i]->GetIfIndex(); 02001 nextHop.hopAddress = associatedInterfaces[i]->GetAddressRange().address; 02002 nextHop.advertisingRouter = parentRouter->GetRouterID(); 02003 hops->push_back(nextHop); 02004 break; 02005 } 02006 } 02007 if (destination.getType() == PointToPointLink) { 02008 OSPF::Neighbor* neighbor = associatedInterfaces[i]->GetNeighborByID(destination.getLinkID().getInt()); 02009 if (neighbor != NULL) { 02010 NextHop nextHop; 02011 nextHop.ifIndex = associatedInterfaces[i]->GetIfIndex(); 02012 nextHop.hopAddress = neighbor->GetAddress(); 02013 nextHop.advertisingRouter = parentRouter->GetRouterID(); 02014 hops->push_back(nextHop); 02015 break; 02016 } 02017 } 02018 } 02019 // next hops for virtual links are generated later, after examining transit areas' SummaryLSAs 02020 } 02021 02022 if (hops->size() == 0) { 02023 unsigned long hostRouteCount = hostRoutes.size(); 02024 for (i = 0; i < hostRouteCount; i++) { 02025 if ((destination.getLinkID().getInt() == ULongFromIPv4Address(hostRoutes[i].address)) && 02026 (destination.getLinkData() == 0xFFFFFFFF)) 02027 { 02028 NextHop nextHop; 02029 nextHop.ifIndex = hostRoutes[i].ifIndex; 02030 nextHop.hopAddress = hostRoutes[i].address; 02031 nextHop.advertisingRouter = parentRouter->GetRouterID(); 02032 hops->push_back(nextHop); 02033 break; 02034 } 02035 } 02036 } 02037 } 02038 02039 return hops; 02040 }
OSPF::LinkStateID OSPF::Area::GetUniqueLinkStateID | ( | OSPF::IPv4AddressRange | destination, | |
OSPF::Metric | destinationCost, | |||
OSPF::SummaryLSA *& | lsaToReoriginate | |||
) | const [private] |
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.
00992 { 00993 if (lsaToReoriginate != NULL) { 00994 delete lsaToReoriginate; 00995 lsaToReoriginate = NULL; 00996 } 00997 00998 OSPF::LSAKeyType lsaKey; 00999 01000 lsaKey.linkStateID = ULongFromIPv4Address(destination.address); 01001 lsaKey.advertisingRouter = parentRouter->GetRouterID(); 01002 01003 const OSPF::SummaryLSA* foundLSA = FindSummaryLSA(lsaKey); 01004 01005 if (foundLSA == NULL) { 01006 return lsaKey.linkStateID; 01007 } else { 01008 OSPF::IPv4Address existingMask = IPv4AddressFromULong(foundLSA->getNetworkMask().getInt()); 01009 01010 if (destination.mask == existingMask) { 01011 return lsaKey.linkStateID; 01012 } else { 01013 if (destination.mask >= existingMask) { 01014 return (lsaKey.linkStateID | (~(ULongFromIPv4Address(destination.mask)))); 01015 } else { 01016 OSPF::SummaryLSA* summaryLSA = new OSPF::SummaryLSA(*foundLSA); 01017 01018 long sequenceNumber = summaryLSA->getHeader().getLsSequenceNumber(); 01019 01020 summaryLSA->getHeader().setLsAge(0); 01021 summaryLSA->getHeader().setLsSequenceNumber((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1); 01022 summaryLSA->setNetworkMask(ULongFromIPv4Address(destination.mask)); 01023 summaryLSA->setRouteCost(destinationCost); 01024 summaryLSA->getHeader().setLsChecksum(0); // TODO: calculate correct LS checksum 01025 01026 lsaToReoriginate = summaryLSA; 01027 01028 return (lsaKey.linkStateID | (~(ULongFromIPv4Address(existingMask)))); 01029 } 01030 } 01031 } 01032 }
bool OSPF::Area::FindSameOrWorseCostRoute | ( | const std::vector< OSPF::RoutingTableEntry * > & | newRoutingTable, | |
const OSPF::SummaryLSA & | summaryLSA, | |||
unsigned short | currentCost, | |||
bool & | destinationInRoutingTable, | |||
std::list< OSPF::RoutingTableEntry * > & | sameOrWorseCost | |||
) | const [private] |
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.
02109 { 02110 destinationInRoutingTable = false; 02111 sameOrWorseCost.clear(); 02112 02113 long routeCount = newRoutingTable.size(); 02114 OSPF::IPv4AddressRange destination; 02115 02116 destination.address = IPv4AddressFromULong(summaryLSA.getHeader().getLinkStateID()); 02117 destination.mask = IPv4AddressFromULong(summaryLSA.getNetworkMask().getInt()); 02118 02119 for (long j = 0; j < routeCount; j++) { 02120 OSPF::RoutingTableEntry* routingEntry = newRoutingTable[j]; 02121 bool foundMatching = false; 02122 02123 if (summaryLSA.getHeader().getLsType() == SummaryLSA_NetworksType) { 02124 if ((routingEntry->GetDestinationType() == OSPF::RoutingTableEntry::NetworkDestination) && 02125 (ULongFromIPv4Address(destination.address & destination.mask) == routingEntry->GetDestinationID().getInt())) 02126 { 02127 foundMatching = true; 02128 } 02129 } else { 02130 if ((((routingEntry->GetDestinationType() & OSPF::RoutingTableEntry::AreaBorderRouterDestination) != 0) || 02131 ((routingEntry->GetDestinationType() & OSPF::RoutingTableEntry::ASBoundaryRouterDestination) != 0)) && 02132 (ULongFromIPv4Address(destination.address) == routingEntry->GetDestinationID().getInt())) 02133 { 02134 foundMatching = true; 02135 } 02136 } 02137 02138 if (foundMatching) { 02139 destinationInRoutingTable = true; 02140 02141 /* If the matching entry is an IntraArea getRoute(intra-area paths are 02142 * always preferred to other paths of any cost), or it's a cheaper InterArea 02143 * route, then skip this LSA. 02144 */ 02145 if ((routingEntry->GetPathType() == OSPF::RoutingTableEntry::IntraArea) || 02146 ((routingEntry->GetPathType() == OSPF::RoutingTableEntry::InterArea) && 02147 (routingEntry->GetCost() < currentCost))) 02148 { 02149 return true; 02150 } else { 02151 // if it's an other InterArea path 02152 if ((routingEntry->GetPathType() == OSPF::RoutingTableEntry::InterArea) && 02153 (routingEntry->GetCost() >= currentCost)) 02154 { 02155 sameOrWorseCost.push_back(routingEntry); 02156 } // else it's external -> same as if not in the table 02157 } 02158 } 02159 } 02160 return false; 02161 }
OSPF::RoutingTableEntry * OSPF::Area::CreateRoutingTableEntryFromSummaryLSA | ( | const OSPF::SummaryLSA & | summaryLSA, | |
unsigned short | entryCost, | |||
const OSPF::RoutingTableEntry & | borderRouterEntry | |||
) | const [private] |
Returns a new RoutingTableEntry based on the input SummaryLSA, with the input cost and the borderRouterEntry's next hops.
02170 { 02171 OSPF::IPv4AddressRange destination; 02172 02173 destination.address = IPv4AddressFromULong(summaryLSA.getHeader().getLinkStateID()); 02174 destination.mask = IPv4AddressFromULong(summaryLSA.getNetworkMask().getInt()); 02175 02176 OSPF::RoutingTableEntry* newEntry = new OSPF::RoutingTableEntry; 02177 02178 if (summaryLSA.getHeader().getLsType() == SummaryLSA_NetworksType) { 02179 newEntry->SetDestinationID(ULongFromIPv4Address(destination.address & destination.mask)); 02180 newEntry->SetAddressMask(ULongFromIPv4Address(destination.mask)); 02181 newEntry->SetDestinationType(OSPF::RoutingTableEntry::NetworkDestination); 02182 } else { 02183 newEntry->SetDestinationID(ULongFromIPv4Address(destination.address)); 02184 newEntry->SetAddressMask(0xFFFFFFFF); 02185 newEntry->SetDestinationType(OSPF::RoutingTableEntry::ASBoundaryRouterDestination); 02186 } 02187 newEntry->SetArea(areaID); 02188 newEntry->SetPathType(OSPF::RoutingTableEntry::InterArea); 02189 newEntry->SetCost(entryCost); 02190 newEntry->SetOptionalCapabilities(summaryLSA.getHeader().getLsOptions()); 02191 newEntry->SetLinkStateOrigin(&summaryLSA); 02192 02193 unsigned int nextHopCount = borderRouterEntry.GetNextHopCount(); 02194 for (unsigned int j = 0; j < nextHopCount; j++) { 02195 newEntry->AddNextHop(borderRouterEntry.GetNextHop(j)); 02196 } 02197 02198 return newEntry; 02199 }
AreaID OSPF::Area::areaID [private] |
Referenced by CreateRoutingTableEntryFromSummaryLSA(), detailedInfo(), GetAreaID(), HasVirtualLink(), info(), OriginateRouterLSA(), and SetAreaID().
std::map<IPv4AddressRange, bool, IPv4AddressRange_Less> OSPF::Area::advertiseAddressRanges [private] |
Referenced by AddAddressRange(), and GetContainingAddressRange().
std::vector<IPv4AddressRange> OSPF::Area::areaAddressRanges [private] |
std::vector<Interface*> OSPF::Area::associatedInterfaces [private] |
std::vector<HostRouteParameters> OSPF::Area::hostRoutes [private] |
Referenced by AddHostRoute(), CalculateNextHops(), and OriginateRouterLSA().
std::map<LinkStateID, RouterLSA*> OSPF::Area::routerLSAsByID [private] |
Referenced by AgeDatabase(), FindRouterLSA(), and InstallRouterLSA().
std::vector<RouterLSA*> OSPF::Area::routerLSAs [private] |
Referenced by AgeDatabase(), detailedInfo(), GetRouterLSA(), GetRouterLSACount(), InstallRouterLSA(), and ~Area().
std::map<LinkStateID, NetworkLSA*> OSPF::Area::networkLSAsByID [private] |
Referenced by AgeDatabase(), FindNetworkLSA(), and InstallNetworkLSA().
std::vector<NetworkLSA*> OSPF::Area::networkLSAs [private] |
Referenced by AgeDatabase(), detailedInfo(), GetNetworkLSA(), GetNetworkLSACount(), InstallNetworkLSA(), and ~Area().
std::map<LSAKeyType, SummaryLSA*, LSAKeyType_Less> OSPF::Area::summaryLSAsByID [private] |
Referenced by AgeDatabase(), FindSummaryLSA(), and InstallSummaryLSA().
std::vector<SummaryLSA*> OSPF::Area::summaryLSAs [private] |
Referenced by AgeDatabase(), detailedInfo(), GetSummaryLSA(), GetSummaryLSACount(), InstallSummaryLSA(), and ~Area().
bool OSPF::Area::transitCapability [private] |
Referenced by detailedInfo(), GetTransitCapability(), and SetTransitCapability().
bool OSPF::Area::externalRoutingCapability [private] |
Metric OSPF::Area::stubDefaultCost [private] |
Referenced by detailedInfo(), GetStubDefaultCost(), and SetStubDefaultCost().
RouterLSA* OSPF::Area::spfTreeRoot [private] |
Referenced by CalculateNextHops(), GetSPFTreeRoot(), and SetSPFTreeRoot().
Router* OSPF::Area::parentRouter [private] |