OSPF Path Selection explained

Hello Vlad

Wow, that’s an interesting discovery. I labbed this one up and found the same result. And actually, it’s interesting that in my case the ABR chose the non-backbone route to the destination.

For some reason, it seems that OSPF will not load balance to destinations that may exist in different areas. I have been unable to find any documentation that tells us why, but there is a possibility that this behavior is Cisco-specific or even IOS-specific. RFC 2328 regarding OSPF load balancing, states the following:

    There is no requirement that a router running OSPF keep track of
    all possible equal-cost routes to a destination.  An
    implementation may choose to keep only a fixed number of routes
    to any given destination.  This does not affect any of the
    algorithms presented in this specification.

This seems to jive with what is happening here. It would be interesting if you could experiment further to see what is used as the tiebreaker. Could it be the next hop IP address or the router ID of the advertising router? It would be an interesting experiment to undertake.

I hope this has been helpful!

Laz

difference between OSPF N1 / N2 and E1 and E2 Route ?

Hello Ravi

Take a look at this lesson that answeres your question in detail:

I hope this has been helpful!

Laz

And here’s an overview of these four types:

https://notes.networklessons.com/ospf-e1-e2-n1-n2-routes

Hi,

I’m not sure this part is completely true:

N1 > E1 > N2 > E2.

Because RFC 3101, section 2.5 Calculating Type-7 AS External Routes, point 6 (b) states:

      (b) Type 1 external paths are always preferred over type 2
          external paths.  When all paths are type 2 external paths,
          the paths with the smallest advertised type 2 metric are
          always preferred.
          [OSPF]

So, if the metric is lower on E2, it will be preferred over N2.

And 6. (d) also says:

      (d) If the new AS external path is still indistinguishable
          from the current paths in N's routing table entry, select
          the preferred path based on a least cost comparison.  Type
          1 external paths are compared by looking at the sum of the
          distance to the ASBR/forwarding addresses and the
          advertised type 1 metric (X+Y).  Type 2 external paths
          advertising equal type 2 metrics are compared by looking
          at the distance to the ASBR/forwarding addresses.
          ~[OSPF]

So, although Type 1 is preferred over Type-2, E1 is preferred over N1 if its metric is lower, and the same with E2 and N2.

It’s only if metrics are the same that Type-7 (N1 and N2) are preferred over Type-5 (E1 and E2), as per the next step:

      (e) If the current LSA is functionally the same as an
          installed LSA (i.e., same destination, cost and non-zero
          forwarding address) then apply the following priorities in
          deciding which LSA is preferred:

             1. A Type-7 LSA with the P-bit set.

             2. A Type-5 LSA.

             3. The LSA with the higher router ID.

I have confirmed this with labs, but please correct me if I am wrong.

Sam

Hello Samir

Yes, you are correct. I believe a more correct way of stating the overall order of preference of route types for OSPF becomes:

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

Within the same path-type category (like E1/N1 or E2/N2), OSPF will prefer the path with the lower metric. Only when the metric is the same will type E1 be preferred over N1, and type E2 be preferred over N2.

I will let Rene know so he can consider updates to the lesson. Thanks for sharing your thoughts and your experimentation with us!

I hope this has been helpful!

Laz

2 Likes

Thanks @samirkhair

I’ll lab this up and give it another try. The first time I tried this was on IOS 12.4, and it changed since IOS 15. I’ll update the lesson.

Rene

1 Like

Lag, in his config guide for the lab, he has type 1 and the config you mentioned points to R5. Because i am having the same error

Hello David

Both the error in the previous post you quoted, as well as the one you are seeing is actually expected behavior. Within the lesson, Rene has added the following note:

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.

So it looks like you are using IOS release 15.1(2)S or later, and if so, that is why you are seeing the N1 routes before the E1 routes. Similarly, you’ll see the N2 routes being selected before the E2 routes. Does that make sense?

Take a look at this NetworkLessons note on OSPF Path Selection for more details.

I hope this has been helpful!

Laz

Hello
In real scenarios, can a router have the same prefix available simultaneously as both an intra-area and an inter-area route? For example, if the network 192.168.1.0/24 exists in Area 1 and is advertised by an ABR into Area 0, is it possible for a router to learn this prefix from both intra-area and inter-area routes at the same time?"

