Detailed explanation of Huawei BGP routing rules

Detailed explanation of Huawei BGP routing rules

On Huawei equipment, there are eleven BGP routing rules, so how to use so many routing rules, the following is an experimental analysis of the eleven routing rules to explain.

Huawei BGP eleven routing rules

1. Prefer the highest protocol preferred value (pref val)
2. Prefer the route with the highest local priority (local_pref)
3. Prefer manual aggregation routes, automatic aggregation routes, routes introduced by the network command, and routes introduced by the import-route command in sequence. , the route learned from the peer
4. The route with the shortest AS_PATH is preferred
5. The origin type is IGP, EGP, incomplete route is preferred in sequence
6. For the route from the same AS, the route with the lowest MED value is preferred.
7. Select EBGP routes, IBGP routes, local cross routes, and remote cross routes in order.
8. The route with the smallest BGP next hop IGP metric value is preferred.
9. The route with the shortest cluster_list is preferred.
10. The route published by the device with the smallest router ID is preferred (if the route carries the originator_ID attribute, the size of the originator_ID will be compared during the route selection process. Then compare the router IDs and select the route with the smallest originator_ID.)
11. Select the route learned from the peer with the smallest IP address.

Experimental topology diagram:

As you can see from the above topology, there are four routers. AR1, AR2, AR3, AR4, among which R1, R2, R3 belong to AS 123, and R4 belongs to AS 4.

Publish a route on R4, 4.4.4.4 to BGP, and learn two BGP routes of 4.4.4.4 on R1

From the above, you can see that the next hops of the two BGP routes learned are R2 and R3 respectively. According to the tenth BGP route selection rule, the route published by the device with the smallest router-id is preferred, and R2 is preferred.

The first routing rule:

preferred-value

preferred-value mainly controls how to leave the device. Preferred-value is a private attribute of the BGP protocol. This command only takes effect on BGP routes. Preferred-value is the weight value in BGP routing rules and is not a standard attribute specified by RFC. Therefore, this command only takes effect locally and does not take effect in BGP egress policies.

Purpose:

Use preferred-value to modify R1 to prefer R3 when going to R4 (control how traffic leaves this device)

Configuration command:

# 配置路由策略
route-policy p_v permit node 10 
 apply preferred-value 1
#
# BGP视图下引用策略,该命令可以理解收到R3发过来的路由,调用路由策略p_v,在策略里面修改preferred-value为1 
bgp 123
  peer 3.3.3.3 route-policy p_v import
# 使用命令查看BGP路由,发现4.4.4.4路由的下一跳变为R3了,prefval值等于1.说明修改成功,也对路由有了影响。
[R1-bgp]display bgp routing-table 

 BGP Local router ID is 1.1.1.1 
 Status codes: * - valid, > - best, d - damped,
               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  4.4.4.4/32         3.3.3.3         0          100        1      4i
 * i                     2.2.2.2         0          100        0      4i

Verify view:

The second routing rule:

The local priority indicates the local priority of the router's BGP route, which is used to determine the best route to leave the AS. The default value is 100, and the larger the better.

The local-preference attribute can only be passed between IBGP neighbors. For IBGP neighbors, it can be configured in the outbound or inbound direction. For EBGP neighbors, it can only be used in the inbound direction.

Purpose:

By modifying the local-preference attribute, you can control whether AS 123 accesses AS 4 through R3 first.

Configuration command:

# 第一种方法,通过修改从EBGP收到的路由中的local-preference属性实现,其中的原理是从EBGP邻居学习到的路由会通告给IBGP邻居,在收到这个路由器上对该路由进行修改local-preference属性,那么通告给IBGP邻居的路由属性则是修改属性后的路由。
# 在R3配置路由策略
route-policy l_p permit node 10 
 apply local-preference 101 
#
# 在R3的BGP下调用策略,
bgp 123
  peer 10.1.34.4 route-policy l_p import
#
# 查看R1路由表,可以看到优选了R3去往R4,其中locprf是101
<R1>display bgp routing-table 

 BGP Local router ID is 1.1.1.1 
 Status codes: * - valid, > - best, d - damped,
               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  4.4.4.4/32         3.3.3.3         0          101        0      4i
 * i                     2.2.2.2         0          100        0      4i
