本文件說明邊界閘道通訊協定 (BGP) 最佳路徑演算法的功能。
BGP路由器通常會收到多個前往同一目的地的路徑。BGP 最佳路徑演算法會決定哪一條是要安裝在 IP 路由表中並用於流量轉送的最佳路徑。
假設路由器收到的具有特定首碼的所有路徑都排列在一個清單中。此清單類似show ip bgp longer-prefixes 命令的輸出。在這個情況下,某些路徑不會被視為最佳路徑的候選路徑。在 show ip bgp longer-prefixes 命令的輸出中,此類路徑通常沒有有效的標幟。在這些情況下,路由器會略過路徑:
在 show ip bgp longer-prefixes 輸出中標記為 not synchronized 的路徑。
如果啟用 BGP 同步,則在 IP 路由表中的必須要有相符的首碼,才能讓內部 BGP (iBGP) 路徑被視為有效路徑。最初,Cisco IOS®軟體預設啟用BGP同步。如果相符的路由是從開放最短路徑優先(OSPF)鄰居得知的,其OSPF路由器ID必須與iBGP鄰居的BGP路由器ID相符。大多數使用者偏好使用 no synchronization BGP 子命令停用同步。
無法存取 NEXT_HOP 的路徑。
請確定具有到達與該路徑關聯的 NEXT_HOP 的內部閘道通訊協定 (IGP) 路由。
如果本機的自治系統 (AS) 出現在 AS_PATH 中,則路徑來自外部 BGP (eBGP) 鄰居。
此類路徑會在輸入路由器時遭到拒絕,且甚至不會安裝在BGP路由資訊庫(RIB)中。 這同樣適用於遭到透過存取、首碼、AS_PATH 或群體清單實作的路由原則拒絕的任何路徑, 除非您已設定鄰居的 neighbor soft-reconfiguration inbound。
如果您已啟用 bgp enforce-first-as ,而 UPDATE 並未包含鄰居的 AS 作為 AS_SEQUENCE 中第一個 AS 編號。
在這種情況下,路由器會傳送通知並關閉作業階段。
輸出中標籤為(received-only)的路show ip bgp longer-prefixes徑
原則已拒絕這些路徑。但是,由於您已為傳送路徑的鄰居設定,soft-reconfiguration inbound因此路由器已儲存路徑。
BGP 會將第一個有效路徑指派為目前的最佳路徑。接著,BGP 會比較最佳路徑和清單中的下一個路徑,直到 BGP 達到有效路徑清單的結尾。此清單提供用來判斷最佳路徑的規則:
優先使用具有最高 WEIGHT 的路徑。
優先使用具有最高 LOCAL_PREF 的路徑。
優先使用從本地透過 network 或 aggregate BGP 子命令產生或透過 IGP 重新分配的路徑。
源自 network 或 redistribute 命令的本地路徑會較源自 aggregate-address 命令的本地聚合優先使用。
優先使用具有最短 AS_PATH 的路徑。
優先使用最低來源類型的路徑。
優先使用具有最小多出口鑑別器 (MED) 的路徑。
優先使用 eBGP 路徑而非 iBGP 路徑。
如果已選取 bestpath,請前往步驟 9(多重路徑)。
優先使用具有最低 IGP 指標的路徑,而非 BGP 下一躍點。
繼續操作,即使已選取 bestpath。
判斷是否需要在 BGP 多重路徑的路由表中安裝多個路徑。
如果尚未選取 bestpath,則繼續操作。
當兩條路徑都是外部路徑時,優先使用首先接收的路徑(最早的路徑)。
即使根據下一個決策標準(步驟 11、12 和 13),較新的路徑會是優先使用的路由,因為較新的路徑不會取代較舊的路徑,此步驟將路由擺動情形降至最低。
如果以下任何事項為真,請跳過此步驟:
您已啟用 bgp best path compare-routerid 命令。
由於路由是從同一路由器接收的,因此多條路徑的路由器 ID 是相同的。
目前沒有最佳路徑。
目前的最佳路徑可能會遺失,例如提供路徑的鄰居關閉時。
優先使用來自具有最低路由器 ID 的 BGP 路由器的路由。
如果沒有手動配置,則路由器ID被選為環回介面上的最高IP地址。如果不存在環回介面,則會將其選為活動物理介面上的最高IP地址。您可以使用bgp router-id命令來手動設定路由器ID。
如果多個路徑的建立者或路由器 ID 相同,則優先使用具有最短叢集清單長度的路徑。
這只發生在 BGP RR 環境中。這允許用戶端與其他叢集中的 RR 或用戶端建立同儕節點關係。在這種情況下,用戶端必須知道 RR 特定的 BGP 屬性。
優先使用來自最低鄰居位址的路徑。
此位址是BGP設定中使用的IP位neighbor址。此位址對應到連線本地路由器的 TCP 連線所使用的遠端同儕節點。
在此範例中,網路10.30.116.0/23有9個可用路徑。show ip bgp network命令會顯示指定網路的BGP路由表中的專案。
Router R1#show ip bgp vpnv4 rd 1100:1001 10.30.116.0/23
BGP routing table entry for 1100:1001:10.30.116.0/23, version 26765275
Paths: (9 available, best #6, no table)
Advertised to update-groups:
1 2 3
(65001 64955 65003) 65089, (Received from a RR-client)
172.16.254.226 (metric 20645) from 172.16.224.236 (172.16.224.236)
Origin IGP, metric 0, localpref 100, valid, confed-internal
Extended Community: RT:1100:1001
mpls labels in/out nolabel/362
(65008 64955 65003) 65089
172.16.254.226 (metric 20645) from 10.131.123.71 (10.131.123.71)
Origin IGP, metric 0, localpref 100, valid, confed-external
Extended Community: RT:1100:1001
mpls labels in/out nolabel/362
(65001 64955 65003) 65089
172.16.254.226 (metric 20645) from 172.16.216.253 (172.16.216.253)
Origin IGP, metric 0, localpref 100, valid, confed-external
Extended Community: RT:1100:1001
mpls labels in/out nolabel/362
(65001 64955 65003) 65089
172.16.254.226 (metric 20645) from 172.16.216.252 (172.16.216.252)
Origin IGP, metric 0, localpref 100, valid, confed-external
Extended Community: RT:1100:1001
mpls labels in/out nolabel/362
(64955 65003) 65089
172.16.254.226 (metric 20645) from 10.77.255.57 (10.77.255.57)
Origin IGP, metric 0, localpref 100, valid, confed-external
Extended Community: RT:1100:1001
mpls labels in/out nolabel/362
(64955 65003) 65089
172.16.254.226 (metric 20645) from 10.57.255.11 (10.57.255.11)
Origin IGP, metric 0, localpref 100, valid, confed-external, best
Extended Community: RT:1100:1001
mpls labels in/out nolabel/362
!--- BGP selects this as the Best Path on comparing
!--- with all the other routes and selected based on lower router ID.
(64955 65003) 65089
172.16.254.226 (metric 20645) from 172.16.224.253 (172.16.224.253)
Origin IGP, metric 0, localpref 100, valid, confed-internal
Extended Community: RT:1100:1001
mpls labels in/out nolabel/362
(65003) 65089
172.16.254.226 (metric 20645) from 172.16.254.234 (172.16.254.234)
Origin IGP, metric 0, localpref 100, valid, confed-external
Extended Community: RT:1100:1001
mpls labels in/out nolabel/362
65089, (Received from a RR-client)
172.16.228.226 (metric 20645) from 172.16.228.226 (172.16.228.226)
Origin IGP, metric 0, localpref 100, valid, confed-internal
Extended Community: RT:1100:1001
mpls labels in/out nolabel/278
BGP會考慮本文所述的各種屬性,從這9個路徑中選擇最佳路徑。此處顯示的輸出中,BGP會比較可用路徑,並根據其較小的路由器ID選擇路徑6作為最佳路徑。
Comparing path 1 with path 2: Both paths have reachable next hops Both paths have a WEIGHT of 0 Both paths have a LOCAL_PREF of 100 Both paths are learned Both paths have AS_PATH length 1 Both paths are of origin IGP The paths have different neighbor AS's so ignoring MED Both paths are internal (no distinction is made between confed-internal and confed-external) Both paths have an IGP metric to the NEXT_HOP of 20645 Path 2 is better than path 1 because it has a lower Router-ID. Comparing path 2 with path 3: Both paths have reachable next hops Both paths have a WEIGHT of 0 Both paths have a LOCAL_PREF of 100 Both paths are learned Both paths have AS_PATH length 1 Both paths are of origin IGP Both paths have the same neighbor AS, 65089, so comparing MED. Both paths have a MED of 0 Both paths are confed-external Both paths have an IGP metric to the NEXT_HOP of 20645 Path 2 is better than path 3 because it has a lower Router-ID. Comparing path 2 with path 4: Both paths have reachable next hops Both paths have a WEIGHT of 0 Both paths have a LOCAL_PREF of 100 Both paths are learned Both paths have AS_PATH length 1 Both paths are of origin IGP Both paths have the same neighbor AS, 65089, so comparing MED. Both paths have a MED of 0 Both paths are confed-external Both paths have an IGP metric to the NEXT_HOP of 20645 Path 2 is better than path 4 because it has a lower Router-ID. Comparing path 2 with path 5: Both paths have reachable next hops Both paths have a WEIGHT of 0 Both paths have a LOCAL_PREF of 100 Both paths are learned Both paths have AS_PATH length 1 Both paths are of origin IGP Both paths have the same neighbor AS, 65089, so comparing MED. Both paths have a MED of 0 Both paths are confed-external Both paths have an IGP metric to the NEXT_HOP of 20645 Path 5 is better than path 2 because it has a lower Router-ID. Comparing path 5 with path 6: Both paths have reachable next hops Both paths have a WEIGHT of 0 Both paths have a LOCAL_PREF of 100 Both paths are learned Both paths have AS_PATH length 1 Both paths are of origin IGP Both paths have the same neighbor AS, 65089, so comparing MED. Both paths have a MED of 0 Both paths are confed-external Both paths have an IGP metric to the NEXT_HOP of 20645 Path 6 is better than path 5 because it has a lower Router-ID. Comparing path 6 with path 7: Both paths have reachable next hops Both paths have a WEIGHT of 0 Both paths have a LOCAL_PREF of 100 Both paths are learned Both paths have AS_PATH length 1 Both paths are of origin IGP Both paths have the same neighbor AS, 65089, so comparing MED. Both paths have a MED of 0 Both paths are internal (no distinction is made between confed-internal and confed-external) Both paths have an IGP metric to the NEXT_HOP of 20645 Path 6 is better than path 7 because it has a lower Router-ID. Comparing path 6 with path 8: Both paths have reachable next hops Both paths have a WEIGHT of 0 Both paths have a LOCAL_PREF of 100 Both paths are learned Both paths have AS_PATH length 1 Both paths are of origin IGP Both paths have the same neighbor AS, 65089, so comparing MED. Both paths have a MED of 0 Both paths are confed-external Both paths have an IGP metric to the NEXT_HOP of 20645 Path 6 is better than path 8 because it has a lower Router-ID. Comparing path 6 with path 9: Both paths have reachable next hops Both paths have a WEIGHT of 0 Both paths have a LOCAL_PREF of 100 Both paths are learned Both paths have AS_PATH length 1 Both paths are of origin IGP The paths have different neighbor AS's so ignoring MED Both paths are internal (no distinction is made between confed-internal and confed-external) Both paths have an IGP metric to the NEXT_HOP of 20645 Path 6 is better than path 9 because it has a lower Router-ID. The best path is #6
擴充的群體屬性(稱為 BGP Cost Community)提供了一種自訂最佳路徑選取流程的方法。最佳路徑演算法運作原理一節所述的演算法中新增一個額外的步驟,會比較成本群體。此步驟在演算法中的必要步驟(插入點)之後執行。具有最低成本值的路徑是優先使用路徑。
BGP 多重路徑允許將到達同一目的地的多個 BGP 路徑安裝到 IP 路由表中。這些路徑會與負載共用的最佳路徑一起安裝到表中。BGP 多重路徑不會影響最佳路徑的選取。例如,路由器仍會根據演演算法將其中一條路徑指定為最佳路徑,並將此最佳路徑通告給鄰居。
以下是 BGP 多重路徑的功能:
eBGP 多重路徑 - maximum-paths n
iBGP 多重路徑 - maximum-paths ibgp n
eiBGP多重路徑 — maximum-paths eibgp
要成為多重路徑的候選路徑,到達同一目標的路徑需要具有與最佳路徑特性相同的這些特性:
重量
本地優先使用程度
AS-PATH 長度
原始來源
MED
以下其中一項:
相鄰 AS 或子 AS (在新增 eiBGP 多重路徑功能之前)
AS-PATH(在新增 eiBGP 多重路徑功能之後)
有些 BGP 多重路徑功能對多重路徑候選選項有額外的要求。
以下是對 eBGP 多重路徑的額外要求:
必須從外部或聯盟外部鄰居(eBGP)得知該路徑。
BGP下一躍點的IGP度量必須等於最佳路徑IGP指標。
以下是對 iBGP 多重路徑的額外要求:
必須從內部鄰居(iBGP)得知該路徑。
除非路由器設定為不等價的iBGP多重路徑,否則BGP下一躍點的IGP度量必須等於最佳路徑IGP指標。
BGP 最多可在 IP 路由表中插入 n 個最近從多重路徑候選路徑接收到的路徑。n的最大值因平台和軟體版本而異。較舊的平台可支援至少6條路徑,而現代平台可支援16條、32條或更多。當停用多重路徑時,預設值為 1。
對於成本不等的負載平衡,您還可以使用 BGP 鏈結頻寬。
| 修訂 | 發佈日期 | 意見 |
|---|---|---|
6.0 |
28-Apr-2026
|
格式設定 |
5.0 |
02-Dec-2024
|
固定格式和連結。 |
4.0 |
11-Jul-2023
|
已更新標題、簡介和格式。已新增背景資訊。 |
3.0 |
22-Jun-2022
|
已更新為機器翻譯准則。 |
1.0 |
10-Dec-2001
|
初始版本 |