|
INET Framework for OMNeT++/OMNEST
|
All OSPF classes are in this namespace.
More...
#include <Ospfv2Router.h>
|
| | Router (cSimpleModule *containingModule, IInterfaceTable *ift, IIpv4RoutingTable *rt) |
| | Constructor. More...
|
| |
| virtual | ~Router () |
| | Destructor. More...
|
| |
| void | setRouterID (RouterId id) |
| |
| RouterId | getRouterID () const |
| |
| void | setRFC1583Compatibility (bool compatibility) |
| |
| bool | getRFC1583Compatibility () const |
| |
| unsigned long | getAreaCount () const |
| |
| std::vector< AreaId > | getAreaIds () |
| |
| MessageHandler * | getMessageHandler () |
| |
| unsigned long | getASExternalLSACount () const |
| |
| AsExternalLsa * | getASExternalLSA (unsigned long i) |
| |
| const AsExternalLsa * | getASExternalLSA (unsigned long i) const |
| |
| bool | getASBoundaryRouter () const |
| |
| unsigned long | getRoutingTableEntryCount () const |
| |
| Ospfv2RoutingTableEntry * | getRoutingTableEntry (unsigned long i) |
| |
| const Ospfv2RoutingTableEntry * | getRoutingTableEntry (unsigned long i) const |
| |
| void | addRoutingTableEntry (Ospfv2RoutingTableEntry *entry) |
| |
| void | addWatches () |
| | Adds OMNeT++ watches for the routerID, the list of Areas and the list of AS External LSAs. More...
|
| |
| void | addArea (Ospfv2Area *area) |
| | Adds a new Area to the Area list. More...
|
| |
| Ospfv2Area * | getAreaByID (AreaId areaID) |
| | Returns the pointer to the Area identified by the input areaID, if it's on the Area list, nullptr otherwise. More...
|
| |
| Ospfv2Area * | getAreaByAddr (Ipv4Address address) |
| | Returns the Area pointer from the Area list which contains the input Ipv4 address, nullptr if there's no such area connected to the Router. More...
|
| |
| Ospfv2Interface * | getNonVirtualInterface (unsigned char ifIndex) |
| | Returns the pointer of the physical Interface identified by the input interface index, nullptr if the Router doesn't have such an interface. More...
|
| |
| bool | installLSA (const Ospfv2Lsa *lsa, AreaId areaID=BACKBONE_AREAID) |
| | Installs a new LSA into the Router database. More...
|
| |
| Ospfv2Lsa * | findLSA (Ospfv2LsaType lsaType, LsaKeyType lsaKey, AreaId areaID) |
| | Find the LSA identified by the input lsaKey in the database. More...
|
| |
| void | ageDatabase () |
| | Ages the LSAs in the Router's database. More...
|
| |
| bool | hasAnyNeighborInStates (int states) const |
| | Returns true if any Neighbor on any Interface in any of the Router's Areas is in any of the input states, false otherwise. More...
|
| |
| void | removeFromAllRetransmissionLists (LsaKeyType lsaKey) |
| | Removes all LSAs from all Neighbor's retransmission lists which are identified by the input lsaKey. More...
|
| |
| bool | isOnAnyRetransmissionList (LsaKeyType lsaKey) const |
| | Returns true if there's at least one LSA on any Neighbor's retransmission list identified by the input lsaKey, false otherwise. More...
|
| |
| bool | floodLSA (const Ospfv2Lsa *lsa, AreaId areaID=BACKBONE_AREAID, Ospfv2Interface *intf=nullptr, Neighbor *neighbor=nullptr) |
| | Floods out the input lsa on a set of Interfaces. More...
|
| |
| bool | isLocalAddress (Ipv4Address address) const |
| | Returns true if the input Ipv4 address falls into any of the Router's Areas' configured Ipv4 address ranges, false otherwise. More...
|
| |
| 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 address range, false otherwise. More...
|
| |
| bool | isDestinationUnreachable (Ospfv2Lsa *lsa) const |
| | Returns true if the destination described by the input lsa is in the routing table, false otherwise. More...
|
| |
| Ospfv2RoutingTableEntry * | lookup (Ipv4Address destination, std::vector< Ospfv2RoutingTableEntry * > *table=nullptr) const |
| | Do a lookup in either the input OSPF routing table, or if it's nullptr then in the Router's own routing table. More...
|
| |
| void | rebuildRoutingTable () |
| | Rebuilds the routing table from scratch(based on the LSA database). More...
|
| |
| bool | deleteRoute (Ospfv2RoutingTableEntry *entry) |
| |
| Ipv4AddressRange | getContainingAddressRange (const Ipv4AddressRange &addressRange, bool *advertise=nullptr) const |
| | Scans through the router's areas' preconfigured address ranges and returns the one containing the input addressRange. More...
|
| |
| Ipv4Route * | getDefaultRoute () |
| | get the default route in the routing table. More...
|
| |
| void | updateExternalRoute (Ipv4Address networkAddress, const Ospfv2AsExternalLsaContents &externalRouteContents, int ifIndex=-1) |
| | Stores information on an AS External Route in externalRoutes and intalls(or updates) a new AsExternalLsa into the database. More...
|
| |
| void | addExternalRouteInIPTable (Ipv4Address networkAddress, const Ospfv2AsExternalLsaContents &externalRouteContents, int ifIndex) |
| | Add an AS External Route in IPRoutingTable. More...
|
| |
| void | removeExternalRoute (Ipv4Address networkAddress) |
| | Removes an AS External Route from the database. More...
|
| |
| 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 SummaryLsa) according to the algorithm defined in RFC2328 Section 16.4. More...
|
| |
All OSPF classes are in this namespace.
Represents the full OSPF data structure as laid out in RFC2328.
◆ Router()
Constructor.
Initializes internal variables, adds a MessageHandler and starts the Database Age timer.
◆ ~Router()
| inet::ospfv2::Router::~Router |
( |
| ) |
|
|
virtual |
Destructor.
Clears all LSA lists and kills the Database Age timer.
31 long areaCount =
areas.size();
32 for (
long i = 0; i < areaCount; i++) {
36 for (
long j = 0; j < lsaCount; j++) {
40 for (
long k = 0;
k < routeCount;
k++) {
◆ addArea()
| void inet::ospfv2::Router::addArea |
( |
Ospfv2Area * |
area | ) |
|
◆ addExternalRouteInIPTable()
Add an AS External Route in IPRoutingTable.
- Parameters
-
| networkAddress | [in] The external route's network address. |
| externalRouteContents | [in] Route configuration data for the external route. |
| ifIndex | [in] |
1418 bool inRoutingTable =
false;
1421 if ((entry->getDestination() == networkAddress)
1422 && (entry->getNetmask() == externalRouteContents.getNetworkMask()))
1424 inRoutingTable =
true;
1429 if (!inRoutingTable) {
1430 Ipv4Route *entry =
new Ipv4Route();
1431 entry->setDestination(networkAddress);
1432 entry->setNetmask(externalRouteContents.getNetworkMask());
◆ addRoutingTableEntry()
◆ addWatches()
| void inet::ospfv2::Router::addWatches |
( |
| ) |
|
◆ ageDatabase()
| void inet::ospfv2::Router::ageDatabase |
( |
| ) |
|
Ages the LSAs in the Router's database.
This method is called on every firing of the DATABASE_AGE_TIMER(every second).
- See also
- RFC2328 Section 14.
281 bool shouldRebuildRoutingTable =
false;
283 for (
long i = 0; i < lsaCount; i++) {
289 if ((selfOriginated && (lsAge < (
LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (
MAX_AGE - 1)))) {
290 lsa->getHeaderForUpdate().setLsAge(lsAge + 1);
292 if (!lsa->validateLSChecksum()) {
293 EV_ERROR <<
"Invalid LS checksum. Memory error detected!\n";
296 lsa->incrementInstallTime();
300 lsa->getHeaderForUpdate().setLsAge(
MAX_AGE);
302 lsa->incrementInstallTime();
305 long sequenceNumber = lsa->getHeader().getLsSequenceNumber();
307 lsa->getHeaderForUpdate().setLsAge(
MAX_AGE);
309 lsa->incrementInstallTime();
314 newLSA->getHeaderForUpdate().setLsSequenceNumber(sequenceNumber + 1);
315 shouldRebuildRoutingTable |= lsa->update(newLSA);
322 if (!selfOriginated && (lsAge ==
MAX_AGE - 1)) {
323 lsa->getHeaderForUpdate().setLsAge(
MAX_AGE);
325 lsa->incrementInstallTime();
330 lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
331 lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter();
336 if (!selfOriginated || unreachable) {
340 shouldRebuildRoutingTable =
true;
343 if (lsa->getPurgeable()) {
347 shouldRebuildRoutingTable =
true;
351 long sequenceNumber = lsa->getHeader().getLsSequenceNumber();
354 shouldRebuildRoutingTable |= lsa->update(newLSA);
366 if ((*it) ==
nullptr) {
374 for (uint32_t j = 0; j <
areas.size(); j++)
379 if (shouldRebuildRoutingTable) {
Referenced by inet::ospfv2::MessageHandler::handleTimer().
◆ calculateASExternalRoutes()
Calculate the AS External Routes from the ASExternalLSAs in the database.
- Parameters
-
| newRoutingTable | [in/out] Push the new RoutingTableEntries into this routing table, and also use this for path calculations. |
- See also
- RFC2328 Section 16.4.
951 const Ospfv2LsaHeader& currentHeader = currentLSA->getHeader();
952 unsigned short externalCost = currentLSA->getContents().getExternalTOSInfo(0).routeCost;
953 RouterId originatingRouter = currentHeader.getAdvertisingRouter();
955 Ospfv2RoutingTableEntry *preferredEntry =
getPreferredEntry(*currentLSA,
true, &newRoutingTable);
959 Ipv4Address destination = currentHeader.getLinkStateID() & currentLSA->getContents().getNetworkMask();
961 Metric preferredCost = preferredEntry->getCost();
962 Ospfv2RoutingTableEntry *destinationEntry =
lookup(destination, &newRoutingTable);
963 if (destinationEntry ==
nullptr) {
964 bool type2ExternalMetric = currentLSA->getContents().getExternalTOSInfo(0).E_ExternalMetricType;
965 Ospfv2RoutingTableEntry *newEntry =
new Ospfv2RoutingTableEntry(
ift);
967 newEntry->setDestination(destination);
968 newEntry->setNetmask(currentLSA->getContents().getNetworkMask());
969 newEntry->setArea(preferredEntry->getArea());
971 if (type2ExternalMetric) {
972 newEntry->setCost(preferredCost);
973 newEntry->setType2Cost(externalCost);
976 newEntry->setCost(preferredCost + externalCost);
979 newEntry->setOptionalCapabilities(currentHeader.getLsOptions());
980 newEntry->setLinkStateOrigin(currentLSA);
982 for (
unsigned int j = 0; j < preferredEntry->getNextHopCount(); j++) {
983 NextHop nextHop = preferredEntry->getNextHop(j);
984 if (!nextHop.hopAddress.isUnspecified()) {
985 nextHop.advertisingRouter = originatingRouter;
986 newEntry->addNextHop(nextHop);
990 newRoutingTable.push_back(newEntry);
994 bool type2ExternalMetric = currentLSA->getContents().getExternalTOSInfo(0).E_ExternalMetricType;
995 unsigned int nextHopCount = preferredEntry->getNextHopCount();
1004 (type2ExternalMetric)) ||
1006 (type2ExternalMetric) &&
1007 (destinationEntry->getType2Cost() < externalCost)))
1012 Ospfv2RoutingTableEntry *destinationPreferredEntry =
getPreferredEntry(*(destinationEntry->getLinkStateOrigin()),
false, &newRoutingTable);
1023 (!type2ExternalMetric) &&
1024 (destinationEntry->getCost() < preferredCost + externalCost))) ||
1026 (type2ExternalMetric) &&
1027 (destinationEntry->getType2Cost() == externalCost) &&
1028 (destinationPreferredEntry->getCost() < preferredCost)))
1034 (!type2ExternalMetric) &&
1035 (destinationEntry->getCost() == (preferredCost + externalCost))) ||
1037 (type2ExternalMetric) &&
1038 (destinationEntry->getType2Cost() == externalCost) &&
1039 (destinationPreferredEntry->getCost() == preferredCost)))
1041 for (
unsigned int j = 0; j < nextHopCount; j++) {
1043 NextHop nextHop = preferredEntry->getNextHop(j);
1044 if (!nextHop.hopAddress.isUnspecified()) {
1045 nextHop.advertisingRouter = originatingRouter;
1046 destinationEntry->addNextHop(nextHop);
1053 destinationEntry->setArea(preferredEntry->getArea());
1055 if (type2ExternalMetric) {
1056 destinationEntry->setCost(preferredCost);
1057 destinationEntry->setType2Cost(externalCost);
1060 destinationEntry->setCost(preferredCost + externalCost);
1063 destinationEntry->setOptionalCapabilities(currentHeader.getLsOptions());
1064 destinationEntry->clearNextHops();
1066 for (
unsigned int j = 0; j < nextHopCount; j++) {
1067 NextHop nextHop = preferredEntry->getNextHop(j);
1068 if (!nextHop.hopAddress.isUnspecified()) {
1069 nextHop.advertisingRouter = originatingRouter;
1070 destinationEntry->addNextHop(nextHop);
Referenced by rebuildRoutingTable().
◆ deleteRoute()
◆ findASExternalLSA() [1/2]
Find the AS External LSA identified by the input lsaKey in the database.
- Parameters
-
| lsaKey | [in] Look for the AS External LSA which is identified by this key. |
- Returns
- The pointer to the AS External LSA if it was found, nullptr otherwise.
Referenced by findLSA(), and getUniqueLinkStateID().
◆ findASExternalLSA() [2/2]
Find the AS External LSA identified by the input lsaKey in the database.
- Parameters
-
| lsaKey | [in] Look for the AS External LSA which is identified by this key. |
- Returns
- The const pointer to the AS External LSA if it was found, nullptr otherwise.
◆ findLSA()
◆ floodLSA()
Floods out the input lsa on a set of Interfaces.
- See also
- RFC2328 Section 13.3.
- Parameters
-
| lsa | [in] The LSA to be flooded out. |
| areaID | [in] If the lsa is a Router, Network or Summary LSA, then flood it only in this Area. |
| intf | [in] The Interface this LSA arrived on. |
| neighbor | [in] The Nieghbor this LSA arrived from. |
- Returns
- True if the LSA was floooded back out on the receiving Interface, false otherwise.
410 bool floodedBackOut =
false;
412 if (lsa !=
nullptr) {
414 for (uint32_t i = 0; i <
areas.size(); i++) {
415 if (
areas[i]->getExternalRoutingCapability()) {
417 floodedBackOut =
true;
428 SummaryLsa *summaryLsa =
areas[i]->originateSummaryLSA_Stub();
430 floodedBackOut =
true;
438 floodedBackOut = areaIt->second->floodLSA(lsa, intf, neighbor);
443 return floodedBackOut;
Referenced by ageDatabase(), installASExternalLSA(), notifyAboutRoutingTableChanges(), inet::ospfv2::LinkStateUpdateHandler::processPacket(), removeExternalRoute(), and updateExternalRoute().
◆ getAreaByAddr()
Returns the Area pointer from the Area list which contains the input Ipv4 address, nullptr if there's no such area connected to the Router.
- Parameters
-
| address | [in] The Ipv4 address whose containing Area we're looking for. |
71 long areaCount =
areas.size();
73 for (
long i = 0; i < areaCount; i++) {
74 if (
areas[i]->containsAddress(address))
◆ getAreaByID()
Returns the pointer to the Area identified by the input areaID, if it's on the Area list, nullptr otherwise.
- Parameters
-
| areaID | [in] The Area identifier. |
66 return (areaIt !=
areasByID.end()) ? areaIt->second :
nullptr;
Referenced by inet::ospfv2::Ospfv2Area::calculateShortestPathTree(), inet::ospfv2::Ospfv2::handleInterfaceDown(), inet::ospfv2::Ospfv2ConfigReader::loadHostRoute(), inet::ospfv2::Ospfv2ConfigReader::loadInterfaceParameters(), inet::ospfv2::Ospfv2ConfigReader::loadLoopbackParameters(), inet::ospfv2::Ospfv2ConfigReader::loadVirtualLink(), inet::ospfv2::Ospfv2Area::originateRouterLSA(), inet::ospfv2::LinkStateUpdateHandler::processPacket(), inet::ospfv2::MessageHandler::processPacket(), and rebuildRoutingTable().
◆ getAreaCount()
| unsigned long inet::ospfv2::Router::getAreaCount |
( |
| ) |
const |
|
inline |
◆ getAreaIds()
| std::vector< AreaId > inet::ospfv2::Router::getAreaIds |
( |
| ) |
|
◆ getASBoundaryRouter()
| bool inet::ospfv2::Router::getASBoundaryRouter |
( |
| ) |
const |
|
inline |
◆ getASExternalLSA() [1/2]
| AsExternalLsa* inet::ospfv2::Router::getASExternalLSA |
( |
unsigned long |
i | ) |
|
|
inline |
◆ getASExternalLSA() [2/2]
| const AsExternalLsa* inet::ospfv2::Router::getASExternalLSA |
( |
unsigned long |
i | ) |
const |
|
inline |
◆ getASExternalLSACount()
| unsigned long inet::ospfv2::Router::getASExternalLSACount |
( |
| ) |
const |
|
inline |
◆ getContainingAddressRange()
Scans through the router's areas' preconfigured address ranges and returns the one containing the input addressRange.
- Parameters
-
| addressRange | [in] The address range to look for. |
| advertise | [out] Whether the advertise flag is set in the returned preconfigured address range. |
- Returns
- The containing preconfigured address range if found, NULL_IPV4ADDRESSRANGE otherwise.
1079 unsigned long areaCount =
areas.size();
1080 for (
unsigned long i = 0; i < areaCount; i++) {
1081 Ipv4AddressRange containingAddressRange =
areas[i]->getContainingAddressRange(addressRange, advertise);
1083 return containingAddressRange;
1086 if (advertise !=
nullptr) {
Referenced by notifyAboutRoutingTableChanges(), and inet::ospfv2::Ospfv2Area::originateSummaryLSA().
◆ getDefaultRoute()
| Ipv4Route * inet::ospfv2::Router::getDefaultRoute |
( |
| ) |
|
◆ getMessageHandler()
Referenced by inet::ospfv2::LinkStateUpdateHandler::acknowledgeLSA(), inet::ospfv2::Neighbor::clearRequestRetransmissionTimer(), inet::ospfv2::Neighbor::clearUpdateRetransmissionTimer(), inet::ospfv2::Ospfv2Interface::floodLsa(), inet::ospfv2::Ospfv2::handleMessageWhenUp(), inet::ospfv2::InterfaceStateDown::processEvent(), inet::ospfv2::InterfaceStateNotDesignatedRouter::processEvent(), inet::ospfv2::NeighborStateDown::processEvent(), inet::ospfv2::NeighborStateAttempt::processEvent(), inet::ospfv2::NeighborStateExchange::processEvent(), inet::ospfv2::NeighborStateExchangeStart::processEvent(), inet::ospfv2::NeighborStateFull::processEvent(), inet::ospfv2::InterfaceStatePointToPoint::processEvent(), inet::ospfv2::NeighborStateLoading::processEvent(), inet::ospfv2::InterfaceStateWaiting::processEvent(), inet::ospfv2::NeighborStateInit::processEvent(), inet::ospfv2::NeighborStateTwoWay::processEvent(), inet::ospfv2::InterfaceStateBackup::processEvent(), inet::ospfv2::InterfaceStateDesignatedRouter::processEvent(), inet::ospfv2::LinkStateRequestHandler::processPacket(), inet::ospfv2::HelloHandler::processPacket(), inet::ospfv2::LinkStateAcknowledgementHandler::processPacket(), inet::ospfv2::DatabaseDescriptionHandler::processPacket(), inet::ospfv2::LinkStateUpdateHandler::processPacket(), 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::Neighbor::~Neighbor(), and inet::ospfv2::Ospfv2Interface::~Ospfv2Interface().
◆ getNonVirtualInterface()
| Ospfv2Interface * inet::ospfv2::Router::getNonVirtualInterface |
( |
unsigned char |
ifIndex | ) |
|
Returns the pointer of the physical Interface identified by the input interface index, nullptr if the Router doesn't have such an interface.
- Parameters
-
| ifIndex | [in] The interface index to look for. |
91 long areaCount =
areas.size();
93 for (
long i = 0; i < areaCount; i++) {
94 Ospfv2Interface *intf =
areas[i]->getInterface(ifIndex);
95 if (intf !=
nullptr) {
Referenced by inet::ospfv2::Ospfv2Area::originateSummaryLSA().
◆ getPreferredEntry()
Selects the preferred routing table entry for the input LSA(which is either an AsExternalLsa or a SummaryLsa) according to the algorithm defined in RFC2328 Section 16.4.
points(1) through(3). This method is used when calculating the AS external routes and also when originating an SummaryLsa for an AS Boundary Router.
- Parameters
-
| lsa | [in] The LSA describing the destination for which the preferred Routing Entry is sought for. |
| skipSelfOriginated | [in] Whether to disregard this LSA if it was self-originated. |
| fromRoutingTable | [in] The Routing Table from which to select the preferred RoutingTableEntry. If it is nullptr then the router's current routing table is used instead. |
- Returns
- The preferred RoutingTableEntry, or nullptr if no such entry exists.
- See also
- RFC2328 Section 16.4. points(1) through(3)
-
Area::originateSummaryLSA
892 if (fromRoutingTable ==
nullptr)
895 const Ospfv2LsaHeader& lsaHeader = lsa.getHeader();
896 const Ospfv2AsExternalLsa *asExternalLSA =
dynamic_cast<const Ospfv2AsExternalLsa *
>(&lsa);
897 unsigned long externalCost = (asExternalLSA !=
nullptr) ? asExternalLSA->getContents().getExternalTOSInfo(0).routeCost : 0;
898 unsigned short lsAge = lsaHeader.getLsAge();
899 RouterId originatingRouter = lsaHeader.getAdvertisingRouter();
900 bool selfOriginated = (originatingRouter ==
routerID);
901 Ipv4Address forwardingAddress;
903 if (asExternalLSA !=
nullptr)
904 forwardingAddress = asExternalLSA->getContents().getExternalTOSInfo(0).forwardingAddress;
906 if ((externalCost ==
LS_INFINITY) || (lsAge ==
MAX_AGE) || (skipSelfOriginated && selfOriginated))
912 if (forwardingAddress.isUnspecified()) {
919 Ospfv2RoutingTableEntry *forwardEntry =
lookup(forwardingAddress, fromRoutingTable);
921 if (forwardEntry ==
nullptr)
932 forwardEntry->clearNextHops();
933 NextHop hop = { forwardEntry->getInterface()->getInterfaceId(), forwardingAddress,
routerID };
934 forwardEntry->addNextHop(hop);
Referenced by calculateASExternalRoutes(), and inet::ospfv2::Ospfv2Area::originateSummaryLSA().
◆ getRFC1583Compatibility()
| bool inet::ospfv2::Router::getRFC1583Compatibility |
( |
| ) |
const |
|
inline |
◆ getRouterID()
| RouterId inet::ospfv2::Router::getRouterID |
( |
| ) |
const |
|
inline |
Referenced by inet::ospfv2::LinkStateUpdateHandler::acknowledgeLSA(), inet::ospfv2::Ospfv2Area::ageDatabase(), inet::ospfv2::Ospfv2InterfaceState::calculateDesignatedRouter(), inet::ospfv2::Ospfv2Area::calculateInterAreaRoutes(), inet::ospfv2::Ospfv2Area::calculateNextHops(), inet::ospfv2::Ospfv2Area::calculateShortestPathTree(), inet::ospfv2::Ospfv2InterfaceState::changeState(), inet::ospfv2::Ospfv2Interface::createUpdatePacket(), inet::ospfv2::Ospfv2Area::getUniqueLinkStateID(), inet::ospfv2::Neighbor::needAdjacency(), inet::ospfv2::Ospfv2Area::originateNetworkLSA(), inet::ospfv2::Ospfv2Area::originateRouterLSA(), inet::ospfv2::Ospfv2Area::originateSummaryLSA(), inet::ospfv2::Ospfv2Area::originateSummaryLSA_Stub(), inet::ospfv2::HelloHandler::processPacket(), inet::ospfv2::DatabaseDescriptionHandler::processPacket(), inet::ospfv2::LinkStateUpdateHandler::processPacket(), inet::ospfv2::MessageHandler::processPacket(), inet::ospfv2::Ospfv2Area::recheckSummaryLSAs(), inet::ospfv2::Neighbor::retransmitUpdatePacket(), inet::ospfv2::Neighbor::sendDatabaseDescriptionPacket(), inet::ospfv2::Ospfv2Interface::sendDelayedAcknowledgements(), inet::ospfv2::Ospfv2Interface::sendHelloPacket(), inet::ospfv2::Neighbor::sendLinkStateRequestPacket(), inet::ospfv2::Ospfv2Interface::sendLsAcknowledgement(), and inet::ospfv2::NeighborState::updateLsa().
◆ getRoutesToASBoundaryRouter()
Returns an std::vector of routes leading to the AS Boundary Router identified by asbrRouterID from the input fromRoutingTable.
If there are no routes leading to the AS Boundary Router, the returned std::vector is empty.
- Parameters
-
| fromRoutingTable | [in] The routing table to look in. |
| asbrRouterID | [in] The ID of the AS Boundary Router to look for. |
816 std::vector<Ospfv2RoutingTableEntry *> results;
817 for (uint32_t i = 0; i < fromRoutingTable.size(); i++) {
818 Ospfv2RoutingTableEntry *routingEntry = fromRoutingTable[i];
819 if (routingEntry->getDestination() == (asbrRouterID & routingEntry->getNetmask())) {
820 if (!routingEntry->getGateway().isUnspecified())
821 results.push_back(routingEntry);
824 for (uint32_t i = 0; i <
areas.size(); i++) {
825 Ospfv2Interface *ospfIfEntry =
areas[i]->getInterface(routingEntry->getInterface()->getInterfaceId());
827 Neighbor *neighbor = ospfIfEntry->getNeighborById(asbrRouterID);
829 results.push_back(routingEntry);
Referenced by getPreferredEntry().
◆ getRoutingTableEntry() [1/2]
◆ getRoutingTableEntry() [2/2]
◆ getRoutingTableEntryCount()
| unsigned long inet::ospfv2::Router::getRoutingTableEntryCount |
( |
| ) |
const |
|
inline |
◆ getUniqueLinkStateID()
Generates a unique LinkStateId for a given destination.
This may require the reorigination of an LSA already in the database(with a different LinkStateId).
- Parameters
-
| destination | [in] The destination for which a unique LinkStateId is required. |
| destinationCost | [in] The path cost to the destination. |
| lsaToReoriginate | [out] The LSA to reoriginate(which was already in the database, and had to be changed). |
| externalMetricIsType2 | [in] True if the destinationCost is given as a Type2 external metric. |
- Returns
- the LinkStateId for the destination.
- See also
- RFC2328 Appendix E.
-
Area::getUniqueLinkStateID
1097 if (lsaToReoriginate !=
nullptr) {
1098 delete lsaToReoriginate;
1099 lsaToReoriginate =
nullptr;
1104 lsaKey.linkStateID = destination.address;
1105 lsaKey.advertisingRouter =
routerID;
1109 if (foundLSA ==
nullptr) {
1110 return lsaKey.linkStateID;
1113 Ipv4Address existingMask = foundLSA->getContents().getNetworkMask();
1115 if (destination.mask >= existingMask) {
1116 return lsaKey.linkStateID.makeBroadcastAddress(destination.mask);
1119 AsExternalLsa *asExternalLSA =
new AsExternalLsa(*foundLSA);
1121 long sequenceNumber = asExternalLSA->getHeader().getLsSequenceNumber();
1123 asExternalLSA->getHeaderForUpdate().setLsAge(0);
1125 asExternalLSA->getContentsForUpdate().setNetworkMask(destination.mask);
1126 asExternalLSA->getContentsForUpdate().getExternalTOSInfoForUpdate(0).E_ExternalMetricType = externalMetricIsType2;
1127 asExternalLSA->getContentsForUpdate().getExternalTOSInfoForUpdate(0).routeCost = destinationCost;
1129 lsaToReoriginate = asExternalLSA;
1131 return lsaKey.linkStateID.makeBroadcastAddress(existingMask);
◆ hasAddressRange()
| bool inet::ospfv2::Router::hasAddressRange |
( |
const Ipv4AddressRange & |
addressRange | ) |
const |
◆ hasAnyNeighborInStates()
| bool inet::ospfv2::Router::hasAnyNeighborInStates |
( |
int |
states | ) |
const |
◆ hasRouteToASBoundaryRouter()
Returns true if there is a route to the AS Boundary Router identified by asbrRouterID in the input inRoutingTable, false otherwise.
- Parameters
-
| inRoutingTable | [in] The routing table to look in. |
| asbrRouterID | [in] The ID of the AS Boundary Router to look for. |
789 for (uint32_t i = 0; i < inRoutingTable.size(); i++) {
790 Ospfv2RoutingTableEntry *routingEntry = inRoutingTable[i];
791 if (routingEntry->getDestination() == (asbrRouterID & routingEntry->getNetmask())) {
792 if (!routingEntry->getGateway().isUnspecified())
796 bool nextHopFound =
false;
797 for (uint32_t i = 0; i <
areas.size(); i++) {
798 Ospfv2Interface *ospfIfEntry =
areas[i]->getInterface(routingEntry->getInterface()->getInterfaceId());
800 Neighbor *neighbor = ospfIfEntry->getNeighborById(asbrRouterID);
Referenced by getPreferredEntry().
◆ installASExternalLSA()
Installs a new AS External LSA into the Router's database.
It tries to install keep one of multiple functionally equivalent AS External LSAs in the database. (See the comment in the method implementation.)
- Parameters
-
| lsa | [in] The LSA to install. It will be copied into the database. |
- Returns
- True if the routing table needs to be updated, false otherwise.
From RFC2328 Section 12.4.4.1.: "If two routers, both reachable from one another, originate functionally equivalent AS-External-LSAs(i.e., same destination, cost and non-zero forwarding address), then the LSA originated by the router having the highest OSPF Router ID is used. The router having the lower OSPF Router ID can then flush its LSA." The problem is: how do we tell whether two routers are reachable from one another based on a Link State Update packet? 0. We can assume that if this LSA reached this router, then this router is reachable from the other router. But what about the other direction?
- The update packet is most likely not sent by the router originating the functionally equivalent AS-External-LSA, so we cannot use the IPv4 packet source address.
- The AS-External-LSA contains only the Router ID of the advertising router, so we can only look up "router" type routing entries in the routing table(these contain the Router ID as their Destination ID). However these entries are only inserted into the routing table for intra-area routers...
168 RouterId advertisingRouter = lsa->getHeader().getAdvertisingRouter();
170 bool reachable =
false;
181 bool ownLSAFloodedOut =
false;
184 lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
185 lsaKey.advertisingRouter =
routerID;
190 (lsaIt->second->getContents().getExternalTOSInfo(0).E_ExternalMetricType == lsa->getContents().getExternalTOSInfo(0).E_ExternalMetricType) &&
191 (lsaIt->second->getContents().getExternalTOSInfo(0).tos == lsa->getContents().getExternalTOSInfo(0).tos) &&
192 (lsaIt->second->getContents().getExternalTOSInfo(0).routeCost == lsa->getContents().getExternalTOSInfo(0).routeCost) &&
193 (lsa->getContents().getExternalTOSInfo(0).forwardingAddress.getInt() != 0) &&
194 (lsaIt->second->getContents().getExternalTOSInfo(0).forwardingAddress == lsa->getContents().getExternalTOSInfo(0).forwardingAddress))
200 lsaIt->second->getHeaderForUpdate().setLsAge(
MAX_AGE);
202 lsaIt->second->incrementInstallTime();
203 ownLSAFloodedOut =
true;
207 lsaKey.advertisingRouter = advertisingRouter;
211 unsigned long areaCount =
areas.size();
212 for (
unsigned long i = 0; i < areaCount; i++) {
213 areas[i]->removeFromAllRetransmissionLists(lsaKey);
215 return (lsaIt->second->update(lsa)) | ownLSAFloodedOut;
218 AsExternalLsa *lsaCopy =
new AsExternalLsa(*lsa);
220 ASSERT(lsaCopy->getHeader().getLsaLength() != 0);
Referenced by installLSA(), and updateExternalRoute().
◆ installLSA()
Installs a new LSA into the Router database.
Checks the input LSA's type and installs it into either the selected Area's database, or if it's an AS External LSA then into the Router's common asExternalLSAs list.
- Parameters
-
| lsa | [in] The LSA to install. It will be copied into the database. |
| areaID | [in] Identifies the input Router, Network and Summary LSA's Area. |
- Returns
- True if the routing table needs to be updated, false otherwise.
104 switch (lsa->getHeader().getLsType()) {
108 const Ospfv2RouterLsa *ospfRouterLSA = check_and_cast<const Ospfv2RouterLsa *>(lsa);
109 return areaIt->second->installRouterLSA(ospfRouterLSA);
117 const Ospfv2NetworkLsa *ospfNetworkLSA = check_and_cast<const Ospfv2NetworkLsa *>(lsa);
118 return areaIt->second->installNetworkLSA(ospfNetworkLSA);
127 const Ospfv2SummaryLsa *ospfSummaryLSA = check_and_cast<const Ospfv2SummaryLsa *>(lsa);
128 return areaIt->second->installSummaryLSA(ospfSummaryLSA);
134 const Ospfv2AsExternalLsa *ospfASExternalLSA = check_and_cast<const Ospfv2AsExternalLsa *>(lsa);
135 ASSERT(ospfASExternalLSA->getHeader().getLsaLength() != 0);
Referenced by inet::ospfv2::LinkStateUpdateHandler::processPacket().
◆ isDestinationUnreachable()
| bool inet::ospfv2::Router::isDestinationUnreachable |
( |
Ospfv2Lsa * |
lsa | ) |
const |
Returns true if the destination described by the input lsa is in the routing table, false otherwise.
- Parameters
-
| lsa | [in] The LSA which describes the destination to look for. |
485 Ipv4Address destination = Ipv4Address(lsa->getHeader().getLinkStateID());
487 Ospfv2RouterLsa *routerLSA =
dynamic_cast<Ospfv2RouterLsa *
>(lsa);
490 RoutingInfo *routingInfo = check_and_cast<RoutingInfo *>(routerLSA);
491 if (routerLSA->getHeader().getLinkStateID() ==
routerID)
495 unsigned int linkCount = routerLSA->getLinksArraySize();
496 RouterLsa *toRouterLSA =
dynamic_cast<RouterLsa *
>(routingInfo->getParent());
498 bool destinationFound =
false;
499 bool unnumberedPointToPointLink =
false;
500 Ipv4Address firstNumberedIfAddress;
502 for (
unsigned int i = 0; i < linkCount; i++) {
503 const auto& link = routerLSA->getLinks(i);
506 if (link.getLinkID() == Ipv4Address(toRouterLSA->getHeader().getLinkStateID())) {
507 if ((link.getLinkData() & 0xFF000000) == 0) {
508 unnumberedPointToPointLink =
true;
509 if (!firstNumberedIfAddress.isUnspecified())
513 destination = Ipv4Address(link.getLinkData());
514 destinationFound =
true;
519 if (((link.getLinkData() & 0xFF000000) != 0) &&
520 firstNumberedIfAddress.isUnspecified())
522 firstNumberedIfAddress = Ipv4Address(link.getLinkData());
527 if (firstNumberedIfAddress.isUnspecified())
528 firstNumberedIfAddress = Ipv4Address(link.getLinkData());
531 if (link.getLinkID() == toRouterLSA->getHeader().getLinkStateID()) {
532 destination = Ipv4Address(link.getLinkData());
533 destinationFound =
true;
537 if (firstNumberedIfAddress.isUnspecified())
538 firstNumberedIfAddress = Ipv4Address(link.getLinkData());
544 if (unnumberedPointToPointLink) {
545 if (!firstNumberedIfAddress.isUnspecified())
546 destination = firstNumberedIfAddress;
551 if (!destinationFound)
555 NetworkLsa *toNetworkLSA =
dynamic_cast<NetworkLsa *
>(routingInfo->getParent());
558 bool destinationFound =
false;
559 for (
unsigned int i = 0; i < linkCount; i++) {
560 const auto& link = routerLSA->getLinks(i);
563 (link.getLinkID() == Ipv4Address(toNetworkLSA->getHeader().getLinkStateID())))
565 destination = Ipv4Address(link.getLinkData());
566 destinationFound =
true;
570 if (!destinationFound)
578 Ospfv2NetworkLsa *networkLSA =
dynamic_cast<Ospfv2NetworkLsa *
>(lsa);
580 destination = networkLSA->getHeader().getLinkStateID() & networkLSA->getNetworkMask();
582 Ospfv2SummaryLsa *summaryLSA =
dynamic_cast<Ospfv2SummaryLsa *
>(lsa);
584 destination = summaryLSA->getHeader().getLinkStateID() & summaryLSA->getNetworkMask();
586 Ospfv2AsExternalLsa *asExternalLSA =
dynamic_cast<Ospfv2AsExternalLsa *
>(lsa);
588 destination = asExternalLSA->getHeader().getLinkStateID() & asExternalLSA->getContents().getNetworkMask();
590 return lookup(destination) ==
nullptr;
Referenced by inet::ospfv2::Ospfv2Area::ageDatabase(), and ageDatabase().
◆ isDirectRoute()
1489 if (entry.getGateway().isUnspecified())
1494 if (intf && !intf->isLoopback()) {
1497 if ((entry.getDestination() & ipv4data->getNetmask()) == (ipv4data->getIPAddress() & ipv4data->getNetmask()))
Referenced by getPreferredEntry(), and rebuildRoutingTable().
◆ isLocalAddress()
| bool inet::ospfv2::Router::isLocalAddress |
( |
Ipv4Address |
address | ) |
const |
◆ isOnAnyRetransmissionList()
| bool inet::ospfv2::Router::isOnAnyRetransmissionList |
( |
LsaKeyType |
lsaKey | ) |
const |
Returns true if there's at least one LSA on any Neighbor's retransmission list identified by the input lsaKey, false otherwise.
- Parameters
-
| lsaKey | [in] Identifies the LSAs to look for on the retransmission lists. |
401 for (uint32_t i = 0; i <
areas.size(); i++) {
Referenced by ageDatabase().
◆ lookup()
Do a lookup in either the input OSPF routing table, or if it's nullptr then in the Router's own routing table.
- See also
- RFC2328 Section 11.1.
- Parameters
-
| destination | [in] The destination to look up in the routing table. |
| table | [in] The routing table to do the lookup in. |
- Returns
- The RoutingTableEntry describing the input destination if there's one, false otherwise.
595 const std::vector<Ospfv2RoutingTableEntry *>& rTable = (table ==
nullptr) ?
ospfRoutingTable : (*table);
596 bool unreachable =
false;
597 std::vector<Ospfv2RoutingTableEntry *> discard;
599 for (uint32_t i = 0; i <
areas.size(); i++) {
600 for (uint32_t j = 0; j <
areas[i]->getAddressRangeCount(); j++) {
601 Ipv4AddressRange range =
areas[i]->getAddressRange(j);
602 for (
auto entry : rTable) {
605 if (range.containsRange(entry->getDestination(), entry->getNetmask()) &&
609 Ospfv2RoutingTableEntry *discardEntry =
new Ospfv2RoutingTableEntry(
ift);
610 discardEntry->setDestination(range.address);
611 discardEntry->setNetmask(range.mask);
614 discardEntry->setArea(
areas[i]->getAreaID());
615 discard.push_back(discardEntry);
622 Ospfv2RoutingTableEntry *bestMatch =
nullptr;
623 unsigned long longestMatch = 0;
624 unsigned long dest = destination.getInt();
626 for (
auto entry : rTable) {
629 unsigned long entryAddress = entry->getDestination().getInt();
630 unsigned long entryMask = entry->getNetmask().getInt();
631 if ((entryAddress & entryMask) == (dest & entryMask)) {
632 if ((dest & entryMask) > longestMatch) {
633 longestMatch = (dest & entryMask);
639 if (bestMatch ==
nullptr)
642 for (
auto entry : discard) {
643 unsigned long entryAddress = entry->getDestination().getInt();
644 unsigned long entryMask = entry->getNetmask().getInt();
645 if ((entryAddress & entryMask) == (dest & entryMask)) {
646 if ((dest & entryMask) > longestMatch) {
654 for (uint32_t i = 0; i < discard.size(); i++)
Referenced by calculateASExternalRoutes(), getPreferredEntry(), and isDestinationUnreachable().
◆ notifyAboutRoutingTableChanges()
| void inet::ospfv2::Router::notifyAboutRoutingTableChanges |
( |
std::vector< Ospfv2RoutingTableEntry * > & |
oldRoutingTable | ) |
|
|
private |
After a routing table rebuild the changes in the routing table are identified and new SummaryLSAs are originated or old ones are flooded out in each area as necessary.
- Parameters
-
| oldRoutingTable | [in] The previous version of the routing table(which is then compared with the one in routingTable). |
- See also
- RFC2328 Section 12.4. points(5) through(6).
1140 if (
areas.size() <= 1)
1142 auto position = std::find_if(
areas.begin(),
areas.end(),
1143 [&] (
const Ospfv2Area *
m) ->
bool { return m->getAreaID() == BACKBONE_AREAID; });
1144 if (position ==
areas.end())
1147 typedef std::map<Ipv4AddressRange, Ospfv2RoutingTableEntry *> RoutingTableEntryMap;
1148 RoutingTableEntryMap oldTableMap;
1149 RoutingTableEntryMap newTableMap;
1151 for (uint32_t i = 0; i < oldRoutingTable.size(); i++) {
1152 Ipv4AddressRange destination(oldRoutingTable[i]->getDestination() & oldRoutingTable[i]->getNetmask(), oldRoutingTable[i]->getNetmask());
1153 oldTableMap[destination] = oldRoutingTable[i];
1161 for (uint32_t i = 0; i <
areas.size(); i++) {
1162 std::map<LsaKeyType, bool, LsaKeyType_Less> originatedLSAMap;
1163 std::map<LsaKeyType, bool, LsaKeyType_Less> deletedLSAMap;
1169 auto destIt = oldTableMap.find(destination);
1170 if (destIt == oldTableMap.end()) {
1171 SummaryLsa *lsaToReoriginate =
nullptr;
1172 SummaryLsa *newLSA =
areas[i]->originateSummaryLSA(
ospfRoutingTable[j], originatedLSAMap, lsaToReoriginate);
1174 if (newLSA !=
nullptr) {
1175 if (lsaToReoriginate !=
nullptr) {
1176 areas[i]->installSummaryLSA(lsaToReoriginate);
1179 lsaKey.linkStateID = lsaToReoriginate->getHeader().getLinkStateID();
1180 lsaKey.advertisingRouter =
routerID;
1181 originatedLSAMap[lsaKey] =
true;
1183 delete lsaToReoriginate;
1186 areas[i]->installSummaryLSA(newLSA);
1189 lsaKey.linkStateID = newLSA->getHeader().getLinkStateID();
1190 lsaKey.advertisingRouter =
routerID;
1191 originatedLSAMap[lsaKey] =
true;
1198 SummaryLsa *lsaToReoriginate =
nullptr;
1199 SummaryLsa *newLSA =
areas[i]->originateSummaryLSA(
ospfRoutingTable[j], originatedLSAMap, lsaToReoriginate);
1201 if (newLSA !=
nullptr) {
1202 if (lsaToReoriginate !=
nullptr) {
1203 areas[i]->installSummaryLSA(lsaToReoriginate);
1206 lsaKey.linkStateID = lsaToReoriginate->getHeader().getLinkStateID();
1207 lsaKey.advertisingRouter =
routerID;
1208 originatedLSAMap[lsaKey] =
true;
1210 delete lsaToReoriginate;
1218 int32_t sequenceNumber = newLSA->getHeader().getLsSequenceNumber();
1220 newLSA->getHeaderForUpdate().setLsSequenceNumber(sequenceNumber + 1);
1222 areas[i]->installSummaryLSA(newLSA);
1225 lsaKey.linkStateID = newLSA->getHeader().getLinkStateID();
1226 lsaKey.advertisingRouter =
routerID;
1227 originatedLSAMap[lsaKey] =
true;
1240 destinationAddressRange = containingAddressRange;
1251 (destinationAddressRange.address & destinationAddressRange.mask).getInt()) &&
1254 oneLessCost = maxRangeCost;
1260 lsaKey.linkStateID = destinationAddressRange.address;
1261 lsaKey.advertisingRouter =
routerID;
1263 SummaryLsa *summaryLSA =
areas[i]->findSummaryLSA(lsaKey);
1265 if (summaryLSA !=
nullptr) {
1266 if (oneLessCost != 0) {
1267 summaryLSA->setRouteCost(oneLessCost);
1270 originatedLSAMap[lsaKey] =
true;
1274 summaryLSA->getHeaderForUpdate().setLsAge(
MAX_AGE);
1277 deletedLSAMap[lsaKey] =
true;
1288 for (uint32_t j = 0; j < oldRoutingTable.size(); j++) {
1289 Ipv4AddressRange destination(oldRoutingTable[j]->getDestination() & oldRoutingTable[j]->getNetmask(), oldRoutingTable[j]->getNetmask());
1291 Ipv4AddressRange destinationAddressRange(oldRoutingTable[j]->getDestination(), oldRoutingTable[j]->getNetmask());
1299 destinationAddressRange = containingAddressRange;
1306 for (uint32_t
k = 0;
k < newRouteCount;
k++) {
1310 (destinationAddressRange.address & destinationAddressRange.mask).getInt()) &&
1317 if (maxRangeCost < oldRoutingTable[j]->getCost()) {
1318 lsaKey.linkStateID = destinationAddressRange.address;
1319 lsaKey.advertisingRouter =
routerID;
1321 SummaryLsa *summaryLSA =
areas[i]->findSummaryLSA(lsaKey);
1323 if (summaryLSA !=
nullptr) {
1324 if (maxRangeCost > 0) {
1325 summaryLSA->setRouteCost(maxRangeCost);
1328 originatedLSAMap[lsaKey] =
true;
1331 auto deletedIt = deletedLSAMap.find(lsaKey);
1332 if (deletedIt == deletedLSAMap.end()) {
1333 summaryLSA->getHeaderForUpdate().setLsAge(
MAX_AGE);
1336 deletedLSAMap[lsaKey] =
true;
Referenced by rebuildRoutingTable().
◆ originateASExternalLSA()
Originates a new AS External LSA based on the input lsa.
- Parameters
-
| lsa | [in] The LSA whose contents should be copied into the newly originated LSA. |
- Returns
- The newly originated LSA.
470 AsExternalLsa *asExternalLSA =
new AsExternalLsa(*lsa);
471 Ospfv2LsaHeader& lsaHeader = asExternalLSA->getHeaderForUpdate();
472 Ospfv2Options lsaOptions;
474 lsaHeader.setLsAge(0);
475 lsaOptions.E_ExternalRoutingCapability =
true;
476 lsaHeader.setLsOptions(lsaOptions);
480 return asExternalLSA;
Referenced by ageDatabase().
◆ printAsExternalLsa()
| void inet::ospfv2::Router::printAsExternalLsa |
( |
| ) |
|
|
private |
1463 Ospfv2AsExternalLsa *entry = check_and_cast<Ospfv2AsExternalLsa *>(
asExternalLSAs[i]);
1465 const Ospfv2LsaHeader&
head = entry->getHeader();
1466 std::string routerId =
head.getAdvertisingRouter().
str(
false);
1467 EV_DETAIL <<
"AS External LSA in OSPF router with ID " << routerId << std::endl;
1470 EV_DETAIL <<
" LS age: " <<
head.getLsAge() << std::endl;
1471 EV_DETAIL <<
" LS type: " <<
head.getLsType() << std::endl;
1472 EV_DETAIL <<
" Link state ID (IP network): " <<
head.getLinkStateID() << std::endl;
1473 EV_DETAIL <<
" Advertising router: " <<
head.getAdvertisingRouter() << std::endl;
1474 EV_DETAIL <<
" Seq number: " <<
head.getLsSequenceNumber() << std::endl;
1475 EV_DETAIL <<
" Length: " <<
head.getLsaLength() << std::endl;
1477 EV_DETAIL <<
" Network Mask: " << entry->getContents().getNetworkMask().
str(
false) << std::endl;
1478 EV_DETAIL <<
" Metric: " << entry->getContents().getExternalTOSInfo(0).routeCost << std::endl;
1479 EV_DETAIL <<
" E flag: " << ((entry->getContents().getExternalTOSInfo(0).E_ExternalMetricType ==
true) ?
"set" :
"unset") << std::endl;
1480 EV_DETAIL <<
" Forwarding Address: " << entry->getContents().getExternalTOSInfo(0).forwardingAddress.str(
false) << std::endl;
1481 EV_DETAIL <<
" External Route Tag: " << entry->getContents().getExternalTOSInfo(0).externalRouteTag << std::endl;
1483 EV_DETAIL << std::endl;
Referenced by calculateASExternalRoutes().
◆ pruneASBoundaryRouterEntries()
| void inet::ospfv2::Router::pruneASBoundaryRouterEntries |
( |
std::vector< Ospfv2RoutingTableEntry * > & |
asbrEntries | ) |
const |
|
private |
Prunes the input std::vector of RoutingTableEntries according to the RFC2328 Section 16.4.1.
- Parameters
-
| asbrEntries | [in/out] The list of RoutingTableEntries to prune. |
- See also
- RFC2328 Section 16.4.1.
842 bool hasNonBackboneIntraAreaPath =
false;
843 for (
auto routingEntry : asbrEntries) {
847 hasNonBackboneIntraAreaPath =
true;
852 if (hasNonBackboneIntraAreaPath) {
853 auto it = asbrEntries.begin();
854 while (it != asbrEntries.end()) {
859 it = asbrEntries.erase(it);
Referenced by getPreferredEntry().
◆ rebuildRoutingTable()
| void inet::ospfv2::Router::rebuildRoutingTable |
( |
| ) |
|
Rebuilds the routing table from scratch(based on the LSA database).
- See also
- RFC2328 Section 16.
665 unsigned long areaCount =
areas.size();
666 bool hasTransitAreas =
false;
667 std::vector<Ospfv2RoutingTableEntry *> newTable;
669 EV_INFO <<
"--> Rebuilding routing table:\n";
671 for (uint32_t i = 0; i < areaCount; i++) {
672 areas[i]->calculateShortestPathTree(newTable);
673 if (
areas[i]->getTransitCapability())
674 hasTransitAreas =
true;
681 backbone->calculateInterAreaRoutes(newTable);
683 for (
auto& area :
areas)
684 area->calculateInterAreaRoutes(newTable);
687 else if (areaCount == 1)
688 areas[0]->calculateInterAreaRoutes(newTable);
690 if (hasTransitAreas) {
691 for (uint32_t i = 0; i < areaCount; i++) {
692 if (
areas[i]->getTransitCapability())
693 areas[i]->recheckSummaryLSAs(newTable);
700 std::vector<Ospfv2RoutingTableEntry *> oldTable;
706 std::vector<Ipv4Route *> eraseEntries;
709 Ospfv2RoutingTableEntry *ospfEntry =
dynamic_cast<Ospfv2RoutingTableEntry *
>(entry);
710 if (ospfEntry !=
nullptr)
711 eraseEntries.push_back(entry);
715 std::vector<Ipv4Route *> addEntries;
721 if (tableEntry->getDestination() != tableEntry->getGateway()) {
722 Ipv4Route *entry =
new Ospfv2RoutingTableEntry(*tableEntry);
723 addEntries.push_back(entry);
730 std::vector<Ipv4Route *> diffAddEntries;
731 std::vector<Ipv4Route *> diffEraseEntries;
732 diffEraseEntries.assign(eraseEntries.begin(), eraseEntries.end());
733 for (
auto& entry : addEntries) {
734 auto position = std::find_if(diffEraseEntries.begin(), diffEraseEntries.end(), [&] (
const Ipv4Route *
m) ->
bool {
735 return (m->getDestination() == entry->getDestination()) &&
736 (m->getNetmask() == entry->getNetmask()) &&
737 (m->getInterface()->getInterfaceId() == entry->getInterface()->getInterfaceId()) &&
738 (m->getGateway() == entry->getGateway()) &&
739 (m->getMetric() == entry->getMetric());
741 if (position != diffEraseEntries.end())
742 diffEraseEntries.erase(position);
744 diffAddEntries.push_back(entry);
747 if (!diffEraseEntries.empty() || !diffAddEntries.empty()) {
748 EV_INFO <<
"OSPF routing table has changed: \n";
749 for (
auto& entry : diffEraseEntries)
750 EV_INFO <<
"deleted: " << entry <<
"\n";
751 for (
auto& entry : diffAddEntries)
752 EV_INFO <<
"added: " << entry <<
"\n";
755 EV_INFO <<
"No changes to the OSPF routing table. \n";
758 for (
auto& entry : eraseEntries)
761 for (
auto& entry : addEntries)
764 EV_INFO <<
"<-- Routing table was rebuilt.\n"
768 EV_INFO << entry <<
"\n";
772 for (
auto& entry : oldTable)
Referenced by inet::ospfv2::Ospfv2Area::ageDatabase(), ageDatabase(), inet::ospfv2::Ospfv2InterfaceState::changeState(), inet::ospfv2::NeighborState::changeState(), inet::ospfv2::HelloHandler::processPacket(), inet::ospfv2::LinkStateUpdateHandler::processPacket(), and updateExternalRoute().
◆ removeExternalRoute()
| void inet::ospfv2::Router::removeExternalRoute |
( |
Ipv4Address |
networkAddress | ) |
|
Removes an AS External Route from the database.
- Parameters
-
| networkAddress | [in] The network address of the external route which needs to be removed. |
1444 lsaKey.linkStateID = networkAddress;
1445 lsaKey.advertisingRouter =
routerID;
1449 lsaIt->second->getHeaderForUpdate().setLsAge(
MAX_AGE);
1450 lsaIt->second->setPurgeable();
◆ removeFromAllRetransmissionLists()
| void inet::ospfv2::Router::removeFromAllRetransmissionLists |
( |
LsaKeyType |
lsaKey | ) |
|
◆ selectLeastCostRoutingEntry()
Selects the least cost RoutingTableEntry from the input std::vector of RoutingTableEntries.
- Parameters
-
| entries | [in] The RoutingTableEntries to choose the least cost one from. |
- Returns
- The least cost entry or nullptr if entries is empty.
873 Ospfv2RoutingTableEntry *leastCostEntry = entries[0];
874 Metric leastCost = leastCostEntry->getCost();
876 for (uint32_t i = 1; i < entries.size(); i++) {
877 Metric currentCost = entries[i]->getCost();
878 if ((currentCost < leastCost) ||
879 ((currentCost == leastCost) && (entries[i]->getArea() > leastCostEntry->getArea())))
881 leastCostEntry = entries[i];
882 leastCost = currentCost;
886 return leastCostEntry;
Referenced by getPreferredEntry().
◆ setRFC1583Compatibility()
| void inet::ospfv2::Router::setRFC1583Compatibility |
( |
bool |
compatibility | ) |
|
|
inline |
◆ setRouterID()
| void inet::ospfv2::Router::setRouterID |
( |
RouterId |
id | ) |
|
|
inline |
◆ updateExternalRoute()
Stores information on an AS External Route in externalRoutes and intalls(or updates) a new AsExternalLsa into the database.
- Parameters
-
| networkAddress | [in] The external route's network address. |
| externalRouteContents | [in] Route configuration data for the external route. |
| ifIndex | [in] |
1358 if (ifIndex != -1) {
1359 bool inRoutingTable =
false;
1360 Ipv4Route *entry =
nullptr;
1364 if ((entry->getDestination() == networkAddress)
1365 && (entry->getNetmask() == externalRouteContents.getNetworkMask()))
1367 inRoutingTable =
true;
1372 if (!inRoutingTable) {
1373 Ipv4Route *entry =
new Ipv4Route;
1375 entry->setNetmask(externalRouteContents.getNetworkMask());
1378 entry->setMetric(externalRouteContents.getExternalTOSInfo(0).routeCost);
1383 entry->setMetric(externalRouteContents.getExternalTOSInfo(0).routeCost);
1387 AsExternalLsa *asExternalLSA =
new AsExternalLsa;
1388 Ospfv2LsaHeader& lsaHeader = asExternalLSA->getHeaderForUpdate();
1389 Ospfv2Options lsaOptions;
1391 lsaHeader.setLsAge(0);
1392 lsaOptions.E_ExternalRoutingCapability =
true;
1393 lsaHeader.setLsOptions(lsaOptions);
1395 lsaHeader.setLinkStateID(networkAddress);
1396 lsaHeader.setAdvertisingRouter(Ipv4Address(
routerID));
1399 asExternalLSA->setContents(externalRouteContents);
1409 delete asExternalLSA;
Referenced by inet::ospfv2::Ospfv2ConfigReader::initiateDefaultRouteDistribution(), inet::ospfv2::Ospfv2::insertExternalRoute(), and inet::ospfv2::Ospfv2ConfigReader::loadExternalRoute().
◆ ageTimer
| cMessage* inet::ospfv2::Router::ageTimer |
|
private |
◆ areas
| std::vector<Ospfv2Area *> inet::ospfv2::Router::areas |
|
private |
A list of the contained areas.
Referenced by addArea(), addWatches(), ageDatabase(), floodLSA(), getAreaByAddr(), getAreaIds(), getContainingAddressRange(), getNonVirtualInterface(), getRoutesToASBoundaryRouter(), hasAddressRange(), hasAnyNeighborInStates(), hasRouteToASBoundaryRouter(), installASExternalLSA(), isLocalAddress(), isOnAnyRetransmissionList(), lookup(), notifyAboutRoutingTableChanges(), rebuildRoutingTable(), removeFromAllRetransmissionLists(), and ~Router().
◆ areasByID
◆ asExternalLSAs
| std::vector<AsExternalLsa *> inet::ospfv2::Router::asExternalLSAs |
|
private |
◆ asExternalLSAsByID
◆ externalRoutes
◆ ift
◆ messageHandler
◆ ospfRoutingTable
◆ rfc1583Compatibility
| bool inet::ospfv2::Router::rfc1583Compatibility |
|
private |
◆ routerID
◆ rt
The documentation for this class was generated from the following files:
void notifyAboutRoutingTableChanges(std::vector< Ospfv2RoutingTableEntry * > &oldRoutingTable)
After a routing table rebuild the changes in the routing table are identified and new SummaryLSAs are...
Definition: Ospfv2Router.cc:1137
Ipv4Address RouterId
Definition: Ospfv2Common.h:129
#define OSPFv2_BGP_DEFAULT_COST
Definition: Ospfv2Common.h:54
@ FULL_STATE
Definition: Ospfv2Neighbor.h:57
Ospfv2RoutingTableEntry * lookup(Ipv4Address destination, std::vector< Ospfv2RoutingTableEntry * > *table=nullptr) const
Do a lookup in either the input OSPF routing table, or if it's nullptr then in the Router's own routi...
Definition: Ospfv2Router.cc:593
std::string str() const
Definition: Units.h:101
std::vector< Ospfv2RoutingTableEntry * > ospfRoutingTable
The OSPF routing table - contains more information than the one in the IP layer.
Definition: Ospfv2Router.h:42
IIpv4RoutingTable * rt
Definition: Ospfv2Router.h:34
virtual Ipv4Address getRouterId() const =0
Returns routerId.
void removeFromAllRetransmissionLists(LsaKeyType lsaKey)
Removes all LSAs from all Neighbor's retransmission lists which are identified by the input lsaKey.
Definition: Ospfv2Router.cc:393
#define MAX_SEQUENCE_NUMBER
Definition: Ospfv2Common.h:34
@ SUMMARYLSA_NETWORKS_TYPE
Definition: Ospfv2Packet_m.h:285
unsigned long Metric
Definition: Ospfv2Common.h:56
std::map< Ipv4Address, Ospfv2AsExternalLsaContents > externalRoutes
A map of the external route advertised by this router.
Definition: Ospfv2Router.h:40
@ MANUAL
manually added static route
Definition: IRoute.h:29
Ipv4Address NextHop
Definition: BgpCommon.h:50
@ TYPE1_EXTERNAL
Definition: Ospfv2RoutingTableEntry.h:28
std::vector< AsExternalLsa * > asExternalLSAs
A list of the ASExternalLSAs advertised by this router.
Definition: Ospfv2Router.h:39
cMessage * ageTimer
Database age timer - fires every second.
Definition: Ospfv2Router.h:41
std::map< LsaKeyType, AsExternalLsa *, LsaKeyType_Less > asExternalLSAsByID
A map of the ASExternalLSAs advertised by this router.
Definition: Ospfv2Router.h:38
void pruneASBoundaryRouterEntries(std::vector< Ospfv2RoutingTableEntry * > &asbrEntries) const
Prunes the input std::vector of RoutingTableEntries according to the RFC2328 Section 16....
Definition: Ospfv2Router.cc:840
std::vector< Ospfv2Area * > areas
A list of the contained areas.
Definition: Ospfv2Router.h:37
void printAsExternalLsa()
Definition: Ospfv2Router.cc:1460
const Ipv4AddressRange NULL_IPV4ADDRESSRANGE(Ipv4Address(0, 0, 0, 0), Ipv4Address(0, 0, 0, 0))
std::vector< T >::iterator find(std::vector< T > &v, const Tk &a)
Definition: stlutils.h:44
@ ROUTERLSA_TYPE
Definition: Ospfv2Packet_m.h:283
#define MAX_AGE
Definition: Ospfv2Common.h:27
static const unsigned char AREA_BORDER_ROUTER_DESTINATION
Definition: Ospfv2RoutingTableEntry.h:36
std::map< AreaId, Ospfv2Area * > areasByID
A map of the contained areas with the AreaId as key.
Definition: Ospfv2Router.h:36
T head(const Point< T, TS ... > &p)
Returns the first coordinate of p.
Definition: Point.h:222
const T * findProtocolData() const
Returns the protocol data for the provided type or returns nullptr if no such protocol data is found.
Definition: NetworkInterface.h:299
B calculateLsaSize(const Ospfv2RouterLsa &lsa)
Definition: Lsa.cc:92
virtual NetworkInterface * getInterfaceById(int id) const =0
Returns an interface by its Id.
bool isLocalAddress(Ipv4Address address) const
Returns true if the input Ipv4 address falls into any of the Router's Areas' configured Ipv4 address ...
Definition: Ospfv2Router.cc:446
static const unsigned char NETWORK_DESTINATION
Definition: Ospfv2RoutingTableEntry.h:35
void rebuildRoutingTable()
Rebuilds the routing table from scratch(based on the LSA database).
Definition: Ospfv2Router.cc:663
@ SUMMARYLSA_ASBOUNDARYROUTERS_TYPE
Definition: Ospfv2Packet_m.h:286
#define INITIAL_SEQUENCE_NUMBER
Definition: Ospfv2Common.h:33
MessageHandler * messageHandler
The message dispatcher class.
Definition: Ospfv2Router.h:43
std::vector< Ospfv2RoutingTableEntry * > getRoutesToASBoundaryRouter(const std::vector< Ospfv2RoutingTableEntry * > &fromRoutingTable, RouterId routerID) const
Returns an std::vector of routes leading to the AS Boundary Router identified by asbrRouterID from th...
Definition: Ospfv2Router.cc:814
const AreaId BACKBONE_AREAID(0, 0, 0, 0)
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
bool hasRouteToASBoundaryRouter(const std::vector< Ospfv2RoutingTableEntry * > &inRoutingTable, RouterId routerID) const
Returns true if there is a route to the AS Boundary Router identified by asbrRouterID in the input in...
Definition: Ospfv2Router.cc:787
intscale< b, 1, 8 > B
Definition: Units.h:1168
bool floodLSA(const Ospfv2Lsa *lsa, AreaId areaID=BACKBONE_AREAID, Ospfv2Interface *intf=nullptr, Neighbor *neighbor=nullptr)
Floods out the input lsa on a set of Interfaces.
Definition: Ospfv2Router.cc:408
virtual Ipv4Route * getRoute(int k) const override=0
Returns the kth route.
RouterId routerID
The router ID assigned by the IP layer.
Definition: Ospfv2Router.h:35
@ OSPF
managed by the given routing protocol
Definition: IRoute.h:35
@ AS_EXTERNAL_LSA_TYPE
Definition: Ospfv2Packet_m.h:287
void startTimer(cMessage *timer, simtime_t delay)
Definition: MessageHandler.cc:375
@ INTERAREA
Definition: Ospfv2RoutingTableEntry.h:27
@ VIRTUAL_LINK
Definition: Ospfv2Packet_m.h:433
bool rfc1583Compatibility
Decides whether to handle the preferred routing table entry to an AS boundary router as defined in RF...
Definition: Ospfv2Router.h:44
virtual bool deleteRoute(Ipv4Route *entry)=0
Deletes the given route from the routing table.
@ EXCHANGE_STATE
Definition: Ospfv2Neighbor.h:55
AsExternalLsa * findASExternalLSA(LsaKeyType lsaKey)
Find the AS External LSA identified by the input lsaKey in the database.
Definition: Ospfv2Router.cc:266
virtual int getNumRoutes() const =0
Returns the total number of unicast routes.
bool isDirectRoute(Ospfv2RoutingTableEntry &entry)
Definition: Ospfv2Router.cc:1487
static const unsigned char AS_BOUNDARY_ROUTER_DESTINATION
Definition: Ospfv2RoutingTableEntry.h:37
bool isDestinationUnreachable(Ospfv2Lsa *lsa) const
Returns true if the destination described by the input lsa is in the routing table,...
Definition: Ospfv2Router.cc:483
@ POINTTOPOINT_LINK
Definition: Ospfv2Packet_m.h:430
#define CHECK_AGE
Definition: Ospfv2Common.h:28
void ageDatabase()
Ages the LSAs in the Router's database.
Definition: Ospfv2Router.cc:278
virtual void addRoute(Ipv4Route *entry)=0
Adds a route to the routing table.
const double k
Definition: Qam1024Modulation.cc:14
@ DATABASE_AGE_TIMER
Definition: Ospfv2Packet_m.h:101
IInterfaceTable * ift
Definition: Ospfv2Router.h:33
bool installASExternalLSA(const Ospfv2AsExternalLsa *lsa)
Installs a new AS External LSA into the Router's database.
Definition: Ospfv2Router.cc:147
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
@ ORIGINATED
Definition: Lsa.h:54
void calculateASExternalRoutes(std::vector< Ospfv2RoutingTableEntry * > &newRoutingTable)
Calculate the AS External Routes from the ASExternalLSAs in the database.
Definition: Ospfv2Router.cc:943
#define LS_INFINITY
Definition: Ted.cc:23
virtual int getNumInterfaces() const =0
Returns the number of interfaces.
bool hasAnyNeighborInStates(int states) const
Returns true if any Neighbor on any Interface in any of the Router's Areas is in any of the input sta...
Definition: Ospfv2Router.cc:384
AsExternalLsa * originateASExternalLSA(AsExternalLsa *lsa)
Originates a new AS External LSA based on the input lsa.
Definition: Ospfv2Router.cc:468
virtual void setDestination(Ipv4Address _dest)
Definition: Ipv4Route.h:64
@ NETWORKLSA_TYPE
Definition: Ospfv2Packet_m.h:284
@ LOADING_STATE
Definition: Ospfv2Neighbor.h:56
virtual NetworkInterface * getInterface(int pos) const =0
Returns the NetworkInterface specified by an index 0..numInterfaces-1.
@ TRANSIT_LINK
Definition: Ospfv2Packet_m.h:431
bool isOnAnyRetransmissionList(LsaKeyType lsaKey) const
Returns true if there's at least one LSA on any Neighbor's retransmission list identified by the inpu...
Definition: Ospfv2Router.cc:399
Ospfv2RoutingTableEntry * selectLeastCostRoutingEntry(std::vector< Ospfv2RoutingTableEntry * > &entries) const
Selects the least cost RoutingTableEntry from the input std::vector of RoutingTableEntries.
Definition: Ospfv2Router.cc:868
value< double, units::m > m
Definition: Units.h:1233
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
@ INTRAAREA
Definition: Ospfv2RoutingTableEntry.h:26
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
@ TYPE2_EXTERNAL
Definition: Ospfv2RoutingTableEntry.h:29
#define LS_REFRESH_TIME
Definition: Ospfv2Common.h:24
RoutingPathType
Definition: Ospfv2RoutingTableEntry.h:25
void clearTimer(cMessage *timer)
Definition: MessageHandler.cc:370
bool containsKey(const std::map< K, V, _C > &m, const Tk &a)
Definition: stlutils.h:80