<R1>
# 查看R2路由表
<R2>display bgp routing-table 

 BGP Local router ID is 2.2.2.2 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 1
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   4.4.4.4/32         10.1.24.4       0                     0      4i
<R2>
# 从R2路由表中看到,R2只有一条路由,这是因为IBGP邻居从IBGP邻居学到的路由不会在通告给IBGP邻居,可以理解为R3把R4的路由通告给R1后,然后R1收到后,并不会把该路由通告给R2,而R2通告给R1的路由也如此,所以在R2上和R3上都只存在一条R4的路由。
# 可以通过把R1配置为路由反射器,使R2也可以学到R3通告的路由。
bgp 123
  peer 2.2.2.2 reflect-client
  peer 3.3.3.3 reflect-client
#
# 配置完路由反射后再次查看R2的路由表
<R2>display bgp routing-table 

 BGP Local router ID is 2.2.2.2 
 Status codes: * - valid, > - best, d - damped,
               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  4.4.4.4/32         3.3.3.3         0          101        0      4i
 *                       10.1.24.4       0                     0      4i
<R2>
# 可以看到存在两条路由,并且去往4.4.4.4的下一跳是R3,从而实现通过local-preference实现控制AS123去往AS4的选路。
# 第二种方式,在IBGP邻居配置local-preference对AS的路由控制,实现原理通过在R3上修改R3向IBGP邻居发送的路由属性从而实现,在IBGP邻居的出方向调用路由策略。
# 在R3的BGP下调用路由策略
bgp 123
  peer 1.1.1.1 route-policy l_p export
# 配置完成后查看R1的BGP路由表和R2的BGP路由表
<R1>display bgp routing-table 

 BGP Local router ID is 1.1.1.1 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 1
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  4.4.4.4/32         3.3.3.3         0          101        0      4i
<R1>
<R2>display bgp routing-table 

 BGP Local router ID is 2.2.2.2 
 Status codes: * - valid, > - best, d - damped,
               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  4.4.4.4/32         3.3.3.3         0          101        0      4i
 *                       10.1.24.4       0                     0      4i
<R2>
# 结果是跟第一种方式一样的
# 第三种方式,在IBGP邻居的入方向调用路由策略,需要在R1接收R3路由的入方向调用策略,实现原理是R1在收到R3路由的时候,对收到的路由修改local-perference值进行影响路哟选路。
# 在R1上配置路由策略
route-policy l_p permit node 10 
 apply local-preference 101 
# 在R1的BGP下调用路由策略
bgp 123
  peer 3.3.3.3 route-policy l_p import
# 查看路由表
<R1>display bgp routing-table 

 BGP Local router ID is 1.1.1.1 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 1
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  4.4.4.4/32         3.3.3.3         0          101        0      4i
<R1>
<R2>display bgp routing-table

 BGP Local router ID is 2.2.2.2 
 Status codes: * - valid, > - best, d - damped,
               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  4.4.4.4/32         3.3.3.3         0          101        0      4i
 *                       10.1.24.4       0                     0      4i
<R2>
# 得到结论跟前二者一样

Route Selection Rule 3

Prefer manual aggregation routes, automatic aggregation routes, routes introduced by the network command, routes introduced by the import-route command, and routes learned from peers in order. This can be understood as the own router has multiple ways to generate a route, so for itself Which route will be preferred by you?

Purpose:

Let's do an experiment with R3 and R4. R4 advertises a 4.4.4.0/24 route to R3. R3 generates a 4.4.4.0/24 route through its own import-route, network, and manual aggregation methods. Observe that R3 will Choose that route.

Configuration command:

# 首先看到R3上学到了R4发送的一条4.4.4.0/24的路由
[R3]display bgp routing-table

 BGP Local router ID is 3.3.3.3 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 1
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   4.4.4.0/24         10.1.34.4       0                     0      4?
[R3]
# R3 通过import-route方式产生一条4.4.4.0/24的路由
ip route-static 4.4.4.0 255.255.255.0 NULL0
# BGP引入路由
bgp 123
  import-route static
#
[R3-bgp]display bgp routing-table

 BGP Local router ID is 3.3.3.3 
 Status codes: * - valid, > - best, d - damped,
               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

 *>   4.4.4.0/24         0.0.0.0         0                     0      ?
 *                       10.1.34.4       0                     0      4?
[R3-bgp]
# 查看R3路由表可以看到优选了import-route的路由
# 然后R3在通过network产生一条4.4.4.0/24的路由,在BGP下宣告4.4.4.0/24的路由
bgp 123
  network 4.4.4.0 255.255.255.0 
