Skip to main content
Version: 7.26

BFD

Bidirectional Forwarding Detection (BFD) checks that the path to a neighbor router forwards packets in both directions. The two routers send each other BFD control packets at a short interval. When no packet arrives for the detection time, the session goes down and the routing protocol that uses it reacts immediately, without waiting for its own hold or dead timer.

BFD does not exchange routes. In RouterOS a BFD session is started by its user:

Each user runs its own session: BGP and OSPF to the same neighbor make two BFD sessions. Sessions run over IPv4 and IPv6.

A session runs only when an entry in /routing/bfd/configuration allows it. Without a matching entry the session stays inactive.

Standards:

RouterOS does not support BFD echo mode or BFD authentication.

Use BFD with BGP​

In this example R1 (AS 65001, 10.0.12.1 on ether2) and R2 (AS 65002, 10.0.12.2) are eBGP neighbors on a directly connected link. R1 allows BFD on ether2:

/routing/bfd/configuration
add interfaces=ether2
/routing/bgp/instance
add name=bgp1 as=65001 router-id=10.255.0.1
/routing/bgp/connection
add name=to-r2 instance=bgp1 remote.address=10.0.12.2 \
local.role=ebgp use-bfd=yes

R2 allows BFD by the neighbor's address instead of the interface:

/routing/bfd/configuration
add addresses=10.0.12.1/32
/routing/bgp/instance
add name=bgp1 as=65002 router-id=10.255.0.2
/routing/bgp/connection
add name=to-r1 instance=bgp1 remote.address=10.0.12.1 \
local.role=ebgp use-bfd=yes

A BGP connection with use-bfd=yes establishes its session only after the BFD session is up. Until then the route,bgp,info log shows Cannot make BGP session. BFD session was not established. When the BFD session goes down, the BGP session goes down with it, and BGP opens it again when BFD is back.

On a router with the default firewall, also accept BFD control packets (UDP port 3784) on the BFD interfaces, see Allow routing protocols.

Use BFD with multihop BGP​

For a BGP session between loopback addresses, BFD runs a multihop session. A multihop session has no interface, so an interfaces entry does not allow it: match the neighbor's address with addresses or with a firewall address list in address-list. In this example R1 (loopback 10.255.0.1) and R3 (AS 65003, loopback 10.255.0.3) reach each other's loopback through R2 (R2-R3 link 10.0.23.0/30). The loopbacks must be reachable without the BGP session, here through static routes. On R1:

/interface/bridge
add name=loopback
/ip/address
add address=10.255.0.1/32 interface=loopback
/ip/route
add dst-address=10.255.0.3/32 gateway=10.0.12.2
/routing/bfd/configuration
add addresses=10.255.0.3/32
/routing/bgp/connection
add name=to-r3 instance=bgp1 remote.address=10.255.0.3 \
local.address=10.255.0.1 local.role=ebgp multihop=yes use-bfd=yes

On R2:

/ip/route
add dst-address=10.255.0.1/32 gateway=10.0.12.1
add dst-address=10.255.0.3/32 gateway=10.0.23.2

On R3, with an address list:

/interface/bridge
add name=loopback
/ip/address
add address=10.255.0.3/32 interface=loopback
/ip/route
add dst-address=10.255.0.1/32 gateway=10.0.23.1
/ip/firewall/address-list
add list=bfd-peers address=10.255.0.1
/routing/bfd/configuration
add address-list=bfd-peers
/routing/bgp/instance
add name=bgp1 as=65003 router-id=10.255.0.3
/routing/bgp/connection
add name=to-r1 instance=bgp1 remote.address=10.255.0.1 \
local.address=10.255.0.3 local.role=ebgp multihop=yes use-bfd=yes

Multihop control packets use UDP port 4784. On a router with the default firewall, accept this port from the neighbor's address too, see Allow routing protocols.

Check both sessions on R1:

[admin@MikroTik] > /routing/bfd/session/print detail
Flags: U - UP
0 U multihop=no vrf=main remote-address=10.0.12.2%ether2
local-address=10.0.12.1 state=up state-changes=1 uptime=1m
desired-tx-interval=200ms actual-tx-interval=200ms required-min-rx=200ms
remote-min-rx=200ms remote-min-tx=200ms multiplier=5 hold-time=1s
packets-rx=345 packets-tx=345

1 U multihop=yes vrf=main remote-address=10.255.0.3 local-address=10.255.0.1
state=up state-changes=2 uptime=20s desired-tx-interval=200ms
actual-tx-interval=200ms required-min-rx=200ms remote-min-rx=200ms
remote-min-tx=200ms multiplier=5 hold-time=1s packets-rx=120
packets-tx=117

Use BFD with OSPF​

Set use-bfd on the OSPF interface template and allow the interface in /routing/bfd/configuration on both neighbors. When the BFD session goes down, OSPF drops the neighbor immediately and logs bfd down. Unlike BGP, OSPF does not wait for BFD: when no configuration entry allows the session, the OSPF neighbor still reaches Full and the BFD session stays inactive. The OSPF page has a complete example.

Use BFD with RIP​

Set use-bfd on the RIP interface template and allow the interface in /routing/bfd/configuration on both neighbors. /routing/rip/interface then shows bfd=yes. When the BFD session goes down, the router removes the routes learned from that neighbor without waiting for route-timeout. See RIP.

