Hello dear readers. Do you remember good old INE's OSPF challenge? In reality it's not so old, but anyway. If you haven't hear about it yet, take a look here:
I remembered about this challenge because at the moment I'm preparing for HCIE lab (yes, I spelled this right, Huawei's Certified Internetwork Expert, yeah, just another one challenge for me) and repeating everything related to Routing&Switching that I used to know from my beloved Cisco. Actually much more interesting stuff hidden inside that topology and especially I'm taking about reverse path from R4 to R1. Just for sake of clarity I made this topology little bit more simple by removing R5 at all and here it is for your reference:
So what's going on here behind the scene with routing from R4 to R1's loopback? Can you guess what will be the result in the R4 routing table and why? By default R4 will install two equal cost routes to routing table and won't take into account that one of paths is through NSSA area:
For purpose of route calculation there is nothing special, we have to find cost to advertising router + cost to summary from area 0. 11+100 = 101+10, the result is the same 111:
Ok, that was not so interesting. At least yet with Cisco IOS. Let's make thing little bit more complex. What if I add "
First let's take a look what was chosen by R4 after clear ip ospf process or reloading R4 router (just in these cases plus loss of both neighbors and then restoring at the same time, that's important but about that later):
As you can see, somehow link to 2.2.2.2 router was chosen. But why? Here is the debug to explain:
I highlighted two most important parts of it. Obviously this is just a matter of algorithm and has nothing to do with RFC. Summaries for area 2 calculated right after area 1. What if I replace area 1 with area 3 or any larger ID number? Not hard to guess. Once again, let's take a look at the results and the debug. For sake of clarify I removed SPF debug for everything except summaries and once again highlighted most important and relevant part:
*Jul 21 22:05:45.189: %OSPF-5-ADJCHG: Process 1, Nbr 2.2.2.2 on GigabitEthernet0/0.24 from LOADING to FULL, Loading Done
*Jul 21 22:05:46.086: OSPF-1 SPF : Detect change in LSA type 1, LSID 2.2.2.2 from 2.2.2.2 area 2
*Jul 21 22:05:51.068: OSPF-1 INTRA: Running SPF for area 2, SPF-type Full
*Jul 21 22:05:51.068: OSPF-1 INTRA: Initializing to run spf
*Jul 21 22:05:51.068: OSPF-1 INTRA: spf_intra() - rebuilding the tree
*Jul 21 22:05:51.068: OSPF-1 INTRA: It is a router LSA 4.4.4.4. Link Count 2
*Jul 21 22:05:51.068: OSPF-1 INTRA: Processing link 0, id 2.2.2.2, link data 10.1.24.4, type 1
*Jul 21 22:05:51.068: OSPF-1 SPF : Add better path to LSA ID 2.2.2.2, gateway 10.1.24.2, dist 100
*Jul 21 22:05:51.068: OSPF-1 INTRA: Putting LSA on the clist LSID 2.2.2.2, Type 1, Adv Rtr. 2.2.2.2
*Jul 21 22:05:51.068: OSPF-1 SPF : Add path: next-hop 10.1.24.2, interface GigabitEthernet0/0.24
*Jul 21 22:05:51.068: OSPF-1 INTRA: Processing link 1, id 10.1.24.0, link data 255.255.255.0, type 3
*Jul 21 22:05:51.068: OSPF-1 SPF : Add better path to LSA ID 10.1.24.255, gateway 10.1.24.0, dist 100
*Jul 21 22:05:51.068: OSPF-1 SPF : Add path: next-hop 10.1.24.4, interface GigabitEthernet0/0.24
*Jul 21 22:05:51.068: OSPF-1 INTRA: Downheap LSA ID 2.2.2.2, Type 1, Adv 2.2.2.2 on clist from index 1 to 1
*Jul 21 22:05:51.068: OSPF-1 INTRA: Update ABR/ASBR Router Route 2.2.2.2 via GigabitEthernet0/0.24/10.1.24.2, metric 100, area 2
*Jul 21 22:05:51.068: OSPF-1 SPF : Added ABR/ASBR path to router 2.2.2.2 via 10.1.24.2, area 2, Area SPF 15, PDB SPF 40, Type Full
*Jul 21 22:05:51.068: OSPF-1 INTRA: It is a router LSA 2.2.2.2. Link Count 2
*Jul 21 22:05:51.068: OSPF-1 INTRA: Processing link 0, id 4.4.4.4, link data 10.1.24.2, type 1
*Jul 21 22:05:51.068: OSPF-1 INTRA: Ignore newdist 200 olddist 0
*Jul 21 22:05:51.068: OSPF-1 INTRA: Processing link 1, id 10.1.24.0, link data 255.255.255.0, type 3
*Jul 21 22:05:51.068: OSPF-1 SPF : Add better path to LSA ID 10.1.24.255, gateway 10.1.24.0, dist 200
*Jul 21 22:05:51.068: OSPF-1 SPF : Add path: next-hop 10.1.24.2, interface GigabitEthernet0/0.24
*Jul 21 22:05:51.068: OSPF-1 INTRA: Adding Stub nets
*Jul 21 22:05:51.068: OSPF-1 INTRA: Route update succeeded for 10.1.24.0/255.255.255.0, metric 100, Next Hop: GigabitEthernet0/0.24/10.1.24.4 area 2
*Jul 21 22:05:51.068: OSPF-1 INTRA: Entered intra-area route sync for area 2
*Jul 21 22:05:51.068: OSPF-1 INTRA: Entered intra-area route sync for area 2
*Jul 21 22:05:51.068: OSPF-1 INTRA: Running SPF for area 3, SPF-type Prefix Recalculation
*Jul 21 22:05:51.068: OSPF-1 INTER: Check and generate summary LSA into all areas
*Jul 21 22:05:51.068: OSPF-1 INTER: Running spf for summaries area 2
*Jul 21 22:05:51.068: OSPF-1 INTER: Start processing: type 3, LSID 1.1.1.1, mask 255.255.255.255,
*Jul 21 22:05:51.068: OSPF-1 INTER: adv_rtr 2.2.2.2, age 97, seq 0x80000003, area 2
*Jul 21 22:05:51.068: OSPF-1 SPF : Add better path to LSA ID 1.1.1.1, gateway 0.0.0.0, dist 111
*Jul 21 22:05:51.068: OSPF-1 SPF : Add path: next-hop 10.1.24.2, interface GigabitEthernet0/0.24
*Jul 21 22:05:51.068: OSPF-1 INTER: Add succeeded for summary route to 1.1.1.1/255.255.255.255, metric 111
*Jul 21 22:05:51.068: OSPF-1 INTER: next-hop GigabitEthernet0/0.24/10.1.24.2, area 2
*Jul 21 22:05:51.068: OSPF-1 INTER: Start processing: type 3, LSID 10.1.12.0, mask 255.255.255.0,
*Jul 21 22:05:51.068: OSPF-1 INTER: adv_rtr 2.2.2.2, age 97, seq 0x80000003, area 2
*Jul 21 22:05:51.068: OSPF-1 SPF : Add better path to LSA ID 10.1.12.0, gateway 0.0.0.0, dist 110
*Jul 21 22:05:51.068: OSPF-1 SPF : Add path: next-hop 10.1.24.2, interface GigabitEthernet0/0.24
*Jul 21 22:05:51.068: OSPF-1 INTER: Add succeeded for summary route to 10.1.12.0/255.255.255.0, metric 110
*Jul 21 22:05:51.068: OSPF-1 INTER: next-hop GigabitEthernet0/0.24/10.1.24.2, area 2
*Jul 21 22:05:51.068: OSPF-1 INTER: Start processing: type 3, LSID 10.1.13.0, mask 255.255.255.0,
*Jul 21 22:05:51.068: OSPF-1 INTER: adv_rtr 2.2.2.2, age 97, seq 0x80000004, area 2
*Jul 21 22:05:51.068: OSPF-1 SPF : Add better path to LSA ID 10.1.13.0, gateway 0.0.0.0, dist 210
*Jul 21 22:05:51.068: OSPF-1 SPF : Add path: next-hop 10.1.24.2, interface GigabitEthernet0/0.24
*Jul 21 22:05:51.068: OSPF-1 INTER: Add succeeded for summary route to 10.1.13.0/255.255.255.0, metric 210
*Jul 21 22:05:51.068: OSPF-1 INTER: next-hop GigabitEthernet0/0.24/10.1.24.2, area 2
*Jul 21 22:05:51.068: OSPF-1 INTER: Start processing: type 3, LSID 10.1.34.0, mask 255.255.255.0,
*Jul 21 22:05:51.068: OSPF-1 INTER: adv_rtr 2.2.2.2, age 367, seq 0x80000001, area 2
*Jul 21 22:05:51.068: OSPF-1 INTER: Intra-area or connected route exists
*Jul 21 22:05:51.068: OSPF-1 INTER: Entered inter-area route sync for area 2
*Jul 21 22:05:51.068: OSPF-1 INTER: Entered inter-area route sync for area 2
*Jul 21 22:05:51.068: OSPF-1 INTER: Running spf for summaries area 3
*Jul 21 22:05:51.068: OSPF-1 INTER: Start processing: type 3, LSID 1.1.1.1, mask 255.255.255.255,
*Jul 21 22:05:51.068: OSPF-1 INTER: adv_rtr 3.3.3.3, age 376, seq 0x80000002, area 3
*Jul 21 22:05:51.068: OSPF-1 SPF : Add better path to LSA ID 1.1.1.1, gateway 0.0.0.0, dist 111
*Jul 21 22:05:51.068: OSPF-1 SPF : Add path: next-hop 10.1.34.3, interface GigabitEthernet0/0.34
*Jul 21 22:05:51.068: OSPF-1 INTER: Add succeeded for summary route to 1.1.1.1/255.255.255.255, metric 111
*Jul 21 22:05:51.068: OSPF-1 INTER: next-hop GigabitEthernet0/0.34/10.1.34.3, area 3
*Jul 21 22:05:51.068: OSPF-1 INTER: Start processing: type 3, LSID 10.1.12.0, mask 255.255.255.0,
*Jul 21 22:05:51.068: OSPF-1 INTER: adv_rtr 3.3.3.3, age 376, seq 0x80000002, area 3
*Jul 21 22:05:51.068: OSPF-1 INTER: Lower cost inter-area route exists
*Jul 21 22:05:51.068: OSPF-1 INTER: Start processing: type 3, LSID 10.1.13.0, mask 255.255.255.0,
*Jul 21 22:05:51.068: OSPF-1 INTER: adv_rtr 3.3.3.3, age 376, seq 0x80000002, area 3
*Jul 21 22:05:51.068: OSPF-1 SPF : Add better path to LSA ID 10.1.13.0, gateway 0.0.0.0, dist 110
*Jul 21 22:05:51.068: OSPF-1 SPF : Add path: next-hop 10.1.34.3, interface GigabitEthernet0/0.34
*Jul 21 22:05:51.068: OSPF-1 INTER: Add succeeded for summary route to 10.1.13.0/255.255.255.0, metric 110
*Jul 21 22:05:51.068: OSPF-1 INTER: next-hop GigabitEthernet0/0.34/10.1.34.3, area 3
*Jul 21 22:05:51.068: OSPF-1 INTER: Start processing: type 3, LSID 10.1.24.0, mask 255.255.255.0,
*Jul 21 22:05:51.068: OSPF-1 INTER: adv_rtr 3.3.3.3, age 376, seq 0x80000002, area 3
*Jul 21 22:05:51.068: OSPF-1 INTER: Intra-area or connected route exists
*Jul 21 22:05:51.068: OSPF-1 INTER: Start processing: type 4, LSID 2.2.2.2, mask 0.0.0.0,
*Jul 21 22:05:51.068: OSPF-1 INTER: adv_rtr 3.3.3.3, age 376, seq 0x80000002, area 3
*Jul 21 22:05:51.068: OSPF-1 INTER: Entered inter-area route sync for area 3
*Jul 21 22:05:51.068: OSPF-1 INTER: Entered inter-area route sync for area 3
*Jul 21 22:05:51.068: OSPF-1 SPF : Delete path to router 2.2.2.2 via 10.1.34.3, Area 3, Area SPF 4, PDB SPF 39, SPF Type Prefix Recalculation
As you can see, now R4 changed it's behavior and will prefer route to R2, no matter in which order we flap routes. Interesting enough? Rate corner case, but at least we know rules. Such tasty small details.
Now I'm going to tell you something about Huawei's VRP. The same topology, only one thing changed - I added Loopback 0 on R4 with address 4.4.4.4/32 and imported it into both areas to demonstrate an interesting behavior in contrast with Cisco's IOS that will show a big difference in INE's OSPF challenge I've mentioned earlier. Here is the topology for your reference:
The main difference is that VRP violates RFC3101 and R2 translate Type 7 LSA into Type 5 that leads to ECMP:
But let's talk about original question. What about reverse path from R4 to R1's loopback 1.1.1.1/32? Please note that I also changed cost of R1's loopback 0 to 1 to match IOS because by default cost of any Loopback interface on VRP equals 0.
In any case VRP prefers route from area with highest ID number, no matter in which order you flap neighbors. If link to R3 is in area 3, then R3 will be preferred next-hop.
And finally, this is not related to ospf path selection tricks, more about differences between vendors, take a look at VRP R4 ospf routes, do you see something suspicious? Sure, I highlighted it:
That's really interesting and important to know when comparing platforms and vendors. Hope that was interesting for you. Don't forget to leave a comment below!
P.S. Thanks to my colleague Denis for pointing me to some spelling mistakes.