The bgp deterministic-med command ensures the comparison of the MED attribute when choosing the paths advertised by different peers in the same AS.
The bgp always-compare-med command ensures the comparison of the MED attribute when choosing the paths advertised by different peers in different ASes.
The bgp always-compare-med command is useful when multiple ISPs or enterprises agree upon a uniform policy for setting the MED, eg: ISP1 sets the MED for Network X to 100; ISP2 sets the MED for Network X to 200. Both ISPs agree that ISP1 has the better path to Net X.
Consider the following BGP routes for network 192.168.1.0/24:
Entry #1 – AS_PATH 300 100, MED 150, external, NEXT_HOP 3.3.3.3, RID 3.3.3.3
Entry #2 – AS_PATH 200 100, MED 200, external, NEXT_HOP 1.1.1.1, RID 1.1.1.1
Entry #3 – AS_PATH 300 100, MED 100, internal, NEXT_HOP 2.2.2.2, RID 2.2.2.2
The order in which the BGP routes were received is Entry #3, Entry #2, and Entry #1.
Entry #3 and Entry #1 are the oldest and newest entries in the BGP routing table respectively.
When the BGP process receives multiple routes to a particular destination, it lists them in the reverse order that they were received – from the newest to the oldest. The BGP process then compares the routes in pairs, starting with the newest entry and moving towards the oldest entry (starting at the top of the list and moving down) – Entry #1 and Entry #2 are compared first, the better of them is then compared to Entry #3, and so on...
Scenario #1: Both commands are disabled
Entry #1 and Entry #2 are compared first. Entry #2 is selected as it has a lower BGP Router ID. The MED is not checked as the paths are originated from neighbors in different neighboring ASes.
Entry #2 and Entry #3 are compared next. Entry #2 is selected as the best path as it is an EBGP route.
RT4#sh ip bgp
BGP table version is 3, local router ID is 4.4.4.4
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* 192.168.1.0 3.3.3.3 150 0 300 100 i
*> 1.1.1.1 200 0 200 100 i
* i 2.2.2.2 100 100 0 300 100 i
RT4#
Scenario #2: bgp deterministic-med is disabled; bgp always-compare-med is enabled
Entry #1 and Entry #2 are compared first. These entries are from different neighboring ASes, but the MED is used in the comparison as the bgp always-compare-med command is enabled. Entry #1 is selected as it has a lower MED. Entry #1 and Entry #3 are compared next.
The MED is used in the comparison again. Entry #3 is selected as the best path as it has a lower MED.
RT4#sh ip bgp BGP table version is 3, local router ID is 4.4.4.4 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path * 192.168.1.0 3.3.3.3 150 0 300 100 i * 1.1.1.1 200 0 200 100 i *>i 2.2.2.2 100 100 0 300 100 i RT4#
Scenario #3: bgp deterministic-med is enabled; bgp always-compare-med is disabled
When the bgp deterministic-med command is enabled, the routes received from the same AS are grouped together, and the best entries of each group are then compared to select the best path.
The BGP routing table on RT4 looks like this:
Entry #1 – AS_PATH 200 100, MED 200, external, RID 1.1.1.1
Entry #2 – AS_PATH 300 100, MED 100, internal, RID 2.2.2.2
Entry #3 – AS_PATH 300 100, MED 150, external, RID 3.3.3.3
Entry #1 is the best of its group as it is the only route originated from AS 200.
Entry #2 is the best for AS 300 as it has the lowest MED.
Entry #1 and Entry #2 are compared eventually. Since the entries are from different ASes and the bgp always-compare-med command is not enabled, the MED is not considered in the comparison. Entry #1 is selected as the best path as it is an EBGP route.
RT4#sh ip bgp BGP table version is 5, local router ID is 4.4.4.4 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path *> 192.168.1.0 1.1.1.1 200 0 200 100 i * i 2.2.2.2 100 100 0 300 100 i * 3.3.3.3 150 0 300 100 i RT4#
Scenario #4: Both commands are enabled
The comparisons for this scenario is same as the previous scenario; expect for the last comparison between Entry #1 and Entry #2, in which the MED is considered in the comparison as the bgp always-compare-med command is enabled.
Entry #2 is selected as the best path as it has a lower MED.
RT4#sh ip bgp BGP table version is 6, local router ID is 4.4.4.4 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path * 192.168.1.0 1.1.1.1 200 0 200 100 i *>i 2.2.2.2 100 100 0 300 100 i * 3.3.3.3 150 0 300 100 i RT4#
It is recommended to implement the bgp deterministic-med command in all new network rollouts. For existing networks, the command must either be deployed on all routers at the same time; or incrementally, with care to avoid possible IBGP routing loops.
If bgp always-compare-med is enabled, MEDs are compared for all paths. This option must be enabled on BGP routers across an entire AS; otherwise routing loops can occur.
No comments:
Post a Comment