BGP选路原则详解(不错的)课件.ppt
BGP路由选路原则详解V1.0,学习总结,个人见解,如有错误欢迎改正!,学习目标,掌握BGP十三条选路原则的原理熟练掌握常见的BGP路由选路原则,BGP路由选路原则,1.Weight属性,2.Local Preference属性,3.本地路由始发方式,4.AS-Path长度,5.Origin属性,6.MED属性,7.EBGP优于IBGP,8.到达Next-hop的代价,9.执行等价负载均衡,10.EBGP路由接收的顺序,11.路由的Router-ID,12.Cluster-list长度,13.配置的BGP Peer指定地址,第一条:Weight属性,比较原则及配置注意事项:Cisco私有,可通过关联Route-map方式进行配置,该值无法传递给其他BGP Peer,只能在本地使用.携带的Weight值越大,则该路由越优先. 本地始发路由的默认值是32768,从其他BGP Peer学习过来的路由的默认值是0虽然Weight属性是Cisco私有的,但是很多厂商也是内置该属性(但无法显示及修改),这样就保证了本地始发的路由是最优先的,因为本地始发路由的”Weight”为32768,从其他BGP Peer学习过来的路由的”Weight”为0.,第一条:Weight属性,实验验证R2、R3分别通告10.0.0.0给R1R1将10.0.0.0使用network方式引入BGP,10.0.0.0/8,10.0.0.0/8,10.0.0.0/8,AS 1,AS 2,R3,R1,R2,IBGP,EBGP,第一条:Weight属性,实验验证R1的BGP表,r1#sh ip bgp BGP table version is 2, local router ID is 9.9.0.1Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path* i10.0.0.0 9.9.13.3 0 100 0 i* 9.9.12.2 0 0 2 i* 0.0.0.0 0 32768 i,第一条:Weight属性,实验验证R1对BGP Peer应用不同的Route-map修改所学习路由的Weight值,10.0.0.0/8,10.0.0.0/8,10.0.0.0/8,AS 1,AS 2,R3,R1,R2,IBGP,EBGP,router bgp 1 -R1的路由策略neighbor 9.9.12.2 route-map FROM_R2 inroute-map FROM_R2 permit 10 set weight 65535,第一条:Weight属性,实验验证R1的BGP表选路结果,r1#sh ip bgpBGP table version is 7, local router ID is 9.9.0.1Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Pathr i10.0.0.0 9.9.13.3 0 100 0 ir 9.9.12.2 0 65535 2 ir 0.0.0.0 0 32768 i,BGP路由选路原则,1.Weight属性,2.Local Preference属性,3.本地路由始发方式,4.AS-Path长度,5.Origin属性,6.MED属性,7.EBGP优于IBGP,8.到达Next-hop的代价,9.执行等价负载均衡,10.EBGP路由接收的顺序,11.路由的Router-ID,12.Cluster-list长度,13.配置的BGP Peer指定地址,第二条:Local Preference属性,比较原则及配置注意事项:值越大,越优先默认情况下,本地始发的路由的LP为100,从EBGP Peer接收的路由的LP为100.Local Preference属性只能在IBGP Peer之间传递,不能在EBGP Peer之间传递,如果在EBGP Peer之间收到的路由的路径属性中携带了Local Preference,则会触发Notifacation报文,造成会话中断,第二条:Local Preference属性,比较原则及配置注意事项:Local Preference通过如下三种方法进行设置:通过将IGP路由引入BGP时关联Route-map进行设置针对IBGP Peer应用IN/OUT方向的Route-map,对从Peer接收到的或者通告给Peer的所有或部分路由进行设置针对EBGP Peer应用IN方向的Route-map,对从Peer接收到的所有或部分路由进行设置Local Preference为BGP选路策略中经常使用的一个路径属性,第二条:Local Preference属性,实验一:Local Prefenerce无法在EBGP Peer之间传递,R1,R2,AS 1,AS 2,10.0.0.0/8,EBGP,router bgp 2 network 10.0.0.0 neighbor 9.9.12.1 remote-as 1 neighbor 9.9.12.1 route-map TO_R1 out!route-map TO_R1 permit 10 set local-preference 500,第二条:Local Preference属性,实验一:Local Prefenerce无法在EBGP Peer之间传递查看本地始发的BGP路由的LP值,r2#show ip bgp BGP table version is 2, local router ID is 9.9.0.2Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path* 10.0.0.0 0.0.0.0 0 32768 i,空值?,r2#sh ip b 10.0.0.0BGP routing table entry for 10.0.0.0/8, version 2Paths: (1 available, best #1, table Default-IP-Routing-Table) Advertised to non peer-group peers: 9.9.12.1 Local 0.0.0.0 from 0.0.0.0 (9.9.0.2) Origin IGP, metric 0, localpref 100, weight 32768, valid, sourced, local, best,第二条:Local Preference属性,实验一:Local Prefenerce无法在EBGP Peer之间传递R2通告给R1的BGP路由是否携带LP?,r1#sh ip bgp BGP table version is 2, local router ID is 9.9.0.1Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path* 10.0.0.0 9.9.12.2 0 0 2 i,500没有传递?,r2#sh ip bgp neighbors 9.9.12.1 advertised-routes BGP table version is 2, local router ID is 9.9.0.2Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path* 10.0.0.0 0.0.0.0 0 32768 i,第二条:Local Preference属性,实验一:Local Prefenerce无法在EBGP Peer之间传递R2通告给R1的BGP Update报文,R2通告的10.0.0.0/8前缀的路径属性中不包含Local Preference属性,第二条:Local Preference属性,实验二:修改本地始发路由的默认LP值,R1,R2,AS 1,10.0.0.0/8,IBGP,router bgp 1 -R2的路由策略 bgp default local-preference 500 network 10.0.0.0 neighbor 9.9.12.1 remote-as 1,第二条:Local Preference属性,实验二:修改本地始发路由的默认LP值,r2#sh ip b BGP table version is 2, local router ID is 10.0.0.1Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path* 10.0.0.0 0.0.0.0 0 32768 i,空值?,r2#sh ip b 10.0.0.0BGP routing table entry for 10.0.0.0/8, version 2Paths: (1 available, best #1, table Default-IP-Routing-Table) Advertised to non peer-group peers: 9.9.12.1 Local 0.0.0.0 from 0.0.0.0 (10.0.0.1) Origin IGP, metric 0, localpref 500, weight 32768, valid, sourced, local, best,第二条:Local Preference属性,实验二:修改本地始发路由的默认LP值,r1#sh ip b BGP table version is 4, local router ID is 9.9.0.1Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path*i10.0.0.0 9.9.12.2 0 500 0 i,第二条:Local Preference属性,实验三:将IGP中的路由引入BGP时关联Route-map设置LP,R1,R2,AS 1,10.0.0.0/8,IBGP,router bgp 1 -R2的路由策略 network 10.0.0.0 route-map SET_LP neighbor 9.9.12.1 remote-as 1!route-map SET_LP permit 10 set local-preference 400,第二条:Local Preference属性,实验三:将IGP中的路由引入BGP时关联Route-map设置LP,r2#sh ip b BGP table version is 3, local router ID is 10.0.0.1Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path* 10.0.0.0 0.0.0.0 0 400 32768 i,r1#sh ip bBGP table version is 6, local router ID is 9.9.0.1Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path*i10.0.0.0 9.9.12.2 0 400 0 i,第二条:Local Preference属性,实验四:对IBGP Peer应用IN/OUT方向Route-mapR3单向访问R6的数据流需求R1R2对R3应用OUT方向Route-map,R1,AS 1,R2,R3,R4,R5,R6,AS 2,以该方式部署策略,对数据流控制的作用范围,10.0.0.0/8,11.0.0.0/8,EBGP,第二条:Local Preference属性,实验四:对IBGP Peer应用IN/OUT方向Route-mapR4、R5正常通告R6的路由,R1、R2的BGP表,R1,AS 1,R2,R3,R4,R5,R6,AS 2,10.0.0.0/8,11.0.0.0/8,EBGP,r1#sh ip bgp Network Next Hop Metric LocPrf Weight Path* 10.0.0.0 9.9.15.5 0 2 i* 9.9.14.4 0 2 i* 11.0.0.0 9.9.15.5 0 2 i* 9.9.14.4 0 2 i,r2#sh ip bgp Network Next Hop Metric LocPrf Weight Path* 10.0.0.0 9.9.25.5 0 2 i* 9.9.24.4 0 2 i* 11.0.0 9.9.25.5 0 2 i* 9.9.24.4 0 2 i,IBGP,IBGP,IBGP,IBGP,第二条:Local Preference属性,实验四:对IBGP Peer应用IN/OUT方向Route-mapR1、R2的路由策略,router bgp 1 -R1的路由策略 neighbor 9.9.13.3 route-map TO_R3 outaccess-list 1 permit 10.0.0.0access-list 2 permit 11.0.0.0route-map TO_R3 permit 10 match ip address 1 set local-preference 500route-map TO_R3 permit 20 match ip address 2 set local-preference 400,router bgp 1 -R2的路由策略 neighbor 9.9.23.3 route-map TO_R3 outaccess-list 1 permit 10.0.0.0access-list 2 permit 11.0.0.0route-map TO_R3 permit 10 match ip address 1 set local-preference 400route-map TO_R3 permit 20 match ip address 2 set local-preference 500,R1,AS 1,R2,R3,R4,R5,R6,AS 2,10.0.0.0/8,11.0.0.0/8,EBGP,IBGP,IBGP,IBGP,IBGP,第二条:Local Preference属性,实验四:对IBGP Peer应用IN/OUT方向Route-mapR3的路由选路结果,r3#sh ip b BGP table version is 6, local router ID is 9.9.0.3Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path* i10.0.0.0 9.9.23.2 0 400 0 2 i*i 9.9.13.1 0 500 0 2 i*i11.0.0.0 9.9.23.2 0 500 0 2 i* i 9.9.13.1 0 400 0 2 i,R1,AS 1,R2,R3,R4,R5,R6,AS 2,10.0.0.0/8,11.0.0.0/8,EBGP,IBGP,IBGP,IBGP,IBGP,第二条:Local Preference属性,实验四:对IBGP Peer应用IN/OUT方向Route-map路由策略结果:R3到R6的实际单向数据流,R1,AS 1,R2,R3,R4,R5,R6,AS 2,10.0.0.0/8,11.0.0.0/8,EBGP,以该方式部署策略,对数据流控制的作用范围,第二条:Local Preference属性,实验五:对EBGP Peer应用IN方向Route-mapR3单向访问R6的数据流需求R1R2分别对R4R5应用OUT方向的Route-map,R1,AS 1,R2,R3,R4,R5,R6,AS 2,以该方式部署策略,对数据流控制的作用范围,10.0.0.0/8,11.0.0.0/8,EBGP,第二条:Local Preference属性,实验五:对EBGP Peer应用IN方向Route-mapR1、R2的路由策略,router bgp 1 -R1的路由策略 neighbor 9.9.14.4 route-map FROM_R4 inaccess-list 1 permit 10.0.0.0route-map FROM_R4 permit 10 match ip address 1 set local-preference 500route-map FROM_R4 permit 20,router bgp 1 -R2的路由策略 neighbor 9.9.25.5 route-map FROM_R5 inaccess-list 2 permit 11.0.0.0route-map FROM_R5 permit 10 match ip address 2 set local-preference 500route-map FROM_R5 permit 20,R1,AS 1,R2,R3,R4,R5,R6,AS 2,10.0.0.0/8,11.0.0.0/8,EBGP,IBGP,IBGP,IBGP,IBGP,第二条:Local Preference属性,实验五:对EBGP Peer应用IN方向Route-mapR1、R2的BGP表,r1#sh ip bgp Network Next Hop Metric LocPrf Weight Path* 10.0.0.0 9.9.15.5 0 2 i* 9.9.14.4 500 0 2 i* 11.0.0.0 9.9.14.4 0 2 i* 9.9.15.5 0 2 i,r2#sh ip bgp Network Next Hop Metric LocPrf Weight Path* 10.0.0.0 9.9.25.5 0 2 i* 9.9.24.4 0 2 i* 11.0.0.0 9.9.25.5 500 0 2 i* 9.9.24.4 0 2 i,R1,AS 1,R2,R3,R4,R5,R6,AS 2,10.0.0.0/8,11.0.0.0/8,EBGP,IBGP,IBGP,IBGP,IBGP,第二条:Local Preference属性,实验五:对EBGP Peer应用IN方向Route-mapR3的BGP表,r3#sh ip bgp BGP table version is 10, local router ID is 9.9.0.3Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path* i10.0.0.0 9.9.23.2 0 100 0 2 i*i 9.9.13.1 0 500 0 2 i*i11.0.0.0 9.9.23.2 0 500 0 2 i* i 9.9.13.1 0 100 0 2 i,R1,AS 1,R2,R3,R4,R5,R6,AS 2,10.0.0.0/8,11.0.0.0/8,EBGP,IBGP,IBGP,IBGP,IBGP,第二条:Local Preference属性,实验五:对EBGP Peer应用IN方向Route-map路由策略结果:R3到R6的实际单向数据流,R1,AS 1,R2,R3,R4,R5,R6,AS 2,10.0.0.0/8,11.0.0.0/8,以该方式部署策略,对数据流控制的作用范围,BGP路由选路原则,1.Weight属性,2.Local Preference属性,3.本地路由始发方式,4.AS-Path长度,5.Origin属性,6.MED属性,7.EBGP优于IBGP,8.到达Next-hop的代价,9.执行等价负载均衡,10.EBGP路由接收的顺序,11.路由的Router-ID,12.Cluster-list长度,13.配置的BGP Peer指定地址,第三条:本地路由始发方式,比较原则及配置注意事项 该比较原则主要是指本地在进入一条IGP路由进去BGP表时,使用不同的方式比如network或redistribute等,那么这些方式之间是存在优先顺序的:networkredistributeaggregate注意,该原则是不会作为BGP路由选路策略的,第三条:本地路由始发方式,实验验证 本地分别以3种方式引入一条路由,如下配置所示,interface Loopback1 ip address 3.3.3.3 255.255.255.255router bgp 1 network 3.3.3.3 mask 255.255.255.255 route-map A aggregate-address 3.3.3.3 255.255.255.255 attribute-map C redistribute connected route-map Broute-map A permit 10 set local-preference 200route-map B permit 10 set local-preference 300route-map C permit 10 set local-preference 400,第三条:本地路由始发方式,实验验证 本地BGP表中的显示,network方式为第一选择,r3#sh ip bgpBGP table version is 13, local router ID is 9.9.0.3Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path* 3.3.3.3/32 0.0.0.0 0 200 32768 i,第三条:本地路由始发方式,实验验证 将network 3.3.3.3 mask 255.255.255.255 删除redistribute方式成为优选,r3#sh ip bBGP table version is 14, local router ID is 9.9.0.3Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path* 3.3.3.3/32 0.0.0.0 0 300 32768 ?,BGP路由选路原则,1.Weight属性,2.Local Preference属性,3.本地路由始发方式,4.AS-Path长度,5.Origin属性,6.MED属性,7.EBGP优于IBGP,8.到达Next-hop的代价,9.执行等价负载均衡,10.EBGP路由接收的顺序,11.路由的Router-ID,12.Cluster-list长度,13.配置的BGP Peer指定地址,第四条:AS-Path长度,比较原则及配置注意事项优选长度小的AS-Path列表其他AS-Path比较原则:在做聚合路由时,使用as-set后产生的AS-Path列表中的里的AS号长度只算一个AS号的长度在联盟内的AS-Path列表中的()的AS号长度不做计算依据当向EBGP Peer 通告路由时,将自己的AS号加在AS-Path列表的最左端,向IBGP Peer通告路由时,不会对AS-Path列表做任何修改,第四条:AS-Path长度,比较原则及配置注意事项修改AS-Path列表的方法:可以通过对EBGP Peer使用IN/OUT方向的Route-map,使用set as-path prepend命令来添加AS号。注意,上述操作只能对EBGP Peer,对IBGP Peer无法生效。可以在BGP进程下使用bgp bestpath as-path ignore命令来跳过AS-Path的长度比较修改AS-Path长度可作为BGP选路策略的一种。,第四条:AS-Path长度,实验一:使用OUT方向的Route-map来修改AS-PathR3访问R4的单向数据流需求,R1,R2,R3,R4,AS1,AS2,10.0.0.0/8,以该方式部署策略,对数据流控制的作用范围,第四条:AS-Path长度,实验一:使用OUT方向的Route-map来修改AS-PathR1、R2的路由策略(R1保持默认),router bgp 2 -R2的路由策略 neighbor 9.9.23.3 route-map TO_R3 outroute-map TO_R3 permit 10 set as-path prepend 5 5 5,R1,R2,R3,R4,AS1,AS2,10.0.0.0/8,IBGP,EBGP,EBGP,IBGP,第四条:AS-Path长度,实验一:使用OUT方向的Route-map来修改AS-PathR3的BGP表选路结果,r3#sh ip bBGP table version is 2, local router ID is 9.9.0.3Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path* 10.0.0.0 9.9.23.2 0 2 5 5 5 i* 9.9.13.1 0 2 i,第四条:AS-Path长度,实验二:使用IN方向的Route-map来修改AS-PathR3访问R4的单向数据流需求,R1,R2,R3,R4,AS1,AS2,10.0.0.0/8,以该方式部署策略,对数据流控制的作用范围,第四条:AS-Path长度,实验二:使用IN方向的Route-map来修改AS-PathR3的路由策略,router bgp 1 -R3的路由策略 neighbor 9.9.23.2 route-map FROM_R2 inroute-map FROM_R2 permit 10 set as-path prepend 5 5 5,R1,R2,R3,R4,AS1,AS2,10.0.0.0/8,IBGP,EBGP,EBGP,IBGP,第四条:AS-Path长度,实验二:使用IN方向的Route-map来修改AS-PathR3的BGP表选路结果,r3#sh ip bgpBGP table version is 2, local router ID is 9.9.0.3Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path* 10.0.0.0 9.9.23.2 0 5 5 5 2 i* 9.9.13.1 0 2 i,不同方向的route-map对于插入的AS号的位置是不同的,BGP路由选路原则,1.Weight属性,2.Local Preference属性,3.本地路由始发方式,4.AS-Path长度,5.Origin属性,6.MED属性,7.EBGP优于IBGP,8.到达Next-hop的代价,9.执行等价负载均衡,10.EBGP路由接收的顺序,11.路由的Router-ID,12.Cluster-list长度,13.配置的BGP Peer指定地址,第五条:Origin属性,比较原则及配置注意事项三种不同的Origin属性的优先顺序:IGPEGPincompleteOrigin属性会一直在BGP路由中携带Origin属性配置方法:将IGP路由引入BGP时关联Route-map进行设置默认情况下,network方式产生的BGP路由的Origin属性为IGP,而redistribute方式产生的BGP路由的Origin属性为“?”对BGP Peer应用IN/OUT方向的Route-map进行设置很少使用设置Origin属性作为BGP路由选路策略,第五条:Origin属性,实验1:设置Origin属性R1R2R3分别以network方式引入路由,R1R3关联不同的Route-map设置不同的Origin属性,11.0.0.0/8,13.0.0.0/8,12.0.0.0/8,AS 1,AS 2,R3,R1,R2,IBGP,EBGP,router bgp 1 -R3的路由策略 network 13.0.0.0 route-map SET_Originroute-map SET_Origin permit 10 set origin incomplete,router bgp 1 -R1的路由策略network 11.0.0.0 route-map SET_Originroute-map SET_Origin permit 10 set origin egp,第五条:Origin属性,实验1:设置Origin属性R1的BGP表,r1# sh ip bgp BGP table version is 4, local router ID is 9.9.0.1Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path* 11.0.0.0 0.0.0.0 0 32768 e* 12.0.0.0 9.9.12.2 0 0 2 i*i13.0.0.0 9.9.13.3 0 100 0 ?,第五条:Origin属性,实验1:设置Origin属性R1对R3应用IN方向的Route-map修改Origin属性,R2对R1使用OUT方向的Route-map修改Origin属性,11.0.0.0/8,13.0.0.0/8,12.0.0.0/8,AS 1,AS 2,R3,R1,R2,IBGP,EBGP,router bgp 1 -R1的路由策略neighbor 9.9.13.3 route-map FROM_R3 inroute-map FROM_R3 permit 10 set origin igp,router bgp 2 -R2的路由策略neighbor 9.9.12.1 route-map TO_R1 outroute-map TO_R1 permit 10 set origin incomplete,第五条:Origin属性,实验1:设置Origin属性R1的BGP表,r1#sh ip bgpBGP table version is 6, local router ID is 9.9.0.1Status codes: s suppressed, d damped, h history, * valid, best, i - internal, r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path* 11.0.0.0 0.0.0.0 0 32768 e* 12.0.0.0 9.9.12.2 0 0 2 ?*i13.0.0.0 9.9.13.3 0 100 0 i,第五条:Origin属性,实验2:不同Origin属性之间的优先顺序,10.0.0.0/8,10.0.0.0/8,AS 1,R3,R1,R2,IBGP,IBGP,10.0.0.0/8,R4,IBGP,rout