INET Framework for OMNeT++/OMNEST
inet::ospfv2::Ospfv2Area Class Reference

#include <Ospfv2Area.h>

Inheritance diagram for inet::ospfv2::Ospfv2Area:

Public Member Functions

 Ospfv2Area (CrcMode crcMode, IInterfaceTable *ift, AreaId id=BACKBONE_AREAID)
 
virtual ~Ospfv2Area ()
 
void setAreaID (AreaId areaId)
 
AreaId getAreaID () const
 
void addAddressRange (Ipv4AddressRange addressRange, bool advertise)
 
unsigned int getAddressRangeCount () const
 
Ipv4AddressRange getAddressRange (unsigned int index) const
 
void addHostRoute (HostRouteParameters &hostRouteParameters)
 
void setTransitCapability (bool transit)
 
bool getTransitCapability () const
 
void setExternalRoutingCapability (bool flooded)
 
bool getExternalRoutingCapability () const
 
void setStubDefaultCost (Metric cost)
 
Metric getStubDefaultCost () const
 
void setSPFTreeRoot (RouterLsa *root)
 
RouterLsagetSPFTreeRoot ()
 
const RouterLsagetSPFTreeRoot () const
 
void setRouter (Router *router)
 
RoutergetRouter ()
 
const RoutergetRouter () const
 
unsigned long getRouterLSACount () const
 
RouterLsagetRouterLSA (unsigned long i)
 
const RouterLsagetRouterLSA (unsigned long i) const
 
unsigned long getNetworkLSACount () const
 
NetworkLsagetNetworkLSA (unsigned long i)
 
const NetworkLsagetNetworkLSA (unsigned long i) const
 
unsigned long getSummaryLSACount () const
 
SummaryLsagetSummaryLSA (unsigned long i)
 
const SummaryLsagetSummaryLSA (unsigned long i) const
 
bool containsAddress (Ipv4Address address) const
 
bool hasAddressRange (Ipv4AddressRange addressRange) const
 
void addWatches ()
 
Ipv4AddressRange getContainingAddressRange (Ipv4AddressRange addressRange, bool *advertise=nullptr) const
 
void addInterface (Ospfv2Interface *intf)
 
int getInterfaceCount () const
 
Ospfv2InterfacegetInterface (unsigned char ifIndex)
 
Ospfv2InterfacegetInterface (Ipv4Address address)
 
std::vector< int > getInterfaceIndices ()
 
bool hasVirtualLink (AreaId withTransitArea) const
 
Ospfv2InterfacefindVirtualLink (RouterId routerID)
 
bool installRouterLSA (const Ospfv2RouterLsa *lsa)
 
bool installNetworkLSA (const Ospfv2NetworkLsa *lsa)
 
bool installSummaryLSA (const Ospfv2SummaryLsa *lsa)
 
RouterLsafindRouterLSA (LinkStateId linkStateID)
 
const RouterLsafindRouterLSA (LinkStateId linkStateID) const
 
NetworkLsafindNetworkLSA (LinkStateId linkStateID)
 
const NetworkLsafindNetworkLSA (LinkStateId linkStateID) const
 
SummaryLsafindSummaryLSA (LsaKeyType lsaKey)
 
const SummaryLsafindSummaryLSA (LsaKeyType lsaKey) const
 
void ageDatabase ()
 
bool hasAnyNeighborInStates (int states) const
 
void removeFromAllRetransmissionLists (LsaKeyType lsaKey)
 
bool isOnAnyRetransmissionList (LsaKeyType lsaKey) const
 
bool floodLSA (const Ospfv2Lsa *lsa, Ospfv2Interface *intf=nullptr, Neighbor *neighbor=nullptr)
 
bool isLocalAddress (Ipv4Address address) const
 
RouterLsaoriginateRouterLSA ()
 
NetworkLsaoriginateNetworkLSA (const Ospfv2Interface *intf)
 
SummaryLsaoriginateSummaryLSA (const Ospfv2RoutingTableEntry *entry, const std::map< LsaKeyType, bool, LsaKeyType_Less > &originatedLSAs, SummaryLsa *&lsaToReoriginate)
 
SummaryLsaoriginateSummaryLSA_Stub ()
 
void calculateShortestPathTree (std::vector< Ospfv2RoutingTableEntry * > &newRoutingTable)
 
void calculateInterAreaRoutes (std::vector< Ospfv2RoutingTableEntry * > &newRoutingTable)
 
void recheckSummaryLSAs (std::vector< Ospfv2RoutingTableEntry * > &newRoutingTable)
 
std::string str () const override
 
std::string info () const
 
std::string detailedInfo () const
 

Private Member Functions

SummaryLsaoriginateSummaryLSA (const SummaryLsa *summaryLSA)
 
bool hasLink (Ospfv2Lsa *fromLSA, Ospfv2Lsa *toLSA) const
 
std::vector< NextHop > * calculateNextHops (Ospfv2Lsa *destination, Ospfv2Lsa *parent) const
 
std::vector< NextHop > * calculateNextHops (const Ospfv2Link &destination, Ospfv2Lsa *parent) const
 
LinkStateId getUniqueLinkStateID (Ipv4AddressRange destination, Metric destinationCost, SummaryLsa *&lsaToReoriginate) const
 Returns a link state ID for the input destination. More...
 
bool findSameOrWorseCostRoute (const std::vector< Ospfv2RoutingTableEntry * > &newRoutingTable, const SummaryLsa &currentLSA, unsigned short currentCost, bool &destinationInRoutingTable, std::list< Ospfv2RoutingTableEntry * > &sameOrWorseCost) const
 Browse through the newRoutingTable looking for entries describing the same destination as the currentLSA. More...
 
Ospfv2RoutingTableEntrycreateRoutingTableEntryFromSummaryLSA (const SummaryLsa &summaryLSA, unsigned short entryCost, const Ospfv2RoutingTableEntry &borderRouterEntry) const
 Returns a new Ospfv2RoutingTableEntry based on the input SummaryLsa, with the input cost and the borderRouterEntry's next hops. More...
 
void printLSDB ()
 
void printSummaryLsa ()
 
bool isDefaultRoute (Ospfv2RoutingTableEntry *entry) const
 
bool isAllZero (Ipv4AddressRange entry) const
 

Private Attributes

CrcMode crcMode
 
IInterfaceTableift
 
AreaId areaID
 
std::map< Ipv4AddressRange, bool > advertiseAddressRanges
 
std::vector< Ipv4AddressRangeareaAddressRanges
 
std::vector< Ospfv2Interface * > associatedInterfaces
 
std::vector< HostRouteParametershostRoutes
 
std::map< LinkStateId, RouterLsa * > routerLSAsByID
 
std::vector< RouterLsa * > routerLSAs
 
std::map< LinkStateId, NetworkLsa * > networkLSAsByID
 
std::vector< NetworkLsa * > networkLSAs
 
std::map< LsaKeyType, SummaryLsa *, LsaKeyType_LesssummaryLSAsByID
 
std::vector< SummaryLsa * > summaryLSAs
 
bool transitCapability
 
bool externalRoutingCapability
 
Metric stubDefaultCost
 
RouterLsaspfTreeRoot
 
RouterparentRouter
 

Constructor & Destructor Documentation

◆ Ospfv2Area()

inet::ospfv2::Ospfv2Area::Ospfv2Area ( CrcMode  crcMode,
IInterfaceTable ift,
AreaId  id = BACKBONE_AREAID 
)
19  :
21  ift(ift),
22  areaID(id),
23  transitCapability(false),
25  stubDefaultCost(1),
26  spfTreeRoot(nullptr),
27  parentRouter(nullptr)
28 {
29 }

◆ ~Ospfv2Area()

inet::ospfv2::Ospfv2Area::~Ospfv2Area ( )
virtual
32 {
33  for (auto interface : associatedInterfaces)
34  delete interface;
35  associatedInterfaces.clear();
36 
37  for (auto routerLSA : routerLSAs)
38  delete routerLSA;
39  routerLSAs.clear();
40 
41  for (auto networkLSA : networkLSAs)
42  delete networkLSA;
43  networkLSAs.clear();
44 
45  for (auto summaryLSA : summaryLSAs)
46  delete summaryLSA;
47  summaryLSAs.clear();
48 }

Member Function Documentation

◆ addAddressRange()

void inet::ospfv2::Ospfv2Area::addAddressRange ( Ipv4AddressRange  addressRange,
bool  advertise 
)
65 {
66  int addressRangeNum = areaAddressRanges.size();
67  bool found = false;
68  bool erased = false;
69 
70  for (int i = 0; i < addressRangeNum; i++) {
71  Ipv4AddressRange curRange = areaAddressRanges[i];
72  if (curRange.contains(addressRange)) { // contains or same
73  found = true;
74  if (advertiseAddressRanges[curRange] != advertise) {
75  throw cRuntimeError("Inconsistent advertise settings for %s and %s address ranges in area %s",
76  addressRange.str().c_str(), curRange.str().c_str(), areaID.str(false).c_str());
77  }
78  }
79  else if (addressRange.contains(curRange)) {
80  if (advertiseAddressRanges[curRange] != advertise) {
81  throw cRuntimeError("Inconsistent advertise settings for %s and %s address ranges in area %s",
82  addressRange.str().c_str(), curRange.str().c_str(), areaID.str(false).c_str());
83  }
84  advertiseAddressRanges.erase(curRange);
86  erased = true;
87  }
88  }
89  if (erased && found) // the found entry contains new entry and new entry contains erased entry ==> the found entry also contains the erased entry
90  throw cRuntimeError("Model error: bad contents in areaAddressRanges vector");
91  if (erased) {
92  auto it = areaAddressRanges.begin();
93  while (it != areaAddressRanges.end()) {
94  if (*it == NULL_IPV4ADDRESSRANGE)
95  it = areaAddressRanges.erase(it);
96  else
97  it++;
98  }
99  }
100  if (!found) {
101  areaAddressRanges.push_back(addressRange);
102  advertiseAddressRanges[addressRange] = advertise;
103  }
104 }

Referenced by inet::ospfv2::Ospfv2ConfigReader::loadAreaFromXML().

◆ addHostRoute()

void inet::ospfv2::Ospfv2Area::addHostRoute ( HostRouteParameters hostRouteParameters)
inline

◆ addInterface()

void inet::ospfv2::Ospfv2Area::addInterface ( Ospfv2Interface intf)

◆ addWatches()

void inet::ospfv2::Ospfv2Area::addWatches ( )
51 {
52  WATCH_PTRVECTOR(routerLSAs);
53  WATCH_PTRVECTOR(networkLSAs);
54  WATCH_PTRVECTOR(summaryLSAs);
55  WATCH_PTRVECTOR(associatedInterfaces);
56 }

Referenced by inet::ospfv2::Ospfv2ConfigReader::loadAreaFromXML().

◆ ageDatabase()

