BGP--Routing Selection--Theoretical Detailed Explanation


One, path attributes

1. Definition

  • Path attributes: path attributes, similar to metric, used to measure the pros and cons of BGP routing (used to select routes)

2. Classification

  1. Recognized mandatory attribute: all BGP update messages must include this attribute
>>>AS路径(As-path)(可用于防环)
>>>下一跳(next-hop)
>>>起源(origin)
  1. Recognized free attribute: This attribute is optional, but it can be recognized by all BGP processes
>>>本地优先级(local preferent)
  1. Optional delivery attribute: even if the BGP process does not recognize the attribute, it will continue to be delivered
>>>团体属性(community)
  1. Optional non-transitive attributes: If the BGP process does not recognize this attribute, you can ignore this update and not pass it on
>>>MED属性

Two, BGP routing principles

  1. If the next hop of this route is unreachable, ignore this route
  2. The higher the value of Preferred-Value, the more preferred, Huawei's private attribute, only local meaning (rarely used)
  3. The higher the Local-Preference value, the more preferred the route
  4. Aggregated routes take precedence over non-aggregated routes
  5. Local manually aggregated routes have higher priority than local automatically aggregated routes
  6. The priority of the local route imported through the Network command is higher than the local route imported through the Import-route command. 7. The shorter the As-path, the more preferred the route.
  7. Comparing origin attributes, IGP is better than EGP, EGP is better than Incomplete (not much controllable)
  8. Choose a route with a smaller MED (the smaller the MED, the more preferred)
  9. EBGP routing is better than IBGP routing
  10. BGP preferentially selects the path with the lowest IGP metric to the next hop of BGP

When all the above are the same, it is an equal-cost route and can be load-shared (Note: As Path must be the same. When load-sharing, the following 3 principles are invalid)

  1. Compare the length of the Cluster list, the shorter is preferred
  2. Compare the originator ID (if there is no originator ID, use the router ID to compare), choose the path with the smaller value
  3. Compare the IP addresses of peers and choose the path with the smallest IP address value

Three, BGP attribute routing configuration

A total of 12 methods, here are 3 common methods

1. According to local-prefernce control routing

The bigger the priority

  1. It is a recognized free attribute, used to tell the routers in the AS which path is the preferred path to leave the AS
  2. The Local Preference attribute can only be transferred between IBGP peers (unless a policy is made, the Local Preference value will not be lost during the transfer process between IBGP peers), but cannot be transferred between EBGP peers. If it is peered in EBGP The path attribute of the route received between the bodies carries LocalPreference, which will trigger the Notifacation message, causing the session to be interrupted;
  3. However, you can use the Import (injection) direction strategy on the AS border router to modify the Local Preference attribute value. That is, after receiving the route, give the local route a Local Preference
  4. Related commands
[R3] route-policy lop permit node 10 ###创建名为Lop的路由策略
[R3-route-policy] apply local-prefernce 222 ##设置本地优先级为222(默认优先级是100)
R3-route-policy]quit
[R3]bgp 200
[R3-bgp]peer 4.4.4.4 route-policy lop export ####在R3上对R4执行出站export方向的路由策略,使得R4在收到R3通告的路由后,在路由的local-prefernce的属性值改为222,使得R4优选R3通告的路由;如果此路由策略在R4配置则方向为入站import

reset bgp all ##重启BGP
refresh bgp all export

2. Use AS-PATH attribute to control routing

Less is better

  1. It is recognized as a mandatory attribute and is a list of As numbers that are routed to the target network
  2. Role: to ensure that routes are transmitted between EBGP peers without loops; in addition, it is also used as one of the criteria for routing optimization
  3. When a route is advertised to an EBGP peer, the router will add the local As number to the As-Path of the route; when the route is advertised to an IBGP peer, the AS-path will not change
  4. Use route-policy to modify the As Path of BGP routing
apply as-path xxx additive          ###在已有AS Path基础上追加xxx
apply as-path xxx overwrite         ###将已有AS Path值替换(覆盖)成xxx
apply as-path none overwrite        ###清空路亩的AS Path属性

5. When using route-policy to modify the AS Path of BGP routes, the AS Path attributes of EBGP routes can be changed between EBGP peers, which affects the optimization of BGP routes. On Huawei routers, between IBGP peers, you can also use route-policy to modify the AS Path of BGP routing. Regardless of the scenario, you must be very cautious when changing the AS-Path of the BGP route. It is recommended to keep the same with the last passed AS number.
6. The Bestroute as-path-ignore command is
used to configure BGP to ignore the AS path attribute when selecting the optimal route. . After configuring this command, BGP will not compare the length of the AS path. By default, the shorter length is better

