OSPF path selection is the algorithm/process that OSPF uses to select the shortest path to a particular network after building a map for the OSPF routing domain and calculating the SPF tree.

OSPF Path Selection Criteria and Rules

OSPF draws a map for the network before applying Dijkstra’s shortest path algorithm to calculate the best cost and path to each destination network. When OSPF has many path choices of the same type (intra-area, inter-area, E1, E2, N1, or N2) to the same destination, the path with the lower cost wins. For example, if OSPF has to choose between two E1 routes to the same IP prefix, the route with the smaller metric gets selected and installed in the routing table.

When OSPF has to choose the best path among path choices of different types, the previous logic does not work at the beginning of the process. However, OSPF path selection first chooses the possible shortest path/paths based on the route type in this order:

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

Once OSPF finishes this step, it selects the route with the lower metric if many path choices exist. In the case multiple OSPF paths have the same metric and type, OSPF load balancing occurs.

OSPF Path Selection Explained With a Network Topology Including Multiple ABRs

In this guide, I will demonstrate the logic of OSPF path selection based on path type using the network diagram in Figure 1. The routing domain has a total of eight routes and is divided into five areas, including one NSSA area (area 3456) that consists of routers R3, R4, R5, and R6.

On router R1, we redistribute the loopback interfaces into OSPF with a metric type of E2. On router R5, we redistribute the loopback interfaces into OSPF with a metric type of N2. On router R6, we redistribute the loopback interfaces into OSPF with a metric type of N1. On router R7, we redistribute the loopback interfaces into OSPF with a metric type of E1.

Figure 1 – Network topology of our routing domain

Here are the initial configurations of the routers.

Router R1

Router(config)# hostname R1
R1(config)# 
R1(config)# interface loopback 0
R1(config-if)# ip address 10.0.100.1 255.255.255.0
R1(config-if)# 
R1(config-if)# interface loopback 1
R1(config-if)# ip address 10.0.110.1 255.255.255.0
R1(config-if)# 
R1(config-if)# interface loopback 2
R1(config-if)# ip address 10.0.120.1 255.255.255.0
R1(config-if)# 
R1(config-if)# interface loopback 3
R1(config-if)# ip address 10.0.130.1 255.255.255.0
R1(config-if)# 
R1(config-if)# interface loopback 4
R1(config-if)# ip address 10.0.140.1 255.255.255.0
R1(config-if)# 
R1(config-if)# interface loopback 5
R1(config-if)# ip address 10.0.150.1 255.255.255.0
R1(config-if)# 
R1(config-if)# interface GigabitEthernet0/2
R1(config-if)# ip address 10.0.12.1 255.255.255.0
R1(config-if)# no shutdown
R1(config-if)# 
R1(config-if)# 
R1(config-if)# router ospf 1
R1(config-router)# router-id 1.1.1.1
R1(config-router)# network 10.0.12.1 0.0.0.0 area 12
R1(config-router)# redistribute connected subnets

Router R2

Router(config)# hostname R2
R2(config)# 
R2(config)# interface loopback 0
R2(config-if)# ip address 10.0.100.2 255.255.255.0
R2(config-if)# ip ospf network point-to-point
R2(config-if)# 
R2(config-if)# interface GigabitEthernet0/1
R2(config-if)# ip address 10.0.12.2 255.255.255.0
R2(config-if)# no shutdown
R2(config-if)# 
R2(config-if)# interface GigabitEthernet0/3
R2(config-if)# ip address 10.0.23.2 255.255.255.0
R2(config-if)# no shutdown
R2(config-if)# 
R2(config-if)# interface GigabitEthernet0/7
R2(config-if)# ip address 10.0.27.2 255.255.255.0
R2(config-if)# no shutdown
R2(config-if)# 
R2(config-if)# interface GigabitEthernet0/8
R2(config-if)# ip address 10.0.28.2 255.255.255.0
R2(config-if)# no shutdown
R2(config-if)# 
R2(config-if)# router ospf 1
R2(config-router)# router-id 2.2.2.2
R2(config-router)# network 10.0.12.2 0.0.0.0 area 12
R2(config-router)# network 10.0.23.2 0.0.0.0 area 0
R2(config-router)# network 10.0.27.2 0.0.0.0 area 27
R2(config-router)# network 10.0.28.2 0.0.0.0 area 28
R2(config-router)# network 10.0.100.2 0.0.0.0 area 0

