本檔案將說明bgp deterministic-med命令,以及它如何影響根據多出口鑑別器(MED)進行的路徑選取。
思科建議您瞭解以下主題:
本文件所述內容不限於特定軟體和硬體版本。
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
如需思科檔案慣例的詳細資訊,請參閱思科技術提示慣例。
MED是一個可選的、不可傳遞的BGP屬性,可為外部鄰居提供有關通向具有多個入口點的自治系統(AS)的首選路徑的提示。MED也稱為路由的外部度量,並且較低的MED值優先於較高值。預設情況下,BGP只會比較從同一個相鄰AS接收的路徑中的MED值。
附註:預設情況下,BGP只會比較從相同相鄰AS接收的路徑的MED值,除非已設定bgp always-compare-med。請參閱bgp deterministic-med命令與bgp always-compare-med命令之間的區別以瞭解其他資訊。
網路拓撲
在此案例中,AS 65502是具有AS 65501的ISP的使用者。R4連線到ISP側的兩台不同的路由器以實現冗餘,並將兩個網路(10.4.0.0/16和10.5.0.0/16)通告給ISP。本節顯示一些相關配置。
| R4 |
|---|
! hostname r4 ! ip cef ! ! interface Loopback10 ip address 10.4.0.1 255.255.0.0 ! interface Loopback11 ip address 10.5.0.1 255.255.0.0 ! interface Serial0/0 ip address 192.168.20.4 255.255.255.0 ! interface Serial1/0 ip address 192.168.30.4 255.255.255.0 ! router bgp 65502 no synchronization bgp log-neighbor-changes network 10.4.0.0 mask 255.255.0.0 network 10.5.0.0 mask 255.255.0.0 neighbor 192.168.20.2 remote-as 65501 neighbor 192.168.30.3 remote-as 65501 no auto-summary ! ip classless ! ! line con 0 exec-timeout 0 0 line aux 0 line vty 0 4 exec-timeout 0 0 login ! ! end |
| R2 |
|---|
! hostname r2 ! ip cef ! ! interface Loopback0 ip address 10.2.2.2 255.255.255.255 ! interface Ethernet0/0 ip address 172.16.0.2 255.255.255.0 ! interface Serial1/0 ip address 192.168.1.2 255.255.255.0 serial restart-delay 0 ! interface Serial2/0 ip address 192.168.20.2 255.255.255.0 serial restart-delay 0 ! router ospf 1 log-adjacency-changes redistribute connected passive-interface Serial2/0 network 10.2.2.2 0.0.0.0 area 0 network 172.16.0.2 0.0.0.0 area 0 network 192.168.1.2 0.0.0.0 area 0 network 192.168.20.2 0.0.0.0 area 0 ! router bgp 65501 no synchronization bgp log-neighbor-changes neighbor 10.1.1.1 remote-as 65501 neighbor 10.1.1.1 update-source Loopback0 neighbor 10.3.3.3 remote-as 65501 neighbor 10.3.3.3 update-source Loopback0 neighbor 192.168.20.4 remote-as 65502 no auto-summary ! ip classless ! ! line con 0 exec-timeout 0 0 transport preferred all transport output all line aux 0 transport preferred all transport output all line vty 0 4 exec-timeout 0 0 login transport preferred all transport input all transport output all ! end |
相關的R1和R3配置使用與R2相同的設計。R1、R2和R3通過環回介面具有iBGP可達性,而IGP為BGP下一跳提供了可達性。R3與R4有eBGP會話,與R1和R2有iBGP會話。
R1有一個與R2對等的iBGP,以及一個與R3對等的iBGP。檢視R4通告的兩個網路的R1、R2和R3 BGP表顯示內容:
r2#show ip bgp 10.4.0.1
BGP routing table entry for 10.4.0.0/16, version 7
Paths: (2 available, best #1, table Default-IP-Routing-Table)
Advertised to non peer-group peers:
10.1.1.1 10.3.3.3
65502
192.168.20.4 from 192.168.20.4 (10.4.4.4)
Origin IGP, metric 0, localpref 100, valid, external, best
65502
192.168.30.4 (metric 74) from 10.3.3.3 (10.3.3.3)
Origin IGP, metric 0, localpref 100, valid, internal
r2#show ip bgp 10.5.0.1
BGP routing table entry for 10.5.0.0/16, version 6
Paths: (2 available, best #2, table Default-IP-Routing-Table)
Advertised to non peer-group peers:
10.1.1.1 10.3.3.3
65502
192.168.30.4 (metric 74) from 10.3.3.3 (10.3.3.3)
Origin IGP, metric 0, localpref 100, valid, internal
65502
192.168.20.4 from 192.168.20.4 (10.4.4.4)
Origin IGP, metric 0, localpref 100, valid, external, best
r3#show ip bgp 10.4.0.1
BGP routing table entry for 10.4.0.0/16, version 8
Paths: (2 available, best #2, table Default-IP-Routing-Table)
Advertised to non peer-group peers:
10.1.1.1 10.2.2.2
65502
192.168.20.4 (metric 74) from 10.2.2.2 (10.2.2.2)
Origin IGP, metric 0, localpref 100, valid, internal
65502
192.168.30.4 from 192.168.30.4 (10.4.4.4)
Origin IGP, metric 0, localpref 100, valid, external, best
r3#show ip bgp 10.5.0.1
BGP routing table entry for 10.5.0.0/16, version 10
Paths: (2 available, best #1, table Default-IP-Routing-Table)
Advertised to non peer-group peers:
10.1.1.1 10.2.2.2
65502
192.168.30.4 from 192.168.30.4 (10.4.4.4)
Origin IGP, metric 0, localpref 100, valid, external, best
65502
192.168.20.4 (metric 74) from 10.2.2.2 (10.2.2.2)
Origin IGP, metric 0, localpref 100, valid, internal
r1#show ip bgp 10.4.0.1
BGP routing table entry for 10.4.0.0/16, version 11
Paths: (2 available, best #1, table Default-IP-Routing-Table)
Not advertised to any peer
65502
192.168.20.4 (metric 128) from 10.2.2.2 (10.2.2.2)
Origin IGP, metric 0, localpref 100, valid, internal, best
65502
192.168.30.4 (metric 128) from 10.3.3.3 (10.3.3.3)
Origin IGP, metric 0, localpref 100, valid, internal
r1#show ip bgp 10.5.0.1
BGP routing table entry for 10.5.0.0/16, version 10
Paths: (2 available, best #2, table Default-IP-Routing-Table)
Not advertised to any peer
65502
192.168.30.4 (metric 128) from 10.3.3.3 (10.3.3.3)
Origin IGP, metric 0, localpref 100, valid, internal
65502
192.168.20.4 (metric 128) from 10.2.2.2 (10.2.2.2)
Origin IGP, metric 0, localpref 100, valid, internal, best
R2和R3都從R4中挑選最佳路徑作為外部路由,根據BGP最佳路徑選擇演算法可預期該最佳路徑。如需詳細資訊,請參閱BGP最佳路徑選取演演算法。
同樣地,R1選擇R2訪問這兩個網路,因為較早的BGP最佳路徑屬性相同,而最小BGP路由器ID用作連線斷開器。R2的路由器ID為10.2.2.2,R3的路由器ID為10.3.3.3。因為R2的路由器ID為10.2.2.2,而R3的路由器ID為10.3.3.3,因此選擇R2。在此基本配置中,預設情況下,發往AS 65502中兩個網路的所有流量從R1通過R2,然後通過R4傳輸。現在,假設R4要對其從AS 65501收到的流量進行負載均衡。要在不修改任何R4 ISP的情況下進行負載均衡,可以將R4配置為利用MED將一個網路的流量強制下行,將另一個網路的流量強制下行。
附註:請注意,所描述的MED配置示例提供按字首的流量工程,而不是真正的等價負載均衡。
以下是應用所需組態後R4的組態:
| R4 |
|---|
! hostname r4 ! ip cef ! ! ! interface Loopback10 ip address 10.4.0.1 255.255.0.0 ! interface Loopback11 ip address 10.5.0.1 255.255.0.0 ! interface Serial0/0 ip address 192.168.20.4 255.255.255.0 ! interface Serial1/0 ip address 192.168.30.4 255.255.255.0 ! router bgp 65502 no synchronization bgp log-neighbor-changes network 10.4.0.0 mask 255.255.0.0 network 10.5.0.0 mask 255.255.0.0 neighbor 192.168.20.2 remote-as 65501 neighbor 192.168.20.2 route-map setMED-R2 out neighbor 192.168.30.3 remote-as 65501 neighbor 192.168.30.3 route-map setMED-R3 out no auto-summary ! ip classless no ip http server ! ! access-list 1 permit 10.4.0.0 0.0.255.255 access-list 2 permit 10.5.0.0 0.0.255.255 ! route-map setMED-R3 permit 10 match ip address 1 set metric 200 ! route-map setMED-R3 permit 20 match ip address 2 set metric 100 !--- The route-map setMED-R3 is applying a MED of 200 to the 10.4.0.0/16 |
注意:在本示例中,僅通告10.4.0.0/16和10.5.0.0/16。如果向同一鄰居通告其他字首,請將其新增到相應的訪問清單或路由對映序列。如果必須通告不匹配的字首而不由出站路由對映過濾,則新增最終的允許序列。
應用MED後,R2選擇R2到R4的路徑/鏈路作為10.4.0.0/16的最佳路徑/鏈路,R3選擇R3到R4的路徑/鏈路作為10.5.0.0/16的最佳路徑/鏈路。在所示的收斂狀態中,R1收到每個字首的符合條件的最佳iBGP通告,並使用R2為10.4.0.0/16,使用R3為10.5.0.0/16:
r1#show ip bgp 10.4.0.1
BGP routing table entry for 10.4.0.0/16, version 14
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Flag: 0x800
Not advertised to any peer
65502
192.168.20.4 (metric 128) from 10.2.2.2 (10.2.2.2)
Origin IGP, metric 100, localpref 100, valid, internal, best
r1#show ip bgp 10.5.0.1
BGP routing table entry for 10.5.0.0/16, version 13
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Flag: 0x800
Not advertised to any peer
65502
192.168.30.4 (metric 128) from 10.3.3.3 (10.3.3.3)
Origin IGP, metric 100, localpref 100, valid, internal, best
有關R2的顯示資訊,請參見下一個示例:
r2#show ip bgp 10.4.0.1
BGP routing table entry for 10.4.0.0/16, version 10
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Advertised to non peer-group peers:
10.1.1.1 10.3.3.3
65502
192.168.20.4 from 192.168.20.4 (10.4.4.4)
Origin IGP, metric 100, localpref 100, valid, external, best
r2#show ip bgp 10.5.0.1
BGP routing table entry for 10.5.0.0/16, version 11
Paths: (2 available, best #1, table Default-IP-Routing-Table)
Advertised to non peer-group peers:
192.168.20.4
65502
192.168.30.4 (metric 74) from 10.3.3.3 (10.3.3.3)
Origin IGP, metric 100, localpref 100, valid, internal, best
65502
192.168.20.4 from 192.168.20.4 (10.4.4.4)
Origin IGP, metric 200, localpref 100, valid, external
R2為10.4.0.0/16顯示了一個路徑,因為R3在R3選擇通過R2的iBGP獲知的路徑作為最佳路徑後,不再通告其R4獲知的路徑。R3在注意到R3使用R2訪問10.4.0.0/164.0.0/16後,撤銷該地址的更新(傳送BGP路由撤回,該更新包含無法到達的度量)。標準iBGP通告規則阻止R3將獲取的iBGP路徑通告回本拓撲中的另一個iBGP對等體:
r3#show ip bgp 10.4.0.0
BGP routing table entry for 10.4.0.0/16, version 20
Paths: (2 available, best #1, table Default-IP-Routing-Table)
Advertised to non peer-group peers:
192.168.30.4
65502
192.168.20.4 (metric 74) from 10.2.2.2 (10.2.2.2)
Origin IGP, metric 100, localpref 100, valid, internal, best
65502
192.168.30.4 from 192.168.30.4 (10.4.4.4)
Origin IGP, metric 200, localpref 100, valid, external
這樣R2就可以節省一些記憶體,因為它不必儲存這些無用的資訊。如果R2和R4之間的BGP會話失敗,R2會向R3傳送針對10.4.0.0/16的不可達更新。此更新會觸發R3通過R4向R2傳送針對10.4.0.0/16的R3路由的更新。R2可以開始通過R3進行路由。
要啟用確定性MED比較,請在BGP路由器配置模式下配置bgp deterministic-med 命令。啟用後,bgp deterministic-med 將通過在同一AS對路徑進行分組之後從基於MED的最佳路徑決策中刪除臨時相關性。這可確保從同一個自治系統(AS)接收的所有路由之間執行準確的MED比較。
如果停用bgp deterministic-med,則接收的路由順序可能會影響基於MED的最佳路徑決策。當從具有完全相同路徑長度但不同MED的多個AS或聯盟子AS收到相同路由時,可能會發生這種情況。
例如,考慮下一條路由:
| 條目 | AS路徑 | MED | 本地優先使用程度 | AS路徑長度 | 原始來源 |
|---|---|---|---|---|---|
| entry1 |
AS 65001 |
100 |
100 |
1 |
IGP |
| entry2 |
AS 65002 |
50 |
100 |
1 |
IGP |
| entry3 |
AS 65001 |
20 |
100 |
1 |
IGP |
到達訂單1示例
收到的BGP路由的順序為(entry1是BGP表中最舊的條目,entry3是最新條目):
最初,只有一條路由,因此entry1成為最佳路徑。將來自AS65002的entry2與來自AS65001的entry1進行比較時,由於路由來自不同的相鄰AS,因此忽略MED;由於所有剩餘屬性都相等,因此路由器會保留目前的最佳路徑entry1。
將來自AS65001且MED 20的entry3與來自AS65001且MED 100的entry1進行比較時,會評估MED,因為兩條路由來自同一個相鄰AS。由於20小於100,條目3成為最終最佳路徑。
到達訂單2示例
現在,假設相同的路由以不同的順序到達:
最初,entry2被選為最佳路徑。將來自AS65001的entry3與來自AS65002的entry2進行比較時,不會評估MED,因為路由來自不同的相鄰AS;由於所有剩餘屬性都相等,因此路由器會保留目前的最佳路徑entry2。
將來自AS1的entry65001與來自AS2的entry2進行比較時65002再次忽略MED,因為路由來自不同的相鄰AS。因此,路由器會保留entry2作為最終的最佳路徑。
禁用MED後,路由到達順序會影響比較序列。請注意,路由器收到的路由與三條路由完全相同,但由於路由到達順序不同,因此它選擇了不同的最佳路徑。這是bgp deterministic-med旨在消除的時間相關性。
附註:有關BGP路徑選取標準的詳細資訊,請參閱BGP最佳路徑選取演演算法。
啟用MED後,路由器首先通過相鄰AS對路由進行分組,然後再做出任何基於MED的決策。此時,來自相同AS的路由將分組到一起,並比較每個組的最佳條目。在給定的示例中,存在兩個AS 65001和AS 65002。
| 群組 | AS路徑 | 條目 | 所選路由 | 原因 |
|---|---|---|---|---|
| 組1 |
AS 65001 |
entry1(MED 100)、entry3(MED 20) |
entry3 |
較低MED(20 < 100) |
| 組2 |
AS 65002 |
entry2(MED 50) |
entry2 |
唯一候選人 |
在組1中,最佳路徑是entry3,因為MED較低(在此決策中使用MED,因為路徑來自同一AS)。 在組2中,只有一個條目(條目2)。 然後,通過比較各組優勝者確定最佳路徑,預設情況下不在此比較中使用MED,因為各組的優勝者來自不同的AS。
此時,不再考慮MED,因為其餘路由來自不同的相鄰AS。BGP最佳路徑演演算法會繼續進行後續屬性(例如eBGP與iBGP的比較、到下一躍點的IGP指標、最早路徑、路由器ID等,取決於不同的屬性)。
主要優點是此過程與接收的路由無關。路由器是否按以下方式獲取路由:
因此,到達訂單產生相同的結果,因為決策是基於路由屬性而不是接收更新的訂單。
附註:如果在比較entry3(第一組的獲勝者)和entry 2(第二組的獲勝者)時也啟用了bgp always-compare-med;由於該MED值較低,第3項獲勝。
附註:啟用bgp deterministic-med命令可確保當選擇由同一AS中的不同對等體通告的路由時,對MED變數進行比較。啟用bgp always-compare-med命令可確保比較來自不同AS中鄰居的路徑的MED。
此範例假設所有高優先順序的BGP屬性(例如Weight、Local Preference、AS Path length、Origin等)都相同。其目的是隔離MED的影響,並解釋為什麼禁用bgp deterministic-med可以確保最佳路徑決策取決於路由到達順序。
思科建議您在所有新網路部署中啟用bgp always-compare-med。此外,如果啟用bgp always-compare-med,則BGP MED決策始終是確定的。
有關bgp deterministic-med和bgp always-compare-med命令的詳細資訊,請參閱bgp deterministic-med命令與bgp always-compare-med命令之間的區別。
| 修訂 | 發佈日期 | 意見 |
|---|---|---|
3.0 |
30-Jul-2026
|
已更新標題、簡介、拼寫、語法、插入橫線以分隔各節/可讀性。 |
2.0 |
26-Jan-2024
|
更新的SEO和格式。 |
1.0 |
10-Dec-2001
|
初始版本 |