OSPF is a widely used interior gateway protocol (IGP) that enables routers to communicate effectively and make intelligent decisions about the paths data should traverse. One of its key aspects is the OSPF Path Selection and OSPF Traffic Engineering, which determines the most suitable network data transmission route.
This article dives into the finer details of OSPF path selection, highlighting its significance and the factors influencing the decision-making process.
OSPF Path Selection Overview
When an OSPF router needs to forward data to a particular destination subnet, it consults its link-state database (LSDB) to determine the available paths and their associated metrics. Metrics are used to quantify the desirability of a route, with lower metric values indicating better paths.
OSPF uses the Cost concept as its metric derived from the link’s bandwidth. The sum of these costs determines the total metric for a path towards a destination subnet.
For each possible route, the OSPF router calculates the metric by adding the interface cost for all outgoing interfaces in that route to reach the subnet. The OSPF link Cost is equal to the OSPF reference-BW / interface-BW. For example, a 10Gbps interface in Nexus switches has an OSPF cost of 40/10=4 since the default OSPF reference is 40G.
Please refer to the figure below as a reference for our discussion in this article.

OSPF path selection process chooses the route with the lowest total cost after determining the type of the route; [1] O > [2] O IA > [3] E1/N1 > [4] E2/N2:
- [1] Intra-Area Routes (O)
- OSPF routes within the same area as the local router.
- Example: Subnet X, connected to R3, is an intra-area route from the R4 perspective.
- [2] Inter-Area Routes (O IA)
- OSPF routes within a different area from the local router.
- Example: Subnet X, connected to R3, is an inter-area route from the R6 perspective.
- [3] External Type-1 Routes (E1/N1).
- OSPF external routes that have metric type E1 (within normal areas) or N1 (within NSSA areas).
- Example: Subnet X, which is redistributed by R3, can be an external E1 route from the R6 perspective. On the other hand, subnet Y, which is redistributed by R5 in the NSSA (area 0.0.0.2), can be an external N1 route from the R2 perspective.
- [4] External Type-1 Routes (E2/N2).
- OSPF external routes that have metric type E2 (within normal areas) or N2 (within NSSA areas).
- Example: Subnet X, which is redistributed by R3, can be an external E2 route from the R6 perspective. On the other hand, subnet Y, which is redistributed by R5 in the NSSA (area 0.0.0.2), can be an external N2 route from the R2 perspective.
- If multiple External type-2 routes exit with the same metric, the metric towards ASBR is compared (External type-1 logic).
OSPF Path Selection Cases
[1] Intra-Area Routes Selection
- OSPF routes advertised via a Type-1 LSA are always preferred over Type-3 and Type-5 LSAs.
- If multiple intra-area routes exist, the OSPF path selection process installs the path with the lowest total path metric in the routing table (RIB) if there is no better routing source than OSPF (lower Administrative Distance than 110).
- If a tie-in metric exists, both routes are installed into the RIB (ECMP).
- Even if the path metric from an intra-area route is higher than an inter-area path metric, the intra-area path is selected.
- Example: Assuming that X and Y are OSPF internal routes (assume area 0.0.0.2 is a regular area). Then, from R4’s perspective, regardless of X and Y costs, R4 will choose the route toward X to reach the 192.168.10.0/24 subnet because it is an intra-area route.
[2] Inter-Area Routes Selection
- Routes advertised via Type-3 LSAs are always preferred over Type-5 LSAs.
- OSPF path selection process for inter-area routes takes the lowest total path metric to the destination subnet. If there is a tie-in metric, then both routes are installed into the routing table (ECMP).
- All inter-area paths for a route must go through area 0.
- When the router analyses the LSDB to calculate the best inter-area route, it does the following:
- Step 1: Calculate the intra-area cost from the local router to the ABR listed in the LSA summary (type-3 LSA).
- Step 2: Add the cost value listed in the type-3 LSA.
- Example: Assuming that X is an OSPF external route (E1/E2), and Y is an OSPF internal route. Then, from R4’s perspective, Regardless of X and Y costs, R4 will choose the route toward Y to reach the 192.168.10.0/24 subnet because it is an inter-area route.
[3] & [4] External Routes Selection
- OSPF external routes are classified into two types:
- Type-1 External Routes (E1/N1)
- Type-2 External Routes (E2/N2)
- In type-2 external routes (E2/N2), the OSPF router uses the metric assigned by the ASBR who redistributes the route (default cost is 20).
- If we have more than one route with the same metric, then the router will use the type-1 logic to calculate the best route.
- In type-1 external routes (E1/N1), the OSPF router uses the metric assigned by the ASBR plus the metric to reach the ASBR itself (accumulative metric).
- By default, NX-OS uses [RFC 2328 mode], where the intra-area ASBR is preferred over the inter-area ASBR regardless of the metric to reach the ASBRs. On the other hand, IOS, IOS-XE, and IOS-XR use [RFC 1583 mode], where the metric to the ASBR is considered regardless of the area.
- Example: Assuming that X and Y are OSPF external routes, where X is an E2 type and Y is an E1. Then, regardless of the cost, R4 will use the Y route to reach the 192.168.10.0/24 subnet. On the other hand, if we’re talking about NX-OS and if X and Y are external type-1 (E1) routes, then regardless of the metric, according to RFC-2328-mode, X will be the preferred route for R4 to reach the subnet 192.168.10.0/24 because R3 is an intra-area ASBR and R5 is an Inter-area ASBR.
- Note: The same logic applied to N1 and N2 in the NSSA areas.
OSPF Traffic Engineering
To Tune OSPF routes cost, we can use one of the following methods:
- Change the reference bandwidth (default is 40Gbps):
in NX-OS(config-router)# auto-cost reference-bandwidth <value> {Mbps | Bbps}
- Change the interface cost:
(config-if)# ip ospf cost <value>
Note: Changing the interface’s bandwidth will affect other features and protocols. - We can use route summarizations or route filtering to prefer one ABR over another to reach subnets in other areas.
- To prefer one ASBR over another to reach external subnets, in addition to route summarizations and route filtering, we can use the command
rfc1583compatibility
if the preferred ASBR is outside the local area. We can also change the default metric or metric type in the ASBR during the redistribution.
Summary
In conclusion, OSPF Path Selection is a process that involves multiple steps and criteria to decide the OSPF best path for a given subnet. It begins with the longest match and then proceeds to the most preferred path type. The OSPF cost is then considered, with the lowest cost metric chosen as the best route. This process ensures that data is routed in the most efficient manner possible.
Note that all routes passing the same path will have the same route metric (cost). Unlike BGP, it has a different approach, where each prefix (NLRI) has its own BGP path attributes.
thank you for this clarification
You’re welcome.