Prerequisites: CCNP level skills.
Topology
Note!
All routers are configured as per topology diagram (pic. 1) and loopback advertised into BGP.
Pic. 1 - Topology Diagram.
Icons designed by: Andrzej Szoblik - http://www.newo.pl
Task 1
On R2 and R4 advertise 10.1.24.0/24 into BGP. R2 should advertise this prefix towards R3 with metric 500.
Task 2
Ensure R3 prefers R1 towards 10.1.24.0/24. Do not modify any attributes to accomplish this.
Lab Solution
Task 1
On R2 and R4 advertise 10.1.24.0/24 into BGP. R2 should advertise this prefix towards R3 with metric 500.
R2 Configuration:
!
ip prefix-list LINK_R2_R4 seq 5 permit 10.1.24.0/24
!
!
route-map SET_MED permit 10
match ip address prefix-list LINK_R2_R4
set metric 500
!
route-map SET_MED permit 999
!
match ip address prefix-list LINK_R2_R4
set metric 500
!
route-map SET_MED permit 999
!
router bgp 20
no synchronization
bgp router-id 172.16.102.2
bgp log-neighbor-changes
network 10.1.24.0 mask 255.255.255.0
network 172.16.102.0 mask 255.255.255.0
neighbor 10.1.23.3 remote-as 13
neighbor 10.1.23.3 route-map SET_MED out
neighbor 10.1.24.4 remote-as 40
no auto-summary
no synchronization
bgp router-id 172.16.102.2
bgp log-neighbor-changes
network 10.1.24.0 mask 255.255.255.0
network 172.16.102.0 mask 255.255.255.0
neighbor 10.1.23.3 remote-as 13
neighbor 10.1.23.3 route-map SET_MED out
neighbor 10.1.24.4 remote-as 40
no auto-summary
!
R4 Configuration:
!
router bgp 40
no synchronization
bgp router-id 172.16.104.4
bgp log-neighbor-changes
network 10.1.24.0 mask 255.255.255.0
network 172.16.104.0 mask 255.255.255.0
network 172.16.144.0 mask 255.255.255.0
neighbor 10.1.14.1 remote-as 13
neighbor 10.1.24.2 remote-as 20
no synchronization
bgp router-id 172.16.104.4
bgp log-neighbor-changes
network 10.1.24.0 mask 255.255.255.0
network 172.16.104.0 mask 255.255.255.0
network 172.16.144.0 mask 255.255.255.0
neighbor 10.1.14.1 remote-as 13
neighbor 10.1.24.2 remote-as 20
!
Pic. 2 - Prefix Details on R3.
Notice!Metric (MED) is disregarded in comparison since the two paths come from different autonomous systems. R3 prefers External to Internal path.
Task 2
Ensure R3 prefers R1 towards 10.1.24.0/24. Do not modify any attributes to accomplish this.
R3 Configuration:
!
router bgp 13
no synchronization
bgp router-id 172.16.103.3
bgp always-compare-med
bgp log-neighbor-changes
network 172.16.103.0 mask 255.255.255.0
neighbor 10.1.13.1 remote-as 13
neighbor 10.1.13.1 next-hop-self
neighbor 10.1.23.2 remote-as 20
neighbor 10.1.35.5 remote-as 50
no auto-summary
no synchronization
bgp router-id 172.16.103.3
bgp always-compare-med
bgp log-neighbor-changes
network 172.16.103.0 mask 255.255.255.0
neighbor 10.1.13.1 remote-as 13
neighbor 10.1.13.1 next-hop-self
neighbor 10.1.23.2 remote-as 20
neighbor 10.1.35.5 remote-as 50
no auto-summary
!
Notice!
For the change to take effect I had to 'clear ip bgp *'
Pic. 3 - Prefix Details on R3.
Note!
MED is now compared and R3 chooses R1 (internal) path over external.
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. The bgp always-compare-med command is useful when multiple service providers or enterprises agree on a uniform policy for setting MED. Thus, for network X, if Internet Service Provider A (ISP A) sets the MED to 10, and ISP B sets the MED to 20, both ISPs agree that ISP A has the better performing path to X.
For example, consider the following routes for network 10.0.0.0/8:
The order in which the BGP routes were received is entry3, entry2, and entry1. (Entry3 is the oldest entry in the BGP table, and entry1 is the newest one.)entry1: AS(PATH) 500, med 150, external, rid 172.16.13.1 entry2: AS(PATH) 100, med 200, external, rid 1.1.1.1 entry3: AS(PATH) 500, med 100, internal, rid 172.16.8.4
Note: When BGP receives multiple routes to a particular destination, it lists them in the reverse order that they were received, from the newest to the oldest. BGP then compares the routes in pairs, starting with the newest entry and moving toward the oldest entry (starting at top of the list and moving down). For example, entry1 and entry2 are compared. The better of these two is then compared to entry3, and so on.
Example 1: Both Commands Disabled
Entry1 and entry2 are compared first. Entry2 is chosen as the better of these two because it has a lower router ID. The MED is not checked because the paths are from a different neighbor autonomous system. Next, entry2 is compared to entry3. Entry2 is chosen as the best path because it is external.Example 2: bgp deterministic-med Disabled, bgp always-compare-med Enabled
Entry1 is compared to entry2. These entries are from different neighbor autonomous systems, but since the bgp always-compare-med command is enabled, MED is used in the comparison. Of these two entries, entry1 is better because it has a lower MED. Next, entry1 is compared to entry3. The MED is checked again because the entries are now from the same autonomous system. Entry3 is chosen as the best path.Example 3: bgp deterministic-med Enabled, bgp always-compare-med Disabled
When the bgp deterministic-med command is enabled, routes from the same autonomous system are grouped together, and the best entries of each group are compared. The BGP table looks like this:There is a group for AS 100 and a group for AS 500. The best entries for each group are compared. Entry1 is the best of its group because it is the only route from AS 100. Entry2 is the best for AS 500 because it has the lowest MED. Next, entry1 is compared to entry2. Since the two entries are not from the same neighbor autonomous system, the MED is not considered in the comparison. The external BGP route wins over the internal BGP route, making entry1 the best route.entry1: AS(PATH) 100, med 200, external, rid 1.1.1.1 entry2: AS(PATH) 500, med 100, internal, rid 172.16.8.4 entry3: AS(PATH) 500, med 150, external, rid 172.16.13.1
Example 4: Both Commands Enabled
The comparisons in this example are the same as in Example 3, except for the last comparison between entry2 and entry1. The MED is taken into account for the last comparison because the bgp always-compare-med command is enabled. Entry2 is selected as the best path.Notice!
The bgp deterministic-med and bgp always-compare-med commands are not enabled by default. Also, the two commands are separate; enabling one does not automatically enable the other.