# 查看R3的路由表
[R3]display bgp routing-table

 BGP Local router ID is 3.3.3.3 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 3
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   4.4.4.0/24         0.0.0.0         0                     0      i
 *                       0.0.0.0         0                     0      ?
 *                       10.1.34.4       0                     0      4?
[R3]
# 可以看到优选了network产生的路由
# 然后R3在通过手动聚合产生一条4.4.4.0/24的路由
bgp 123
  aggregate 4.4.4.0 255.255.255.0 
# 
# 查看R3上的路由表
[R3-bgp]display bgp routing-table

 BGP Local router ID is 3.3.3.3 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 5
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   4.4.4.0/24         127.0.0.1                             0      i
 *                       0.0.0.0         0                     0      i
 *                       0.0.0.0         0                     0      ?
 *                       10.1.34.4       0                     0      4?
 *>   4.4.4.4/32         10.1.34.4       0                     0      4i
[R3-bgp]
# 根据以上路由表可以看到优选了手动聚合的路由,下一跳为127.0.0.1的这条为手动聚合的路由。

Rule 4 of routing rules

The route with the shortest AS_PATH is preferred. This rule is relatively easy to understand. From a literal meaning, the route with the shortest as_path is optimal. In principle, it can be understood that the more as_path, the more AS domains it spans, and the longer the path is, the less optimal it will be.

The AS_Path attribute is a private attribute of BGP. It records all the AS numbers that a route passes through from the local area to the destination address. By using the AS_Path attribute, you can control route selection and prevent routing loops. When there are multiple routes to the same destination, BGP will compare the AS_Path attributes of the routes, and the route with the shorter AS_Path list will be considered the best route.

Purpose:

By modifying the AS_PATH length on R2 and R3, it affects the routing selection of R1.

Configuration command:

# 在修改as_path长度前进行查看R1的BGP路由表
<R1>display bgp routing-table

 BGP Local router ID is 1.1.1.1 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 4
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  4.4.4.0/24         2.2.2.2         0          100        0      4?
 * i                     3.3.3.3         0          100        0      4?
 *>i  4.4.4.4/32         2.2.2.2         0          100        0      4i
 * i                     3.3.3.3         0          100        0      4i
<R1>
# 在R2配置as-path长度,首先使用路由策略定义好要增加的AS-PATH长度
route-policy as permit node 10 
 apply as-path 100 200 300 additive
# 然后在BGP接受EBGP路由时调用该策略
bgp 123
peer 10.1.24.4 route-policy as import
# 
# 配置完成后查看R1的路由表
<R1>display bgp routing-table

 BGP Local router ID is 1.1.1.1 
 Status codes: * - valid, > - best, d - damped,
               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  4.4.4.0/24         3.3.3.3         0          100        0      4?
 *>i  4.4.4.4/32         3.3.3.3         0          100        0      4i
<R1>
# R1优选了R3出去,然后查看R2自身的BGP路由表
[R2-bgp]display bgp routing-table 

 BGP Local router ID is 2.2.2.2 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 4
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  4.4.4.0/24         3.3.3.3         0          100        0      4?
 *                       10.1.24.4       0                     0      100 200 30
0 4?
 *>i  4.4.4.4/32         3.3.3.3         0          100        0      4i
 *                       10.1.24.4       0                     0      100 200 30
0 4i
[R2-bgp]
#可以看到R2自身修改了后,也优先选择R3做为下一跳了

Rule 5 of routing rules

Routes with origin types of IGP, EGP, and incomplete are preferred in order.

origin identifies the source of the BGP route and records how a route became a BGP route. The BGP route generated by network is identified as IGP. The BGP route generated by import-route is identified as incomplete and is displayed as a route with a number ? in the routing table. EGP is a route generated by running the EGP protocol. BGP and EBGP are not the same thing. EGP is basically not seen in the current network.

This routing rule can be understood as the routes imported into BGP from the network are better than the routes imported into BGP.

Purpose:

There are routes advertised by R2 and routes advertised by R3 on R1. The route advertised by R2 is preferred through router-id, so that the route selection of R1 can be affected by modifying the origin attribute.

Configuration command:

# 先查看R1的BGP路由表
<R1>display bgp routing-table

 BGP Local router ID is 10.1.12.1 
 Status codes: * - valid, > - best, d - damped,
               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  4.4.4.4/32         2.2.2.2         0          100        0      4i
 * i                     3.3.3.3         0          100        0      4i
