What is the MED?

The MED (Multi-Exit Discriminator) is an optional BGP attribute, that is used when there are multiple external points for a single AS.

For example, you may want traffic coming into your AS destined for network A to take one path but traffic destined for network B to take another.

This is achieved by both routers within the single AS, assigning a MED value to the prefix which is then advertised to the upstream router. The upstream router, as part of the best path selection process, will then select the necessary path based on the lowest MED for the given prefix.

image1-3
Figure 1 - BGP MED.

Example

Let us look at an example of MED in action.

Topology

Our topology and example are based upon:

  • 2 networks being advertised from behind R4.
  • A route map configured on R2 and R3 to add the required MED attributes to networks 100.1.1.0/24 and 100.2.1.0/24.
  • The MED attributes will be used by R1 to ensure traffic ingress to AS200 result in R1 sending traffic to 100.1.1.0/24 via R2 and 100.2.1.0/24 via R3.

med
Figure 2 - MED Topology example.

First of all, if we look at the best path, we can see that the best path selected (denoted via >) for both prefixes (10.[1-2].100.0/24) is 2.2.2.2 (R2).


R1#show ip bgp           
BGP table version is 4, 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, 
              t secondary path, 
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *    10.1.100.0/24    3.3.3.3                                0 200 i
 *>                    2.2.2.2                                0 200 i
 *    10.2.100.0/24    3.3.3.3                                0 200 i
 *>                    2.2.2.2                                0 200 i

Configuration

Our configuration will follow the following steps on R2 and R3:

  1. An access list will define the network.
  2. A route map will be assigned the network (ACL) to an action.
  3. The route map action will be to set the MED value for the route.
  4. The route map will then be assigned to the R1 neighbour, based on outbound advertisements.

Let us begin…

R2

R2(config)# access-list 1 permit 10.1.100.0 0.0.0.255
R2(config)# access-list 2 permit 10.2.100.0 0.0.0.255

R2(config)# route-map MED permit 10
R2(config-route-map)# match ip address 1
R2(config-route-map)# set metric 100

R2(config)# route-map MED permit 20
R2(config-route-map)# match ip address 2
R2(config-route-map)# set metric 200
R2(config)# router bgp 200

R2(config-router)# neighbor 1.1.1.1 route-map MED out

R2# clear bgp ip * soft

R3

R3(config)# access-list 1 permit 10.1.100.0 0.0.0.255
R3(config)# access-list 2 permit 10.2.100.0 0.0.0.255

R3(config)# route-map MED permit 10
R3(config-route-map)# match ip address 1
R3(config-route-map)# set metric 200

R3(config)# route-map MED permit 20
R3(config-route-map)# match ip address 2
R3(config-route-map)# set metric 100

R3(config)# router bgp 200
R3(config-router)# neighbor 1.1.1.1 route-map MED out

R3# clear bgp ip * soft

Verification

To verify our configured is working correctly, we can look at the BGP table to look at the valid and best BGP paths on R1. As you can see the metric is assigned correctly again each prefix for R2 and R3.


R1#show ip bgp 
BGP table version is 19, 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, 
              t secondary path, 
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
     Network          Next Hop            Metric LocPrf Weight Path
 *    10.1.100.0/24    3.3.3.3                200             0 200 i
 *>                    2.2.2.2                100             0 200 i
 *>   10.1.200.0/24    0.0.0.0                  0         32768 i
 *>   10.2.100.0/24    3.3.3.3                100             0 200 i
 *                     2.2.2.2                200             0 200 i

Final confirmation can be seen from the BGP table with regards to the routes propagating into the RIB. As shown below:


R1#show ip route bgp 
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR

Gateway of last resort is not set
      10.0.0.0/8 is variably subnetted, 8 subnets, 3 masks
B        10.1.100.0/24 [20/100] via 2.2.2.2, 13:48:23
B        10.2.100.0/24 [20/100] via 3.3.3.3, 13:37:26