BGP GR
BGP GR
网络需求
FortiGate HA 集群与上下游路由器运行 BGP 协议,并开启 GR。在 FortiGate 的 HA 发生主备切换时,GR 需要确保每个路由器(包括 FortiGate 及其它路由器)在 HA 切换期间保持其路由表中的 BGP 路由(GR Helper),以避免流量中断。
重要
如果 FortiGate 的上下游为只支持 GR Helper Only(只能作为 GR Helper,不具有 GR Restarter 功能)模式的路由器,需要 FortiGate 运行 FortiOS 7.4.2 及以上版本才能正常完成 GR 过程。
在 FortiGate HA 集群中,BGP 进程相关工作仅在主设备上运行。当发生 HA 切换时,将在新选举的主机上启动一个新的 BGP 协商过程,在此过程中,新的主机需要在路由 Kernel 表中维持从原主机学习到的 BGP 路由,直至新的 BGP 邻居形成。
对于 BGP 的 GR,有以下几个计时器需要了解:
holdtime-timer(默认 180s):将 BGP 邻居标记为死亡的秒数。即在考虑与对等方的连接关闭之前,在 Keepalive、Update 或 Notification 消息之间等待的秒数。graceful-restart-time(默认 120s):邻居重新启动所需的时间,即 GR-Helper 在删除过时路由之前等待 OPEN 消息的秒数。请确保graceful-restart-time小于或等于holdtime-timer。graceful-update-delay(默认 120s):GR 完成后,路由宣告/学习的延迟时间。graceful-stalepath-time(默认 360s):在 GR-Helper 上保持 GR 邻居的过时路由的时间,即在删除之前保持过时路由的最大总时间。
网络拓扑