Router R3

Router(config)# hostname R3
R3(config)# 
R3(config)# interface GigabitEthernet0/2
R3(config-if)# ip address 10.0.23.3 255.255.255.0
R3(config-if)# no shutdown
R3(config-if)# 
R3(config-if)# interface GigabitEthernet0/4
R3(config-if)# ip address 10.0.34.3 255.255.255.0
R3(config-if)# no shutdown
R3(config-if)# 
R3(config-if)# router ospf 1
R3(config-router)# router-id 3.3.3.3
R3(config-router)# area 3456 nssa
R3(config-router)# network 10.0.23.3 0.0.0.0 area 0
R3(config-router)# network 10.0.34.3 0.0.0.0 area 3456

Router R4

Router(config)# hostname R4
R4(config)# 
R4(config)# interface GigabitEthernet0/3
R4(config-if)# ip address 10.0.34.4 255.255.255.0
R4(config-if)# no shutdown
R4(config-if)# 
R4(config-if)# interface GigabitEthernet0/5
R4(config-if)# ip address 10.0.45.4 255.255.255.0
R4(config-if)# no shutdown
R4(config-if)# 
R4(config-if)# interface GigabitEthernet0/6
R4(config-if)# ip address 10.0.46.4 255.255.255.0
R4(config-if)# no shutdown
R4(config-if)# 
R4(config-if)# router ospf 1
R4(config-router)# router-id 4.4.4.4
R4(config-router)# area 3456 nssa
R4(config-router)# network 10.0.34.4 0.0.0.0 area 3456
R4(config-router)# network 10.0.45.4 0.0.0.0 area 3456
R4(config-router)# network 10.0.46.4 0.0.0.0 area 3456

Router R5

Router(config)# hostname R5
R5(config)# 
R5(config)# interface loopback 0
R5(config-if)# ip address 10.0.100.5 255.255.255.0
R5(config-if)# 
R5(config-if)# interface loopback 1
R5(config-if)# ip address 10.0.110.5 255.255.255.0
R5(config-if)# 
R5(config-if)# interface loopback 2
R5(config-if)# ip address 10.0.120.5 255.255.255.0
R5(config-if)# 
R5(config-if)# interface loopback 3
R5(config-if)# ip address 10.0.130.5 255.255.255.0
R5(config-if)# 
R5(config-if)# interface loopback 4
R5(config-if)# ip address 10.0.140.5 255.255.255.0
R5(config-if)# 
R5(config-if)# interface GigabitEthernet0/4
R5(config-if)# ip address 10.0.45.5 255.255.255.0
R5(config-if)# no shutdown
R5(config-if)# 
R5(config-if)# router ospf 1
R5(config-router)# router-id 5.5.5.5
R5(config-router)# area 3456 nssa
R5(config-router)# network 10.0.45.5 0.0.0.0 area 3456
R5(config-router)# redistribute connected subnets

Router R6

Router(config)# hostname R6
R6(config)# 
R6(config)# interface loopback 0
R6(config-if)# ip address 10.0.100.6 255.255.255.0
R6(config-if)# 
R6(config-if)# interface loopback 1
R6(config-if)# ip address 10.0.110.6 255.255.255.0
R6(config-if)# 
R6(config-if)# interface loopback 2
R6(config-if)# ip address 10.0.120.6 255.255.255.0
R6(config-if)# 
R6(config-if)# 
R6(config-if)# interface GigabitEthernet0/4
R6(config-if)# ip address 10.0.46.6 255.255.255.0
R6(config-if)# no shutdown
R6(config-if)# 
R6(config-if)# router ospf 1
R6(config-router)# router-id 6.6.6.6
R6(config-router)# area 3456 nssa
R6(config-router)# network 10.0.46.6 0.0.0.0 area 3456
R6(config-router)# redistribute connected subnets metric-type 1

Router R7