[R2] route-policy as permit node 10
[R2-route-policy]apply as-path 123 123 123 additive   ##在已有AS Path基础上追加
[R2-route-policy]quit
[R2]bgp 200
[R2-bgp]peer 1.1.1.1 route-policy as export
<R2>reset bgp all
<R2>refresh bgp all export

3. Control routing through MED attributes

The smaller the priority

  1. Is an optional non-transitive attribute and is a measure
  2. Generally, BGP devices only compare the MED attribute values ​​of routes from the same AS (different peers). You can configure commands to allow BGP to compare the MED attribute values ​​of routes from different ASs. After executing the compare-different-as-med command, the system will compare the MED values ​​of routes from peers in different ASs.
  3. compare-different-as-med命令
[R2] route-policy med permit node 10
[R2-route-policy] apply cost + 500/- 500
[R2-route-policy]quit
[R2]bgp 200
[R2-bgp]peer 1.1.1.1 route-policy med export
< R2 >reset bgp all
< R2 >refresh bgp all export

display bgp routing-table        ###查BGP的路由表
display bgp routing-table 目标网段       ##查看详细信息

4. In the case of multiple network segments, only match a certain network segment to select the route

  • Origin belongs to the public and must be followed. It is used to define the source of path information. Its function is to mark how a route becomes a BGP route, and it works between EBGP neighbors.
  • It has three attributes:
    • IGP (i): highest priority
    • EGP(e): second priority
    • Incomplete (? ): the lowest priority
ip ip-prefix 1 permit 100.0.1.0 24
route-policy RP permit node 10
if-match ip-prefix 1 ###默认拒绝所有
apply origin incomplete
route-policy RP permit node 20

bgp 100
network 100.0.1.0 24
peer 10.1.13.3 as-number 345
peer 10.1.13.3 route-policy RP export

Four, BPG route reflector

  • In the AS, in order to ensure the connectivity between IBGP peers, a fully connected relationship needs to be established between IBGP peers
  • When the number of IBGP peers is large, the cost of establishing a fully connected network is high. Use route reflector RR (Route Reflector) to solve this problem
  • The cluster ID is used to prevent multiple route reflectors in the cluster and routing loops between clusters
  • When there are multiple route reflectors in a cluster, all route reflectors in the same cluster must be configured with the same cluster ID
  • The RR advertises routing rules to IBGP neighbors as follows: (equivalent to the role of a relay)
1.从非客户端学到的路由,发布给所有客户端
2.从客户端学到的路由,发布给所有非客户端和客户端(发起此路由的客户端除外) 
3.从EBGP对等体学到的路由,发布给所有的非客户端和客户端
  • The RR configuration commands
    R1, R2, R3, R4, R5, and R6 do not need to establish a full interconnection, but only establish neighbor relationships with routers on the network segment directly connected to them, and then act as route reflectors on R2 and R5 (the configuration of R5 and R2 The similarity is abbreviated)
[R2]bgp 100
[R2-bgp] router-id 2.2.2.2
[R2-bgp]peer 1.1.1.1 as-number 100
[R2-bgp]peer 1.1.1.1 connect-interface LoopBackO
[R2-bgp]peer 3.3.3.3 as-number 100
[R2-bgp]peer 3.3.3.3 connect-interface LoopBackO
[R2-bgp]peer 4.4.4.4 as-number 100
[R2-bgp]peer 4.4.4.4 connect-interface LoopBackO
[R2-bgp]peer 5.5.5.5 as-number 100
[R2-bgp]peer 5.5.5.5 connect-interface LoopBackO
[R2-bgp]reflector cluster-id 2 ###配置路由反射器的集群ID
[R2-bgp]peer 3.3.3.3 reflect-client ##指定客户端

mark


Five, BGP route aggregation

  • Scenario 1: Create a static summary route
[R7-bgp] network 192.168.0.0 255.255.252.0 ###将这个聚合的路由通告出去
[R7]ip route-static 192.168.0.0 255.255.252.0 NULL0 ###将聚合的路由通告出去,因为在手动汇总的这个192.168.0.0在路由表中是不存在的的,要把它加入到NULL0里才能在bgp进程里用上面的network来通告这条路由
  • Option II:
[R7-bgp] aggregate 192.168.0.0 255.255.252.0 detail-suppressed as-set ###配置手动路由聚合用aggregate, 

detail-suppressed是抑制明细路由的通告,增加las-set关键字后,该汇总路由将继承明细路由的路径属性,其中对明细路由AS-Path属性可以起到汇总路由防环作用

Guess you like

Origin blog.csdn.net/weixin_51486343/article/details/112109023