BGP routing rules and load sharing

Overview:

The biggest advantage of BGP over IGP is that the path selection strategy is very rich, and the path selection is determined by adjusting the routing attributes of BGP. When using these routing attributes, you should consider the order and rules. Especially when a router has multiple paths to the destination, BGP needs to select the best path first according to the following routing rules. The "12 rules" for BGP routing are as follows:

Insert picture description here

Specific rules:

1. The next hop is reachable.

Note: The
next hop is reachable as the first rule in the BGP route selection rule. If the next hop IP address of a BGP route is unreachable, the BGP route will not participate in route selection.

2. Prefer the route with the highest value of the protocol preference value (PrefVal).

Note: The protocol preference value (PrefVal) is a unique attribute of Huawei equipment, and it also ranks first in the routing rules. Therefore, the priority is compared. This attribute is only meaningful for this router and will not be passed to other devices. The larger the protocol preference value, the better. The default preference value is 0. Different vendors have their own implementation methods.

3. Prefer the route with the highest Local Pref value.

Note: The
local priority attribute is transmitted within the entire AS, but will not be transmitted outside the AS. The larger the value, the more preferred. It is generally used as the router in the AS to select an optimal exit to the outside. If the route is not set with a local preference, BGP will process the route according to the default local preference of 100 when selecting a route.

4. The order of local origin priority is: ①Manually aggregated routes→②Automatically aggregated routes→③routes advertised by the network command→④routes imported by the import-route command→⑤routes learned from peers.

Note:
Rule 3 refers to the BGP routes generated by the current router. Locally generated routes are better than the routes learned by neighbors. Locally generated routes are divided into locally generated aggregated routes and IP route injected routes. Among them, aggregated routes are better than non-aggregated routes, and aggregation can be divided into manual aggregation and automatic aggregation, and the former is better than the latter; routes advertised into BGP through the network command are better than routes imported into BGP through import ; Next is the route learned from the neighbor. The routes in BGP are nothing more than the above types. If the routes of the same target prefix enter BGP through the above methods at the same time, the judgment will be made according to the above priority.

5. Prefer the route with the shortest AS path (AS_PATH).

Note: The
AS_PATH attribute is a list of AS paths to the target network. Similar to the hop concept in the distance vector protocol, the route with the shorter AS_PATH length is preferred.

6. Prefer the routes with Origin type as IGP, EGP, and incomplete in sequence.

Note:
Origin is the origin attribute of BGP, which refers to the origin of BGP routes. BGP routes will carry an origin attribute. If the route is a route generated through a network, the origin type is IGP (identified as i), if the route is learned through the EGP protocol, the origin type is EGP (identified as e), if the external route is imported into BGP Route, the origin type is incomplete (identified as? ). The order of priority is i>e>?.

Rule 4 compares the injection position of the route (local injection is better than what the neighbor learns), which is used to select the best route from the multiple routes generated locally to send to its neighbors; Rule 6 compares the route The injection method (network or impot). The origin code is used to select the best one among multiple identical routes received from different neighbors.

7. Prefer the route with the lowest MED (Multi Exit Discriminator) value.

Note:
By default , MED compares the MED values ​​of routes from the same neighbor. The smaller the number, the better the route. If it is a route from different neighboring ASs, MED does not participate in the comparison. Unless the compare-different-as-med command is enabled, MED can be compared between routes from different neighboring ASs.

8. Prefer eBGP routing, iBGP routing in turn.

Note:
If the route is learned through eBGP and iBGP at the same time, if other rules are the same, the eBGP peer will be selected first. The reason is simple, eBGP connects to external AS, and iBGP connects to internal AS. The router believes that since the route learned through eBGP must come from an external AS, it is more preferred to directly select eBGP peers to reach the outside than to traverse the entire AS and then reach the outside.

9. Prefer the route with the smallest metric value (Metric) to the next hop of BGP.

Note:
The next hop address of the BGP route is learned through the IGP protocol. According to the routing table, the metric
value to the next hop is calculated . The smaller the metric , the more preferred.

10. Prefer the route with the shortest Cluster_List.
Description:

  1. Cluster_List is an attribute in the route reflector, which is added by the route reflector. The Cluster_ID is added to the Cluster_List to record the cluster path that the reflected BGP route passes through in the AS. Similar to the AS_PATH attribute, the shorter the Cluster_List, the more preferred the route.
  2. If the route participating in the comparison does not have a Cluster_List, then rule 9 is skipped and the following rules are directly compared. If a route does not have Cluster_List, and other routes have Cluster. List, the route without Cluster_List attribute takes precedence.

11. Prefer the route advertised by the device with the smallest Router_ID.

Explanation:
The route advertised by the neighbor with the smallest Router_ID has the highest priority:

  1. If the route carries the Originator_ID attribute, the size of the Originator_ID will be compared during the route selection process, and the
    Router_ID will not be compared. Among them, the route with the smallest Originator. _ID is the best.
  2. If the originator_ ID of the routes participating in the comparison is the same, the Router_ ID is no longer compared, and the rule 11 is directly started.

12. Prefer the route learned from the peer with the smallest IP Address.

Explanation: The
last step will compare the IP addresses of neighbors, with the smallest being the first.

BGP load sharing:

Note: Configure as Huawei equipment.

