Protocol 27 of 81Layer 3FrameAssembly v3.1.2
llms-full.txt
bfdBidirectional Forwarding Detection Control Packet

50ms Hair-Trigger Link Heartbeats (rtr_a <-> rtr_b bfd UDP 3784)

Default Port / Protocol
UDP 3784 (Multihop 4784, TTL 255)
Host Endpoint Rule
Dual-Stack IPv4/IPv6
Wireshark Display Filter
bfd
Standards & Specs
RFC 5880, RFC 5881, RFC 5883
Wire Stack:Ethernet II[802.1Q / QinQ / MPLS]IPv4 / IPv6BFD (UDP 3784 (Multihop 4784, TTL 255))

What It Does on the Wire

Waiting 180 seconds for BGP Hold Time to notice a dead fiber is painful — bfd fires ttl 255 UDP 3784 control packets with microsecond mintx/minrx timers and discriminator handshakes.

Bidirectional Forwarding Detection (bfd, RFC 5880) provides sub-50ms forwarding-plane failure detection for BGP, OSPF, IS-IS, VRRP, and MPLS/VXLAN tunnels. Single-hop BFD (RFC 5881) runs over UDP dstport 3784 with srcport >= 49152 and mandatory TTL / Hop Limit 255, while multihop BFD (RFC 5883) uses dstport 4784 and Seamless BFD uses dstport 7784.

FrameAssembly constructs the exact 24-byte BFD v1 Control header—packing Version 1, 5-bit Diagnostic (diag), 2-bit State (state), Detect Multiplier (mult), 32-bit mydisc / yourdisc session discriminators, and microsecond mintx / minrx intervals.

Sub-Second BGP / OSPF Fast-Reroute Lab Captures

Model BFD 3-way state bring-up (Down 1 -> Init 2 -> Up 3) followed by diag 1 (Control Detection Time Expired) triggering immediate BGP teardown.

Hardware Linecard CoPP & GTSM (ttl 255) Filtering

Verify router Control Plane Policing hardware queues prioritize UDP 3784 / 4784 (dscp 48 CS6) and reject spoofed ttl 254 packets.

VXLAN / Geneve / MPLS OAM Health Probing

Combine bfd with vlan or mpls shims to test carrier transport OAM monitoring.

Minimal Quickstart (bfd_quickstart.frasm)

Hit Preview Packets to compile in-browser and eyeball timestamps + wire byte lengths, or ship it straight to the Playground.

bfd_quickstart.frasm7 lines
Open in Playground
host rtr_leaf { ip 172.16.0.1 }
host rtr_spine { ip 172.16.0.2 }
compile {
rtr_leaf -> rtr_spine bfd state 3 mydisc 101 yourdisc 202 mintx 50000 minrx 50000 mult 3 wait 50ms
rtr_leaf <- rtr_spine bfd state 3 mydisc 202 yourdisc 101 mintx 50000 minrx 50000 mult 3
}

What the Compiler Calculates So You Don't Have To

  • Defaults UDP srcport to RFC 5881 range (49152+), dstport to 3784, and IP ttl / Hop Limit to 255.
  • Bit-packs Version (1), diag (0..31), state (0..3), mult (default 3), Length = 24, mydisc, yourdisc, mintx (100000 us), minrx (100000 us), and Echo RX interval.
  • Validates state (0..=3) and diag (0..=31) bounds at compile time.
Multi-Frame Lab · Ready to Compile

BFD 3-Way Session Bring-Up (Down -> Init -> Up) & Detection Timeout

Traces two routers negotiating a 50ms (50000 us * mult 3 = 150ms detection) BFD session from Down (1) through Init (2) to Up (3), followed by a diag 1 timeout.

bfd_state_machine.frasm14 lines
Open in Playground
host pe_north { ip 10.255.1.1 }
host pe_south { ip 10.255.1.2 }
compile {
// 1. Initial Down packet (state 1, yourdisc 0 = peer unknown, slow 1s timer)
pe_north -> pe_south bfd state 1 diag 0 mydisc 0x1001 yourdisc 0 mintx 1000000 minrx 1000000 mult 3 dscp 48 wait 2ms
// 2. Peer sees 0x1001 and transitions to Init (state 2)
pe_north <- pe_south bfd state 2 diag 0 mydisc 0x2002 yourdisc 0x1001 mintx 50000 minrx 50000 mult 3 dscp 48 wait 2ms
// 3. Both peers reach Up (state 3) at 50ms (50,000 us) intervals
pe_north -> pe_south bfd state 3 diag 0 mydisc 0x1001 yourdisc 0x2002 mintx 50000 minrx 50000 mult 3 dscp 48 wait 50ms
pe_north <- pe_south bfd state 3 diag 0 mydisc 0x2002 yourdisc 0x1001 mintx 50000 minrx 50000 mult 3 dscp 48 wait 150ms
// 4. Link failure detected: state 1 (Down), diag 1 (Control Detection Time Expired)
pe_north -> pe_south bfd state 1 diag 1 mydisc 0x1001 yourdisc 0x2002 mintx 1000000 minrx 1000000 mult 3 dscp 48
}
Terminal Commands (FrameAssembly CLI v3.1.2)
# 1. Eyeball relative timestamps, ports & wire lengths in your terminal
frameassembly show bfd_state_machine.frasm

