We all know that OSPF uses the formula reference/bandwidth (the default reference value is 100Mbps) to calculate the cost per link then OSPF will use the SPF (Shorter Path First) Dijkstra Algorithm to calculate the metric to reach the target network.
However, which interface does OSPF uses to calculate its metric? Is it the neighbor’s outbound interface or its inbound interface? Or both?
Let put this in the lab. I will be using a simple OSPF topology, see Figure 1.1 below.
I have configured the IP addresses and enabled OSPF for all the routers. I am going to focus on R3’s LAN, 172.16.1.0/24, metric from R1. All the routers should have all the routes and their metrics. Lets check R1’s routing table.
Now, R1’s routing table is showing that the cost to get to the 172.16.1.0/24 network is 129. Here is a quick review on how OSPF got the cost of 129. Look back at the Figure 1.1, the link from R1 to R2 is a T1 link; and the link from R2 to R3 is T1 as well. Each T1 link has a cost of 64 (100Mbps/1.544Mbps=64Mbps), so now we have two T1 connections which make them 128 plus the loopback interface, which is 172.16.1.0/24 (Loopback has a cost of 1, see the show ip ospf interface loopback0 output on R3)
Let’s change R3’s serial 0/1 cost from 64 to 100 then let’s check R1’s routing table for the network 172.16.1.0/24 if the metric value has changed or not.
Well, after changing R3’s serial 0/1 cost to 100, R1 still sees the metric 129 for the network 172.16.1.0/24. Nothing has changed.
Now, I am going to change R2’s serial 0/1 cost from 64 to 100 (see Example 1.5) then let’s check R1’s routing table (see Example 1.6) if the metric has changed or not.
Aha! The metric went up from 129 to 165. Now, we know OSPF uses the inbound interface to calculate the metric.
In summary, OSPF does not use the sending interface cost to calculate the route metric, and we tested that by changing R3’s serial 0/1 interface cost to 100. OSPF uses the receiving interface’s cost to calculate the metric for each network it receives. All routes that R2 receives (and the network 10.1.23.0/24) from its serial 0/1, R2 will calculate the metric using its serial 0/1 cost (100) plus the OSPF neighbor’s cost for those routes then R2 will advertise those routes to its OSPF neighbor/s in this case it is R1.
In a nutshell, when R3 advertises the network 172.16.1.0 to R2, R3 advertises it with the cost of 1 because it is a loopback interface. Now, when R2 receives the network 172.16.1.0 from R3, the received network has a cost of 1; therefore, R2 add its own cost which is 64 to the network. R2 add the cost of 64 because it is received from R2 inbound interface which is a serial interface. R2 advertise the network 172.16.1.0 to R1. R1 receives the network 172.16.1.0 from R2 with the cost of 65 (cost of 1 from R3 plus cost of 64 from R2 equals 65). Since R1 receives the network from its serial interface, R1 will add a cost of 64 to the network’s metric. This will give us a total of cost of 129.