From eb570f0a70b769afafa17588ddeaec6679744c02 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 18 Dec 2024 16:31:05 +0100 Subject: [PATCH] topotests: bgp_bmp, add a test to check for bgp vrf peer loc-rib message Add a test where, when the vrf interface is flapping, a peer down and a peer up message are sent. This test, when used with ASAN, detects the memory leak of the open_tx and open_rx messages of the loc-rib. Refresh the method of updating the SEQ value when reading the peer messages: only update to the last matching SEQ value. Signed-off-by: Philippe Guibert --- tests/topotests/bgp_bmp/bgpbmp.py | 16 +++++++--- tests/topotests/bgp_bmp/test_bgp_bmp_2.py | 37 +++++++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/tests/topotests/bgp_bmp/bgpbmp.py b/tests/topotests/bgp_bmp/bgpbmp.py index eac78a63f7..8c14c4c9de 100644 --- a/tests/topotests/bgp_bmp/bgpbmp.py +++ b/tests/topotests/bgp_bmp/bgpbmp.py @@ -193,6 +193,7 @@ def bmp_check_for_peer_message( Check for the presence of a peer up message for the peer """ global SEQ + last_seq = SEQ # we care only about the new messages messages = [ @@ -215,16 +216,23 @@ def bmp_check_for_peer_message( ): if is_rd_instance and m["peer_type"] != "route distinguisher instance": continue - peers.append(m["peer_ip"]) + peers.append((m["peer_ip"], m["seq"])) elif m["policy"] == "loc-rib" and m["bmp_log_type"] == bmp_log_type: - peers.append("0.0.0.0") + peers.append(("0.0.0.0", m["seq"])) # check for prefixes for ep in expected_peers: - if ep not in peers: + for _ip, _seq in peers: + if ep == _ip: + msg = "The peer {} is present in the {} log messages." + logger.debug(msg.format(ep, bmp_log_type)) + if _seq > last_seq: + last_seq = _seq + break + else: msg = "The peer {} is not present in the {} log messages." logger.debug(msg.format(ep, bmp_log_type)) return False - SEQ = messages[-1]["seq"] + SEQ = last_seq return True diff --git a/tests/topotests/bgp_bmp/test_bgp_bmp_2.py b/tests/topotests/bgp_bmp/test_bgp_bmp_2.py index f16ff2b445..fc0bf1b795 100644 --- a/tests/topotests/bgp_bmp/test_bgp_bmp_2.py +++ b/tests/topotests/bgp_bmp/test_bgp_bmp_2.py @@ -252,6 +252,43 @@ def test_peer_down(): assert success, "Checking the updated prefixes has been failed !." +def test_bgp_instance_flapping(): + """ + Checking for BGP loc-rib up messages + """ + tgen = get_topogen() + + # create flapping at BMP + tgen.net["r1vrf"].cmd("ip link set dev vrf1 down") + + peers = ["0.0.0.0"] + logger.info("checking for BMP peer down LOC-RIB message.") + test_func = partial( + bmp_check_for_peer_message, + peers, + "peer down", + tgen.gears["bmp1vrf"], + os.path.join(tgen.logdir, "bmp1vrf", "bmp.log"), + is_rd_instance=True, + ) + success, _ = topotest.run_and_expect(test_func, True, count=30, wait=1) + assert success, "Checking the BMP peer down LOC-RIB message failed !." + + tgen.net["r1vrf"].cmd("ip link set dev vrf1 up") + + logger.info("checking for BMP peer up LOC-RIB message.") + test_func = partial( + bmp_check_for_peer_message, + peers, + "peer up", + tgen.gears["bmp1vrf"], + os.path.join(tgen.logdir, "bmp1vrf", "bmp.log"), + is_rd_instance=True, + ) + success, _ = topotest.run_and_expect(test_func, True, count=30, wait=1) + assert success, "Checking the BMP peer up LOC-RIB message failed !." + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) -- 2.39.5