For a Summary of this great protocol please check out this link: BGP Summary
the topology used:
Note: When BGP receives multiple routes to a particular destination, it lists them in the reverse order that they were received, from the newest to the oldest. BGP then compares the routes in pairs, starting with the newest entry and moving toward the oldest entry (starting at top of the list and moving down). For example, entry1 and entry2 are compared. The better of these two is then compared to entry3, and so on.
we can see that to get to the 220.127.116.11 network, R1 is choosing R3 as the best path because of Step 7 of the BGP Algorithm Process should win here again (Ebgp over IGBP), without comparing any med value.
we can test this decision process, by turning down the peering relationship between R1 and R3
we can see that we prefer now the path towards R2, because of a lower MED value, if we change the metric to something higher than R4’s metric announced to R1, in R2 (say 200).
and having that route announce from R2 to R1
R1 is going now to preferring the path over R4, because of a better MED Value (lower value), Lets change the MED again to 100 in R2 for the BGP Peering relationship between R4 and R2, now R1 is going to prefer the path to reach the 18.104.22.168/32 network over R2 because we are comparing the MED Values in the same Group (AS 4,3)
We can see that R1 is preferring R2 to reach the network, so this is very OK, routers are talking here 🙂
Now, lets enable again then the relationship with R3 again, and proceed test out the Example 2
here, we have 3 entries now, and 1 of the entries is arriving from a different autonomous system number, we do not compare the MED value by default in this case, entry 1 is the Best path because of the administrative distance (External Vs Internal ) , so we stop at step 7 on the decision process… and the Step 6 is not analyzed this step indicates that comparison only occurs if the first (the neighboring) AS is the same in the two paths. Any confederation sub-ASs are ignored
Entry1 is compared to entry2. These entries are from different neighbor autonomous systems, but since the bgp always-compare-med command is enabled, MED is used in the comparison. Of these two entries, entry1 is better because it has a lower MED. Next, entry1 is compared to entry3. The MED is checked again because the entries are now from the same autonomous system. Entry3 is chosen as the best path.
entry1: AS(PATH) 500, med 150, external, rid 172.16.13.1 entry2: AS(PATH) 100, med 200, external, rid 22.214.171.124 entry3: AS(PATH) 500, med 100, internal, rid 172.16.8.4
from this output we determine that Entry 1 received from 126.96.36.199, with AS 4,3, Entry 2 received from 188.8.131.52 with AS 4,3 and Entry 3 comes from 184.108.40.206, with AS 3,3.
Entry 1 is evaluated with Entry 2, since both entries transport the same AS information, the Step 6 of the decision process is now perform, and the best path is Entry 1 because it has the lowest MED and wins over the med that carried in Entry 2. Step 6 of the decision process. Now Entry 1 is compared with Entry 3, and Entry 1 (lowest MED) is the winner of the election process because of the ALWAYS-COMPARE-MED, configuration done in the BGP Process. And this is testable by the outputs before enabling the always-compare-med, so we are like relaxing a little bit the rule of step 6 … This comparison only occurs if the first (the neighboring) AS is the same in the two paths. and instead of not comparing the MED Value of the route received over to different AS, with this command we can now compare the entries with the MED Value even if the Entries are not from the same AS.
When the bgp deterministic-med command is enabled, routes from the same autonomous system are grouped together, and the best entries of each group are compared. The BGP table looks like this:
entry1: AS(PATH) 100, med 200, external, rid 220.127.116.11 entry2: AS(PATH) 500, med 100, internal, rid 172.16.8.4 entry3: AS(PATH) 500, med 150, external, rid 172.16.13.1
There is a group for AS 100 and a group for AS 500. The best entries for each group are compared. Entry1 is the best of its group because it is the only route from AS 100. Entry2 is the best for AS 500 because it has the lowest MED. Next, entry1 is compared to entry2. Since the two entries are not from the same neighbor autonomous system, the MED is not considered in the comparison. The external BGP route wins over the internal BGP route, making entry1 the best route.
Group 1: Entry 1 = 3,3 from 18.104.22.168
Group 2: Entry 2 = 4,3 from 22.214.171.124 vs Entry 3 = 4,3 from 126.96.36.199
Entry 1 is the only one on that group so no other entries on that group to compare. so he is the winner by forfeit. Now Group 2 is now evaluated, and here we have 2 entries, Entry 2 and Entry 3 are compared and Entry 2 wins the process because of a better MED Value (lowest metric again step 6), now the winners of each group are compared and Entry 1 from Group 1 is compared with the winner of Group 2 (Entry 2), and Entry 1 wins because of step 7, since we are not using the always-compared-med in the BGP Routing Process, so step 6 is not checked here.The winner of each group are compared and the winner depends now on the BGP Process based on step 6 (if always compare med is enabled) or step 7 if this command is not enabled. This reminds me to those football chart 🙂
Now if we enable always-compared-med & deterministic-med, entry 2 of group #2 wins against entry 1 of group #1, because of a lower MED Value.
Enabling the bgp deterministic-med command ensures the comparison of the MED variable when choosing routes advertised by different peers in the same autonomous system. Enabling the bgp always-compare-med command ensures the comparison of the MED for paths from neighbors in different autonomous systems. The bgp always-compare-med command is useful when multiple service providers or enterprises agree on a uniform policy for setting MED.