BGP选路原则.docx
《BGP选路原则.docx》由会员分享,可在线阅读,更多相关《BGP选路原则.docx(31页珍藏版)》请在冰豆网上搜索。
![BGP选路原则.docx](https://file1.bdocx.com/fileroot1/2022-12/11/264405d5-1c3c-40df-b005-de3f7f71be95/264405d5-1c3c-40df-b005-de3f7f71be951.gif)
BGP选路原则
IPA-taskpacket002:
BGP选路原则
实验二:
BGP选路原则
实验目标:
调试和观察BGP的选路原则
实验TOP:
物理拓扑
逻辑拓扑
基本配置:
R1
!
hostnameR1
!
noipdomainlookup
!
interfaceLoopback0
ipaddress1.1.1.1255.255.255.0
!
interfaceLoopback10
ipaddress10.10.10.10255.255.255.0
ipospfnetworkpoint-to-point
!
interfaceEthernet0/0
ipaddress10.1.1.1255.255.255.0
!
interfaceSerial1/0
ipaddress12.1.1.1255.255.255.0
serialrestart-delay0
clockrate64000
!
interfaceSerial2/0
ipaddress13.1.1.1255.255.255.0
serialrestart-delay0
!
routerospf10
router-id1.1.1.1
log-adjacency-changes
network10.1.1.00.0.0.255area0
network10.10.10.00.0.0.255area0
network12.1.1.00.0.0.255area0
network13.1.1.00.0.0.255area0
!
routerbgp1
nosynchronization
bgprouter-id1.1.1.1
bgplog-neighbor-changes
network1.1.1.0mask255.255.255.0
neighbor10.1.1.4remote-as345
neighbor12.1.1.2remote-as2
neighbor13.1.1.3remote-as345
noauto-summary
!
ipclassless
noiphttpserver
noiphttpsecure-server
!
!
linecon0
exec-timeout00
loggingsynchronous
lineaux0
linevty04
!
end
R2
!
hostnameR2
!
noipdomainlookup
!
!
interfaceLoopback0
ipaddress2.2.2.2255.255.255.0
!
interfaceLoopback10
ipaddress20.20.20.20255.255.255.0
ipospfnetworkpoint-to-point
!
interfaceEthernet0/0
noipaddress
shutdown
!
interfaceSerial1/0
ipaddress24.1.1.2255.255.255.0
serialrestart-delay0
clockrate64000
!
interfaceSerial2/0
ipaddress12.1.1.2255.255.255.0
serialrestart-delay0
!
routerospf10
router-id2.2.2.2
log-adjacency-changes
network12.1.1.00.0.0.255area0
network20.20.20.00.0.0.255area0
network24.1.1.00.0.0.255area0
!
routerbgp2
nosynchronization
bgprouter-id2.2.2.2
bgplog-neighbor-changes
network2.2.2.0mask255.255.255.0
neighbor12.1.1.1remote-as1
neighbor24.1.1.4remote-as345
noauto-summary
!
ipclassless
noiphttpserver
noiphttpsecure-server
!
!
!
!
!
linecon0
exec-timeout00
loggingsynchronous
lineaux0
linevty04
!
end
R3
!
hostnameR3
!
noipdomainlookup
!
!
interfaceLoopback0
ipaddress3.3.3.3255.255.255.0
!
interfaceLoopback10
ipaddress30.30.30.30255.255.255.0
ipospfnetworkpoint-to-point
!
interfaceEthernet0/0
noipaddress
shutdown
!
interfaceSerial1/0
ipaddress13.1.1.3255.255.255.0
serialrestart-delay0
clockrate64000
!
interfaceSerial2/0
ipaddress35.1.1.3255.255.255.0
serialrestart-delay0
!
routerospf10
router-id3.3.3.3
log-adjacency-changes
network13.1.1.00.0.0.255area0
network30.30.30.00.0.0.255area0
network35.1.1.00.0.0.255area0
!
routerbgp345
nosynchronization
bgprouter-id3.3.3.3
bgplog-neighbor-changes
network3.3.3.0mask255.255.255.0
neighbor13.1.1.1remote-as1
neighbor35.1.1.5remote-as345
neighbor45.1.1.4remote-as345
noauto-summary
!
ipclassless
noiphttpserver
noiphttpsecure-server
!
!
!
!
!
linecon0
exec-timeout00
loggingsynchronous
lineaux0
linevty04
!
End
R4
!
hostnameR4
!
noipdomainlookup
!
!
interfaceLoopback0
ipaddress4.4.4.4255.255.255.0
!
interfaceLoopback10
ipaddress40.40.40.40255.255.255.0
ipospfnetworkpoint-to-point
!
interfaceEthernet0/0
ipaddress10.1.1.4255.255.255.0
!
interfaceSerial1/0
ipaddress45.1.1.4255.255.255.0
serialrestart-delay0
clockrate64000
!
interfaceSerial2/0
ipaddress24.1.1.4255.255.255.0
serialrestart-delay0
!
routerospf10
router-id4.4.4.4
log-adjacency-changes
network10.1.1.00.0.0.255area0
network24.1.1.00.0.0.255area0
network40.40.40.00.0.0.255area0
network45.1.1.00.0.0.255area0
!
routerbgp345
nosynchronization
bgprouter-id4.4.4.4
bgplog-neighbor-changes
network4.4.4.0mask255.255.255.0
neighbor10.1.1.1remote-as1
neighbor24.1.1.2remote-as2
neighbor35.1.1.3remote-as345
neighbor45.1.1.5remote-as345
noauto-summary
!
ipclassless
noiphttpserver
noiphttpsecure-server
!
!
!
!
!
linecon0
exec-timeout00
loggingsynchronous
lineaux0
linevty04
!
End
R5
!
hostnameR5
!
noipdomainlookup
!
!
interfaceLoopback0
ipaddress5.5.5.5255.255.255.0
!
interfaceLoopback10
ipaddress50.50.50.50255.255.255.0
ipospfnetworkpoint-to-point
!
interfaceEthernet0/0
noipaddress
shutdown
!
interfaceSerial1/0
ipaddress35.1.1.5255.255.255.0
serialrestart-delay0
clockrate64000
!
interfaceSerial2/0
ipaddress45.1.1.5255.255.255.0
serialrestart-delay0
!
routerospf10
router-id5.5.5.5
log-adjacency-changes
network35.1.1.00.0.0.255area0
network45.1.1.00.0.0.255area0
network50.50.50.00.0.0.255area0
!
routerbgp345
nosynchronization
bgprouter-id5.5.5.5
bgplog-neighbor-changes
network5.5.5.0mask255.255.255.0
neighbor35.1.1.3remote-as345
neighbor45.1.1.4remote-as345
noauto-summary
!
ipclassless
noiphttpserver
noiphttpsecure-server
!
!
!
!
!
linecon0
exec-timeout00
loggingsynchronous
lineaux0
linevty04
!
End
(注:
路由器接口默认是关闭的,所以应将对应的接口开启)
如上配置,已经将R1至R5基本配置完成。
BGP选路规则:
BGP路由信息库(RIB)包括
Adj-RIBs-In:
储存未经处理的路由信息,来自对等体接收到的更新消息,所包含的路由信息是可用的
Loc-RIB:
包含的路由是运行BGP的路由器通过对Adj-RIBs-In中的路由使用他的本地路由策略而选择的路由
Adj-RIBs-Out:
包含运行BGP的路由器向其对等体公布的路由
三个数据库间的处理方法如下:
1、为每一条可用路由计算优先级,并对BGPupdate消息中包含的路由信息变更做出处理。
2、将最优路由放入Loc-RIB。
3、将适合的路由放入Adj-RIBs-Out(调用仅在上一步完成后)。
BGP路径选择顺序
1、优选有最大Weight的路由(范围0到65,535)。
A:
weight是CISCO私有的参数,路由器配置了权重后在本地有效。
2、优选有最大LOCAL_PREF值的路由(范围0到4,294,967,295)。
3、优选从本路由器始发的路由(包括本地network配置的重分布,或者在IGP表中已经有一些需要被配置路由聚合的地址,在BGP中用Aggregate命令配置的路由聚合)。
4、优选有最短AS_PATH的路由。
A:
如果配置了Bgpbestpathas-pathignore,则这个步骤被忽略。
B:
一个AS路径集被当作一个AS,无论在这个集合中有多少AS;AS路径长度中没有包括。
AS_CONFED_SEQUENCE。
5、根据Origin属性,优选具有最低起源类型的路由(IGP>EGP>Incomplete)。
6、优选最小MED值的路由(范围0到4,294,967,295)。
A:
只有在通过两条路径得到第一个AS(对等体)是同一个AS时才进行MED比较;任何子自治域的联盟系统都会被忽略。
也就是说,只有在AS序列号中第一个AS号码一致时,才进行MED比较;任何联盟AS序列号(AS_CONFED_SEQUENCE)都会被忽略。
B:
如果路由器上配置了bgpalways—compare—med,在全部的路径进行MED比较。
但是这需要全体AS都同时启用这个功能,否则有可能发生路由环路。
C:
如果路由器上配置了bgpbestpathmedconfed,将对所有只包括AS_CONFED_SEQUE
NCE的路径进行MED比较(即路径是起源于本地联盟)。
D:
如果接收到的路径没有分配MED值,则将此路径分配为0,除非路由器上配置了bestpathmissing—is—worst,将被看作MED值为4,294,967,295的路由将在注入到BGP路由选择表之前被改为4,294,967,295。
E:
BGP明确的MED值9也可以影响此步骤。
7、外部路由eBGP优先于联盟(confederation)外部路由优于内部路由iBGP(优选eBGP路由)。
注意,路径中包括AS_CONFEND_SEQUENCE属性对联盟只有在本地有效,因此被看作是内部路径。
无法区别外部联盟和内部联盟。
8、优选能通过最近的IGP邻居到达的路径(优选对BGP下一跳具有最低IGP度量值的路径)。
9、如果在路由器上配置了maximum—pathsN,而且从同一个对等体自治域/子自治域接收到多条外部/外部联盟的路径,则最多可以将N条最近接收到的路径加入到IP路由选择表中,这可以使得eBGP在多条路径上进行负载分担,目前N所代表的最大数目是6;当没有启用此功能时,缺省数值是1。
在输入了showip bgpx.x.x.x后系统输出信息中可以看到最早接收到的路径被标记为最优路径,在将这条最优路径转发到内部对等体之前,需要执行与next_hop_self作用相同的功能。
10、如果是external的路由,优选最老的路由(最先被学习到的路由)。
A:
此步骤可以将路由摆动的影响减到最小,因为新接收到的路径不会取代老的,即使这条新接收的路径是通过下面提及到的额外路径选择标准来进行选择的。
这使得只在iBGP路径下应用额外的选择步骤更有意义。
B:
此步骤可以被bgpbestpathcompare_routerid命令语句所关闭。
C:
如果路由器标志是一样的,此步骤可以被屏蔽,因为这说明路由器正在从自己那里接收路由。
D:
如果当前没有最优路由器,此步骤可以被屏蔽。
当提供某个路径的对等体路由器宏机,就会发生丢失当前最优路径的情况。
11、如果在同一时间学习到多条到同一目的地的路由,优选最小BGP-router-ID的路由,注意,如果一个路径包括路由反射器属性,起始者标识将代替路由器标识在路径选择过程中起作用。
12、如果路由从路由反射器上学习到,优选最小Cluster-ID(BGP_IDoftheroutereflector)长度的路由,而且它运行客户机和其他反射器族中的RR/Clients之间做对等连接,在这种情况下,路由器必须知道BGP协议中的RR的具体配置。
13、优选具有最低对等体地址接收到的路径。
这个地址是在BGP对等体上配置并使用的地址,这个地址是本地对等体路由器在其上配置TCP邻居并与远端对等体建立连接时采用的地址。
BGP路径选择顺序:
如果路径不可达或者同步开启后,路径不同步,则该路径不参与选路
1、Weight——权重(越大越优先,Cisco私有属性)
2、Local_Pref——本地优先(越大越优先,本AS内有效)
3、Next_Hop——所传递路由的本地起源优先,即下一跳是0.0.0.0(在BGP表中,当前路由器通告的路由的下一跳为0.0.0.0)
4、AS_Path(越短越优先,对于out与in方向的AS_Path操作产生的效果是不同的)
5、Origin起源(优先:
IGP>EGP>Incomplete;IGP指通过在BGP中network通告出来的路由,Incomplete指在BGP中通过重发布通告出来的路由)
6、MED(越小越优先,影响另一个AS的出站选路)
7、eBGP>iBGP(从eBGP对等体学习的路由优先于从iBGP对等体学习的路由)
8、BGP优先选择到BGP下一跳的IGP度量最低的路径
9、如果有多条来自相同相邻AS的路由并通过Maximum-paths使多条路径可用,则将所有开销相同的路由加入Loc-RIB
10、Age(eBGP)(Age越大越优先,多条路径具有相同的RID,这个原则不考虑)
11、BGP邻居的RID(越小越优先)
12、如果多条路径始发路由器ID或路由器ID相同,那么优选Cluster-List最短的路径
13、选择邻居ip地址最小的路由
下面根据观察每台路由器的BGP表并根据BGP的路径选择顺序进行分析:
R1
我们可以通过showipbgp命令来查看本路由器的BGP表,以下为R1的BGP表。
R1#showipbgp
BGPtableversionis6,localrouterIDis1.1.1.1
Statuscodes:
ssuppressed,ddamped,hhistory,*valid,>best,i-internal,
rRIB-failure,SStale
Origincodes:
i-IGP,e-EGP,?
-incomplete
NetworkNextHopMetricLocPrfWeightPath
*>1.1.1.0/240.0.0.0032768i
*2.2.2.0/2410.1.1.403452i
*>12.1.1.2002i
*13.1.1.303452i
*3.3.3.0/2410.1.1.40345i
*12.1.1.202345i
*>13.1.1.300345i
*4.4.4.0/2410.1.1.400345i
*12.1.1.202345i
*>13.1.1.30345i
*5.5.5.0/2410.1.1.40345i
*12.1.1.202345i
*>13.1.1.30345i
分析:
2.2.2.0/24:
从拓扑图中可以看到R1分别从R2、R3和R4三个eBGP对等体学习到2.2.2.0网段,但最后只将从R2学习到的下一跳为12.1.1.2的路由条目作为最优路径装进路由表。
根据BGP的路径选择顺序:
1、Weight(未设置)
2、Local_Perf(未设置)
3、Next_Hop(无)
4、AS_Path
由于从R3和R4学习到的路由条目跨越了AS345,所以由R3和R4传来的路由条目为2跳,最终选择由R2传来下一跳为12.1.1.2的路由条目装进路由表。
(注意:
当BGP协议依据某条选路规则选出最优路径时,将不再考虑后面的规则。
)
3.3.3.0/24:
R1分别从R2、R3和R4三个eBGP对等体学习到3.3.3.0网段,并将下一跳为13.1.1.3的路由条目装进路由表。
根据BGP的路径选择顺序:
1、Weight(未设置)
2、Local_Perf(未设置)
3、Next_Hop(无)
4、AS_Path
由R2传来的路由条目为2跳,R3和R4相同,都为1跳,所以先排除R2传来的路由条目为最佳路由。
5、Origin起源(无)
6、MED值(未设置)
7、eBGP>iBGP(R3和R4同为R1的eBGP对等体)
8、cost(用于iBGP)
9、Maximum-paths(无)
10、Age(用于eBGP,越大越优先)
这里我们用showipbgpsummary查看R1与R3、R4的老化时间。
可以看到R1与R3建立对等体的时间较长,所以选择由R3传来的下一跳为13.1.1.3的路由条目做为最佳路径装进路由表。
R1#showipbgpsummary
BGProuteridentifier1.1.1.1,localASnumber1
BGPtableversionis6,mainroutingtableversion6
5networkentriesusing505bytesofmemory
13pathentriesusing624bytesofmemory
6BGPpathattributeentriesusing360bytesofmemory
4BGPAS-PATHentriesusing96bytesofmemory
0BGProute-mapcacheentriesusing0bytesofmemory
0BGPfilter-listcacheentriesusing0bytesofmemory
BGPusing1585totalb