<R1>
# 可以看到目前学到的两条路由起源属性都是IGP的,通过在R2上修改起源属性为EGP的,进而影响选路,并且证实I>E
# 配置R2路由策略
route-policy ogn permit node 10 
 apply origin egp 10
# BGP下调用策略,因为origin属性是公认必遵属性,所有路由器都可以识别的属性,所以可以通过如方向调用,也可以通过出方向调用。
bgp 123
  peer 10.1.24.4 route-policy ogn import
# 配置完成查看R2的路由表,检查结果
[R2-bgp]display bgp routing-table 

 BGP Local router ID is 10.1.12.2 
 Status codes: * - valid, > - best, d - damped,
               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  4.4.4.4/32         3.3.3.3         0          100        0      4i
 *                       10.1.24.4       0                     0      4e
[R2-bgp]
# 从路由表可以看到R2优选了从R3学到的IGP路由,而没有优选自己的EGP路由
# 在R3上修改origin属性为incomplete,证实E>?
route-policy origin permit node 10 
 apply origin incomplete
# 在R3的BGP下调用策略,在R1邻居上调用策略,使用出方向的方法,这样不会修改自身路由器所学到路由,只会对通告给R1的路由有影响。
# 查看R3的BGP路由表
[R3-bgp]display bgp routing-table

 BGP Local router ID is 10.1.13.3 
 Status codes: * - valid, > - best, d - damped,
               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

 *>   4.4.4.4/32         10.1.34.4       0                     0      4i
 * i                     2.2.2.2         0          100        0      4e
[R3-bgp]
# 从上述路由表可以看到自己通过R4学到的路由是IGP的,优于EGP所以优选了从R4学到的路由,然后在看R1上的路由表
<R1>display bgp routing-table 

 BGP Local router ID is 10.1.12.1 
 Status codes: * - valid, > - best, d - damped,
               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  4.4.4.4/32         2.2.2.2         0          100        0      4e
 * i                     3.3.3.3         0          100        0      4?
<R1>
# 从上述路由表可以看到R1上从R2学到的优选了,而没有优选从R3学到的,是因为R3学到的路由是incomplete。从而证实了I>E>?

Rule 6 of routing rules

For routes from the same AS, the route with the lowest MED value is preferred.

This routing rule is exactly the opposite of the second routing rule. local-preference controls how traffic leaves the AS, while MED controls how traffic returns to the AS.

The delivery range of MED can only be carried between two ASs and cannot be carried to a third AS. For example, when AS 10 advertises MED to AS 20, AS 20 will carry the MED attribute, but when AS 20 advertises it to AS 30, it will not carry the MED attribute.

MED delivery rules:

The MED can be passed when the route learned from the EBGP neighbor is passed to its own IBGP neighbor.

When the route learned from the EBGP neighbor is passed to its own EBGP neighbor, the MED is not carried.

When the route learned from the IBGP neighbor is passed to its EBGP neighbor, the MED is not carried.

MED function:

Carry the IGP cost of the advertised BGP route in this AS through the MED value to let the opposite AS know the IGP cost of my local route.

default med:

You can directly configure default med under BGP, but this command takes effect only on imported routes and aggregated routes, and will only be transmitted to its own EBGP neighbors, not to its own IBGP neighbors.

limit:

By default, the router will compare the MED value only when it receives a BGP route from a neighbor in the same AS. If the route comes from a different AS, it will not compare the MED value. If you need to compare MED values ​​from different ASs, you need to configure the command compare-different-as-med.

Purpose

The cost of accessing R1 from R2 is 50, and the cost of accessing R1 from R3 is 10. When R4 accesses R1, it is best to go to R3 to access it.

Configuration command:

# 先看一下R4访问R1的默认选举
<R4>display bgp routing-table 

 BGP Local router ID is 10.1.24.4 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 3
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   4.4.4.4/32         0.0.0.0         0                     0      i
 *>   10.10.10.10/32     10.1.24.2                             0      123i
 *                       10.1.34.3                             0      123i
<R4>
# 从路由表可以看出,R4访问R1是通过router-id比较出优先走R2的,然后通过在R2和R3上配置使得R4通过MED优选R3
# 配置R2的路由策略,并且修改IGP的开销
route-policy med permit node 10 
 apply cost-type internal 
#
interface GigabitEthernet0/0/0
 isis cost 50
#BGP下调用策略
bgp 123
  peer 10.1.24.4 route-policy med export
#
# R3配置路由策略,并且调用策略
route-policy med permit node 10 
 apply cost-type internal 
