BGP Best Path Selection

BGP routers typically have a number of peers and consequentially can learn a number of different paths to a destination. In order to decide the best path BGP uses the BGP Best Path Selection Algorithm. Essentially this is a step-by-step selection process. The first valid path in the selection process is considered the best path and installed in the routing table.

Cisco also has an excellent page on best path selection here

Note: The BGP best path selection algorithm will only process valid BGP paths. Paths will not be considered valid, and therefore not part of the selection process, for the following reasons:

Paths marked as not synchronised (when synchronisation is enabled)Remember BGP synchronisation? After IOS version 12.2(8)T synchronisation was disabled by default, however, before this version synchronisation was enabled to address networks that didn’t have iBGP running on all routers in an autonomous system. In order for eBGP to advertise an iBGP learnt prefix to a peer, the prefix would need to exist in an IGP (e.g. OSPF)
The next hop is not reachableIf the next hop for a prefix is not reachable, it is considered invalid.
eBGP learnt prefixes with the local AS number in the pathFor example, route-maps using access-lists, prefix-lists, AS_PATH, or communities to filter prefixes. If soft-reconfiguration inbound is configured then these prefixes will show in the BGP table as (received-only) implying they are filtered by a prefix.
Prefixes denied through routing policies.For example, route-maps using access-lists, prefix-lists, AS_PATH, or communities to filter prefixes. If soft-reconfiguration inbound is configured then these prefixes will show in the BGP table as received-only implying they are filtered by a prefix.
bgp enforce-first-asbgp enforce-first-as is enabled by default. When a BGP neighbour sends you a prefix, the peer will have their AS number listed as the first AS in the AS PATH.

For example, if we look at the prefixes received from neighbour AS 65000, all prefixes will show 65000 as the first hop.

If this is not the case then the prefix is denied.

Now on to the selection process itself. Many engineers remember the process using the acronym “We Love Oranges As Oranges Mean Pure Refreshment“.

WWeight. Prefer the prefix with the highest weight. Note weight is Cisco proprietary and is local to the router it is configured on
LLocal Preference (LOCAL_PREF). Prefer the prefix with the highest local preference.

Local preference is exchanged between iBGP peers only and not advertised to any other AS. By default, local preference is set at 100 and determines the best path to exit an AS. Typically the value of local preference is set on prefixes received from an eBGP peer.
OOriginate. Prefer locally originated prefixes.

These are locally originated prefixes within the local AS, and are preferred in the following order:

> Prefixes installed via either the BGP network command, or locally redistributed into BGP
> Prefixes installed via the BGP aggregate sub-command.
AIGPThere may be some instances where the Accumulated IGP Metric Attribute will be configured. For example, an ISP may acquire another ISP, and become responsible for two BGP autonomous systems. Neither AS has visibility of the peer’s IGP which can lead to suboptimal routing.

AIGP will take into account the metrics in the IGPs in order to select the best end-to-end path.

Typically this attribute is not configured, however, and therefore not part of the BGP selection process.
AAS Path (AS_PATH). Prefer the path with the shortest AS path (as-set counts as 1)

Note: This path can be skipped if you have the bgp bestpath as-path ignore command configured. For example, suppose you received the same prefix from two directly connected ISPs with the following AS Paths

Primary ISP 200, 500, 600, 400
Secondary ISP 200, 300, 400

Ordinarily, the prefix from the secondary ISP would be selected, as it’s shorter, however, if you were to ignore as-path comparison, the selection process would pass to the next step.
OOrigin. Prefer the path with the lowest origin type

IGP < EGP < incomplete
IGP (shows as i) relates to prefixes originating internally using the network command.
EGP (shows as e) relates to legacy EGP protocol and is now defunct
incomplete (?) refers to prefixes that have been redistributed
MMED (Multi-Exit Discriminator). Prefer the lowest.

Otherwise known as the external metric. MED is only compared if the first hop for a destination prefix is the same AS.

However, this can be changed to any AS with the bgp always-compare-med command.

Furthermore, the bgp deterministic-med command will first compare multiple paths to the same prefix (within the same neighbour AS), and then compare this with any other paths via other connected autonomous systems.

In terms of operation, MED suggests to an eBGP peer how to enter the AS, and is applied to outbound prefix updates.

In other words, you may receive a prefix from a neighbour with a MED set indicating the preferred inbound path. The default value for MED is 0.
PPaths.
Prefer eBGP over iBGP

Note: if BGP multipath is configured this will allow multiple paths to be installed in the routing table for load-balancing.

The following attributes to this point in the algorithm but be the same i.e.

> Weight
> Local-preference
> AS-path
> Origin
> MED

Multipath does not affect the best path selection. One path still is designated as the best and advertised to neighbours.

When multiple external paths are received the prefix received first is considered best. This avoids flapping should a new prefix replace a new one.
RRouter ID. Prefer the lowest router ID.
Neighbour AddressIf everything is equal to this point, prefer the prefix that comes from the lowest neighbor address

Unknown's avatar

Author: Simon Chamberlain

An experienced Network Professional writing yet another blog

Leave a comment