OSPF Path Selection explained

As you might have learned in CCNA or CCNP, OSPF will use cost as the metric to choose the shortest path for each destination, this is true but it’s not entirely correct. OSPF will first look at the “type of path” to make a decision and, secondly look at the metric. This is the preferred path list that OSPF uses:

  • Intra-Area (O)
  • Inter-Area (O IA)
  • External Type 1 (E1)
  • NSSA Type 1 (N1)
  • External Type 2 (E2)
  • NSSA Type 2 (N2)

After the path selection, it will look at the lowest-cost path. To give a quick example…when Prefix “X” is learned as an intra-area route (O) and as an inter-area route (O IA), then OSPF will always select the intra-area route, even if the inter-area route has a lower cost.

Since Cisco IOS release 15.1(2)S, Cisco uses the path selection order from RFC 3101, which obsoletes RFC 1587. This means that it prefers N1 routes before E1 and N2 over E2 routes. In other words, the preferred path list is O > O IA > N1 > E1 > N2 > E2.

I will demonstrate this behavior to you using the following topology:

ospf path selection topology

We will create a loopback0 interface on R2 – R7 using the same prefix and advertise it in OSPF as following:

  • R2: Intra-Area (O)
  • R3: Inter-Area (O IA)
  • R4: External Type 1 (E1)
  • R5: External Type 2 (E2)
  • R6: NSSA Type 1 (N1)
  • R7: NSSA Type 2 (N2)

We will check R1 to see what path it will prefer. Let’s configure OSPF first:

R1(config)#router ospf 1
R1(config-router)#network area 0
R1(config-router)#network area 0
R1(config-router)#network area 0
R1(config-router)#network area 0
R1(config-router)#network area 167
R1(config-router)#network area 167
R1(config-router)#area 167 nssa

First, we’ll advertise the correct areas on R1. Don’t forget to make area 167 the NSSA area. Let’s continue with the other routers:

R2(config)#router ospf 1
R2(config-router)#network area 0
R2(config-router)#network area 0

On R2, we will advertise as an intra-area route.

R3(config)#router ospf 1
R3(config-router)#network area 0
R3(config-router)#network area 3

R3 will advertise in area 3 to make it an inter-area route.

R4(config)#router ospf 1
R4(config-router)#network area 0       
R4(config-router)#redistribute connected subnets metric-type 1

R4 will redistribute prefix as an external type 1 route.

R5(config-if)#router ospf 1
R5(config-router)#network area 0
R5(config-router)#redistribute connected subnets metric-type 2

R5 will redistribute prefix as an external type 2 route.

R6(config)#router ospf 1
R6(config-router)#network area 167       
R6(config-router)#redistribute connected subnets metric-type 1
R6(config-router)#area 167 nssa 

R6 is an NSSA ABR and will advertise as an N1 route.

R7(config)#router ospf 1
R7(config-router)#network area 167
R7(config-router)#redistribute connected subnets metric-type 2
R7(config-router)#area 167 nssa

Lastly, R7 will redistribute, so it shows up as an N2 route.

Since I’m creating a loopback interface with the same IP address on router R2-R7, we will have duplicate OSPF router ids. Make sure you make them unique on each router with the router-id command.

Let’s verify our configuration:

R1#show ip ospf neighbor

Neighbor ID     Pri   State           Dead Time   Address         Interface       1   FULL/BDR        00:00:38    FastEthernet0/3       1   FULL/BDR        00:00:38    FastEthernet0/2       1   FULL/BDR        00:00:38    FastEthernet0/1       1   FULL/BDR        00:00:37    FastEthernet0/0       1   FULL/BDR        00:00:30    FastEthernet0/5       1   FULL/BDR        00:00:39    FastEthernet0/4

All OSPF neighbor adjacencies are working. Let’s take a look at the routing table to see what path OSPF has decided to use:

We're Sorry, Full Content Access is for Members Only...

If you like to keep on reading, Become a Member Now! Here is why:

  • Learn any CCNA, CCNP and CCIE R&S Topic. Explained As Simple As Possible.
  • Try for Just $1. The Best Dollar You’ve Ever Spent on Your Cisco Career!
  • Full Access to our 791 Lessons. More Lessons Added Every Week!
  • Content created by Rene Molenaar (CCIE #41726)

1671 Sign Ups in the last 30 days

100% Satisfaction Guaranteed!
You may cancel your monthly membership at any time.
No Questions Asked!

Forum Replies

  1. Great post Rene. OSPF is a protocol with lots of details. We can see some interesting things when we do OSPF external type 2 with same cost but different cost to ASBR.

  2. i’ve learn something new, thanks rene :slight_smile:

  3. good site… for good lessons :smiley:

    keep sharing, m/

  4. I learned inner depth regarding protocol working …keep sharing …

82 more replies! Ask a question or join the discussion by visiting our Community Forum