Use BFD for a static route​

With check-gateway=bfd, the router checks the gateway of a static route with a BFD session. When the session is down, the route is inactive. Allow the gateway's address:

/routing/bfd/configuration
add addresses=10.0.12.2/32
/ip/route
add dst-address=192.0.2.0/24 gateway=10.0.12.2 check-gateway=bfd

The router at the gateway needs a BFD session to this router too: its own route with check-gateway=bfd and a configuration entry for this router's address. On R2:

/routing/bfd/configuration
add addresses=10.0.12.1/32
/ip/route
add dst-address=198.51.100.0/24 gateway=10.0.12.1 check-gateway=bfd

The check-gateway session is a multihop session and uses UDP port 4784. On a router with the default firewall, accept this port from the gateway's address, see Allow routing protocols.

Allow and forbid sessions​

The entries in /routing/bfd/configuration are checked in order, and the first entry that matches a session decides. An entry matches by:

  • interfaces: the interface of a single-hop session. An interface list works too, for example the built-in static list, which contains all interfaces that are not dynamic.
  • addresses or address-list: the neighbor's address, for single-hop and multihop sessions.
  • vrf: the VRF of the session. An entry without vrf matches sessions in every VRF.

With forbid-bfd=yes, a matching entry forbids the session. To forbid BFD on ether3 and allow it on every other static interface:

/routing/bfd/configuration
add interfaces=ether3 forbid-bfd=yes
add interfaces=static

The forbid entry has to come first: with the static entry first, it matches ether3 too and allows the session. Use move to change the order of existing entries.

To allow the neighbors of a network in a VRF, for example 10.0.99.0/24 in VRF vrf1:

/routing/bfd/configuration
add addresses=10.0.99.0/24 vrf=vrf1

Set the timers​

Each configuration entry sets the timers of the sessions it allows:

  • min-tx: how often this router wants to send control packets. Default: 200 ms.
  • min-rx: the shortest interval at which this router accepts packets from the neighbor. Default: 200 ms.
  • multiplier: how many intervals the neighbor waits before it declares the session down, 1 to 255. Default: 5.

min-tx and min-rx accept values up to 4294 seconds.

With the defaults, a session goes down after 1 second without packets. Longer intervals detect a failure later. To use 500 ms and a multiplier of 3 on R1's link to R2:

/routing/bfd/configuration
set [find interfaces=ether2] min-tx=500ms min-rx=500ms multiplier=3

R2 keeps the defaults. R1's session then shows the values of both ends:

[admin@MikroTik] > /routing/bfd/session/print detail where multihop=no
Flags: U - UP
1 U multihop=no vrf=main remote-address=10.0.12.2%ether2
local-address=10.0.12.1 state=up state-changes=1 uptime=1m28s
desired-tx-interval=500ms actual-tx-interval=500ms required-min-rx=500ms
remote-min-rx=200ms remote-min-tx=200ms multiplier=3 hold-time=2s500ms
packets-rx=419 packets-tx=420

R1 sends every 500 ms, the slower of its own min-tx and R2's min-rx. R2 sends every 500 ms too, because R1 accepts no faster packets. hold-time is R1's detection time: R2's multiplier (5) times 500 ms. R2 declares the session down after R1's multiplier (3) times 500 ms, 1.5 seconds. Set the same timers at both ends to get the same detection time in both directions.

Check sessions​

/routing/bfd/session lists the sessions that BGP, OSPF, RIP and static routes have started. The state field shows the BFD state:

  • up: both routers receive each other's packets.
  • init: this router receives packets, but the neighbor does not see this router's packets.
  • down: the session is not up, for example because no packets arrive from the neighbor.
  • admin-down: the AdminDown state of RFC 5880.

A session that the configuration does not allow is inactive (I), with a comment that says why. Here a forbid entry for ether2 stopped R1's session to R2:

[admin@MikroTik] > /routing/bfd/session/print detail where multihop=no
Flags: I - INACTIVE
1 I ;;; BFD forbidden for interface
multihop=no vrf=main remote-address=10.0.12.2%ether2
local-address=10.0.12.1 desired-tx-interval=0ms required-min-rx=0ms
multiplier=0
  • BFD forbidden for interface: a single-hop session with no matching entry, or a matching entry with forbid-bfd=yes.
  • BFD forbidden for destination address: a multihop session with no matching addresses or address-list entry.

A session in down with packets-rx=0 receives nothing from the neighbor. Check that the neighbor runs BFD for this session (use-bfd, a configuration entry) and that no firewall drops the packets.

Technical details​

Ports and packets​

  • Single-hop control packets: UDP destination port 3784, IP TTL 255.
  • Multihop control packets: UDP destination port 4784, IP TTL 64.
  • Source port: from the range 49152-65535.

Timer negotiation​

  • The transmit interval of a session that is up is the larger of the local min-tx and the neighbor's min-rx.
  • A session that is not up sends one packet per second (actual-tx-interval=1s).
  • The detection time (hold-time) is the neighbor's multiplier times the larger of the local min-rx and the neighbor's desired transmit interval (its min-tx).

All properties are described in the CLI reference: /routing/bfd/configuration and /routing/bfd/session.