#
bgp 123
  peer 10.1.34.4 route-policy med export
#配置完成,在R4上再次查看前往R1的选路
<R4>display bgp routing-table 

 BGP Local router ID is 10.1.24.4 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 3
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   4.4.4.4/32         0.0.0.0         0                     0      i
 *>   10.10.10.10/32     10.1.34.3                             0      123i
 *                       10.1.24.2       50                    0      123i
<R4>
# 根据路由表可以看到,R4选择了R3做为优选下一跳设备,使用该方法在没有对AS4进行配置时,从而影响了AS4的选路。

Rule 7 of Route Selection Rules

EBGP routes, IBGP routes, local cross routes, and remote cross routes are preferred in order.

The understanding of this routing rule is that routes learned from EBGP neighbor peers are better than routes learned from IBGP neighbor peers.

Purpose:

There are two routes 4.4.4.4/32 on R3, which are the routes learned from R4 and the routes reflected by R1. The route learned by R4 is of EBGP type, and the route reflected by R1 is IBGP route. Check the comparison by observing the routing table.

Configuration command:

# 查看R3的BGP路由表
[R3-bgp]display bgp routing-table

 BGP Local router ID is 10.1.13.3 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 3
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   4.4.4.4/32         10.1.34.4       0                     0      4i
 * i                     2.2.2.2         0          100        0      4i
 *>i  10.10.10.10/32     1.1.1.1         0          100        0      i
[R3-bgp]
# 可以看到优选了下一跳为R4的路由表,然后看详细信息,查看下一跳为R2的路由为什么没被优选
[R3-bgp]display bgp routing-table 4.4.4.4

 BGP local router ID : 10.1.13.3
 Local AS number : 123
 Paths:   2 available, 1 best, 1 select
 BGP routing table entry information of 4.4.4.4/32:
 From: 10.1.34.4 (10.1.24.4)
 Route Duration: 04h43m10s  
 Direct Out-interface: GigabitEthernet0/0/1
 Original nexthop: 10.1.34.4
 Qos information : 0x0
 AS-path 4, origin igp, MED 0, pref-val 0, valid, external, best, select, active
, pre 255
 Advertised to such 1 peers:
    1.1.1.1
 BGP routing table entry information of 4.4.4.4/32:
 From: 1.1.1.1 (10.1.12.1)
 Route Duration: 03h21m11s  
 Relay IP Nexthop: 10.1.13.1
 Relay IP Out-Interface: GigabitEthernet0/0/0
 Original nexthop: 2.2.2.2
 Qos information : 0x0
 AS-path 4, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre 2
55, IGP cost 20, not preferred for peer type
 Originator:  10.1.12.2
 Cluster list: 10.1.12.1
 Not advertised to any peer yet
 # 通过以上回显可以看到没被优选的原因是  not preferred for peer type 不是对等体类型首选,可以理解为对等体类型就是EBGP和IBGP

Rule 8 of routing rules

Prefer the route with the smallest BGP next hop IGP metric value

It can be understood as the preference for the BGP next-hop IGP with a small overhead value. For example, there are two routes with different next-hops, where the preferred-value is both 0 and the local-preference is 100, both of which are learned from peers. Yes, the length of AS_PATH is the same, the origin attributes are all IGP, and the MED values ​​are all empty, which are all learned through IBGP neighbors. The first seven items cannot be compared to find out the optimal route, and then the eighth item will be compared. According to the above description, if there are different next hops, there will be a route to this next hop, and the next hop route is learned through IGP, so there is IGP overhead, such as the overhead from R1 to R2 is 20, and the cost from R1 to R3 is 10, then R3 will be preferred.

Purpose:

R1 prefers R2 when accessing R4. Modifying the IGP cost value affects R1's access to R4 and prefers R3.

Configuration command:

# 查看R1路由表,在没有做修改前优先选择的R2下一跳
<R1>display bgp  routing-table 

 BGP Local router ID is 10.1.12.1 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 3
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  4.4.4.4/32         2.2.2.2         0          100        0      4i
 * i                     3.3.3.3         0          100        0      4i
 *>   10.10.10.10/32     0.0.0.0         0                     0      i
<R1>
# 在R1上修改R1跟R2的互联的接口,修改ISIS开销值为20,增加开销
interface GigabitEthernet0/0/0
 isis cost 20
