BGP IPv4 - Med Always Compare

Med Always Compare

In BGP (Border Gateway Protocol), the "always compare MED" attribute configuration determines whether the Multi-Exit Discriminator (MED) values should be considered for path selection even if the paths are from different autonomous systems. When this feature is enabled with the "always compare MED" setting, BGP routers will compare MED values even for routes learned from different ASes during the best path selection process. Typically, BGP ignores MED when comparing routes from different ASes, prioritizing the AS path length. However, enabling "always compare MED" can be useful in scenarios where cross-AS comparisons of MED values are desired, providing more flexibility in influencing route selection based on MED values regardless of the AS path. This feature is a crucial aspect of fine-tuning BGP routing decisions in complex network environments.

Lab:

BGP Topology

Disclaimer

This Configuration Guide is designed to assist members to enhance their skills in particular technology area. While every effort has been made to ensure that all material is as complete and accurate as possible, the enclosed material is presented on an “as is” basis. Neither the authors nor Forum assume any liability or responsibility to any person or entity with respect to loss or damages incurred from the information contained in this guide. This configuration guide was developed by Forum. Any similarities between material presented in this configuration guide and any other material is completely coincidental.

Cisco IOS Software, Linux Software (I86BI_LINUX-ADVENTERPRISEK9-M), Version 15.2(4)M1, DEVELOPMENT TEST SOFTWARE

Task 1: Configure IPv4 BGP MED compare always

Step 2: In the configuration mode of router configure IPv4 BGP Process by following command:

R1:
interface Serial2/0
ip address 12.0.0.1 255.255.255.0
no shutdown
interface Loopback100
ip address 100.0.0.1 255.255.255.0
exit

router bgp 65100
neighbor 12.0.0.2 remote-as 65000
address-family ipv4
network 100.0.0.0 mask 255.255.255.0
exit

R2: 
interface Serial2/0
ip address 12.0.0.2 255.255.255.0
no shutdown
interface Ethernet0/0
ip address 23.0.0.2 255.255.255.0
no shutdown
exit

router bgp 65000
neighbor 12.0.0.1 remote-as 65100
neighbor 23.0.0.3 remote-as 65000
exit

R3: 
interface Ethernet0/0
ip address 23.0.0.3 255.255.255.0
no shutdown
interface Serial2/0
ip address 34.0.0.3 255.255.255.0
no shutdown
exit

router bgp 65000
neighbor 34.0.0.4 remote-as 65200
neighbor 23.0.0.2 remote-as 65000
exit
		
R4:
interface Serial2/0
ip address 34.0.0.4 255.255.255.0
no shutdown
interface Loopback100
ip address 100.0.0.4 255.255.255.0
exit

router bgp 65200
neighbor 34.0.0.3 remote-as 65000
address-family ipv4
network 100.0.0.0 mask 255.255.255.0
exit
		
R2:
R2#show bgp ipv4 unicast
BGP table version is 2, local router ID is 23.0.0.2
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
 *>  100.0.0.0/24     12.0.0.1         0             		  0 	65100 i
 * i                  34.0.0.4         0    	100           0 	65200 i

Router R2 has two path to reach the network 100.0.0.0/24 via 34.0.0.4 & via 12.0.0.1
Router R2 selects 12.0.0.1 as its best path to reach 100.0.0.0/24 network.

Step 2: Configure BGP path manipulation using MED by following command

R2:
router bgp 65000
neighbor 12.0.0.1 remote-as 65100
neighbor 12.0.0.1 route-map abc in
exit
route-map abc permit 10
set metric 100
exit

R2#show bgp ipv4 unicast
BGP table version is 2, local router ID is 23.0.0.2
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
 *>  100.0.0.0/24     12.0.0.1        100             	  	   0 	 65100 i
 * i                  34.0.0.4         0    	 100           0 	 65200 i

Router R2 has two path to reach the network 100.0.0.0/24 via 12.0.0.1 & via 34.0.0.4.
BGP path manipulation is done by setting higher metric value of 100 for path via 12.0.0.1 using MED, but still Router R1 selects the same path via 12.0.0.1 as its best path, because MED is local to a router and it is use to change router’s decision when it receives multiple path from same AS.
Therefore to compare routes from different Autonomous system can be achieved by ‘bgp always-compare-med’ command.

Step 3: Configure MED compare always using ‘bgp always-compare-med’ command

R2:
router bgp 65000
bgp always-compare-med
exit

Step 4: Verify MED compare always

R2#show bgp ipv4 unicast
BGP table version is 2, local router ID is 23.0.0.2
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
 *   100.0.0.0/24     12.0.0.1       100                      0 	  65100 i
 *>i                  34.0.0.4        0    	     100      	  0 	  65200 i

 To compare MED metric routes from different Autonomous system can be achieved by ‘bgp always-compare-med’ command.