BGP - Always Compare MED

    BGP path selection is based on many attributes, one of the attribute is BGP METRIC (MED), which will be used only when the EBGP traffic is coming from the same AS. I would recommend you to have a look at the BGP METRIC (MED) - BGP ATTRIBUTE before reading this article.

Consider the below topology for Default BGP METRIC behavior:

From the above topology, 
  • R1 will use METRIC attribute because it will receive routes from R2 and R3.
  • R1 receiving routes from the same AS_23 (R2 and R3 are from the AS_23), so it will compare the best metric value and forward the traffic. If R2 and R3 are from different AS, metric will be considered from R1 router for forwarding traffic.

Now, let's start with BGP Always compare MED:

Consider the below Topology:

From the above topology, 
Our task is to reach 4.4.4.4/32 in AS_4 from R1
We can see that R1 from AS_1 is connected to R2 (AS_2) and R3(AS_3) in order to reach 4.4.4.4/32
We need to use BGP MED (METRIC) to manipulate the traffic.

Lets the start the configuration:

R1 Interface Information:
R1#show ip int brief
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.12.1    YES manual up                    up
FastEthernet0/1            192.168.13.1    YES manual up                    up
R1#

R2 Interface Information:
R2#show ip int brief
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.12.2    YES manual up                    up
FastEthernet0/1            192.168.24.2    YES manual up                    up
R2#

R3 Interface Information:
R3#show ip int brief
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.13.3    YES manual up                    up
FastEthernet0/1            192.168.34.3    YES manual up                    up
R3#

R4 Interface Information:
R4#show ip int br
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.24.4    YES manual up                    up
FastEthernet0/1            192.168.34.4    YES manual up                    up
Loopback0                  4.4.4.4         YES manual up                    up
R4#

R1 BGP Configuration:
R1#conf terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.12.2 remote-as 2
R1(config-router)#neighbor 192.168.13.3 remote-as 3
R1(config-router)#redistribute connected
R1(config-router)#end
R1#

R2 BGP Configuration:
R2#conf terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R2(config)#router bgp 2
R2(config-router)#neighbor 192.168.12.1 remote-as 1
R2(config-router)#neighbor 192.168.24.4 remote-as 4
R2(config-router)#end
R2#

R3 BGP Configuration:
R3#conf terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R3(config)#router bgp 3
R3(config-router)#neighbor 192.168.13.1 remote-as 1
R3(config-router)#neighbor 192.168.34.4 remote-as 4
R3(config-router)#end
R3#

R4 BGP Configuration:
R4#conf terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R4(config)#router bgp 4
R4(config-router)#neighbor 192.168.24.2 remote-as 2
R4(config-router)#neighbor 192.168.34.3 remote-as 3
R4(config-router)#network 4.4.4.4 mask 255.255.255.255
R4(config-router)#end
R4#

R1 BGP Table:

From the above BGP table, we can see that the R1 prefers R2 (Next hop: 192.168.12.2 ) to reach the destination 4.4.4.4/32

Now we need to make R1 to prefer R3(Next Hop: 192.168.13.3) as a next-hop to reach 4.4.4.4/32 using Metric Attribute.

Creating a ROUTE-MAP in R2:
R2#conf ter
R2(config)#route-map METRIC-TEST
R2(config-route-map)#match ip address 1
R2(config-route-map)#set metric 500
R2(config)#route-map METRIC-TEST permit 20
R2(config-route-map)#exit
R2(config)#end
R2#

Viewing the Route-map in R2:
R2#show route-map
route-map METRIC-TEST, permit, sequence 10
  Match clauses:
    ip address (access-lists): 1
  Set clauses:
    metric 500
  Policy routing matches: 0 packets, 0 bytes
route-map METRIC-TEST, permit, sequence 20
  Match clauses:
  Set clauses:
  Policy routing matches: 0 packets, 0 bytes
R2#

Creating an ACL in R2:
R2# conf ter
R2(config)#access-list 1 permit host 4.4.4.4
R2(config)#end
R2#

Viewing the Access-list in R2:
R2#show access-lists
Standard IP access list 1
    10 permit 4.4.4.4
R2#

Mapping the Route-map to BGP in R2:
R2(config)#router bgp 2
R2(config-router)#neighbor 192.168.12.1 route-map METRIC-TEST out
R2(config-router)#end
R2#


Creating a ROUTE-MAP in R3:
R3#conf ter
R3(config)#route-map METRIC-TEST
R3(config-route-map)#match ip address 1
R3(config-route-map)#set metric 300
R3(config-route-map)#exi
R3(config)#route-map METRIC-TEST permit 20
R3(config-route-map)#exi
R3(config)#

Viewing the Route-map in R3:
R3#show route-map
route-map METRIC-TEST, permit, sequence 10
  Match clauses:
    ip address (access-lists): 1
  Set clauses:
    metric 300
  Policy routing matches: 0 packets, 0 bytes
route-map METRIC-TEST, permit, sequence 20
  Match clauses:
  Set clauses:
  Policy routing matches: 0 packets, 0 bytes
R3#

Creating an ACL in R3:
R3#conf ter
R3(config)#access-list 1 permit host 4.4.4.4
R3(config)#end
R3#

Viewing the Access-list in R3:
R3#show access-lists
Standard IP access list 1
    10 permit 4.4.4.4
R3#

Mapping the Route-map to BGP in R3:
R3#conf ter
R3(config)#router bgp 3
R3(config-router)#neighbor 192.168.13.1 route-map METRIC-TEST out
R3(config-router)#end
R3#

Now, checking the BGP table of R1:

From the above BGP table,
  • Metric are updated from both the neighbors, R2 (metric: 500) and R3(metric: 300)
  • Still R2 remains the next-hop router. The change doesn't manipulate the traffic flow, because the network R2 and R3 are learned from the different AS.

BGP Always compare MED configuration has to be done from R1 router. Below is the configuration,
R1#conf terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R1(config)#router bgp 1
R1(config-router)#bgp always-compare-med
R1(config-router)#end
R1#

In some older versions, we need to clear the complete BGP session to take metric into effect. This can be done using the command "clear ip bgp *". Please note that this will kill the TCP sessions and your neighbor will go down and try to form again.

Below is the BGP table of R1 after clearing the bgp session using the command "clear ip bgp *"

  • Now in the R1 BGP table, we can see that, it prefers to use R3 (192.168.13.3) as Next Hop to reach 4.4.4.4/32.
  • This is achieved because now R1 compared the Metric (MED) even if it received from different AS number. Since R3 has a lower METRIC, it is more preferred as compared to R2.
Thanks for reading this article...!!!
You can also look into my video tutorial in Tamil:

Post a Comment