You are on page 1of 8

OSPF BEST PATH SELECTION

====================================================

Reference Diagram: 

How does a router chose the best route overall?

Determine the Longest Math

In example 1, there are several different paths to 1.1.1.1. By order of operations, the
router will first consider the length of the route. Whichever route is longest, meaning
the most host bits are set therefore becoming more specific, will be selected.This aspect
supersedes where it was learned, what the metric is, or most other factors in terms of
destination based routing.
Step 1) Determine the Longest Match, the most specific route.
Example 1: R1 has two paths to 1.1.1.1. One is advertised as a /8, the other as a /32. Because the /32 is the longest match, you can see within the CEF table it is
the path selected (even though the other path is in the RIB)

Determine the Lowest Administrative Distance

Now, assume each route has the same length but is learned from various sources. The
route could have been entered statically, learned from OSPF via neighbors or
redistribution, or even RIP. In any case, the router next chooses the path with the
lowest administrative distance. Admin distance for each protocol can be set manually,
however does have default values. Example 2 displays where this can be seen in the
routing table. These values are good to know, especially if you are attempting to add in
floating static routes, or are performing redistribution and you don't want the new
protocol to be the primary means of path propagation just yet.
Step 2) Determine the path with the lowest administrative distance
     
Admin Distance:
                Connected.................0
                Static.........................1
                EIGRP Summary......5 (This occurs only on the router where the
summary was generated)
                eBGP........................20
                Internal EIGRP.........90
                OSPF........................110
                IS-IS.........................115
                RIP...........................120
                External EIGRP.......170
                iBGP........................200
                NHRP......................250 (You'll typically only when using phase
3 DMVPN)

Example 2: The only change on R1 here is the creation of a static route to 1.1.1.1. Because static routes, by default, have  a lower admin distance the path through
R3 is now preferred.

Determine Mode Preferred Route Origination within OSPF


In this post, we'll assume the route with the admin distance 110 (OSPF) happens to be
the lowest. This is where OSPF becomes much more complicated than the other IGPs.
The next step for OSPF is not as simple as lowest metric, as with other protocols, but to
check the origination of the route. The origination of the route is determined by what
Type LSA within the LSDB is used. For example, the LSA types are listed here:

      Type-1.....Router LSA .......................................................Intra-Area......................


(O)
      Type-2.....Network LSA(Learned from a DR) ..................Intra-Area....................(O)
      Type-3.....Summary LSA...................................................Inter-Area.....................(O
IA)
      Type-5.....External LSA......................................................External.......................(E1
or E2)
      Type-7.....NSSA External LSA...........................................NSSA External.............
(N1 or N2)

I didn't mention Type-4 LSAs (ASBR Summary) because they are advertised simply to
recurs to a type 3 in order to find the ASBR. Now that we have all of our routes
generated with a type code next to it as in the example 3, OSPF has enough
information to select the best path in this order:

1.       Intra-Area
2.       Inter-Area
3.       E1 or N1 (determined by metric - if equal E1 is chosen)
4.       E2 or N2 (determined by forward metric - if equal E2 is chosen)

Having said all of that,


     Step 3) Determine most preferred route origination (within OSPF)
Example 3: In this example, I changed the area R3 learned of 1.1.1.1 from area 0 to area 1. This forced it to become an inter area route (O IA) rather
than a intra area route (O). You can see that the Intra area route won, and therefore is the only one present in the RIB. *both routes were also changed
to /32s

Example 4: Here, I took the path to 1.1.1.1 on R2 out of OSPF completely, and instead redistributed it into OSPF making is an external (O E2/E1) route.
Therefore, Inter area route to R3 is now the best selection.

Determine the Lowest Cumulative Cost

Finally, now that we have the longest matched route, of the lowest admin distance, and
in the case of OSPF the most preferred origination we can check the metrics.
Technically, the RFC does not dictate the metric to be correlated to anything, however
Cisco has chosen to inversely correlate the OSPF 'cost' to bandwidth. For example, the
higher the bandwidth the lower the cost by default. Cisco routers determine what to
base the cost versus bandwidth on a 'reference bandwidth' which defaults to 100mbps.
The reference bandwidth is then divided by the link bandwidth to generate the link
cost. For Example:

      Outgoing link bandwidth = 100mbps


      Reference Bandwidth = 100mbps
      Cost = Reference B/W divided by 10 = Cost is 1

It is best practice to manipulate the reference bandwidth to accommodate the link


speeds within your environment. If the reference bandwidth is left at 100mbps, any link
above 100mbps will has an equal cost of 1, therefore OSPF will not be able to
distinguish between a gig link and a fast Ethernet link. You can do this as shown below
in Example 5:
     Step 4) Determine the lowest cumulative cost
Example 5: Here I first redistributed both routes as E1s, and edited the cost of the outbound interface on R1 towards R3. After the cost bump, R3's path
is no longer considered valid as the path through R2 has a lower cost.

Summary & Caveats

In summary, path selection for a router running OSPF goes as such

1.       Determine the Longest Match, the most specific route.


2.       Determine the path with the lowest administrative distance
3.       Determine most preferred route origination (within OSPF)
4.       Determine the lowest cumulative cost

In addition to these routing decisions, within OSPF there are also underlying rules
about path selection that cannot be broken. Such as how inter area routes must traverse
area 0.

There are also caveats to some rules depending on operating system. For example, IOS
follows a slightly different variation of an older OSPF RFC (RFC1583) while NX-OS,
by default, adheres to RFC2328. The difference within these two RFCs is minor,
however can cause major issues, including loops within a network. The difference in
the two RFCs is:
 RFC1583: If an N2 and E2 route to the same destination is learned, the one with
the lowest cost is chosen
 RFC2328: If an N2 and E2 route to the same destination is learned, the router
will ALWAYS prefer the route towards the NSSA area, regardless of cost. 

You might also like