本文档介绍边界网关协议 (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) 路径视为有效路径。最初,BGP同步在Cisco IOS®软件中默认启用。如果从开放最短路径优先(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 路径。
如果选择了最佳路径,则转到步骤 9(多路径)。
首选具有最低 IGP 度量且指向 BGP 下一跳的路径。
无论是否已选择了最佳路径,均继续。
确定 BGP 多路径的路由表中是否需要安装多个路径。
如果尚未选择最佳路径,则继续。
当两条路径都是外部路径时,首选先收到的路径(最旧的那个)。
此步骤可最大程度地减小路由抖动,这是因为即使根据下一个决定条件(步骤 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 连接中使用的远程对等方。
在本示例中,有9条路径可用于网络10.30.116.0/23。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 多路径允许安装到同一目的地的多个 BGP 路径的 IP 路由表中。这些路径与最佳路径一起安装到表中,以实现负载共享。BGP 多路径不影响最佳路径选择。例如,路由器仍然根据算法指定其中一个路径为最佳路径,并将此最佳路径通告给邻居。
下面是 BGP 多路径功能:
eBGP多路径 — 最大路径n
iBGP多路径- maximum-paths ibgp n
eiBGP多路径- maximum-paths eibgp
若要成为多路径候选对象,同一目的地的路径需要使下列这些特性等同于最佳路径特性:
权重
本地首选
AS-PATH 长度
原点
中文
下列项之一:
相邻 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
|
初始版本 |