- FW1 与 FW2 建立 A - P 模式的 HA。
- FW1/FW2 与 FW3、FW4 分别建立 IBGP 邻居,FW3、FW4 宣告各自的网段。
- FW1/FW2 与 FW3、FW4 开启 BGP Graceful Restart,FW1/FW2 发生主备切换后,FW3、FW4 可以进入 GR Helper 模式,协助 FW1/FW2 的 GR 过程。
配置步骤
基础网络配置(略)。
FW1 与 FW2 的 HA 配置(略)。
安全策略配置(略)。
配置 FW1/FW2 的 BGP,开启 GR 功能,restart-period 设置为 600s,计时器配置均保持默认,邻居配置中开启路由反射器(RR),将两个 IBGP 邻居的路由互相反射,反射时将下一跳改为自己。
重要
虽然 GR Restarter 配置了
graceful-restart-time,但该参数只是告知邻居(GR Helper)GR 过程的最大时间。只要 GR Restarter 认为自己完成了 GR(路由收敛完成),即使时间没有达到配置的graceful-restart-time,也会向 GR Helper 发送 EoR(End-of-Rib)报文来告知邻居自身 GR 已完成,此时 GR Helper 会直接删除陈旧(Stale)路由。这在某些 ADVPN 环境下下可能存在问题:例如 Hub 的 BGP 使用 neighbor-group 模式,且 Hub 与内网路由器还有 BGP GR 关系,当 Hub 发生 HA 切换后,由于 Hub 无法主动向 Spoke 发起 BGP 协商,在 Spoke 再次与 Hub 建立 BGP 并收敛前,Hub 会认为 GR 已经完成并提前结束 GR,从而导致内网路由器无法保持 Spoke 的相关路由。
如果想让 GR Restarter 只在
graceful-restart-time到期时才向 GR Helper 发送 EoR(End-of-Rib),则需要开启如下命令:config router bgp set graceful-end-on-timer enable end
config router bgp set as 65001 set router-id 202.103.12.1 set graceful-restart enable set graceful-restart-time 120 set graceful-stalepath-time 360 set graceful-update-delay 120 config neighbor edit "202.103.12.2" set capability-graceful-restart enable set next-hop-self-rr enable set soft-reconfiguration enable set remote-as 65001 set route-reflector-client enable next edit "202.103.13.2" set capability-graceful-restart enable set next-hop-self-rr enable set soft-reconfiguration enable set remote-as 65001 set route-reflector-client enable next end end配置 FW3 的 BGP,宣告内网网络,路由器作为 GR-Helper 也需要开启 GR 功能,计时器配置均保持默认。
config router bgp set as 65001 set router-id 202.103.12.2 set graceful-restart enable config neighbor edit "202.103.12.1" set capability-graceful-restart enable set soft-reconfiguration enable set remote-as 65001 next end config network edit 1 set prefix 10.10.1.0 255.255.255.0 next end end配置 FW4 的 BGP,宣告内网网络,路由器作为 GR-Helper 也需要开启 GR 功能,计时器配置均保持默认。
config router bgp set as 65001 set router-id 202.103.13.2 set graceful-restart enable config neighbor edit "202.103.13.1" set capability-graceful-restart enable set soft-reconfiguration enable set remote-as 65001 next end config network edit 1 set prefix 10.10.2.0 255.255.255.0 next end end配置 FW1/FW2 HA 配置中的 route-ttl 为 360s(默认 10s),在此时间内,新的主机需要在路由 Kernel 表中维持从原主机学习到的 BGP 路由,直至新的 BGP 邻居形成,并完成 BGP 路由学习。
重要
重要步骤,防止 HA 切换后,新主机建立新的 BGP 邻居前,路由消失导致业务中断。
config system ha set route-ttl 360 end
结果验证
初始状态下,FW1 为主设备,FW2 为备设备。
FW1 # diagnose sys ha status HA information Statistics traffic.local = s:0 p:42869 b:39035389 traffic.total = s:0 p:42867 b:39033889 activity.ha_id_changes = 2 activity.fdb = c:0 q:0 Model=80008, Mode=2 Group=7 Debug=0 nvcluster=1, ses_pickup=0, delay=0 [Debug_Zone HA information] HA group member information: is_manage_primary=1. FGVM08TM23000175: Primary, serialno_prio=1, usr_priority=128, hostname=FW1 FGVM08TM23000176: Secondary, serialno_prio=0, usr_priority=100, hostname=FW2 [Kernel HA information] vcluster 1, state=work, primary_ip=169.254.0.2, primary_id=0 FGVM08TM23000175: Primary, ha_prio/o_ha_prio=0/0 FGVM08TM23000176: Secondary, ha_prio/o_ha_prio=1/1初始状态下查看 FW3 的 BGP 邻居状态与路由信息,邻居状态为已建立状态,BGP 路由学习正常。
FW3 # get router info bgp summary VRF 0 BGP router identifier 202.103.12.2, local AS number 65001 BGP table version is 3 1 BGP AS-PATH entries 0 BGP community entries Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 202.103.12.1 4 65001 1229 1229 2 0 0 16:55:54 1 Total number of neighbors 1 FW3 # get router info routing-table bgp Routing table for VRF=0 B 10.10.2.0/24 [200/0] via 202.103.12.1 (recursive is directly connected, port2), 00:02:15, [1/0]初始状态下查看 FW4 的 BGP 邻居状态与路由信息,邻居状态为已建立状态,BGP 路由学习正常。
FW4 # get router info bgp summary VRF 0 BGP router identifier 202.103.13.2, local AS number 65001 BGP table version is 3 1 BGP AS-PATH entries 0 BGP community entries Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 202.103.13.1 4 65001 1232 1233 2 0 0 17:01:22 1 Total number of neighbors 1 FW4 # get router info routing-table bgp Routing table for VRF=0 B 10.10.1.0/24 [200/0] via 202.103.13.1 (recursive is directly connected, port2), 00:03:00, [1/0]初始状态下查看 FW1 的 BGP 邻居状态与路由信息,邻居状态为已建立,BGP 路由学习正常。
FW1 # get router info bgp summary VRF 0 BGP router identifier 202.103.12.1, local AS number 65001 BGP table version is 1 1 BGP AS-PATH entries 0 BGP community entries Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 202.103.12.2 4 65001 1232 1241 1 0 0 17:03:12 1 202.103.13.2 4 65001 1233 1238 1 0 0 17:03:11 1 Total number of neighbors 2 FW1 # get router info routing-table bgp Routing table for VRF=0 B 10.10.1.0/24 [200/0] via 202.103.12.2 (recursive is directly connected, port2), 17:02:56, [1/0] B 10.10.2.0/24 [200/0] via 202.103.13.2 (recursive is directly connected, port3), 17:02:55, [1/0]使 FW1 和 FW2 发生 HA 主备倒换,此时 FW2 成为 HA 主设备。
FW2 # diagnose sys ha status HA information Statistics traffic.local = s:0 p:6233 b:4732229 traffic.total = s:0 p:6286 b:4735596 activity.ha_id_changes = 4 activity.fdb = c:0 q:0 Model=80008, Mode=2 Group=7 Debug=0 nvcluster=1, ses_pickup=0, delay=0 [Debug_Zone HA information] HA group member information: is_manage_primary=1. FGVM08TM23000176: Primary, serialno_prio=0, usr_priority=100, hostname=FW2 FGVM08TM23000175: Secondary, serialno_prio=1, usr_priority=128, hostname=FW1 [Kernel HA information] vcluster 1, state=work, primary_ip=169.254.0.1, primary_id=0 FGVM08TM23000176: Primary, ha_prio/o_ha_prio=0/0 FGVM08TM23000175: Secondary, ha_prio/o_ha_prio=1/1查看 FW2 的 BGP Debug 信息,FW2 成为 HA 主后,向 BGP 邻居发送 BGP OPEN 消息,其中包含 Cap GR,Restarting 时间为 120s。
FW2 # diagnose ip router bgp level info FW2 # diagnose ip router bgp all enable FW2 # diagnose debug console time enable ...... 2024-01-16 14:53:33 BGP: 202.103.12.2-Outgoing [ENCODE] Open: Ver 4 MyAS 65001 Holdtime 180 ...... 2024-01-16 14:53:33 BGP: 202.103.12.2-Outgoing [DECODE] Open Opt: Option Type 2, Option Len 8 2024-01-16 14:53:33 BGP: 202.103.12.2-Outgoing [DECODE] Open Cap: Cap Code 64, Cap Len 6 2024-01-16 14:53:33 BGP: 202.103.12.2-Outgoing [DECODE] Cap GR: Restart Flag Off, Restart Time 120 diagnose ip2024-01-16 14:53:33 BGP: 202.103.12.2-Outgoing [DECODE] Cap GR: AFI/SAFI 1/1 Fwd-state Flag 1, action: Set ...... 2024-01-16 14:53:34 2024-01-16 14:53:34 BGP: 202.103.12.2-Outgoing [GRST] GRST Init Announce:GRST Defer Announce Timer(120) Started id=20300 msg="BGP: %BGP-5-ADJCHANGE: VRF 0 neighbor 202.103.12.2 Up " ...... 2024-01-16 14:53:59 BGP: 202.103.12.2-Outgoing [FSM] Update: IPv4 Unicast End-Of-Rib Marker Received 2024-01-16 14:53:59 BGP: 202.103.12.2-Outgoing [FSM] Process End-of-RIB: Received for afi/safi: 1/1该报文格式如下图所示。