Router(config)# hostname R7
R7(config)# 
R7(config)# interface loopback 0
R7(config-if)# ip address 10.0.100.7 255.255.255.0
R7(config-if)# 
R7(config-if)# interface loopback 1
R7(config-if)# ip address 10.0.110.7 255.255.255.0
R7(config-if)# 
R7(config-if)# interface loopback 2
R7(config-if)# ip address 10.0.120.7 255.255.255.0
R7(config-if)# 
R7(config-if)# interface loopback 3
R7(config-if)# ip address 10.0.130.7 255.255.255.0
R7(config-if)# 
R7(config-if)# interface GigabitEthernet0/2
R7(config-if)# ip address 10.0.27.7 255.255.255.0
R7(config-if)# no shutdown
R7(config-if)# 
R7(config-if)# router ospf 1
R7(config-router)# router-id 7.7.7.7
R7(config-router)# network 10.0.27.7 0.0.0.0 area 27
R7(config-router)# redistribute connected subnets metric-type 1

Router R8

Router(config)# hostname R8
R8(config)# 
R8(config)# interface loopback 0
R8(config-if)# ip address 10.0.100.8 255.255.255.0
R8(config-if)# ip ospf network point-to-point
R8(config-if)# 
R8(config-if)# interface loopback 1
R8(config-if)# ip address 10.0.110.8 255.255.255.0
R8(config-if)# ip ospf network point-to-point
R8(config-if)# 
R8(config-if)# interface GigabitEthernet0/2
R8(config-if)# ip address 10.0.28.8 255.255.255.0
R8(config-if)# no shutdown
R8(config-if)# 
R8(config-if)# router ospf 1
R8(config-router)# router-id 8.8.8.8
R8(config-router)# network 10.0.28.8 0.0.0.0 area 28
R8(config-router)# network 10.0.100.8 0.0.0.0 area 28
R8(config-router)# network 10.0.110.8 0.0.0.0 area 28

OSPF Path Selection Algorithm Prefers Intra-Area Routes Are Over Inter-Area, E1, E2, N1, and N2 Routes

OSPF prefers a route learned through a Type 1 LSA over OSPF routes advertised via Type 3, Type 5, and Type 7 LSAs for the same destination IP prefix. When many intra-area (router LSA) paths exist to a specific network, OSPF selects the route with the lowest total path cost and adds it to the Routing Information Base (RIB). OSPF installs many of them, up to the maximum path count, into the RIB if some of them have the same metric.

In this example, router R3 is learning IP prefix 10.0.100.0/24 through a router LSA.

R3# show ip ospf database router 2.2.2.2

            OSPF Router with ID (3.3.3.3) (Process ID 1)

                Router Link States (Area 0)

  LS age: 53
  Options: (No TOS-capability, DC)
  LS Type: Router Links
  Link State ID: 2.2.2.2
  Advertising Router: 2.2.2.2
  LS Seq Number: 80000008
  Checksum: 0xD97A
  Length: 48
  Area Border Router
  Number of Links: 2

    Link connected to: a Stub Network
     (Link ID) Network/subnet number: 10.0.100.0
     (Link Data) Network Mask: 255.255.255.0
      Number of MTID metrics: 0
       TOS 0 Metrics: 1

    Link connected to: a Transit Network
     (Link ID) Designated Router address: 10.0.23.3
     (Link Data) Router Interface address: 10.0.23.2
      Number of MTID metrics: 0
       TOS 0 Metrics: 1

The show ip ospf database summary, show ip ospf database external, and show ip ospf database nssa-external commands state that router R3 has inter-area, E1, E2, N1, and N2 OSPF routes to IP prefix 10.0.100.0/24.

R3# show ip ospf database summary 10.0.100.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)

                Summary Net Link States (Area 0)

  LS age: 68
  Options: (No TOS-capability, DC, Upward)
  LS Type: Summary Links(Network)
  Link State ID: 10.0.100.0 (summary Network Number)
  Advertising Router: 2.2.2.2
  LS Seq Number: 80000006
  Checksum: 0x843B
  Length: 28
  Network Mask: /24
        MTID: 0         Metric: 2 


                Summary Net Link States (Area 3456)

  LS age: 127
  Options: (No TOS-capability, DC, Upward)
  LS Type: Summary Links(Network)
  Link State ID: 10.0.100.0 (summary Network Number)
  Advertising Router: 3.3.3.3
  LS Seq Number: 80000006
  Checksum: 0xCA9
  Length: 28
  Network Mask: /24
        MTID: 0         Metric: 2 
