BGP Best Path
BGP automatically install the first received path as the best path. 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. The following list provides the attributed that the BGP best-path algorithm uses for the process of selecting the best route. These attributes are processed in the order listed:
- Highest weight.
- Highest local preference.
- Prefer the route originated by the local router.
- Prefer the path with the shorter Accumulated Interior Gateway Protocol (AIGP) metric attribute.
- Shortest AS_Path.
- Best Origin code.
- Lowest MED.
- External path over Internal path.
- Prefer the path through the closest IGP neighbor.
- Prefer the path from the oldest eBGP session.
- Prefer the path with the lowest neighbor BGP RID.
- Prefer the path with the minimum cluster list length.
- Prefer the path with the lowest neighbor IP address.
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. Some vendors and publications consider this the first step.
The BGP routing policy can vary from organization to organization, based on the manipulation of the BGP PAs. Because some PAs are transitive and carry from one AS to another AS, those changes could impact downstream routing for other SPs, too. Other PAs are nontransitive and influence the routing policy only within the organization.
1. Weight
- Cisco-defined attribute.
- 16-bit value (0 to 65535), assigned locally on the router (not advertised to other routers, only influences outbound traffic from a router or an AS).
- Highest weight preferred.
- Weight can be set for specific routes with an inbound route map or for all routes learned from a specific neighbor.
Because it is the first step, it should be used when other attributes should not influence the best path for a specific network prefix.
2. Local Preference
3. Origin
Preference is given in the following order:
- Routes that were advertised locally.
- Networks that have been aggregated locally.
- Routes received by BGP peers.
4. Accumulated IGP
AIGP is an optional nontransitive PA that is included with advertisements throughout an AS. It provides the ability for BGP to maintain and calculate a conceptual path metric in environments that use multiple ASs with unique IGP routing domains in each AS.
AS100, 200 and 300 are under the control of the same SP. AIGP has been enabled on the BGP sessions between all the routers, and the IGPs are redistributed into BGP. The AIGP metric is advertised between all 3 ASs, allowing BGP to use the AIGP metric for best-path calculations between the ASs.
AIGP PA exchanges must be agreed upon between the BGP peers, and AIGP metrics are only included in prefix advertisements between AIGP-enabled peers. AIGP metrics are enabled for a BGP neighbor with the BGP address family configuration command neighbor ip-address aigp.
The AIGP metric is a 32-bit (0 to 4,294,967,295) value that can be set during redistribution or during receipt of a prefix with a route map. Route maps use the configuration command set aigp-metric {igp-metric | metric}. The igp-metric keyword sets the value to the IGP path metric on the redistributing router for the specific route. Static routes and network advertisements populate the AIGP metric with the path metric to the next-hop address of the route.
The following guidelines apply to AIGP metrics:
- A path with an AIGP metric is preferred to a path without an AIGP metric.
- If the next-hop address requires a recursive lookup, the AIGP path needs to calculate a derived metric to include the distance to the next-hop address. This ensures that the cost to the BGP edge router is included. The formula is:
- Derived AIGP Metric = (Original AIGP Metric + Next-Hop AIGP Metric)
- If multiple AIGP paths exist and one next-hop address contains an AIGP metric and the other does not, the non-AIGP path is not used.
- The next-hop AIGP metric is recursively added if multiple lookups are performed.
- AIGP paths are compared based on the derived AIGP metric (with recursive next hops) or the actual AIGP metric (nonrecursive next hop). The path with the lower AIGP metric is preferred.
- When router R2 advertises an AIGP-enabled path that was learned from R1, if the next-hop address changes to an R2 address, R2 increments the AIGP metric to reflect the distance (the IGP path metric) between R1 and R2.
5. Shortest AS_Path
Typically correlates to the AS hop count. A shorter AS_Path is preferred over a longer AS_Path.
When working with confederations, AS_CONFED_SEQUENCE (confederation AS_Path) is not counted, and for aggregated addresses with multiple ASNs under the AS_SET portion of AS_Path, the AS_SET counts for only one AS_Path entry.
6. Origin Type
7. Multi-Exit Discriminator
8. eBGP over iBGP
The next BGP best-path decision factor is whether the route comes from an iBGP, eBGP, or confederation member AS (Sub-AS) peering. The best-path selection order is as follows:
- eBGP peers (most desirable)
- Confederation member AS peers
- iBGP peers (least desirable)
BGP confederations are not a ENARSI topic.
9. Lowest IGP Metric
10. Prefer the Oldest eBGP Session
BGP can maintain large routing tables, and unstable sessions result in the BGP best-path calculation executing frequently. BGP maintains stability in a network by preferring the path from the oldest (established) BGP session. The downfall of this technique is that it does not lead to a deterministic method of identifying the BGP best path from a design perspective.
11. Router ID
The next step for the BGP best-path algorithm is to select the best path using the lowest RID of the advertising eBGP router. If the route was received by a RR, then the originator ID is substituted for the RID.
12. Minimum Cluster List Length
The cluster list is a non-transitive BGP attribute that is appended (not overwritten) by a route reflector with its cluster ID. Route reflectors use the cluster-id attribute as a loop-prevention mechanism.The cluster ID is not advertised between ASs and is locally significant. In simplest terms, this step locates the path that has traveled the smallest number of iBGP advertisement hops.
- R3 advertises the 172.16.0.0/24 network prefix to RR1 and RR2 with only the originator ID.
- RR1 reflects the advertisement to RR2 after appending its RID to the cluster list.
- RR2 selects the path advertisement directly from R3. R3’s cluster list length is 0, which is more desirable than RR1’s cluster list length of 1.
13. Lowest Neighbor Address
This step is limited to iBGP peerings because eBGP peerings use the oldest received path as the tie breaker.
R2 selects the path advertised from 10.12.1.1 as it is the lower IP address.



