To understand the use of BGP deterministic-MED we must first understand behavior of BGP algorithm when a route is received on a router via multiple paths.
Understanding BGP Algorithm
BGP algorithm assigns the first valid path as the current best path. This first valid path is then compared with the next path listed. 1st and 2nd path are compared and out them the one chosen as best is then compared with 3rd path and so on until the end of paths in the list is reached.
What is BGP deterministic-MED?
Because of the way BGP’s best path algorithm works, it can lead to MED being left uncompared between routes using identical AS_PATH’s towards a prefix.
As we all are aware the BGP always compare-MED feature ensures the MED gets compared when different AS are advertising the same route BGP Deterministic-med feature ensures the MED gets compared for a route being advertised from different paths in same AS.
How does it work?
Let us take the example of below diagram to further understand how BGP deterministic MED works.
In the diagram below R5 advertises its loopback 126.96.36.199/32 towards R1.
R1 gets this update from 3 paths R2, R3 & R4 with different MED values.
R3 & R4 are within the same AS 300 and R2 is within AS 200.
Routing Table on R1:
According to the BGP best path algorithm the most recent path is evaluated against the path below it.
Between the Route from R3 and R2 , R2 is chosen as the best path. This is so because the MED isn’t compared for BGP updates from R2 & R3 as they are part of different AS and as per BGP algorithms working the older route is preferred one which here is from R2.
Now comparing routes from R2 with route from R4 again MED isn’t compared as they are both from different AS. R4 being the older route here is preferred over the route from R2 and hence is selected as the best. So we see in this scenario how the MED working of preferring the lower MED updates hasn’t taken effect in this scenario.
To overcome this situation we use BGP deterministic-med on R1. Deterministic-med rectifies this problem by listing one route from same AS_PATH under a group in BGP table. Paths within a group are then compared against each other. Then the best of the group is compared against the next group down.
Enabling BGP Deterministic-MED
Routing Table on R1 now:
Now we see the table has been restructured and the routes with same AS path are grouped together.
Routes from R3 and R4 are compared and since route from R3 has lower MED it is best out of the group. Now route from R3 is compared with the only route of other group i.e. from R2 and since the route from R3 is older it is preferred and selected as best based on BGP’s algorithm default working.