Professional Documents
Culture Documents
22.BGP+Basics+-+Route+Selection+Rules
22.BGP+Basics+-+Route+Selection+Rules
22.BGP+Basics+-+Route+Selection+Rules
The preceding BGP routing table contains two BGP routes to the network 100.0.1.0/24. Of the two routes, the device sel
ects the optimal route, marks it with a right angle bracket (>), and adds it to the IP routing table.
All routes in the BGP routing table are valid and marked with an asterisk (*) at the beginning. Valid routes are those
whose Next_Hop is reachable (the device has a route to the Next_Hop in the IP routing table). Invalid BGP routes
cannot be selected.
Overview of BGP Route Selection Rules
BGP selects the optimal route as follows:
1. Prefers the route with the largest Preferred_Value. 7. Prefers the route advertised by an EBGP peer.
2. Prefers the route with the largest Local_Preference. 8. Prefers the route with the smallest IGP cost to the Next_Hop.
3. Prefers locally originated routes. 9. Allows multiple routes to participate in load balancing (if
5. Prefers the route with the highest Origin priority 10. Prefers the route with the shortest Cluster_List.
(IGP>EGP>Incomplete). 11. Prefers the route sent by the BGP peer with the smallest
12. Prefers the route sent by the peer with the lowest IP
address.
BGP route selection rules may vary with vendors. These BGP route selection rules are implemented by Huawei devices
running a V8 version.
Topology for Verifying Route Selection Rules
AS 100 AS 200
R1 R2
GE 0/0/0 GE 0/0/0
10.1.13.1/24 10.1.25.2/24
GE 0/0/0 GE 0/0/1
10.1.13.3/24 10.1.25.5/24
GE 0/0/1 GE 0/0/1
10.1.34.3/24 10.1.45.4/24
GE 0/0/0 GE 0/0/0
10.1.34.4/24 10.1.45.5/24
R3 R4 R5
OSPF
AS 345
• IP addresses and ASs are planned according to the topology. Interface loopback 0 is configured on all routers, and its
IP address is in the format of x.x.x.x/32, where x is the device ID.
• In AS 345, OSPF is enabled on involved interfaces (including loopback 0) of R3, R4, and R5.
• EBGP peer relationships are established using directly connected interfaces. IBGP peer relationships are established
using loopback 0 interfaces.
Topology for Verifying Route Selection Rules
AS 100 AS 200
R1 R2
EBGP peer
EBGP peer
IBGP peer IBGP peer
R3 R4 R5
AS 345
Contents
1. Preferring the Route with the Largest 7. Preferring the Route Advertised by an EBGP Peer
Preferred_Value 8. Preferring the Route with the Smallest IGP Cost to the
4. Preferring the Route with the Shortest AS_Path 10. Preferring the Route with the Shortest Cluster_List
5. Preferring the Route with the Highest Origin 11. Preferring the Route Sent by the BGP Peer with the
6. Preferring the Route with the Smallest MED 12. Preferring the Route Sent by the Peer with the Lowest IP
Address
Preferred_Value
• Preferred_Value is a Huawei proprietary path attribute and is similar to a priority. Its value is
an integer ranging from 0 to 65535. The larger the value, the higher the priority.
• This attribute is valid only locally and is not sent to any peers.
• The default Preferred_Values of locally originated routes and the routes received from BGP
peers are both 0.
Modifying the Preferred_Value of All Routes Received from a Specified Peer
100.0.1.0/24 100.0.1.0/24
R1 R2
AS 100 AS 200
100.0.1.0/24 100.0.1.0/24
R3 R5
AS 345 R4 5.5.5.5
1. Preferring the Route with the Largest 7. Preferring the Route Advertised by an EBGP Peer
Preferred_Value 8. Preferring the Route with the Smallest IGP Cost to the
4. Preferring the Route with the Shortest 10. Preferring the Route with the Shortest Cluster_List
AS_Path 11. Preferring the Route Sent by the BGP Peer with the Smallest
Priority (IGP>EGP>Incomplete) 12. Preferring the Route Sent by the Peer with the Lowest IP
100.0.1.0/24 100.0.1.0/24
BGP route
A route-policy is configured on R3 to set the Local_Preference of the route 100.0.1.0/24 to 200 when R3 advertises the
route to R4 so that R4 preferentially selects the route 100.0.1.0/24 advertised by R3.
Contents
1. Preferring the Route with the Largest 7. Preferring the Route Advertised by an EBGP Peer
Preferred_Value 8. Preferring the Route with the Smallest IGP Cost to the
4. Preferring the Route with the Shortest AS_Path 10. Preferring the Route with the Shortest Cluster_List
5. Preferring the Route with the Highest Origin 11. Preferring the Route Sent by the BGP Peer with the
6. Preferring the Route with the Smallest MED 12. Preferring the Route Sent by the Peer with the Lowest IP
Address
Rule Description
• If other conditions are the same, locally originated routes take precedence over routes learned from peers.
• Locally originated routes include routes imported using the network or import-route command, manual summary r
outes, and automatic summary routes. Locally originated routes are selected as follows:
2. Manual summary routes generated using the aggregate command take precedence over the automatic
summary routes generated using the summary automatic command.
3. The routes imported using the network command take precedence over the routes imported using the import-
route command.
Contents
1. Preferring the Route with the Largest 7. Preferring the Route Advertised by an EBGP Peer
Preferred_Value 8. Preferring the Route with the Smallest IGP Cost to the
4. Preferring the Route with the Shortest AS_Path 10. Preferring the Route with the Shortest Cluster_List
5. Preferring the Route with the Highest Origin 11. Preferring the Route Sent by the BGP Peer with the
6. Preferring the Route with the Smallest MED 12. Preferring the Route Sent by the Peer with the Lowest IP
Address
Using a Route-policy to Modify the AS_Path Attribute
100.0.1.0/24 100.0.1.0/24
Key configurations of R3 are as follows:
R3 R5 bgp 345
peer 10.1.13.1 route-policy RP import
AS 345 R4
BGP route
An import policy is created on R3 to configure R3 to add an AS number (100) to the AS_Path attribute of the route 100.0.1.0/24
advertised by R1 after receiving the route. In this way, the length of the AS_Path attribute is increased by 1 after R4 receives
the route. Therefore, R4 prefers the route advertised by R5.
Using a Route-policy to Modify the AS_Path Attribute
• The following commands can be used to modify the AS_Path of BGP routes:
• apply as-path xxx additive Adds xxx to the existing AS_Path.
• apply as-path xxx overwrite Replaces the existing AS_Path value with xxx.
• apply as-path none overwrite Clears the AS_Path.
• A route-policy can be used to modify the AS_Path of EBGP routes. On Huawei routers, you can also u
se a route-policy to modify the AS_Path of IBGP routes. Exercise caution when modifying the AS_Pat
h of BGP routes because the modification may lead to routing loops.
• The bestroute as-path-ignore command configures BGP to ignore AS_Path length comparison when
selecting the optimal route. By default, the route with the shortest AS_Path length is preferred.
Supplement 1 to the AS_Path-based Route Selection Rule
• Rule supplement: No matter how many AS numbers an AS_Set contains, BGP regards the AS_Set as one AS
number when calculating routes.
R1
172.16.1.0/24
• Rule supplement: No matter how many AS numbers an AS_Set contains, BGP regards the AS_Set as one AS
number when calculating routes.
In this example, R7 considers that the AS_Set
{999,100,200} contains only one AS number when
R1 R4
selecting the optimal route. In this case, the AS_Path
172.16.1.0/24
lengths of the two routes to 172.16.0.0/16 are the same.
AS 100 AS 999 Therefore, R7 needs to compare other attributes to
select the optimal route.
R2 R5 S
u 172.16.0.0/16
172.16.2.0/24 m AS_Path: 400 {999,100,200}
m
a R7
AS200 AS 400
r
y
R3 R6
S AS 600
u
172.16.3.0/24 m 172.16.0.0/16
m AS_Path: 500 300
a
AS 300 AS500
r
y
Supplement 2 to the AS_Path-based Route Selection Rule
• Rule supplement: AS_CONFED_SEQUENCE and AS_CONFED_SET are not involved in AS_Path length calculati
on.
AS 200 R2
R5 prefers the route 10.1.1.0/24 learned
from R4 because its AS_Path is shorter
than the AS_Path of the route learned from
R3.
R1 R3
10.1.1.0/24
AS 100 AS 300
10.1.1.0/24
Confederation AS 45 AS_Path=300 200 100
R4 R5
AS_Path length: 3
AS 64514 AS 64515
10.1.1.0/24
AS_Path=(64514) 100
AS_Path length: 1
Contents
1. Preferring the Route with the Largest 7. Preferring the Route Advertised by an EBGP Peer
Preferred_Value 8. Preferring the Route with the Smallest IGP Cost to the
4. Preferring the Route with the Shortest 10. Preferring the Route with the Shortest Cluster_List
AS_Path 11. Preferring the Route Sent by the BGP Peer with the
Priority (IGP>EGP>Incomplete) 12. Preferring the Route Sent by the Peer with the Lowest IP
• Origin is also a well-known mandatory attribute. It indicates how a route becomes a BGP route. According to the way
a route became a BGP route, Origin is classified into three types: IGP, EGP, and Incomplete.
• When multiple routes to the same destination have different Origin attributes and other conditions are the same, BGP
selects routes according to the following sequence of Origin types: IGP > EGP > Incomplete.
Indicates that the origin of the route cannot be identified. For example, if a route
Incomplete ?
was imported using the import-route command, its Origin is Incomplete.
Using a Route-policy to Modify the Origin Attribute
100.0.1.0/24 100.0.1.0/24
Key configurations of R1 are as follows:
ip ip-prefix 1 permit 100.0.1.0 24
R1 R2
route-policy RP permit node 10
AS 100 AS 200 if-match ip-prefix 1
apply origin incomplete
100.0.1.0/24 100.0.1.0/24 route-policy RP permit node 20
Origin=? Origin=i
10.1.13.3 bgp 100
R3 R5 network 100.0.1.0 24
peer 10.1.13.3 as-number 345
R4 peer 10.1.13.3 route-policy RP export
AS 345
BGP route
R1 and R2 import the route 100.0.1.0/24 to BGP using the network command. A route-policy is created on R1 to configure R1
to change the Origin attribute of the route 100.0.1.0/24 to Incomplete before advertising the route to R3. In this case, R4 prefers
the route 100.0.1.0/24 advertised by R5.
Using a Route-policy to Modify the Origin Attribute
1. Preferring the Route with the Largest 7. Preferring the Route Advertised by an EBGP Peer
Preferred_Value 8. Preferring the Route with the Smallest IGP Cost to the
4. Preferring the Route with the Shortest 10. Preferring the Route with the Shortest Cluster_List
AS_Path 11. Preferring the Route Sent by the BGP Peer with the
Priority (IGP>EGP>Incomplete) 12. Preferring the Route Sent by the Peer with the Lowest
• Multi-exit discrimination (MED) is an optional non-transitive attribute used to determine the optimal route when traffic enters
an AS with multiple ASBRs.
• During route selection, the route with the smallest MED value is selected as the optimal route if all other attributes are the
same.
• After the MED is sent to an EBGP peer, the peer keeps the MED in the route when transmitting the route within its AS. Once
the route leaves the AS, the MED is not transmitted to the next AS.
• By default, a router compares the MED values of only the BGP routes that are destined for the same
destination and are received from the same neighboring AS. If two routes are destined for the same
destination but are received from different neighboring ASs, the router does not compare the MED
values. To enable the router to compare the MED values in such cases, run the compare-different-as-
med command.
• If a route does not carry MED, BGP considers its MED as the default value (0) during route selection. If
the bestroute med-none-as-maximum command is run, BGP considers its MED as the largest MED
value (4294967295).
Contents
1. Preferring the Route with the Largest 7. Preferring the Route Advertised by an EBGP Peer
Preferred_Value 8. Preferring the Route with the Smallest IGP Cost to the
4. Preferring the Route with the Shortest AS_Path 10. Preferring the Route with the Shortest Cluster_List
5. Preferring the Route with the Highest Origin 11. Preferring the Route Sent by the BGP Peer with the
6. Preferring the Route with the Smallest MED 12. Preferring the Route Sent by the Peer with the Lowest
IP Address
Preferring the Route Advertised by an EBGP Peer
100.0.1.0/24 100.0.1.0/24
R1 R2
R5 learns the BGP route 100.0.1.0/24 from IBGP
AS 100 AS 200 peer R3 and EBGP peer R2. When other conditions
are the same, R5 prefers the BGP route learned from
100.0.1.0/24 100.0.1.0/24
R2.
10.1.13.3
R3 R5
AS 345 R4
Note: In this topology, an IBGP peer relationship is established between R3 and R5 using loopback 0 interfaces. The
peer next-hop-local command is run on R3, with R5 specified as the peer.
Preferring the Route Advertised by an EBGP Peer
1. Preferring the Route with the Largest 7. Preferring the Route Advertised by an EBGP Peer
4. Preferring the Route with the Shortest 10. Preferring the Route with the Shortest Cluster_List
AS_Path 11. Preferring the Route Sent by the BGP Peer with the
Priority (IGP>EGP>Incomplete) 12. Preferring the Route Sent by the Peer with the
100.0.1.0/24 • The eighth rule does not take effect because the Next_Ho
BGP route
NH=3.3.3.3 AS 345 p attribute values of the two BGP routes are the same (3.3.
R4 (RR)
3.3).
1. Preferring the Route with the Largest 7. Preferring the Route Advertised by an EBGP Peer
Preferred_Value 8. Preferring the Route with the Smallest IGP Cost to the
4. Preferring the Route with the Shortest 10. Preferring the Route with the Shortest Cluster_List
AS_Path 11. Preferring the Route Sent by the BGP Peer with the
Priority (IGP>EGP>Incomplete) 12. Preferring the Route Sent by the Peer with the Lowest
AS 100 AS 300
R1 R3 R1 AS 123
R3
8. 8. 4
8. 4
8.
0/ /2
8.
8. 0 /2
24 .0 0/ 8.
.8 24 8.
8.
8 8.
R2 R2
AS 200 AS 200
8.8.8.0/24 8.8.8.0/24
AS 400 R4 AS 400
R4
After R2 learns two EBGP routes to 8.8.8.0/24, R2 After R2 learns two IBGP routes to 8.8.8.0/24, R2
then selects only one optimal route, adds it to the then selects only one optimal route, adds it to the
routing table, and sends it to R4. routing table, and sends it to R4.
BGP Route Load Balancing
• On large-scale networks, there are usually multiple valid BGP routes to the same destination. Among these routes,
a device selects only one optimal BGP route, adds it to the routing table, and advertises only the optimal route to p
eers. In this case, traffic loads may be unbalanced. BGP route load balancing can address this problem. With BGP
route load balancing, multiple equal-cost BGP routes are added to the routing table, which reduces network conges
tion.
• Although BGP load balancing is configured, a device selects only one optimal route from multiple BGP routes to th
e same destination and advertises only the optimal route to peers.
• For BGP route load balancing to take effect, the attributes involved in the first eight rules must be the same.
BGP Route Load Balancing
• If BGP load balancing is configured, the local device changes the next hop address to its address regardless of wh
ether the peer next-hop-local command is run.
• By default, traffic cannot be balanced among IBGP and EBGP routes on the public network. If multiple routes with
the same destination address exist on the public network, the system selects the optimal route first. If the optimal
route is an IBGP route, only IBGP routes carry out load balancing. If the optimal route is an EBGP route, only
EBGP routes carry out load balancing.
• If there are multiple routes to the same destination address but these routes pass through different ASs, load balan
cing cannot be implemented by default. To allow these routes to participate in load balancing, run the load-balanci
ng as-path-ignore command. However, exercise caution when running this command because it changes the con
ditions of route load balancing.
• The load-balancing as-path-ignore and bestroute as-path-ignore commands are mutually exclusive.0
BGP Route Load Balancing
8.8.8.0/24 8.8.8.0/24
AS 100 AS 300
R1 R3 [R2-bgp] maximum load-balancing ebgp 2
//Set the maximum number of equal-cost EBGP routes for
8.
AS 8.8 24
0/ 00
load balancing to 2. The default value is 1, indicating that load
_P .0/2 8.
at 4 8. =3 balancing is not performed.
h= 8. ath
10
0 _P
AS [R2-bgp] load-balancing as-path-ignore
AS 200 R2 //The AS_Path attributes of the two routes advertised by R1
8.8.8.0/24
and R3 are different. Therefore, this command needs to be
configured so that the AS_Path attributes of the routes are not
compared during load balancing. Exercise caution when runni
AS 400 ng this command because it may lead to routing loops.
R4
R2 learns two EBGP routes to 8.8.8.0/24. Route attributes of the two routes are the same except the AS_Path attribute. By
default, R2 selects only one optimal route and advertises it to R4. After the maximum load-balancing ebgp 2 command is run
on R2, R2 adds the two equal-cost EBGP routes to the routing table for load balancing.
BGP Route Load Balancing
<R2>display bgp routing-table In the BGP routing table of R2, only one BGP route
BGP Local router ID is 10.1.12.2 is selected as the optimal route and is advertised to
Status codes: * - valid, > - best, d - damped, R4.
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 2
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 8.8.8.0/24 10.1.12.1 0 0 100i
* 10.1.23.3 0 0 300i
BGP Route Load Balancing
8.8.8.0/24 8.8.8.0/24
R1 AS123
R3
8. 4
8.
8. 0 /2
0/ 8.
24 8.
8.
[R2-bgp] maximum load-balancing ibgp 2 R2
AS200
//Set the maximum number of equal-cost IBGP routes for
8.8.8.0/24
load balancing to 2. The default value is 1, indicating that
load balancing is not performed.
R4 AS400
R2 learns two IBGP routes to 8.8.8.0/24, and the path attributes of the two routes are the same. Therefore, R2 selects only one
optimal route and advertises it to R4. After the maximum load-balancing ibgp 2 command is run on R2, R2 adds the two
equal-cost IBGP routes to the routing table for load balancing.
BGP Route Load Balancing
<R2>display bgp routing-table In the BGP routing table of R2, only one BGP
BGP Local router ID is 10.1.12.2 route is selected as the optimal route and is
Status codes: * - valid, > - best, d - damped, advertised to R4.
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 2
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 8.8.8.0/24 1.1.1.1 0 100 0 i
*i 3.3.3.3 0 100 0 i
Contents
1. Preferring the Route with the Largest 7. Preferring the Route Advertised by an EBGP Peer
4. Preferring the Route with the Shortest AS_Path 10. Preferring the Route with the Shortest Cluster_List
5. Preferring the Route with the Highest Origin 11. Preferring the Route Sent by the BGP Peer with the
6. Preferring the Route with the Smallest MED 12. Preferring the Route Sent by the Peer with the
Lowest IP Address
Preferring the Route with the Shortest Cluster_List (Example 1)
100.0.1.0/24 100.0.1.0/24
R1 R2
• An IBGP peer relationship is established
100.0.1.0/24 AS 100 AS 200 between R3 and R4, between R4 and R5, and
between R3 and R5 using loopback interfaces.
1. Preferring the Route with the Largest 7. Preferring the Route Advertised by an EBGP Peer
Preferred_Value 8. Preferring the Route with the Smallest IGP Cost to the
4. Preferring the Route with the Shortest 10. Preferring the Route with the Shortest Cluster_List
AS_Path 11. Preferring the Route Sent by the BGP Peer with the
Priority (IGP>EGP>Incomplete) 12. Preferring the Route Sent by the Peer with the Lowest
100.0.1.0/24 100.0.1.0/24
R1 R2
AS 100 AS 200
100.0.1.0/24 100.0.1.0/24
R3 R5
BGP route
In this topology, no BGP routing policies are deployed. R4 learns the BGP routes to 100.0.1.0/24 from R3 and R5. R4 cannot
select the optimal route using the first 10 rules. In this case, R4 preferentially selects the route advertised by the peer (R3) with
the smallest router ID according to this rule.
Preferring the Route Sent by the BGP Peer with the Smallest Router ID
• Rule supplement: If routes carry the Originator_ID attribute, the router compares the Originator_IDs rather than rout
er IDs and preferentially selects the route with the smallest Originator_ID.
8.8.8.0/24 1. The two routes have the same Preferred_Value and Local_Preference.
2. The two routes are not originated locally.
R4 3. The two routes have the same AS_Path length.
4. The two routes have the same Origin.
5. The two routes have the same MED.
6. The two routes are both IBGP routes.
Reflection Reflection
7. The two routes have the same Next_Hop.
1. Preferring the Route with the Largest 7. Preferring the Route Advertised by an EBGP Peer
Preferred_Value 8. Preferring the Route with the Smallest IGP Cost to the
4. Preferring the Route with the Shortest 10. Preferring the Route with the Shortest Cluster_List
AS_Path 11. Preferring the Route Sent by the BGP Peer with the
Priority (IGP>EGP>Incomplete) 12. Preferring the Route Sent by the Peer with the Lowest
8.8.8.0/24 1. The two routes have the same Preferred_Value and Local_Preference.
2. The two routes are not originated locally.
R4
3. The two routes have the same AS_Path length.
4. The two routes have the same Origin.
5. The two routes have the same MED.
6. The two routes are both IBGP routes.
Reflection Reflection
7. The two routes have the same Next_Hop.
R1 R3 8. The two routes have the same Cluster_List length.
RR RR
9. Because the two routes carry the Originator_ID attribute, R2 compares the Origin
ator_IDs the routes. However, the two routes have the same Originator_ID.
10. The route sent by the BGP peer (R1) with the smallest peer IP address is preferr
AS1234
R2
ed.
Note: The peer IP address is the one specified in the peer command in the BGP vie
w of R2 when a peer relationship is established between R1 and R2, or between
R2 and R3.
Preferring the Route Sent by the Peer with the Lowest IP Address