void inet::ospfv2::Ospfv2Area::ageDatabase ( )
365 {
366  bool shouldRebuildRoutingTable = false;
367 
368  for (uint32_t i = 0; i < routerLSAs.size(); i++) {
369  RouterLsa *lsa = routerLSAs[i];
370  unsigned short lsAge = lsa->getHeader().getLsAge();
371  bool selfOriginated = (lsa->getHeader().getAdvertisingRouter() == parentRouter->getRouterID());
372  bool unreachable = parentRouter->isDestinationUnreachable(lsa);
373 
374  if ((selfOriginated && (lsAge < (LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) {
375  lsa->getHeaderForUpdate().setLsAge(lsAge + 1);
376  if ((lsAge + 1) % CHECK_AGE == 0) {
377  if (!lsa->validateLSChecksum()) {
378  EV_ERROR << "Invalid LS checksum. Memory error detected!\n";
379  }
380  }
381  lsa->incrementInstallTime();
382  }
383  if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))) {
384  if (unreachable) {
385  lsa->getHeaderForUpdate().setLsAge(MAX_AGE);
386  floodLSA(lsa);
387  lsa->incrementInstallTime();
388  }
389  else {
390  long sequenceNumber = lsa->getHeader().getLsSequenceNumber();
391  if (sequenceNumber == MAX_SEQUENCE_NUMBER) {
392  lsa->getHeaderForUpdate().setLsAge(MAX_AGE);
393  floodLSA(lsa);
394  lsa->incrementInstallTime();
395  }
396  else {
397  RouterLsa *newLSA = originateRouterLSA();
398 
399  newLSA->getHeaderForUpdate().setLsSequenceNumber(sequenceNumber + 1);
400  shouldRebuildRoutingTable |= lsa->update(newLSA);
401  delete newLSA;
402 
403  floodLSA(lsa);
404  }
405  }
406  }
407  if (!selfOriginated && (lsAge == MAX_AGE - 1)) {
408  lsa->getHeaderForUpdate().setLsAge(MAX_AGE);
409  floodLSA(lsa);
410  lsa->incrementInstallTime();
411  }
412  if (lsAge == MAX_AGE) {
413  LsaKeyType lsaKey;
414 
415  lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
416  lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter();
417 
418  if (!isOnAnyRetransmissionList(lsaKey) &&
420  {
421  if (!selfOriginated || unreachable) {
422  routerLSAsByID.erase(lsa->getHeader().getLinkStateID());
423  delete lsa;
424  routerLSAs[i] = nullptr;
425  shouldRebuildRoutingTable = true;
426  }
427  else {
428  RouterLsa *newLSA = originateRouterLSA();
429  long sequenceNumber = lsa->getHeader().getLsSequenceNumber();
430 
431  newLSA->getHeaderForUpdate().setLsSequenceNumber((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1);
432  shouldRebuildRoutingTable |= lsa->update(newLSA);
433  delete newLSA;
434 
435  floodLSA(lsa);
436  }
437  }
438  }
439  }
440 
441  auto routerIt = routerLSAs.begin();
442  while (routerIt != routerLSAs.end()) {
443  if ((*routerIt) == nullptr) {
444  routerIt = routerLSAs.erase(routerIt);
445  }
446  else {
447  routerIt++;
448  }
449  }
450 
451  for (uint32_t i = 0; i < networkLSAs.size(); i++) {
452  unsigned short lsAge = networkLSAs[i]->getHeader().getLsAge();
453  bool unreachable = parentRouter->isDestinationUnreachable(networkLSAs[i]);
454  NetworkLsa *lsa = networkLSAs[i];
455  Ospfv2Interface *localIntf = getInterface(lsa->getHeader().getLinkStateID());
456  bool selfOriginated = false;
457 
458  if ((localIntf != nullptr) &&
459  (localIntf->getState() == Ospfv2Interface::DESIGNATED_ROUTER_STATE) &&
460  (localIntf->getNeighborCount() > 0) &&
461  (localIntf->hasAnyNeighborInStates(Neighbor::FULL_STATE)))
462  {
463  selfOriginated = true;
464  }
465 
466  if ((selfOriginated && (lsAge < (LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) {
467  lsa->getHeaderForUpdate().setLsAge(lsAge + 1);
468  if ((lsAge + 1) % CHECK_AGE == 0) {
469  if (!lsa->validateLSChecksum()) {
470  EV_ERROR << "Invalid LS checksum. Memory error detected!\n";
471  }
472  }
473  lsa->incrementInstallTime();
474  }
475  if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))) {
476  if (unreachable) {
477  lsa->getHeaderForUpdate().setLsAge(MAX_AGE);
478  floodLSA(lsa);
479  lsa->incrementInstallTime();
480  }
481  else {
482  long sequenceNumber = lsa->getHeader().getLsSequenceNumber();
483  if (sequenceNumber == MAX_SEQUENCE_NUMBER) {
484  lsa->getHeaderForUpdate().setLsAge(MAX_AGE);
485  floodLSA(lsa);
486  lsa->incrementInstallTime();
487  }
488  else {
489  NetworkLsa *newLSA = originateNetworkLSA(localIntf);
490 
491  if (newLSA != nullptr) {
492  newLSA->getHeaderForUpdate().setLsSequenceNumber(sequenceNumber + 1);
493  shouldRebuildRoutingTable |= lsa->update(newLSA);
494  delete newLSA;
495  }
496  else { // no neighbors on the network -> old NetworkLsa must be flushed
497  lsa->getHeaderForUpdate().setLsAge(MAX_AGE);
498  lsa->incrementInstallTime();
499  }
500 
501  floodLSA(lsa);
502  }
503  }
504  }
505  if (!selfOriginated && (lsAge == MAX_AGE - 1)) {
506  lsa->getHeaderForUpdate().setLsAge(MAX_AGE);
507  floodLSA(lsa);
508  lsa->incrementInstallTime();
509  }
510  if (lsAge == MAX_AGE) {
511  LsaKeyType lsaKey;
512 
513  lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
514  lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter();
515 
516  if (!isOnAnyRetransmissionList(lsaKey) &&
518  {
519  if (!selfOriginated || unreachable) {
520  networkLSAsByID.erase(lsa->getHeader().getLinkStateID());
521  delete lsa;
522  networkLSAs[i] = nullptr;
523  shouldRebuildRoutingTable = true;
524  }
525  else {
526  NetworkLsa *newLSA = originateNetworkLSA(localIntf);
527  long sequenceNumber = lsa->getHeader().getLsSequenceNumber();
528 
529  if (newLSA != nullptr) {
530  newLSA->getHeaderForUpdate().setLsSequenceNumber((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1);
531  shouldRebuildRoutingTable |= lsa->update(newLSA);
532  delete newLSA;
533 
534  floodLSA(lsa);
535  }
536  else { // no neighbors on the network -> old NetworkLsa must be deleted
537  delete networkLSAs[i];
538  }
539  }
540  }
541  }
542  }
543 
544  auto networkIt = networkLSAs.begin();
545  while (networkIt != networkLSAs.end()) {
546  if ((*networkIt) == nullptr) {
547  networkIt = networkLSAs.erase(networkIt);
548  }
549  else {
550  networkIt++;
551  }
552  }
553 
554  for (uint32_t i = 0; i < summaryLSAs.size(); i++) {
555  unsigned short lsAge = summaryLSAs[i]->getHeader().getLsAge();
556  bool selfOriginated = (summaryLSAs[i]->getHeader().getAdvertisingRouter() == parentRouter->getRouterID());
557  bool unreachable = parentRouter->isDestinationUnreachable(summaryLSAs[i]);
558  SummaryLsa *lsa = summaryLSAs[i];
559 
560  if ((selfOriginated && (lsAge < (LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) {
561  lsa->getHeaderForUpdate().setLsAge(lsAge + 1);
562  if ((lsAge + 1) % CHECK_AGE == 0) {
563  if (!lsa->validateLSChecksum()) {
564  EV_ERROR << "Invalid LS checksum. Memory error detected!\n";
565  }
566  }
567  lsa->incrementInstallTime();
568  }
569  if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))) {
570  if (unreachable) {
571  lsa->getHeaderForUpdate().setLsAge(MAX_AGE);
572  floodLSA(lsa);
573  lsa->incrementInstallTime();
574  }
575  else {
576  long sequenceNumber = lsa->getHeader().getLsSequenceNumber();
577  if (sequenceNumber == MAX_SEQUENCE_NUMBER) {
578  lsa->getHeaderForUpdate().setLsAge(MAX_AGE);
579  floodLSA(lsa);
580  lsa->incrementInstallTime();
581  }
582  else {
583  SummaryLsa *newLSA = originateSummaryLSA(lsa);
584 
585  if (newLSA != nullptr) {
586  newLSA->getHeaderForUpdate().setLsSequenceNumber(sequenceNumber + 1);
587  shouldRebuildRoutingTable |= lsa->update(newLSA);
588  delete newLSA;
589 
590  floodLSA(lsa);
591  }
592  else {
593  lsa->getHeaderForUpdate().setLsAge(MAX_AGE);
594  floodLSA(lsa);
595  lsa->incrementInstallTime();
596  }
597  }
598  }
599  }
600  if (!selfOriginated && (lsAge == MAX_AGE - 1)) {
601  lsa->getHeaderForUpdate().setLsAge(MAX_AGE);
602  floodLSA(lsa);
603  lsa->incrementInstallTime();
604  }
605  if (lsAge == MAX_AGE) {
606  LsaKeyType lsaKey;
607 
608  lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
609  lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter();
610 
611  if (!isOnAnyRetransmissionList(lsaKey) &&
613  {
614  if (!selfOriginated || unreachable) {
615  summaryLSAsByID.erase(lsaKey);
616  delete lsa;
617  summaryLSAs[i] = nullptr;
618  shouldRebuildRoutingTable = true;
619  }
620  else {
621  SummaryLsa *newLSA = originateSummaryLSA(lsa);
622  if (newLSA != nullptr) {
623  long sequenceNumber = lsa->getHeader().getLsSequenceNumber();
624 
625  newLSA->getHeaderForUpdate().setLsSequenceNumber((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1);
626  shouldRebuildRoutingTable |= lsa->update(newLSA);
627  delete newLSA;
628 
629  floodLSA(lsa);
630  }
631  else {
632  summaryLSAsByID.erase(lsaKey);
633  delete lsa;
634  summaryLSAs[i] = nullptr;
635  shouldRebuildRoutingTable = true;
636  }
637  }
638  }
639  }
640  }
641 
642  auto summaryIt = summaryLSAs.begin();
643  while (summaryIt != summaryLSAs.end()) {
644  if ((*summaryIt) == nullptr) {
645  summaryIt = summaryLSAs.erase(summaryIt);
646  }
647  else {
648  summaryIt++;
649  }
650  }
651 
652  for (uint32_t m = 0; m < associatedInterfaces.size(); m++)
653  associatedInterfaces[m]->ageTransmittedLsaLists();
654 
655  if (shouldRebuildRoutingTable)
657 }

◆ calculateInterAreaRoutes()

void inet::ospfv2::Ospfv2Area::calculateInterAreaRoutes ( std::vector< Ospfv2RoutingTableEntry * > &  newRoutingTable)
See also
RFC 2328 Section 16.2.
Todo:
This function does a lot of lookup in the input newRoutingTable. Restructuring the input vector into some kind of hash would quite probably speed up execution.
2291 {
2292  printSummaryLsa();
2293 
2294  for (uint32_t i = 0; i < summaryLSAs.size(); i++) {
2295  SummaryLsa *currentLSA = summaryLSAs[i];
2296  const Ospfv2LsaHeader& currentHeader = currentLSA->getHeader();
2297 
2298  unsigned long routeCost = currentLSA->getRouteCost();
2299  unsigned short lsAge = currentHeader.getLsAge();
2300  RouterId originatingRouter = currentHeader.getAdvertisingRouter();
2301  bool selfOriginated = (originatingRouter == parentRouter->getRouterID());
2302 
2303  if ((routeCost == LS_INFINITY) || (lsAge == MAX_AGE) || (selfOriginated)) { // (1) and(2)
2304  continue;
2305  }
2306 
2307  char lsType = currentHeader.getLsType();
2308  unsigned long routeCount = newRoutingTable.size();
2309  Ipv4AddressRange destination;
2310 
2311  destination.address = currentHeader.getLinkStateID();
2312  destination.mask = currentLSA->getNetworkMask();
2313 
2314  if ((lsType == SUMMARYLSA_NETWORKS_TYPE) && (parentRouter->hasAddressRange(destination))) { // (3)
2315  // look for an "Active" INTRAAREA route
2316  bool foundIntraAreaRoute = false;
2317  for (uint32_t j = 0; j < routeCount; j++) {
2318  Ospfv2RoutingTableEntry *routingEntry = newRoutingTable[j];
2319  if ((routingEntry->getDestinationType() == Ospfv2RoutingTableEntry::NETWORK_DESTINATION) &&
2320  (routingEntry->getPathType() == Ospfv2RoutingTableEntry::INTRAAREA) &&
2321  destination.containedByRange(routingEntry->getDestination(), routingEntry->getNetmask()))
2322  {
2323  foundIntraAreaRoute = true;
2324  break;
2325  }
2326  }
2327  if (foundIntraAreaRoute)
2328  continue;
2329  }
2330 
2331  Ospfv2RoutingTableEntry *borderRouterEntry = nullptr;
2332 
2333  // The routingEntry describes a route to an other area -> look for the border router originating it
2334  for (uint32_t j = 0; j < routeCount; j++) { // (4) N == destination, BR == borderRouterEntry
2335  Ospfv2RoutingTableEntry *routingEntry = newRoutingTable[j];
2336 
2337  if ((routingEntry->getArea() == areaID) &&
2338  (((routingEntry->getDestinationType() & Ospfv2RoutingTableEntry::AREA_BORDER_ROUTER_DESTINATION) != 0) ||
2339  ((routingEntry->getDestinationType() & Ospfv2RoutingTableEntry::AS_BOUNDARY_ROUTER_DESTINATION) != 0)) &&
2340  (routingEntry->getDestination() == originatingRouter))
2341  {
2342  borderRouterEntry = routingEntry;
2343  break;
2344  }
2345  }
2346  if (!borderRouterEntry)
2347  continue;
2348 
2349  /* (5) "this LSA describes an inter-area path to destination N,
2350  * whose cost is the distance to BR plus the cost specified in the LSA.
2351  * Call the cost of this inter-area path IAC."
2352  */
2353  bool destinationInRoutingTable = true;
2354  unsigned short currentCost = routeCost + borderRouterEntry->getCost();
2355  std::list<Ospfv2RoutingTableEntry *> sameOrWorseCost;
2356 
2357  if (findSameOrWorseCostRoute(newRoutingTable,
2358  *currentLSA,
2359  currentCost,
2360  destinationInRoutingTable,
2361  sameOrWorseCost))
2362  {
2363  continue;
2364  }
2365 
2366  if (destinationInRoutingTable && (sameOrWorseCost.size() > 0)) {
2367  Ospfv2RoutingTableEntry *equalEntry = nullptr;
2368 
2369  /* Look for an equal cost entry in the sameOrWorseCost list, and
2370  * also clear the more expensive entries from the newRoutingTable.
2371  */
2372  // FIXME The code does not work according to the comment
2373  for (auto checkedEntry : sameOrWorseCost) {
2374  if (checkedEntry->getCost() > currentCost) {
2375  for (auto entryIt = newRoutingTable.begin(); entryIt != newRoutingTable.end(); entryIt++) {
2376  if (checkedEntry == (*entryIt)) {
2377  delete *entryIt;
2378  newRoutingTable.erase(entryIt);
2379  break;
2380  }
2381  }
2382  }
2383  else { // EntryCost == currentCost
2384  equalEntry = checkedEntry; // should be only one - if there are more they are ignored
2385  }
2386  }
2387 
2388  unsigned long nextHopCount = borderRouterEntry->getNextHopCount();
2389 
2390  if (equalEntry != nullptr) {
2391  /* Add the next hops of the border router advertising this destination
2392  * to the equal entry.
2393  */
2394  for (unsigned long j = 0; j < nextHopCount; j++) {
2395  equalEntry->addNextHop(borderRouterEntry->getNextHop(j));
2396  }
2397  }
2398  else {
2399  Ospfv2RoutingTableEntry *newEntry = createRoutingTableEntryFromSummaryLSA(*currentLSA, currentCost, *borderRouterEntry);
2400  ASSERT(newEntry != nullptr);
2401  newRoutingTable.push_back(newEntry);
2402  }
2403  }
2404  else {
2405  Ospfv2RoutingTableEntry *newEntry = createRoutingTableEntryFromSummaryLSA(*currentLSA, currentCost, *borderRouterEntry);
2406  ASSERT(newEntry != nullptr);
2407  newRoutingTable.push_back(newEntry);
2408  }
2409  }
2410 }

Referenced by inet::ospfv2::Router::rebuildRoutingTable().

◆ calculateNextHops() [1/2]

std::vector< NextHop > * inet::ospfv2::Ospfv2Area::calculateNextHops ( const Ospfv2Link destination,
Ospfv2Lsa parent 
) const
private
2017 {
2018  std::vector<NextHop> *hops = new std::vector<NextHop>;
2019 
2020  RouterLsa *routerLSA = check_and_cast<RouterLsa *>(parent);
2021  if (routerLSA != spfTreeRoot) {
2022  for (uint32_t i = 0; i < routerLSA->getNextHopCount(); i++)
2023  hops->push_back(routerLSA->getNextHop(i));
2024  return hops;
2025  }
2026  else {
2027  for (auto interface : associatedInterfaces) {
2028  Ospfv2Interface::Ospfv2InterfaceType intfType = interface->getType();
2029 
2030  if ((intfType == Ospfv2Interface::POINTTOPOINT) ||
2031  ((intfType == Ospfv2Interface::VIRTUAL) &&
2032  (interface->getState() > Ospfv2Interface::LOOPBACK_STATE)))
2033  {
2034  Neighbor *neighbor = (interface->getNeighborCount() > 0) ? interface->getNeighbor(0) : nullptr;
2035  if (neighbor != nullptr) {
2036  Ipv4Address neighborAddress = neighbor->getAddress();
2037  if (((neighborAddress != NULL_IPV4ADDRESS) &&
2038  (neighborAddress == destination.getLinkID())) ||
2039  ((neighborAddress == NULL_IPV4ADDRESS) &&
2040  (interface->getAddressRange().address == destination.getLinkID()) &&
2041  (interface->getAddressRange().mask.getInt() == destination.getLinkData())))
2042  {
2043  NextHop nextHop;
2044  nextHop.ifIndex = interface->getIfIndex();
2045  nextHop.hopAddress = neighborAddress;
2046  nextHop.advertisingRouter = parentRouter->getRouterID();
2047  hops->push_back(nextHop);
2048  break;
2049  }
2050  }
2051  }
2052  if ((intfType == Ospfv2Interface::BROADCAST) ||
2053  (intfType == Ospfv2Interface::NBMA))
2054  {
2055  if (isSameNetwork(destination.getLinkID(), Ipv4Address(destination.getLinkData()), interface->getAddressRange().address, interface->getAddressRange().mask)) {
2056  NextHop nextHop;
2057  nextHop.ifIndex = interface->getIfIndex();
2058  if (interface->getNeighborCount() == 1) {
2059  Neighbor *neighbor = interface->getNeighbor(0);
2060  nextHop.hopAddress = neighbor->getAddress();
2061  }
2062  else
2063  nextHop.hopAddress = Ipv4Address::UNSPECIFIED_ADDRESS;
2064  nextHop.advertisingRouter = parentRouter->getRouterID();
2065  hops->push_back(nextHop);
2066  break;
2067  }
2068  }
2069  if (intfType == Ospfv2Interface::POINTTOMULTIPOINT) {
2070  if (destination.getType() == STUB_LINK) {
2071  if (destination.getLinkID() == interface->getAddressRange().address) {
2072  // The link contains the router's own interface address and a full mask,
2073  // so we insert a next hop pointing to the interface itself. Kind of pointless, but
2074  // not much else we could do...
2075  // TODO check what other OSPF implementations do in this situation
2076  NextHop nextHop;
2077  nextHop.ifIndex = interface->getIfIndex();
2078  nextHop.hopAddress = interface->getAddressRange().address;
2079  nextHop.advertisingRouter = parentRouter->getRouterID();
2080  hops->push_back(nextHop);
2081  break;
2082  }
2083  }
2084  if (destination.getType() == POINTTOPOINT_LINK) {
2085  Neighbor *neighbor = interface->getNeighborById(destination.getLinkID());
2086  if (neighbor != nullptr) {
2087  NextHop nextHop;
2088  nextHop.ifIndex = interface->getIfIndex();
2089  nextHop.hopAddress = neighbor->getAddress();
2090  nextHop.advertisingRouter = parentRouter->getRouterID();
2091  hops->push_back(nextHop);
2092  break;
2093  }
2094  }
2095  }
2096  // next hops for virtual links are generated later, after examining transit areas' SummaryLSAs
2097  }
2098 
2099  if (hops->size() == 0) {
2100  for (uint32_t i = 0; i < hostRoutes.size(); i++) {
2101  if ((destination.getLinkID() == hostRoutes[i].address) &&
2102  (destination.getLinkData() == 0xFFFFFFFF))
2103  {
2104  NextHop nextHop;
2105  nextHop.ifIndex = hostRoutes[i].ifIndex;
2106  nextHop.hopAddress = hostRoutes[i].address;
2107  nextHop.advertisingRouter = parentRouter->getRouterID();
2108  hops->push_back(nextHop);
2109  break;
2110  }
2111  }
2112  }
2113  }
2114 
2115  return hops;
2116 }

◆ calculateNextHops() [2/2]

std::vector< NextHop > * inet::ospfv2::Ospfv2Area::calculateNextHops ( Ospfv2Lsa destination,
Ospfv2Lsa parent 
) const
private
1890 {
1891  std::vector<NextHop> *hops = new std::vector<NextHop>;
1892 
1893  RouterLsa *routerLSA = dynamic_cast<RouterLsa *>(parent);
1894  if (routerLSA != nullptr) {
1895  if (routerLSA != spfTreeRoot) {
1896  for (uint32_t i = 0; i < routerLSA->getNextHopCount(); i++)
1897  hops->push_back(routerLSA->getNextHop(i));
1898  return hops;
1899  }
1900  else {
1901  RouterLsa *destinationRouterLSA = dynamic_cast<RouterLsa *>(destination);
1902  if (destinationRouterLSA != nullptr) {
1903  for (auto interface : associatedInterfaces) {
1904  Ospfv2Interface::Ospfv2InterfaceType intfType = interface->getType();
1905  if ((intfType == Ospfv2Interface::POINTTOPOINT) ||
1906  ((intfType == Ospfv2Interface::VIRTUAL) &&
1907  (interface->getState() > Ospfv2Interface::LOOPBACK_STATE)))
1908  {
1909  Neighbor *ptpNeighbor = interface->getNeighborCount() > 0 ? interface->getNeighbor(0) : nullptr;
1910  if (ptpNeighbor != nullptr) {
1911  if (ptpNeighbor->getNeighborID() == destinationRouterLSA->getHeader().getLinkStateID()) {
1912  NextHop nextHop;
1913  nextHop.ifIndex = interface->getIfIndex();
1914  nextHop.hopAddress = ptpNeighbor->getAddress();
1915  nextHop.advertisingRouter = destinationRouterLSA->getHeader().getAdvertisingRouter();
1916  hops->push_back(nextHop);
1917  break;
1918  }
1919  }
1920  }
1921  if (intfType == Ospfv2Interface::POINTTOMULTIPOINT) {
1922  Neighbor *ptmpNeighbor = interface->getNeighborById(destinationRouterLSA->getHeader().getLinkStateID());
1923  if (ptmpNeighbor != nullptr) {
1924  unsigned int linkCount = destinationRouterLSA->getLinksArraySize();
1925  Ipv4Address rootID = Ipv4Address(parentRouter->getRouterID());
1926  for (uint32_t j = 0; j < linkCount; j++) {
1927  const auto& link = destinationRouterLSA->getLinks(j);
1928  if (link.getLinkID() == rootID) {
1929  NextHop nextHop;
1930  nextHop.ifIndex = interface->getIfIndex();
1931  nextHop.hopAddress = Ipv4Address(link.getLinkData());
1932  nextHop.advertisingRouter = destinationRouterLSA->getHeader().getAdvertisingRouter();
1933  hops->push_back(nextHop);
1934  }
1935  }
1936  break;
1937  }
1938  }
1939  }
1940  }
1941  else {
1942  NetworkLsa *destinationNetworkLSA = dynamic_cast<NetworkLsa *>(destination);
1943  if (destinationNetworkLSA != nullptr) {
1944  Ipv4Address networkDesignatedRouter = destinationNetworkLSA->getHeader().getLinkStateID();
1945  for (auto interface : associatedInterfaces) {
1946  Ospfv2Interface::Ospfv2InterfaceType intfType = interface->getType();
1947  if (((intfType == Ospfv2Interface::BROADCAST) ||
1948  (intfType == Ospfv2Interface::NBMA)) &&
1949  (interface->getDesignatedRouter().ipInterfaceAddress == networkDesignatedRouter))
1950  {
1951  Ipv4AddressRange range = interface->getAddressRange();
1952  NextHop nextHop;
1953  nextHop.ifIndex = interface->getIfIndex();
1954  if (interface->getNeighborCount() == 1) {
1955  Neighbor *neighbor = interface->getNeighbor(0);
1956  nextHop.hopAddress = neighbor->getAddress();
1957  }
1958  else
1959  nextHop.hopAddress = Ipv4Address::UNSPECIFIED_ADDRESS;
1960  nextHop.advertisingRouter = destinationNetworkLSA->getHeader().getAdvertisingRouter();
1961  hops->push_back(nextHop);
1962  }
1963  }
1964  }
1965  }
1966  }
1967  }
1968  else {
1969  NetworkLsa *networkLSA = dynamic_cast<NetworkLsa *>(parent);
1970  if (networkLSA != nullptr) {
1971  if (networkLSA->getParent() != spfTreeRoot) {
1972  for (uint32_t i = 0; i < networkLSA->getNextHopCount(); i++)
1973  hops->push_back(networkLSA->getNextHop(i));
1974  return hops;
1975  }
1976  else {
1977  Ipv4Address parentLinkStateID = parent->getHeader().getLinkStateID();
1978 
1979  RouterLsa *destinationRouterLSA = dynamic_cast<RouterLsa *>(destination);
1980  if (destinationRouterLSA != nullptr) {
1981  RouterId destinationRouterID = destinationRouterLSA->getHeader().getLinkStateID();
1982  for (uint32_t i = 0; i < destinationRouterLSA->getLinksArraySize(); i++) {
1983  const auto& link = destinationRouterLSA->getLinks(i);
1984  NextHop nextHop;
1985 
1986  if (((link.getType() == TRANSIT_LINK) &&
1987  (link.getLinkID() == parentLinkStateID)) ||
1988  ((link.getType() == STUB_LINK) &&
1989  ((link.getLinkID() & Ipv4Address(link.getLinkData())) == (parentLinkStateID & networkLSA->getNetworkMask()))))
1990  {
1991  for (auto interface : associatedInterfaces) {
1992  Ospfv2Interface::Ospfv2InterfaceType intfType = interface->getType();
1993  if (((intfType == Ospfv2Interface::BROADCAST) ||
1994  (intfType == Ospfv2Interface::NBMA)) &&
1995  (interface->getDesignatedRouter().ipInterfaceAddress == parentLinkStateID))
1996  {
1997  Neighbor *nextHopNeighbor = interface->getNeighborById(destinationRouterID);
1998  if (nextHopNeighbor != nullptr) {
1999  nextHop.ifIndex = interface->getIfIndex();
2000  nextHop.hopAddress = nextHopNeighbor->getAddress();
2001  nextHop.advertisingRouter = destinationRouterLSA->getHeader().getAdvertisingRouter();
2002  hops->push_back(nextHop);
2003  }
2004  }
2005  }
2006  }
2007  }
2008  }
2009  }
2010  }
2011  }
2012 
2013  return hops;
2014 }

Referenced by calculateShortestPathTree().

◆ calculateShortestPathTree()

void inet::ospfv2::Ospfv2Area::calculateShortestPathTree ( std::vector< Ospfv2RoutingTableEntry * > &  newRoutingTable)
1400 {
1401  bool finished = false;
1402  std::vector<Ospfv2Lsa *> treeVertices;
1403  Ospfv2Lsa *justAddedVertex;
1404  std::vector<Ospfv2Lsa *> candidateVertices;
1405 
1406  printLSDB();
1407 
1408  if (spfTreeRoot == nullptr) {
1409  RouterLsa *newLSA = originateRouterLSA();
1410 
1411  installRouterLSA(newLSA);
1412 
1413  RouterLsa *routerLSA = findRouterLSA(parentRouter->getRouterID());
1414 
1415  spfTreeRoot = routerLSA;
1416  floodLSA(newLSA);
1417  delete newLSA;
1418  }
1419 
1420  if (spfTreeRoot == nullptr)
1421  return;
1422 
1423  for (uint32_t i = 0; i < routerLSAs.size(); i++)
1424  routerLSAs[i]->clearNextHops();
1425 
1426  for (uint32_t i = 0; i < networkLSAs.size(); i++)
1427  networkLSAs[i]->clearNextHops();
1428 
1430  treeVertices.push_back(spfTreeRoot);
1431  justAddedVertex = spfTreeRoot; // (1)
1432 
1433  do {
1434  auto vertexType = static_cast<Ospfv2LsaType>(justAddedVertex->getHeader().getLsType());
1435 
1436  if (vertexType == ROUTERLSA_TYPE) {
1437  RouterLsa *routerVertex = check_and_cast<RouterLsa *>(justAddedVertex);
1438  if (routerVertex->getV_VirtualLinkEndpoint()) { // (2)
1439  transitCapability = true;
1440  }
1441 
1442  unsigned int linkCount = routerVertex->getLinksArraySize();
1443  for (uint32_t i = 0; i < linkCount; i++) {
1444  const auto& link = routerVertex->getLinks(i);
1445  LinkType linkType = static_cast<LinkType>(link.getType());
1446  Ospfv2Lsa *joiningVertex;
1447  Ospfv2LsaType joiningVertexType;
1448 
1449  if (linkType == STUB_LINK) { // (2) (a)
1450  continue;
1451  }
1452 
1453  if (linkType == TRANSIT_LINK) {
1454  joiningVertex = findNetworkLSA(link.getLinkID());
1455  joiningVertexType = NETWORKLSA_TYPE;
1456  }
1457  else {
1458  joiningVertex = findRouterLSA(link.getLinkID());
1459  joiningVertexType = ROUTERLSA_TYPE;
1460  }
1461 
1462  if ((joiningVertex == nullptr) ||
1463  (joiningVertex->getHeader().getLsAge() == MAX_AGE) ||
1464  (!hasLink(joiningVertex, justAddedVertex))) // (from, to) (2) (b)
1465  {
1466  continue;
1467  }
1468 
1469  unsigned int treeSize = treeVertices.size();
1470  bool alreadyOnTree = false;
1471 
1472  for (uint32_t j = 0; j < treeSize; j++) {
1473  if (treeVertices[j] == joiningVertex) {
1474  alreadyOnTree = true;
1475  break;
1476  }
1477  }
1478  if (alreadyOnTree) { // (2) (c)
1479  continue;
1480  }
1481 
1482  unsigned long linkStateCost = routerVertex->getDistance() + link.getLinkCost();
1483  unsigned int candidateCount = candidateVertices.size();
1484  Ospfv2Lsa *candidate = nullptr;
1485 
1486  for (uint32_t j = 0; j < candidateCount; j++) {
1487  if (candidateVertices[j] == joiningVertex) {
1488  candidate = candidateVertices[j];
1489  }
1490  }
1491  if (candidate != nullptr) { // (2) (d)
1492  RoutingInfo *routingInfo = check_and_cast<RoutingInfo *>(candidate);
1493  unsigned long candidateDistance = routingInfo->getDistance();
1494 
1495  if (linkStateCost > candidateDistance) {
1496  continue;
1497  }
1498  if (linkStateCost < candidateDistance) {
1499  routingInfo->setDistance(linkStateCost);
1500  routingInfo->clearNextHops();
1501  }
1502  std::vector<NextHop> *newNextHops = calculateNextHops(joiningVertex, justAddedVertex); // (destination, parent)
1503  for (auto it = newNextHops->begin(); it != newNextHops->end(); ++it)
1504  routingInfo->addNextHop(*it);
1505  delete newNextHops;
1506  }
1507  else {
1508  if (joiningVertexType == ROUTERLSA_TYPE) {
1509  RouterLsa *joiningRouterVertex = check_and_cast<RouterLsa *>(joiningVertex);
1510  joiningRouterVertex->setDistance(linkStateCost);
1511  std::vector<NextHop> *newNextHops = calculateNextHops(joiningVertex, justAddedVertex); // (destination, parent)
1512  for (auto it = newNextHops->begin(); it != newNextHops->end(); ++it)
1513  joiningRouterVertex->addNextHop(*it);
1514  delete newNextHops;
1515  RoutingInfo *vertexRoutingInfo = check_and_cast<RoutingInfo *>(joiningRouterVertex);
1516  vertexRoutingInfo->setParent(justAddedVertex);
1517 
1518  candidateVertices.push_back(joiningRouterVertex);
1519  }
1520  else {
1521  NetworkLsa *joiningNetworkVertex = check_and_cast<NetworkLsa *>(joiningVertex);
1522  joiningNetworkVertex->setDistance(linkStateCost);
1523  std::vector<NextHop> *newNextHops = calculateNextHops(joiningVertex, justAddedVertex); // (destination, parent)
1524  for (auto it = newNextHops->begin(); it != newNextHops->end(); ++it)
1525  joiningNetworkVertex->addNextHop(*it);
1526  delete newNextHops;
1527  RoutingInfo *vertexRoutingInfo = check_and_cast<RoutingInfo *>(joiningNetworkVertex);
1528  vertexRoutingInfo->setParent(justAddedVertex);
1529 
1530  candidateVertices.push_back(joiningNetworkVertex);
1531  }
1532  }
1533  }
1534  }
1535 
1536  if (vertexType == NETWORKLSA_TYPE) {
1537  NetworkLsa *networkVertex = check_and_cast<NetworkLsa *>(justAddedVertex);
1538  unsigned int routerCount = networkVertex->getAttachedRoutersArraySize();
1539 
1540  for (uint32_t i = 0; i < routerCount; i++) { // (2)
1541  RouterLsa *joiningVertex = findRouterLSA(networkVertex->getAttachedRouters(i));
1542  if ((joiningVertex == nullptr) ||
1543  (joiningVertex->getHeader().getLsAge() == MAX_AGE) ||
1544  (!hasLink(joiningVertex, justAddedVertex))) // (from, to) (2) (b)
1545  {
1546  continue;
1547  }
1548 
1549  unsigned int treeSize = treeVertices.size();
1550  bool alreadyOnTree = false;
1551 
1552  for (uint32_t j = 0; j < treeSize; j++) {
1553  if (treeVertices[j] == joiningVertex) {
1554  alreadyOnTree = true;
1555  break;
1556  }
1557  }
1558  if (alreadyOnTree) { // (2) (c)
1559  continue;
1560  }
1561 
1562  unsigned long linkStateCost = networkVertex->getDistance(); // link cost from network to router is always 0
1563  unsigned int candidateCount = candidateVertices.size();
1564  Ospfv2Lsa *candidate = nullptr;
1565 
1566  for (uint32_t j = 0; j < candidateCount; j++) {
1567  if (candidateVertices[j] == joiningVertex) {
1568  candidate = candidateVertices[j];
1569  }
1570  }
1571  if (candidate != nullptr) { // (2) (d)
1572  RoutingInfo *routingInfo = check_and_cast<RoutingInfo *>(candidate);
1573  unsigned long candidateDistance = routingInfo->getDistance();
1574 
1575  if (linkStateCost > candidateDistance) {
1576  continue;
1577  }
1578  if (linkStateCost < candidateDistance) {
1579  routingInfo->setDistance(linkStateCost);
1580  routingInfo->clearNextHops();
1581  }
1582  std::vector<NextHop> *newNextHops = calculateNextHops(joiningVertex, justAddedVertex); // (destination, parent)
1583  for (auto it = newNextHops->begin(); it != newNextHops->end(); ++it)
1584  routingInfo->addNextHop(*it);
1585  delete newNextHops;
1586  }
1587  else {
1588  joiningVertex->setDistance(linkStateCost);
1589  std::vector<NextHop> *newNextHops = calculateNextHops(joiningVertex, justAddedVertex); // (destination, parent)
1590  for (auto it = newNextHops->begin(); it != newNextHops->end(); ++it)
1591  joiningVertex->addNextHop(*it);
1592  delete newNextHops;
1593  RoutingInfo *vertexRoutingInfo = check_and_cast<RoutingInfo *>(joiningVertex);
1594  vertexRoutingInfo->setParent(justAddedVertex);
1595 
1596  candidateVertices.push_back(joiningVertex);
1597  }
1598  }
1599  }
1600 
1601  if (candidateVertices.empty()) { // (3)
1602  finished = true;
1603  }
1604  else {
1605  unsigned int candidateCount = candidateVertices.size();
1606  unsigned long minDistance = LS_INFINITY;
1607  Ospfv2Lsa *closestVertex = candidateVertices[0];
1608 
1609  for (uint32_t i = 0; i < candidateCount; i++) {
1610  RoutingInfo *routingInfo = check_and_cast<RoutingInfo *>(candidateVertices[i]);
1611  unsigned long currentDistance = routingInfo->getDistance();
1612 
1613  if (currentDistance < minDistance) {
1614  closestVertex = candidateVertices[i];
1615  minDistance = currentDistance;
1616  }
1617  else {
1618  if (currentDistance == minDistance) {
1619  if ((closestVertex->getHeader().getLsType() == ROUTERLSA_TYPE) &&
1620  (candidateVertices[i]->getHeader().getLsType() == NETWORKLSA_TYPE))
1621  {
1622  closestVertex = candidateVertices[i];
1623  }
1624  }
1625  }
1626  }
1627 
1628  treeVertices.push_back(closestVertex);
1629 
1630  for (auto it = candidateVertices.begin(); it != candidateVertices.end(); it++) {
1631  if ((*it) == closestVertex) {
1632  candidateVertices.erase(it);
1633  break;
1634  }
1635  }
1636 
1637  if (closestVertex->getHeader().getLsType() == ROUTERLSA_TYPE) {
1638  RouterLsa *routerLSA = check_and_cast<RouterLsa *>(closestVertex);
1639  if (routerLSA->getB_AreaBorderRouter() || routerLSA->getE_ASBoundaryRouter()) {
1640  Ospfv2RoutingTableEntry *entry = new Ospfv2RoutingTableEntry(ift);
1641  RouterId destinationID = routerLSA->getHeader().getLinkStateID();
1642  unsigned int nextHopCount = routerLSA->getNextHopCount();
1644 
1645  entry->setDestination(destinationID);
1646  entry->setLinkStateOrigin(routerLSA);
1647  entry->setArea(areaID);
1648  entry->setPathType(Ospfv2RoutingTableEntry::INTRAAREA);
1649  entry->setCost(routerLSA->getDistance());
1650  if (routerLSA->getB_AreaBorderRouter()) {
1652  }
1653  if (routerLSA->getE_ASBoundaryRouter()) {
1655  }
1656  entry->setDestinationType(destinationType);
1657  entry->setOptionalCapabilities(routerLSA->getHeader().getLsOptions());
1658  for (uint32_t i = 0; i < nextHopCount; i++) {
1659  entry->addNextHop(routerLSA->getNextHop(i));
1660  }
1661 
1662  newRoutingTable.push_back(entry);
1663 
1664  Ospfv2Area *backbone;
1665  if (areaID != BACKBONE_AREAID) {
1667  }
1668  else {
1669  backbone = this;
1670  }
1671  if (backbone != nullptr) {
1672  Ospfv2Interface *virtualIntf = backbone->findVirtualLink(destinationID);
1673  if ((virtualIntf != nullptr) && (virtualIntf->getTransitAreaId() == areaID)) {
1674  Ipv4AddressRange range;
1675  range.address = getInterface(routerLSA->getNextHop(0).ifIndex)->getAddressRange().address;
1676  range.mask = Ipv4Address::ALLONES_ADDRESS;
1677  virtualIntf->setAddressRange(range);
1678  virtualIntf->setIfIndex(ift, routerLSA->getNextHop(0).ifIndex);
1679  virtualIntf->setOutputCost(routerLSA->getDistance());
1680  Neighbor *virtualNeighbor = virtualIntf->getNeighbor(0);
1681  if (virtualNeighbor != nullptr) {
1682  unsigned int linkCount = routerLSA->getLinksArraySize();
1683  RouterLsa *toRouterLSA = dynamic_cast<RouterLsa *>(justAddedVertex);
1684  if (toRouterLSA != nullptr) {
1685  for (uint32_t i = 0; i < linkCount; i++) {
1686  const auto& link = routerLSA->getLinks(i);
1687 
1688  if ((link.getType() == POINTTOPOINT_LINK) &&
1689  (link.getLinkID() == toRouterLSA->getHeader().getLinkStateID()) &&
1690  (virtualIntf->getState() < Ospfv2Interface::WAITING_STATE))
1691  {
1692  virtualNeighbor->setAddress(Ipv4Address(link.getLinkData()));
1693  virtualIntf->processEvent(Ospfv2Interface::INTERFACE_UP);
1694  break;
1695  }
1696  }
1697  }
1698  else {
1699  NetworkLsa *toNetworkLSA = dynamic_cast<NetworkLsa *>(justAddedVertex);
1700  if (toNetworkLSA != nullptr) {
1701  for (uint32_t i = 0; i < linkCount; i++) {
1702  const auto& link = routerLSA->getLinks(i);
1703 
1704  if ((link.getType() == TRANSIT_LINK) &&
1705  (link.getLinkID() == toNetworkLSA->getHeader().getLinkStateID()) &&
1706  (virtualIntf->getState() < Ospfv2Interface::WAITING_STATE))
1707  {
1708  virtualNeighbor->setAddress(Ipv4Address(link.getLinkData()));
1709  virtualIntf->processEvent(Ospfv2Interface::INTERFACE_UP);
1710  break;
1711  }
1712  }
1713  }
1714  }
1715  }
1716  }
1717  }
1718  }
1719  }
1720 
1721  if (closestVertex->getHeader().getLsType() == NETWORKLSA_TYPE) {
1722  NetworkLsa *networkLSA = check_and_cast<NetworkLsa *>(closestVertex);
1723  Ipv4Address destinationID = (networkLSA->getHeader().getLinkStateID() & networkLSA->getNetworkMask());
1724  unsigned int nextHopCount = networkLSA->getNextHopCount();
1725  bool overWrite = false;
1726  Ospfv2RoutingTableEntry *entry = nullptr;
1727  unsigned long routeCount = newRoutingTable.size();
1728  Ipv4Address longestMatch(0u);
1729 
1730  for (uint32_t i = 0; i < routeCount; i++) {
1731  if (newRoutingTable[i]->getDestinationType() == Ospfv2RoutingTableEntry::NETWORK_DESTINATION) {
1732  Ospfv2RoutingTableEntry *routingEntry = newRoutingTable[i];
1733  Ipv4Address entryAddress = routingEntry->getDestination();
1734  Ipv4Address entryMask = routingEntry->getNetmask();
1735 
1736  if ((entryAddress & entryMask) == (destinationID & entryMask)) {
1737  if ((destinationID & entryMask) > longestMatch) {
1738  longestMatch = (destinationID & entryMask);
1739  entry = routingEntry;
1740  }
1741  }
1742  }
1743  }
1744  if (entry != nullptr) {
1745  const Ospfv2Lsa *entryOrigin = entry->getLinkStateOrigin();
1746  if ((entry->getCost() != networkLSA->getDistance()) ||
1747  (entryOrigin->getHeader().getLinkStateID() >= networkLSA->getHeader().getLinkStateID()))
1748  {
1749  overWrite = true;
1750  }
1751  }
1752 
1753  if ((entry == nullptr) || (overWrite)) {
1754  if (entry == nullptr) {
1755  entry = new Ospfv2RoutingTableEntry(ift);
1756  }
1757 
1758  entry->setDestination(Ipv4Address(destinationID));
1759  entry->setNetmask(networkLSA->getNetworkMask());
1760  entry->setLinkStateOrigin(networkLSA);
1761  entry->setArea(areaID);
1762  entry->setPathType(Ospfv2RoutingTableEntry::INTRAAREA);
1763  entry->setCost(networkLSA->getDistance());
1764  entry->setDestinationType(Ospfv2RoutingTableEntry::NETWORK_DESTINATION);
1765  entry->setOptionalCapabilities(networkLSA->getHeader().getLsOptions());
1766  for (uint32_t i = 0; i < nextHopCount; i++) {
1767  entry->addNextHop(networkLSA->getNextHop(i));
1768  }
1769 
1770  if (!overWrite) {
1771  newRoutingTable.push_back(entry);
1772  }
1773  }
1774  }
1775 
1776  justAddedVertex = closestVertex;
1777  }
1778  } while (!finished);
1779 
1780  // set parent to null for all router LSAs not on the SPF tree
1781  for (auto& routerLSA : routerLSAs) {
1782  bool onTree = false;
1783  for (auto& node : treeVertices) {
1784  if (node == routerLSA) {
1785  onTree = true;
1786  break;
1787  }
1788  }
1789  if (onTree)
1790  continue;
1791  else {
1792  routerLSA->setParent(nullptr);
1793  }
1794  }
1795  // set parent to null for all network LSAs not on the SPF tree
1796  for (auto& networkLSA : networkLSAs) {
1797  bool onTree = false;
1798  for (auto& node : treeVertices) {
1799  if (node == networkLSA) {
1800  onTree = true;
1801  break;
1802  }
1803  }
1804  if (onTree)
1805  continue;
1806  else {
1807  networkLSA->setParent(nullptr);
1808  }
1809  }
1810 
1811  for (uint32_t i = 0; i < treeVertices.size(); i++) {
1812  RouterLsa *routerVertex = dynamic_cast<RouterLsa *>(treeVertices[i]);
1813  if (routerVertex == nullptr)
1814  continue;
1815 
1816  for (uint32_t j = 0; j < routerVertex->getLinksArraySize(); j++) {
1817  const auto& link = routerVertex->getLinks(j);
1818  if (link.getType() != STUB_LINK)
1819  continue;
1820 
1821  unsigned long destinationID = (link.getLinkID().getInt() & link.getLinkData());
1822  Ospfv2RoutingTableEntry *entry = nullptr;
1823  unsigned long longestMatch = 0;
1824 
1825  for (auto routingEntry : newRoutingTable) {
1826  if (routingEntry->getDestinationType() == Ospfv2RoutingTableEntry::NETWORK_DESTINATION) {
1827  unsigned long entryAddress = routingEntry->getDestination().getInt();
1828  unsigned long entryMask = routingEntry->getNetmask().getInt();
1829 
1830  if ((entryAddress & entryMask) == (destinationID & entryMask)) {
1831  if ((destinationID & entryMask) > longestMatch) {
1832  longestMatch = (destinationID & entryMask);
1833  entry = routingEntry;
1834  }
1835  }
1836  }
1837  }
1838 
1839  unsigned long distance = routerVertex->getDistance() + link.getLinkCost();
1840 
1841  if (entry != nullptr) {
1842  Metric entryCost = entry->getCost();
1843 
1844  if (distance > entryCost)
1845  continue;
1846  else if (distance < entryCost) {
1847  entry->setCost(distance);
1848  entry->clearNextHops();
1849  entry->setLinkStateOrigin(routerVertex);
1850  }
1851  else if (distance == entryCost) {
1852  // no const version from check_and_cast
1853  const Ospfv2Lsa *lsOrigin = entry->getLinkStateOrigin();
1854  if (dynamic_cast<const RouterLsa *>(lsOrigin) || dynamic_cast<const NetworkLsa *>(lsOrigin)) {
1855  if (lsOrigin->getHeader().getLinkStateID() < routerVertex->getHeader().getLinkStateID())
1856  entry->setLinkStateOrigin(routerVertex);
1857  }
1858  else
1859  throw cRuntimeError("Can not cast class '%s' to RouterLsa or NetworkLsa", lsOrigin->getClassName());
1860  }
1861 
1862  std::vector<NextHop> *newNextHops = calculateNextHops(link, routerVertex); // (destination, parent)
1863  for (auto it = newNextHops->begin(); it != newNextHops->end(); ++it)
1864  entry->addNextHop(*it);
1865  delete newNextHops;
1866  }
1867  else {
1868  entry = new Ospfv2RoutingTableEntry(ift);
1869 
1870  entry->setDestination(Ipv4Address(destinationID));
1871  entry->setNetmask(Ipv4Address(link.getLinkData()));
1872  entry->setLinkStateOrigin(routerVertex);
1873  entry->setArea(areaID);
1874  entry->setPathType(Ospfv2RoutingTableEntry::INTRAAREA);
1875  entry->setCost(distance);
1876  entry->setDestinationType(Ospfv2RoutingTableEntry::NETWORK_DESTINATION);
1877  entry->setOptionalCapabilities(routerVertex->getHeader().getLsOptions());
1878  std::vector<NextHop> *newNextHops = calculateNextHops(link, routerVertex); // (destination, parent)
1879  for (auto it = newNextHops->begin(); it != newNextHops->end(); ++it)
1880  entry->addNextHop(*it);
1881  delete newNextHops;
1882 
1883  newRoutingTable.push_back(entry);
1884  }
1885  }
1886  }
1887 }

◆ containsAddress()

bool inet::ospfv2::Ospfv2Area::containsAddress ( Ipv4Address  address) const
153 {
154  int addressRangeNum = areaAddressRanges.size();
155  for (int i = 0; i < addressRangeNum; i++) {
156  if (areaAddressRanges[i].contains(address)) {
157  return true;
158  }
159  }
160  return false;
161 }

◆ createRoutingTableEntryFromSummaryLSA()

Ospfv2RoutingTableEntry * inet::ospfv2::Ospfv2Area::createRoutingTableEntryFromSummaryLSA ( const SummaryLsa summaryLSA,
unsigned short  entryCost,
const Ospfv2RoutingTableEntry borderRouterEntry 
) const
private

Returns a new Ospfv2RoutingTableEntry based on the input SummaryLsa, with the input cost and the borderRouterEntry's next hops.

2252 {
2253  Ipv4AddressRange destination;
2254 
2255  destination.address = summaryLSA.getHeader().getLinkStateID();
2256  destination.mask = summaryLSA.getNetworkMask();
2257 
2258  Ospfv2RoutingTableEntry *newEntry = new Ospfv2RoutingTableEntry(ift);
2259 
2260  if (summaryLSA.getHeader().getLsType() == SUMMARYLSA_NETWORKS_TYPE) {
2261  newEntry->setDestination(destination.address & destination.mask);
2262  newEntry->setNetmask(destination.mask);
2263  newEntry->setDestinationType(Ospfv2RoutingTableEntry::NETWORK_DESTINATION);
2264  }
2265  else {
2266  newEntry->setDestination(destination.address);
2267  newEntry->setNetmask(Ipv4Address::ALLONES_ADDRESS);
2268  newEntry->setDestinationType(Ospfv2RoutingTableEntry::AS_BOUNDARY_ROUTER_DESTINATION);
2269  }
2270  newEntry->setArea(areaID);
2271  newEntry->setPathType(Ospfv2RoutingTableEntry::INTERAREA);
2272  newEntry->setCost(entryCost);
2273  newEntry->setOptionalCapabilities(summaryLSA.getHeader().getLsOptions());
2274  newEntry->setLinkStateOrigin(&summaryLSA);
2275 
2276  unsigned int nextHopCount = borderRouterEntry.getNextHopCount();
2277  for (unsigned int j = 0; j < nextHopCount; j++) {
2278  newEntry->addNextHop(borderRouterEntry.getNextHop(j));
2279  }
2280 
2281  return newEntry;
2282 }

Referenced by calculateInterAreaRoutes().

◆ detailedInfo()

std::string inet::ospfv2::Ospfv2Area::detailedInfo ( ) const
134 {
135  std::stringstream out;
136 
137  out << info();
138 
139  out << "RouterLSAs:\n";
140  for (auto& entry : routerLSAs)
141  out << " " << entry << "\n";
142  out << "NetworkLSAs:\n";
143  for (auto& entry : networkLSAs)
144  out << " " << entry << "\n";
145  out << "SummaryLSAs:\n";
146  for (auto& entry : summaryLSAs)
147  out << " " << entry << "\n";
148 
149  return out.str();
150 }

◆ findNetworkLSA() [1/2]

NetworkLsa * inet::ospfv2::Ospfv2Area::findNetworkLSA ( LinkStateId  linkStateID)
341 {
342  auto lsaIt = networkLSAsByID.find(linkStateID);
343  return (lsaIt != networkLSAsByID.end()) ? lsaIt->second : nullptr;
344 }

Referenced by calculateShortestPathTree(), inet::ospfv2::Ospfv2InterfaceState::changeState(), and inet::ospfv2::NeighborState::updateLsa().

◆ findNetworkLSA() [2/2]

const NetworkLsa * inet::ospfv2::Ospfv2Area::findNetworkLSA ( LinkStateId  linkStateID) const
347 {
348  auto lsaIt = networkLSAsByID.find(linkStateID);
349  return (lsaIt != networkLSAsByID.end()) ? lsaIt->second :nullptr;
350 }

◆ findRouterLSA() [1/2]

RouterLsa * inet::ospfv2::Ospfv2Area::findRouterLSA ( LinkStateId  linkStateID)
329 {
330  auto lsaIt = routerLSAsByID.find(linkStateID);
331  return (lsaIt != routerLSAsByID.end()) ? lsaIt->second : nullptr;
332 }

Referenced by calculateShortestPathTree(), inet::ospfv2::Ospfv2InterfaceState::changeState(), inet::ospfv2::HelloHandler::processPacket(), and inet::ospfv2::NeighborState::updateLsa().

◆ findRouterLSA() [2/2]

const RouterLsa * inet::ospfv2::Ospfv2Area::findRouterLSA ( LinkStateId  linkStateID) const
335 {
336  auto lsaIt = routerLSAsByID.find(linkStateID);
337  return (lsaIt != routerLSAsByID.end()) ? lsaIt->second : nullptr;
338 }

◆ findSameOrWorseCostRoute()

bool inet::ospfv2::Ospfv2Area::findSameOrWorseCostRoute ( const std::vector< Ospfv2RoutingTableEntry * > &  newRoutingTable,
const SummaryLsa summaryLSA,
unsigned short  currentCost,
bool &  destinationInRoutingTable,
std::list< Ospfv2RoutingTableEntry * > &  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.

2187 {
2188  destinationInRoutingTable = false;
2189  sameOrWorseCost.clear();
2190 
2191  Ipv4AddressRange destination;
2192  destination.address = summaryLSA.getHeader().getLinkStateID();
2193  destination.mask = summaryLSA.getNetworkMask();
2194 
2195  for (auto routingEntry : newRoutingTable) {
2196  bool foundMatching = false;
2197 
2198  if (summaryLSA.getHeader().getLsType() == SUMMARYLSA_NETWORKS_TYPE) {
2199  if ((routingEntry->getDestinationType() == Ospfv2RoutingTableEntry::NETWORK_DESTINATION) &&
2200  destination.containedByRange(routingEntry->getDestination(), routingEntry->getNetmask()))
2201  {
2202  if (isDefaultRoute(routingEntry) && !isAllZero(destination))
2203  foundMatching = false;
2204  else
2205  foundMatching = true;
2206  }
2207  }
2208  else {
2209  if ((((routingEntry->getDestinationType() & Ospfv2RoutingTableEntry::AREA_BORDER_ROUTER_DESTINATION) != 0) ||
2210  ((routingEntry->getDestinationType() & Ospfv2RoutingTableEntry::AS_BOUNDARY_ROUTER_DESTINATION) != 0)) &&
2211  (destination.address == routingEntry->getDestination()) &&
2212  (destination.mask == routingEntry->getNetmask()))
2213  {
2214  foundMatching = true;
2215  }
2216  }
2217 
2218  if (foundMatching) {
2219  destinationInRoutingTable = true;
2220 
2221  /* If the matching entry is an INTRAAREA route (intra-area paths are
2222  * always preferred to other paths of any cost), or it's a cheaper INTERAREA
2223  * route, then skip this LSA.
2224  */
2225  if ((routingEntry->getPathType() == Ospfv2RoutingTableEntry::INTRAAREA) ||
2226  ((routingEntry->getPathType() == Ospfv2RoutingTableEntry::INTERAREA) &&
2227  (routingEntry->getCost() < currentCost)))
2228  {
2229  return true;
2230  }
2231  else {
2232  // if it's an other INTERAREA path
2233  if ((routingEntry->getPathType() == Ospfv2RoutingTableEntry::INTERAREA) &&
2234  (routingEntry->getCost() >= currentCost))
2235  {
2236  sameOrWorseCost.push_back(routingEntry);
2237  } // else it's external -> same as if not in the table
2238  }
2239  }
2240  }
2241 
2242  return false;
2243 }

Referenced by calculateInterAreaRoutes().

◆ findSummaryLSA() [1/2]

SummaryLsa * inet::ospfv2::Ospfv2Area::findSummaryLSA ( LsaKeyType  lsaKey)
353 {
354  auto lsaIt = summaryLSAsByID.find(lsaKey);
355  return (lsaIt != summaryLSAsByID.end()) ? lsaIt->second : nullptr;
356 }

Referenced by getUniqueLinkStateID().

◆ findSummaryLSA() [2/2]

const SummaryLsa * inet::ospfv2::Ospfv2Area::findSummaryLSA ( LsaKeyType  lsaKey) const
359 {
360  auto lsaIt = summaryLSAsByID.find(lsaKey);
361  return (lsaIt != summaryLSAsByID.end()) ? lsaIt->second : nullptr;
362 }

◆ findVirtualLink()

Ospfv2Interface * inet::ospfv2::Ospfv2Area::findVirtualLink ( RouterId  routerID)
249 {
250  int interfaceNum = associatedInterfaces.size();
251  for (int i = 0; i < interfaceNum; i++) {
252  if ((associatedInterfaces[i]->getType() == Ospfv2Interface::VIRTUAL) &&
253  (associatedInterfaces[i]->getNeighborById(routerID) != nullptr))
254  {
255  return associatedInterfaces[i];
256  }
257  }
258  return nullptr;
259 }

Referenced by calculateShortestPathTree(), and inet::ospfv2::MessageHandler::processPacket().

◆ floodLSA()

bool inet::ospfv2::Ospfv2Area::floodLSA ( const Ospfv2Lsa lsa,
Ospfv2Interface intf = nullptr,
Neighbor neighbor = nullptr 
)
684 {
685  bool floodedBackOut = false;
686  for (uint32_t i = 0; i < associatedInterfaces.size(); i++) {
687  if (associatedInterfaces[i]->floodLsa(lsa, intf, neighbor)) {
688  floodedBackOut = true;
689  }
690  }
691  return floodedBackOut;
692 }

Referenced by ageDatabase(), calculateShortestPathTree(), inet::ospfv2::Ospfv2InterfaceState::changeState(), inet::ospfv2::HelloHandler::processPacket(), and inet::ospfv2::NeighborState::updateLsa().

◆ getAddressRange()

Ipv4AddressRange inet::ospfv2::Ospfv2Area::getAddressRange ( unsigned int  index) const
inline
56 { return areaAddressRanges[index]; }

Referenced by getInterface(), and isLocalAddress().

◆ getAddressRangeCount()

unsigned int inet::ospfv2::Ospfv2Area::getAddressRangeCount ( ) const
inline
55 { return areaAddressRanges.size(); }

◆ getAreaID()

◆ getContainingAddressRange()

Ipv4AddressRange inet::ospfv2::Ospfv2Area::getContainingAddressRange ( Ipv4AddressRange  addressRange,
bool *  advertise = nullptr 
) const
175 {
176  int addressRangeNum = areaAddressRanges.size();
177  for (int i = 0; i < addressRangeNum; i++) {
178  if (areaAddressRanges[i].contains(addressRange)) {
179  if (advertise != nullptr) {
180  auto rangeIt = advertiseAddressRanges.find(areaAddressRanges[i]);
181  if (rangeIt != advertiseAddressRanges.end()) {
182  *advertise = rangeIt->second;
183  }
184  else {
185  throw cRuntimeError("Model error: inconsistent contents in areaAddressRanges and advertiseAddressRanges variables");
186  }
187  }
188  return areaAddressRanges[i];
189  }
190  }
191  if (advertise != nullptr) {
192  *advertise = false;
193  }
194  return NULL_IPV4ADDRESSRANGE;
195 }

◆ getExternalRoutingCapability()

◆ getInterface() [1/2]

Ospfv2Interface * inet::ospfv2::Ospfv2Area::getInterface ( Ipv4Address  address)
211 {
212  int interfaceNum = associatedInterfaces.size();
213  for (int i = 0; i < interfaceNum; i++) {
214  if ((associatedInterfaces[i]->getType() != Ospfv2Interface::VIRTUAL) &&
215  (associatedInterfaces[i]->getAddressRange().address == address))
216  {
217  return associatedInterfaces[i];
218  }
219  }
220  return nullptr;
221 }

◆ getInterface() [2/2]

Ospfv2Interface * inet::ospfv2::Ospfv2Area::getInterface ( unsigned char  ifIndex)
198 {
199  int interfaceNum = associatedInterfaces.size();
200  for (int i = 0; i < interfaceNum; i++) {
201  if ((associatedInterfaces[i]->getType() != Ospfv2Interface::VIRTUAL) &&
202  (associatedInterfaces[i]->getIfIndex() == ifIndex))
203  {
204  return associatedInterfaces[i];
205  }
206  }
207  return nullptr;
208 }

Referenced by ageDatabase(), calculateShortestPathTree(), inet::ospfv2::Ospfv2::handleInterfaceDown(), and inet::ospfv2::MessageHandler::processPacket().

◆ getInterfaceCount()

int inet::ospfv2::Ospfv2Area::getInterfaceCount ( ) const
inline
87 { return associatedInterfaces.size(); }

◆ getInterfaceIndices()

std::vector< int > inet::ospfv2::Ospfv2Area::getInterfaceIndices ( )
224 {
225  std::vector<int> indices;
226  for (auto& intf : associatedInterfaces)
227  indices.push_back(intf->getIfIndex());
228  return indices;
229 }

Referenced by inet::ospfv2::Ospfv2::handleInterfaceDown().

◆ getNetworkLSA() [1/2]

NetworkLsa* inet::ospfv2::Ospfv2Area::getNetworkLSA ( unsigned long  i)
inline

◆ getNetworkLSA() [2/2]

const NetworkLsa* inet::ospfv2::Ospfv2Area::getNetworkLSA ( unsigned long  i) const
inline
77 { return networkLSAs[i]; }

◆ getNetworkLSACount()

unsigned long inet::ospfv2::Ospfv2Area::getNetworkLSACount ( ) const
inline
75 { return networkLSAs.size(); }

Referenced by inet::ospfv2::Neighbor::createDatabaseSummary().

◆ getRouter() [1/2]

Router* inet::ospfv2::Ospfv2Area::getRouter ( )
inline
69 { return parentRouter; }

Referenced by inet::ospfv2::Ospfv2InterfaceState::calculateDesignatedRouter(), inet::ospfv2::Ospfv2InterfaceState::changeState(), inet::ospfv2::NeighborState::changeState(), inet::ospfv2::Neighbor::clearRequestRetransmissionTimer(), inet::ospfv2::Neighbor::clearUpdateRetransmissionTimer(), inet::ospfv2::Neighbor::createDatabaseSummary(), inet::ospfv2::Ospfv2Interface::createUpdatePacket(), inet::ospfv2::Ospfv2Interface::floodLsa(), inet::ospfv2::Neighbor::needAdjacency(), inet::ospfv2::NeighborStateAttempt::processEvent(), inet::ospfv2::NeighborStateExchange::processEvent(), inet::ospfv2::NeighborStateExchangeStart::processEvent(), inet::ospfv2::InterfaceStateNotDesignatedRouter::processEvent(), inet::ospfv2::NeighborStateFull::processEvent(), inet::ospfv2::NeighborStateLoading::processEvent(), inet::ospfv2::NeighborStateTwoWay::processEvent(), inet::ospfv2::InterfaceStateBackup::processEvent(), inet::ospfv2::InterfaceStateDesignatedRouter::processEvent(), inet::ospfv2::NeighborStateDown::processEvent(), inet::ospfv2::InterfaceStateDown::processEvent(), inet::ospfv2::NeighborStateInit::processEvent(), inet::ospfv2::InterfaceStatePointToPoint::processEvent(), inet::ospfv2::InterfaceStateWaiting::processEvent(), inet::ospfv2::Ospfv2Interface::reset(), inet::ospfv2::Neighbor::reset(), inet::ospfv2::Neighbor::retransmitDatabaseDescriptionPacket(), inet::ospfv2::Neighbor::retransmitUpdatePacket(), inet::ospfv2::Neighbor::sendDatabaseDescriptionPacket(), inet::ospfv2::Ospfv2Interface::sendDelayedAcknowledgements(), inet::ospfv2::Ospfv2Interface::sendHelloPacket(), inet::ospfv2::Neighbor::sendLinkStateRequestPacket(), inet::ospfv2::Ospfv2Interface::sendLsAcknowledgement(), inet::ospfv2::Neighbor::startRequestRetransmissionTimer(), inet::ospfv2::Neighbor::startUpdateRetransmissionTimer(), inet::ospfv2::NeighborState::updateLsa(), inet::ospfv2::Neighbor::~Neighbor(), and inet::ospfv2::Ospfv2Interface::~Ospfv2Interface().

◆ getRouter() [2/2]

const Router* inet::ospfv2::Ospfv2Area::getRouter ( ) const
inline
70 { return parentRouter; }

◆ getRouterLSA() [1/2]

RouterLsa* inet::ospfv2::Ospfv2Area::getRouterLSA ( unsigned long  i)
inline

◆ getRouterLSA() [2/2]

const RouterLsa* inet::ospfv2::Ospfv2Area::getRouterLSA ( unsigned long  i) const
inline
74 { return routerLSAs[i]; }

◆ getRouterLSACount()

unsigned long inet::ospfv2::Ospfv2Area::getRouterLSACount ( ) const
inline
72 { return routerLSAs.size(); }

Referenced by inet::ospfv2::Neighbor::createDatabaseSummary().

◆ getSPFTreeRoot() [1/2]

RouterLsa* inet::ospfv2::Ospfv2Area::getSPFTreeRoot ( )
inline
65 { return spfTreeRoot; }

◆ getSPFTreeRoot() [2/2]

const RouterLsa* inet::ospfv2::Ospfv2Area::getSPFTreeRoot ( ) const
inline
66 { return spfTreeRoot; }

◆ getStubDefaultCost()

Metric inet::ospfv2::Ospfv2Area::getStubDefaultCost ( ) const
inline
63 { return stubDefaultCost; }

◆ getSummaryLSA() [1/2]

SummaryLsa* inet::ospfv2::Ospfv2Area::getSummaryLSA ( unsigned long  i)
inline

◆ getSummaryLSA() [2/2]

const SummaryLsa* inet::ospfv2::Ospfv2Area::getSummaryLSA ( unsigned long  i) const
inline
80 { return summaryLSAs[i]; }

◆ getSummaryLSACount()

unsigned long inet::ospfv2::Ospfv2Area::getSummaryLSACount ( ) const
inline
78 { return summaryLSAs.size(); }

Referenced by inet::ospfv2::Neighbor::createDatabaseSummary().

◆ getTransitCapability()

bool inet::ospfv2::Ospfv2Area::getTransitCapability ( ) const
inline
59 { return transitCapability; }

◆ getUniqueLinkStateID()

LinkStateId inet::ospfv2::Ospfv2Area::getUniqueLinkStateID ( Ipv4AddressRange  destination,
Metric  destinationCost,
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 returns 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 that 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 nullptr 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.

1013 {
1014  if (lsaToReoriginate != nullptr) {
1015  delete lsaToReoriginate;
1016  lsaToReoriginate = nullptr;
1017  }
1018 
1019  LsaKeyType lsaKey;
1020 
1021  lsaKey.linkStateID = destination.address;
1022  lsaKey.advertisingRouter = parentRouter->getRouterID();
1023 
1024  const SummaryLsa *foundLSA = findSummaryLSA(lsaKey);
1025 
1026  if (foundLSA == nullptr) {
1027  return lsaKey.linkStateID;
1028  }
1029  else {
1030  Ipv4Address existingMask = foundLSA->getNetworkMask();
1031 
1032  if (destination.mask == existingMask) {
1033  return lsaKey.linkStateID;
1034  }
1035  else {
1036  if (destination.mask >= existingMask) {
1037  return lsaKey.linkStateID.makeBroadcastAddress(destination.mask);
1038  }
1039  else {
1040  SummaryLsa *summaryLSA = new SummaryLsa(*foundLSA);
1041 
1042  long sequenceNumber = summaryLSA->getHeader().getLsSequenceNumber();
1043 
1044  summaryLSA->getHeaderForUpdate().setLsAge(0);
1045  summaryLSA->getHeaderForUpdate().setLsSequenceNumber((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1);
1046  summaryLSA->setNetworkMask(destination.mask);
1047  summaryLSA->setRouteCost(destinationCost);
1048 
1049  lsaToReoriginate = summaryLSA;
1050 
1051  return lsaKey.linkStateID.makeBroadcastAddress(existingMask);
1052  }
1053  }
1054  }
1055 }

Referenced by originateSummaryLSA().

◆ hasAddressRange()

bool inet::ospfv2::Ospfv2Area::hasAddressRange ( Ipv4AddressRange  addressRange) const
164 {
165  int addressRangeNum = areaAddressRanges.size();
166  for (int i = 0; i < addressRangeNum; i++) {
167  if (areaAddressRanges[i] == addressRange) {
168  return true;
169  }
170  }
171  return false;
172 }

◆ hasAnyNeighborInStates()

bool inet::ospfv2::Ospfv2Area::hasAnyNeighborInStates ( int  states) const
660 {
661  for (uint32_t i = 0; i < associatedInterfaces.size(); i++) {
663  return true;
664  }
665  return false;
666 }

Referenced by ageDatabase(), and inet::ospfv2::Router::rebuildRoutingTable().

◆ hasLink()

bool inet::ospfv2::Ospfv2Area::hasLink ( Ospfv2Lsa fromLSA,
Ospfv2Lsa toLSA 
) const
private
2119 {
2120  unsigned int i;
2121 
2122  RouterLsa *fromRouterLSA = dynamic_cast<RouterLsa *>(fromLSA);
2123  if (fromRouterLSA != nullptr) {
2124  unsigned int linkCount = fromRouterLSA->getLinksArraySize();
2125  RouterLsa *toRouterLSA = dynamic_cast<RouterLsa *>(toLSA);
2126  if (toRouterLSA != nullptr) {
2127  for (i = 0; i < linkCount; i++) {
2128  const auto& link = fromRouterLSA->getLinks(i);
2129  LinkType linkType = static_cast<LinkType>(link.getType());
2130 
2131  if (((linkType == POINTTOPOINT_LINK) ||
2132  (linkType == VIRTUAL_LINK)) &&
2133  (link.getLinkID() == toRouterLSA->getHeader().getLinkStateID()))
2134  {
2135  return true;
2136  }
2137  }
2138  }
2139  else {
2140  NetworkLsa *toNetworkLSA = dynamic_cast<NetworkLsa *>(toLSA);
2141  if (toNetworkLSA != nullptr) {
2142  for (i = 0; i < linkCount; i++) {
2143  const auto& link = fromRouterLSA->getLinks(i);
2144 
2145  if ((link.getType() == TRANSIT_LINK) &&
2146  (link.getLinkID() == toNetworkLSA->getHeader().getLinkStateID()))
2147  {
2148  return true;
2149  }
2150  if ((link.getType() == STUB_LINK) &&
2151  ((link.getLinkID() & Ipv4Address(link.getLinkData())) == (toNetworkLSA->getHeader().getLinkStateID() & toNetworkLSA->getNetworkMask()))) // FIXME should compare masks?
2152  {
2153  return true;
2154  }
2155  }
2156  }
2157  }
2158  }
2159  else {
2160  NetworkLsa *fromNetworkLSA = dynamic_cast<NetworkLsa *>(fromLSA);
2161  if (fromNetworkLSA != nullptr) {
2162  unsigned int routerCount = fromNetworkLSA->getAttachedRoutersArraySize();
2163  RouterLsa *toRouterLSA = dynamic_cast<RouterLsa *>(toLSA);
2164  if (toRouterLSA != nullptr) {
2165  for (i = 0; i < routerCount; i++) {
2166  if (fromNetworkLSA->getAttachedRouters(i) == toRouterLSA->getHeader().getLinkStateID()) {
2167  return true;
2168  }
2169  }
2170  }
2171  }
2172  }
2173 
2174  return false;
2175 }

Referenced by calculateShortestPathTree().

◆ hasVirtualLink()

bool inet::ospfv2::Ospfv2Area::hasVirtualLink ( AreaId  withTransitArea) const
232 {
233  if ((areaID != BACKBONE_AREAID) || (withTransitArea == BACKBONE_AREAID)) {
234  return false;
235  }
236 
237  int interfaceNum = associatedInterfaces.size();
238  for (int i = 0; i < interfaceNum; i++) {
239  if ((associatedInterfaces[i]->getType() == Ospfv2Interface::VIRTUAL) &&
240  (associatedInterfaces[i]->getTransitAreaId() == withTransitArea))
241  {
242  return true;
243  }
244  }
245  return false;
246 }

Referenced by originateRouterLSA().

◆ info()

std::string inet::ospfv2::Ospfv2Area::info ( ) const
112 {
113  std::stringstream out;
114 
115  out << "areaID: " << areaID.str(false) << ", ";
116  out << "transitCapability: " << (transitCapability ? "true" : "false") << ", ";
117  out << "externalRoutingCapability: " << (externalRoutingCapability ? "true" : "false") << ", ";
118  out << "stubDefaultCost: " << stubDefaultCost << ", ";
119  for (uint32_t i = 0; i < areaAddressRanges.size(); i++) {
120  out << "addressRanges[" << i << "]: ";
121  out << areaAddressRanges[i].address.str(false);
122  out << "/" << areaAddressRanges[i].mask.str(false) << " ";
123  }
124  for (uint32_t i = 0; i < associatedInterfaces.size(); i++) {
125  out << "interface[" << i << "]: ";
126  out << associatedInterfaces[i]->getAddressRange().address.str(false);
127  out << "/" << associatedInterfaces[i]->getAddressRange().mask.str(false) << " ";
128  }
129 
130  return out.str();
131 }

Referenced by detailedInfo(), and inet::ospfv2::operator<<().

◆ installNetworkLSA()

bool inet::ospfv2::Ospfv2Area::installNetworkLSA ( const Ospfv2NetworkLsa lsa)
283 {
284  LinkStateId linkStateID = lsa->getHeader().getLinkStateID();
285  auto lsaIt = networkLSAsByID.find(linkStateID);
286  if (lsaIt != networkLSAsByID.end()) {
287  LsaKeyType lsaKey;
288 
289  lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
290  lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter();
291 
293  return lsaIt->second->update(lsa);
294  }
295  else {
296  NetworkLsa *lsaCopy = new NetworkLsa(*lsa);
297  networkLSAsByID[linkStateID] = lsaCopy;
298  networkLSAs.push_back(lsaCopy);
299  return true;
300  }
301 }

Referenced by inet::ospfv2::Ospfv2InterfaceState::changeState().

◆ installRouterLSA()

bool inet::ospfv2::Ospfv2Area::installRouterLSA ( const Ospfv2RouterLsa lsa)
262 {
263  LinkStateId linkStateID = lsa->getHeader().getLinkStateID();
264  auto lsaIt = routerLSAsByID.find(linkStateID);
265  if (lsaIt != routerLSAsByID.end()) {
266  LsaKeyType lsaKey;
267 
268  lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
269  lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter();
270 
272  return lsaIt->second->update(lsa);
273  }
274  else {
275  RouterLsa *lsaCopy = new RouterLsa(*lsa);
276  routerLSAsByID[linkStateID] = lsaCopy;
277  routerLSAs.push_back(lsaCopy);
278  return true;
279  }
280 }

Referenced by calculateShortestPathTree(), and inet::ospfv2::Ospfv2InterfaceState::changeState().

◆ installSummaryLSA()

bool inet::ospfv2::Ospfv2Area::installSummaryLSA ( const Ospfv2SummaryLsa lsa)
304 {
305  LsaKeyType lsaKey;
306 
307  lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
308  lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter();
309 
310  auto lsaIt = summaryLSAsByID.find(lsaKey);
311  if (lsaIt != summaryLSAsByID.end()) {
312  LsaKeyType lsaKey;
313 
314  lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
315  lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter();
316 
318  return lsaIt->second->update(lsa);
319  }
320  else {
321  SummaryLsa *lsaCopy = new SummaryLsa(*lsa);
322  summaryLSAsByID[lsaKey] = lsaCopy;
323  summaryLSAs.push_back(lsaCopy);
324  return true;
325  }
326 }

◆ isAllZero()

bool inet::ospfv2::Ospfv2Area::isAllZero ( Ipv4AddressRange  entry) const
private
2608 {
2609  if (entry.address.getInt() == 0 && entry.mask.getInt() == 0)
2610  return true;
2611  return false;
2612 }

Referenced by findSameOrWorseCostRoute().

◆ isDefaultRoute()

bool inet::ospfv2::Ospfv2Area::isDefaultRoute ( Ospfv2RoutingTableEntry entry) const
private
2601 {
2602  if (entry->getDestination().getInt() == 0 && entry->getNetmask().getInt() == 0)
2603  return true;
2604  return false;
2605 }

Referenced by findSameOrWorseCostRoute().

◆ isLocalAddress()

bool inet::ospfv2::Ospfv2Area::isLocalAddress ( Ipv4Address  address) const
695 {
696  for (uint32_t i = 0; i < associatedInterfaces.size(); i++) {
697  if (associatedInterfaces[i]->getAddressRange().address == address)
698  return true;
699  }
700  return false;
701 }

◆ isOnAnyRetransmissionList()

bool inet::ospfv2::Ospfv2Area::isOnAnyRetransmissionList ( LsaKeyType  lsaKey) const
675 {
676  for (uint32_t i = 0; i < associatedInterfaces.size(); i++) {
678  return true;
679  }
680  return false;
681 }

Referenced by ageDatabase().

◆ originateNetworkLSA()

NetworkLsa * inet::ospfv2::Ospfv2Area::originateNetworkLSA ( const Ospfv2Interface intf)
949 {
950  if (intf->hasAnyNeighborInStates(Neighbor::FULL_STATE)) {
951  NetworkLsa *networkLSA = new NetworkLsa;
952  Ospfv2LsaHeader& lsaHeader = networkLSA->getHeaderForUpdate();
953  long neighborCount = intf->getNeighborCount();
954  Ospfv2Options lsOptions;
955 
956  lsaHeader.setLsAge(0);
957  lsOptions.E_ExternalRoutingCapability = externalRoutingCapability;
958  lsaHeader.setLsOptions(lsOptions);
959  lsaHeader.setLsType(NETWORKLSA_TYPE);
960  lsaHeader.setLinkStateID(intf->getAddressRange().address);
961  lsaHeader.setAdvertisingRouter(Ipv4Address(parentRouter->getRouterID()));
962  lsaHeader.setLsSequenceNumber(INITIAL_SEQUENCE_NUMBER);
963 
964  networkLSA->setNetworkMask(intf->getAddressRange().mask);
965 
966  for (long j = 0; j < neighborCount; j++) {
967  const Neighbor *neighbor = intf->getNeighbor(j);
968  if (neighbor->getState() == Neighbor::FULL_STATE) {
969  unsigned short netIndex = networkLSA->getAttachedRoutersArraySize();
970  networkLSA->setAttachedRoutersArraySize(netIndex + 1);
971  networkLSA->setAttachedRouters(netIndex, Ipv4Address(neighbor->getNeighborID()));
972  }
973  }
974  unsigned short netIndex = networkLSA->getAttachedRoutersArraySize();
975  networkLSA->setAttachedRoutersArraySize(netIndex + 1);
976  networkLSA->setAttachedRouters(netIndex, Ipv4Address(parentRouter->getRouterID()));
977 
978  // update the length field in the LSA header
979  lsaHeader.setLsaLength(B(calculateLsaSize(*networkLSA)).get());
980 
981  setLsaCrc(*networkLSA, crcMode);
982  return networkLSA;
983  }
984  else {
985  return nullptr;
986  }
987 }

Referenced by ageDatabase(), inet::ospfv2::Ospfv2InterfaceState::changeState(), and inet::ospfv2::NeighborState::updateLsa().

◆ originateRouterLSA()

RouterLsa * inet::ospfv2::Ospfv2Area::originateRouterLSA ( )
704 {
705  RouterLsa *routerLSA = new RouterLsa;
706  Ospfv2LsaHeader& lsaHeader = routerLSA->getHeaderForUpdate();
707  Ospfv2Options lsOptions;
708 
709  lsaHeader.setLsAge(0);
710  lsOptions.E_ExternalRoutingCapability = externalRoutingCapability;
711  lsaHeader.setLsOptions(lsOptions);
712  lsaHeader.setLsType(ROUTERLSA_TYPE);
713  lsaHeader.setLinkStateID(parentRouter->getRouterID());
714  lsaHeader.setAdvertisingRouter(Ipv4Address(parentRouter->getRouterID()));
715  lsaHeader.setLsSequenceNumber(INITIAL_SEQUENCE_NUMBER);
716 
717  routerLSA->setB_AreaBorderRouter(parentRouter->getAreaCount() > 1);
718  routerLSA->setE_ASBoundaryRouter((externalRoutingCapability && parentRouter->getASBoundaryRouter()) ? true : false);
720  routerLSA->setV_VirtualLinkEndpoint((backbone == nullptr) ? false : backbone->hasVirtualLink(areaID));
721 
722  routerLSA->setNumberOfLinks(0);
723  routerLSA->setLinksArraySize(0);
724  for (uint32_t i = 0; i < associatedInterfaces.size(); i++) {
725  Ospfv2Interface *intf = associatedInterfaces[i];
726 
727  if (intf->getState() == Ospfv2Interface::DOWN_STATE) {
728  continue;
729  }
730 
731  if ((intf->getState() == Ospfv2Interface::LOOPBACK_STATE) &&
732  ((intf->getType() != Ospfv2Interface::POINTTOPOINT) ||
733  (intf->getAddressRange().address != NULL_IPV4ADDRESS)))
734  {
735  Ospfv2Link stubLink;
736  stubLink.setType(STUB_LINK);
737  stubLink.setLinkID(intf->getAddressRange().address);
738  stubLink.setLinkData(0xFFFFFFFF);
739  stubLink.setLinkCost(0);
740  stubLink.setNumberOfTOS(0);
741  stubLink.setTosDataArraySize(0);
742 
743  unsigned short linkIndex = routerLSA->getLinksArraySize();
744  routerLSA->setLinksArraySize(linkIndex + 1);
745  routerLSA->setNumberOfLinks(linkIndex + 1);
746  routerLSA->setLinks(linkIndex, stubLink);
747  }
748  if (intf->getState() > Ospfv2Interface::LOOPBACK_STATE) {
749  switch (intf->getType()) {
751  Neighbor *neighbor = (intf->getNeighborCount() > 0) ? intf->getNeighbor(0) : nullptr;
752  if (neighbor != nullptr) {
753  if (neighbor->getState() == Neighbor::FULL_STATE) {
754  Ospfv2Link link;
755  link.setType(POINTTOPOINT_LINK);
756  link.setLinkID(Ipv4Address(neighbor->getNeighborID()));
757  if (intf->getAddressRange().address != NULL_IPV4ADDRESS) {
758  link.setLinkData(intf->getAddressRange().address.getInt());
759  }
760  else {
761  link.setLinkData(intf->getIfIndex());
762  }
763  link.setLinkCost(intf->getOutputCost());
764  link.setNumberOfTOS(0);
765  link.setTosDataArraySize(0);
766 
767  unsigned short linkIndex = routerLSA->getLinksArraySize();
768  routerLSA->setLinksArraySize(linkIndex + 1);
769  routerLSA->setNumberOfLinks(linkIndex + 1);
770  routerLSA->setLinks(linkIndex, link);
771  }
772  if (intf->getState() == Ospfv2Interface::POINTTOPOINT_STATE) {
773  if (neighbor->getAddress() != NULL_IPV4ADDRESS) {
774  Ospfv2Link stubLink;
775  stubLink.setType(STUB_LINK);
776  stubLink.setLinkID(neighbor->getAddress());
777  stubLink.setLinkData(0xFFFFFFFF);
778  stubLink.setLinkCost(intf->getOutputCost());
779  stubLink.setNumberOfTOS(0);
780  stubLink.setTosDataArraySize(0);
781 
782  unsigned short linkIndex = routerLSA->getLinksArraySize();
783  routerLSA->setLinksArraySize(linkIndex + 1);
784  routerLSA->setNumberOfLinks(linkIndex + 1);
785  routerLSA->setLinks(linkIndex, stubLink);
786  }
787  else {
788  if (intf->getAddressRange().mask.getInt() != 0xFFFFFFFF) {
789  Ospfv2Link stubLink;
790  stubLink.setType(STUB_LINK);
791  stubLink.setLinkID(intf->getAddressRange().address
792  & intf->getAddressRange().mask);
793  stubLink.setLinkData(intf->getAddressRange().mask.getInt());
794  stubLink.setLinkCost(intf->getOutputCost());
795  stubLink.setNumberOfTOS(0);
796  stubLink.setTosDataArraySize(0);
797 
798  unsigned short linkIndex = routerLSA->getLinksArraySize();
799  routerLSA->setLinksArraySize(linkIndex + 1);
800  routerLSA->setNumberOfLinks(linkIndex + 1);
801  routerLSA->setLinks(linkIndex, stubLink);
802  }
803  }
804  }
805  }
806  }
807  break;
808 
810  case Ospfv2Interface::NBMA: {
811  if (intf->getState() == Ospfv2Interface::WAITING_STATE) {
812  Ospfv2Link stubLink;
813  stubLink.setType(STUB_LINK);
814  stubLink.setLinkID(intf->getAddressRange().address
815  & intf->getAddressRange().mask);
816  stubLink.setLinkData(intf->getAddressRange().mask.getInt());
817  stubLink.setLinkCost(intf->getOutputCost());
818  stubLink.setNumberOfTOS(0);
819  stubLink.setTosDataArraySize(0);
820 
821  unsigned short linkIndex = routerLSA->getLinksArraySize();
822  routerLSA->setLinksArraySize(linkIndex + 1);
823  routerLSA->setNumberOfLinks(linkIndex + 1);
824  routerLSA->setLinks(linkIndex, stubLink);
825  }
826  else {
827  Neighbor *dRouter = intf->getNeighborByAddress(intf->getDesignatedRouter().ipInterfaceAddress);
828  if (((dRouter != nullptr) && (dRouter->getState() == Neighbor::FULL_STATE)) ||
829  ((intf->getDesignatedRouter().routerID == parentRouter->getRouterID()) &&
830  (intf->hasAnyNeighborInStates(Neighbor::FULL_STATE))))
831  {
832  Ospfv2Link link;
833  link.setType(TRANSIT_LINK);
834  link.setLinkID(intf->getDesignatedRouter().ipInterfaceAddress);
835  link.setLinkData(intf->getAddressRange().address.getInt());
836  link.setLinkCost(intf->getOutputCost());
837  link.setNumberOfTOS(0);
838  link.setTosDataArraySize(0);
839 
840  unsigned short linkIndex = routerLSA->getLinksArraySize();
841  routerLSA->setLinksArraySize(linkIndex + 1);
842  routerLSA->setNumberOfLinks(linkIndex + 1);
843  routerLSA->setLinks(linkIndex, link);
844  }
845  else {
846  Ospfv2Link stubLink;
847  stubLink.setType(STUB_LINK);
848  stubLink.setLinkID(intf->getAddressRange().address
849  & intf->getAddressRange().mask);
850  stubLink.setLinkData(intf->getAddressRange().mask.getInt());
851  stubLink.setLinkCost(intf->getOutputCost());
852  stubLink.setNumberOfTOS(0);
853  stubLink.setTosDataArraySize(0);
854 
855  unsigned short linkIndex = routerLSA->getLinksArraySize();
856  routerLSA->setLinksArraySize(linkIndex + 1);
857  routerLSA->setNumberOfLinks(linkIndex + 1);
858  routerLSA->setLinks(linkIndex, stubLink);
859  }
860  }
861  }
862  break;
863 
865  Neighbor *neighbor = (intf->getNeighborCount() > 0) ? intf->getNeighbor(0) : nullptr;
866  if ((neighbor != nullptr) && (neighbor->getState() == Neighbor::FULL_STATE)) {
867  Ospfv2Link link;
868  link.setType(VIRTUAL_LINK);
869  link.setLinkID(Ipv4Address(neighbor->getNeighborID()));
870  link.setLinkData(intf->getAddressRange().address.getInt());
871  link.setLinkCost(intf->getOutputCost());
872  link.setNumberOfTOS(0);
873  link.setTosDataArraySize(0);
874 
875  unsigned short linkIndex = routerLSA->getLinksArraySize();
876  routerLSA->setLinksArraySize(linkIndex + 1);
877  routerLSA->setNumberOfLinks(linkIndex + 1);
878  routerLSA->setLinks(linkIndex, link);
879  }
880  }
881  break;
882 
884  Ospfv2Link stubLink;
885  stubLink.setType(STUB_LINK);
886  stubLink.setLinkID(intf->getAddressRange().address);
887  stubLink.setLinkData(0xFFFFFFFF);
888  stubLink.setLinkCost(0);
889  stubLink.setNumberOfTOS(0);
890  stubLink.setTosDataArraySize(0);
891 
892  unsigned short linkIndex = routerLSA->getLinksArraySize();
893  routerLSA->setLinksArraySize(linkIndex + 1);
894  routerLSA->setNumberOfLinks(linkIndex + 1);
895  routerLSA->setLinks(linkIndex, stubLink);
896 
897  long neighborCount = intf->getNeighborCount();
898  for (long i = 0; i < neighborCount; i++) {
899  Neighbor *neighbor = intf->getNeighbor(i);
900  if (neighbor->getState() == Neighbor::FULL_STATE) {
901  Ospfv2Link link;
902  link.setType(POINTTOPOINT_LINK);
903  link.setLinkID(Ipv4Address(neighbor->getNeighborID()));
904  link.setLinkData(intf->getAddressRange().address.getInt());
905  link.setLinkCost(intf->getOutputCost());
906  link.setNumberOfTOS(0);
907  link.setTosDataArraySize(0);
908 
909  unsigned short linkIndex = routerLSA->getLinksArraySize();
910  routerLSA->setLinksArraySize(linkIndex + 1);
911  routerLSA->setNumberOfLinks(linkIndex + 1);
912  routerLSA->setLinks(linkIndex, stubLink);
913  }
914  }
915  }
916  break;
917 
918  default:
919  break;
920  }
921  }
922  }
923 
924  for (uint32_t i = 0; i < hostRoutes.size(); i++) {
925  Ospfv2Link stubLink;
926  stubLink.setType(STUB_LINK);
927  stubLink.setLinkID(hostRoutes[i].address);
928  stubLink.setLinkData(0xFFFFFFFF);
929  stubLink.setLinkCost(hostRoutes[i].linkCost);
930  stubLink.setNumberOfTOS(0);
931  stubLink.setTosDataArraySize(0);
932 
933  unsigned short linkIndex = routerLSA->getLinksArraySize();
934  routerLSA->setLinksArraySize(linkIndex + 1);
935  routerLSA->setNumberOfLinks(linkIndex + 1);
936  routerLSA->setLinks(linkIndex, stubLink);
937  }
938 
939  // update the length field in the LSA header
940  lsaHeader.setLsaLength(calculateLSASize(routerLSA).get());
941 
942  routerLSA->setSource(LsaTrackingInfo::ORIGINATED);
943 
944  setLsaCrc(*routerLSA, crcMode);
945  return routerLSA;
946 }

Referenced by ageDatabase(), calculateShortestPathTree(), inet::ospfv2::Ospfv2InterfaceState::changeState(), inet::ospfv2::HelloHandler::processPacket(), and inet::ospfv2::NeighborState::updateLsa().

◆ originateSummaryLSA() [1/2]

SummaryLsa * inet::ospfv2::Ospfv2Area::originateSummaryLSA ( const Ospfv2RoutingTableEntry entry,
const std::map< LsaKeyType, bool, LsaKeyType_Less > &  originatedLSAs,
SummaryLsa *&  lsaToReoriginate 
)
1060 {
1061  if (((entry->getDestinationType() & Ospfv2RoutingTableEntry::AREA_BORDER_ROUTER_DESTINATION) != 0) ||
1062  (entry->getPathType() == Ospfv2RoutingTableEntry::TYPE1_EXTERNAL) ||
1063  (entry->getPathType() == Ospfv2RoutingTableEntry::TYPE2_EXTERNAL) ||
1064  (entry->getArea() == areaID))
1065  {
1066  return nullptr;
1067  }
1068 
1069  bool allNextHopsInThisArea = true;
1070  for (unsigned int i = 0; i < entry->getNextHopCount(); i++) {
1071  Ospfv2Interface *nextHopInterface = parentRouter->getNonVirtualInterface(entry->getNextHop(i).ifIndex);
1072  if ((nextHopInterface != nullptr) && (nextHopInterface->getAreaId() != areaID)) {
1073  allNextHopsInThisArea = false;
1074  break;
1075  }
1076  }
1077  if ((allNextHopsInThisArea) || (entry->getCost() >= LS_INFINITY)) {
1078  return nullptr;
1079  }
1080 
1081  if ((entry->getDestinationType() & Ospfv2RoutingTableEntry::AS_BOUNDARY_ROUTER_DESTINATION) != 0) {
1082  Ospfv2RoutingTableEntry *preferredEntry = parentRouter->getPreferredEntry(*(entry->getLinkStateOrigin()), false);
1083  if ((preferredEntry != nullptr) && (*preferredEntry == *entry) && (externalRoutingCapability)) {
1084  SummaryLsa *summaryLSA = new SummaryLsa;
1085  Ospfv2LsaHeader& lsaHeader = summaryLSA->getHeaderForUpdate();
1086  Ospfv2Options lsOptions;
1087 
1088  lsaHeader.setLsAge(0);
1089  lsOptions.E_ExternalRoutingCapability = externalRoutingCapability;
1090  lsaHeader.setLsOptions(lsOptions);
1091  lsaHeader.setLsType(SUMMARYLSA_ASBOUNDARYROUTERS_TYPE);
1092  lsaHeader.setLinkStateID(entry->getDestination());
1093  lsaHeader.setAdvertisingRouter(Ipv4Address(parentRouter->getRouterID()));
1094  lsaHeader.setLsSequenceNumber(INITIAL_SEQUENCE_NUMBER);
1095 
1096  summaryLSA->setNetworkMask(entry->getNetmask());
1097  summaryLSA->setRouteCost(entry->getCost());
1098  summaryLSA->setTosDataArraySize(0);
1099 
1100  summaryLSA->setSource(LsaTrackingInfo::ORIGINATED);
1101 
1102  // update the length field in the LSA header
1103  lsaHeader.setLsaLength(B(calculateLsaSize(*summaryLSA)).get());
1104 
1105  setLsaCrc(*summaryLSA, crcMode);
1106  return summaryLSA;
1107  }
1108  }
1109  else { // entry->getDestinationType() == Ospfv2RoutingTableEntry::NETWORK_DESTINATION
1110  if (entry->getPathType() == Ospfv2RoutingTableEntry::INTERAREA) {
1111  Ipv4AddressRange destinationRange;
1112 
1113  destinationRange.address = entry->getDestination();
1114  destinationRange.mask = entry->getNetmask();
1115 
1116  LinkStateId newLinkStateID = getUniqueLinkStateID(destinationRange, entry->getCost(), lsaToReoriginate);
1117 
1118  if (lsaToReoriginate != nullptr) {
1119  LsaKeyType lsaKey;
1120 
1121  lsaKey.linkStateID = entry->getDestination();
1122  lsaKey.advertisingRouter = parentRouter->getRouterID();
1123 
1124  auto lsaIt = summaryLSAsByID.find(lsaKey);
1125  if (lsaIt == summaryLSAsByID.end()) {
1126  delete lsaToReoriginate;
1127  lsaToReoriginate = nullptr;
1128  return nullptr;
1129  }
1130  else {
1131  SummaryLsa *summaryLSA = new SummaryLsa(*(lsaIt->second));
1132  Ospfv2LsaHeader& lsaHeader = summaryLSA->getHeaderForUpdate();
1133 
1134  lsaHeader.setLsAge(0);
1135  lsaHeader.setLsSequenceNumber(INITIAL_SEQUENCE_NUMBER);
1136  lsaHeader.setLinkStateID(newLinkStateID);
1137 
1138  // update the length field in the LSA header
1139  lsaHeader.setLsaLength(B(calculateLsaSize(*summaryLSA)).get());
1140 
1141  setLsaCrc(*summaryLSA, crcMode);
1142  return summaryLSA;
1143  }
1144  }
1145  else {
1146  SummaryLsa *summaryLSA = new SummaryLsa;
1147  Ospfv2LsaHeader& lsaHeader = summaryLSA->getHeaderForUpdate();
1148  Ospfv2Options lsOptions;
1149 
1150  lsaHeader.setLsAge(0);
1151  lsOptions.E_ExternalRoutingCapability = externalRoutingCapability;
1152  lsaHeader.setLsOptions(lsOptions);
1153  lsaHeader.setLsType(SUMMARYLSA_NETWORKS_TYPE);
1154  lsaHeader.setLinkStateID(newLinkStateID);
1155  lsaHeader.setAdvertisingRouter(Ipv4Address(parentRouter->getRouterID()));
1156  lsaHeader.setLsSequenceNumber(INITIAL_SEQUENCE_NUMBER);
1157 
1158  summaryLSA->setNetworkMask(entry->getNetmask());
1159  summaryLSA->setRouteCost(entry->getCost());
1160  summaryLSA->setTosDataArraySize(0);
1161 
1162  summaryLSA->setSource(LsaTrackingInfo::ORIGINATED);
1163 
1164  // update the length field in the LSA header
1165  lsaHeader.setLsaLength(B(calculateLsaSize(*summaryLSA)).get());
1166 
1167  setLsaCrc(*summaryLSA, crcMode);
1168  return summaryLSA;
1169  }
1170  }
1171  else { // entry->getPathType() == Ospfv2RoutingTableEntry::INTRAAREA
1172  Ipv4AddressRange destinationAddressRange;
1173 
1174  destinationAddressRange.address = entry->getDestination();
1175  destinationAddressRange.mask = entry->getNetmask();
1176 
1177  bool doAdvertise = false;
1178  Ipv4AddressRange containingAddressRange = parentRouter->getContainingAddressRange(destinationAddressRange, &doAdvertise);
1179  if (((entry->getArea() == BACKBONE_AREAID) && // the backbone's configured ranges should be ignored
1180  (transitCapability)) || // when originating Summary LSAs into transit areas
1181  (containingAddressRange == NULL_IPV4ADDRESSRANGE))
1182  {
1183  LinkStateId newLinkStateID = getUniqueLinkStateID(destinationAddressRange, entry->getCost(), lsaToReoriginate);
1184 
1185  if (lsaToReoriginate != nullptr) {
1186  LsaKeyType lsaKey;
1187 
1188  lsaKey.linkStateID = entry->getDestination();
1189  lsaKey.advertisingRouter = parentRouter->getRouterID();
1190 
1191  auto lsaIt = summaryLSAsByID.find(lsaKey);
1192  if (lsaIt == summaryLSAsByID.end()) {
1193  delete lsaToReoriginate;
1194  lsaToReoriginate = nullptr;
1195  return nullptr;
1196  }
1197  else {
1198  SummaryLsa *summaryLSA = new SummaryLsa(*(lsaIt->second));
1199  Ospfv2LsaHeader& lsaHeader = summaryLSA->getHeaderForUpdate();
1200 
1201  lsaHeader.setLsAge(0);
1202  lsaHeader.setLsSequenceNumber(INITIAL_SEQUENCE_NUMBER);
1203  lsaHeader.setLinkStateID(newLinkStateID);
1204 
1205  // update the length field in the LSA header
1206  lsaHeader.setLsaLength(B(calculateLsaSize(*summaryLSA)).get());
1207 
1208  setLsaCrc(*summaryLSA, crcMode);
1209  return summaryLSA;
1210  }
1211  }
1212  else {
1213  SummaryLsa *summaryLSA = new SummaryLsa;
1214  Ospfv2LsaHeader& lsaHeader = summaryLSA->getHeaderForUpdate();
1215  Ospfv2Options lsOptions;
1216 
1217  lsaHeader.setLsAge(0);
1218  lsOptions.E_ExternalRoutingCapability = externalRoutingCapability;
1219  lsaHeader.setLsOptions(lsOptions);
1220  lsaHeader.setLsType(SUMMARYLSA_NETWORKS_TYPE);
1221  lsaHeader.setLinkStateID(newLinkStateID);
1222  lsaHeader.setAdvertisingRouter(Ipv4Address(parentRouter->getRouterID()));
1223  lsaHeader.setLsSequenceNumber(INITIAL_SEQUENCE_NUMBER);
1224 
1225  summaryLSA->setNetworkMask(entry->getNetmask());
1226  summaryLSA->setRouteCost(entry->getCost());
1227  summaryLSA->setTosDataArraySize(0);
1228 
1229  summaryLSA->setSource(LsaTrackingInfo::ORIGINATED);
1230 
1231  // update the length field in the LSA header
1232  lsaHeader.setLsaLength(B(calculateLsaSize(*summaryLSA)).get());
1233 
1234  setLsaCrc(*summaryLSA, crcMode);
1235  return summaryLSA;
1236  }
1237  }
1238  else {
1239  if (doAdvertise) {
1240  Metric maxRangeCost = 0;
1241  for (unsigned long i = 0; i < parentRouter->getRoutingTableEntryCount(); i++) {
1242  const Ospfv2RoutingTableEntry *routingEntry = parentRouter->getRoutingTableEntry(i);
1243  if ((routingEntry->getDestinationType() == Ospfv2RoutingTableEntry::NETWORK_DESTINATION) &&
1244  (routingEntry->getPathType() == Ospfv2RoutingTableEntry::INTRAAREA) &&
1245  containingAddressRange.containsRange(routingEntry->getDestination(), routingEntry->getNetmask()) &&
1246  (routingEntry->getCost() > maxRangeCost))
1247  {
1248  maxRangeCost = routingEntry->getCost();
1249  }
1250  }
1251 
1252  LinkStateId newLinkStateID = getUniqueLinkStateID(containingAddressRange, maxRangeCost, lsaToReoriginate);
1253  LsaKeyType lsaKey;
1254 
1255  if (lsaToReoriginate != nullptr) {
1256  lsaKey.linkStateID = lsaToReoriginate->getHeader().getLinkStateID();
1257  lsaKey.advertisingRouter = parentRouter->getRouterID();
1258 
1259  auto originatedIt = originatedLSAs.find(lsaKey);
1260  if (originatedIt != originatedLSAs.end()) {
1261  delete lsaToReoriginate;
1262  lsaToReoriginate = nullptr;
1263  return nullptr;
1264  }
1265 
1266  lsaKey.linkStateID = entry->getDestination();
1267  lsaKey.advertisingRouter = parentRouter->getRouterID();
1268 
1269  auto lsaIt = summaryLSAsByID.find(lsaKey);
1270  if (lsaIt == summaryLSAsByID.end()) {
1271  delete lsaToReoriginate;
1272  lsaToReoriginate = nullptr;
1273  return nullptr;
1274  }
1275 
1276  SummaryLsa *summaryLSA = new SummaryLsa(*(lsaIt->second));
1277  Ospfv2LsaHeader& lsaHeader = summaryLSA->getHeaderForUpdate();
1278 
1279  lsaHeader.setLsAge(0);
1280  lsaHeader.setLsSequenceNumber(INITIAL_SEQUENCE_NUMBER);
1281  lsaHeader.setLinkStateID(newLinkStateID);
1282 
1283  // update the length field in the LSA header
1284  lsaHeader.setLsaLength(B(calculateLsaSize(*summaryLSA)).get());
1285 
1286  setLsaCrc(*summaryLSA, crcMode);
1287  return summaryLSA;
1288  }
1289  else {
1290  lsaKey.linkStateID = newLinkStateID;
1291  lsaKey.advertisingRouter = parentRouter->getRouterID();
1292 
1293  auto originatedIt = originatedLSAs.find(lsaKey);
1294  if (originatedIt != originatedLSAs.end()) {
1295  return nullptr;
1296  }
1297 
1298  SummaryLsa *summaryLSA = new SummaryLsa;
1299  Ospfv2LsaHeader& lsaHeader = summaryLSA->getHeaderForUpdate();
1300  Ospfv2Options lsOptions;
1301 
1302  lsaHeader.setLsAge(0);
1303  lsOptions.E_ExternalRoutingCapability = externalRoutingCapability;
1304  lsaHeader.setLsOptions(lsOptions);
1305  lsaHeader.setLsType(SUMMARYLSA_NETWORKS_TYPE);
1306  lsaHeader.setLinkStateID(newLinkStateID);
1307  lsaHeader.setAdvertisingRouter(Ipv4Address(parentRouter->getRouterID()));
1308  lsaHeader.setLsSequenceNumber(INITIAL_SEQUENCE_NUMBER);
1309 
1310 // summaryLSA->setNetworkMask(entry->getNetmask());
1311  summaryLSA->setNetworkMask(containingAddressRange.mask);
1312  summaryLSA->setRouteCost(entry->getCost());
1313  summaryLSA->setTosDataArraySize(0);
1314 
1315  summaryLSA->setSource(LsaTrackingInfo::ORIGINATED);
1316 
1317  // update the length field in the LSA header
1318  lsaHeader.setLsaLength(B(calculateLsaSize(*summaryLSA)).get());
1319 
1320  setLsaCrc(*summaryLSA, crcMode);
1321  return summaryLSA;
1322  }
1323  }
1324  }
1325  }
1326  }
1327 
1328  return nullptr;
1329 }

Referenced by ageDatabase(), and originateSummaryLSA().

◆ originateSummaryLSA() [2/2]

SummaryLsa * inet::ospfv2::Ospfv2Area::originateSummaryLSA ( const SummaryLsa summaryLSA)
private
1359 {
1360  const std::map<LsaKeyType, bool, LsaKeyType_Less> emptyMap;
1361  SummaryLsa *dontReoriginate = nullptr;
1362 
1363  const Ospfv2LsaHeader& lsaHeader = summaryLSA->getHeader();
1364  unsigned long entryCount = parentRouter->getRoutingTableEntryCount();
1365 
1366  for (unsigned long i = 0; i < entryCount; i++) {
1367  const Ospfv2RoutingTableEntry *entry = parentRouter->getRoutingTableEntry(i);
1368 
1369  if ((lsaHeader.getLsType() == SUMMARYLSA_ASBOUNDARYROUTERS_TYPE) &&
1370  ((((entry->getDestinationType() & Ospfv2RoutingTableEntry::AREA_BORDER_ROUTER_DESTINATION) != 0) ||
1371  ((entry->getDestinationType() & Ospfv2RoutingTableEntry::AS_BOUNDARY_ROUTER_DESTINATION) != 0)) &&
1372  ((entry->getDestination() == lsaHeader.getLinkStateID()) && // FIXME Why not compare network addresses (addr masked with netmask)?
1373  (entry->getNetmask() == summaryLSA->getNetworkMask()))))
1374  {
1375  SummaryLsa *returnLSA = originateSummaryLSA(entry, emptyMap, dontReoriginate);
1376  if (dontReoriginate != nullptr) {
1377  delete dontReoriginate;
1378  }
1379  return returnLSA;
1380  }
1381 
1382  Ipv4Address lsaMask = summaryLSA->getNetworkMask();
1383 
1384  if ((lsaHeader.getLsType() == SUMMARYLSA_NETWORKS_TYPE) &&
1385  (entry->getDestinationType() == Ospfv2RoutingTableEntry::NETWORK_DESTINATION) &&
1386  isSameNetwork(entry->getDestination(), entry->getNetmask(), lsaHeader.getLinkStateID(), lsaMask))
1387  {
1388  SummaryLsa *returnLSA = originateSummaryLSA(entry, emptyMap, dontReoriginate);
1389  if (dontReoriginate != nullptr) {
1390  delete dontReoriginate;
1391  }
1392  return returnLSA;
1393  }
1394  }
1395 
1396  return nullptr;
1397 }

◆ originateSummaryLSA_Stub()

SummaryLsa * inet::ospfv2::Ospfv2Area::originateSummaryLSA_Stub ( )
1332 {
1333  SummaryLsa *summaryLSA = new SummaryLsa;
1334  Ospfv2LsaHeader& lsaHeader = summaryLSA->getHeaderForUpdate();
1335  Ospfv2Options lsOptions;
1336 
1337  lsaHeader.setLsAge(0);
1338  lsOptions.E_ExternalRoutingCapability = externalRoutingCapability;
1339  lsaHeader.setLsOptions(lsOptions);
1340  lsaHeader.setLsType(SUMMARYLSA_NETWORKS_TYPE);
1341  lsaHeader.setLinkStateID(Ipv4Address("0.0.0.0"));
1342  lsaHeader.setAdvertisingRouter(Ipv4Address(parentRouter->getRouterID()));
1343  lsaHeader.setLsSequenceNumber(INITIAL_SEQUENCE_NUMBER);
1344 
1345  summaryLSA->setNetworkMask(Ipv4Address("0.0.0.0"));
1346  summaryLSA->setRouteCost(stubDefaultCost);
1347  summaryLSA->setTosDataArraySize(0);
1348 
1349  summaryLSA->setSource(LsaTrackingInfo::ORIGINATED);
1350 
1351  // update the length field in the LSA header
1352  lsaHeader.setLsaLength(B(calculateLsaSize(*summaryLSA)).get());
1353 
1354  setLsaCrc(*summaryLSA, crcMode);
1355  return summaryLSA;
1356 }

◆ printLSDB()

void inet::ospfv2::Ospfv2Area::printLSDB ( )
private
2510 {
2511  // iterate over all routerLSA in all routers inside this area
2512  for (uint32_t i = 0; i < routerLSAs.size(); i++) {
2513  Ospfv2RouterLsa *entry = check_and_cast<Ospfv2RouterLsa *>(routerLSAs[i]);
2514 
2515  const Ospfv2LsaHeader& head = entry->getHeader();
2516  std::string routerId = head.getAdvertisingRouter().str(false);
2517  EV_DETAIL << "Router LSA in Area " << areaID.str(false) << " in OSPF router with ID " << routerId << std::endl;
2518 
2519  // print header info
2520  EV_DETAIL << " LS age: " << head.getLsAge() << std::endl;
2521  EV_DETAIL << " LS type: " << head.getLsType() << std::endl;
2522  EV_DETAIL << " Link state ID: " << head.getLinkStateID() << std::endl;
2523  EV_DETAIL << " Advertising router: " << head.getAdvertisingRouter() << std::endl;
2524  EV_DETAIL << " Seq number: " << head.getLsSequenceNumber() << std::endl;
2525  EV_DETAIL << " Length: " << head.getLsaLength() << std::endl;
2526 
2527  EV_DETAIL << " Number of links: " << entry->getLinksArraySize() << std::endl << std::endl;
2528  for (unsigned int j = 0; j < entry->getLinksArraySize(); j++) {
2529  const auto& lEntry = entry->getLinks(j);
2530  LinkType linkType = static_cast<LinkType>(lEntry.getType());
2531  if (linkType == POINTTOPOINT_LINK) {
2532  EV_DETAIL << " Link connected to: another router (point-to-point)" << std::endl;
2533  EV_DETAIL << " Neighboring router ID (link ID): " << lEntry.getLinkID() << std::endl;
2534  EV_DETAIL << " Router interface address (link data): " << Ipv4Address(lEntry.getLinkData()).str(false) << std::endl;
2535  EV_DETAIL << " Link cost: " << lEntry.getLinkCost() << std::endl;
2536  }
2537  else if (linkType == TRANSIT_LINK) {
2538  EV_DETAIL << " Link connected to: a transit network" << std::endl;
2539  EV_DETAIL << " DR address (link ID): " << lEntry.getLinkID() << std::endl;
2540  EV_DETAIL << " Router interface address (link data): " << Ipv4Address(lEntry.getLinkData()).str(false) << std::endl;
2541  EV_DETAIL << " Link cost: " << lEntry.getLinkCost() << std::endl;
2542  }
2543  else if (linkType == STUB_LINK) {
2544  EV_DETAIL << " Link connected to: a stub network" << std::endl;
2545  EV_DETAIL << " Network/subnet number (link ID): " << lEntry.getLinkID() << std::endl;
2546  EV_DETAIL << " Network mask (link data): " << Ipv4Address(lEntry.getLinkData()).str(false) << std::endl;
2547  EV_DETAIL << " Link cost: " << lEntry.getLinkCost() << std::endl;
2548  }
2549  else {
2550  EV_DETAIL << " Link connected to: a virtual link" << std::endl;
2551  }
2552  EV_DETAIL << std::endl;
2553  }
2554  }
2555 
2556  // iterate over all networkLSA in all routers inside this area
2557  for (unsigned int i = 0; i < networkLSAs.size(); i++) {
2558  EV_DETAIL << "Network LSA in Area " << areaID.str(false) << std::endl;
2559  Ospfv2NetworkLsa *entry = check_and_cast<Ospfv2NetworkLsa *>(networkLSAs[i]);
2560 
2561  // print header info
2562  const Ospfv2LsaHeader& head = entry->getHeader();
2563  EV_DETAIL << " LS age: " << head.getLsAge() << std::endl;
2564  EV_DETAIL << " LS type: " << head.getLsType() << std::endl;
2565  EV_DETAIL << " Link state ID: " << head.getLinkStateID() << std::endl;
2566  EV_DETAIL << " Advertising router: " << head.getAdvertisingRouter() << std::endl;
2567  EV_DETAIL << " Seq number: " << head.getLsSequenceNumber() << std::endl;
2568  EV_DETAIL << " Length: " << head.getLsaLength() << std::endl;
2569 
2570  EV_DETAIL << " Number of attached routers: " << entry->getAttachedRoutersArraySize() << std::endl;
2571  for (unsigned int j = 0; j < entry->getAttachedRoutersArraySize(); j++)
2572  EV_DETAIL << " Attached router: " << entry->getAttachedRouters(j) << std::endl;
2573  EV_DETAIL << std::endl;
2574  }
2575 }

Referenced by calculateShortestPathTree().

◆ printSummaryLsa()

void inet::ospfv2::Ospfv2Area::printSummaryLsa ( )
private
2578 {
2579  for (uint32_t i = 0; i < summaryLSAs.size(); i++) {
2580  Ospfv2SummaryLsa *entry = check_and_cast<Ospfv2SummaryLsa *>(summaryLSAs[i]);
2581 
2582  const Ospfv2LsaHeader& head = entry->getHeader();
2583  std::string routerId = head.getAdvertisingRouter().str(false);
2584  EV_DETAIL << "Summary LSA from OSPF router with ID " << routerId << std::endl;
2585 
2586  // print header info
2587  EV_DETAIL << " LS age: " << head.getLsAge() << std::endl;
2588  EV_DETAIL << " LS type: " << head.getLsType() << std::endl;
2589  EV_DETAIL << " Link state ID (IP network): " << head.getLinkStateID().str(false) << std::endl;
2590  EV_DETAIL << " Advertising router: " << head.getAdvertisingRouter() << std::endl;
2591  EV_DETAIL << " Seq number: " << head.getLsSequenceNumber() << std::endl;
2592  EV_DETAIL << " Length: " << head.getLsaLength() << std::endl;
2593 
2594  EV_DETAIL << " Network Mask: " << entry->getNetworkMask().str(false) << std::endl;
2595  EV_DETAIL << " Metric: " << entry->getRouteCost() << std::endl;
2596  EV_DETAIL << std::endl;
2597  }
2598 }

Referenced by calculateInterAreaRoutes().

◆ recheckSummaryLSAs()

void inet::ospfv2::Ospfv2Area::recheckSummaryLSAs ( std::vector< Ospfv2RoutingTableEntry * > &  newRoutingTable)
2413 {
2414  for (uint32_t i = 0; i < summaryLSAs.size(); i++) {
2415  SummaryLsa *currentLSA = summaryLSAs[i];
2416  const Ospfv2LsaHeader& currentHeader = currentLSA->getHeader();
2417 
2418  unsigned long routeCost = currentLSA->getRouteCost();
2419  unsigned short lsAge = currentHeader.getLsAge();
2420  RouterId originatingRouter = currentHeader.getAdvertisingRouter();
2421  bool selfOriginated = (originatingRouter == parentRouter->getRouterID());
2422 
2423  if ((routeCost == LS_INFINITY) || (lsAge == MAX_AGE) || (selfOriginated)) { // (1) and(2)
2424  continue;
2425  }
2426 
2427  unsigned long routeCount = newRoutingTable.size();
2428  char lsType = currentHeader.getLsType();
2429  Ospfv2RoutingTableEntry *destinationEntry = nullptr;
2430  Ipv4AddressRange destination;
2431 
2432  destination.address = currentHeader.getLinkStateID();
2433  destination.mask = currentLSA->getNetworkMask();
2434 
2435  for (uint32_t j = 0; j < routeCount; j++) { // (3)
2436  Ospfv2RoutingTableEntry *routingEntry = newRoutingTable[j];
2437  bool foundMatching = false;
2438 
2439  if (lsType == SUMMARYLSA_NETWORKS_TYPE) {
2440  if ((routingEntry->getDestinationType() == Ospfv2RoutingTableEntry::NETWORK_DESTINATION) &&
2441  ((destination.address & destination.mask) == routingEntry->getDestination()))
2442  {
2443  foundMatching = true;
2444  }
2445  }
2446  else {
2447  if ((((routingEntry->getDestinationType() & Ospfv2RoutingTableEntry::AREA_BORDER_ROUTER_DESTINATION) != 0) ||
2448  ((routingEntry->getDestinationType() & Ospfv2RoutingTableEntry::AS_BOUNDARY_ROUTER_DESTINATION) != 0)) &&
2449  (destination.address == routingEntry->getDestination()))
2450  {
2451  foundMatching = true;
2452  }
2453  }
2454 
2455  if (foundMatching) {
2456  Ospfv2RoutingTableEntry::RoutingPathType pathType = routingEntry->getPathType();
2457 
2458  if ((pathType == Ospfv2RoutingTableEntry::TYPE1_EXTERNAL) ||
2460  (routingEntry->getArea() != BACKBONE_AREAID))
2461  {
2462  break;
2463  }
2464  else {
2465  destinationEntry = routingEntry;
2466  break;
2467  }
2468  }
2469  }
2470  if (destinationEntry == nullptr) {
2471  continue;
2472  }
2473 
2474  Ospfv2RoutingTableEntry *borderRouterEntry = nullptr;
2475  unsigned short currentCost = routeCost;
2476 
2477  for (uint32_t j = 0; j < routeCount; j++) { // (4) BR == borderRouterEntry
2478  Ospfv2RoutingTableEntry *routingEntry = newRoutingTable[j];
2479 
2480  if ((routingEntry->getArea() == areaID) &&
2481  (((routingEntry->getDestinationType() & Ospfv2RoutingTableEntry::AREA_BORDER_ROUTER_DESTINATION) != 0) ||
2482  ((routingEntry->getDestinationType() & Ospfv2RoutingTableEntry::AS_BOUNDARY_ROUTER_DESTINATION) != 0)) &&
2483  (routingEntry->getDestination() == originatingRouter))
2484  {
2485  borderRouterEntry = routingEntry;
2486  currentCost += borderRouterEntry->getCost();
2487  break;
2488  }
2489  }
2490  if (borderRouterEntry == nullptr) {
2491  continue;
2492  }
2493  else { // (5)
2494  if (currentCost <= destinationEntry->getCost()) {
2495  if (currentCost < destinationEntry->getCost()) {
2496  destinationEntry->clearNextHops();
2497  }
2498 
2499  unsigned long nextHopCount = borderRouterEntry->getNextHopCount();
2500 
2501  for (uint32_t j = 0; j < nextHopCount; j++) {
2502  destinationEntry->addNextHop(borderRouterEntry->getNextHop(j));
2503  }
2504  }
2505  }
2506  }
2507 }

◆ removeFromAllRetransmissionLists()

void inet::ospfv2::Ospfv2Area::removeFromAllRetransmissionLists ( LsaKeyType  lsaKey)
669 {
670  for (uint32_t i = 0; i < associatedInterfaces.size(); i++)
672 }

Referenced by installNetworkLSA(), installRouterLSA(), and installSummaryLSA().

◆ setAreaID()

void inet::ospfv2::Ospfv2Area::setAreaID ( AreaId  areaId)
inline
52 { areaID = areaId; }

◆ setExternalRoutingCapability()

void inet::ospfv2::Ospfv2Area::setExternalRoutingCapability ( bool  flooded)
inline

◆ setRouter()

void inet::ospfv2::Ospfv2Area::setRouter ( Router router)
inline
68 { parentRouter = router; }

Referenced by inet::ospfv2::Router::addArea().

◆ setSPFTreeRoot()

void inet::ospfv2::Ospfv2Area::setSPFTreeRoot ( RouterLsa root)
inline

◆ setStubDefaultCost()

void inet::ospfv2::Ospfv2Area::setStubDefaultCost ( Metric  cost)
inline

◆ setTransitCapability()

void inet::ospfv2::Ospfv2Area::setTransitCapability ( bool  transit)
inline
58 { transitCapability = transit; }

◆ str()

std::string inet::ospfv2::Ospfv2Area::str ( ) const
override
107 {
108  return areaID.str(false);
109 }

Member Data Documentation

◆ advertiseAddressRanges

std::map<Ipv4AddressRange, bool> inet::ospfv2::Ospfv2Area::advertiseAddressRanges
private

◆ areaAddressRanges

std::vector<Ipv4AddressRange> inet::ospfv2::Ospfv2Area::areaAddressRanges
private

◆ areaID

◆ associatedInterfaces

◆ crcMode

CrcMode inet::ospfv2::Ospfv2Area::crcMode
private

◆ externalRoutingCapability

bool inet::ospfv2::Ospfv2Area::externalRoutingCapability
private

◆ hostRoutes

std::vector<HostRouteParameters> inet::ospfv2::Ospfv2Area::hostRoutes
private

◆ ift

IInterfaceTable* inet::ospfv2::Ospfv2Area::ift
private

◆ networkLSAs

std::vector<NetworkLsa *> inet::ospfv2::Ospfv2Area::networkLSAs
private

◆ networkLSAsByID

std::map<LinkStateId, NetworkLsa *> inet::ospfv2::Ospfv2Area::networkLSAsByID
private

◆ parentRouter

◆ routerLSAs

std::vector<RouterLsa *> inet::ospfv2::Ospfv2Area::routerLSAs
private

◆ routerLSAsByID

std::map<LinkStateId, RouterLsa *> inet::ospfv2::Ospfv2Area::routerLSAsByID
private

◆ spfTreeRoot

RouterLsa* inet::ospfv2::Ospfv2Area::spfTreeRoot
private

◆ stubDefaultCost

Metric inet::ospfv2::Ospfv2Area::stubDefaultCost
private

Referenced by info(), and originateSummaryLSA_Stub().

◆ summaryLSAs

std::vector<SummaryLsa *> inet::ospfv2::Ospfv2Area::summaryLSAs
private

◆ summaryLSAsByID

std::map<LsaKeyType, SummaryLsa *, LsaKeyType_Less> inet::ospfv2::Ospfv2Area::summaryLSAsByID
private

◆ transitCapability

bool inet::ospfv2::Ospfv2Area::transitCapability
private

The documentation for this class was generated from the following files:
inet::ospfv2::RouterId
Ipv4Address RouterId
Definition: Ospfv2Common.h:129
inet::ospfv2::Neighbor::FULL_STATE
@ FULL_STATE
Definition: Ospfv2Neighbor.h:57
inet::ospfv2::Ospfv2Area::getInterface
Ospfv2Interface * getInterface(unsigned char ifIndex)
Definition: Ospfv2Area.cc:197
inet::units::value::str
std::string str() const
Definition: Units.h:101
inet::ospfv2::Ospfv2Area::associatedInterfaces
std::vector< Ospfv2Interface * > associatedInterfaces
Definition: Ospfv2Area.h:33
inet::ospfv2::Ospfv2Interface::POINTTOPOINT
@ POINTTOPOINT
Definition: Ospfv2Interface.h:32
inet::ospfv2::Ospfv2RoutingTableEntry::getCost
Metric getCost() const
Definition: Ospfv2RoutingTableEntry.h:68
inet::ospfv2::Ospfv2Area::calculateNextHops
std::vector< NextHop > * calculateNextHops(Ospfv2Lsa *destination, Ospfv2Lsa *parent) const
Definition: Ospfv2Area.cc:1889
inet::ospfv2::Ospfv2Area::findNetworkLSA
NetworkLsa * findNetworkLSA(LinkStateId linkStateID)
Definition: Ospfv2Area.cc:340
inet::ospfv2::STUB_LINK
@ STUB_LINK
Definition: Ospfv2Packet_m.h:432
inet::ospfv2::Ospfv2Interface::Ospfv2InterfaceType
Ospfv2InterfaceType
Definition: Ospfv2Interface.h:30
inet::ospfv2::Ospfv2Interface::WAITING_STATE
@ WAITING_STATE
Definition: Ospfv2Interface.h:54
MAX_SEQUENCE_NUMBER
#define MAX_SEQUENCE_NUMBER
Definition: Ospfv2Common.h:34
inet::ospfv2::SUMMARYLSA_NETWORKS_TYPE
@ SUMMARYLSA_NETWORKS_TYPE
Definition: Ospfv2Packet_m.h:285
inet::ospfv2::Metric
unsigned long Metric
Definition: Ospfv2Common.h:56
inet::ospfv2::Router::getAreaCount
unsigned long getAreaCount() const
Definition: Ospfv2Router.h:63
inet::ospfv2::Ospfv2Area::parentRouter
Router * parentRouter
Definition: Ospfv2Area.h:46
inet::ospfv2::calculateLSASize
B calculateLSASize(const Ospfv2Lsa *lsa)
Definition: Lsa.cc:66
inet::ospfv2::Ospfv2Interface::getAddressRange
Ipv4AddressRange getAddressRange() const
Definition: Ospfv2Interface.h:167
inet::ospfv2::Ospfv2Interface::INTERFACE_UP
@ INTERFACE_UP
Definition: Ospfv2Interface.h:40
inet::ospfv2::Ospfv2Interface::DESIGNATED_ROUTER_STATE
@ DESIGNATED_ROUTER_STATE
Definition: Ospfv2Interface.h:58
inet::ospfv2::Ospfv2Area::isDefaultRoute
bool isDefaultRoute(Ospfv2RoutingTableEntry *entry) const
Definition: Ospfv2Area.cc:2600
inet::bgp::NextHop
Ipv4Address NextHop
Definition: BgpCommon.h:50
inet::ospfv2::Ospfv2Area::networkLSAs
std::vector< NetworkLsa * > networkLSAs
Definition: Ospfv2Area.h:38
inet::ospfv2::Ospfv2RoutingTableEntry::TYPE1_EXTERNAL
@ TYPE1_EXTERNAL
Definition: Ospfv2RoutingTableEntry.h:28
inet::ospfv2::Ospfv2LsaType
Ospfv2LsaType
Enum generated from inet/routing/ospfv2/Ospfv2Packet.msg:78 by opp_msgtool.
Definition: Ospfv2Packet_m.h:282
inet::ospfv2::NULL_IPV4ADDRESSRANGE
const Ipv4AddressRange NULL_IPV4ADDRESSRANGE(Ipv4Address(0, 0, 0, 0), Ipv4Address(0, 0, 0, 0))
inet::ospfv2::ROUTERLSA_TYPE
@ ROUTERLSA_TYPE
Definition: Ospfv2Packet_m.h:283
inet::ospfv2::Ospfv2Area::hasAnyNeighborInStates
bool hasAnyNeighborInStates(int states) const
Definition: Ospfv2Area.cc:659
MAX_AGE
#define MAX_AGE
Definition: Ospfv2Common.h:27
inet::ospfv2::Router::getASBoundaryRouter
bool getASBoundaryRouter() const
Definition: Ospfv2Router.h:71
inet::ospfv2::Ospfv2RoutingTableEntry::AREA_BORDER_ROUTER_DESTINATION
static const unsigned char AREA_BORDER_ROUTER_DESTINATION
Definition: Ospfv2RoutingTableEntry.h:36
inet::ospfv2::NULL_IPV4ADDRESS
const Ipv4Address NULL_IPV4ADDRESS(0, 0, 0, 0)
inet::math::head
T head(const Point< T, TS ... > &p)
Returns the first coordinate of p.
Definition: Point.h:222
inet::ospfv2::Ospfv2Area::spfTreeRoot
RouterLsa * spfTreeRoot
Definition: Ospfv2Area.h:44
inet::ospfv2::calculateLsaSize
B calculateLsaSize(const Ospfv2RouterLsa &lsa)
Definition: Lsa.cc:92
inet::ospfv2::Ospfv2Area::originateNetworkLSA
NetworkLsa * originateNetworkLSA(const Ospfv2Interface *intf)
Definition: Ospfv2Area.cc:948
inet::ospfv2::Ospfv2RoutingTableEntry::NETWORK_DESTINATION
static const unsigned char NETWORK_DESTINATION
Definition: Ospfv2RoutingTableEntry.h:35
inet::ospfv2::Ospfv2Area::findRouterLSA
RouterLsa * findRouterLSA(LinkStateId linkStateID)
Definition: Ospfv2Area.cc:328
inet::ospfv2::Router::rebuildRoutingTable
void rebuildRoutingTable()
Rebuilds the routing table from scratch(based on the LSA database).
Definition: Ospfv2Router.cc:663
inet::Ipv4Address::ALLONES_ADDRESS
static const Ipv4Address ALLONES_ADDRESS
255.255.255.255
Definition: Ipv4Address.h:94
inet::ospfv2::SUMMARYLSA_ASBOUNDARYROUTERS_TYPE
@ SUMMARYLSA_ASBOUNDARYROUTERS_TYPE
Definition: Ospfv2Packet_m.h:286
INITIAL_SEQUENCE_NUMBER
#define INITIAL_SEQUENCE_NUMBER
Definition: Ospfv2Common.h:33
inet::ospfv2::Ospfv2Area::summaryLSAsByID
std::map< LsaKeyType, SummaryLsa *, LsaKeyType_Less > summaryLSAsByID
Definition: Ospfv2Area.h:39
inet::ospfv2::BACKBONE_AREAID
const AreaId BACKBONE_AREAID(0, 0, 0, 0)
inet::ospfv2::Ospfv2Area::info
std::string info() const
Definition: Ospfv2Area.cc:111
inet::ospfv2::Router::getAreaByID
Ospfv2Area * getAreaByID(AreaId areaID)
Returns the pointer to the Area identified by the input areaID, if it's on the Area list,...
Definition: Ospfv2Router.cc:63
inet::ospfv2::Router::getNonVirtualInterface
Ospfv2Interface * getNonVirtualInterface(unsigned char ifIndex)
Returns the pointer of the physical Interface identified by the input interface index,...
Definition: Ospfv2Router.cc:89
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::ospfv2::Ospfv2Area::Ospfv2Area
Ospfv2Area(CrcMode crcMode, IInterfaceTable *ift, AreaId id=BACKBONE_AREAID)
Definition: Ospfv2Area.cc:19
inet::ospfv2::Ospfv2Area::networkLSAsByID
std::map< LinkStateId, NetworkLsa * > networkLSAsByID
Definition: Ospfv2Area.h:37
inet::ospfv2::Ospfv2Interface::VIRTUAL
@ VIRTUAL
Definition: Ospfv2Interface.h:36
inet::ospfv2::Ospfv2Area::transitCapability
bool transitCapability
Definition: Ospfv2Area.h:41
inet::ospfv2::Ospfv2Area::areaAddressRanges
std::vector< Ipv4AddressRange > areaAddressRanges
Definition: Ospfv2Area.h:32
inet::contains
bool contains(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:65
inet::ospfv2::Ospfv2Area::summaryLSAs
std::vector< SummaryLsa * > summaryLSAs
Definition: Ospfv2Area.h:40
inet::ospfv2::Ospfv2Area::ift
IInterfaceTable * ift
Definition: Ospfv2Area.h:29
inet::ospfv2::Ospfv2RoutingTableEntry::INTERAREA
@ INTERAREA
Definition: Ospfv2RoutingTableEntry.h:27
inet::ospfv2::Router::getRoutingTableEntryCount
unsigned long getRoutingTableEntryCount() const
Definition: Ospfv2Router.h:73
inet::ospfv2::Ospfv2Area::getAddressRange
Ipv4AddressRange getAddressRange(unsigned int index) const
Definition: Ospfv2Area.h:56
inet::ospfv2::Ospfv2Area::hostRoutes
std::vector< HostRouteParameters > hostRoutes
Definition: Ospfv2Area.h:34
inet::ospfv2::VIRTUAL_LINK
@ VIRTUAL_LINK
Definition: Ospfv2Packet_m.h:433
inet::ospfv2::Ospfv2Interface::NBMA
@ NBMA
Definition: Ospfv2Interface.h:34
inet::ospfv2::RoutingInfo::setDistance
void setDistance(unsigned long d)
Definition: Lsa.h:44
inet::ospfv2::LinkStateId
Ipv4Address LinkStateId
Definition: Ospfv2Common.h:131
inet::ospfv2::Ospfv2Area::isOnAnyRetransmissionList
bool isOnAnyRetransmissionList(LsaKeyType lsaKey) const
Definition: Ospfv2Area.cc:674
inet::ospfv2::Ospfv2Area::originateRouterLSA
RouterLsa * originateRouterLSA()
Definition: Ospfv2Area.cc:703
inet::ospfv2::Ospfv2Area::routerLSAsByID
std::map< LinkStateId, RouterLsa * > routerLSAsByID
Definition: Ospfv2Area.h:35
inet::ospfv2::Neighbor::EXCHANGE_STATE
@ EXCHANGE_STATE
Definition: Ospfv2Neighbor.h:55
inet::ospfv2::Ospfv2Area::hasLink
bool hasLink(Ospfv2Lsa *fromLSA, Ospfv2Lsa *toLSA) const
Definition: Ospfv2Area.cc:2118
inet::Ipv4Address::str
std::string str(bool printUnspec=true) const
Returns the string representation of the address (e.g.
Definition: Ipv4Address.cc:98
inet::ospfv2::Ospfv2Area::floodLSA
bool floodLSA(const Ospfv2Lsa *lsa, Ospfv2Interface *intf=nullptr, Neighbor *neighbor=nullptr)
Definition: Ospfv2Area.cc:683
inet::ospfv2::Router::getRouterID
RouterId getRouterID() const
Definition: Ospfv2Router.h:60
inet::ospfv2::Ospfv2RoutingTableEntry::AS_BOUNDARY_ROUTER_DESTINATION
static const unsigned char AS_BOUNDARY_ROUTER_DESTINATION
Definition: Ospfv2RoutingTableEntry.h:37
inet::ospfv2::Router::isDestinationUnreachable
bool isDestinationUnreachable(Ospfv2Lsa *lsa) const
Returns true if the destination described by the input lsa is in the routing table,...
Definition: Ospfv2Router.cc:483
inet::ospfv2::POINTTOPOINT_LINK
@ POINTTOPOINT_LINK
Definition: Ospfv2Packet_m.h:430
CHECK_AGE
#define CHECK_AGE
Definition: Ospfv2Common.h:28
inet::ospfv2::Ospfv2Area::getUniqueLinkStateID
LinkStateId getUniqueLinkStateID(Ipv4AddressRange destination, Metric destinationCost, SummaryLsa *&lsaToReoriginate) const
Returns a link state ID for the input destination.
Definition: Ospfv2Area.cc:1010
inet::ospfv2::Router::getRoutingTableEntry
Ospfv2RoutingTableEntry * getRoutingTableEntry(unsigned long i)
Definition: Ospfv2Router.h:74
inet::ospfv2::Ospfv2Area::printSummaryLsa
void printSummaryLsa()
Definition: Ospfv2Area.cc:2577
inet::ospfv2::Ospfv2Interface::POINTTOMULTIPOINT
@ POINTTOMULTIPOINT
Definition: Ospfv2Interface.h:35
inet::ospfv2::setLsaCrc
void setLsaCrc(Ospfv2Lsa &lsa, CrcMode crcMode)
Definition: Ospfv2Crc.cc:49
inet::ospfv2::Ospfv2Area::externalRoutingCapability
bool externalRoutingCapability
Definition: Ospfv2Area.h:42
inet::ospfv2::Router::getPreferredEntry
Ospfv2RoutingTableEntry * getPreferredEntry(const Ospfv2Lsa &lsa, bool skipSelfOriginated, std::vector< Ospfv2RoutingTableEntry * > *fromRoutingTable=nullptr)
Selects the preferred routing table entry for the input LSA(which is either an AsExternalLsa or a Sum...
Definition: Ospfv2Router.cc:889
inet::ospfv2::LsaTrackingInfo::ORIGINATED
@ ORIGINATED
Definition: Lsa.h:54
inet::ospfv2::Ospfv2Area::routerLSAs
std::vector< RouterLsa * > routerLSAs
Definition: Ospfv2Area.h:36
inet::ospfv2::Ospfv2Area::findSummaryLSA
SummaryLsa * findSummaryLSA(LsaKeyType lsaKey)
Definition: Ospfv2Area.cc:352
inet::ospfv2::Ospfv2Area::printLSDB
void printLSDB()
Definition: Ospfv2Area.cc:2509
LS_INFINITY
#define LS_INFINITY
Definition: Ted.cc:23
inet::Ipv4Address::getNetworkMask
Ipv4Address getNetworkMask() const
Returns an address with the network mask corresponding to the address class.
Definition: Ipv4Address.cc:178
inet::Ipv4Address::UNSPECIFIED_ADDRESS
static const Ipv4Address UNSPECIFIED_ADDRESS
0.0.0.0
Definition: Ipv4Address.h:91
inet::ospfv2::Ospfv2Interface::LOOPBACK_STATE
@ LOOPBACK_STATE
Definition: Ospfv2Interface.h:53
inet::ospfv2::Ospfv2Interface::POINTTOPOINT_STATE
@ POINTTOPOINT_STATE
Definition: Ospfv2Interface.h:55
inet::ospfv2::Ospfv2Area::advertiseAddressRanges
std::map< Ipv4AddressRange, bool > advertiseAddressRanges
Definition: Ospfv2Area.h:31
inet::units::value::get
const value_type & get() const
Definition: Units.h:108
inet::ospfv2::LinkType
LinkType
Enum generated from inet/routing/ospfv2/Ospfv2Packet.msg:113 by opp_msgtool.
Definition: Ospfv2Packet_m.h:429
inet::ospfv2::Ospfv2Area::originateSummaryLSA
SummaryLsa * originateSummaryLSA(const Ospfv2RoutingTableEntry *entry, const std::map< LsaKeyType, bool, LsaKeyType_Less > &originatedLSAs, SummaryLsa *&lsaToReoriginate)
Definition: Ospfv2Area.cc:1057
inet::ospfv2::Ipv4AddressRange::address
Ipv4Address address
Definition: Ospfv2Common.h:71
inet::ospfv2::Ospfv2RoutingTableEntry::RoutingDestinationType
unsigned char RoutingDestinationType
Definition: Ospfv2RoutingTableEntry.h:32
inet::ospfv2::Ospfv2Area::removeFromAllRetransmissionLists
void removeFromAllRetransmissionLists(LsaKeyType lsaKey)
Definition: Ospfv2Area.cc:668
inet::ospfv2::NETWORKLSA_TYPE
@ NETWORKLSA_TYPE
Definition: Ospfv2Packet_m.h:284
inet::ospfv2::Ospfv2Area::areaID
AreaId areaID
Definition: Ospfv2Area.h:30
inet::ospfv2::Neighbor::LOADING_STATE
@ LOADING_STATE
Definition: Ospfv2Neighbor.h:56
inet::ospfv2::Ospfv2Interface::BROADCAST
@ BROADCAST
Definition: Ospfv2Interface.h:33
inet::ospfv2::TRANSIT_LINK
@ TRANSIT_LINK
Definition: Ospfv2Packet_m.h:431
inet::ospfv2::Ospfv2Area::createRoutingTableEntryFromSummaryLSA
Ospfv2RoutingTableEntry * createRoutingTableEntryFromSummaryLSA(const SummaryLsa &summaryLSA, unsigned short entryCost, const Ospfv2RoutingTableEntry &borderRouterEntry) const
Returns a new Ospfv2RoutingTableEntry based on the input SummaryLsa, with the input cost and the bord...
Definition: Ospfv2Area.cc:2249
inet::units::values::m
value< double, units::m > m
Definition: Units.h:1233
inet::ospfv2::Ospfv2Area::isAllZero
bool isAllZero(Ipv4AddressRange entry) const
Definition: Ospfv2Area.cc:2607
inet::ospfv2::Router::getContainingAddressRange
Ipv4AddressRange getContainingAddressRange(const Ipv4AddressRange &addressRange, bool *advertise=nullptr) const
Scans through the router's areas' preconfigured address ranges and returns the one containing the inp...
Definition: Ospfv2Router.cc:1077
inet::ospfv2::Ospfv2RoutingTableEntry::INTRAAREA
@ INTRAAREA
Definition: Ospfv2RoutingTableEntry.h:26
inet::ospfv2::Router::hasAddressRange
bool hasAddressRange(const Ipv4AddressRange &addressRange) const
Returns true if one of the Router's Areas the same Ipv4 address range configured as the input Ipv4 ad...
Definition: Ospfv2Router.cc:457
inet::ospfv2::Ospfv2Area::crcMode
CrcMode crcMode
Definition: Ospfv2Area.h:28
inet::ospfv2::Ospfv2Interface::DOWN_STATE
@ DOWN_STATE
Definition: Ospfv2Interface.h:52
inet::ospfv2::Ospfv2RoutingTableEntry::TYPE2_EXTERNAL
@ TYPE2_EXTERNAL
Definition: Ospfv2RoutingTableEntry.h:29
LS_REFRESH_TIME
#define LS_REFRESH_TIME
Definition: Ospfv2Common.h:24
inet::ospfv2::Ospfv2RoutingTableEntry::RoutingPathType
RoutingPathType
Definition: Ospfv2RoutingTableEntry.h:25
inet::ospfv2::Ospfv2Area::findVirtualLink
Ospfv2Interface * findVirtualLink(RouterId routerID)
Definition: Ospfv2Area.cc:248
inet::ospfv2::Ospfv2Area::stubDefaultCost
Metric stubDefaultCost
Definition: Ospfv2Area.h:43
inet::ospfv2::isSameNetwork
bool isSameNetwork(Ipv4Address address1, Ipv4Address mask1, Ipv4Address address2, Ipv4Address mask2)
Definition: Ospfv2Common.h:174
inet::ospfv2::Ospfv2Area::findSameOrWorseCostRoute
bool findSameOrWorseCostRoute(const std::vector< Ospfv2RoutingTableEntry * > &newRoutingTable, const SummaryLsa &currentLSA, unsigned short currentCost, bool &destinationInRoutingTable, std::list< Ospfv2RoutingTableEntry * > &sameOrWorseCost) const
Browse through the newRoutingTable looking for entries describing the same destination as the current...
Definition: Ospfv2Area.cc:2182
inet::ospfv2::Ospfv2Area::installRouterLSA
bool installRouterLSA(const Ospfv2RouterLsa *lsa)
Definition: Ospfv2Area.cc:261