路由优选规则
当到达同一个目的网段存在多条路由时,BGP通过如下的次序进行路由优选:
丢弃下一跳不可达的路由
- 优选Preferred-Value属性值最大的路由
- 优选Local_Preference属性值最大的路由
- 本地始发的BGP路由优于从其他对等体学习到的路由,本地始发的路由优先级按照:优选手动聚合>自动聚合>network>import>从对等体学到的
- 优选AS_Path属性值最短的路由
- 优选Origin属性最优的路由。Origin属性值按优先级从高到低排列:IGP>EGP>Incomplete
- 优选MED属性值最小的路由
- 优选从EBGP对等体学来的路由(EBGP路由优先级高于IBGP路由)
- 优选到Next_Hip的IGP度量值最小的路由
- 优选Cluster_List最短的路由
- 优选Router ID(Originator_ID)最小的设备通告的路由
- 优选具有最小IP地址对等体通告的路由
到第八条还没有选举出来,BGP可以满足等价负载
等价负载最大路由数量和忽略AS-Path
maxinum load-balancing 2//最大的等价路由数为2个,表示到达目的地最大只能有2条路径
load-balancing as-path-ignore//负载忽略as-path
案例一
如图10.10.10.10/32和10.10.10.20/32,NextHop都是2.2.2.2
优选Preferred-Value属性值最大的路由
现在将NextHop改成3.3.3.3
//在AR1上执行
peer 3.3.3.3 preferred-value 100//将到对等体3.3.3.3的preferred-value改成100
如果只针对10.10.10.10/32这条BGP路由的NextHop改成3.3.3.3
//在AR1上执行
#
acl number 2000
rule 5 permit source 10.10.10.10 0
#
route-policy 1 permit node 1
if-match acl 2000
apply preferred-value 100
#
route-policy 1 permit node 2//route-policy最后隐藏一条deny any,所以要加这一条permit any
#
peer 3.3.3.3 route-policy 1 import
#
优选Local_Preference属性值最大的路由
default local-preference 200//将本地local-preference改成200
此时NextHop变成了3.3.3.3
如果只针对10.10.10.10/32这条BGP路由的NextHop改成3.3.3.3
//在AR3上执行
#
acl number 2000
rule 5 permit source 10.10.10.10 0
#
route-policy 1 permit node 1
if-match acl 2000
apply local-preference 200
#
route-policy 1 permit node 2
#
peer 1.1.1.1 route-policy 1 export
#
本地始发的BGP路由优于从其他对等体学习到的路由,本地始发的路由优先级按照:优选手动聚合>自动聚合>network>import>从对等体学到的
在AR3上手动聚合路由
aggregate 10.0.0.0 255.0.0.0 detail-suppressed//聚合10.0.0.0/8路由,并且抑制明细路由
在AR2上自动聚合路由
#
ip route-static 10.10.10.10 255.255.255.255 24.1.1.4
ip route-static 10.10.10.20 255.255.255.255 24.1.1.4
#
summary automatic
import-route static
#
查看AR1上的bgp路由,选择了手动聚合的路由,如图:
优选AS_Path属性值最短的路由
//在AR3上执行
#
acl number 2000
rule 5 permit source 10.10.10.10 0
#
peer 1.1.1.1 route-policy 1 export
#
route-policy 1 permit node 1
if-match acl 2000
apply as-path 300 additive
#
route-policy 1 permit node 2
#
//在AR3上执行
#
acl number 2000
rule 5 permit source 10.10.10.10 0
#
peer 1.1.1.1 route-policy 1 export
#
route-policy 1 permit node 1
if-match acl 2000
apply as-path 300 overwrite
#
route-policy 1 permit node 2
#
//在AR3上执行
#
acl number 2000
rule 5 permit source 10.10.10.10 0
#
peer 1.1.1.1 route-policy 1 export
#
route-policy 1 permit node 1
if-match acl 2000
apply as-path none overwrite
#
route-policy 1 permit node 2
#
优选Origin属性最优的路由。Origin属性值按优先级从高到低排列:IGP>EGP>Incomplete
//在AR3上执行
#
acl number 2000
rule 5 permit source 10.10.10.10 0
#
peer 1.1.1.1 route-policy 1 export
#
route-policy 1 permit node 1
if-match acl 2000
apply origin incomplete
#
route-policy 1 permit node 2
#
优选MED属性值最小的路由
//在AR3上执行
#
acl number 2000
rule 5 permit source 10.10.10.10 0
#
peer 1.1.1.1 route-policy 1 import
#
route-policy 1 permit node 1
if-match acl 2000
apply cost 200
#
route-policy 1 permit node 2
#
在AR1的环回口上新增100.100.100.100/32并且宣告进OSPF中,也可以在AR3上执行,但是此操作只会针对import-route命令引入,具体看BGP属性MED注意事项
//在AR3上执行
#
default med 200
import-route ospf 1
#
此时在AR4上查看bgp路由,MED值为200
优选从EBGP对等体学来的路由(EBGP路由优先级高于IBGP路由)
将AR2和AR3建立IBGP对等体,此时BGP路由表如图:
10.10.10.10/32会从34.1.1.4和2.2.2.2传递过来,优选了34.1.1.4
优选到Next_Hop的IGP度量值最小的路由
将100.100.100.100/32宣告进OSPF,然后在AR2和AR3的BGP上network这条路由,此时传递路由会选择AR2的这条路径
现在在AR2的G0/0/0口上执行ospf cost 100,此时会选择AR3这条路径传递
//在AR2上执行
#
ospf cost 100
#
案例二
优选Cluster_List最短的路由
AR3、AR4、AR7做反射,AR5会从两条路径接收到100.100.100.100/32这条BGP路由,此时会选择AR8这条路径
案例三
优选Router ID(Originator_ID)最小的设备通告的路由
分别在AR4和AR8上查看display bgp routing-table 100.100.100.100,如图:
AR4上比较小,所以路由是从AR4上传递过来的:
优选具有最小IP地址对等体通告的路由
配置完BGP对等体后,默认会优选具有最小IP地址对等体通告的路由