Showing posts with label Routing. Show all posts
Showing posts with label Routing. Show all posts

Saturday, May 9, 2026

EVPN, Simplest Example

 I've been meaning to write this one up for a while. If you've been working in networking for the last few years, you've probably heard about EVPN-VXLAN. Maybe it's been pitched to you as the next-gen data center fabric, the spine-leaf revolution, or the thing that kills spanning tree for good. All true, by the way.

But reading about it and actually building it are two different things. I spent last weekend wiring up a lab with Arista vEOS containers, and I figured I'd walk through exactly how it works — not the theory, but the actual config. Here's what I built and how it all fits together.

The Topology

I won't bore you with a Visio diagram. Here's what it looks like:

         Spine-1              Spine-2
       11.1.1.1/32          22.2.2.2/32
       100.0.0.1/32         100.0.0.2/32
           |                      |
      10.1.x.x/30-------------10.2.x.x/30
           |                      |
      Leaf-2 ==(MLAG)== Leaf-4    Leaf-3
     100.0.0.22/32             100.0.0.33/33
           |                      |
          EP-1                   EP-2

Four Arista switches. Two spines, two leafs in an MLAG pair, one standalone leaf, and two endpoints that simulate actual servers. No hardware — just vEOS-lab boxes running EOS 4.26.9M.

Step 1: The Underlay (Just Good Old OSPF)

Before you can do any fancy overlay stuff, the switches need to talk to each other. I went with OSPF because it's dead simple and I don't need BGP at the underlay level for a lab.

Every switch gets a Loopback0 for the router-id and a Loopback1 for VTEP traffic. The point-to-point links between spines and leaves go into OSPF area 0. Here's what it looks like on a spine:

router ospf 1
   router-id 11.1.1.1
   network 10.1.2.0/30 area 0.0.0.0
   network 10.1.3.0/30 area 0.0.0.0
   network 10.1.4.0/30 area 0.0.0.0
   network 11.1.1.1/32 area 0.0.0.0

And a leaf:

router ospf 1
   router-id 2.2.2.2
   network 2.2.2.2/32 area 0.0.0.0
   network 10.1.2.0/30 area 0.0.0.0
   network 10.2.2.0/30 area 0.0.0.0
   network 100.0.0.22/32 area 0.0.0.0

Notice I'm advertising the VTEP loopback (100.0.0.x) into OSPF too. That's critical — the VTEPs need to reach each other's source IPs, otherwise VXLAN encapsulation won't work.

The spine interfaces are pure L3 (no switchport, IP configured). The leaf interfaces facing the spines are also L3. Only the ports facing endpoints are switchports.

Step 2: iBGP for EVPN — Spines as Route Reflectors

This is where it gets interesting. The overlay (EVPN) runs over iBGP with the spines acting as route reflectors. The leaves peer with both spines, and the spines reflect routes between leaves. No full mesh required.

On both spines, the config is almost identical:

router bgp 65000
   router-id 11.1.1.1
   no bgp default ipv4-unicast
   neighbor 2.2.2.2 remote-as 65000
   neighbor 2.2.2.2 update-source Loopback0
   neighbor 2.2.2.2 route-reflector-client
   neighbor 2.2.2.2 send-community
   !
   address-family evpn
      neighbor 2.2.2.2 activate
      neighbor 3.3.3.3 activate

The route-reflector-client line is the key — it tells the spine to redistribute EVPN routes it learns from one leaf to the other leaves. Without it, each leaf would need a BGP session to every other leaf, which doesn't scale.

On the leaf side, it's simpler:

router bgp 65000
   router-id 2.2.2.2
   neighbor 11.1.1.1 remote-as 65000
   neighbor 11.1.1.1 update-source Loopback0
   neighbor 11.1.1.1 send-community
   neighbor 22.2.2.2 remote-as 65000
   !
   address-family evpn
      neighbor 11.1.1.1 activate
      neighbor 22.2.2.2 activate

Why two spines? Redundancy. If Spine-1 dies, EVPN routes still flow through Spine-2. The leaves install routes from both and get ECMP (equal-cost multipath) automatically. You can see this in the route table — routes show up with * >Ec flags, meaning they're reachable via both spines.

Step 3: VLANs to VNIs — The Heart of VXLAN

VXLAN is basically VLAN-on-steroids. Instead of a 12-bit VLAN ID (max 4094), you get a 24-bit VNI (VXLAN Network Identifier) — 16 million segments. But the real magic is that VXLAN encapsulates L2 frames inside UDP packets, so they can travel across L3 networks.

