BGP Path Selection
IGPs, such as EIGRP or OSPF, choose routes based on lowest metric. They attempt to find the shortest, fastest way to get traffic to its destination. BGP, however, has a different way of route selection. It assigns various attributes to each path; these attributes can be administratively manipulated to control the path that is selected. It then examines the value of these attributes in an ordered fashion until it can narrow all the possible routes down to one path.
BGP Attributes
BGP chooses a route to a network based on the attributes of its path. Four categories of attributes exist as follows:
- Well-known mandatory: Must be recognized by all BGP routers, present in all BGP updates, and passed on to other BGP routers. For example, AS path, origin, and next hop.
- Well-known discretionary: Must be recognized by all BGP routers and passed on to other BGP routers but need not be present in an update, for example, local preference.
- Optional transitive: Might or might not be recognized by a BGP router but is passed on to other BGP routers. If not recognized, it is marked as partial, for example, aggregator, community.
- Optional nontransitive: Might or might not be recognized by a BGP router and is not passed on to other routers, for example, Multi-Exit Discriminator (MED), originator ID.
Table 6-2 lists common BGP attributes, their meanings, and their category.
Table 6-2. BGP Attributes
Attribute |
Meaning |
AS path |
An ordered list of all the autonomous systems through which this update has passed. Well-known, mandatory. |
Origin |
How BGP learned of this network. i = by network command, e = from EGP, ? = redistributed from other source. Well-known, mandatory. |
Local Preference |
A value telling IBGP peers which path to select for traffic leaving the AS. Default value is 100. Well-known, discretionary. |
Multi-Exit Discriminator (MED) |
Suggests to a neighboring autonomous system which of multiple paths to select for traffic bound into your autonomous system. Lowest MED is preferred. Optional, non-transitive. |
Weight |
Cisco proprietary, to tell a router which of multiple local paths to select for traffic leaving the AS. Highest weight is preferred. Only has local significance. |
BGP Path Selection Criteria
BGP tries to narrow its path selection down to one best path; it does not load balance by default. To do so, it examines the path attributes of any loop-free, synchronized (if synchronization is enabled) routes with a reachable next-hop in the following order:
- Choose the route with the highest weight.
- If weight is not set, choose the route with the highest local preference.
- Choose routes that this router originated.
- Choose the path with the shortest Autonomous System path.
- Choose the path with the lowest origin code (i is lowest, e is next, ? is last).
- Choose the route with the lowest MED, if the same Autonomous System advertises the possible routes.
- Choose an EBGP route over an IBGP route.
- Choose the route through the nearest IGP neighbor as determined by the lowest IGP metric.
- Choose the oldest route
- Choose a path through the neighbor with the lowest router ID.
- Choose a path through the neighbor with the lowest IP address.
To enable BGP to load balance over more than one path, you must enter the command maximum-paths number-of-paths. BGP can load balance over a maximum of six paths.
Influencing BGP Path Selection
BGP was not created to be a fast protocol; it was created to enable as much administrative control over route path selection as possible. Path selection is controlled by manipulating BGP attributes, usually using route maps. You can set a default local preference by using the command bgp default local-preference and a default MED for redistributed routes with the default-metric command under the BGP routing process. But by using route maps, you can change attributes for certain neighbors only or for certain routes only. The earlier section on route maps contains an example of using a route map to set a local preference of 200 for specific redistributed routes. This is higher than the default local preference of 120, so routers within the AS are more likely to prefer that path than others.
Route maps can also be applied to routes sent to or received from a neighbor. The following example shows a simple route map that sets a MED value and adds two more copies of its AS number to the AS path on all routes advertised out to an EBGP neighbor:
route-map MED permit 10 set metric 50 set as-path prepend 65001 65001 ! router bgp 65001 neighbor 10.1.1.1 route-map MED out
When attributes are changed, you must tell BGP to apply the changes. Either clear the BGP session (clear ip bgp *) or do a soft reset (clear ip bgp * soft in | out). Routers using recent IOS versions do a route refresh when the session in cleared inbound.