BGP Route Selection Rules and Load Balancing
There may be multiple routes to the same destination in a BGP routing table. BGP will select one route as the optimal route and advertise it to peers. To select the optimal route among these routes, BGP compares the BGP attributes of the routes in sequence based on route selection rules.
BGP Attributes
Route attributes describe routes. BGP route attributes are classified into the following types. Table 9-1 lists common BGP attributes.
Well-known mandatory attribute
All BGP devices can identify this type of attributes, which must be carried in Update messages. Without this type of attributes, errors occur in routing information.
Well-known discretionary attribute
All BGP devices can identify this type of attributes, which are optional in Update messages. Without this type of attributes, errors do not occur in routing information.
Optional transitive attribute
BGP devices may not identify this type of attributes but still accept them and advertise them to peers.
Optional non-transitive attribute
BGP devices may not identify this type of attributes. If a BGP device does not identify this type of attributes, it ignores them and does not advertise them to peers.
Attribute |
Type |
---|---|
Origin |
Well-known mandatory |
AS_Path |
Well-known mandatory |
Next_Hop |
Well-known mandatory |
Local_Pref |
Well-known discretionary |
Community |
Optional transitive |
MED |
Optional non-transitive |
Originator_ID |
Optional non-transitive |
Cluster_List |
Optional non-transitive |
The following describes common BGP route attributes:
Origin
The Origin attribute defines the origin of a route and marks the path of a BGP route. The Origin attribute is classified into three types:
IGP
A route with IGP as the Origin attribute is of the highest priority. The Origin attribute of the routes imported into a BGP routing table using the network command is IGP.
EGP
A route with EGP as the Origin attribute is of the second highest priority. The Origin attribute of the routes obtained through EGP is EGP.
Incomplete
A route with Incomplete as the Origin attribute is of the lowest priority. The Origin attribute of the routes learned by other means is Incomplete. For example, the Origin attribute of the routes imported by BGP using the import-route command is Incomplete.
AS_Path
The AS_Path attribute records all the ASs that a route passes through from the source to the destination in the vector order. To prevent inter-AS routing loops, a BGP device does not receive the routes of which the AS_Path list contains the local AS number.
When a BGP speaker advertises an imported route:
If the route is advertised to EBGP peers, the BGP speaker creates an AS_Path list containing the local AS number in an Update message.
If the route is advertised to IBGP peers, the BGP speaker creates an empty AS_Path list in an Update message.
When a BGP speaker advertises a route learned in the Update message sent by another BGP speaker:
If the route is advertised to EBGP peers, the BGP speaker adds the local AS number to the leftmost of the AS_Path list. According to the AS_Path list, the BGP speaker that receives the route can learn about the ASs through which the route passes to reach the destination. The number of the AS that is nearest to the local AS is placed on the top of the AS_Path list. The other AS numbers are listed according to the sequence in which the route passes through ASs.
If the route is advertised to IBGP peers, the BGP speaker does not change the AS_Path attribute of the route.
Next_Hop
The Next_Hop attribute records the next hop that a route passes through. The Next_Hop attribute of BGP is different from that of an IGP because it may not be the neighbor IP address. A BGP speaker processes the Next_Hop attribute based on the following rules:
When advertising a route to an EBGP peer, the BGP speaker sets the Next_Hop attribute of the route to the address of the local interface through which the BGP peer relationship is established with the peer.
When advertising a locally originated route to an IBGP peer, the BGP speaker sets the Next_Hop attribute of the route to the address of the local interface through which the BGP peer relationship is established with the peer.
When advertising a route learned from an EBGP peer to an IBGP peer, the BGP speaker does not change the Next_Hop attribute of the route.
Local_Pref
The Local_Pref attribute indicates the BGP preference of a device and helps determine the optimal route when traffic leaves an AS. When a BGP device obtains multiple routes to the same destination address but with different next hops from different IBGP peers, the BGP device prefers the route with the highest Local_Pref value. The Local_Pref attribute is exchanged only between IBGP peers and is not advertised to other ASs. The Local_Pref attribute can be manually configured. If no Local_Pref attribute is configured for a route, the Local_Pref attribute of the route uses the default value 100.
MED
The multi-exit discriminator (MED) attribute helps determine the optimal route when traffic enters an AS. When a BGP device obtains multiple routes to the same destination address but with different next hops from EBGP peers, the BGP device selects the route with the smallest MED value as the optimal route.
The MED attribute is exchanged only between two neighboring ASs. The AS that receives the MED attribute does not advertise it to any other ASs. The MED attribute can be manually configured. If no MED attribute is configured for a route, the MED attribute of the route uses the default value 0.
Community
The Community attribute identifies the BGP routes with the same characteristics, simplifies the applications of routing policies, and facilitates route maintenance and management.
The Community attribute includes self-defined community attributes and well-known community attributes. Table 9-2 lists well-known community attributes.
Table 9-2 Well-known community attributesCommunity Attribute
Value
Description
Internet
0 (0x00000000)
A BGP device can advertise the received route with the Internet attribute to all peers.
No_Advertise
4294967042 (0xFFFFFF02)
A BGP device does not advertise the received route with the No_Advertise attribute to any peer.
No_Export
4294967041 (0xFFFFFF01)
A BGP device does not advertise the received route with the No_Export attribute to devices outside the local AS.
No_Export_Subconfed
4294967043 (0xFFFFFF03)
A BGP device does not advertise the received route with the No_Export_Subconfed attribute to devices outside the local AS or to devices outside the local sub-AS.
Originator_ID and Cluster_List
The Originator_ID attribute and Cluster_List attribute help eliminate loops in route reflector scenarios. For details, see Route Reflector.
BGP Route Selection Policies
When there are multiple routes to the same destination, BGP compares the following attributes in sequence to select the optimal route:
Prefers the route with the largest PrefVal value.
The PrefVal attribute is a Huawei proprietary attribute and is valid only on the device where it is configured.
Prefers the route with the highest Local_Pref value.
If a route does not have the Local_Pref attribute, the Local_Pref attribute of the route uses the default value 100.
Prefers the manually summarized route, automatically summarized route, route imported using the network command, route imported using the import-route command, and route learned from peers. These routes are in descending order of priority.
Prefers the route with the shortest AS_Path.
Prefers the route whose Origin attribute is of the highest priority. The three types of Origin attributes are listed as follows in descending order of priority: IGP, EGP, and Incomplete.
Prefers the route with the lowest MED value if routes are received from the same AS.
Prefers local VPN routes, LocalCross routes, and RemoteCross routes in descending order.
LocalCross routes indicate the routes that are leaked between local VPN instances or routes imported between public network and VPN instances.
If the ERT of a VPNv4 route in the routing table of a VPN instance on a PE matches the IRT of another VPN instance on the PE, the VPNv4 route is added to the routing table of the second VPN instance. This route is called a LocalCross route. If the ERT of a VPNv4 route learned from a remote PE matches the IRT of a VPN instance on the local PE, the VPNv4 route is added to the routing table of that VPN instance. This route is called a RemoteCross route.
Prefers EBGP routes to IBGP routes.
- Prefers the route with the lowest IGP metric to the BGP next hop.
If there are multiple routes to the same destination, an IGP calculates the route metric using its routing algorithm.
Prefers the route with the shortest Cluster_List.
Prefers the route advertised by the device with the smallest router ID.
If a route carries the Originator_ID attribute, BGP prefers the route with the smallest Originator_ID without comparing the router ID.
Prefers the route learned from the peer with the lowest IP address.
BGP Load Balancing
When there are multiple equal-cost routes to the same destination, you can perform load balancing among these routes to load balance traffic. Equal-cost BGP routes can be generated for traffic load balancing only when the first eight route attributes described in "BGP Route Selection Policies" are the same among the routes.