In this lab let's configure MED for the same lab scenario,
Lab topology
Objective
- Will configure R2, R3 and R4 by setting a MED value to influence the inbound traffic.
- Will configure bgp deterministic-med and always-compare-med and observe the behavior.
For this lab scenario I have removed the local-pref and AS-prepend configuration I had done in the previous post BGP Path selection
R1#show ip bgp
BGP table version is 2, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path
*> 24.7.3.65/32 2.2.2.2 0 200 600 i
* 3.3.3.3 0 200 600 i
* 4.4.4.4 0 200 600 i
* 10.10.15.5 0 500 600 i
From the output we can see that R1 has chosen the path through 2.2.2.2 (R2) because of the lowest Router-ID. All other parameters are the same.
R1#show ip bgp 24.7.3.65
BGP routing table entry for 24.7.3.65/32, version 2
Paths: (4 available, best #1, table default)
Advertised to update-groups:
6
Refresh Epoch 2
200 600
2.2.2.2 from 2.2.2.2 (2.2.2.2)
Origin IGP, localpref 100, valid, external, best
rx pathid: 0, tx pathid: 0x0
Refresh Epoch 2
200 600
3.3.3.3 from 3.3.3.3 (3.3.3.3)
Origin IGP, localpref 100, valid, external
rx pathid: 0, tx pathid: 0
Refresh Epoch 2
200 600
4.4.4.4 from 4.4.4.4 (4.4.4.4)
Origin IGP, localpref 100, valid, external
rx pathid: 0, tx pathid: 0
Refresh Epoch 2
500 600
10.10.15.5 from 10.10.15.5 (5.5.5.5)
Origin IGP, localpref 100, valid, external
rx pathid: 0, tx pathid: 0
I have cleared the peering with 2.2.2.2 and now 3.3.3.3 is chosen as the best path because it has the second lowest router-id after 2.2.2.2.
R1#show ip bgp 24.7.3.65/32
BGP routing table entry for 24.7.3.65/32, version 3
Paths: (4 available, best #2, table default)
Advertised to update-groups:
6
Refresh Epoch 2
200 600
2.2.2.2 from 2.2.2.2 (2.2.2.2)
Origin IGP, localpref 100, valid, external
rx pathid: 0, tx pathid: 0
Refresh Epoch 2
200 600
3.3.3.3 from 3.3.3.3 (3.3.3.3)
Origin IGP, localpref 100, valid, external, best
rx pathid: 0, tx pathid: 0x0
Refresh Epoch 2
200 600
4.4.4.4 from 4.4.4.4 (4.4.4.4)
Origin IGP, localpref 100, valid, external
rx pathid: 0, tx pathid: 0
Refresh Epoch 2
500 600
10.10.15.5 from 10.10.15.5 (5.5.5.5)
Origin IGP, localpref 100, valid, external
rx pathid: 0, tx pathid: 0
Now I will set the metric values on R2, R3 and R4, where I will set the metric accordingly
- R2 metric 500
- R3 metric 300
- R4 metric 400
So R3 having the lowest MED metric value will be chosen as the best route.
R1#clear ip bgp *
R1#show ip bgp
BGP table version is 3, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path
*> 24.7.3.65/32 3.3.3.3 300 0 200 600 i !-- Here we can see that path through R3 is the best path.
* 4.4.4.4 400 0 200 600 i
* 2.2.2.2 500 0 200 600 i
* 10.10.15.5 0 500 600 i
Now I will set the MED value of R4 to 300 which will make it the same to R3. Then let's see the results.
R1#show ip bgp
BGP table version is 3, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path
* 24.7.3.65/32 4.4.4.4 300 0 200 600 i
*> 3.3.3.3 300 0 200 600 i
* 2.2.2.2 500 0 200 600 i
* 10.10.15.5 0 500 600 i
R1 BGP still chooses the path through R3 as the best path, because R3's route is more stable because of being older to R4.
If we want to make BGP to compare MED between advertisements from the same AS irrespective of their age. We can use the bgp deterministic-med router configuration command. When this command is enabled the router will group all paths from the same AS and compare them together before comparing them to paths from different ASes.
R1#show ip bgp
BGP table version is 2, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path
*> 24.7.3.65/32 3.3.3.3 300 0 200 600 i !- Best path is through R3
* 2.2.2.2 500 0 200 600 i !- Next in order is 2.2.2.2
* 4.4.4.4 300 0 200 600 i
* 10.10.15.5 350 0 500 600 i
As you can see that routes with same MED value are not grouped together. R3 and R4 have a MED value of 300 but there is a MED value of 500 before R4 metric 300.
Once I configure bgp deterministic-med on all the routers R1-to-R4. We can see that the routes have been grouped by metric value.
R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#router bgp 100
R1(config-router)#bgp deterministic-med
R1(config-router)#exit
R1(config)#end
R1#
*Mar 18 22:41:33.863: %SYS-5-CONFIG_I: Configured from console by console
R1#show ip bgp
BGP table version is 2, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path
*> 24.7.3.65/32 3.3.3.3 300 0 200 600 i 300
* 4.4.4.4 300 0 200 600 i
* 2.2.2.2 500 0 200 600 i
* 10.10.15.5 350 0 500 600 i
Now you can see that R3 and R4 routes have been grouped together due to the metric value. The prefix entries have been re-ordered where the prefix within a group are at the top of the list. First the two paths within the group are compared to determine the best path, then this best value is compared against the next group. MED values are only compared within the same autonomous system.
R3 route has been chosen as the best path because of the following reasons.
- Router-id of R3 (3.3.3.3) is lower then the router-id of R4 (4.4.4.4), all other parameters are same.
- Even though R2 has a lower router-id but its MED value is set to 500.
- R5 route has a MED value configured for 350.
If BGP Deterministic MED is used, it should be enabled on all BGP speaking devices within an AS to ensure a consistent policy regarding the use of MEDs.
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. Cisco website
Note: Cisco Systems recommends enabling the bgp deterministic-med command in all new network rollouts. For existing networks, the command must either be deployed on all routers at the same time, or incrementally, with care to avoid possible internal BGP (iBGP) routing loops.
This topic concludes here, if you think I may have been missing anything important in this topic, please let me know and I will update.