抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >


BFD 协议原理与配置

BFD

BFD: 双向转发检测,基于 UDP 工作,端口号 3784

BFD 优点

BFD 提供了一个通用的,标准化的,介质无关的,协议无关的快速故障检测机制,有以下两大优点:

  • 对相邻转发引擎之间的通道提供轻负荷,快速故障检测.
  • 用单一的机制对任何介质,任何协议层进行实时检测.

BFD 的故障检测机制

BFD 依赖会话进行故障检测,在两个系统之间建立 BFD 会话,并沿他们的路径快速的发送 BFD 控制报文,如果一方在特定的时间内没有收到对方的 BFD 报文,那么 BFD 认为会话 DOWN, 此时联动的其他协议或接口状态会发生改变.

BFD 会话建立方式

(主要区别在于 LD 和 RD 的配置方式)

静态建立 BFD 会话:通过命令行手工配置 BFD 会话参数,包括 LD 和 RD 等,然后手工下发 BFD 会话建立请求

动态建立 BFD 会话:

1. 动态分配本地标识符:当应用程序触发动态创建 BFD 会话时,系统分配属于动态会话标识符的值作为本地标识符。向对端发送 RD 为 0 的 BFD 报文.

2. 自学习远端标识符:当 BFD 会话的一端收到 RD 为 0 的 BFD 控制报文时,判断该报文是否与本地 BFD 会话匹配,如果匹配,则学习接收到的 BFD 报文中的 LD, 获取远端标识符.

BFD 会话建立过程

BFD 会话有四种状态 Down,Init,UP,Admindown. 会话状态通过 BFD 的 State 字段传递,系统根据自己本地的会话状态和接收到对端的 BFD 报文来驱动状态的变化,BFD 状态机的建立采用三次握手机制,以确保两端都能知道状态的变化.

1.RA 和 RB 各自启动 BFD 的状态机,初始状态是 Down, 发送状态为 Down 报文.

2.RB 收到状态为 Down 的 BFD 报文,状态切换至 Init, 并发送状态为 Init 的报文.

3.RB 本地 BFD 状态变为 Init 后,不再处理接收到的 Down 报文.

4.RB 收到状态为 Init 的 BFD 报文后,本地切换到 UP 状态.

5.RA 的 BFD 状态变化和 RB 一样.

BFD 状态

Down 状态说明会话 down, 一个会话维持在 down 状态直到收到对端的报文并且报文中 STA 字段不是 UP

Init 状态说明与远端正在通信,并期望进入 UP 状态,当远端还没有回应一个 Init 状态的会话会维持 Init 状态,直到接收到对端的 Init 包和 UP 包就会跳转到 UP 状态,否则,等到检测时间超时后,会跳转到 Down 状态.

UP 状态说明 BFD 会话建立成功,并且正在确认链路的连通性,会话会一直保持在 up 状态直到链路故障或管理 Down 操作.

如果收到远端的 Down 报文或者检测时间超时会话会从 up 跳转到 Down.

Admindown 意味着会话被管理操作 down, 导致远端系统会话进入到 down 状态,并一直保持 down 状态直到本端退出 Admindown.

BFD 检测模式

1. 异步模式:本端按一定周期发送 BFD 控制报文,检测位置为远端,远端检测本端是否周期性的发送 BFD 控制报文.

2. 查询模式:本端自身发送的 BFD 控制报文是否得到了回应.

BFD 检测时间

本地 BFD 报文的实际发送间隔 = MAX (本地配置的发送时间间隔,对端配置的接收时间间隔)

本地 BFD 报文的实际接收间隔 = MAX (本地配置的接收时间间隔,对端配置的发送时间间隔)

超时时间:

1. 异步模式:对端超时倍数 * 本端的接收间隔

2. 查询模式:本端超时倍数 * 本端的接收间隔

静态路由与 BFD 联动

单跳检测

