Friday, June 11, 2010

OSPF Distance Vector Routing Behavior - I thought It's a Link State Routing Protocol :-(

From your past studies of CCNA and CCNP you must always be thinking that OSPF is a Link State Routing Protocol. But now it's time to change that thought :-(

Okay don't afraid as It's not going to be some rocket science stuff :-)

But before that I would like to list ( in short) the difference between "Distance Vector" routing protocols and "Link State" routing protocols.

By definition the Distance vector protocols are based on idea of what we commonly called as " Routing By Rumors" . So no router in the Routing Domain has complete piece of information locally. It just blindly trusts information passed by It's Peer routers. Which is not a good idea sometimes and can create potential routing loops in the network.

On the other hand Link State protocols shares entire information within the routing domain. This important piece of information is stored locally in area called "Link State Database". All the routers in same area (eg OSPF & Level in -> IS-IS) have same copy of database. Apart from this there are several other differences as well and can be found in any good CCNA book.


Now most of CCNA and CCNP books put OSPF under umbrella of Link State Routing Protocol. But let me hurt you little by saying that when we talk about link state routing protocols then IS-IS is the only true link state routing protocol.


Ok...Sorry to hurt that felling but it's true that OSPF is not a true link state routing protocol and that is what I am gonna prove it here with simple topologies.


Now first we will take a look at a OPSF topology containing just 1 AREA and will investigate it's behavior with some show commands. So lets begin:




In this simple topology we have 3 routers - R1, R2 and R3. Now once you will lab this up you will find that under default values, the R1 directly reaches to R3 and is not taking path through R2 to reach R3. Although in it's local database it will have entries for R3 loopback learned from R2 and Directly from R3. So looks like Open Shortest Path First protocol does take the shortest path from R1 to R3's Loopback address.

Hmmm... So we confirm that INTRA AREA OSPF routing is Link State In Nature.


Now lets talk about INTER AREA behavior:




In this topology we are trying to find out if Open Shortest Path First (OSPF) is actually taking shortest path . The routers in question here are R4 and R5. From R4 we will try to Reach R5's loopback (with basic configs - nothing fancy) and will try to find if it goes through R6 (Shortest Path - R4->R6->R5) or if it goes through R4->R2->R1->R3->R5(longer path).


Here are the base configurations for each router:


*************************
*        CONFIGURATION            *
*************************
R1#sh ip int b | e do
Interface                  IP-Address      OK? Method Status   Protocol
Serial0/0                  12.12.12.1      YES manual up          up
Serial0/1                  13.13.13.1      YES manual up          up
Loopback0                  11.11.11.11     YES manual up       up


R1#sh run | s r o
router ospf 1
 log-adjacency-changes
 network 12.12.12.1 0.0.0.0 area 0
 network 13.13.13.1 0.0.0.0 area 0

R2#sh ip int b | e do
Interface                  IP-Address      OK? Method Status   Protocol
Serial0/0                  12.12.12.2      YES manual up           up
Serial0/1                  24.24.24.2      YES manual up           up
Loopback0                  22.22.22.22     YES manual up        up


R2#sh run | s r o
router ospf 1
 log-adjacency-changes
 network 12.12.12.2 0.0.0.0 area 0
 network 24.24.24.2 0.0.0.0 area 2

R3#sh ip int b | e do
Interface                  IP-Address      OK? Method Status  Protocol
Serial0/0                  13.13.13.3      YES manual up         up
Serial0/1                  35.35.35.3      YES manual up         up
Loopback0                  33.33.33.33     YES manual up      up

R3#sh run | s r o
router ospf 1
 log-adjacency-changes
 network 13.13.13.3 0.0.0.0 area 0
 network 35.35.35.3 0.0.0.0 area 3

R4#sh ip int b | e do
Interface                  IP-Address      OK? Method Status     Protocol
Serial0/0                  24.24.24.4      YES manual up            up
Serial0/1                  46.46.46.4      YES manual up            up
Loopback0                  44.44.44.44     YES manual up         up


R4#sh run | s r o
router ospf 1
 log-adjacency-changes
 network 24.24.24.4 0.0.0.0 area 2
 network 44.44.44.44 0.0.0.0 area 2
 network 46.46.46.4 0.0.0.0 area 2


R5#sh ip int b | e unassign|do
Interface                  IP-Address      OK? Method Status  Protocol
Serial0/0                  35.35.35.5      YES manual up          up
Serial0/1                  65.65.65.5      YES manual up          up
Loopback0                  55.55.55.55     YES manual up       up


R5#sh run | s r o
router ospf 1
 log-adjacency-changes
 network 35.35.35.5 0.0.0.0 area 3
 network 55.55.55.55 0.0.0.0 area 3
 network 65.65.65.5 0.0.0.0 area 3


