BGP Best Path Selection Flashcards
BGP Best-Path
The BGP best-path selection algorithm influences how traffic enters or leaves an autonomous system (AS). Some router configurations modify the BGP attributes to influence inbound traffic, outbound traffic, or inbound and outbound traffic, depending on the network design requirements.
BGP installs the first received path as the best path automatically. When additional paths are received for the same network prefix length, the newer paths are compared against the current best path. If there is a tie, processing continues until a best path winner is identified.
BGP Best-Path Algorithm
- Prefer the highest weight
- Prefer the highest local preference
- Prefer the route originated by the local router
- Prefer the shortest AS_Path
- Prefer the best origin code
- Prefer the lowest multi-exit discriminator (MED)
- Prefer an external path over an internal path
- Prefer the path through the closest IGP neighbor
- Prefer the oldest route for eBGP paths
- Prefer the path with the lowest neighbor BGP RID
- Prefer the path with the lowest neighbor IP address
Rule 1
All BGP prefixes must pass the route validity check, and the next-hop IP address must be resolvable for the route to be eligible as a best path.
Weight
BGP weight is a Cisco-defined attribute.
Weight is a 16-bit value (0 through 65,535) assigned locally on the router.
The path with the higher weight is preferred.
Weight can be set for specific routes with an inbound route map or for all routes learned from a specific neighbor.
Weight is not advertised to peers and only influences outbound traffic from a router or an AS.
Weight Example
R4 is an edge router for AS 400 and sets the weight to 222 for the 172.16.0.0/24 prefix received from R2. This ensures that R4 uses R2 for outbound traffic to this prefix.
R6 is an edge router for AS 400 and sets the weight to 333 for the 172.24.0.0/24 prefix received from R3. This ensures that R6 uses R3 for outbound traffic to this prefix.
Local Preference
Local preference (LOCAL_PREF) is a well-known discretionary path attribute and is included with path advertisements throughout an AS.
Default local preference value is 100.
The local preference attribute is a 32-bit value (0 through 4,294,967,295) that indicates the preference for exiting the AS to the destination network prefix.
The local preference is not advertised between eBGP peers and is typically used to influence the outbound traffic (that is, leaving an autonomous system).
Local preference can be set for specific routes by using a route map or for all routes received from a specific neighbor.
Local Pref Example
- *R4** is an edge router for AS 400 and sets the local preference to 222 for the 172.16.0.0/24 prefix received from R2, making it the preferred path for AS 400.
- *R6** is an edge router for AS 400 and sets the local preference to 333 for the 172.24.0.0/24 prefix received from R3, making it the preferred path for AS 400.
Phase 1: Initial BGP Edge Route Processing
- *R4** receives the prefix for 172.16.0.0/24 from R2 and sets the local preference to 222.
- *R6** receives the prefix for 172.24.0.0/24 from R3 and sets the local preference to 333.
Phase 2: BGP Edge Evaluation of Multiple Paths
- *R4** detects that the 172.24.0.0/24 path from R3 (AS 300) has a higher local preference than the path from R2 (AS 200). R4 marks the path from R6 as the best path for the prefix and sends route withdrawals to R5 and R6 for the path from R2.
- *R6** detects that the 172.16.0.0/24 path from R2 (AS 200) has a higher local preference than the path from R3 (AS 300). R6 marks the path from R4 as the best path for the prefix and sends a route withdrawals to R5 and R4 for the path from R3.
Locally Originated
Locally Originated in the Network or Aggregate Advertisement
The third decision point in the best-path algorithm is to determine whether the route originated locally.
Preference is given in the following order:
- Routes that were advertised locally
- Networks that have been aggregated locally
- Routes received by BGP peers
Shortest AS_PATH
A shorter AS_Path is preferred over a longer AS_Path.
Prepending ASNs to AS_Path makes the AS_Path longer, thereby making that path less desirable compared with other paths.
In general, paths that have had AS_Path prepended are not selected as the BGP best path because AS_Path is longer than the non-prepended path advertisement.
Inbound traffic is influenced by prepending AS_Path length in advertisements sent to other ASs, and outbound traffic is influenced by prepending advertisements received from other ASs.
Shortest AS_PATH Example
R4 prepends AS 222 210 for the 172.24.0.0/24 path received from R2, making it the least preferred path for AS 400.
R6 prepends AS 333 321 for the 172.16.0.0/24 path received from R3, making it the least preferred path for AS 400.
Remember that BGP routers do not remove inferior routes. The routes must be withdrawn from a neighbor in order to be removed.
Origin Type
The next BGP best-path decision factor is the well-known mandatory BGP attribute named origin.
By default, networks that are advertised on Cisco routers using the network statement are set with the i (for IGP) origin, and redistributed networks are assigned the ? (incomplete) origin attribute.
IGP over EGP over Incomplete
Origin Type Example
R4 sets the origin to incomplete for the 172.24.0.0/24 path received from R2, making it the least preferred path for R4, R5, and R6.
R6 sets the origin to incomplete for the 172.16.0.0/24 path received from R3, making it the least preferred path for R4, R5, and R6.
MED
BGP sets the MED automatically to the IGP path metric during network advertisement or redistribution.
If the MED is received from an eBGP session, it can be advertised to other iBGP peers, but it should not be sent outside the AS that received it.
The MED’s purpose is to influence traffic flows inbound from a different AS.
A lower MED is preferred over a higher MED.
In order for the MED to be an effective decision factor, the paths being decided upon must come from the same ASN.
MED Example
AS 100 advertises the 172.16.0.0/24 and 172.20.0.0/24 network prefixes with different MED values at each edge router (R1 and R2).
AS 200 sends traffic out R3 to the 172.16.0.0/24 network prefix because R1’s MED (40) is lower than R2’s MED (60).
AS 200 sends traffic out R4 to the 172.20.0.0/24 network prefix because R2’s MED (30) is lower than R1’s MED (70).
MED Example 2
R4 sets the MED to 40 for 172.16.0.0/24, 50 for 172.20.0.0/24, and 90 for 172.24.0.0/24.
R6 sets the MED to 80 for 172.16.0.0/24 and 10 for 172.24.0.0/24.