[R1]ip route-static 4.4.4.4 32 12.1.1.2
[R1]ip route-static 4.4.4.4 32 13.1.1.3 preference 70
[R1]ip route-static 24.1.1.0 24 12.1.1.2
[R1]ip route-static 34.1.1.0 24 13.1.1.3
[R2]ip route-static 4.4.4.4 32 24.1.1.4
[R3]ip route-static 4.4.4.4 32 34.1.1.4
[R4]ip route-static 12.1.1.1 24 24.1.1.2
[R4]ip route-static 13.1.1.1 24 34.1.1.3
----
R1:
bfd // 开启BFD功能
bfd 12 bind peer-ip 12.1.1.2 interface GigabitEthernet0/0/0
discriminator local 10
discriminator remote 20
commit
----
R2:
bfd // 开启BFD功能
bfd 21 bind peer-ip 123.1.1.1 interface GigabitEthernet0/0/0
discriminator local 20
discriminator remote 10
commit
----
R1配置静态路由与BFD联动
[R1]ip route-static 4.4.4.4 255.255.255.255 12.1.1.2 track bfd-session 12
---
[R1]bfd // 开启BFD功能
[R1-bfd]q
[R1]bfd ?
STRING<1-15> BFD configuration name <1-15>
<cr> Please press ENTER to execute command
[R1]bfd 12 ?
bind Bind type
<cr> Please press ENTER to execute command
[R1]bfd 12 bind peer-ip 12.1.1.2 ?
interface Bind the outgoing-interface(only for single hop)
source-ip Set source IP address
vpn-instance Vpn instance name
<cr> Please press ENTER to execute command
[R1]bfd 12 bind peer-ip 12.1.1.2 interface ?
GigabitEthernet GigabitEthernet interface
[R1]bfd 12 bind peer-ip 12.1.1.2 interface GigabitEthernet 0/0/0
[R1-bfd-session-12]
[R1-bfd-session-12]dis th
[V200R003C00]
#
bfd 12 bind peer-ip 12.1.1.2 interface GigabitEthernet0/0/0
#
return
[R1-bfd-session-12]discriminator local 10
[R1-bfd-session-12]discriminator remote 20
[R1-bfd-session-12]commit
[R1-bfd-session-12]dis th
[V200R003C00]
#
bfd 12 bind peer-ip 12.1.1.2 interface GigabitEthernet0/0/0
discriminator local 10
discriminator remote 20
commit
#
return
[R1-bfd-session-12]
---
[R2]undo bfd
Warning: All BFD capability on the device will be deleted. Continue? [Y/N]y
[R2]
[R1]undo bfd 12
---

多跳检测

[R1]ip route-static 4.4.4.4 32 12.1.1.2
[R1]ip route-static 4.4.4.4 32 13.1.1.3 preference 70
[R1]ip route-static 24.1.1.0 24 12.1.1.2
[R1]ip route-static 34.1.1.0 24 13.1.1.3
[R2]ip route-static 1.1.1.1 32 12.1.1.1
[R2]ip route-static 4.4.4.4 32 24.1.1.4
[R3]ip route-static 1.1.1.1 32 13.1.1.1
[R3]ip route-static 4.4.4.4 32 34.1.1.4
[R4]ip route-static 12.1.1.1 24 24.1.1.2
[R4]ip route-static 13.1.1.1 24 34.1.1.3
[R4]ip route-static 1.1.1.1 24 34.1.1.3
[R4]ip route-static 1.1.1.1 24 24.1.1.2

[R1-bfd-session-14]dis th
[V200R003C00]
#
bfd 14 bind peer-ip 24.1.1.4 // 创建BFD会话绑定x.x.x.x
discriminator local 10 // 本端标识符
discriminator remote 40 //远端标识符
commit // 启用
#
[R4-bfd-session-41]dis th
[V200R003C00]
#
bfd 41 bind peer-ip 12.1.1.1
discriminator local 40
discriminator remote 10
commit
#
return
[R1]display bfd session all
--------------------------------------------------------------------------------
Local Remote PeerIpAddr State Type InterfaceName
--------------------------------------------------------------------------------

10 40 24.1.1.4 Up S_IP_PEER -
--------------------------------------------------------------------------------
Total UP/DOWN Session Number : 1/0

[R1]display bfd session all
--------------------------------------------------------------------------------
Local Remote PeerIpAddr State Type InterfaceName
--------------------------------------------------------------------------------

10 40 24.1.1.4 Down S_IP_PEER -
--------------------------------------------------------------------------------
Total UP/DOWN Session Number : 0/1