# 查看R1的路由表
[R1]display bgp routing-table

 BGP Local router ID is 10.1.12.1 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 3
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  4.4.4.4/32         3.3.3.3         0          100        0      4i
 * i                     2.2.2.2         0          100        0      4i
 *>   10.10.10.10/32     0.0.0.0         0                     0      i
[R1]
# 优选了R3做为下一跳设备

Load sharing

In BGP route selection rules, when the current eight cannot select the optimal route, BGP load balancing can be turned on.

Things to note:

By default, the fourth AS_PATH among the first eight entries needs to be the same in this scenario. When the PA_PATH length is the same but belongs to different ASs, load sharing cannot be performed. In this scenario, if you need to implement load balancing, you can use the command to ignore the AS_PATH check. You can configure the load-balancing as-path-ignore command under BGP to ignore the AS_PATH check.

Purpose:

By default, BGP does not enable load sharing. You need to manually enable BGP load sharing. By configuring load balancing on R1, load balancing is achieved for R1 accessing R4.

# 先查看没有修改配置的R1到R4的路由表
[R1-bgp]display ip routing-table 4.4.4.4 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Table : Public
Summary Count : 1
Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        4.4.4.4/32  IBGP    255  0          RD   2.2.2.2         GigabitEthernet
0/0/0

[R1-bgp]
# 通过路由表看到只有一条路由
# 可以通过在R1的BGP下配置命令开启负载分担
bgp 123
  maximum load-balancing 8
# 再次查看R1的IP路由表
[R1-bgp]display ip routing-table 4.4.4.4
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Table : Public
Summary Count : 2
Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

        4.4.4.4/32  IBGP    255  0          RD   2.2.2.2         GigabitEthernet
0/0/0
                    IBGP    255  0          RD   3.3.3.3         GigabitEthernet
0/0/1

[R1-bgp]
# 从上面路由表可以看到去往R4有了两个下一跳了,这是在IP路由表中的表现,其原理就是BGP路由表在加载到IP路由表的时候,如果前面八条都没有比较出来后,配置maximum load-balancing命令后,就会把没比较出来的也加载到IP路由表中去,但是在BGP路由表中还是一样的会比较出一个最优。查看BGP路由表时,可以看到依然只有一条是最优的。
[R1-bgp]display bgp routing-table 

 BGP Local router ID is 10.1.12.1 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 3
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  4.4.4.4/32         2.2.2.2         0          100        0      4i
 * i                     3.3.3.3         0          100        0      4i
 *>   10.10.10.10/32     0.0.0.0         0                     0      i
[R1-bgp]
# 通过第十条选路原则比较出的最优,而不会把两条路由都标识为最优路由

Route Selection Rules Article 9

Prefer the route with the shortest cluster_list. The meaning of this routing principle is the same as the literal meaning. In the RR scenario, there is an attribute cluster_list attribute. This is a list type, very similar to AS_PATH. Each time it passes through an RR, a cluster_list record will be added.

To simulate and implement the Article 9 route selection scenario, it is necessary to modify the original topology and change it to a hierarchical RR scenario.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-QCkF1Od7-1681473046862) (Detailed explanation of Huawei BGP routing rules.assets/image-20230413164802056.png)]

In the above topology, R3 acts as an ASBR to receive routes from R4 and advertises them to R5. R5 acts as the top-level RR. R1 and R2 both act as clients of R5. R1 also acts as an RR to perform reflection routing on R2.

Purpose:

Verify the ninth routing rule through experimental phenomena

Configuration command:

# 根据以上描述进行配置R5
bgp 123
 peer 1.1.1.1 as-number 123 
 peer 1.1.1.1 connect-interface LoopBack0
 peer 2.2.2.2 as-number 123 
 peer 2.2.2.2 connect-interface LoopBack0
 peer 3.3.3.3 as-number 123 
 peer 3.3.3.3 connect-interface LoopBack0
 #
 ipv4-family unicast
  undo synchronization
  peer 1.1.1.1 enable
  peer 1.1.1.1 reflect-client
  peer 2.2.2.2 enable
  peer 2.2.2.2 reflect-client
  peer 3.3.3.3 enable
#
#R1配置
bgp 123
 peer 2.2.2.2 as-number 123 
 peer 2.2.2.2 connect-interface LoopBack0
 peer 5.5.5.5 as-number 123 
 peer 5.5.5.5 connect-interface LoopBack0
 #
 ipv4-family unicast
  undo synchronization
  peer 2.2.2.2 enable
  peer 2.2.2.2 reflect-client
  peer 5.5.5.5 enable
