service information

BGP best path selection

BGP best path selection

In BGP, a router receives prefix announcements via eBGP. If you are multi-homed or peer, you will receive announcements for one and the same prefix from multiple sources. Out of these multiple announcements, a router has to select one announcement as best. 

The decision which prefix announcement is best has to meet the following criteria:

  • Only one single path for each prefix is needed (and wanted)
  • The decision has to be based on attributes of the BGP announcement
  • The decision has to be deterministic (with the same parameters, the decision is always the same)

Below, you can find an example of the BGP routing algorithm according to RFC4271 that explains how your router chooses which prefix to take.

Your router*:

  1. Checks if next hop is reachable
  2. Chooses route with the highest Local Preference (this is where you prefer peering over upstream)
  3. Prefers the route with the shortest AS path
  4. Prefers the route with the lowest origin attribute
  5. Prefers the route with the lowest MED value
  6. Prefers routes received from eBGP over iBGP
  7. Prefers the nearest exit from your network (in terms of your internal routing protocol)
  8. Implementation dependent: Prefers older (= more stable) routes
  9. Prefers routes learned from the router with lower router ID
  10. Prefers routes learned from the router with lower IP address

*most important rules are bold; implementations are vendor-specific

The router starts selecting a best path by checking if the BGP announcement is valid. Only paths where the next hop is reachable are taken into consideration; if the next hop is not reachable, the announcement is discarded.