[R1]ip route-static 4.4.4.4 32 12.1.1.2 track bfd-session 14

[R1]ping -c 500 -a 1.1.1.1 4.4.4.4
PING 4.4.4.4: 56 data bytes, press CTRL_C to break
Reply from 4.4.4.4: bytes=56 Sequence=1 ttl=254 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=2 ttl=254 time=40 ms
Reply from 4.4.4.4: bytes=56 Sequence=3 ttl=254 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=4 ttl=254 time=20 ms
Reply from 4.4.4.4: bytes=56 Sequence=5 ttl=254 time=40 ms
Reply from 4.4.4.4: bytes=56 Sequence=6 ttl=254 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=7 ttl=254 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=8 ttl=254 time=50 ms
Reply from 4.4.4.4: bytes=56 Sequence=9 ttl=254 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=10 ttl=254 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=11 ttl=254 time=40 ms
Reply from 4.4.4.4: bytes=56 Sequence=12 ttl=254 time=40 ms
Reply from 4.4.4.4: bytes=56 Sequence=13 ttl=254 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=14 ttl=254 time=40 ms
Reply from 4.4.4.4: bytes=56 Sequence=15 ttl=254 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=16 ttl=254 time=30 ms
Request time out
Request time out
Jan 24 2024 15:46:13-08:00 R1 %%01BFD/4/STACHG_TODWN(l)[1]:BFD session changed t
o Down. (SlotNumber=0, Discriminator=167772160, Diagnostic=DetectDown, Applicati
ons=None, ProcessPST=False, BindInterfaceName=None, InterfacePhysicalState=None,
InterfaceProtocolState=None)
Request time out
Reply from 4.4.4.4: bytes=56 Sequence=20 ttl=254 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=21 ttl=254 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=22 ttl=254 time=40 ms
Reply from 4.4.4.4: bytes=56 Sequence=23 ttl=254 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=24 ttl=254 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=25 ttl=254 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=26 ttl=254 time=40 ms
Reply from 4.4.4.4: bytes=56 Sequence=27 ttl=254 time=30 ms
Reply from 4.4.4.4: bytes=56 Sequence=28 ttl=254 time=40 ms

OSPF 与 BFD 联动

# R1
interface LoopBack0
ip address 1.1.1.1 255.255.255.255
#
ospf 1 router-id 1.1.1.1
bfd all-interfaces enable
area 0.0.0.0
network 1.1.1.1 0.0.0.0
network 12.1.1.1 0.0.0.0
network 13.1.1.1 0.0.0.0

# R2
interface LoopBack0
ip address 2.2.2.2 255.255.255.255
#
ospf 1 router-id 2.2.2.2
bfd all-interfaces enable
area 0.0.0.0
network 2.2.2.2 0.0.0.0
network 12.1.1.2 0.0.0.0
network 24.1.1.2 0.0.0.0
#

# R3
interface LoopBack0
ip address 3.3.3.3 255.255.255.255
#
ospf 1 router-id 3.3.3.3
bfd all-interfaces enable
area 0.0.0.0
network 3.3.3.3 0.0.0.0
network 13.1.1.3 0.0.0.0
network 34.1.1.3 0.0.0.0
#


# R4
interface LoopBack0
ip address 4.4.4.4 255.255.255.255
#
ospf 1 router-id 4.4.4.4
bfd all-interfaces enable
area 0.0.0.0
network 4.4.4.4 0.0.0.0
network 24.1.1.4 0.0.0.0
network 34.1.1.4 0.0.0.0
#
[R1]dis bfd session all
--------------------------------------------------------------------------------
Local Remote PeerIpAddr State Type InterfaceName
--------------------------------------------------------------------------------

8192 8192 12.1.1.2 Up D_IP_IF GigabitEthernet0/0/0
8195 8195 13.1.1.3 Up D_IP_IF GigabitEthernet0/0/1
--------------------------------------------------------------------------------
Total UP/DOWN Session Number : 2/0



推荐阅读
VRF 虚拟路由转发 VRF 虚拟路由转发 DHCP DHCP OSPF路由计算 OSPF路由计算 BGP BGP IP路由基础 IP路由基础 数据转发过程 数据转发过程

留言区

Are You A Robot?