#
# 完成配置查看R2的路由表
<R2>display bgp routing-table 

 BGP Local router ID is 10.1.12.2 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 4
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  4.4.4.4/32         3.3.3.3         0          100        0      4i
 * i                     3.3.3.3         0          100        0      4i
 *>i  10.10.10.10/32     1.1.1.1         0          100        0      i
 * i                     1.1.1.1         0          100        0      i
<R2>
# 通过上面可以看到有两条下一跳为3.3.3.3的路由,但是看起来都一模一样,看不出来区别,需要看详细信息。使用命令查看详细信息
<R2>display bgp routing-table 4.4.4.4 

 BGP local router ID : 10.1.12.2
 Local AS number : 123
 Paths:   2 available, 1 best, 1 select
 BGP routing table entry information of 4.4.4.4/32:
 From: 5.5.5.5 (5.5.5.5)
 Route Duration: 00h08m35s  
 Relay IP Nexthop: 10.1.25.5
 Relay IP Out-Interface: GigabitEthernet0/0/2
 Original nexthop: 3.3.3.3
 Qos information : 0x0
 AS-path 4, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, best,
 select, active, pre 255, IGP cost 20
 Originator:  10.1.13.3
 Cluster list: 5.5.5.5
 Not advertised to any peer yet

 BGP routing table entry information of 4.4.4.4/32:
 From: 1.1.1.1 (10.1.12.1)
 Route Duration: 00h11m07s  
 Relay IP Nexthop: 10.1.25.5
 Relay IP Out-Interface: GigabitEthernet0/0/2
 Original nexthop: 3.3.3.3
 Qos information : 0x0
 AS-path 4, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre 2
55, IGP cost 20, not preferred for Cluster List
 Originator:  10.1.13.3
 Cluster list: 10.1.12.1, 5.5.5.5
 Not advertised to any peer yet

<R2>
# 根据以上命令回显可以看到,在下方的回显中 Cluster list: 不一样,而没有优选的原因为not preferred for Cluster List。

Route Selection Rule 10

Prefer the route published by the device with the smallest router ID (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 no longer be compared, and the route with the smallest originator_ID will be preferred)

To implement the tenth routing principle, there are two concepts. One is that the router ID is always compared in this way before, and the other is that after passing the RR, if the originator_ID attribute exists, the router- will not be compared. id, the following uses a modified topology to reflect the comparison of originator_ID.

Purpose:

Demonstrate the phenomenon of originator_ID election through experiments

Configuration command:

# 配置R1跟R6建立BGP邻居,配置R5跟R6建立BGP邻居,并且配置为反射客户端
# R6配置
bgp 123
 peer 1.1.1.1 as-number 123 
 peer 1.1.1.1 connect-interface LoopBack0
 peer 5.5.5.5 as-number 123 
 peer 5.5.5.5 connect-interface LoopBack0
 #
 ipv4-family unicast
  undo synchronization
  peer 1.1.1.1 enable
  peer 5.5.5.5 enable
#
# 在R6上查看路由表
[R6-bgp]display bgp routing-table 

 BGP Local router ID is 6.6.6.6 
 Status codes: * - valid, > - best, d - damped,
               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  4.4.4.4/32         2.2.2.2         0          100        0      4i
 * i                     3.3.3.3         0          100        0      4i
[R6-bgp]
# 可以看到优选了R2的,查看详细信息
[R6-bgp]display bgp routing-table 4.4.4.4

 BGP local router ID : 6.6.6.6
 Local AS number : 123
 Paths:   2 available, 1 best, 1 select
 BGP routing table entry information of 4.4.4.4/32:
 From: 1.1.1.1 (10.1.12.1)
 Route Duration: 00h14m51s  
 Relay IP Nexthop: 10.1.16.1
 Relay IP Out-Interface: GigabitEthernet0/0/0
 Original nexthop: 2.2.2.2
 Qos information : 0x0
 AS-path 4, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, best,
 select, active, pre 255, IGP cost 20
 Originator:  10.1.12.2
 Cluster list: 10.1.12.1
 Not advertised to any peer yet

 BGP routing table entry information of 4.4.4.4/32:
 From: 5.5.5.5 (5.5.5.5)
 Route Duration: 00h05m56s  
 Relay IP Nexthop: 10.1.56.5
 Relay IP Out-Interface: GigabitEthernet0/0/1
 Original nexthop: 3.3.3.3
 Qos information : 0x0
 AS-path 4, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre 2
