1.1.BGP协议最佳路径选择算法
BGP是一个路径矢量路由协议,也就是说,它的工作就是在自主系统间交换路由信息,以便发现访问互联网某处数据的最有效路径。每个 BGP路由器通过邻居声名与周边的一个或多个路由器连接。一旦建立了邻居关系,这些BGP路由器之间就会相互交换路由信息。据我最近一次统计,整个互联网上有大约12.5万个路由信息,因此要配备一个强大的路由器才能将所有BGP路由信息接收下来。
1.1.1.BGP 最佳路径选择算法概述
由于整个互联网的BGP路由表有超过30万个路由,同时一个BGP路由器可能从多个来源收到多份的路由表,因此肯定会有一种方法可以比较不同的 BGP路由表,并从中选择最佳的路由方案。这种方法就是BGP 最佳路径选择算法。
可能你会注意到,Cisco BGP路由器会将应用权重(weight)作为路由表的第一标准,而其它品牌的路由器则不是这样。Cisco的官方BGP最佳路径选择算法文档中详细列明了所参考的各项标准。接下来我会列出每种标准并给出解释和范例。
默认情况下,BGP最佳路径都是基于最短自治系统(AS)的原理得出的。不过很多时候,诸如weight,localpreference以及MED这样的标准都是网络管理员自行设定的。
接下来我们就按照BGP选择最佳路径的参考顺序将这几项标准介绍一下:
n #1 Weight —权重是Cisco为本地路由器设定的自定义参数,并不随路由器更新而变化。如果指向某一IP地址的路径有多条(这很常见),那么BGP会寻找权重最高的路径。设定权重的参考因素很多,包括邻居命令, as-path 访问列表,或者路由镜像等。
n #2 Local Preference—本地出口优先级参数会告知 AS 哪条路径具有本地优先,数值越高优先级越高。默认为100。比如:
n bgp defaultlocal-preference 150
n #3 Network orAggregate —这个参数会选择本地发起的网络或聚合作为路径。将特定的路径加入路由中,会让路由更有效率,同时也节省了网络空间。更多有关聚合的信息,可以参考Cisco的文章“UnderstandingRoute Aggregation in BGP.”
n #4 Shortest AS_PATH— BGP 只有在weight, local preference和locally originated相当接近的时候才使用这个参数。
n #5 Lowest origintype —这个参数处理InteriorGateway Protocol (IGP) 协议的优先级低于 Exterior GatewayProtocol (EGP)协议。
n #6 Lowestmulti-exit discriminator (MED) —较低的 MED 值要优于较高的MED值。
n #7 eBGP over iBGP —类似于#5,BGP AS Path 更倾向 eBGP 而不是 iBGP。
n #8 Lowest IGPmetric —这个参数倾向于采用最低IGP作为BGP下一跳。
n #9 Multiple paths —这个参数决定是否要在路由表中装入多个路径。可以参考 BGP Multipath 获取更多信息。
n #10 External paths —当所有路径都为外部路径时,选择首先接收到的路径(较老的路径)。
n #11 Lowest routerID —选择来自具有最低路由器ID的BGP路由器的路径。
n #12 Minimum clusterlist —如果多个路径的originator或路由器 ID相同,选择cluster列表长度最短的路径。
n #13 Lowest neighboraddress —这是指最低邻居地址传来的路径。
1.1.2.案例分析
1.1.2.1. 拓扑图
上图为BGP协议最佳路径选择算法的验证拓扑。
1.1.2.2. 验证方法:
l 跟踪1.1.1.0/24验证第7条
l 跟踪3.3.3.0/24验证第10,11,13条
l 路由过滤跟踪3.3.3.0/24验证第6条(影响邻居最佳路由选择)
l 跟踪33.33.33.0/24验证第5条,并在此基础上验证第3条
l 跟踪33.33.33.0/24验证第4条
l 跟踪1.1.1.0/24验证第1,2条
若要完成此实验需满足两个重要条件:1.已经同步或者同步已经关闭,2.下一跳可达。
1.1.3.验证第十三条,最低的邻居IP地址:
在R1,R6间建立两个邻接关系,然后在R1上观察网络3.3.3.0/24使用那一条路径作为下一跳。
实验输出
R1#show ip bgp BGP table version is 2, local router ID is 1.1.1.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path *> 3.3.3.3/24 16.16.16.6 0 65236 i * 61.61.61.6 0 65236 i |
1.1.4.验证第十一条,比较较小的邻居的RouterID
在R3上观察1.1.1.0/24的路由,优选从R2过来的那条路径
实验输出
R3#show ip bgp BGP table version is 2, local router ID is 3.3.3.3 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path * i 1.1.1.0/24 36.36.36.6 0 100 0 65101 i *>i 23.23.23.2 0 100 0 65101 i |
1.1.5.验证第十条,EBGP优选the oldestone
通过在R2上输入命令cle ip bgp * ,重置R1,R2的邻接关系,然后在R1的路由表中观察到关于网络3.3.3.0/24的下一跳的变化情况
实施策略前输出
R1#show ip route bgp Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override
Gateway of last resort is not set
3.0.0.0/24 is subnetted, 1 subnets B 3.3.3.0 [20/0] via 12.12.12.2, 00:00:46 |
实施策略后输出
R1#show ip route bgp Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override
Gateway of last resort is not set
3.0.0.0/24 is subnetted, 1 subnets B 3.3.3.0 [20/0] via 16.16.16.6, 00:00:05 |
1.1.6.验证第九条,maximum-paths负载分担
在R1开启命令maximum-paths 2,应该在R1的路由表中看到关于网络3.3.3.0/24有两个下一跳,实现了负载分担。
配置如下
router bgp 1 bgp router-id 1.1.1.1 maximum-paths 2 |
实验输出
R1#show ip route bgp Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override
Gateway of last resort is not set
3.0.0.0/24 is subnetted, 1 subnets B 3.3.3.0 [20/0] via 16.16.16.6, 00:00:05 [20/0] via 12.12.12.2, 00:00:05 |
1.1.7.验证第八条,lowestIGP metric
在R3观察1.1.1.0/24的路由,通过在R2上修改R2,R3间链路的带宽,从而影响EIGRP的metric。
配置如下
int s0/1 bandwidth 100 |
实验输出
R3#show ip bgp 1.1.1.0 255.255.255.0 BGP routing table entry for 1.1.1.0/24, version 5 Paths: (2 available, no best path) Not advertised to any peer Refresh Epoch 2 65101 12.12.12.1 (inaccessible) from 23.23.23.2 (2.2.2.2) Origin IGP, metric 0, localpref 100, valid, internal rx pathid: 0, tx pathid: 0 Refresh Epoch 2 65101 16.16.16.1 (inaccessible) from 36.36.36.6 (6.6.6.6) best Origin IGP, metric 0, localpref 100, valid, internal rx pathid: 0, tx pathid: 0 |
1.1.8.验证第七条,EBGP VsIBGP
在R2,R6间建立IBGP邻接关系,然后在R6上观察网络1.1.1.0/24的两个来源:
从R1来的是EBGP,从R2来的是IBGP
实验输出
R6#show ip bgp BGP table version is 3, local router ID is 6.6.6.6 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path * i 1.1.1.0/24 12.12.12.1 0 100 0 65101 i *> 16.16.16.1 0 0 65101 i |
1.1.9.验证第六条,MED
在R2,R6上分别修改关于网络3.3.3.0/24的med值,然后在R1上观察。
试验配置
R2 router bgp 236 bgp router-id 2.2.2.2 neighbor 12.12.12.1 route-map Net3 out ! route-map Net3 permit 10 match ip address 3 set metric 20 route-map Net3 permit 20 ! access-list 3 permit 3.3.3.0 0.0.0.255 |
R6 router bgp 236 bgp router-id 6.6.6.6 neighbor 16.16.16.1 route-map Net3 out ! route-map Net3 permit 10 match ip address 3 set metric 60 route-map Net3 permit 20 ! access-list 3 permit 3.3.3.0 0.0.0.255 |
实验输出
R1#show ip bgp BGP table version is 6, local router ID is 1.1.1.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path *> 3.3.3.0/24 12.12.12.2 20 0 65236 i * 16.16.16.6 60 0 65236 i |
1.1.10. 验证第五条,locally originated
在R3上观察26.26.26.0/24的网络
网络26.26.26.0/24在R6被重分发直连进入BGP表;在R2上被network进入BGP表
试验配置
R6 router bgp 236 bgp router-id 6.6.6.6 redistribute connected route-map S02 ! route-map S02 permit 10 match interface Serial0/2 |
R2 router bgp 236 bgp router-id 2.2.2.2 network 26.26.26.0 mask 255.255.255.0 |
实验输出
R3#show ip bgp BGP table version is 15, local router ID is 3.3.3.3 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path *>i 26.26.26.0/24 23.23.23.2 0 100 0 i * i 36.36.36.6 0 100 0 ? |
1.1.11. 验证第四条,Prefer shortest AS path.
在R3观察1.1.1.0/24的路由,R3应该可以收到分别从R2,R6的两条路由。
在R2上加route-map,利用as-pathprepend修改从R1过来的路由1.1.1.0/24的AS-path的长度
实验配置
R2 router bgp 236 neighbor 12.12.12.1 route-map Net1 in ! route-map Net1 permit 10 match ip address 1 set as-path prepend 1 set as-path prepend last-as 2 ! route-map Net1 permit 20 ! access-list 1 permit 1.1.1.0 0.0.0.255 |
实验输出
R3#show ip bgp BGP table version is 7, local router ID is 3.3.3.3 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path *> i 1.1.1.0/24 23.23.23.2 0 100 0 1 65101 65101 65101 i |
1.1.12. 验证第三条,是否起源于local router
在路由器R3观察网络1.1.1.0/24的两个来源:一个从IBGP学到,一个是本地network进来的
在R3上面多加一个环回接口1.1.1.3/24,或者在R2和R1运行EIGRP,R3通过EIGRP从R2学到R1在EIGRP中宣告的1.1.1./0的路由。
实验输出
R3#show ip bgp BGP table version is 6, local router ID is 3.3.3.3 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path *> 1.1.1.0/24 0.0.0.0 0 32768 i |
1.1.13. 验证第二条,本地优先级
配置之前后showip bgp(tracerout 1.1.1.1)观察1.1.1.0/24路由
通过在R2上修改1.1.1.0/24的路由的本地优先级,从而影响R3的路由选择,将R3到网络1.1.1.0/24的下一跳由原来的36.36.36.6 修改为23.23.23.2
实验配置
R2 router bgp 236 bgp router-id 6.6.6.6 neighbor 23.23.23.3 route-map Net1 out access-list 1 permit 1.1.1.0 0.0.0.255 ! route-map Net1 permit 10 match ip address 1 set local-preference 200 ! route-map Net1 permit 20 |
实验输出
R3#show ip bgp BGP table version is 7, local router ID is 3.3.3.3 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path *>i 1.1.1.0/24 23.23.23.2 0 200 0 1 65101 65101 65101 i |
1.1.14. 验证第一条,weight
配置前后观察R3上1.1.1.0/24的路由
实验配置
R3 router bgp 236 neighbor 36.36.36.6 route-map Net1 in route-map Net1 permit 10 match ip address 1 set weight 5 ! route-map Net1 permit 20 ! access-list 1 permit 1.1.1.0 0.0.0.255 |
实验输出
R3#show ip bgp BGP table version is 7, local router ID is 3.3.3.3 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path *>i 1.1.1.0/24 23.23.23.2 0 200 5 1 65101 65101 65101 i |
本文出自 “黑客的眼睛” 博客,转载请与作者联系!
原文地址:http://9627522.blog.51cto.com/9617522/1955220