BFD
双向转发检测 (BFD) 是一种用于检测网络路径故障的低延迟协议,独立于路由协议运行。它使用带有可配置端口的 UDP 封装,支持多跳会话,但目前缺少 echo 模式和认证。配置涉及在 RouterOS CLI 中指定接口、地址和 VRF。
BFD
Bidirectional Forwarding Detection(BFD,双向转发检测)是一种低开销、短时长的协议,用于检测两个转发引擎之间双向路径上的故障。这包括物理接口、子接口、数据链路,以及尽可能包括转发引擎本身,所有这些都具有非常低的延迟。它独立于介质、数据协议和路由协议运行。
BFD 是一种 hello 协议,用于检查双向邻居可达性。它提供亚秒级的链路故障检测,并且不像协议 hello 定时器那样特定于任何路由协议。
Control 数据封装在 UDP 帧中,目的端口为 3784;端口 4784 用于多跳路径。源端口范围为 49152 – 65535。
Echo 封装在 UDP 帧中,目的端口为 3785。
标准与技术:
- RFC 5880 Bidirectional Forwarding Detection (BFD)
- RFC 5881 BFD for IPv4 and IPv6
- RFC 5882 Generic Application of BFD
- RFC 5883 Bidirectional Forwarding Detection (BFD) for Multihop Paths
尚不支持的功能
- Echo 模式。
- 为 ip route 网关启用 BFD。
- 认证。
配置
允许或禁止 BFD 会话可以在 /routing/bfd/configuration 菜单中完成。例如:
/routing bfd configuration
add interfaces=sfp12 forbid-bfd=yes
add interfaces=static
配置条目对顺序敏感,这意味着在上面的示例中,我们明确禁止在 "sfp12" 接口上的 BFD 会话(使用 forbid-bfd),并允许在属于 "static" 接口列表的其余接口上使用。
为了能够过滤多跳会话,可以使用 addresses 或 address-list 属性来匹配目的地,以及适当的 vrf(如果会话不在 "main" VRF 中运行)。
/ip firewall address-list
add address=10.155.255.183 list=bgp_allow_bfd
add address=10.155.255.217 list=bgp_allow_bfd
/routing bfd configuration
add addresses=111.111.0.0/16 vrf=vrf1
add address-list=bgp_allow_bfd
任何未在配置中明确列出的内容默认被禁止。
与 BGP 配合使用 BFD
要为 BGP 会话启用 BFD,请在 /routing/bgp/connection 菜单中的所需条目上设置 use-bfd。
当关联的 BFD 会话断开时,BGP 会话输出会显示出来:
[admin@dr_02_BGP_MUM] /routing/bgp/session> print
Flags: E - established
0 E ;;; BFD session down
name="ovpn_test1-1"
remote.address=111.111.11.11@vrf1 .as=65530 .id=10.155.101.217
.capabilities=mp,rr,as4 .hold-time=infinity .messages=40717
.bytes=3436281 .eor=""
local.address=111.111.11.12@vrf1 .as=555 .id=111.111.11.12
.capabilities=mp,rr,gr,as4 .messages=1 .bytes=19 .eor=""
output.procid=20
input.procid=20 .filter=bgp-in ebgp
hold-time=infinity use-bfd=yes uptime=3s210ms
last-started=2023-05-19 09:54:04 prefix-count=3853
与 OSPF 配合使用 BFD
要为 OSPF 邻居启用 BFD,请在 /routing/ospf/interface-template 菜单中的所需条目上设置 use-bfd。
会话状态
在 /routing/bfd/session 菜单中查看当前会话的状态:
[admin@dr_02_BGP_MUM] /routing/bfd/session> print
Flags: U - up, I - inactive
0 I ;;; BFD forbidden for destination address
multihop=yes remote-address=10.155.101.183 local-address="" desired-tx-interval=0ms required-min-rx=0ms
multiplier=0
1 multihop=no remote-address=111.111.11.11%ovpn-out1@vrf1 local-address=111.111.11.12@vrf1 state=down
state-changes=0 desired-tx-interval=200ms required-min-rx=200ms remote-min-rx=1us multiplier=5
packets-rx=0 packets-tx=7674
BFD 选择本地 tx 间隔和远程最小 rx 间隔中较大的一个作为期望的发送间隔。如果会话未建立,期望的最小 tx 间隔默认为 1 秒。