55, IGP cost 20, not preferred for router ID
 Originator:  10.1.13.3
 Cluster list: 5.5.5.5
 Not advertised to any peer yet

[R6-bgp]
# 查看详细信息可以看到,两条路由都携带了Originator属性,但是都不一样,从而比较了Originator属性的大小。在存在Originator属性的情况下,是不会比较router-id的。

Route Selection Rule 11

Prefer routes learned from the peer with the smallest IP address.

The last routing rule compares the addresses of peers, so when will the eleventh comparison be used?

Purpose:

Configure the experiment so that the optimal one is determined by comparing the last routing rule. A change to the topology is required

R3 learns the route of R4, and R5 and R1 serve as RRs and reflect it to R2. At this time, there will be two routes of R4 in the routing table of R2.

Configuration command:

# 配置R3,跟R1和R5建立邻居
bgp 123
 peer 1.1.1.1 as-number 123 
 peer 1.1.1.1 connect-interface LoopBack0
 peer 5.5.5.5 as-number 123 
 peer 5.5.5.5 connect-interface LoopBack0
 peer 10.1.34.4 as-number 4 
 #
 ipv4-family unicast
  undo synchronization
  peer 1.1.1.1 enable
  peer 1.1.1.1 next-hop-local 
  peer 5.5.5.5 enable
  peer 5.5.5.5 next-hop-local 
  peer 10.1.34.4 enable
# 配置R5跟R2和R3建立邻居,并且配置路由反射
bgp 123
 peer 2.2.2.2 as-number 123 
 peer 2.2.2.2 connect-interface LoopBack0
 peer 3.3.3.3 as-number 123 
 peer 3.3.3.3 connect-interface LoopBack0
 #
 ipv4-family unicast
  undo synchronization
  peer 2.2.2.2 enable
  peer 2.2.2.2 reflect-client
  peer 3.3.3.3 enable
  peer 3.3.3.3 reflect-client
# 配置R1,跟R5一样
bgp 123
 peer 2.2.2.2 as-number 123 
 peer 2.2.2.2 connect-interface LoopBack0
 peer 3.3.3.3 as-number 123 
 peer 3.3.3.3 connect-interface LoopBack0
 #
 ipv4-family unicast
  undo synchronization
  peer 2.2.2.2 enable
  peer 2.2.2.2 reflect-client
  peer 3.3.3.3 enable
  peer 3.3.3.3 reflect-client
# 查看R2的路由表
[R2-bgp]display bgp routing-table

 BGP Local router ID is 10.1.12.2 
 Status codes: * - valid, > - best, d - damped,
               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  4.4.4.4/32         3.3.3.3         0          100        0      4i
 * i                     3.3.3.3         0          100        0      4i
[R2-bgp]
# 可以看到存在着两条R4的路由,然后通过查看详细信息,看是什么原因下面那条没被优选的
[R2-bgp]display bgp routing-table 4.4.4.4

 BGP local router ID : 10.1.12.2
 Local AS number : 123
 Paths:   2 available, 1 best, 1 select
 BGP routing table entry information of 4.4.4.4/32:
 From: 1.1.1.1 (10.1.12.1)
 Route Duration: 00h01m11s  
 Relay IP Nexthop: 10.1.12.1
 Relay IP Out-Interface: GigabitEthernet0/0/0
 Original nexthop: 3.3.3.3
 Qos information : 0x0
 AS-path 4, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, best,
 select, active, pre 255, IGP cost 20
 Originator:  10.1.13.3
 Cluster list: 10.1.12.1
 Not advertised to any peer yet

 BGP routing table entry information of 4.4.4.4/32:
 From: 5.5.5.5 (5.5.5.5)
 Route Duration: 00h08m18s  
 Relay IP Nexthop: 10.1.12.1
 Relay IP Out-Interface: GigabitEthernet0/0/0
 Original nexthop: 3.3.3.3
 Qos information : 0x0
 AS-path 4, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, pre 2
55, IGP cost 20, not preferred for peer address
 Originator:  10.1.13.3
 Cluster list: 5.5.5.5
 Not advertised to any peer yet

[R2-bgp]
# 查看详细信息可以看到,是因为not preferred for peer address才没有被优选的,然后通过上面的信息可以看到在携带了Originator: 属性的情况下,是没有比较router-id的,而此时是要比较Originator,但是都一样比较不出来,所以才比较到了具有最小IP address的对等体学来的路由。

Guess you like

Origin blog.csdn.net/qq_41816198/article/details/130160883