1.1 解析BGP選路的意義
每個路由協議都有自己計算路由的方法,計算路由的方法稱為路由算法,BGP選路方法就是BGP的路由算法,BGP運行路由算法的目的是計算出有效路由進而優選出最優路由,選路算法是BGP路由協議的核心算法之一。
1.2 BGP選路與常見IGP選路的區別
眾所周知,鏈路狀態算法的路由協議,其路由非通告所得,而是計算所得,所以在鏈路狀態算法如OSPF,在其作用域內無法人為地干涉路由優選,即算法不可改變,在路由器的實現中在代碼中固定,人為干涉的結果會導致路由無法計算或計算出錯,在鏈路狀態算法的作用域之間,有相對比較簡單的計算規則,一般也沒有必要人為地去干涉選路(如OSPF協議的區域間路由)。
以上原因導致OSPF的路由計算對網絡管理員來說比較傻瓜化,大部分的選路工作由機器完成,管理員參與的部分極少。
基於距離矢量的IGP,如RIP由於路由協議中攜帶的信息量極少,可供選路決策的條件很少,所以討論其協議內部的路由優選意義不大。
BGP選路是一個比較復雜的過程,需要深入討論,原因是BGP的設計者將需要大部分由代碼固化完成的工作分了一部分出來“允許”管理員參與完成,在協議中也包含了豐富的優選參數,可供選路時自動或人為地進行控制與決策。這也說明,關於BGP的主要工作內容由兩部分:
² 在AS之間及AS內部傳遞路由――自動完成
² 控制、管理、優化路由――自動或由管理員手動完成
通過選路,我們可以看出設計者設計如此多屬性的原因,與通用的IGP協議采用單一Metric計算路由相比,BGP的眾多屬性更細致地反映一條路由的“歷史背景”,在選路過程中可以自動或手動地利用這些豐富的材料進行綜合考慮,進而更為細膩地優選和控制路由。
2 BGP選路過程解析
2.1 選路規則
BGP IPv4選路規則如下:
Ø 下一跳(Next_Hop)不可達的路由及其他無效路由不參與優選;
Ø 優選協議優先級值低的路由;
Ø 標簽路由(有LSP隧道)優於非標簽路由;
Ø 若配置了Preferred-value值,優選值高的;
Ø 優選本地優先級(Local_Pref)最高的路由;
Ø 優選本路由器始發的路由;
Ø 優選AS路徑(AS_Path)最短的路由;
Ø 依次選擇Origin屬性值為IGP、EGP、Incomplete的路由;
Ø 優選MED值最低的路由;
Ø EBGP路由優於聯盟EBGP路由,聯盟EBGP路由由於IBGP路由;
Ø 優選下一跳(Next_Hop)花費(Cost)值最低的路由;
Ø 優選Cluster_List長度最短的路由;
Ø 優選Originator_ID最小的路由;
Ø Router ID值小者優先;
Ø BGP會話地址小者優先。
以上優選規則是從前到后依次比較的,只有在前一個條件無法選出最優路由的情況下才考慮緊接的后一個條件。
2.2 實例解析選路過程
在本小節,通過實例的方式,按照以上選路規則解析路由器在選路過程中各步驟的決策條件。由於BGP屬性豐富,實際使用環境千變萬化,在實際使用中會出現各種應用場景,一個完整體現所有決策過程的拓撲會很復雜,為了簡潔明了地展開,本文用簡化的拓撲來解析每個決策步驟。
圖1說明:
RA、RB、RC都屬於AS100,三者建立Full mesh IBGP連接
RD、RE屬於AS200,二者建立IBGP連接
RA環回地址:192.168.100.1
RB環回地址:192.168.100.2
RC環回地址:192.168.100.3
步驟1:NEXT_HOP不可達的路由及沒有隧道的標簽路由都是無效路由,不參與優選
解析:RA從RB和RC分別收到關於20.1.1.0/24的路由,但下一跳沒有改變,下一跳屬於AS外部路由,RA不可達,所以下面兩條路由沒有星號(*)標志,都是無效的路由。
在RA上的BGP表信息如下:
[RA]display bgp routing-table Total Number of Routes: 2 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn i 20.1.1.0/24 10.1.4.2 0 100 0 200i i 10.1.5.2 0 100 0 200i
步驟2:優選協議優先級低的路由
解析:在路由有效的情況下比較路由優先級。通過路由策略修改協議優先級,RA從RC收到的路由優先級修改為250,而RA從RB收到的路由優先級為缺省的255,所以在RA上優選的結果是從RC收到的路由更優。
[RA-bgp]display bgp routing-table Total Number of Routes: 2 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *>i 20.1.1.0/24 192.168.100.3 0 100 0 200i * i 192.168.100.2 0 150 0 200i [RA-bgp]disp ip rout 20.1.1.1 Routing Table : Public Summary Count : 1 Destination/Mask Proto Pre Cost NextHop Interface 20.1.1.0/24 BGP 250 0 192.168.100.3 GE0/1.112
步驟3:標簽路由優於非標簽路由
解析: 取消上一步修改路由優先級的路由策略配置,RA從RB和RC的路由優先級一致,根據協議優先級無法選出最優路由。繼續比較,首先考慮的條件是該路由是否是標簽路由(是否存在LSP隧道)。重新配置路由策略,使RC向RA發送路由的同時分發標簽,帶有標簽的路由優於非標簽路由,所以優選從RC收到的路由。
[RA]display bgp routing-table Total Number of Routes: 2 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *>i 20.1.1.0/24 192.168.100.3 0 100 0 200i * i 192.168.100.2 0 150 0 200i [RA]disp ip rout 20.1.1.1 Routing Table : Public Summary Count : 1 Destination/Mask Proto Pre Cost NextHop Interface 20.1.1.0/24 BGP 255 0 192.168.100.3 GE0/1.112 [RA]display mpls lsp include 20.1.1.1 24 ------------------------------------------------------------------------- LSP Information: BGP LSP ------------------------------------------------------------------------- FEC In/Out Label In/Out IF Vrf Name 20.1.1.0/24 NULL/1025 -/- [RA-route-policy]display bgp routing-table 20.1.1.0 BGP local Router ID : 192.168.100.1 Local AS number : 100 Paths: 2 available, 1 best BGP routing table entry information of 20.1.1.0/24: Label information (Received/Applied): 1025/NULL From : 192.168.100.3 (192.168.50.29) Relay Nexthop : 10.1.2.2 Original nexthop: 192.168.100.3 AS-path : 200 Origin : igp Attribute value : MED 0, localpref 100, pref-val 0, pre 255 State : valid, internal, best, Not advertised to any peers yet BGP routing table entry information of 20.1.1.0/24: From : 192.168.100.2 (135.1.1.1) Relay Nexthop : 10.1.1.2 Original nexthop: 192.168.100.2 AS-path : 200 Origin : igp Attribute value : MED 0, localpref 150, pref-val 0, pre 255 State : valid, internal, Not advertised to any peers yet
步驟4:Preferred-value值高的路由優先
解析:取消上一步分發標簽的策略,RA從RB和RC收到的路由都沒有LSP隧道,所有前述條件無法選出最優路由,系統將進一步比較Preferred-value值優選路由。配置路由策略,使RA從RC收到的路由Preferred-value值較高,RA優選從RC收到的路由。
[RA-bgp]display bgp routing-table Total Number of Routes: 2 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *>i 20.1.1.0/24 192.168.100.3 0 100 30 200i * i 192.168.100.2 150 0 200i [RA-bgp]display bgp routing-table 20.1.1.0 BGP local Router ID : 192.168.100.1 Local AS number : 100 Paths: 2 available, 1 best BGP routing table entry information of 20.1.1.0/24: From : 192.168.100.2 (135.1.1.1) Relay Nexthop : 10.1.1.2 Original nexthop: 192.168.100.2 AS-path : 200 Origin : igp Attribute value : localpref 150, pref-val 0, pre 255 State : valid, internal, Not advertised to any peers yet BGP routing table entry information of 20.1.1.0/24: From : 192.168.100.3 (192.168.50.29) Relay Nexthop : 10.1.2.2 Original nexthop: 192.168.100.3 AS-path : 200 Origin : igp Attribute value : MED 0, localpref 100, pref-val 30, pre 255 State : valid, internal, best, Not advertised to any peers yet
步驟5:Local_Preference值高的路由優先
解析:在Preferred-value值相同的情況,進一步比較Local_Preference值優選路由,取消上一步修改Preferred-value值的路由策略,RA從RB收到的路由Local_Preference值較高,所以優選從RB收到的路由。
[RA-route-policy]disp bgp ro Total Number of Routes: 2 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *>i 20.1.1.0/24 192.168.100.2 0 150 0 200i * i 192.168.100.3 0 100 0 200i [RA-route-policy]display bgp routing-table 20.1.1.0 BGP local Router ID : 192.168.100.1 Local AS number : 100 Paths: 2 available, 1 best BGP routing table entry information of 20.1.1.0/24: From : 192.168.100.3 (192.168.50.29) Relay Nexthop : 10.1.2.2 Original nexthop: 192.168.100.3 AS-path : 200 Origin : igp Attribute value : MED 0, localpref 100, pref-val 0, pre 255 State : valid, internal, Not advertised to any peers yet BGP routing table entry information of 20.1.1.0/24: From : 192.168.100.2 (135.1.1.1) Relay Nexthop : 10.1.1.2 Original nexthop: 192.168.100.2 AS-path : 200 Origin : igp Attribute value : MED 0, localpref 150, pref-val 0, pre 255 State : valid, internal, best, Not advertised to any peers yet
步驟6:本地路由優先
解析:在RA上用路由聚合命令生成本地路由,並且使本地生成路由、IBGP路由、EBGP路由的路由優先級都相等。這時其他先決條件都相等的情況下,本地生成的路由優先。
[RA-route-policy]display bgp routing-table Total Number of Routes: 3 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *> 20.1.1.0/24 127.0.0.1 100 0 i * i 192.168.100.3 100 0 i [RA-route-policy]display bgp routing-table 20.1.1.0 24 BGP local Router ID : 192.168.100.1 Local AS number : 100 Paths: 2 available, 1 best BGP routing table entry information of 20.1.1.0/24: From : 192.168.100.3 (192.168.50.29) Relay Nexthop : 10.1.2.2 Original nexthop: 192.168.100.3 AS-path : (null) Origin : igp Attribute value : localpref 100, pref-val 0, pre 150 State : valid, internal, This route is an atomic-aggregated route Aggregator : AS 100, Aggregator ID: 192.168.50.29 Not advertised to any peers yet BGP routing table entry information of 20.1.1.0/24: Imported route. From : 0.0.0.0 (0.0.0.0) Original nexthop: 127.0.0.1 AS-path : (null) Origin : igp Attribute value : localpref 100, pref-val 0, pre 150 State : valid, local, best, This route is an aggregated route Aggregator : AS 100, Aggregator ID: 192.168.100.1 Advertised to such 1 peers: 192.168.100.3
步驟7:AS-Path較短的路由優先
解析:在前述條件都相同的情況下,將進一步比較AS-Path長度來優選路由。配置添加AS號的路由策略,RA從RC收到關於20.1.1.0/24的路由AS-path中包含兩個AS號,從RB收到的路由中包含三個AS號,在其它先決條件都相同的情況下,RA從RC收到的路由AS-path列表相對更短,所以優選從RC收到的路由。
按照AS-Path優選路由的規則可以細化為:AS_SEQ類型的AS-path長度為所包含的AS個數,AS_SET類型的AS-path長度為1,聯盟AS類型不計入AS-path長度。
[RA-bgp]display bgp routing-table Total Number of Routes: 4 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *>i 20.1.1.0/24 192.168.100.3 0 100 0 300 200i * i 192.168.100.2 100 0 400 300 200i
步驟8:依次選擇Origin屬性值為IGP、EGP、Incomplete的路由
解析1:在AS-Path長度相同的情況下將進一步比較Origin屬性的值。
下表顯示RA從RB收到的路由origin屬性為incomplete,從RC收到的路由origin屬性為egp,在其他先決條件都相等的情況下,origin屬性egp優於incomplete,RA優選從RC收到的路由
[RA-bgp]display bgp routing-table Total Number of Routes: 4 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *>i 20.1.1.0/24 192.168.100.3 0 100 0 320 200e * i 192.168.100.2 100 0 300 200?
解析2:下表顯示RA從RB收到的路由origin屬性被修改為igp,從RC收到的路由origin屬性仍然為egp,在其他先決條件都相等的情況下,origin屬性igp優於egp,所以最優路由發生變化,從RB收到的路由變成最優路由
[RA-route-policy]display bgp routing-table Total Number of Routes: 4 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *>i 20.1.1.0/24 192.168.100.2 100 0 300 200i * i 192.168.100.3 0 100 0 320 200e
總結:IGP優於EGP,EGP優於incomplete
步驟9:優選MED值最低的路由
解析1:取消上一步修改Origin屬性的路由策略,在Origin屬性及其他先決條件都無法比較出最優路由的情況下,MED屬性值小的路由優先,下表RA從RC收到關於20.1.1.0/24的路由MED值更低所以更優。
[RA-route-policy]display bgp routing-table Total Number of Routes: 2 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *>i 20.1.1.0/24 192.168.100.3 15 100 0 320 200e * i 192.168.100.2 20 100 0 320 200e
步驟10:依次優選EBGP路由、聯盟EBGP路由、IBGP路由
圖2說明:
RA和RB屬於聯盟子系統65001,RC屬於聯盟子系統65002;
RA與RB建立聯盟子系統內IBGP鄰居關系;
RA與RC建立聯盟子系統間EBGP鄰居關系;
RA與RE建立普通EBGP鄰居關系。
圖2 聯盟選路拓撲
解析1:在圖2中,RA分別從RB、RC、RE收到路由,在本步驟前的其他先決條件都相同的情況下優選來自EBGP的路由,EBGP路由優於聯盟EBGP和IBGP路由,所以RA優選來自RE的路由。
[RA-bgp]display bgp routing-table Total Number of Routes: 3 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *> 20.1.1.0/24 10.1.0.2 5 160 0 200i * i 192.168.100.3 5 160 0 (65002) 200i * i 192.168.100.2 5 160 0 200i
解析1:當EBGP路由被撤銷后,重新優選,由於聯盟EBGP路由優於IBGP路由,所以來自RC的路由優於來自RB的路由
[RA-GigabitEthernet0/1.110]display bgp routing-table Total Number of Routes: 2 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *>i 20.1.1.0/24 192.168.100.3 5 160 0 (65002) 200i * i 192.168.100.2 5 160 0 200i
步驟11:優選下一跳Cost值最低的路由;
解析:在其他先決條件都相等的情況下將比較下一跳的Cost值,RA從RC收到的路由下一跳為RC的環回地址192.168.100.3,到達該地址的IGP cost為13;RA從RB收到的路由下一跳為RB的環回地址192.168.100.2,到達該地址的IGP cost為15。因此優選從RC收到的路由。
[RA-GigabitEthernet0/1.112]display bgp routing-table Total Number of Routes: 2 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *>i 20.1.1.0/24 192.168.100.3 100 0 200i * i 192.168.100.2 0 100 0 200i [RA-GigabitEthernet0/1.112]disp ip rout 192.168.100.2 Routing Table : Public Summary Count : 1 Destination/Mask Proto Pre Cost NextHop Interface 192.168.100.2/32 OSPF 10 15 10.1.1.2 GE0/1.111 [RA-GigabitEthernet0/1.112]disp ip rout 192.168.100.3 Routing Table : Public Summary Count : 1 Destination/Mask Proto Pre Cost NextHop Interface 192.168.100.3/32 OSPF 10 13 10.1.2.2 GE0/1.112
步驟12:優選Cluster_List長度最短的路由;
在圖3中,BGP會話關系用黑色鏈路表示,綠色鏈路表示RB向RA反射從RD收到的路由;紅色鏈路表示RD發出的路由經過兩個反射器(RE和RC)反射到RA。
RA從RB收到的路由Cluster_List中只有一個條目;RA從RC收到的路由Cluster_List中有兩個條目。所以從RB收到的路由更優。
[RA]display bgp routing-table Total Number of Routes: 2 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *>i 40.1.1.0/24 192.168.100.2 100 0 ? * i 192.168.100.3 100 0 ? [RA]display bgp routing-table 40.1.1.0 BGP local Router ID : 192.168.100.1 Local AS number : 100 Paths: 2 available, 1 best BGP routing table entry information of 40.1.1.0/24: From : 30.1.1.3 (30.1.1.3) Relay Nexthop : 10.1.1.2 Original nexthop: 192.168.100.2 AS-path : (null) Origin : incomplete Attribute value : localpref 100, pref-val 0, pre 255 State : valid, internal, best, Originator : 192.168.100.4 Cluster list : 192.168.100.2 Not advertised to any peers yet BGP routing table entry information of 40.1.1.0/24: From : 30.1.1.2 (30.1.1.2) Relay Nexthop : 10.1.2.2 Original nexthop: 192.168.100.3 AS-path : (null) Origin : incomplete Attribute value : localpref 100, pref-val 0, pre 255 State : valid, internal, Originator : 192.168.100.4 Cluster list : 192.168.100.3, 192.168.100.5 Not advertised to any peers yet
步驟13:優選Originator_ID最小的路由;
在前述步驟未選出最優路由的情況下,進一步比較Originator_ID。
在圖4中,BGP會話關系用黑色鏈路表示,綠色鏈路表示RB向RA反射從RD收到的路由;紅色鏈路表示RC向RA反射從RE收到的路由。
解析:RA從RB收到的路由中Originator_ID相對更小,所以從RB收到的路由更優。
[RA]display bgp routing-table Total Number of Routes: 2 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *>i 20.1.1.0/24 192.168.100.2 100 0 ? * i 192.168.100.3 100 0 ? [RA]display bgp routing-table 20.1.1.1 BGP local Router ID : 192.168.100.1 Local AS number : 100 Paths: 2 available, 1 best BGP routing table entry information of 20.1.1.0/24: From : 30.1.1.2 (30.1.1.2) Relay Nexthop : 10.1.2.2 Original nexthop: 192.168.100.3 AS-path : (null) Origin : incomplete Attribute value : localpref 100, pref-val 0, pre 255 State : valid, internal, Originator : 192.168.100.5 Cluster list : 192.168.100.3 Not advertised to any peers yet BGP routing table entry information of 20.1.1.0/24: From : 30.1.1.3 (30.1.1.3) Relay Nexthop : 10.1.1.2 Original nexthop: 192.168.100.2 AS-path : (null) Origin : incomplete Attribute value : localpref 100, pref-val 0, pre 255 State : valid, internal, best, Originator : 192.168.100.4 Cluster list : 192.168.100.2 Not advertised to any peers yet
步驟14:Router ID值小者優先
RA從RB和RC收到的路由在前述步驟都無法優選出路由的情況下需要進一步比較Router ID來選出最優路由,在此步驟中Router ID值小的路由優先。
解析:RB的BGP Router ID為6.6.6.6;RC的BGP Router ID為5.5.5.5。所以在RA的BGP路由表中,從RC收到的路由優先。
[RA-bgp]display bgp routing-table Total Number of Routes: 2 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *>i 20.1.1.0/24 192.168.100.3 100 0 200i * i 192.168.100.2 0 100 0 200i [RA-bgp]display bgp routing-table 20.1.1.1 BGP local Router ID : 192.168.100.1 Local AS number : 100 Paths: 2 available, 1 best BGP routing table entry information of 20.1.1.0/24: From : 192.168.100.3 (5.5.5.5) Relay Nexthop : 10.1.2.2 Original nexthop: 192.168.100.3 AS-path : 200 Origin : igp Attribute value : localpref 100, pref-val 0, pre 255 State : valid, internal, best, Not advertised to any peers yet BGP routing table entry information of 20.1.1.0/24: From : 192.168.100.2 (6.6.6.6) Relay Nexthop : 10.1.1.2 Original nexthop: 192.168.100.2 AS-path : 200 Origin : igp Attribute value : MED 0, localpref 100, pref-val 0, pre 255 State : valid, internal, Not advertised to any peers yet
步驟15:建立BGP會話的地址值小者優先
RA從RB和RC收到的路由在前述步驟都無法優選出路由的情況下(除其他先決條件外,兩條路由的Router ID也相同)需要進一步比較建立BGP會話的地址值來選出最優路由,在此步驟中BGP會話地址值小的路由優先。
解析:在圖1中RB的環回地址為192.168.100.2,RB與RA的BGP會話通過此地址建立;RC的環回地址為192.168.100.3,RC與RA的BGP會話通過此地址建立。因為RB與RA建立BGP會話的地址相對更小,所以在RA的BGP路由表中,從RB收到的路由優先。
[RA-bgp]display bgp routing-table Total Number of Routes: 2 BGP Local Router ID is 192.168.100.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Network NextHop MED LocPrf PrefVal Path/Ogn *>i 20.1.1.0/24 192.168.100.2 0 100 0 200i * i 192.168.100.3 100 0 200i [RA-bgp]display bgp routing-table 20.1.1.1 BGP local Router ID : 192.168.100.1 Local AS number : 100 Paths: 2 available, 1 best BGP routing table entry information of 20.1.1.0/24: From : 192.168.100.2 (6.6.6.6) Relay Nexthop : 10.1.1.2 Original nexthop: 192.168.100.2 AS-path : 200 Origin : igp Attribute value : MED 0, localpref 100, pref-val 0, pre 255 State : valid, internal, best, Not advertised to any peers yet BGP routing table entry information of 20.1.1.0/24: From : 192.168.100.3 (6.6.6.6) Relay Nexthop : 10.1.2.2 Original nexthop: 192.168.100.3 AS-path : 200 Origin : igp Attribute value : localpref 100, pref-val 0, pre 255 State : valid, internal, Not advertised to any peers yet
2.3 優選路由的策略
優選路由的策略方法有很多,簡單舉例如下:
l 影響某台路由器本地選路結果
建議配置路由策略在本地修改Preferred-value來影響選路過程;由於Preferred-value值不屬於路由屬性,修改后只在本地生效,不會隨路由信息傳播。但影響本地選路后,BGP只發送最優路由,對其他路由器也有一定的影響。
l 影響IBGP鄰居的選路
如果希望影響本AS內部的路由器優選自己發出的路由,建議通過修改Local_Preference屬性值來實現,在圖1中,RB向RA發送的路由中Local_Preference屬性值為150,RC向RA發送的路由中Local_Preference屬性值為缺省值100,在RA上將優選從RB收到的路由,出AS的流量將通過RB發向AS200。
Local_Preference屬性可以向所有IBGP鄰居發送,可以對本AS內部所有的IBGP鄰居選路產生影響。
l 影響EBGP鄰居的選路
如果希望EBGP鄰居優選自己發出的路由,建議通過修改MED屬性值來實現,在圖1中,RD向EBGP鄰居RB發送的路由中MED屬性值為20,RE希望AS100中的路由器優選自己發出的路由,所以向EBGP鄰居RC發送的路由中MED屬性值為15,低於RD向RB發送路由的MED值,因為MED值低的路由更優,在AS100中將優選來自RE的路由。
在使用MED屬性時須注意,利用MED值進行優選是有一定條件的,來自不同AS的路由缺省情況下不能根據MED值優選路由,需要使能來自不同AS的路由選路時考慮MED這個特性才可以進行比較。
2.4 優選過程總結
從以上選路方式可以看出,在選路過程中,人為干預的決策條件(如:Preferred-value)以及本自治系統內使用的管理屬性(如:Local_Preference)等條件都放在選路決策的前幾步,而隨機條件(如:Router ID和會話地址的決策)都在最后,目的是使路由優選的管理和控制更加方便,這樣可以在各自治系統內部按照統一的策略來管理和計算路由。
原文鏈接:http://www.h3c.com/cn/d_201010/922168_30005_0.htm