在 FW2 进入 GR 状态后,查看 FW3 的 BGP 邻居状态与 BGP 路由状态,FW3 进入 GR Helper 状态,开始与 FW2 建立新的 BGP 邻居,之前已学习到的 BGP 路由未消失,被打上 S(Stale)标记。(FW4 也是一样的状态,这里就不再赘述)
FW3 # get router info bgp summary VRF 0 BGP router identifier 202.103.12.2, local AS number 65001 BGP table version is 10 1 BGP AS-PATH entries 0 BGP community entries Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 202.103.12.1 4 65001 101 104 0 0 0 never OpenConfirm Total number of neighbors 1 FW3 # get router info bgp network VRF 0 BGP table version is 7, local router ID is 202.103.12.2 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, S Stale Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight RouteTag Path *> 10.10.1.0/24 0.0.0.0 100 32768 0 i <-/1> S>i10.10.2.0/24 202.103.12.1 0 100 0 0 i <-/1> Total number of prefixes 2 FW3 # get router info routing-table bgp Routing table for VRF=0 B 10.10.2.0/24 [200/0] via 202.103.12.1 (recursive is directly connected, port2), 00:01:06, [1/0]在 FW3 上查看 BGP 的 Debug 信息,FW3 与 FW1 的 BGP 连接断开后,进入 GR Helper 模式,GR 倒计时 120s。(FW4 也是一样的状态,这里就不再赘述)
FW3 # diagnose ip router bgp level info FW3 # diagnose ip router bgp all enable FW3 # diagnose debug console time enable 2024-01-16 15:13:53 BGP: [NETWORK] Accept Thread: Incoming conn from host 202.103.12.1 (FD=26 VRF=0) 2024-01-16 15:13:53 BGP: 202.103.12.1-Outgoing [FSM] State: Established Event: 14 ...... 2024-01-16 15:14:22 BGP: 202.103.12.1-Outgoing [RIB] Update: Received Prefix 10.10.2.0/24 path_id 0 ......等待 FW2 与 FW3 的 BGP 邻居建立完成后,FW2 的 GR 完成,FW3 退出 GR Helper 状态,期间被打上 S 标记的旧 BGP 路由没有消失,重新和 FW2 建立 BGP 邻居并学习 BGP 路由后,S 标记变为 * 标记。(FW4 也是一样的状态,这里就不再赘述)
FW3 # get router info bgp summary
VRF 0 BGP router identifier 202.103.12.2, local AS number 65001
BGP table version is 7
1 BGP AS-PATH entries
0 BGP community entries
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
202.103.12.1 4 65001 79 81 0 0 0 00:00:05 1
FW3 # get router info bgp network
VRF 0 BGP table version is 12, local router ID is 202.103.12.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight RouteTag Path
*> 10.10.1.0/24 0.0.0.0 100 32768 0 i <-/1>
*>i10.10.2.0/24 202.103.12.1 0 100 0 0 i <-/1>
Total number of prefixes 2
FW3 # get router info routing-table bgp
Routing table for VRF=0
B 10.10.2.0/24 [200/0] via 202.103.12.1 (recursive is directly connected, port2), 00:01:06, [1/0]在 FW3 上查看 BGP 的 Debug 信息,FW3 从 FW2 完成了新的 BGP 路由学习后,向 FW2 发送了 End-of-RIB 报文,报文格式如下(空的 BGP Update 报文),通知其路由已经学习完成。
2024-01-16 15:14:22 BGP: VRF 0 NSM announce: 10.10.2.0/24 2024-01-16 15:14:22 BGP: 202.103.12.1-Outgoing [FSM] Update: IPv4 Unicast End-Of-Rib Marker Received 2024-01-16 15:14:22 BGP: 202.103.12.1-Outgoing [FSM] Process End-of-RIB: Received for afi/safi: 1/1
在 FW3 上查看 BGP 邻居状态,其中包含 GR 相关信息,如邻居的 GR 时间为 120s。
FW3 # get router info bgp neighbors VRF 0 neighbor table: BGP neighbor is 202.103.12.1, remote AS 65001, local AS 65001, internal link BGP version 4, remote router ID 202.103.12.1 BGP state = Established, up for 00:04:58 Last read 00:00:02, hold time is 180, keepalive interval is 60 seconds Configured hold time is 180, keepalive interval is 60 seconds ...... For address family: IPv4 Unicast BGP table version 13, neighbor version 12 Index 1, Offset 0, Mask 0x2 AF-dependant capabilities: Graceful restart: advertised, received, negotiated ...... Connections established 13; dropped 12 Graceful-restart Status: Remote restart-time is 120 sec ......GR 期间,FW2 从 FW1 重启前同步的路由一直存在(route-ttl 360,prio = 2164260865)。
FW2 # get router info kernel | grep 10.10. tab=254 vf=0 scope=0 type=1 proto=30 prio=2164260865 0.0.0.0/0.0.0.0/0->10.10.1.0/24 pref=0.0.0.0 gwy=202.103.12.2 dev=4(port2) tab=254 vf=0 scope=0 type=1 proto=30 prio=2164260865 0.0.0.0/0.0.0.0/0->10.10.2.0/24 pref=0.0.0.0 gwy=202.103.13.2 dev=5(port3)GR 结束后,学到了新的 BGP 路由(prio = 1)。
FW2 # get router info kernel | grep 10.10. tab=254 vf=0 scope=0 type=1 proto=11 prio=1 0.0.0.0/0.0.0.0/0->10.10.1.0/24 pref=0.0.0.0 gwy=202.103.12.2 dev=4(port2) tab=254 vf=0 scope=0 type=1 proto=30 prio=2164260865 0.0.0.0/0.0.0.0/0->10.10.1.0/24 pref=0.0.0.0 gwy=202.103.12.2 dev=4(port2) tab=254 vf=0 scope=0 type=1 proto=11 prio=1 0.0.0.0/0.0.0.0/0->10.10.2.0/24 pref=0.0.0.0 gwy=202.103.13.2 dev=5(port3) tab=254 vf=0 scope=0 type=1 proto=30 prio=2164260865 0.0.0.0/0.0.0.0/0->10.10.2.0/24 pref=0.0.0.0 gwy=202.103.13.2 dev=5(port3)整个 HA 切换引起的 GR 期间,所有设备路由转发表未发生实际变化,流量不会中断。
GR 与 BFD 的使用关系
重要
BGP GR 或 OSPF GR 不建议与 BFD 同时使用。
GR 用于 FortiGate 通知邻居自己的路由进程将重启,并且邻居从 FortiGate 学到的路由应在重启期间保留。但 BFD 检测到故障时会将动态路由邻居重置。这种操作上的差异使得在 GR 的同时使用 BFD 会导致功能上的冲突,可能导致 GR 期间流量中断。
业界通用的做法是在使用 GR 时关闭 BFD。例如在 FortiGate 和 GCP(Google 云平台)之间配置动态路由 + GR + BFD 时:
- GCP 将关闭 BFD 并发送 AdminDown(BFD 事件)到 FortiGate(参考 https://cloud.google.com/network-connectivity/docs/router/concepts/bfd#graceful-restart-and-bfd )。
- FortiGate 不会因为 AdminDown 类型的 BFD 通知重置 BGP 连接(参考 https://handbook.fortinet.com.cn/routing/bfd/bfd_and_bgp.html#注意事项 )。