R3# show ip ospf database external 10.0.100.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)

                Type-5 AS External Link States

  LS age: 127
  Options: (No TOS-capability, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.100.0 (External Network Number )
  Advertising Router: 1.1.1.1
  LS Seq Number: 80000006
  Checksum: 0xEC3C
  Length: 36
  Network Mask: /24
        Metric Type: 2 (Larger than any link state path)
        MTID: 0 
        Metric: 20 
        Forward Address: 0.0.0.0
        External Route Tag: 0

  LS age: 194
  Options: (No TOS-capability, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.100.0 (External Network Number )
  Advertising Router: 7.7.7.7
  LS Seq Number: 80000006
  Checksum: 0xB4DC
  Length: 36
  Network Mask: /24
        Metric Type: 1 (Comparable directly to link state metric)
        MTID: 0 
        Metric: 20 
        Forward Address: 0.0.0.0
        External Route Tag: 0
R3# show ip ospf database nssa-external 10.0.100.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)

                Type-7 AS External Link States (Area 3456)

  LS age: 327
  Options: (No TOS-capability, Type 7/5 translation, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.100.0 (External Network Number )
  Advertising Router: 5.5.5.5
  LS Seq Number: 80000007
  Checksum: 0xDDF3
  Length: 36
  Network Mask: /24
        Metric Type: 2 (Larger than any link state path)
        MTID: 0 
        Metric: 20 
        Forward Address: 10.0.45.5
        External Route Tag: 0

  LS age: 25
  Options: (No TOS-capability, Type 7/5 translation, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.100.0 (External Network Number )
  Advertising Router: 6.6.6.6
  LS Seq Number: 80000007
  Checksum: 0x57F4
  Length: 36
  Network Mask: /24
        Metric Type: 1 (Comparable directly to link state metric)
        MTID: 0 
        Metric: 20 
        Forward Address: 10.0.46.6
        External Route Tag: 0

However, R3 selects the intra-area route to that subnet and installs it in the RIB, as you can see in the following show ip ospf rib command output.

R3# show ip ospf rib 10.0.100.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)


                Base Topology (MTID 0)

OSPF local RIB
Codes: * - Best, > - Installed in global RIB
LSA: type/LSID/originator

*>  10.0.100.0/24, Intra, cost 2, area 0
     SPF Instance 3, age 03:00:26
     Flags: RIB
      via 10.0.23.2, GigabitEthernet0/2
       Flags: RIB
       LSA: 1/2.2.2.2/2.2.2.2

Since R3 does not have a non-OSPF route with an administrative distance lower than OSPF for IP prefix 10.0.100.0/24, router R3 adds the intra-area route in question to the routing table.

R3# show ip route 10.0.100.0
Routing entry for 10.0.100.0/24
  Known via "ospf 1", distance 110, metric 2, type intra area
  Last update from 10.0.23.2 on GigabitEthernet0/2, 03:06:55 ago
  Routing Descriptor Blocks:
  * 10.0.23.2, from 2.2.2.2, 03:06:55 ago, via GigabitEthernet0/2
      Route metric is 2, traffic share count is 1

OSPF Path Selection Algorithm Prefers Inter-Area OSPF Routes Are Over E1, E2, N1, and N2 Routes

OSPF favors a route learned through a Type 3 LSA over OSPF routes learned via Type 5 and Type 7 LSAs for the exact network. When the router has many inter-area (summary LSA) paths to a particular network, OSPF picks the route with the smaller total path cost and installs it in the Routing Information Base (RIB). Besides, OSPF adds many of them, up to the maximum path count, to the RIB if some of them have identical metrics.

These show ip ospf command outputs example indicates that router R3 has inter-area, E1, E2, N1, and N2 routes to IP prefix 10.0.110.0/24. Besides, subnet 10.0.110.0/24 is not part of router R3’s connected areas according to the network diagram, and thus it would not have an intra-area to that subnet.

R3# show ip ospf database summary 10.0.110.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)

                Summary Net Link States (Area 0)

  LS age: 1908
  Options: (No TOS-capability, DC, Upward)
  LS Type: Summary Links(Network)
  Link State ID: 10.0.110.0 (summary Network Number)
  Advertising Router: 2.2.2.2
  LS Seq Number: 80000006
  Checksum: 0x169F
  Length: 28
  Network Mask: /24
        MTID: 0         Metric: 2 



omitted output

R3# show ip ospf database external 10.0.110.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)

                Type-5 AS External Link States

  LS age: 1965
  Options: (No TOS-capability, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.110.0 (External Network Number )
  Advertising Router: 1.1.1.1
  LS Seq Number: 80000006
  Checksum: 0x7EA0
  Length: 36
  Network Mask: /24
        Metric Type: 2 (Larger than any link state path)
        MTID: 0 
        Metric: 20 
        Forward Address: 0.0.0.0
        External Route Tag: 0

  LS age: 174
  Options: (No TOS-capability, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.110.0 (External Network Number )
  Advertising Router: 3.3.3.3
  LS Seq Number: 80000007
  Checksum: 0xD780
  Length: 36
  Network Mask: /24
        Metric Type: 1 (Comparable directly to link state metric)
        MTID: 0 
        Metric: 20 
        Forward Address: 10.0.46.6
        External Route Tag: 0

  LS age: 17
  Options: (No TOS-capability, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.110.0 (External Network Number )
  Advertising Router: 7.7.7.7
  LS Seq Number: 80000007
  Checksum: 0x4442
  Length: 36
  Network Mask: /24
        Metric Type: 1 (Comparable directly to link state metric)
        MTID: 0 
        Metric: 20 
        Forward Address: 0.0.0.0
        External Route Tag: 0
R3# show ip ospf database nssa-external 10.0.110.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)

                Type-7 AS External Link States (Area 3456)

  LS age: 159
  Options: (No TOS-capability, Type 7/5 translation, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.110.0 (External Network Number )
  Advertising Router: 5.5.5.5
  LS Seq Number: 80000008
  Checksum: 0x6D59
  Length: 36
  Network Mask: /24
        Metric Type: 2 (Larger than any link state path)
        MTID: 0 
        Metric: 20 
        Forward Address: 10.0.45.5
        External Route Tag: 0

  LS age: 1863
  Options: (No TOS-capability, Type 7/5 translation, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.110.0 (External Network Number )
  Advertising Router: 6.6.6.6
  LS Seq Number: 80000007
  Checksum: 0xE859
  Length: 36
  Network Mask: /24
        Metric Type: 1 (Comparable directly to link state metric)
        MTID: 0 
        Metric: 20 
        Forward Address: 10.0.46.6
        External Route Tag: 0

According to the OSPF path selection process, router R3 would install the inter-area route into the RIB.

R3# show ip ospf rib 10.0.110.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)

                Base Topology (MTID 0)

OSPF local RIB
Codes: * - Best, > - Installed in global RIB
LSA: type/LSID/originator

*>  10.0.110.0/24, Inter, cost 3, area 0
     SPF Instance 10, age 03:28:32
     Flags: RIB, PartialSPF
      via 10.0.23.2, GigabitEthernet0/2
       Flags: RIB
       LSA: 3/10.0.110.0/2.2.2.2

OSPF Path Selection Algorithm Prefers N1 OSPF Routes Are Over E1, E2, and N2 Routes

OSPF favors an N1 route over E1, E2, and N2 OSPF routes learned via Type 5 and Type 7 LSAs for the exact network. When the router has many N1 (NSSA external type 1 LSA) paths to a network, OSPF chooses the route with the smaller metric and installs it in the RIB. Additionally, OSPF inserts many of them, up to the maximum path count, into the RIB if some of them have equal total path costs.

These show ip ospf command outputs example indicates that router R3 has E1, E2, N1, and N2 routes to IP prefix 10.0.120.0/24. Besides, subnet 10.0.120.0/24 is not an internal subnet of any OSPF area based on the network diagram, and thus R3 does not have intra-area and inter-area routes to that subnet.

R3# show ip ospf database external 10.0.120.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)

                Type-5 AS External Link States

  LS age: 1455
  Options: (No TOS-capability, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.120.0 (External Network Number )
  Advertising Router: 1.1.1.1
  LS Seq Number: 80000007
  Checksum: 0xE06
  Length: 36
  Network Mask: /24
        Metric Type: 2 (Larger than any link state path)
        MTID: 0 
        Metric: 20 
        Forward Address: 0.0.0.0
        External Route Tag: 0

  LS age: 1660
  Options: (No TOS-capability, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.120.0 (External Network Number )
  Advertising Router: 3.3.3.3
  LS Seq Number: 80000007
  Checksum: 0x69E4
  Length: 36
  Network Mask: /24
        Metric Type: 1 (Comparable directly to link state metric)
        MTID: 0 
        Metric: 20 
        Forward Address: 10.0.46.6
        External Route Tag: 0

  LS age: 1502
  Options: (No TOS-capability, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.120.0 (External Network Number )
  Advertising Router: 7.7.7.7
  LS Seq Number: 80000007
  Checksum: 0xD5A6
  Length: 36
  Network Mask: /24
        Metric Type: 1 (Comparable directly to link state metric)
        MTID: 0 
        Metric: 20 
        Forward Address: 0.0.0.0
        External Route Tag: 0
R3# show ip ospf database nssa-external 10.0.120.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)

                Type-7 AS External Link States (Area 3456)

  LS age: 1645
  Options: (No TOS-capability, Type 7/5 translation, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.120.0 (External Network Number )
  Advertising Router: 5.5.5.5
  LS Seq Number: 80000008
  Checksum: 0xFEBD
  Length: 36
  Network Mask: /24
        Metric Type: 2 (Larger than any link state path)
        MTID: 0 
        Metric: 20 
        Forward Address: 10.0.45.5
        External Route Tag: 0

  LS age: 1315
  Options: (No TOS-capability, Type 7/5 translation, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.120.0 (External Network Number )
  Advertising Router: 6.6.6.6
  LS Seq Number: 80000008
  Checksum: 0x78BE
  Length: 36
  Network Mask: /24
        Metric Type: 1 (Comparable directly to link state metric)
        MTID: 0 
        Metric: 20 
        Forward Address: 10.0.46.6
        External Route Tag: 0     

The show ip ospf rib command output states that router R3 installs the N1 route to subnet 10.0.120.0/24, which means N1 is preferred over E1, E2, and N2 routes to that subnet.

R3#  show ip ospf rib 10.0.120.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)


                Base Topology (MTID 0)

OSPF local RIB
Codes: * - Best, > - Installed in global RIB
LSA: type/LSID/originator

*>  10.0.120.0/24, NSSA1, cost 22, fwd cost 2, tag 0, area 3456
     SPF Instance 9, age 03:47:56
     Flags: RIB, ViaFwAddr, IntraNonBB, NSSA P-bit
      via 10.0.34.4, GigabitEthernet0/4
       Flags: RIB
       LSA: 7/10.0.120.0/6.6.6.6

E1 OSPF Routes Are Preferred Over E2 and N2 Routes by The OSPF Route Selection Algorithm

OSPF selects an E1 route over E2, and N2 OSPF routes learned via Type 5 and Type 7 LSAs for the same network. When the router has many E1 (external type 1 LSA) paths to a network, OSPF chooses the route with the smaller metric and installs it in the RIB. Additionally, OSPF inserts many of them, up to the maximum path count, into the RIB if some of them have equal total path costs.

These show ip ospf command outputs example indicates that router R3 has E1, E2, and N2 routes to IP prefix 10.0.130.0/24. Besides, subnet 10.0.130.0/24 is not an internal or type 1 NSSA external subnet of any OSPF area based on the network diagram and the routers’ initial configurations, and thus R3 does not have intra-area, inter-area, or N1 routes to that subnet.

R3# show ip ospf database external 10.0.130.0
            OSPF Router with ID (3.3.3.3) (Process ID 1)

                Type-5 AS External Link States

  LS age: 186
  Options: (No TOS-capability, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.130.0 (External Network Number )
  Advertising Router: 1.1.1.1
  LS Seq Number: 80000008
  Checksum: 0x9D6B
  Length: 36
  Network Mask: /24
        Metric Type: 2 (Larger than any link state path)
        MTID: 0 
        Metric: 20 
        Forward Address: 0.0.0.0
        External Route Tag: 0

  LS age: 214
  Options: (No TOS-capability, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.130.0 (External Network Number )
  Advertising Router: 7.7.7.7
  LS Seq Number: 80000008
  Checksum: 0x650C
  Length: 36
  Network Mask: /24
        Metric Type: 1 (Comparable directly to link state metric)
        MTID: 0 
        Metric: 20 
        Forward Address: 0.0.0.0
        External Route Tag: 0
R3# show ip ospf database nssa-external 10.0.130.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)

                Type-7 AS External Link States (Area 3456)

  LS age: 396
  Options: (No TOS-capability, Type 7/5 translation, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.130.0 (External Network Number )
  Advertising Router: 5.5.5.5
  LS Seq Number: 80000009
  Checksum: 0x8E23
  Length: 36
  Network Mask: /24
        Metric Type: 2 (Larger than any link state path)
        MTID: 0 
        Metric: 20 
        Forward Address: 10.0.45.5
        External Route Tag: 0

The show ip ospf rib command output tells that router R3 installs the E1 route to subnet 10.0.130.0/24, which means the E1 route is favored over E2 and N2 routes to that IP prefix.

R3#  show ip ospf rib 10.0.130.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)


                Base Topology (MTID 0)

OSPF local RIB
Codes: * - Best, > - Installed in global RIB
LSA: type/LSID/originator

*>  10.0.130.0/24, Ext1, cost 22, fwd cost 2, tag 0
     SPF Instance 9, age 03:56:24
     Flags: RIB
      via 10.0.23.2, GigabitEthernet0/2
       Flags: RIB
       LSA: 5/10.0.130.0/7.7.7.7

N2 OSPF Routes Are Preferred Over E2 Routes by The OSPF Route Selection Algorithm

OSPF selects an N2 route over an E2 OSPF route for the same network. When the router has many N2 (NSSA external type 2 LSA) paths to a network, OSPF selects the route with the smaller metric and installs it in the RIB. Additionally, OSPF installs many of them, up to the maximum path count, into the RIB if some of them have identical total path costs.

These show ip ospf command outputs example indicates that router R3 has E2 and N2 routes to IP prefix 10.0.140.0/24. Besides, subnet 10.0.140.0/24 is not an internal, type 1 NSSA external, or type 1 external subnet based on the network diagram and the routers’ initial configurations, and thus R3 does not have intra-area, inter-area, E1, and N1 routes to that subnet.

R3# show ip ospf database external 10.0.140.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)

                Type-5 AS External Link States

  LS age: 674
  Options: (No TOS-capability, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.140.0 (External Network Number )
  Advertising Router: 1.1.1.1
  LS Seq Number: 80000008
  Checksum: 0x2FCF
  Length: 36
  Network Mask: /24
        Metric Type: 2 (Larger than any link state path)
        MTID: 0 
        Metric: 20 
        Forward Address: 0.0.0.0
        External Route Tag: 0


omitted output

R3# show ip ospf database nssa-external 10.0.140.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)

                Type-7 AS External Link States (Area 3456)

  LS age: 885
  Options: (No TOS-capability, Type 7/5 translation, DC, Upward)
  LS Type: AS External Link
  Link State ID: 10.0.140.0 (External Network Number )
  Advertising Router: 5.5.5.5
  LS Seq Number: 80000009
  Checksum: 0x2087
  Length: 36
  Network Mask: /24
        Metric Type: 2 (Larger than any link state path)
        MTID: 0 
        Metric: 20 
        Forward Address: 10.0.45.5
        External Route Tag: 0      

The show ip ospf rib command output indicates that router R3 installs the N2 route to IP prefix 10.0.140.0/24, which means the N2 route is preferred over the E2 route to that prefix.

R3#  show ip ospf rib 10.0.140.0

            OSPF Router with ID (3.3.3.3) (Process ID 1)


                Base Topology (MTID 0)

OSPF local RIB
Codes: * - Best, > - Installed in global RIB
LSA: type/LSID/originator

*>  10.0.140.0/24, NSSA2, cost 20, fwd cost 2, tag 0, area 3456
     SPF Instance 9, age 04:10:16
     Flags: RIB, ViaFwAddr, IntraNonBB, NSSA P-bit
      via 10.0.34.4, GigabitEthernet0/4
       Flags: RIB
       LSA: 7/10.0.140.0/5.5.5.5

OSPF Path Selection Algorithm and Equal Cost Multi-Path

When OSPF discovers multiple equal-cost paths to a destination network, the OSPF path selection algorithm installs them into the routing table as equal-cost multi-path routes and Cisco IOS performs equal load sharing between those routes.

OSPF equal load sharing can be done on a per-packet basis or a per-destination basis, which is the default behavior.

By default, the maximum equal-cost path count on Cisco IOs is 4, it is 16 on Cisco XR. You can the maximum path default value using the maximum-paths command in router configuration mode.

Finally, OSPF does not support unequal load balancing, unlike EIGRP.

The Route with The Low OSPF Cost Would Not Be Chosen as The Shortest Path by The OSPF Path Selection Process

In this section, I will show you an example where OSPF chooses to install a route with a higher metric for a particular subnet instead of a route with a smaller metric.

 

Figure 2 – OSPF routing domain consisting of two areas

Subnet 10.0.23.0/24 connecting routers R3 and R2 is advertised in areas 0 and 12. It appears in the OSPF database of router R4 within R3’s router LSA and a Type 3 LSA originated by router R1, the ABR connecting areas 0 and 12.

R4# show ip ospf database router 3.3.3.3

            OSPF Router with ID (4.4.4.4) (Process ID 1)

                Router Link States (Area 0)

  LS age: 117
  Options: (No TOS-capability, DC)
  LS Type: Router Links
  Link State ID: 3.3.3.3
  Advertising Router: 3.3.3.3
  LS Seq Number: 80000005
  Checksum: 0x23FE
  Length: 48
  Number of Links: 2

    Link connected to: a Transit Network
     (Link ID) Designated Router address: 10.0.34.4
     (Link Data) Router Interface address: 10.0.34.3
      Number of MTID metrics: 0
       TOS 0 Metrics: 100

    Link connected to: a Stub Network
     (Link ID) Network/subnet number: 10.0.23.0
     (Link Data) Network Mask: 255.255.255.0
      Number of MTID metrics: 0
       TOS 0 Metrics: 1
R4# show ip ospf database summary 10.0.23.0

            OSPF Router with ID (4.4.4.4) (Process ID 1)

                Summary Net Link States (Area 0)

  LS age: 172
  Options: (No TOS-capability, DC, Upward)
  LS Type: Summary Links(Network)
  Link State ID: 10.0.23.0 (summary Network Number)
  Advertising Router: 1.1.1.1
  LS Seq Number: 80000003
  Checksum: 0xFA19
  Length: 28
  Network Mask: /24
        MTID: 0         Metric: 2 

R4 has two paths to reach subnet 10.0.23.0/24: one path is an intra-area path that goes through R3 with a total cost of 101, and the other is an inter-area path with R1 as the next-hop router with a metric of 3.

Consequently, R4 would choose the intra-area path even though it has a higher cost than the inter-area path, as shown in the show ip ospf rib 10.0.23.0 command output.

R4# show ip ospf rib 10.0.23.0

            OSPF Router with ID (4.4.4.4) (Process ID 1)


                Base Topology (MTID 0)

OSPF local RIB
Codes: * - Best, > - Installed in global RIB
LSA: type/LSID/originator

*>  10.0.23.0/24, Intra, cost 101, area 0
     SPF Instance 5, age 01:16:19
     Flags: RIB
      via 10.0.34.3, GigabitEthernet0/3
       Flags: RIB
       LSA: 1/3.3.3.3/3.3.3.3

Related Lessons to OSPF Path Selection

Mohamed Ouamer is a computer science teacher and a self-published author. He taught networking technologies and programming for more than fifteen years. While he loves to share knowledge and write, Mohamed's best passions include spending time with his family, visiting his parents, and learning new things.