R6#sh ip int b | e do
Interface                  IP-Address      OK? Method Status      Protocol
Serial0/0                  46.46.46.6      YES manual up             up
Serial0/1                  65.65.65.6      YES manual up             up

R6#sh run | s r o
router ospf 1
 log-adjacency-changes
 network 46.46.46.6 0.0.0.0 area 2
 network 65.65.65.6 0.0.0.0 area 3


Now as we are done with basic configuration. Now lets review the routing tables of each router in the topology to find out which path R4 is taking to reach R5's loopback interface.

*************************
*          VERIFICATION             *
*************************


R1#sh ip ro os
     35.0.0.0/24 is subnetted, 1 subnets
O IA    35.35.35.0 [110/128] via 13.13.13.3, 00:40:50, Serial0/1
     55.0.0.0/32 is subnetted, 1 subnets
O IA    55.55.55.55 [110/129] via 13.13.13.3, 00:31:55, Serial0/1
     65.0.0.0/24 is subnetted, 1 subnets
O IA    65.65.65.0 [110/192] via 13.13.13.3, 00:24:11, Serial0/1
     24.0.0.0/24 is subnetted, 1 subnets
O IA    24.24.24.0 [110/128] via 12.12.12.2, 00:49:54, Serial0/0
     46.0.0.0/24 is subnetted, 1 subnets
O IA    46.46.46.0 [110/192] via 12.12.12.2, 00:24:32, Serial0/0
     44.0.0.0/32 is subnetted, 1 subnets
O IA    44.44.44.44 [110/129] via 12.12.12.2, 00:45:28, Serial0/0 



R2#sh ip ro os
     35.0.0.0/24 is subnetted, 1 subnets
O IA    35.35.35.0 [110/192] via 12.12.12.1, 00:41:18, Serial0/0
     55.0.0.0/32 is subnetted, 1 subnets
O IA    55.55.55.55 [110/193] via 12.12.12.1, 00:32:23, Serial0/0
     65.0.0.0/24 is subnetted, 1 subnets
O IA    65.65.65.0 [110/256] via 12.12.12.1, 00:24:39, Serial0/0
     46.0.0.0/24 is subnetted, 1 subnets
O       46.46.46.0 [110/128] via 24.24.24.4, 00:25:01, Serial0/1
     13.0.0.0/24 is subnetted, 1 subnets
O       13.13.13.0 [110/128] via 12.12.12.1, 00:50:29, Serial0/0
     44.0.0.0/32 is subnetted, 1 subnets
O       44.44.44.44 [110/65] via 24.24.24.4, 00:45:57, Serial0/1



R3#sh ip ro os
     55.0.0.0/32 is subnetted, 1 subnets
O       55.55.55.55 [110/65] via 35.35.35.5, 00:32:43, Serial0/1
     65.0.0.0/24 is subnetted, 1 subnets
O       65.65.65.0 [110/128] via 35.35.35.5, 00:24:59, Serial0/1
     24.0.0.0/24 is subnetted, 1 subnets
O IA    24.24.24.0 [110/192] via 13.13.13.1, 00:41:43, Serial0/0
     12.0.0.0/24 is subnetted, 1 subnets
O       12.12.12.0 [110/128] via 13.13.13.1, 00:41:43, Serial0/0
     46.0.0.0/24 is subnetted, 1 subnets
O IA    46.46.46.0 [110/256] via 13.13.13.1, 00:25:20, Serial0/0
     44.0.0.0/32 is subnetted, 1 subnets
O IA    44.44.44.44 [110/193] via 13.13.13.1, 00:41:43, Serial0/0



R4#sh ip ro os
     35.0.0.0/24 is subnetted, 1 subnets
O IA    35.35.35.0 [110/256] via 24.24.24.2, 00:28:30, Serial0/0
     55.0.0.0/32 is subnetted, 1 subnets
O IA    55.55.55.55 [110/257] via 24.24.24.2, 00:28:30, Serial0/0
     65.0.0.0/24 is subnetted, 1 subnets
O IA    65.65.65.0 [110/320] via 24.24.24.2, 00:25:28, Serial0/0
     12.0.0.0/24 is subnetted, 1 subnets
O IA    12.12.12.0 [110/128] via 24.24.24.2, 00:28:30, Serial0/0
     13.0.0.0/24 is subnetted, 1 subnets
O IA    13.13.13.0 [110/192] via 24.24.24.2, 00:28:30, Serial0/0



R5#sh ip ro os
     24.0.0.0/24 is subnetted, 1 subnets
O IA    24.24.24.0 [110/256] via 35.35.35.3, 00:29:01, Serial0/0
     12.0.0.0/24 is subnetted, 1 subnets
O IA    12.12.12.0 [110/192] via 35.35.35.3, 00:29:01, Serial0/0
     46.0.0.0/24 is subnetted, 1 subnets
O IA    46.46.46.0 [110/320] via 35.35.35.3, 00:26:12, Serial0/0
     13.0.0.0/24 is subnetted, 1 subnets
