Build the Next-Generation Data Center
6 week online course starting in spring 2017

OSPF route selection rules

OSPF implementation in Cisco IOS deviates slightly from OSPF/NSSA standards (RFC 2328 and RFC 3101). These are the OSPF route selection rules as implemented by Cisco IOS release 12.2(33)SRE1 (all recent releases probably behave identically):

Note: Update history is at the end of the post

Update history:
  • The original version of this post was published on 2008-01-17.
  • The post was updated and renamed on 2011-03-30 after a lengthy (and very productive) discussion with one of my readers.
  • 2011-04-16: Fixed the final tie-breaker part.
  • 2016-02-19: Fixed a typo - early OSPF RFC was RFC 1583, not RFC 1683

18 comments:

  1. its a good one.

    regards
    shivluy

    ReplyDelete
  2. Excelent information.

    I've been searching for this for hours, but always you just find information about E1, E2 routes and what they mean...as you said...not the whole story..

    thanks a lot/....

    ReplyDelete
  3. Anton Yurchenko31 March, 2011 02:05

    Big big thanks! I had pieces of it written down, but pieces about Cisco specific behavior are excellent finds.

    ReplyDelete
  4. I have a question about OSPF default originates.

    I have 4 ABR in once OSPF domain. Three of the ABRs are generating a OSPF default route with a metric of 200 and 1 is using a metric of 1000. The show ip ospf database external 0.0.0.0 shows that the default originate with 200 as an E2 and the default originate with the metric of 1000 as and E2 route. The ABR with a metric of 1000 is the BDR and the ABR with metrics of 200 are the DRs. The default route for clients of the DRs prefer the BDR default route with a metric of 1000 over the default of the DR with a metric of 200. Any ideas on how to fix this situation?


    Thanks,

    ReplyDelete
  5. DR/BDR doesn't matter. They just influence how updates are flooded through the network.

    Make sure all routers originate either E1 or E2 default routes (not a mix).

    ReplyDelete
  6. Can someone please tell what the tie breaker is, i have 2 routes in OSPF that are teh same but it prefers the first one when both are recieved



    192.168.5.0/24 172.17.18.2 (172.17.18.2 Rid) 20 A Oi tunnel.5
    192.168.5.0/24 172.17.19.2 (192.168.5.11 Rid) 20 A Oi tunnel.200

    ReplyDelete
  7. It is well known (and in every textbook) that in IOS intra-area through the backbone are preferred over intra-area across a nonzero area, cost notwithstanding, but I cannot find any reference for this behaviour in RFC2328. Do you know the reason for this feature (or bug)?

    One similar case where behaviour is different is identical externals from the same ASBR, which is also an ABR, received across two distinct areas from another ABR in the same areas: these are selected by cost, with possible ECM, at least in 12.4(4)T1. This seems to be consistent with section 16.4.1 of RFC2328.

    No matter how many times you read RFC2328, there is always one more case that forces you to read it again and fire up GNS3.

    ReplyDelete
  8. Well, apparently I did misread all those textbooks, and IOS follows RFC. Intra-area routes from two different areas (a corner case not as easy to see as I previously believed) are treated by the ABR exactly as externals, selected by cost with possible ECM.

    ReplyDelete
  9. Ivan I have a comment here :

    Inter-area routes are preferred over external routes; see Section 16.2 paragraph (5) of the OSPF RFC.

    This is 100% true :)
    In case of redistribution, an O-E2 Route can be preferred over an O route ... :(

    Quote from :
    http://www.cisco.com/en/US/tech/tk365/technologies_white_paper09186a0080531fd2.shtml#routepref

    "The OSPF route selection rule is that intra-area routes are preferred over inter-area routes, which are preferred over external routes. However, this rule should apply to routes learned via the same process. In other words, there is no preference between external routes from one process compared to internal routes of other process."


    I don't want to flood your blogpost but this is the result of the test:

    O E2 1.1.1.1 [110/20] via 23.0.0.2, 00:00:16, FastEthernet0/1

    Type-5 AS External Link States

    Link ID ADV Router Age Seq# Checksum Tag
    1.1.1.1 1.1.1.1 1307 0x80000001 0x009BFC 0

    R2(config-router)#distance ospf intra-area 109

    O 1.1.1.1 [109/11] via 12.0.0.1, 00:00:09, FastEthernet0/0



    Hope you enjoy the sharing !

    See ya !


    Nic


    ReplyDelete
  10. Does only ABR sends default route to neighbor , while we enable default originate ?
    or it is not specific.

    ReplyDelete
    Replies
    1. Any router can originate E1 or E2 default route (unless it's in a stub area). On top of that, ABR would originate default route into stub/NSSA areas.

      Delete
  11. I'm trying this out on junipers and cannot explain this

    Area 0 Area 1

    ---------------R2 ( ABR ) --------------------
    R1 R4
    ---cost 100----R3 ( ABR and ASBR ) ------------
    E1 Redistibuted at R3

    Costs not indicated are 1

    the route from R1 to E1 will always be the highcost direct link

    I can only conclude that R1 prefers this link as it considers ASBR as in its own area
    but I cannot find this documented in the RFC
    do you have any idea ?

    ReplyDelete
  12. Hi! Article need update. In Cisco IOS Release 15.1(2)S and later releases, RFC 3101 replaces RFC 1587, and RFC 3101 behavior is automatically enabled.

    ReplyDelete
  13. Hi Ivan,

    When you say " Cisco IOS ignores this rule even after configuring no compatible rfc1683 (Section 16.4.1 of the OSPF RFC)" it should say " Cisco IOS ignores this rule even after configuring no compatible rfc1583 (Section 16.4.1 of the OSPF RFC)"

    Apart from this, thanks for the post!

    ReplyDelete
  14. Hello Ivan,

    i think that N2P=1 routes are preferred over E2 routes, which are preferred over N2P=0 routes. P is the P-bit.
    This behaviour is actually a bit more compliant with RFC3101, Section 2.5, (6)(e).
    i believe i have verified this with IOS 15.2(4)M2 in gns3.

    ReplyDelete
    Replies
    1. Yes, I did so also.

      This is the part confirming this:

      N2 route is preferred over E2 route

      R4#sh ip ospf database external

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

      Type-5 AS External Link States

      LS age: 12
      Options: (No TOS-capability, DC, Upward)
      LS Type: AS External Link
      Link State ID: 100.100.100.0 (External Network Number )
      Advertising Router: 4.4.4.4
      LS Seq Number: 80000001
      Checksum: 0x8871
      Length: 36
      Network Mask: /24
      Metric Type: 2 (Larger than any link state path)
      MTID: 0
      Metric: 18
      Forward Address: 192.168.1.1
      External Route Tag: 0

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

      R4#sh ip ospf database nssa-external

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

      Type-7 AS External Link States (Area 1)

      Routing Bit Set on this LSA in topology Base with MTID 0
      LS age: 79
      Options: (No TOS-capability, Type 7/5 translation, DC, Upward)
      LS Type: AS External Link
      Link State ID: 100.100.100.0 (External Network Number )
      Advertising Router: 1.1.1.1
      LS Seq Number: 8000000A
      Checksum: 0x3CB6
      Length: 36
      Network Mask: /24
      Metric Type: 2 (Larger than any link state path)
      MTID: 0
      Metric: 18
      Forward Address: 192.168.1.1
      External Route Tag: 0

      R4#sh ip ospf border-routers

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


      Base Topology (MTID 0)

      Internal Router Routing Table
      Codes: i - Intra-area route, I - Inter-area route

      i 1.1.1.1 [2] via 192.168.1.1, GigabitEthernet1/0, ASBR, Area 1, SPF 28
      i 5.5.5.5 [2] via 192.168.47.7, GigabitEthernet3/0, ASBR, Area 0, SPF 7
      i 2.2.2.2 [2] via 192.168.47.7, GigabitEthernet3/0, ABR/ASBR, Area 0, SPF 7
      i 2.2.2.2 [2] via 192.168.1.2, GigabitEthernet1/0, ABR/ASBR, Area 1, SPF 28
      i 3.3.3.3 [2] via 192.168.47.7, GigabitEthernet3/0, ABR/ASBR, Area 0, SPF 7
      i 3.3.3.3 [2] via 192.168.1.3, GigabitEthernet1/0, ABR/ASBR, Area 1, SPF 28

      R4#sh ip route 100.100.100.100
      Routing entry for 100.100.100.0/24
      Known via "ospf 1", distance 110, metric 18, type NSSA extern 2, forward metric 2
      Last update from 192.168.1.1 on GigabitEthernet1/0, 00:00:50 ago
      Routing Descriptor Blocks:
      * 192.168.1.1, from 1.1.1.1, 00:00:50 ago, via GigabitEthernet1/0
      Route metric is 18, traffic share count is 1

      Delete
    2. Yes, I agree. I have confirmed this hereunder on the same IOS train:

      N2 route is preferred over E2 route

      R4#sh ip ospf database external

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

      Type-5 AS External Link States

      LS age: 12
      Options: (No TOS-capability, DC, Upward)
      LS Type: AS External Link
      Link State ID: 100.100.100.0 (External Network Number )
      Advertising Router: 4.4.4.4
      LS Seq Number: 80000001
      Checksum: 0x8871
      Length: 36
      Network Mask: /24
      Metric Type: 2 (Larger than any link state path)
      MTID: 0
      Metric: 18
      Forward Address: 192.168.1.1
      External Route Tag: 0

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

      R4#sh ip ospf database nssa-external

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

      Type-7 AS External Link States (Area 1)

      Routing Bit Set on this LSA in topology Base with MTID 0
      LS age: 79
      Options: (No TOS-capability, Type 7/5 translation, DC, Upward)
      LS Type: AS External Link
      Link State ID: 100.100.100.0 (External Network Number )
      Advertising Router: 1.1.1.1
      LS Seq Number: 8000000A
      Checksum: 0x3CB6
      Length: 36
      Network Mask: /24
      Metric Type: 2 (Larger than any link state path)
      MTID: 0
      Metric: 18
      Forward Address: 192.168.1.1
      External Route Tag: 0

      R4#sh ip ospf border-routers

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


      Base Topology (MTID 0)

      Internal Router Routing Table
      Codes: i - Intra-area route, I - Inter-area route

      i 1.1.1.1 [2] via 192.168.1.1, GigabitEthernet1/0, ASBR, Area 1, SPF 28
      i 5.5.5.5 [2] via 192.168.47.7, GigabitEthernet3/0, ASBR, Area 0, SPF 7
      i 2.2.2.2 [2] via 192.168.47.7, GigabitEthernet3/0, ABR/ASBR, Area 0, SPF 7
      i 2.2.2.2 [2] via 192.168.1.2, GigabitEthernet1/0, ABR/ASBR, Area 1, SPF 28
      i 3.3.3.3 [2] via 192.168.47.7, GigabitEthernet3/0, ABR/ASBR, Area 0, SPF 7
      i 3.3.3.3 [2] via 192.168.1.3, GigabitEthernet1/0, ABR/ASBR, Area 1, SPF 28

      R4#sh ip route 100.100.100.100
      Routing entry for 100.100.100.0/24
      Known via "ospf 1", distance 110, metric 18, type NSSA extern 2, forward metric 2
      Last update from 192.168.1.1 on GigabitEthernet1/0, 00:00:50 ago
      Routing Descriptor Blocks:
      * 192.168.1.1, from 1.1.1.1, 00:00:50 ago, via GigabitEthernet1/0
      Route metric is 18, traffic share count is 1

      Delete

You don't have to log in to post a comment, but please do provide your real name/URL. Anonymous comments might get deleted.