Hello George

Yes, it is possible for a router to learn the same prefix from both intra-area and inter-area routes at the same time. However, the router will prefer the intra-area route over the inter-area route due to OSPF’s route selection process. In other words, only the intra-area route will be installed in the routing table.

OSPF prefers intra-area routes over inter-area routes because they are considered more reliable. This is because intra-area routes are within the same OSPF area, and therefore have a more direct path to the destination.

In your scenario, if a router in Area 1 learns about the network 192.168.1.0/24 from both an intra-area route (from within Area 1) and an inter-area route (from Area 0), only the intra-area route will be installed in the routing table. If however the intra-area route becomes unavailable for some reason, the router will then install the inter-area route. This is part of OSPF’s built-in redundancy and failover mechanisms.

I hope this has been helpful!

Laz

Why do E1 and N1 show a cost of 21, and E2 and N2 show a cost of 20?

Hello Speedosuper111

That question gets to the heart of the difference between the “1” and “2” type OSPF routes for N and E.

Type 2 routes in both cases, once they enter the OSPF domain, do not add any more OSPF cost, no matter how deep into the OSPF infrastructure they go. They maintain the original cost (20) no matter how many additional hops they traverse within the OSPF infrastructure.

Type 1 routes in both cases, take the original cost (20) and add any additional cost that may exist within the OSPF domain.

So looking at this diagram:

  • We can see that when the 1.1.1.1/32 network on R4 (which is E1) is advertised to R1, the cost of the hop from R4 to R1 is added to the original cost of 20, resulting in a cost of 21. For every additional hop (say to R6 or R7) the cost is incremented accordingly.
  • We can see that when the 1.1.1.1/32 network on R5 (which is E2) is advertised to R1, the cost of the hop from R5 to R1 is NOT added to the original cost of 20, resulting in a cost of 20. For every additional hop (say to R6 or R7) the cost is NOT incremented, but remains the same at 20.

The N1 and N2 type routes have a similar behavior.

I hope this has been helpful!

Laz

Hello, everyone.

This part is a bit confusing so I need some clarity regarding it.

O > O IA > External Routes

The routes on the left (before >) will always be preferred over the ones on the right, regardless of the cost?

Take 192.168.1.0/24 as an example. It’s an inter-area route from the perspective of R3

R3#

O IA  192.168.1.0/24 [110/2] via 20.20.20.4, 00:52:06, GigabitEthernet

Now, I will configure this exact same network on R7-XR (so R3 will also receive a intra-area route). I will give it a very high cost.

R7-XR#

interface Loopback0
 ipv4 address 192.168.1.1 255.255.255.0

router ospf 110
auto-cost reference-bandwidth 10000

area 2
interface Loopback0
cost 665
loopback stub-network enable

R3, who had the O IA route now replaced it with the O route.

R3#
O     192.168.1.0/24 [110/666] via 192.168.5.7, 00:17:18, GigabitEthernet2

R3 didn’t care whether the cost was higher or lower, all it cared about was the fact that this comes from inside the area so it should be preferred.

All of this works fine for O > O IA > external routes but starting from external routes, it works differently?

Let’s focus on N1 > E1 > N2 > E2 now.

R5 is redistirbuting 6.6.6.6/32 into Area 51 as a N1 route and advertising this to R4. I’ve also configured R2-XR to redistribute that exact same network as a E1 route (I’ve cut the link to Area 51 for R2-XR because it would advertise the route as N1 there). The blue area on the right is a normal area and R4 is receiving the E1 route there.

R4#show ip ospf database

Type-5 AS External Link States

Link ID         ADV Router      Age         Seq#       Checksum Tag
6.6.6.6         2.2.2.2         1031        0x80000002 0x0011EE 0

Type-7 AS External Link States (Area 51)

Link ID         ADV Router      Age         Seq#       Checksum Tag
6.6.6.6         5.5.5.5         33          0x8000000C 0x0091DE 0


At the moment, the cost is exactly the same for both routes and R4 is preferring the N1 route.