# 2. Compile .frasm -> classic .pcap (tcpdump/tcpreplay/Suricata) or nanosecond .pcapng
frameassembly bfd_state_machine.frasm bfd_state_machine.pcap
frameassembly bfd_state_machine.frasm bfd_state_machine.pcapng

# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture
frameassembly reverse bfd_state_machine.pcap bfd_state_machine_edited.frasm

All bfd Keywords & Header Options

Every sub-keyword and header option is lowercase [a-z0-9]+ with zero underscores — mix and match them in any order after bfd:

src_host -> dst_host bfd [state <0..3>] [diag <0..31>] [mydisc <number>] [yourdisc <number>] [mintx <number>] [minrx <number>] [mult <0..255>]
Keyword / OptionAccepted ValueDefaultEffect on Packet
state <0..3>2-bit BFD session state (0..3)3 (Up)Sets session state: 0 = AdminDown, 1 = Down, 2 = Init, 3 = Up.
diag <0..31>5-bit RFC 5880 Diagnostic code (0..31)0 (No Diagnostic)Sets failure reason (0 None, 1 Control Detection Time Expired, 3 Neighbor Signaled Session Down, 7 Administratively Down).
mydisc <number> | yourdisc <number>32-bit non-zero / peer session discriminatorsmydisc 1, yourdisc 0Sets My Discriminator and Your Discriminator (0 until learned from peer).
mintx <number> | minrx <number>Whole number (microseconds)100000 (100 ms)Sets Desired Min TX Interval and Required Min RX Interval in microseconds (50000 = 50ms, 1000000 = 1s).
mult <1..255>8-bit Detect Multiplier3Sets the missed-packet multiplier (Detection Time = mult * max(minrx, peer_mintx)).

Cross-Layer Wrappers Valid with bfd

802.1Q VLAN / QinQ / MPLS tags, IPv4/IPv6 QoS & TTL fields, wait gaps, and transport overrides allowed on this protocol

10 options
OptionRange / FormatDefaultEffect on Packet
wait <number><ns|us|ms|s|m>Time gap (ns, us, ms, s, m)10msAdvances the packet timestamp clock after sending this packet and before the next packet (wait 0ns sends back-to-back).
payload "<text>" | hexpayload "<hex>"Quoted text or hex bytes (choose one)OmittedAppends or overrides raw payload bytes ("deadbeef" or "de:ad:be:ef") and updates packet lengths and checksums.
srcmac <mac> | dstmac <mac>Colon, hyphen, or Cisco dot MACHost MAC / RFC multicast MACOverrides the 14-byte Ethernet II source or destination MAC address for this single packet.
vlan <0..4095> [pcp <0..7>] [dei <0|1>]VLAN ID 0..4095, PCP 0..7, DEI 0..1UntaggedWraps the packet in an IEEE 802.1Q VLAN tag (0x8100) with optional 802.1p QoS priority.
qinq <0..4095> [innervlan <0..4095>]Outer S-VLAN 0..4095, Inner C-VLAN 0..4095Untagged (innervlan 1 when qinq is set)Double-tags the packet with outer IEEE 802.1ad S-Tag (0x88a8) plus inner IEEE 802.1Q C-Tag (0x8100).
mpls <0..1048575> [exp|tc <0..7>] [bos <0|1>] [mplsttl <0..255>]Label 0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255Unlabeled (at most 1 mpls tag per packet)Inserts a 32-bit MPLS label header (0x8847) ahead of the Layer 3 header.
ttl <0..255> [dscp <0..63>] [ecn <0..3>]TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3ttl 255, dscp 0, ecn 0Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings.
ipid <0..65535> [df] [mf] [fragoffset <0..8191>]IPv4 ID, DF/MF flags, fragment offset 0..8191ipid 1, flags 0, fragoffset 0Sets IPv4 Identification, Do-Not-Fragment (df), More-Fragments (mf), and fragment offset (ignored over IPv6).
flowlabel <0..1048575>20-bit IPv6 Flow Label (0..1048575)0Sets the 20-bit IPv6 Flow Label for ECMP routing tests (ignored when running over IPv4 hosts).
srcport <0..65535> | dstport <0..65535>Port number 0..65535srcport 49152 (remembered), UDP 3784 (Multihop 4784, TTL 255)Overrides source or destination port and remembers the port pair automatically on <- replies.

Gotchas & Quick Fixes

mintx and minrx Are Expressed in Microseconds (Not Milliseconds)

Avoid
r1 -> r2 bfd mintx 50 minrx 50 // 50 microseconds!
Valid v3.1.2 Syntax
r1 -> r2 bfd mintx 50000 minrx 50000 // 50 milliseconds

Per RFC 5880 §4.1, BFD timer fields are encoded in microseconds (50000 = 50 ms, 300000 = 300 ms).

Use dstport 4784 for Multihop BFD (RFC 5883)

Valid v3.1.2 Syntax
r1 -> r2 bfd dstport 4784 ttl 64 state 3 mydisc 10 yourdisc 20

Single-hop BFD uses UDP 3784 with ttl 255; for multihop eBGP loopback BFD sessions, override dstport 4784 and set an appropriate ttl.

Field Guide 05
VLANs, QinQ, MPLS, Tunnel Soup & Dual-Stack IPv6