BGP path selection algorithm

BGP will only advertise its best path by default. But how does BGP select the best path ?

There are some common attributes, such as Cisco own Weight, Local preference and AS path length. But others tie breakers, you will only see when the 1st attributes are equal.

As an administrator or operator, you have the option to change and impact routing ingress and egress, by manipulate these attributes. route maps will be on of the tools used to set attributes values and modify them.

  • BGP Path selection

Weight and Local preference

Both R1 & R2 receive 192.168.10.0 & 192.168.20.0 from AS200, R10 & R20. These 2 prefixes are then announced to R3. R3 will have both prefixes in its BGP table

Copy to Clipboard

From the “show bgp ipv4 unicast” command, we see that for both prefixes, R3 prefers R1 as next hop. All attributes are similar when compared by BGP, weight is zero, LocPrf 100, even IGP metric is the same. Here, BGP relies on lowest router ID, 1.1.1.1 is the tie breaker.

Attributes manipulation

Let’s suppose Link R1-R3 is a low speed one, so we should ensure R3 used its link to R2 and prefers prefixes from R2. We could makes changes to IGP metrics, but this will likely affect other routing and traffic which is not BGP. Instead we could change weight in R3 to be higher towards R2.

In IOS we have to clear BGP sessions before changes takes effect, this can be a hard reset which tears down the session, therefore not recommended in a production network. Soft clear is safer and does not tear down the peering.

After the soft rest, both prefixes from R2 are weighted with 100, and are now preferred. Greater than sign shows which is the preferred prefix next hop.

Copy to Clipboard

Local preference

Weight is local to the router, but LocPrf is not within an AS. In our same example, weight on R3 is removed and instead we set LocPrf to 110 for 192.168.10.0/24 and 120 for 192.168.20.0/24.  A route map will achieve this on R2.

More on route maps on BGP Route maps & Communitiesh

Copy to Clipboard

Because LocPrf  is now known within AS100, all 3 routers have agreed that R2 is best next hop for 192.168.10.0 & 192.168.20.0.
Router R3 no longer has 2 next hops in its BGP table, as R3 will only select and keep best route. As per the output, LocPrf values are also used by R3.

Copy to Clipboard

BGP AS Path Prepending

To influence Ingress traffic, we can use AS prepend, which essentially means we add our AS number a set number of times to the AS path of prefixes we advertise. This makes a given as path longer when compared to another prefix received via another path and un-prepended.

Methods and configurations seen here are only the tip of the iceberg. There is much more to BGP path manipulation, and different ways to achieve them