Commit c213d2ff8a for frr
commit c213d2ff8a2df8a5cd3c29479be6f8a1c2b08092
Author: Nelson Lako Tangala <nelson.lako_tangala@6wind.com>
Date: Fri Oct 30 14:07:10 2026 +0100
bfdd: drop peer config left on shared sessions
When a protocol client (bgpd, staticd...) and a 'bfd / peer' node share
a session, removing the node with 'no peer' or 'no bfd' leaves its
timers and profile on the session instead of restoring the client's.
While the node exists, a new client registration also overwrites the
profile of the node.
For example, bgpd registers the session to 10.0.0.2 with profile
'slow' (2000ms):
router bgp 65001
neighbor 10.0.0.2 bfd profile slow
1. Add a node with its own timers (1500ms), then remove it:
bfd
peer 10.0.0.2
transmit-interval 1500
receive-interval 1500
exit
no peer 10.0.0.2
The node is gone, but the session keeps its timers instead of going
back to profile 'slow':
> # show bfd peer 10.0.0.2
> [...]
> Peer Type: dynamic
> [...]
> Local timers:
> Detect-multiplier: 3
> Receive interval: 1500ms
> Transmission interval: 1500ms
2. On a new session, add a node with profile 'fast' (700ms). The
session now uses 700ms:
bfd
peer 10.0.0.2
profile fast
Then make bgpd register the session again, by entering 'neighbor
10.0.0.2 bfd profile slow' again. The node still says 'profile fast',
but the session switches to 'slow':
> # show bfd peer 10.0.0.2
> [...]
> Peer Type: configured
> [...]
> Receive interval: 2000ms
> Transmission interval: 2000ms
bfdd does not record which settings come from which side: removing the
node only drops its reference while clients still use the session, and
bfdd_dest_register() applies the profile of the client without storing
it.
Store the profile of each client registration, and keep the peer
settings the client created the session with apart from those of the
node. When the node or its profile is removed from a session still in
use, restore these settings and the profile of the last client
registration. Keep the profile of the node, while set, when a client
registers.
Resetting to the defaults instead would drop the timers of the client,
and raise the minimum TTL of a multihop session from 1 to 254, which
discards the packets of its peer.
Add the bfd_profile_shared_peer topotest.
Fixes: 2a573ff672f4 ("bfdd: support global BFD reset")
Fixes: 18322efd130a ("bfdd,lib: implement protocol profile selection")
Signed-off-by: Nelson Lako Tangala <nelson.lako_tangala@6wind.com>
diff --git a/bfdd/bfd.c b/bfdd/bfd.c
index 2cdaa5024d..897d249cfc 100644
--- a/bfdd/bfd.c
+++ b/bfdd/bfd.c
@@ -307,6 +307,23 @@ void bfd_profile_remove(struct bfd_session *bs)
bfd_profile_remove_reference(bs);
}
+void bfd_profile_apply_client(struct bfd_session *bs)
+{
+ const char *profname = ptm_bfd_client_profile(bs);
+
+ if (profname)
+ bfd_profile_apply(profname, bs);
+ else
+ bfd_profile_remove(bs);
+}
+
+void bfd_session_unconfigure(struct bfd_session *bs)
+{
+ bs->peer_profile = bs->client_peer_profile;
+ UNSET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG_PROFILE);
+ bfd_profile_apply_client(bs);
+}
+
void gen_bfd_key(struct bfd_key *key, struct sockaddr_any *peer, struct sockaddr_any *local,
bool mhop, const char *ifname, const char *vrfname, const char *bfdname)
{
@@ -1148,6 +1165,7 @@ struct bfd_session *bfd_session_new(enum bfd_mode_type mode)
/* Set peer session defaults. */
bfd_profile_set_default(&bs->peer_profile);
+ bfd_profile_set_default(&bs->client_peer_profile);
bs->timers.desired_min_tx = BFD_DEFDESIREDMINTX;
bs->timers.required_min_rx = BFD_DEFREQUIREDMINRX;
@@ -1240,6 +1258,37 @@ static void _bfd_session_update(struct bfd_session *bs,
bfd_profile_apply(bpc->bpc_profile, bs);
}
+void bfd_session_save_client_config(struct bfd_session *bs, const struct bfd_peer_cfg *bpc)
+{
+ struct bfd_profile *bp = &bs->client_peer_profile;
+
+ /* The peer settings _bfd_session_update() applies. */
+ bfd_profile_set_default(bp);
+
+ if (bpc->bpc_has_txinterval)
+ bp->min_tx = bpc->bpc_txinterval * 1000;
+
+ if (bpc->bpc_has_recvinterval)
+ bp->min_rx = bpc->bpc_recvinterval * 1000;
+
+ if (bpc->bpc_has_detectmultiplier)
+ bp->detection_multiplier = bpc->bpc_detectmultiplier;
+
+ if (bpc->bpc_has_echorecvinterval)
+ bp->min_echo_rx = bpc->bpc_echorecvinterval * 1000;
+
+ if (bpc->bpc_has_echotxinterval)
+ bp->min_echo_tx = bpc->bpc_echotxinterval * 1000;
+
+ if (bpc->bpc_has_minimum_ttl)
+ bp->minimum_ttl = bpc->bpc_minimum_ttl;
+
+ bp->echo_mode = bpc->bpc_echo;
+ bp->admin_shutdown = bpc->bpc_shutdown;
+ strlcpy(bp->auth_config.key_chain_name, bpc->auth_config.key_chain_name,
+ sizeof(bp->auth_config.key_chain_name));
+}
+
int bfd_session_update(struct bfd_session *bs, struct bfd_peer_cfg *bpc)
{
/* User didn't want to update, return failure. */
@@ -1352,6 +1401,7 @@ struct bfd_session *ptm_bfd_sess_new(struct bfd_peer_cfg *bpc)
/* Apply other configurations. */
_bfd_session_update(bfd, bpc);
+ bfd_session_save_client_config(bfd, bpc);
return bfd;
}
@@ -2585,9 +2635,14 @@ static void _bfd_session_remove_manual(struct hash_bucket *hb,
bs->refcount--;
UNSET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG);
- /* Don't delete sessions still in use. */
- if (bs->refcount != 0)
+ /*
+ * Don't delete sessions still in use, but drop what the `peer` node
+ * configured.
+ */
+ if (bs->refcount != 0) {
+ bfd_session_unconfigure(bs);
return;
+ }
bfd_session_free(bs);
}
diff --git a/bfdd/bfd.h b/bfdd/bfd.h
index 5ef75357f7..9325bef315 100644
--- a/bfdd/bfd.h
+++ b/bfdd/bfd.h
@@ -275,6 +275,7 @@ enum bfd_session_flags {
BFD_SESS_FLAG_PASSIVE = 1 << 10, /* Passive mode */
BFD_SESS_FLAG_MAC_SET = 1 << 11, /* MAC of peer known */
BFD_SESS_FLAG_LOG_SESSION_CHANGES = 1 << 12, /* Log session changes */
+ BFD_SESS_FLAG_CONFIG_PROFILE = 1 << 13, /* Profile set with bfd NB API */
};
enum bfd_mode_type {
@@ -401,6 +402,11 @@ struct bfd_session {
struct bfd_profile *profile;
/** BFD peer configuration (without profile). */
struct bfd_profile peer_profile;
+ /**
+ * Peer configuration the first client of the session asked for,
+ * restored when a `peer` node stops configuring the session.
+ */
+ struct bfd_profile client_peer_profile;
/* Timers */
struct bfd_config_timers timers;
@@ -856,6 +862,32 @@ void bfd_profile_apply(const char *profname, struct bfd_session *bs);
*/
void bfd_profile_remove(struct bfd_session *bs);
+/**
+ * Give the session back the profile one of its clients registered it with,
+ * or no profile if they gave none.
+ *
+ * \param bs the BFD session.
+ */
+void bfd_profile_apply_client(struct bfd_session *bs);
+
+/**
+ * Remove the configuration a `peer` node set on a session that clients still
+ * use: give it back the peer settings of its first client, and the profile of
+ * its clients.
+ *
+ * \param bs the BFD session.
+ */
+void bfd_session_unconfigure(struct bfd_session *bs);
+
+/**
+ * Save the peer settings a client registered the session with, which the
+ * session gets back when a `peer` node stops configuring it.
+ *
+ * \param bs the BFD session.
+ * \param bpc the peer configuration of the client.
+ */
+void bfd_session_save_client_config(struct bfd_session *bs, const struct bfd_peer_cfg *bpc);
+
/**
* Apply new profile values to sessions using it.
*
@@ -892,6 +924,16 @@ void bfdd_sessions_disable_vrf(struct vrf *vrf);
int ptm_bfd_notify(struct bfd_session *bs, uint8_t notify_state);
+/**
+ * Look up the profile a client registered the session with.
+ *
+ * \param bs the BFD session.
+ *
+ * \returns the profile name of the most recent registration that gave one,
+ * among those of the clients still using the session, or NULL.
+ */
+const char *ptm_bfd_client_profile(const struct bfd_session *bs);
+
/*
* dplane.c
*/
diff --git a/bfdd/bfdd_nb_config.c b/bfdd/bfdd_nb_config.c
index f608cdfadc..409ba4108d 100644
--- a/bfdd/bfdd_nb_config.c
+++ b/bfdd/bfdd_nb_config.c
@@ -385,9 +385,14 @@ static int bfd_session_destroy(enum nb_event event, const struct lyd_node *dnode
UNSET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG);
bs->refcount--;
- /* There are still daemons using it. */
- if (bs->refcount > 0)
+ /*
+ * There are still daemons using it: drop what the `peer` node
+ * configured, which would otherwise outlive it.
+ */
+ if (bs->refcount > 0) {
+ bfd_session_unconfigure(bs);
break;
+ }
if (bglobal.debug_peer_event)
zlog_info("session destroy: %s", bs_to_string(bs));
@@ -966,6 +971,7 @@ int bfdd_bfd_sessions_single_hop_profile_modify(struct nb_cb_modify_args *args)
return NB_OK;
bs = nb_running_get_entry(args->dnode, NULL, true);
+ SET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG_PROFILE);
bfd_profile_apply(yang_dnode_get_string(args->dnode, NULL), bs);
return NB_OK;
@@ -980,7 +986,9 @@ int bfdd_bfd_sessions_single_hop_profile_destroy(
return NB_OK;
bs = nb_running_get_entry(args->dnode, NULL, true);
- bfd_profile_remove(bs);
+ UNSET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG_PROFILE);
+ /* Fall back on the profile of the clients, if any. */
+ bfd_profile_apply_client(bs);
return NB_OK;
}
diff --git a/bfdd/ptm_adapter.c b/bfdd/ptm_adapter.c
index 260956d5e7..f774c83ec3 100644
--- a/bfdd/ptm_adapter.c
+++ b/bfdd/ptm_adapter.c
@@ -23,6 +23,10 @@
struct ptm_client_notification {
struct bfd_session *pcn_bs;
struct ptm_client *pcn_pc;
+ /* Profile the client registered the session with, empty if none. */
+ char pcn_profile[BFD_PROFILE_NAME_LEN];
+ /* Order of the registration that set the profile. */
+ uint64_t pcn_seq;
TAILQ_ENTRY(ptm_client_notification) pcn_entry;
};
@@ -38,6 +42,8 @@ TAILQ_HEAD(pcqueue, ptm_client);
static struct pcqueue pcqueue;
static struct zclient *bfd_zclient;
+/* Number of client registrations, to order their profiles. */
+static uint64_t pcn_seq;
/*
@@ -481,6 +487,7 @@ stream_failure:
static void bfdd_dest_register(struct stream *msg, vrf_id_t vrf_id)
{
+ struct ptm_client_notification *pcn;
struct ptm_client *pc;
struct bfd_session *bs;
struct bfd_peer_cfg bpc;
@@ -512,13 +519,31 @@ static void bfdd_dest_register(struct stream *msg, vrf_id_t vrf_id)
* BFD daemon (this code) on the other hand only supports
* changing peer configuration manually (through `peer` node)
* or via profiles.
+ *
+ * A profile configured in the `peer` node takes precedence.
*/
- if (bpc.bpc_has_profile)
+ if (bpc.bpc_has_profile && !CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG_PROFILE))
bfd_profile_apply(bpc.bpc_profile, bs);
+
+ /*
+ * The session has no client yet, because a `peer` node
+ * created it or its clients all left: save the peer settings
+ * of this one, as ptm_bfd_sess_new() would have.
+ */
+ if (bs->refcount == (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG) ? 1 : 0))
+ bfd_session_save_client_config(bs, &bpc);
}
/* Create client peer notification register. */
- pcn_new(pc, bs);
+ pcn = pcn_new(pc, bs);
+
+ /*
+ * Remember the client's profile, to give it back to the session
+ * when the `peer` node configuration goes away.
+ */
+ strlcpy(pcn->pcn_profile, bpc.bpc_has_profile ? bpc.bpc_profile : "",
+ sizeof(pcn->pcn_profile));
+ pcn->pcn_seq = ++pcn_seq;
ptm_bfd_notify(bs, bs->ses_state);
}
@@ -1003,6 +1028,27 @@ static struct ptm_client_notification *pcn_lookup(struct ptm_client *pc,
return pcn;
}
+const char *ptm_bfd_client_profile(const struct bfd_session *bs)
+{
+ struct ptm_client_notification *pcn, *last = NULL;
+ struct ptm_client *pc;
+
+ /*
+ * The lists are ordered by first registration, not by the last one:
+ * compare the registrations.
+ */
+ TAILQ_FOREACH (pc, &pcqueue, pc_entry) {
+ TAILQ_FOREACH (pcn, &pc->pc_pcnqueue, pcn_entry) {
+ if (pcn->pcn_bs != bs || !pcn->pcn_profile[0])
+ continue;
+ if (last == NULL || pcn->pcn_seq > last->pcn_seq)
+ last = pcn;
+ }
+ }
+
+ return last ? last->pcn_profile : NULL;
+}
+
static void pcn_free(struct ptm_client_notification *pcn)
{
struct ptm_client *pc;
diff --git a/tests/topotests/bfd_profile_shared_peer/__init__.py b/tests/topotests/bfd_profile_shared_peer/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/topotests/bfd_profile_shared_peer/r1/frr.conf b/tests/topotests/bfd_profile_shared_peer/r1/frr.conf
new file mode 100644
index 0000000000..ea94f09cc7
--- /dev/null
+++ b/tests/topotests/bfd_profile_shared_peer/r1/frr.conf
@@ -0,0 +1,32 @@
+!
+interface r1-eth0
+ ip address 192.168.1.1/24
+!
+interface r1-eth1
+ ip address 192.168.2.1/24
+!
+bfd
+ profile slow
+ transmit-interval 2000
+ receive-interval 2000
+ !
+ profile fast
+ transmit-interval 700
+ receive-interval 700
+ !
+ profile medium
+ transmit-interval 1200
+ receive-interval 1200
+ !
+!
+router bgp 65001
+ no bgp ebgp-requires-policy
+ neighbor 192.168.1.2 remote-as external
+ neighbor 192.168.1.2 bfd
+ neighbor 192.168.1.2 bfd profile slow
+ neighbor 192.168.2.2 remote-as external
+ neighbor 192.168.2.2 ebgp-multihop
+ neighbor 192.168.2.2 update-source 192.168.2.1
+ neighbor 192.168.2.2 bfd
+ neighbor 192.168.2.2 bfd 4 900 900
+!
diff --git a/tests/topotests/bfd_profile_shared_peer/r2/frr.conf b/tests/topotests/bfd_profile_shared_peer/r2/frr.conf
new file mode 100644
index 0000000000..b0b96f5698
--- /dev/null
+++ b/tests/topotests/bfd_profile_shared_peer/r2/frr.conf
@@ -0,0 +1,16 @@
+!
+interface r2-eth0
+ ip address 192.168.1.2/24
+!
+interface r2-eth1
+ ip address 192.168.2.2/24
+!
+router bgp 65002
+ no bgp ebgp-requires-policy
+ neighbor 192.168.1.1 remote-as external
+ neighbor 192.168.1.1 bfd
+ neighbor 192.168.2.1 remote-as external
+ neighbor 192.168.2.1 ebgp-multihop
+ neighbor 192.168.2.1 update-source 192.168.2.2
+ neighbor 192.168.2.1 bfd
+!
diff --git a/tests/topotests/bfd_profile_shared_peer/test_bfd_profile_shared_peer.py b/tests/topotests/bfd_profile_shared_peer/test_bfd_profile_shared_peer.py
new file mode 100644
index 0000000000..6e4e34feeb
--- /dev/null
+++ b/tests/topotests/bfd_profile_shared_peer/test_bfd_profile_shared_peer.py
@@ -0,0 +1,399 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+
+#
+# test_bfd_profile_shared_peer.py
+#
+# Copyright 2026 6WIND S.A.
+#
+
+"""
+test_bfd_profile_shared_peer.py: check that a 'bfd / peer' node sharing the
+session of a BFD client (bgpd) overrides the client's settings while it
+exists, and leaves nothing behind once removed.
+
+r1 has three profiles, slow (2000ms), fast (700ms) and medium (1200ms), and
+two BGP neighbors on r2, both with BFD:
+- 192.168.1.2, single hop, registered with profile slow;
+- 192.168.2.2, multihop (hop count 255, so minimum TTL 1), registered with
+ timers 900ms and detect multiplier 4.
+One test adds a static route through 192.168.1.2 with BFD, so that staticd
+shares the session of bgpd. The tests add and remove 'peer' nodes on r1,
+which bfdd attaches to the sessions of the clients, and check the local
+settings of those sessions.
+"""
+
+import os
+import sys
+import json
+import pytest
+
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+
+# pylint: disable=C0413
+from lib import topotest
+from lib.topogen import Topogen, get_topogen
+from lib.common_config import step
+
+pytestmark = [pytest.mark.bfdd, pytest.mark.bgpd]
+
+SHOP = "192.168.1.2"
+MHOP = "192.168.2.2 multihop local-address 192.168.2.1"
+STATIC_PREFIX = "10.9.9.0/24"
+MHOP_CLIENT = {
+ "receive-interval": 900,
+ "transmit-interval": 900,
+ "detect-multiplier": 4,
+ "minimum-ttl": 1,
+}
+
+
+def build_topo(tgen):
+ tgen.add_router("r1")
+ tgen.add_router("r2")
+
+ switch = tgen.add_switch("s1")
+ switch.add_link(tgen.gears["r1"])
+ switch.add_link(tgen.gears["r2"])
+
+ switch = tgen.add_switch("s2")
+ switch.add_link(tgen.gears["r1"])
+ switch.add_link(tgen.gears["r2"])
+
+
+def setup_module(mod):
+ tgen = Topogen(build_topo, mod.__name__)
+ tgen.start_topology()
+
+ for router in tgen.routers().values():
+ router.load_frr_config()
+
+ tgen.start_router()
+
+
+def teardown_module(mod):
+ tgen = get_topogen()
+ tgen.stop_topology()
+
+
+def expect_session(peer, expected, count=10):
+ "Wait for the r1 session to peer to be up with the expected settings."
+ r1 = get_topogen().gears["r1"]
+
+ def _check():
+ output = r1.vtysh_cmd("show bfd peer {} json".format(peer))
+ try:
+ session = json.loads(output)
+ except ValueError:
+ return False
+ return topotest.json_cmp(session, dict(expected, status="up"))
+
+ _, result = topotest.run_and_expect(_check, None, count=count, wait=1)
+ assert result is None, "r1 session to {} is not up with {}: {}".format(
+ peer, expected, result
+ )
+
+
+def expect_no_session(address):
+ "Wait for r1 to have no session to address."
+ r1 = get_topogen().gears["r1"]
+
+ def _check():
+ output = json.loads(r1.vtysh_cmd("show bfd peers json"))
+ return any(session["peer"] == address for session in output)
+
+ _, result = topotest.run_and_expect(_check, False, count=10, wait=1)
+ assert not result, "r1 session to {} is not deleted".format(address)
+
+
+def expect_timers(interval, count=10):
+ "Wait for the r1 session to 192.168.1.2 to be up with these timers (ms)."
+ expected = {"receive-interval": interval, "transmit-interval": interval}
+ expect_session(SHOP, expected, count)
+
+
+def configure(commands):
+ get_topogen().gears["r1"].vtysh_cmd("configure terminal\n" + commands)
+
+
+def notifications(peer):
+ "Count the notifications bfdd sent for the r1 session to peer."
+ r1 = get_topogen().gears["r1"]
+ output = json.loads(r1.vtysh_cmd("show bfd peer {} counters json".format(peer)))
+ return output["zebra-notifications"]
+
+
+def register(commands, peer=SHOP):
+ """
+ Make a client register the session to peer again, and wait for bfdd to
+ process the registration: the registration goes through zebra, and bfdd
+ answers each one with a notification.
+ """
+ count = notifications(peer)
+ configure(commands)
+ _, result = topotest.run_and_expect(
+ lambda: notifications(peer) > count, True, count=10, wait=1
+ )
+ assert result, "bfdd did not process the registration: " + commands
+
+
+def register_bgp(profile):
+ "Make bgpd register the session to 192.168.1.2 with another profile."
+ register("router bgp 65001\n neighbor {} bfd profile {}".format(SHOP, profile))
+
+
+def register_static(profile):
+ "Make staticd register the session to 192.168.1.2 with this profile."
+ register("ip route {} {} bfd profile {}".format(STATIC_PREFIX, SHOP, profile))
+
+
+def test_bfd_client_profile():
+ "bgpd registers the sessions with its own settings."
+ tgen = get_topogen()
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("bgpd registers 192.168.1.2 with profile slow")
+ expect_timers(2000, count=60)
+
+ step("bgpd registers 192.168.2.2 multihop with timers 900 and multiplier 4")
+ expect_session(MHOP, MHOP_CLIENT, count=60)
+
+
+def test_bfd_peer_timers_removed():
+ "The timers of a removed peer node do not stay on the session."
+ tgen = get_topogen()
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Add peer 192.168.1.2 with its own timers, which take precedence")
+ configure(
+ """bfd
+ peer 192.168.1.2
+ transmit-interval 1500
+ receive-interval 1500
+ """
+ )
+ expect_timers(1500)
+
+ step("Remove the peer: the session goes back to profile slow")
+ configure("bfd\n no peer 192.168.1.2")
+ expect_timers(2000)
+
+ step("bgpd registers the session again with profile medium, then slow")
+ register_bgp("medium")
+ expect_timers(1200)
+ register_bgp("slow")
+ expect_timers(2000)
+
+
+def test_bfd_peer_profile_removed():
+ "The profile of a removed peer node does not stay on the session."
+ tgen = get_topogen()
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Add peer 192.168.1.2 with profile fast, which takes precedence")
+ configure("bfd\n peer 192.168.1.2\n profile fast")
+ expect_timers(700)
+
+ step("Remove the peer: the session goes back to profile slow")
+ configure("bfd\n no peer 192.168.1.2")
+ expect_timers(2000)
+
+
+def test_bfd_peer_profile_precedence():
+ "The profile of a peer node takes precedence over a client registration."
+ tgen = get_topogen()
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Add peer 192.168.1.2 with profile fast")
+ configure("bfd\n peer 192.168.1.2\n profile fast")
+ expect_timers(700)
+
+ step("bgpd registers the session with profile medium: profile fast stays")
+ register_bgp("medium")
+ expect_timers(700)
+
+ step("Remove the profile of the peer: the session takes profile medium")
+ configure("bfd\n peer 192.168.1.2\n no profile fast")
+ expect_timers(1200)
+
+ step("bgpd registers the session with profile slow, then the peer goes")
+ register_bgp("slow")
+ expect_timers(2000)
+ configure("bfd\n no peer 192.168.1.2")
+ expect_timers(2000)
+
+
+def test_bfd_two_clients():
+ "Without the peer profile, the session takes the last client profile."
+ tgen = get_topogen()
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("staticd registers 192.168.1.2 too, with profile medium")
+ register_static("medium")
+ expect_timers(1200)
+
+ # bfdd orders its clients by their first message, which comes from
+ # each daemon at startup: register them in both orders.
+ step("Add peer 192.168.1.2 with profile fast")
+ configure("bfd\n peer 192.168.1.2\n profile fast")
+ expect_timers(700)
+
+ step("staticd registers with profile slow, then bgpd with medium")
+ register_static("slow")
+ register_bgp("medium")
+ expect_timers(700)
+
+ step("Remove the profile of the peer: the session takes profile medium")
+ configure("bfd\n peer 192.168.1.2\n no profile fast")
+ expect_timers(1200)
+
+ step("Add profile fast to the peer again")
+ configure("bfd\n peer 192.168.1.2\n profile fast")
+ expect_timers(700)
+
+ step("bgpd registers with profile slow, then staticd with medium")
+ register_bgp("slow")
+ register_static("medium")
+ expect_timers(700)
+
+ step("Remove the peer: the session takes profile medium")
+ configure("bfd\n no peer 192.168.1.2")
+ expect_timers(1200)
+
+ step("Remove the static route, bgpd registers with profile slow")
+ configure("no ip route {} {}".format(STATIC_PREFIX, SHOP))
+ register_bgp("medium")
+ register_bgp("slow")
+ expect_timers(2000)
+
+
+def test_bfd_client_peer_settings():
+ "A removed peer node gives the session back the settings of its client."
+ tgen = get_topogen()
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Add, then remove, peer 192.168.2.2 without settings: nothing changes")
+ configure("bfd\n peer " + MHOP)
+ expect_session(MHOP, MHOP_CLIENT)
+ configure("bfd\n no peer " + MHOP)
+ expect_session(MHOP, MHOP_CLIENT)
+
+ step("Add peer 192.168.2.2 with its own timers and minimum TTL")
+ configure(
+ """bfd
+ peer {}
+ transmit-interval 1500
+ receive-interval 1500
+ minimum-ttl 10
+ """.format(
+ MHOP
+ )
+ )
+ expected = {
+ "receive-interval": 1500,
+ "transmit-interval": 1500,
+ "detect-multiplier": 4,
+ "minimum-ttl": 10,
+ }
+ expect_session(MHOP, expected)
+
+ step("Remove the peer: the session goes back to the settings of bgpd")
+ configure("bfd\n no peer " + MHOP)
+ expect_session(MHOP, MHOP_CLIENT)
+
+
+def test_bfd_peer_before_client():
+ "A peer node created before the client gives way to the client settings."
+ tgen = get_topogen()
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("bgpd deregisters 192.168.2.2, which deletes the session")
+ configure("router bgp 65001\n no neighbor 192.168.2.2 bfd")
+ expect_no_session("192.168.2.2")
+
+ step("Add peer 192.168.2.2 with minimum TTL 1, then bgpd registers it")
+ configure("bfd\n peer {}\n minimum-ttl 1".format(MHOP))
+ expected = {
+ "receive-interval": 300,
+ "transmit-interval": 300,
+ "detect-multiplier": 3,
+ "minimum-ttl": 1,
+ }
+ expect_session(MHOP, expected, count=30)
+ # A single command, so a single registration: bfdd keeps the settings
+ # of the first one, as it would for a session the client creates.
+ register(
+ "router bgp 65001\n neighbor 192.168.2.2 bfd 4 900 900",
+ peer=MHOP,
+ )
+ expect_session(MHOP, expected)
+
+ step("Remove the peer: the session takes the settings of bgpd")
+ configure("bfd\n no peer " + MHOP)
+ expect_session(MHOP, MHOP_CLIENT)
+
+
+def test_bfd_no_bfd():
+ "'no bfd' does not leave the peer node settings on the session."
+ tgen = get_topogen()
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Add peer 192.168.1.2 with profile fast and its own timers")
+ configure(
+ """bfd
+ peer 192.168.1.2
+ profile fast
+ transmit-interval 1500
+ receive-interval 1500
+ """
+ )
+ expect_timers(1500)
+
+ step("Remove the whole bfd node, profiles included: bfdd default timers")
+ configure("no bfd")
+ expect_timers(300)
+
+ step("Add the profiles again: bgpd registers the session with them")
+ configure(
+ """bfd
+ profile slow
+ transmit-interval 2000
+ receive-interval 2000
+ exit
+ profile fast
+ transmit-interval 700
+ receive-interval 700
+ exit
+ profile medium
+ transmit-interval 1200
+ receive-interval 1200
+ exit
+ """
+ )
+ register_bgp("medium")
+ expect_timers(1200)
+ register_bgp("slow")
+ expect_timers(2000)
+
+
+def test_memory_leak():
+ "Run the memory leak test and report results."
+ tgen = get_topogen()
+ if not tgen.is_memleak_enabled():
+ pytest.skip("Memory leak test/report is disabled")
+
+ tgen.report_memory_leaks()
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))