O N1 6.6.6.6 [110/21] via 192.168.1.5, 00:01:35, GigabitEthernet2

If I change the metric on R5 to a larger value (the 6.6.6.6/32 prefix is coming from EIGRP)

R5(config-router)#redistribute eigrp 100 metric 500

R4 will now prefer the E1 route

O E1 6.6.6.6 [110/21] via 20.20.20.2, 00:00:10, GigabitEthernet1

So if there are two routes of the same metric type (E1/N1), N1 will only be preferred if the cost ties? Which isn’t how it works with O and IA routes, those will always be preferred one over the other regardless of the cost.

If I tell R2-XR to advertise an E2 route instead, the N1 route will be preferred regardless of the metric on R4.

O N1 172.16.10.0 [110/501] via 192.168.1.5, 00:00:15, GigabitEthernet2

So to summarize, different route types O > O IA > N/E-1 > N/E-2 will always be preferred over eachother, regardless of the cost. An O Route will beat an O IA route. An E1 route will beat an E2 or an N2 route.

However, routes of the same kind such as E1 or N1 will only be preferred if the cost ties?

Thank you
David

Hello David

What you’ve proved here is something that is found in RFC 3101 that defines how preference is defined for the route types:

Preference is defined as follows:

      (a) Intra-area and inter-area paths are always preferred over
          AS external paths.

      (b) Type 1 external paths are always preferred over type 2
          external paths.  When all paths are type 2 external paths,
          the paths with the smallest advertised type 2 metric are
          always preferred.

So this confirms the behavior that you see in your experiment.

So it would probably be more correct to say:

O > O IA > (N1 > E1) > (N2 > E2) if:

  • the cost between N1 and E1 are the same
  • the cost between N2 and E2 are the same
  • If the costs are different, then the cost overrides the route type

I will let Rene know to consider adding appropriate notes to clarify this point. Thanks so much for this useful and enlightening experiment!

I hope this has been helpful!

Laz

Hello Laz.

Great, thanks for confirming.

Turns out it can get even more complicated because N1/2 doesn’t necessarily have to be preferred over E1/2 even if the cost ties.

Here I am redistributing a network configured on R3-XR (3.3.3.3/32) into areas 0 and 1. This means that it won’t have the P-bit set in the NSSA area.

I’ve set the cost on R2’s G2 interface to 2, so it will receive an E1 route from Area 0 and an N1 route from Area 1, both with the same cost. In this case, it prefers E1 over N1

Turns out that the P-bit needs to be set in the NSSA route in order for it to actually be preferred if the cost ties.

David

Hello David

Thanks for sharing your experimentation with us. Indeed, this is an additional nuance that has been added to OSPF operation based on RFC 3101, which deals with OSPF NSSAs.

The specific behavior is described in section 2.5 of the RFC like so:

          If the current LSA is functionally the same as an
          installed LSA (i.e., same destination, cost and non-zero
          forwarding address) then apply the following priorities in
          deciding which LSA is preferred:

             1. A Type-7 LSA with the P-bit set.
             2. A Type-5 LSA.
             3. The LSA with the higher router ID.

Putting it a different way, this means that when an OSPF router compares a Type-5 LSA (E1/E2) and a Type-7 LSA (N1/N2) with equal cost and type, the Type-7 route is preferred only if its P-bit is set.

Now, the question I always like to dig deeper into is why?? The answer to this is somewhat complex, but I’ll try to be brief and link to additional info.

When two LSAs are “functionally the same,” meaning they share the same destination, cost, and a non-zero forwarding address, the OSPF router uses the P-bit as the primary tie-breaker to satisfy several operational goals:

  1. By giving the highest priority to a Type-7 LSA with the P-bit set, OSPF ensures that the route explicitly intended for domain-wide propagation is the one selected for the routing table.
  2. To prevent the policy paradox (i.e., traffic hijacking), which is further described in this section of RFC3101.

These behaviors are beneficial when applied to large-scale OSPF deployments, and their benefits are most evident when used in large-scale networks. These benefits cannot be readily observed in small labs, but the behaviors can be studied.

I hope this has been helpful!

Laz

Hello Laz.

Thank you so much, I appreciate the confirmation.

David

1 Like