ESNP LAB 笔记:配置静态BFD检测MPLS LDP LSP
一、BFD 简介
1.1 定义
BFD(Bidirectional Forwarding Detection,双向转发检测)是一种通用、标准化、介质无关且协议无关的快速故障检测机制。与路由协议不同,BFD 本身并不负责邻居发现,也不参与业务流量的重路由,它的唯一作用是 快速检测转发通道是否正常。
它通过在设备之间建立轻量级的会话,并以极短的周期交换检测报文,实时监测 IP 网络中链路或转发路径的连通性。一旦在协商的检测时间内未收到对端报文,BFD 会立即判定通道故障,并将状态通知给上层应用(如 OSPF、BGP、MPLS 等),从而触发业务的快速收敛与切换,保障网络和业务的高可用性与连续性。
1.2 产生背景与目的
为降低链路或节点故障对业务的影响,网络设备需要快速检测邻居通信状态。然而:
硬件告警(如 SDH)虽能快速检测,但并非所有介质都支持;
路由协议的 Hello 报文检测速度较慢(通常大于 1 秒),高速环境下可能丢失大量数据;
Hello 机制无法覆盖所有场景(如静态路由、隧道)。
BFD 正是为解决以上问题而产生,能够跨介质、跨协议统一提供快速故障检测。
1.3 功能
对相邻设备的转发通道进行轻量、快速的连通性检测(接口、链路、隧道甚至设备故障)。
提供通用检测机制,可独立于具体的三层协议运行。
检测结果实时通告上层路由/转发协议,实现快速收敛。
1.4 受益
毫秒级故障检测(典型 3×100ms = 300ms),显著提升业务连续性。
覆盖物理链路、逻辑链路、隧道等多种场景。
可与 OSPF、BGP、MPLS LSP、静态路由等配合,提高网络可靠性。
二、BFD原理描述
2.1 BFD基本原理
BFD 在两台网络设备之间建立会话,用于检测双向转发路径的连通性,为上层应用(如路由协议、MPLS、静态路由等)提供快速故障感知能力。
BFD 本身不具备邻居发现功能,而是依赖上层应用告知对端邻居信息来建立会话。
会话建立后,双方周期性发送 BFD 控制报文。若在约定的检测时间内未收到对端报文,则判定该转发路径故障,并立即通知上层应用触发收敛或切换。
BFD 可以看作是操作系统为上层应用提供的一种“快速故障检测服务”。
上层应用(如 OSPF、IS-IS、BGP、静态路由、MPLS LSP)向 BFD 注册需求,指定检测的目标地址、检测周期等参数;
BFD 模块根据这些参数创建、维护或删除会话,并周期性交互检测报文;
检测结果实时通告给上层应用,使其能够在故障发生时立即采取保护或切换措施。
下面以OSPF与BFD联动为例,简单介绍BFD会话建立流程。
OSPF 与 BFD 联动的会话建立流程:
OSPF 邻居发现,两台设备通过 OSPF 的 Hello 报文机制建立邻居关系。
OSPF 通告邻居信息,OSPF 在邻居关系建立成功后,将对端的邻居信息(如源 IP、目的 IP)传递给 BFD。
BFD 会话建立,BFD 根据 OSPF 提供的邻居信息发起会话请求,建立 BFD 会话。
BFD 链路检测,会话建立后,BFD 周期性发送检测报文;一旦在约定时间内未收到对端响应,则判定链路故障,并立即通知 OSPF。OSPF 收到通知后会快速收敛,触发路由重计算或切换,保证业务不中断。
2.2 BFD单跳检测和多跳检测
在 IP 链路上可以建立 BFD 会话,利用 BFD 的检测机制对链路进行快速故障检测。BFD for IP 支持 IPv4 链路的单跳检测和多跳检测:
BFD 单跳检测(Single-hop BFD)
单跳检测用于两个 直连系统之间的 IP 连通性检测,这里的“一跳”指的是 IP 的一跳。在这种场景下,对于某一种给定的数据协议,在指定接口上只会建立 一个 BFD 会话。单跳检测常用于直连路由器之间的链路快速故障检测。BFD 多跳检测(Multi-hop BFD)
多跳检测用于检测两个系统之间 跨越多个路由跳数的任意路径的连通性。这些路径可能跨越很多中间设备,甚至在某些部分出现路径重叠。多跳检测常用于验证端到端的 IP 路由可达性(例如:PE–PE之间的转发路径),在隧道、VPN 等场景下尤其重要。
2.3 BFD会话建立
2.3.1 建立模式
BFD 会话双方在BFD会话建立阶段可处于 主动模式 和 被动模式:
主动模式:无论是否收到对端报文,都会主动发出 BFD 控制报文;
被动模式:只有在收到对端报文后才会回应;
👉 至少一方为主动模式,会话才能成功建立。
2.3.2 会话管理
BFD会话有四种状态:Down、Init、Up和AdminDown。会话状态变化通过BFD报文的State字段传递,系统根据自己本地的会话状态和接收到的对端BFD报文驱动状态改变。BFD状态机的建立和拆除都采用三次握手机制,以确保两端系统都能知道状态的变化。以BFD会话建立为例,简单介绍状态机的迁移过程。
DeviceA和DeviceB各自启动BFD状态机,初始状态为Down,发送状态为Down的BFD报文。对于静态配置BFD会话,报文中的Your Discriminator的值是用户指定的;对于动态创建BFD会话,Your Discriminator的值是0。
DeviceB收到状态为Down的BFD报文且已学习到Your Discriminator的值时,状态会切换至Init,并发送状态为Init的BFD报文。(DeviceB本地BFD状态为Init后,不再处理接收到的状态为Down的报文。)
DeviceA的BFD状态变化同DeviceB,DeviceA收到状态为Down的BFD报文且已学习到Your Discriminator的值时,会向DeviceB发送状态为Init的报文。
DeviceB收到状态为Init的BFD报文后,本地状态切换至Up。
DeviceA的BFD状态变化同DeviceB。
2.4 BFD检测机制
BFD 的核心机制是在两个系统之间建立会话,并沿它们之间的转发路径周期性发送 BFD 控制报文。如果一方在规定的检测时间内未收到对端报文,则判定该路径发生故障,并上报给上层应用,实现快速收敛。
报文封装与会话建立
BFD 控制报文封装在 UDP 报文中传送。在会话建立初期,双方系统通过交换控制报文协商必要参数,包括:会话标识符、最小收发报文间隔、本端 BFD 状态等。协商成功后,双方按照协商结果在路径上定时发送 BFD 控制报文。业务相关性
当 BFD 与不同的上层业务结合使用时,BFD 协商报文的发送路径会跟随业务指定的路径进行转发,而 BFD 检测报文则严格沿业务的实际转发路径传递,从而确保检测与业务一致。检测模式
BFD 的主要检测模式是 异步模式(Asynchronous Mode,UDP目的端口3784)。在该模式下,双方周期性互发控制报文,如果连续丢失若干个报文,会话即被判定为 Down。Echo 功能(辅助)
异步模式可结合 Echo 功能(UDP目的端口3785)。当启用 Echo 功能时,本地设备向对端发送 BFD Echo 报文,对端设备不处理该报文,而是通过转发面原路返回。若连续若干个 Echo 报文未返回,会话同样被判定为 Down。由于直接验证了转发路径,Echo 功能能更准确反映实际数据面状况,但仅适用于单跳检测。
2.5 BFD协议报文
🔑 BFD 报文关键字段
State (Sta)
表示本地 BFD 会话的状态。
取值:
0 = AdminDown(管理员关闭,会话不可用)
1 = Down(未建立,链路不可用)
2 = Init(正在初始化,尝试建立会话)
3 = Up(会话建立成功,链路正常)
👉 是 BFD 协商和检测的核心字段,直接反映会话状态。Detect Mult (Detection Multiplier)
检测倍数,用于计算 BFD 的超时时间。
检测时间 = Required Min RX Interval × Detect Mult。
例如:
Min RX = 100ms,Detect Mult = 3
,则超时时间 = 300ms,如果 300ms 内没收到报文,就判定链路 Down。
👉 这是 BFD 快速检测的核心机制。My Discriminator / Your Discriminator
My Discriminator:本端唯一 ID(非 0),标识一个会话。
Your Discriminator:记录对端的 My Discriminator。
BFD 报文通过这两个字段实现 会话绑定,区分多个会话。
👉 类似于 TCP 的端口号,用来标识会话实例。Desired Min TX Interval / Required Min RX Interval
Desired Min TX Interval:本端期望的最小发送间隔。
Required Min RX Interval:本端能接受的最小接收间隔。
两端交换这两个参数后,协商出最终的报文发送周期。
👉 这是 BFD 协商检测速度的核心参数。P (Poll) / F (Final)
用于参数协商。
P=1:请求对端立即确认新的参数。
F=1:对端确认(回应 Poll)。
👉 相当于 TCP 的握手机制,保证参数协商一致。C (Control Plane Independent)
表示 BFD 是否依赖控制平面:
0:依赖控制平面,控制平面重启时 BFD 可能误判 Down。
对比本端与对端的C bit位,二者不都为1时,表示BFD报文在控制平面传输。这种情况下,GR期间BFD检测往往会误down,其结果是不可信的,业务不需要进行响应。
1:独立于控制平面,即使控制平面重启,BFD 检测仍然有效。
👉 对 GR(Graceful Restart) 场景特别关键。
对比本端与对端的C bit位,二者都为1时,表示发送系统的BFD实现不依赖于控制平面,BFD报文在转发平面传输,即使控制平面失效,BFD仍然能够起作用。这种情况下,GR期间BFD检测down是可信的,业务将响应down消息并改变拓扑和路由,避免流量丢失。
✨ 总结:
会话状态(State) → 直观反映链路是否 Up。
检测倍数(Detect Mult)+ Min RX → 控制检测超时,决定 BFD 反应速度。
Discriminator → 标识和绑定会话。
Poll/Final → 保证参数协商一致。
C 位 → 保证在控制平面故障时,转发检测仍然可靠。
三、BFD for LDP LSP
3.1 概述
在 LDP 中,LSR 通过周期性发送 Hello 消息来通告自身存在并维持与邻居的 Hello 邻接关系。每个邻居对应一个 Hello 保持定时器(Hello Hold Timer),当收到新的 Hello 消息时,该定时器被刷新。如果在保持定时器超时之前未收到邻居的 Hello,则认为邻接关系中断。
然而,这种基于定时器的机制存在局限性:
故障检测依赖定时器到期,收敛速度较慢(通常Hello Interval默认 5 秒、 Hold Timer默认 15 秒);
当 LSR 之间通过二层设备互联时(例如交换机、环网),链路的物理断开并不会立刻反映到 LDP Hello 邻接关系上,导致无法快速发现链路故障。
因此,LDP Hello 机制更多用于 邻居发现与基本连通性维持,而不是快速故障检测。对于快速感知链路中断,通常需要依赖 BFD(Bidirectional Forwarding Detection) 等辅助机制。
3.2 BFD for LDP LSP
BFD for LDP LSP 是一种针对 LDP 建立的 LSP 的快速检测机制。它的作用是:
快速发现 LSP 故障:通过在入节点和出节点之间建立 BFD 会话,周期性发送 BFD 控制报文来检测链路状态。
检测方式:BFD 报文由源端沿着 LSP 转发至目的端,目的端收到后立即返回响应。源端通过是否按时收到响应来判断 LSP 是否正常。
快速收敛:一旦 BFD 检测到 LSP 故障,会立即将此信息上报给转发层,触发业务流量的快速切换。
保障业务:转发层会根据本地的备份路径选择策略(如备份 LSP、TE LSP、FRR 机制等),将业务流量切换到可用的备份通道,从而保证业务连续性和可靠性。
四、测试环境
4.1 测试拓扑
采用eNSP Pro (版本:V100R002C10)搭建测试环境,设备采用NE路由器模拟器。
MPLS相关配置参考之前的笔记。
4.2 LSP信息
MPLS/LDP基本配置完成后,LSP信息:
[PE1]dis mpls lspFlag after Out IF: (I) - RLFA Iterated LSP, (I*) - Normal and RLFA Iterated LSPFlag after LDP FRR: (L) - Logic FRR LSP -------------------------------------------------------------------------------LSP Information: LDP LSP-------------------------------------------------------------------------------FEC In/Out Label In/Out IF Vrf Name1.1.1.1/32 3/NULL -/- 2.2.2.2/32 NULL/3 -/GE3/0/0 2.2.2.2/32 48000/3 -/GE3/0/0 3.3.3.3/32 NULL/48001 -/GE3/0/0 3.3.3.3/32 48001/48001 -/GE3/0/0 4.4.4.4/32 NULL/48002 -/GE3/0/0 4.4.4.4/32 48002/48002 -/GE3/0/0 [PE1][P1]dis mpls lspFlag after Out IF: (I) - RLFA Iterated LSP, (I*) - Normal and RLFA Iterated LSPFlag after LDP FRR: (L) - Logic FRR LSP -------------------------------------------------------------------------------LSP Information: LDP LSP-------------------------------------------------------------------------------FEC In/Out Label In/Out IF Vrf Name1.1.1.1/32 NULL/3 -/GE3/0/0 1.1.1.1/32 48000/3 -/GE3/0/0 2.2.2.2/32 3/NULL -/- 3.3.3.3/32 NULL/3 -/GE3/0/1 3.3.3.3/32 48001/3 -/GE3/0/1 4.4.4.4/32 NULL/48002 -/GE3/0/1 4.4.4.4/32 48002/48002 -/GE3/0/1 [P1][P2]dis mpls lspFlag after Out IF: (I) - RLFA Iterated LSP, (I*) - Normal and RLFA Iterated LSPFlag after LDP FRR: (L) - Logic FRR LSP -------------------------------------------------------------------------------LSP Information: LDP LSP-------------------------------------------------------------------------------FEC In/Out Label In/Out IF Vrf Name1.1.1.1/32 NULL/48000 -/GE3/0/1 1.1.1.1/32 48000/48000 -/GE3/0/1 2.2.2.2/32 NULL/3 -/GE3/0/1 2.2.2.2/32 48001/3 -/GE3/0/1 3.3.3.3/32 3/NULL -/- 4.4.4.4/32 NULL/3 -/GE3/0/2 4.4.4.4/32 48002/3 -/GE3/0/2 [P2][PE2]dis mpls lspFlag after Out IF: (I) - RLFA Iterated LSP, (I*) - Normal and RLFA Iterated LSPFlag after LDP FRR: (L) - Logic FRR LSP -------------------------------------------------------------------------------LSP Information: LDP LSP-------------------------------------------------------------------------------FEC In/Out Label In/Out IF Vrf Name1.1.1.1/32 NULL/48000 -/GE3/0/2 1.1.1.1/32 48000/48000 -/GE3/0/2 2.2.2.2/32 NULL/48001 -/GE3/0/2 2.2.2.2/32 48001/48001 -/GE3/0/2 3.3.3.3/32 NULL/3 -/GE3/0/2 3.3.3.3/32 48002/3 -/GE3/0/2 4.4.4.4/32 3/NULL -/- [PE2]
五、配置静态BFD检测LDP LSP
5.1 配置步骤
1、在被检测链路两端节点上使能全局BFD能力
[PE1]bfd[PE2]bfd
2、在Ingress上配置绑定到LDP LSP的BFD会话,发送报文的最小时间间隔是100毫秒,接收报文的最小时间间隔是100毫秒,并且能够修改端口状态表
PE1:
#bfd pe1tope2 bind ldp-lsp peer-ip 4.4.4.4 nexthop 192.168.12.2 interface GigabitEthernet3/0/0discriminator local 1discriminator remote 2min-tx-interval 100min-rx-interval 100process-pst#
peer-ip:指定BFD 会话绑定动态LSP的目的端IP 地址,必须是 MPLS LSR ID或LDP实例的LSRID
interface参数:可选参数,指定BFD绑定的出接口。当被检测的LSP出接口地址是借用的或者是被借用时,必须指定出接口。
discriminator:本端/远端标识符
process-pst:允许 BFD 会话状态改变时通告上层应用。如果允许BFD修改端口状态表PST(PortState Table),当检测到BFD 会话状态变为down时,系统将更改PST中相应表项。缺省情况下,静态BFD会话未使能通告联动检测业务,可用undo process-pst命令恢复缺省配置
由于PE1的BFD有绑定相关LSP,此BFD session的down会导致对应LSP中断,从而加快LSP的故障检测。
3、在Egress上配置绑定到IP链路的BFD会话,用来将LDP LSP的故障通告给Ingress
PE2:
#bfd pe2tope1 bind peer-ip 1.1.1.1discriminator local 2discriminator remote 1min-tx-interval 100min-rx-interval 100#
peer-ip:指定 BFD会话绑定的对端IP地址。如果只指定对端 IP 地址,则表示检测多跳链路。
由于PE2此BFD没有绑定相关LSP,此BFD session的down不会影响这一侧的LSP,但会导致PE1的BFD session down,从而影响PE1作为ingress的LSP。
5.2 配置结果
5.2.1 PE1
[PE1]dis bfd session all (w): State in WTR(*): State is invalid--------------------------------------------------------------------------------Local Remote PeerIpAddr State Type InterfaceName --------------------------------------------------------------------------------1 2 4.4.4.4 Up S_LDP_LSP GigabitEthernet3/0/0--------------------------------------------------------------------------------Total UP/DOWN Session Number : 1/0[PE1][PE1]dis bfd session all verbose (w): State in WTR(*): State is invalid--------------------------------------------------------------------------------State : Up Name : pe1tope2--------------------------------------------------------------------------------Local Discriminator : 1 Remote Discriminator : 2 Session Detect Mode : Asynchronous Mode Without Echo FunctionBFD Bind Type : LDP_LSP Bind Session Type : Static Bind Peer IP Address : 4.4.4.4 NextHop Ip Address : 192.168.12.2 Bind Interface : GigabitEthernet3/0/0 Tunnel ID : - FSM Board Id : 3 TOS-EXP : 7Min Tx Interval (ms) : 100 Min Rx Interval (ms) : 100 Actual Tx Interval (ms): 100 Actual Rx Interval (ms): 100 Local Detect Multi : 3 Detect Interval (ms) : 300 Echo Passive : Disable Acl Number : - Destination Port : 3784 TTL : 1 Proc Interface Status : Disable Process PST : Enable WTR Interval (ms) : - Config PST : Enable Active Multi : 3 Last Local Diagnostic : No DiagnosticBind Application : No Application BindSession TX TmrID : - Session Detect TmrID : - Session Init TmrID : - Session WTR TmrID : - Session Echo Tx TmrID : - Session Description : - Track Group Name : - --------------------------------------------------------------------------------Total UP/DOWN Session Number : 1/0
[PE1]dis bfd session all verbose :
会话基本信息
State : Up → 当前会话状态是 Up,说明 BFD 检测正常。
Name : pe1tope2 → 这是你在配置时起的会话名字。
会话标识
Local Discriminator : 1 / Remote Discriminator : 2
👉 本端 ID = 1,对端 ID = 2。用于唯一标识会话(两端要匹配)。会话类型
Session Detect Mode : Asynchronous Mode Without Echo Function
👉 表示使用 异步检测模式,不启用 Echo 功能。BFD Bind Type : LDP_LSP
👉 会话绑定在 LDP LSP 上。Bind Peer IP Address : 4.4.4.4
👉 这是 LSP 的 对端(PE2)的 LSR ID。NextHop IP Address : 192.168.12.2
👉 PE1 发送 BFD 报文时的 下一跳(P1 接口地址)。Bind Interface : GigabitEthernet3/0/0
👉 出接口。定时器参数
Min Tx Interval (ms) : 100 / Min Rx Interval (ms) : 100
👉 最小发送/接收间隔 100ms。Actual Tx Interval : 100 / Actual Rx Interval : 100
👉 实际使用值就是 100ms。Local Detect Multi : 3
👉 探测倍数(Detect Multiplier),表示允许连续 3 个周期没有收到 BFD 报文才判定会话 Down。Detect Interval (ms) : 300
👉 计算方式 =Min Rx Interval × Detect Multiplier = 100 × 3 = 300ms
,即 300ms 内没收到报文就判定链路故障。其它字段
TTL : 1
👉 BFD 报文在 MPLS LSP 中传输时,TTL 设置为 1(控制报文只作用在 LSP 内)。Process PST : Enable / Config PST : Enable
Last Local Diagnostic : No Diagnostic
👉 没有检测到故障。✅ 总结:
这条会话就是在 PE1 与 PE2 的 LDP LSP 上运行的 BFD。
当前状态 Up,说明链路可达。
检测周期是 100ms,故障判定时间是 300ms。
一旦失败,PE1 会立即触发 PST,把业务流量切到备份 LSP。
5.2.2 PE2
[PE2]dis bfd session all(w): State in WTR(*): State is invalid--------------------------------------------------------------------------------Local Remote PeerIpAddr State Type InterfaceName --------------------------------------------------------------------------------2 1 1.1.1.1 Up S_IP_PEER - --------------------------------------------------------------------------------Total UP/DOWN Session Number : 1/0[PE2]dis bfd session all verbose (w): State in WTR(*): State is invalid--------------------------------------------------------------------------------(Multi Hop) State : Up Name : pe2tope1--------------------------------------------------------------------------------Local Discriminator : 2 Remote Discriminator : 1 Session Detect Mode : Asynchronous Mode Without Echo FunctionBFD Bind Type : Peer IP Address Bind Session Type : Static Bind Peer IP Address : 1.1.1.1 Bind Interface : - Track Interface : - FSM Board Id : 3 TOS-EXP : 7Min Tx Interval (ms) : 100 Min Rx Interval (ms) : 100 Actual Tx Interval (ms): 100 Actual Rx Interval (ms): 100 Local Detect Multi : 3 Detect Interval (ms) : 300 Echo Passive : Disable Acl Number : - Destination Port : 3784 TTL : 254 Proc Interface Status : Disable Process PST : Disable WTR Interval (ms) : - Config PST : Disable Active Multi : 3 Last Local Diagnostic : No DiagnosticBind Application : No Application BindSession TX TmrID : - Session Detect TmrID : - Session Init TmrID : - Session WTR TmrID : - Session Echo Tx TmrID : - Session Description : - Track Group Name : - --------------------------------------------------------------------------------Total UP/DOWN Session Number : 1/0
这个很有意思,你这里 [PE2] 的会话显示和 [PE1] 有点不一样:
PE1 → 配置的是
bind ldp-lsp peer-ip 3.3.3.3
→ 所以它的 BFD Bind Type = LDP_LSP,并且通过 LDP FEC(目的 4.4.4.4)去匹配 LSP。
TTL = 1,因为是沿着 LSP 单跳传过去。
PE2 → 显示的是
Bind Type : Peer IP Address
→ 说明在 PE2 看来,这个会话是通过 对端的 Router-ID (1.1.1.1) 直接标识的,而不是通过本地 LSP 来绑定。
TTL = 254,也符合 多跳 BFD (Multi-Hop) 的特征。
为什么会这样?
本质上这是 对称的会话:
PE1 建立
bind ldp-lsp
,告诉系统:我要监控“到 4.4.4.4 的 LSP”。对端 PE2 收到 BFD 控制报文以后,会用 源 IP 1.1.1.1 + UDP 3784 识别会话,就自动建立了一个 Peer IP Address 类型的会话。
所以 PE2 看到的绑定方式就是 “基于对端 IP (1.1.1.1)” 的,而不是通过本地 FEC/LSP 查表触发。
换句话说:主动发起端用 LSP 绑定,响应端只是看成一个普通的 peer-ip BFD 会话。
这就是为什么:
PE1 session →
BFD Bind Type : LDP_LSP
PE2 session →
BFD Bind Type : Peer IP Address (Multi-Hop)
✅ 可以总结:
在发起端(PE1):BFD 会话通过
bind ldp-lsp
绑定到一条 LSP,BFD 报文被强制走该 LSP。在对端(PE2):收到 BFD 报文后,不需要自己去查找 LSP,而是直接以报文中的源 IP = 1.1.1.1 建立会话,因此显示为 Peer IP Address 类型。
5.3 抓包信息
5.3.1 PE1发出的BFD报文
Frame 1: 70 bytes on wire (560 bits), 70 bytes captured (560 bits)
Ethernet II, Src: 38:32:47:11:03:00, Dst: 38:17:15:11:03:00
MultiProtocol Label Switching Header, Label: 48002, Exp: 7, S: 1, TTL: 2550000 1011 1011 1000 0010 .... .... .... = MPLS Label: 48002 (0x0bb82).... .... .... .... .... 111. .... .... = MPLS Experimental Bits: 7.... .... .... .... .... ...1 .... .... = MPLS Bottom Of Label Stack: 1.... .... .... .... .... .... 1111 1111 = MPLS TTL: 255
Internet Protocol Version 4, Src: 1.1.1.1, Dst: 127.192.7.2010100 .... = Version: 4.... 0101 = Header Length: 20 bytes (5)Differentiated Services Field: 0xe0 (DSCP: CS7, ECN: Not-ECT)Total Length: 52Identification: 0x0000 (0)000. .... = Flags: 0x0...0 0000 0000 0000 = Fragment Offset: 0Time to Live: 1[Expert Info (Note/Sequence): "Time To Live" only 1]["Time To Live" only 1][Severity level: Note][Group: Sequence]Protocol: UDP (17)Header Checksum: 0x2f4f [validation disabled][Header checksum status: Unverified]Source Address: 1.1.1.1Destination Address: 127.192.7.201[Stream index: 0]
User Datagram Protocol, Src Port: 49153, Dst Port: 3784Source Port: 49153Destination Port: 3784Length: 32Checksum: 0x0000 [zero-value ignored][Stream index: 0][Stream Packet Number: 1][Timestamps][Time since first frame: 0.000000000 seconds][Time since previous frame: 0.000000000 seconds]UDP payload (24 bytes)
BFD Control message001. .... = Protocol Version: 1...0 0000 = Diagnostic Code: No Diagnostic (0x00)11.. .... = Session State: Up (0x3)Message Flags: 0xc8, Control Plane Independent: Set0... .. = Poll: Not set.0.. .. = Final: Not set..1. .. = Control Plane Independent: Set...0 .. = Authentication Present: Not set.... 0. = Demand: Not set.... .0 = Multipoint: Not setDetect Time Multiplier: 3 (= 300 ms Detection time)Message Length: 24 bytesMy Discriminator: 0x00000001Your Discriminator: 0x00000002Desired Min TX Interval: 100 ms (100000 us)Required Min RX Interval: 100 ms (100000 us)Required Min Echo Interval: 0 ms (0 us)
1) 链路/封装层(以太 / MPLS / IP / UDP / BFD)
Ethernet II:正常二层封装(给出 MAC 源/目的)。
MPLS header
Label = 48002:这是用于转发该 BFD 控制包的 MPLS 标签,表明报文是沿某条 LSP/标签转发的。标签值本身是局部意义(取决于发送者/下游)。
Exp = 7:实验/服务质量字段(通常被映射为 CoS/PHB)。
S = 1:栈底位 = 1,说明这是标签栈的最底层标签(没有更内层标签)。
MPLS TTL = 255:MPLS 层 TTL 很大(一般用于确保 MPLS 域内转发,不会在中间减到 0)。
IP header
Src = 1.1.1.1,Dst = 127.192.7.201:BFD 控制包的 IP 源/目的地址。这里目的地址不是普通公网地址,可能是本地/特殊用途地址(某些实现把 BFD 控制/回送设置为回环或特定对端地址);关键是两端对该目的/源的匹配要一致。
IP TTL = 1:IP 层 TTL = 1(注意:MPLS 封装下转发主要看 MPLS TTL;IP TTL=1 常见于一些控制探测封装以防止 IP 层被误转发,或用于 multi-hop/loop detection 策略)。
UDP
SrcPort = 49153, DstPort = 3784:BFD 控制消息使用 UDP/3784(标准端口);源端口是临时端口。UDP 校验和为 0(抓包显示被忽略/零值),有些实现对 UDP checksum 处理不同,注意中间网络对 checksum 的要求。
BFD Control Message(payload)
Protocol Version = 1。
Session State = Up(值 3):表明本端把会话视为
Up
。Message Flags: Control Plane Independent = Set:表示 BFD 报文采用 Control-Plane-Independent 模式(即检测不依赖于路由控制面,仅依赖数据面转发)。
Detect Time Multiplier = 3:检测倍数(detect multiplier)。与 min-rx 相乘给出故障判定时间。
My Discriminator = 1 / Your Discriminator = 2:双方用以唯一标识会话的标识符(Discriminator),必须和对端看到的值对应。
Desired Min TX Interval = 100 ms / Required Min RX Interval = 100 ms:发送/接收的最小间隔为 100 毫秒。
Message Length = 24 bytes:符合基本 BFD 控制包长度。
2) 关键含义(一句话总结)
这是一个 被 MPLS 封装的 BFD 控制包(UDP/3784),沿某条 LSP(label 48002)转发,BFD 会话当前为 Up,两端约定最小发送/接收间隔为 100 ms、检测倍数为 3,即理论上 300 ms 内无报文则判会话 Down。Control-Plane-Independent 标志被置位,表明检测依赖数据面独立转发能力。
3) 与你现有配置/会话核对的检查项(实践要点)
当看到这种包时,建议分别在两端核对下面几项,确保会话和转发无异常:
Discriminator 匹配
抓包显示
My=1, Your=2
,在对端抓包应看到相反(My=2, Your=1
)。如果不匹配,会话无法建立/确认。
Interval / Detect 时间
Min Tx = 100 ms, Min Rx = 100 ms, Multiplier = 3
→ 故障判定时间 = 300 ms。与
dis bfd session
命令输出处的Actual Tx/Rx Interval
、Detect Interval
一致。目的/源 IP(Peer IP)是否正确
抓包的 IP 源/目需与配置/期望一致(如你配置的 peer-ip/LSR ID)。
若包的目的地址不是预期(特殊 127.* 地址或其它回送地址),确认这是设备实现的正常行为(多厂家实现细节不同)。
MPLS 标签与 LSP 对应性
Label = 48002 应与本端 LFIB/LSP 表中某条 LSP 的出标签或入标签相对应(或为对端为你分配的标签)。
确认此标签沿着期望的 LSP 转发(
dis mpls lsp
/dis tunnel-info
/dis fib
等表项比对)。Control Plane Independent 标志
若置位,说明 BFD 依赖数据平面转发:若数据平面出问题(LSP 不通),BFD 能更快检测。
TTL 差异
MPLS TTL=255 与 IP TTL=1 的组合通常表明“在 MPLS 域内按标签转发,IP 层不期望被正常跨路由转发”。这是正常的控制/探测封装行为,但如果你在调试中看到 IP TTL 导致包被路由器 IP 层丢弃,要检查封装/转发策略。
UDP 目的端口 3784(标准 BFD)
确保中间设备没有对该端口过滤或做特殊处理。
5.3.2 PE2发出的BFD报文
抓包点(PE2-G3/0/2)。
Frame 2: 70 bytes on wire (560 bits), 70 bytes captured (560 bits)
Ethernet II, Src: 38:03:10:11:03:02, Dst: 38:38:50:11:03:02
MultiProtocol Label Switching Header, Label: 48000, Exp: 7, S: 1, TTL: 2550000 1011 1011 1000 0000 .... .... .... = MPLS Label: 48000 (0x0bb80).... .... .... .... .... 111. .... .... = MPLS Experimental Bits: 7.... .... .... .... .... ...1 .... .... = MPLS Bottom Of Label Stack: 1.... .... .... .... .... .... 1111 1111 = MPLS TTL: 255
Internet Protocol Version 4, Src: 192.168.34.4, Dst: 1.1.1.10100 .... = Version: 4.... 0101 = Header Length: 20 bytes (5)Differentiated Services Field: 0xe0 (DSCP: CS7, ECN: Not-ECT)Total Length: 52Identification: 0x0000 (0)000. .... = Flags: 0x0...0 0000 0000 0000 = Fragment Offset: 0Time to Live: 254Protocol: UDP (17)Header Checksum: 0xd72a [validation disabled][Header checksum status: Unverified]Source Address: 192.168.34.4Destination Address: 1.1.1.1[Stream index: 1]
User Datagram Protocol, Src Port: 49154, Dst Port: 3784Source Port: 49154Destination Port: 3784Length: 32Checksum: 0x0000 [zero-value ignored][Stream index: 1][Stream Packet Number: 1][Timestamps]UDP payload (24 bytes)
BFD Control message001. .... = Protocol Version: 1...0 0000 = Diagnostic Code: No Diagnostic (0x00)11.. .... = Session State: Up (0x3)Message Flags: 0xc8, Control Plane Independent: Set0... .. = Poll: Not set.0.. .. = Final: Not set..1. .. = Control Plane Independent: Set...0 .. = Authentication Present: Not set.... 0. = Demand: Not set.... .0 = Multipoint: Not setDetect Time Multiplier: 3 (= 300 ms Detection time)Message Length: 24 bytesMy Discriminator: 0x00000002Your Discriminator: 0x00000001Desired Min TX Interval: 100 ms (100000 us)Required Min RX Interval: 100 ms (100000 us)Required Min Echo Interval: 0 ms (0 us)
首先封装为源/目地址为:192.168.34.4/1.1.1.1,然后在FIB表中,去往1.1.1.1的路由迭代到了相应LSP。
PE2 经由其到 PE1 的 LSP 发出的 BFD Control(UDP dst 3784),外层 MPLS 标签为
48000
,BFD 字段My/Your Disc = 2/1
、MinTx/MinRx = 100 ms
、Detect Mult = 3
,与 PE2 的 BFD 会话配置 / 状态一致 —— 它是对 PE1 那端 BFD 报文的对等回复(方向相反)。
5.3.3 BFD会话建立阶段抓包
抓包点:PE1-G3/0/0
测试方法:将P1-G3/0/1执行shutdown/udo shutdown。
抓包信息:
Frame 72,PE2发Down报文,由于抓包点是PE1,收到的是已经pop mpls label的报文。
Frame 72: 66 bytes on wire (528 bits), 66 bytes captured (528 bits)
Ethernet II, Src: 38:41:38:11:03:00, Dst: 38:33:72:11:03:00
Internet Protocol Version 4, Src: 192.168.34.4, Dst: 1.1.1.1
User Datagram Protocol, Src Port: 49154, Dst Port: 3784
BFD Control message001. .... = Protocol Version: 1...0 0001 = Diagnostic Code: Control Detection Time Expired (0x01)01.. .... = Session State: Down (0x1)Message Flags: 0x48, Control Plane Independent: Set0... .. = Poll: Not set.0.. .. = Final: Not set..1. .. = Control Plane Independent: Set...0 .. = Authentication Present: Not set.... 0. = Demand: Not set.... .0 = Multipoint: Not setDetect Time Multiplier: 50 (= 100100 ms Detection time)Message Length: 24 bytesMy Discriminator: 0x00000002Your Discriminator: 0x00000001Desired Min TX Interval: 2002 ms (2002000 us)Required Min RX Interval: 2002 ms (2002000 us)Required Min Echo Interval: 0 ms (0 us)
Fram73,PE1收到PE2发送的Down报文后,在Your Discriminator为自己的标识,转为init,并发送Init报文。
Frame 73: 70 bytes on wire (560 bits), 70 bytes captured (560 bits)
Ethernet II, Src: 38:33:72:11:03:00, Dst: 38:41:38:11:03:00
MultiProtocol Label Switching Header, Label: 48006, Exp: 7, S: 1, TTL: 255
Internet Protocol Version 4, Src: 1.1.1.1, Dst: 127.19.190.172
User Datagram Protocol, Src Port: 49153, Dst Port: 3784
BFD Control message001. .... = Protocol Version: 1...0 0001 = Diagnostic Code: Control Detection Time Expired (0x01)10.. .... = Session State: Init (0x2)Message Flags: 0x88, Control Plane Independent: Set0... .. = Poll: Not set.0.. .. = Final: Not set..1. .. = Control Plane Independent: Set...0 .. = Authentication Present: Not set.... 0. = Demand: Not set.... .0 = Multipoint: Not setDetect Time Multiplier: 50 (= 50000 ms Detection time)Message Length: 24 bytesMy Discriminator: 0x00000001Your Discriminator: 0x00000002Desired Min TX Interval: 1000 ms (1000000 us)Required Min RX Interval: 1000 ms (1000000 us)Required Min Echo Interval: 0 ms (0 us)
Frame 74,PE2收到PE1发送的Init报文后,转为Up,并发送Up报文。
Frame 75: 70 bytes on wire (560 bits), 70 bytes captured (560 bits)
Ethernet II, Src: 38:33:72:11:03:00, Dst: 38:41:38:11:03:00
MultiProtocol Label Switching Header, Label: 48006, Exp: 7, S: 1, TTL: 255
Internet Protocol Version 4, Src: 1.1.1.1, Dst: 127.19.190.172
User Datagram Protocol, Src Port: 49153, Dst Port: 3784
BFD Control message001. .... = Protocol Version: 1...0 0001 = Diagnostic Code: Control Detection Time Expired (0x01)11.. .... = Session State: Up (0x3)Message Flags: 0xc8, Control Plane Independent: Set0... .. = Poll: Not set.0.. .. = Final: Not set..1. .. = Control Plane Independent: Set...0 .. = Authentication Present: Not set.... 0. = Demand: Not set.... .0 = Multipoint: Not setDetect Time Multiplier: 50 (= 50000 ms Detection time)Message Length: 24 bytesMy Discriminator: 0x00000001Your Discriminator: 0x00000002Desired Min TX Interval: 1000 ms (1000000 us)Required Min RX Interval: 1000 ms (1000000 us)Required Min Echo Interval: 0 ms (0 us)
Frame 75,PE1收到PE2发送的Up报文后,转为Up状态,并发送Up报文。
Frame 75: 70 bytes on wire (560 bits), 70 bytes captured (560 bits)
Ethernet II, Src: 38:33:72:11:03:00, Dst: 38:41:38:11:03:00
MultiProtocol Label Switching Header, Label: 48006, Exp: 7, S: 1, TTL: 255
Internet Protocol Version 4, Src: 1.1.1.1, Dst: 127.19.190.172
User Datagram Protocol, Src Port: 49153, Dst Port: 3784
BFD Control message001. .... = Protocol Version: 1...0 0001 = Diagnostic Code: Control Detection Time Expired (0x01)11.. .... = Session State: Up (0x3)Message Flags: 0xc8, Control Plane Independent: Set0... .. = Poll: Not set.0.. .. = Final: Not set..1. .. = Control Plane Independent: Set...0 .. = Authentication Present: Not set.... 0. = Demand: Not set.... .0 = Multipoint: Not setDetect Time Multiplier: 50 (= 50000 ms Detection time)Message Length: 24 bytesMy Discriminator: 0x00000001Your Discriminator: 0x00000002Desired Min TX Interval: 1000 ms (1000000 us)Required Min RX Interval: 1000 ms (1000000 us)Required Min Echo Interval: 0 ms (0 us)
注意,此时双方的发送/接收时间周期都没有进行协商。
Frame 86,PE2发送了自己的发送/接收时间周期给PE1,进行协商,注意Flags变化。
Frame 86: 66 bytes on wire (528 bits), 66 bytes captured (528 bits)
Ethernet II, Src: 38:41:38:11:03:00, Dst: 38:33:72:11:03:00
Internet Protocol Version 4, Src: 192.168.34.4, Dst: 1.1.1.1
User Datagram Protocol, Src Port: 49154, Dst Port: 3784
BFD Control message001. .... = Protocol Version: 1...0 0001 = Diagnostic Code: Control Detection Time Expired (0x01)11.. .... = Session State: Up (0x3)Message Flags: 0xe8, Poll: Set, Control Plane Independent: Set1... .. = Poll: Set.0.. .. = Final: Not set..1. .. = Control Plane Independent: Set...0 .. = Authentication Present: Not set.... 0. = Demand: Not set.... .0 = Multipoint: Not setDetect Time Multiplier: 3 (= 300 ms Detection time)Message Length: 24 bytesMy Discriminator: 0x00000002Your Discriminator: 0x00000001Desired Min TX Interval: 100 ms (100000 us)Required Min RX Interval: 100 ms (100000 us)Required Min Echo Interval: 0 ms (0 us)
Frame 119,PE1发送了自己的发送/接收时间周期给PE2,进行协商,注意Flags变化。
Frame 119: 70 bytes on wire (560 bits), 70 bytes captured (560 bits)
Ethernet II, Src: 38:33:72:11:03:00, Dst: 38:41:38:11:03:00
MultiProtocol Label Switching Header, Label: 48006, Exp: 7, S: 1, TTL: 255
Internet Protocol Version 4, Src: 1.1.1.1, Dst: 127.19.190.172
User Datagram Protocol, Src Port: 49153, Dst Port: 3784
BFD Control message001. .... = Protocol Version: 1...0 0001 = Diagnostic Code: Control Detection Time Expired (0x01)11.. .... = Session State: Up (0x3)Message Flags: 0xe8, Poll: Set, Control Plane Independent: Set1... .. = Poll: Set.0.. .. = Final: Not set..1. .. = Control Plane Independent: Set...0 .. = Authentication Present: Not set.... 0. = Demand: Not set.... .0 = Multipoint: Not setDetect Time Multiplier: 3 (= 300 ms Detection time)Message Length: 24 bytesMy Discriminator: 0x00000001Your Discriminator: 0x00000002Desired Min TX Interval: 100 ms (100000 us)Required Min RX Interval: 100 ms (100000 us)Required Min Echo Interval: 0 ms (0 us)
最终,正常情况下,双方安装协商一致的参数,进行报文发送。
PE1发送检测控制报文给PE2:
Frame 274: 70 bytes on wire (560 bits), 70 bytes captured (560 bits)
Ethernet II, Src: 38:33:72:11:03:00, Dst: 38:41:38:11:03:00
MultiProtocol Label Switching Header, Label: 48006, Exp: 7, S: 1, TTL: 255
Internet Protocol Version 4, Src: 1.1.1.1, Dst: 127.19.190.172
User Datagram Protocol, Src Port: 49153, Dst Port: 3784
BFD Control message001. .... = Protocol Version: 1...0 0001 = Diagnostic Code: Control Detection Time Expired (0x01)11.. .... = Session State: Up (0x3)Message Flags: 0xc8, Control Plane Independent: Set0... .. = Poll: Not set.0.. .. = Final: Not set..1. .. = Control Plane Independent: Set...0 .. = Authentication Present: Not set.... 0. = Demand: Not set.... .0 = Multipoint: Not setDetect Time Multiplier: 3 (= 300 ms Detection time)Message Length: 24 bytesMy Discriminator: 0x00000001Your Discriminator: 0x00000002Desired Min TX Interval: 100 ms (100000 us)Required Min RX Interval: 100 ms (100000 us)Required Min Echo Interval: 0 ms (0 us)
PE2发送检测控制报文给PE1:
Frame 275: 66 bytes on wire (528 bits), 66 bytes captured (528 bits)
Ethernet II, Src: 38:41:38:11:03:00, Dst: 38:33:72:11:03:00
Internet Protocol Version 4, Src: 192.168.34.4, Dst: 1.1.1.1
User Datagram Protocol, Src Port: 49154, Dst Port: 3784
BFD Control message001. .... = Protocol Version: 1...0 0001 = Diagnostic Code: Control Detection Time Expired (0x01)11.. .... = Session State: Up (0x3)Message Flags: 0xc8, Control Plane Independent: Set0... .. = Poll: Not set.0.. .. = Final: Not set..1. .. = Control Plane Independent: Set...0 .. = Authentication Present: Not set.... 0. = Demand: Not set.... .0 = Multipoint: Not setDetect Time Multiplier: 3 (= 300 ms Detection time)Message Length: 24 bytesMy Discriminator: 0x00000002Your Discriminator: 0x00000001Desired Min TX Interval: 100 ms (100000 us)Required Min RX Interval: 100 ms (100000 us)Required Min Echo Interval: 0 ms (0 us)
Kimi分析总结:
(wireshark通过bfd协议过滤,把bfd报文导出为txt文件,上传给kimi解析,所有帧号/时间和上面截图不一致。)
这段 BFD 报文序列完整记录了 双向转发检测(BFD)会话从 Down → Init → Up 的完整建立过程,并进入稳定保活阶段。以下是对整个过程的详细分析与归纳总结:
🔍 一、基础信息概览
项目 内容说明 协议版本 BFD v1(Protocol Version: 1) 诊断码 所有报文均为 Control Detection Time Expired
(0x01)状态变化 Down → Init → Up(最终稳定在 Up 状态) 链路类型 MPLS 网络承载(可见 MPLS Header,Label=48006) 通信双方 192.168.34.4 ↔ 1.1.1.1(UDP 3784 端口) 控制面独立 所有报文均设置 Control Plane Independent
标志位,说明 BFD 不依赖控制面🧭 二、BFD 状态机演进过程
帧号 时间(秒) 源地址 状态(State) 说明 1 0.000000 192.168.34.4 Down 启动会话,发送 Down 状态报文 2 0.016510 1.1.1.1 Init 对端回应 Init,表示已收到 Down 3 0.100249 192.168.34.4 Up 本地状态转为 Up,会话建立完成 4 0.203719 1.1.1.1 Up 对端也转为 Up,双向 Up 完成 ✅ 结论:BFD 会话在 约 200ms 内完成建立,符合 BFD 快速检测的设计目标。
⚙️ 三、关键参数分析
1. 检测时间(Detect Time)变化
初始阶段:
Detect Time Multiplier = 50
Desired Min TX Interval = 2002ms
检测时间 ≈ 100 秒(非常宽松,用于初始握手)
稳定阶段:
Detect Time Multiplier = 3
Desired Min TX Interval = 100ms
检测时间 ≈ 300ms(快速检测链路故障)
✅ 说明:BFD 在握手完成后自动切换为高频心跳 + 短检测时间,实现毫秒级故障检测。
2. ** discriminator(会话标识符)**
192.168.34.4 使用
My Discriminator = 0x00000002
1.1.1.1 使用
My Discriminator = 0x00000001
✅ 双方互相识别对方的 discriminator,确保会话唯一性。
3. Poll/Final 机制(参数协商
多次出现 Poll (P) 位 = 1 和 Final (F) 位 = 1
表示双方在动态协商检测参数(如 TX/RX Interval、Multiplier)
✅ 这是 BFD 标准行为,用于参数同步与确认。
🧪 四、行为特征总结
特征点 表现说明 ✅ 快速建立 200ms 内完成 Down → Up 状态机转换 ✅ 高频心跳 稳定后每 100ms 发送一次报文 ✅ 毫秒级检测 检测时间 300ms,满足电信级保护倒换要求(<1s) ✅ 控制面独立 所有报文设置 Control Plane Independent
,BFD 不依赖路由协议✅ MPLS 支持 报文封装在 MPLS 中,说明 BFD 用于检测 MPLS LSP 或 PW 的连通性 ✅ 参数协商完整 使用 Poll/Final 机制完成参数同步,无冲突或异常
✅ 五、结论
这是一个标准、健康、高效的 BFD 会话建立过程,完全符合 RFC 5880 规范,适用于:
MPLS 网络中的 LSP 保护
电信级链路故障检测(<500ms)
控制面独立场景(如 Segment Routing、L2VPN、PWE3)