In a large network, there are usually multiple effective routes to the same destination, but BGP only advertises the optimal route to peers. This feature often causes a lot of traffic load imbalance. By configuring BGP load sharing, you can balance traffic load and reduce network congestion.

In general, only when the first 8 attributes (except for the next hop) described in "BGP Route Selection Strategy" are exactly the same, and the AS_PATH attribute is also the same, BGP routes can be equal to each other and realize BGP load sharing. . However, the rules for routing load sharing can also be changed by configuration, such as ignoring the comparison of routing AS_PATH attributes, but these configurations need to ensure that they do not cause routing loops.

BGP can implement two forms of load balancing: load balancing for BGP routes and load balancing for next-hop routes.

1. Multiple BGP routes with different next hops appear in the IP routing table at the same time

By default, BGP only delivers the best BGP route to the IP routing table. However, this behavior can be configured with the maximum load-balancing [eBGP | iBGP] mumber command to configure the maximum number of equal-cost routes for BGP load balancing.

BGP can deliver multiple routes with the same first 8 rules in the "routing rules" to the IP routing table at the same time. The condition of load sharing is: in the first to eighth rules of "BGP routing selection strategy", the attributes to be compared must be "exactly the same." For multiple routes that meet this condition, after maximum load-balancing is enabled, multiple routes can be issued to the routing table. By default, the maximum number of equal-cost routes for BGP load balancing is 1, that is, no load balancing is performed.

If the number of BGP routes that meet the load sharing conditions is greater than the defined BGP load sharing specifications, the following order is preferred:

  1. The shortest Cluster_List is preferred.
  2. Preferably, the router advertised by the router with the smallest Router_ID: If the route carries the Originator_ID attribute, the size of the Originator_ID will be compared during the routing process (Router_ID is no longer compared), and the route with the smallest Originator_ID will be preferred.
  3. Compare the IP addresses of the peers and prefer the route learned from the peer with the smaller IP address.

When routes to the same destination in the public network form load sharing, the system will first determine the optimal route type. If the optimal route is an iBGP route, only iBGP routes form load sharing; if the optimal route is an eBGP route, only eBGP routes form load sharing. That is, iBGP routes and eBGP routes that reach the same destination in the public network cannot form load balancing. Load sharing is only effective for this device, but the device will still select the best route to send to other peers based on the routing principle, but load sharing is displayed in the routing table.

By default, routes will compare the AS_PATH attributes of the routes when they form load sharing. BGP only performs load sharing on routes with the same AS_PATH attributes. The BGP load sharing feature is also applicable to autonomous systems within the alliance. Configure the route not to compare the AS_PATH attributes of the route when forming load balancing. You can use the load-balancing as path-ignore command to achieve this. However, this method may cause routing loops, so use it with caution.

Because BGP does not have a routing algorithm, it cannot decide whether to load balance routes based on a clear metric. But BGP has many routing attributes, and the priority of these attributes in the BGP routing strategy is different. The processing rules for BGP load sharing are added to these routing strategies, that is, when all high-priority routes have the same attributes and BGP routing attributes are the same, BGP will base on the configured maximum load-sharing number of routes. Perform load sharing.

experiment:
Insert picture description here

As shown in the figure, AS 254 advertises two BGP routes 100.1.1.0/24 and 200.1.1.0/24, which are advertised into AS 100 by R5/R6. There are two eBGP routes from R1 to AS200, which can be reached through R5 and R6. . At present, only one of these two BGP routes enters the IP routing table of R1 by default:
Insert picture description here
load balancing command in the BGP process of R1: maximum load-balancing eBGP 2.

Check the IP routing table again, the two routes to AS 254 each have two next hops, and enter the IP routing table at the same time:
Insert picture description here
2. Load sharing of next hop routes

The difference between BGP and IGP is that its next-hop address can be the interface IP of a router that is not directly connected. When BGP advertises routes between iBGP neighbors in the AS, the down-hop remains unchanged, and data traffic is forwarded in the direction learned by the route. The next hop that is not directly connected will perform "iterative routing" on the router to look up the routing table. BGP relies on the next hop route to forward data, so if the route corresponding to the next hop address is load-sharing in the IP routing table , Then it can also be counted as BGP load sharing here.

The realization of this load sharing is actually not directly related to BGP, and it is entirely due to ECMP (Equal Cost Multiple Path) in IGP protocol routing. IGP calculates the metric value of the route according to its own routing algorithm, and performs load sharing among routes with the same metric value, which is actually IGP load sharing.

experiment:
Insert picture description here

As shown in the figure, R6 advertises a BGP route 100.1.1.0/24, and R5 accesses this network segment. When the data flow passes through R1, load sharing will be carried out. Because R1 and R4 establish iBGP neighbors, the BGP table of R1 reaches 100.1. The next hop of the 1.0 network segment is 10.1.4.4 (loopback 0) of R4, and the OSPF protocol is running inside AS 100. When R1 reaches the target network segment, it will iterate to 10.1.4.4 of R4, and there are two ways to reach R4. Equal-cost paths.

Check the BGP routing table of R1, the next hop address is 10.1.4.4:
Insert picture description here

Since there are two equal-cost paths to 10.1.4.4 in the IP routing table of R1, the BGP route will also have two next hops:
Insert picture description here

Sorting out the source of information: "HCIE Routing Exchange Learning Guide"

Guess you like

Origin blog.csdn.net/tushanpeipei/article/details/112750398