I mapped VLANs to VNIs like this:

10 10010 Management-ish segment
50 10050 Spare / not fully used yet
55 10055 Tenant A workload
66 10066 Tenant B workload (only on Leaf-2/4)

On the leaf, you configure the VXLAN interface like this:

interface Vxlan1
   vxlan source-interface Loopback1
   vxlan udp-port 4789
   vxlan vlan 10,50,55,66 vni 10010,10050,10055,10066
   vxlan vrf A vni 55555
   vxlan vrf B vni 66666

source-interface Loopback1 is your VTEP IP. In my case, Leaf-2 and Leaf-4 use 100.0.0.22, Leaf-3 uses 100.0.0.33. The spines don't run VXLAN at all — they're pure L3 switches that just forward the encapsulated UDP packets between VTEPs.

Step 4: L2 EVPN — Telling Other Switches About MACs

EVPN is the control plane for VXLAN. It's what tells VTEPs "hey, MAC address aa:bb:cc:dd is reachable behind VTEP 100.0.0.33, send your VXLAN traffic there."

There are a few route types in EVPN. The ones that matter most are:

Type 2 (MAC/IP Advertisement): This is what teaches the fabric about host MACs and optionally their IPs. Each leaf runs the redistribute learned command under the VLAN BGP config, which tells BGP to push locally-learned MACs into EVPN:

   vlan 55
      rd 2.2.2.2:10055
      route-target both 10055:10055
      redistribute learned

When EP-2 (connected to Leaf-3) sends a frame, Leaf-3 learns its MAC and advertises it via BGP EVPN to both spines, which reflect it to Leaf-2/4. Now Leaf-2 knows: "MAC 5001.009b.566c is behind 100.0.0.33."

Type 3 (IMET — Inclusive Multicast Ethernet Tag): This handles BUM traffic (broadcast, unknown unicast, multicast). Each leaf tells the others "I'm participating in VNI 10055, send BUM traffic to my VTEP IP." Looks like this in the EVPN table:

RD: 2.2.2.2:10055 imet 100.0.0.22
RD: 3.3.3.3:10055 imet 100.0.0.33

ARP requests (broadcasts) get flooded to all VTEPs participating in that VNI.

Step 5: L3 EVPN — Routing Between Subnets

Here's where it gets really cool. With traditional VXLAN, inter-subnet traffic has to hairpin through a gateway. With EVPN, you can run an anycast gateway — every leaf acts as the default gateway for the same subnet, with the same IP AND the same MAC address.

interface Vlan55
   vrf A
   ip address virtual 10.55.55.1/24

Both Leaf-2 and Leaf-3 have this same config. The virtual keyword means the gateway IP 10.55.55.1 is active on both switches simultaneously. Hosts that ARP for their gateway get the same MAC response from any leaf. As far as the hosts are concerned, their gateway is always local.

For routing between different tenants/subnets, you use a Layer 3 VNI. I have VRF A (L3VNI 55555) and VRF B (L3VNI 66666). Traffic between VRF A and VRF B on different leaves gets VXLAN-encapsulated with the L3VNI. On the same leaf, it routes locally.

The BGP config for VRFs looks like:

   vrf A
      rd 2.2.2.2:1
      route-target import evpn 1:1
      route-target export evpn 1:1
      redistribute connected

The Route Target (RT) controls who imports what. RT 1:1 is for VRF A, RT 2:2 is for VRF B. You can cross-import them if you want — Leaf-2's VRF B actually imports both RT 1:1 and RT 2:2, which means VRF B can reach VRF A routes. That's how EP-1 on VLAN 66 (VRF B, 10.66.66.0/24) can reach EP-2 on VLAN 55 (VRF A, 10.55.55.0/24).

Type 5 (IP Prefix): These are the L3 EVPN routes. Instead of advertising a MAC, they advertise an IP prefix:

RD: 2.2.2.2:1 ip-prefix 10.55.55.0/24
RD: 3.3.3.3:1 ip-prefix 10.55.55.0/24

This tells the fabric "I have the subnet 10.55.55.0/24 locally." Both leaves advertise it because both have the anycast gateway configured.

Step 6: MLAG — The Ugly Truth About Redundancy

I've got Leaf-3 and Leaf-4 in an MLAG pair. MLAG (Multi-Chassis Link Aggregation) lets you connect a server or switch to two switches using a standard LAG/LACP bundle, making both switches look like a single device.