O IA    13.13.13.0 [110/128] via 35.35.35.3, 00:29:01, Serial0/0
     44.0.0.0/32 is subnetted, 1 subnets
O IA    44.44.44.44 [110/257] via 35.35.35.3, 00:29:01, Serial0/0




R6#sh ip ro os
     35.0.0.0/24 is subnetted, 1 subnets
O       35.35.35.0 [110/128] via 65.65.65.5, 00:25:26, Serial0/1
     55.0.0.0/32 is subnetted, 1 subnets
O       55.55.55.55 [110/65] via 65.65.65.5, 00:25:27, Serial0/1
     24.0.0.0/24 is subnetted, 1 subnets
O       24.24.24.0 [110/128] via 46.46.46.4, 00:25:45, Serial0/0
     12.0.0.0/24 is subnetted, 1 subnets
O IA    12.12.12.0 [110/192] via 46.46.46.4, 00:25:45, Serial0/0
     13.0.0.0/24 is subnetted, 1 subnets
O IA    13.13.13.0 [110/192] via 65.65.65.5, 00:25:27, Serial0/1
     44.0.0.0/32 is subnetted, 1 subnets
O       44.44.44.44 [110/65] via 46.46.46.4, 00:25:45, Serial0/0


So as you can see R4 is taking longer path instead of taking short path through Router R6. So technically it proves the point that Inter-Area OSPF routing is Distance vector in nature. However this behavior protects OSPF from forming routing loops when LSA 3 gets exchanged between different areas. So inter-area topology works more like a Hub-n-Spoke topology where OSPF area 0 acts as HUB and rest of areas acts as SPOKE.

But before I end, I want to share Database of R5 and R6. Just make sure you look and understand R6's Databse because there is something very important to see in there :-)

*************************
*      Database Verification       *
*************************

R5#sh ip o d

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

                Router Link States (Area 3)

Link ID         ADV Router      Age         Seq#       Checksum Link count
33.33.33.33     33.33.33.33     419         0x80000005 0x0013E4 2
65.65.65.5      65.65.65.5      42          0x80000007 0x00CEFE 5
65.65.65.6      65.65.65.6      1885        0x80000001 0x00B703 2

                Summary Net Link States (Area 3)

Link ID         ADV Router      Age         Seq#       Checksum
12.12.12.0      33.33.33.33     920         0x80000002 0x00F81A
13.13.13.0      33.33.33.33     920         0x80000002 0x0052FD
24.24.24.0      33.33.33.33     920         0x80000002 0x00C9E4
44.44.44.44     33.33.33.33     920         0x80000002 0x0047FD
46.46.46.0      33.33.33.33     1951        0x80000001 0x0032FA


R6#sh ip o d

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

                Router Link States (Area 2)

Link ID         ADV Router      Age         Seq#       Checksum Link count
22.22.22.22     22.22.22.22     1579        0x80000005 0x00B5F5 2
44.44.44.44     44.44.44.44     1939        0x80000008 0x00F714 5
65.65.65.6      65.65.65.6      1938        0x80000001 0x001E27 2

                Summary Net Link States (Area 2)

Link ID         ADV Router      Age         Seq#       Checksum
12.12.12.0      22.22.22.22     1579        0x80000002 0x00C1BD
13.13.13.0      22.22.22.22     1579        0x80000002 0x00201C
35.35.35.0      22.22.22.22     1078        0x80000002 0x008732
55.55.55.55     22.22.22.22     590         0x80000002 0x0096AE
65.65.65.0      22.22.22.22     67          0x80000002 0x00CC52

                Router Link States (Area 3)

Link ID         ADV Router      Age         Seq#       Checksum Link count
33.33.33.33     33.33.33.33     456         0x80000005 0x0013E4 2
65.65.65.5      65.65.65.5      79          0x80000007 0x00CEFE 5
65.65.65.6      65.65.65.6      1921        0x80000001 0x00B703 2

                Summary Net Link States (Area 3)

Link ID         ADV Router      Age         Seq#       Checksum
12.12.12.0      33.33.33.33     959         0x80000002 0x00F81A
13.13.13.0      33.33.33.33     959         0x80000002 0x0052FD
24.24.24.0      33.33.33.33     959         0x80000002 0x00C9E4
44.44.44.44     33.33.33.33     959         0x80000002 0x0047FD
46.46.46.0      33.33.33.33     1989        0x80000001 0x0032FA
 


Now if you want to dig in theory of this further more, please visit Jeff Doyle's blog: 
http://www.networkworld.com/community/node/19293 

HTH
 Deepak Arora 

2 comments:

Anonymous said...

Nice Article

Thiru (Born for Networking) said...

Thank u so much Sir.

I am going to work with OSPF protocol.One of my Colleague asked this question "How ospf act as distance vector protocol" I got an answer through your scenario.