From 2bd5cd1b81a91dc6f38547f75b74e97f4e9ea5e9 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Thu, 19 Dec 2024 08:58:02 +0100 Subject: [PATCH] bgpd, topotests: bmp imported bgp, add loc-rib peer up support when router-id changes Add the emission of a loc-rib peer up event for an imported bgp instance at route-id reconfiguration. Add a test to control in the BMP collector that the peer up message is the one from that BGP instance. Signed-off-by: Philippe Guibert --- bgpd/bgp_bmp.c | 56 ++++++++++++++++++----- tests/topotests/bgp_bmp/test_bgp_bmp_3.py | 51 +++++++++++++++++++++ 2 files changed, 96 insertions(+), 11 deletions(-) diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index 880cb2c8f4..313834c023 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -3394,24 +3394,58 @@ static int bgp_bmp_early_fini(void) return 0; } -/* called when the routerid of an instance changes */ -static int bmp_bgp_attribute_updated(struct bgp *bgp, bool withdraw) +static int bmp_bgp_attribute_updated_instance(struct bmp_targets *bt, enum bmp_vrf_state *vrf_state, + struct bgp *bgp, bool withdraw, struct stream *s) { - struct bmp_bgp *bmpbgp = bmp_bgp_find(bgp); - - if (!bmpbgp) - return 0; - - bmp_bgp_update_vrf_status(&bmpbgp->vrf_state, bgp, vrf_state_unknown); - - if (bmpbgp->vrf_state == vrf_state_down) + bmp_bgp_update_vrf_status(vrf_state, bgp, vrf_state_unknown); + if (*vrf_state == vrf_state_down) /* do not send peer events, router id will not be enough to set state to up */ return 0; /* vrf_state is up: trigger a peer event */ - bmp_send_all_safe(bmpbgp, bmp_peerstate(bgp->peer_self, withdraw)); + bmp_send_bt(bt, s); + return 1; +} + +/* called when the routerid of an instance changes */ +static int bmp_bgp_attribute_updated(struct bgp *bgp, bool withdraw) +{ + struct bmp_bgp *bmpbgp = bmp_bgp_find(bgp); + struct bgp *bgp_vrf; + struct bmp_targets *bt; + struct listnode *node; + struct bmp_imported_bgp *bib; + int ret = 0; + struct stream *s = bmp_peerstate(bgp->peer_self, withdraw); + + if (!s) + return 0; + + if (bmpbgp) { + frr_each (bmp_targets, &bmpbgp->targets, bt) { + ret = bmp_bgp_attribute_updated_instance(bt, &bmpbgp->vrf_state, bgp, + withdraw, s); + } + } + + for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) { + if (bgp == bgp_vrf) + continue; + bmpbgp = bmp_bgp_find(bgp_vrf); + if (!bmpbgp) + continue; + frr_each (bmp_targets, &bmpbgp->targets, bt) { + frr_each (bmp_imported_bgps, &bt->imported_bgps, bib) { + if (bgp_lookup_by_name(bib->name) != bgp) + continue; + ret += bmp_bgp_attribute_updated_instance(bt, &bib->vrf_state, bgp, + withdraw, s); + } + } + } + stream_free(s); return 1; } diff --git a/tests/topotests/bgp_bmp/test_bgp_bmp_3.py b/tests/topotests/bgp_bmp/test_bgp_bmp_3.py index 088f4cb453..06d9f1f9e6 100644 --- a/tests/topotests/bgp_bmp/test_bgp_bmp_3.py +++ b/tests/topotests/bgp_bmp/test_bgp_bmp_3.py @@ -263,6 +263,57 @@ def test_peer_down(): assert success, "Checking the updated prefixes has been failed !." +def test_bgp_routerid_changed(): + """ + Checking for BGP loc-rib up messages with new router-id + """ + tgen = get_topogen() + + tgen.gears["r1import"].vtysh_cmd( + """ + configure terminal + router bgp 65501 vrf vrf1 + bgp router-id 192.168.1.77 + """ + ) + + peers = ["0.0.0.0"] + + logger.info( + "checking for BMP peer down LOC-RIB message with router-id set to 192.168.0.1." + ) + test_func = partial( + bmp_check_for_peer_message, + peers, + "peer down", + tgen.gears["bmp1import"], + os.path.join(tgen.logdir, "bmp1import", "bmp.log"), + is_rd_instance=True, + peer_bgp_id="192.168.0.1", + ) + success, _ = topotest.run_and_expect(test_func, True, count=30, wait=1) + assert ( + success + ), "Checking the BMP peer down LOC-RIB message with router-id set to 192.168.0.1 failed !." + + logger.info( + "checking for BMP peer up LOC-RIB message with router-id set to 192.168.1.77." + ) + test_func = partial( + bmp_check_for_peer_message, + peers, + "peer up", + tgen.gears["bmp1import"], + os.path.join(tgen.logdir, "bmp1import", "bmp.log"), + is_rd_instance=True, + peer_bgp_id="192.168.1.77", + ) + success, _ = topotest.run_and_expect(test_func, True, count=30, wait=1) + assert ( + success + ), "Checking the BMP peer up LOC-RIB message with router-id set to 192.168.1.77 failed !." + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args))