mlag configuration
   domain-id mlag1
   local-interface Vlan4094
   peer-address 10.40.94.4
   peer-link Port-Channel100

The peer-link (Port-Channel100, built from two 10G links) carries all VLANs plus the MLAG keepalive VLAN 4094. The peer-address is how the two switches talk MLAG protocol.

Why MLAG in an EVPN fabric? Because some endpoints don't speak BGP or EVPN and just want a simple LACP bundle to two switches. EP-2 connects to Leaf-3 via Port-Channel5 (two member links) with MLAG. If one leaf goes down, the server keeps forwarding through the other leaf.

One thing that tripped me up: the VTEP source IP on MLAG pairs should use the same IP (100.0.0.22) so that remote VTEPs see both switches as the same VXLAN endpoint. The vxlan virtual-router encapsulation mac-address mlag-system-id line takes care of the MAC part — both switches use the same MLAG system MAC for VXLAN encapsulation, so remote switches don't flip-flop between MAC addresses.

The Traffic Flow

Let me walk through what happens when EP-1 (10.55.55.10, connected to Leaf-2) sends a packet to EP-2 (10.55.55.2, connected to Leaf-3):

  1. Same subnet: EP-1 does a MAC lookup. If it already knows EP-2's MAC (learned from an earlier ARP), it sends the frame directly.
  2. Leaf-2 receives the frame on access port Ethernet3, VLAN 55. It looks up the destination MAC in its MAC table.
  3. The MAC is remote — Leaf-2 learned it via EVPN Type 2 route: MAC 5001.009b.566c is behind VTEP 100.0.0.33.
  4. VXLAN encapsulation: Leaf-2 takes the original L2 frame and wraps it in a UDP packet with VNI 10055, outer source IP 100.0.0.22, outer destination IP 100.0.0.33.
  5. Routing through spines: The spine doesn't care about VXLAN. It looks at the outer IP header (100.0.0.22 → 100.0.0.33) and routes it via OSPF.
  6. Leaf-3 receives and decapsulates: Takes the outer header off, gets the original L2 frame, and delivers it to EP-2 on Port-Channel5, VLAN 55.

