When configuring OSPF, you have the possibility to do load balancing in case you have 2 or more equal routes to the same destination network. And yes, the routes should be equal that means that they should have the same cost.
But what is the cost exactly in OSPF? The cost is the metric that OSPF uses in order to define the best path to the destination. If you know RIP routing protocol, then you know that the metric of RIP is the number of hops, which means that the router will see how many hops he needs to reach to the destination network and will add the lowest one to his routing table.
In OSPF, the metric is the cost. The cost is calculated based on the reference bandwidth divided with the bandwidth on the interface. The reference bandwidth is always 108 bits per second.
Let’s say that we are running OSPF on a router’s interface which has a bandwidth of 100 Mbps, and we need to get the cost. So we will do the following:
Cost = Reference bandwidth / Interface bandwidth
Cost = 108 / 100.000.000
Cost = 1
You can see, I have made the interface bandwidth on bps same as the reference bandwidth.
Now we know how to calculate the cost, let’s check how the load balancing happens in OSPF.
In OSPF, the lowest the metric the better it is, and the route with the lowest metric is the one which will be chosen to be added to the routing table. Let me show you this in a graph.
Let’s say that R1 wants to reach the destination network connected to R5 and we have OSPF configured everywhere.
R1 will check which is the lowest cost path and will make it his best route and add it in his routing table.
Let’s check the cost via R2:
7 + 5 + 5 = 17
Let’s check the cost via R3:
5 + 5 + 5 = 15
Let’s check the cost via R4:
15 + 10 + 5 = 20
So R1 have all of these cost calculation in his LSDB, and after running the SPF algorithm he will add the route via R3 in his routing table because it has the lowest cost between all. But what about the other paths? Actually, R1 will not add them in his routing table because they have a higher cost value, but he will leave them in his OSPF database then in case the main route goes down then he will run the SPF algorithm again and will add to his routing table the 2nd best path which is in our case via R2.
Now we understand about the cost, let’s see how the load balancing happens in OSPF.
Let’s check again the scenario, I see that the path from R1 via R2 and the path from R1 via R3 have now equal cost which is 15.
In this case, OSPF will add the 2 paths in his routing table because they have equal costs. Remember, OSPF works only on equal cost. Some other routing protocols like EIGRP in Cisco can do unequal cost load balancing, but OSPF cannot.
Once we have the 2 routes in R1 routing table, then he will do load balancing splitting the bandwidth to the destination network as 50/50 from each route.