For inter-VRF traffic (say EP-2 10.55.55.2 → EP-1's other IP 10.66.66.10):

  1. EP-2 sends to its default gateway 10.55.55.1.
  2. Leaf-3 receives the packet, routes it in VRF A. Destination is 10.66.66.10, which is in VRF B.
  3. Leaf-3 doesn't have VRF B locally. It VXLAN-encapsulates using L3VNI 66666 and sends to Leaf-2.
  4. Leaf-2 decapsulates, routes in VRF B, and delivers to EP-1 on VLAN 66.

Saturday, January 17, 2015

BGP fast-external-fallover

By default, BGP fast external fallover is enabled on Cisco IOS. What this feature do is allow BGP neighbors on a directly connected interface to annound the neighbor down as soon as the carrier signal is lost on that interface. This allows faster convergence in case of link failure since the failure will be detected instantiously, but the down side for it is that a flapping link might introduce a problem for that matter.


Examining the simple topology above. R1 and R2 are EBGP peers using the directly connected interface between them.

R1#show ip bgp summary

BGP router identifier 10.1.2.1, local AS number 1

BGP table version is 1, main routing table version 1

 

Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd

10.1.2.2        4            2       9      10        1    0    0 00:05:23        0



The peering is up and everything seems fine. As mentioned earlier, the fast-external-failover feature is enabled by default, so when the link between those two routers goes down, the peering will instantly go down.

R1(config)#int f0/0
R1(config-if)#shut
R1(config-if)#
*Jan 17 01:36:11.143: BGP: tbl IPv4 Unicast:base Service reset requests
*Jan 17 01:36:11.143: BGP: tbl IPv4 Multicast:base Service reset requests
*Jan 17 01:36:11.147: BGP: 10.1.2.2 reset due to Interface flap
*Jan 17 01:36:11.151: %BGP-5-ADJCHANGE: neighbor 10.1.2.2 Down Interface flap
*Jan 17 01:36:11.151: %BGP_SESSION-5-ADJCHANGE: neighbor 10.1.2.2 IPv4 Unicast topology base removed from session  Interface flap
*Jan 17 01:36:13.115: %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to administratively down
*Jan 17 01:36:13.419: BGP: Regular scanner timer event
*Jan 17 01:36:13.419: BGP: Performing BGP general scanning
*Jan 17 01:36:13.419: BGP: tbl IPv4 Unicast:base Performing BGP Nexthop scanning for general scan
*Jan 17 01:36:13.419: BGP(0): Future scanner version: 14, current scanner version: 13
*Jan 17 01:36:13.419: BGP: tbl IPv4 Multicast:base Performing BGP Nexthop scanning for general scan
*Jan 17 01:36:13.419: BGP(6): Future scanner version: 15, current scanner version: 14
*Jan 17 01:36:14.115: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down



The reason that the BGP  peering went down was the interface flap between R1 and R2, this happened in mere milliseconds.
Now we’ll enable the interface between them and we’ll disable this feature. As a note, the hold time interval for BGP = 60 x 3 which is 180 sec

R1(config)#router bgp 1
R1(config-router)#no bgp fast-external-fallover
R1(config)#interface f0/0
R1(config-if)#shut
*Jan 17 01:43:45.659: BGP: 10.1.2.2 reset due to BGP Notification sent
*Jan 17 01:43:45.663: %BGP-5-ADJCHANGE: neighbor 10.1.2.2 Down BGP Notification sent
*Jan 17 01:43:45.663: %BGP-3-NOTIFICATION: sent to neighbor 10.1.2.2 4/0 (hold time expired) 0 bytes
*Jan 17 01:43:45.671: BGP: tbl IPv4 Unicast:base Service reset requests
*Jan 17 01:43:45.671: BGP: tbl IPv4 Multicast:base Service reset requests
*Jan 17 01:43:45.675: %BGP_SESSION-5-ADJCHANGE: neighbor 10.1.2.2 IPv4 Unicast topology base removed from session  BGP Notification sent
After three minutes, BGP peering went down due to hold time expiration.

So the logical question arise, should I leave this feature enabled or should I disable it? Well, that is dependent on many factors.
Depending on the link quality, if the feature is enabled and the link flaps a lot, that will cause many some instability of the BGP routing table, even more; remote service providers might dampen the routes you’re advertising and the more it flaps the greater the penalty on those routes.

Saturday, September 13, 2014

BGP always-compare-med vs deterministic-med

BGP route selection algorithm has always been very systematic, up until you get to the MED or ( Multi-Exit Discriminator), which can be a little bit confusing. in this post, i’ll try to make it as simple as it can be to understand the difference between using the commands bgp always-compare-med  and  bgp deterministic-med

i’m writing this assuming that the reader is fully aware of the BGP route selection, seeking only an understanding of the difference between those two commands

now let’s check the below topology


R1 in AS 1 is peering with R2 and R3 in AS23 , and with R4 in AS4, do does R5 in AS5. throughout the post, we’ll be using R1 to eexaminethe network 5.5.5.5/32 originated in AS5  as a reference to check the difference between those two commands.

Let’s first see the configuration on R1 and check the routing table

R1#show ip bgp 5.5.5.5
BGP routing table entry for 5.5.5.5/32, version 17
Paths: (3 available, best #3, table Default-IP-Routing-Table)
Flag: 0x820
 Advertised to update-groups:
       1
 23 5
   10.0.12.2 from 10.0.12.2 (2.2.2.2)
     Origin IGP, localpref 100, valid, external
 23 5
   10.0.13.3 from 10.0.13.3 (3.3.3.3)
     Origin IGP, localpref 100, valid, external
 4 5
   10.0.14.4 from 10.0.14.4 (4.4.4.4)
     Origin IGP, localpref 100, valid, external, best

when BGP received updates, it lists them in order of older (down) to newer ( up), and if there’s no tie between assuming all the routes are valid, the oldest route will be selected as the best.

we can check that by simply clearing neighbor 4.4.4.4, since the session will restart and it will be the oldest one, it’ll be the one on top and 3.3.3.3 will be at the bottom and selected as the best

R1#clear ip bgp 10.0.14.4
R1#
*Mar  1 02:25:48.883: %BGP-5-ADJCHANGE: neighbor 10.0.14.4 Down User reset
*Mar  1 02:25:49.683: %BGP-5-ADJCHANGE: neighbor 10.0.14.4 Up

R1#show ip bgp 5.5.5.5
BGP routing table entry for 5.5.5.5/32, version 6
Paths: (3 available, best #3, table Default-IP-Routing-Table)
Flag: 0x860
 Advertised to update-groups:
       1
 4 5
   10.0.14.4 from 10.0.14.4 (4.4.4.4)
     Origin IGP, localpref 100, valid, external
 23 5
   10.0.12.2 from 10.0.12.2 (2.2.2.2)
     Origin IGP, localpref 100, valid, external
 23 5
   10.0.13.3 from 10.0.13.3 (3.3.3.3)
     Origin IGP, localpref 100, valid, external, best

As expected, now let’s try sending different MED from R2,R3 and R4 to R1 and see how will that work

R1#show ip bgp 5.5.5.5
BGP routing table entry for 5.5.5.5/32, version 13
Paths: (3 available, best #2, table Default-IP-Routing-Table)
Flag: 0x4860
 Advertised to update-groups:
       1
 4 5
   10.0.14.4 from 10.0.14.4 (4.4.4.4)
     Origin IGP, metric 400, localpref 100, valid, external
 23 5
   10.0.12.2 from 10.0.12.2 (2.2.2.2)
     Origin IGP, metric 200, localpref 100, valid, external, best
 23 5
   10.0.13.3 from 10.0.13.3 (3.3.3.3)
     Origin IGP, metric 300, localpref 100, valid, external

Well, it seems that R2 now is the preferred exit for 5.5.5.5, the reason is that by default BGP will compare routes in pairs when they’re from the same neighboring system. and since the route from R4 is the oldest route and R2 is from the same AS, the comparison will take lace between R2 and R3 while excluding R4 since it’s from a different AS.

to be really sure about it, we’ll lower the metric from R4 and soft clear the sessions. R2 should still be preferred route

R1#show ip bgp 5.5.5.5
BGP routing table entry for 5.5.5.5/32, version 11
Paths: (3 available, best #2, table Default-IP-Routing-Table)
 Advertised to update-groups:
       1
 4 5
   10.0.14.4 from 10.0.14.4 (4.4.4.4)
     Origin IGP, metric 100, localpref 100, valid, external
 23 5
   10.0.12.2 from 10.0.12.2 (2.2.2.2)
     Origin IGP, metric 200, localpref 100, valid, external, best
 23 5
   10.0.13.3 from 10.0.13.3 (3.3.3.3)
     Origin IGP, metric 300, localpref 100, valid, external

and still R2 is preferred. Now to change this behavior we need to make R1 compare between routes from different autonomous systems, this can be done by the command bgp always-compare-med

the way it works is as mentioned before, BGP scans prefixes from the top down, so it will compare between the routes from R4 and R2, and the best of them will compete with the oldest route

R1(config-router)#bgp always-compare-med

R1#clear ip bgp *
*Mar  1 00:25:19.759: %BGP-5-ADJCHANGE: neighbor 10.0.12.2 Down User reset
*Mar  1 00:25:19.763: %BGP-5-ADJCHANGE: neighbor 10.0.13.3 Down User reset
*Mar  1 00:25:19.767: %BGP-5-ADJCHANGE: neighbor 10.0.14.4 Down User reset
*Mar  1 00:25:20.531: %BGP-5-ADJCHANGE: neighbor 10.0.12.2 Up
*Mar  1 00:25:20.783: %BGP-5-ADJCHANGE: neighbor 10.0.13.3 Up
*Mar  1 00:25:20.951: %BGP-5-ADJCHANGE: neighbor 10.0.14.4 Up

R1#show ip bgp 5.5.5.5
BGP routing table entry for 5.5.5.5/32, version 2
Paths: (3 available, best #1, table Default-IP-Routing-Table)
Flag: 0x820
 Advertised to update-groups:
       1
 4 5
   10.0.14.4 from 10.0.14.4 (4.4.4.4)
     Origin IGP, metric 100, localpref 100, valid, external, best
 23 5
   10.0.13.3 from 10.0.13.3 (3.3.3.3)
     Origin IGP, metric 300, localpref 100, valid, external
 23 5
   10.0.12.2 from 10.0.12.2 (2.2.2.2)
     Origin IGP, metric 200, localpref 100, valid, external

and now, even though R4 is the newest route and not from the same AS as R2 and R3, this time R4 MED is included in the path selection.

now let’s remove bgp always-compare-med  and talk about bgp deterministic-med

deterministic med will group prefix from the same ASs together in the BGP table, regardless of the way it received them, and start comparing prefixes inside each group, and the best of group will compete with the best of other groups.

The reason to do this is that eliminated the arbitrary behavior of the the oldest route being the best from routes of the same AS

R1(config)#router bgp 1
R1(config-router)#no bgp always-compare-med

R1#clear ip bgp *
*Mar  1 00:42:35.435: %BGP-5-ADJCHANGE: neighbor 10.0.12.2 Down User reset
*Mar  1 00:42:35.439: %BGP-5-ADJCHANGE: neighbor 10.0.13.3 Down User reset
*Mar  1 00:42:35.443: %BGP-5-ADJCHANGE: neighbor 10.0.14.4 Down User reset
*Mar  1 00:42:36.107: %BGP-5-ADJCHANGE: neighbor 10.0.12.2 Up
*Mar  1 00:42:36.739: %BGP-5-ADJCHANGE: neighbor 10.0.13.3 Up
*Mar  1 00:42:37.167: %BGP-5-ADJCHANGE: neighbor 10.0.14.4 Up

R1#show ip bgp 5.5.5.5
BGP routing table entry for 5.5.5.5/32, version 6
Paths: (3 available, best #3, table Default-IP-Routing-Table)
Flag: 0x4860
 Advertised to update-groups:
       1
 23 5
   10.0.12.2 from 10.0.12.2 (2.2.2.2)
     Origin IGP, metric 200, localpref 100, valid, external
 4 5
   10.0.14.4 from 10.0.14.4 (4.4.4.4)
     Origin IGP, metric 100, localpref 100, valid, external
 23 5
   10.0.13.3 from 10.0.13.3 (3.3.3.3)
     Origin IGP, metric 300, localpref 100, valid, external, best

after removing the always compare med and clearing all sessions, R1 just preferred the oldest route.

now let’s enable bgp deterministic-med

R1(config)#router bgp 1
R1(config-router)#bgp deterministic-med
R1(config-router)#end

R1#show ip bgp 5.5.5.5
BGP routing table entry for 5.5.5.5/32, version 9
Paths: (3 available, best #2, table Default-IP-Routing-Table)
Flag: 0x4840
 Advertised to update-groups:
       1
 4 5
   10.0.14.4 from 10.0.14.4 (4.4.4.4)
     Origin IGP, metric 100, localpref 100, valid, external
 23 5
   10.0.12.2 from 10.0.12.2 (2.2.2.2)
     Origin IGP, metric 200, localpref 100, valid, external, best
 23 5
   10.0.13.3 from 10.0.13.3 (3.3.3.3)
     Origin IGP, metric 300, localpref 100, valid, external

you can see that right after we issued the command, routes from R2 is now the preferred exit for 5.5.5.5, this eliminates R1 preferring routes based on their age

now finally, let’s enable bgp always-compare-bed  with bgp deterministic-med

R1(config-router)#bgp always-compare-med

R1#clear ip bgp *
*Mar  1 00:56:55.059: %BGP-5-ADJCHANGE: neighbor 10.0.12.2 Down User reset
*Mar  1 00:56:55.067: %BGP-5-ADJCHANGE: neighbor 10.0.13.3 Down User reset
*Mar  1 00:56:55.071: %BGP-5-ADJCHANGE: neighbor 10.0.14.4 Down User reset
*Mar  1 00:56:55.447: %BGP-5-ADJCHANGE: neighbor 10.0.13.3 Up
*Mar  1 00:56:55.895: %BGP-5-ADJCHANGE: neighbor 10.0.12.2 Up
*Mar  1 00:56:56.099: %BGP-5-ADJCHANGE: neighbor 10.0.14.4 Up

R1#show ip bgp 5.5.5.5
BGP routing table entry for 5.5.5.5/32, version 2
Paths: (3 available, best #1, table Default-IP-Routing-Table)
Flag: 0x820
 Advertised to update-groups:
       1
 4 5
   10.0.14.4 from 10.0.14.4 (4.4.4.4)
     Origin IGP, metric 100, localpref 100, valid, external, best
 23 5
   10.0.12.2 from 10.0.12.2 (2.2.2.2)
     Origin IGP, metric 200, localpref 100, valid, external
 23 5
   10.0.13.3 from 10.0.13.3 (3.3.3.3)
     Origin IGP, metric 300, localpref 100, valid, external

since we have deterministic MED enabled along with always compare MED , routes from group one ( which contains R4 only) is compared, and the best, which is R4 is compared to the best of group 2 which contains R2 and R3. Obviously the winner will be R4 due to the lower MED

a few things to note before closing this post, Cisco recommends enabling deterministic MED in BGP deployments to eliminate any “randomness” when it comes to routers choosing the best path.

always compare MED needs and agreement between your domain and the other different service providers, if you’re hooked up to two service providers and ISP-A for example decided to send you a lower MED, all traffic will be directed to ISP-A even though ISP-B might be the better one for you.

hopefully this cleared a little bit the difference between those two commands