From 51cedaa30cd5da7705e421d04b67b9b8ac5f9ead Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Tue, 12 Nov 2024 09:41:46 +0100 Subject: [PATCH] topotests: bmp, test syncro for pre/post-policy of imported bgps Add a test that controls that the configuration of an imported BGP instance triggers a re-syncronisation. Ensure that changing an attribute like route distinguisher triggers also a re-syncronisation. Signed-off-by: Philippe Guibert --- .../bmp1import/bmp-update-loc-rib-step2.json | 34 +++++++ .../bmp-update-post-policy-step2.json | 36 +++++++ .../bmp-update-pre-policy-step2.json | 36 +++++++ .../bmp-withdraw-post-policy-step2.json | 36 ------- tests/topotests/bgp_bmp/test_bgp_bmp_3.py | 96 ++++++++++++++++++- 5 files changed, 199 insertions(+), 39 deletions(-) create mode 100644 tests/topotests/bgp_bmp/bmp1import/bmp-update-loc-rib-step2.json create mode 100644 tests/topotests/bgp_bmp/bmp1import/bmp-update-post-policy-step2.json create mode 100644 tests/topotests/bgp_bmp/bmp1import/bmp-update-pre-policy-step2.json delete mode 100644 tests/topotests/bgp_bmp/bmp1import/bmp-withdraw-post-policy-step2.json diff --git a/tests/topotests/bgp_bmp/bmp1import/bmp-update-loc-rib-step2.json b/tests/topotests/bgp_bmp/bmp1import/bmp-update-loc-rib-step2.json new file mode 100644 index 0000000000..60066d502c --- /dev/null +++ b/tests/topotests/bgp_bmp/bmp1import/bmp-update-loc-rib-step2.json @@ -0,0 +1,34 @@ +{ + "loc-rib": { + "update": { + "172.31.0.77/32": { + "as_path": "", + "bgp_nexthop": "192.168.1.3", + "bmp_log_type": "update", + "ip_prefix": "172.31.0.77/32", + "is_filtered": false, + "origin": "IGP", + "peer_asn": 65501, + "peer_bgp_id": "192.168.0.1", + "peer_distinguisher": "666:22", + "peer_type": "loc-rib instance", + "policy": "loc-rib" + }, + "2001::1125/128": { + "afi": 2, + "as_path": "", + "bmp_log_type": "update", + "ip_prefix": "2001::1125/128", + "is_filtered": false, + "nxhp_ip": "192:167::3", + "origin": "IGP", + "peer_asn": 65501, + "peer_bgp_id": "192.168.0.1", + "peer_distinguisher": "666:22", + "peer_type": "loc-rib instance", + "policy": "loc-rib", + "safi": 1 + } + } + } +} diff --git a/tests/topotests/bgp_bmp/bmp1import/bmp-update-post-policy-step2.json b/tests/topotests/bgp_bmp/bmp1import/bmp-update-post-policy-step2.json new file mode 100644 index 0000000000..b555c2a371 --- /dev/null +++ b/tests/topotests/bgp_bmp/bmp1import/bmp-update-post-policy-step2.json @@ -0,0 +1,36 @@ +{ + "post-policy": { + "update": { + "172.31.0.77/32": { + "as_path": "", + "bgp_nexthop": "192.168.1.3", + "bmp_log_type": "update", + "ip_prefix": "172.31.0.77/32", + "ipv6": false, + "origin": "IGP", + "peer_asn": 65501, + "peer_bgp_id": "192.168.1.3", + "peer_distinguisher": "666:22", + "peer_ip": "192.168.1.3", + "peer_type": "route distinguisher instance", + "policy": "post-policy" + }, + "2001::1125/128": { + "afi": 2, + "as_path": "", + "bmp_log_type": "update", + "ip_prefix": "2001::1125/128", + "ipv6": true, + "nxhp_ip": "192:167::3", + "origin": "IGP", + "peer_asn": 65501, + "peer_bgp_id": "192.168.1.3", + "peer_distinguisher": "666:22", + "peer_ip": "192:167::3", + "peer_type": "route distinguisher instance", + "policy": "post-policy", + "safi": 1 + } + } + } +} diff --git a/tests/topotests/bgp_bmp/bmp1import/bmp-update-pre-policy-step2.json b/tests/topotests/bgp_bmp/bmp1import/bmp-update-pre-policy-step2.json new file mode 100644 index 0000000000..20549926d5 --- /dev/null +++ b/tests/topotests/bgp_bmp/bmp1import/bmp-update-pre-policy-step2.json @@ -0,0 +1,36 @@ +{ + "pre-policy": { + "update": { + "172.31.0.77/32": { + "as_path": "", + "bgp_nexthop": "192.168.1.3", + "bmp_log_type": "update", + "ip_prefix": "172.31.0.77/32", + "ipv6": false, + "origin": "IGP", + "peer_asn": 65501, + "peer_bgp_id": "192.168.1.3", + "peer_distinguisher": "666:22", + "peer_ip": "192.168.1.3", + "peer_type": "route distinguisher instance", + "policy": "pre-policy" + }, + "2001::1125/128": { + "afi": 2, + "as_path": "", + "bmp_log_type": "update", + "ip_prefix": "2001::1125/128", + "ipv6": true, + "nxhp_ip": "192:167::3", + "origin": "IGP", + "peer_asn": 65501, + "peer_bgp_id": "192.168.1.3", + "peer_distinguisher": "666:22", + "peer_ip": "192:167::3", + "peer_type": "route distinguisher instance", + "policy": "pre-policy", + "safi": 1 + } + } + } +} diff --git a/tests/topotests/bgp_bmp/bmp1import/bmp-withdraw-post-policy-step2.json b/tests/topotests/bgp_bmp/bmp1import/bmp-withdraw-post-policy-step2.json deleted file mode 100644 index 9eb221d4d0..0000000000 --- a/tests/topotests/bgp_bmp/bmp1import/bmp-withdraw-post-policy-step2.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "post-policy": { - "withdraw": { - "2001::1111/128": { - "afi": 2, - "bmp_log_type": "withdraw", - "ip_prefix": "2001::1111/128", - "ipv6": true, - "label": 0, - "peer_asn": 65502, - "peer_bgp_id": "192.168.0.2", - "peer_distinguisher": "0:0", - "peer_ip": "192:168::2", - "peer_type": "global instance", - "policy": "post-policy", - "rd": "555:2", - "safi": 128 - }, - "172.31.0.15/32": { - "afi": 1, - "bmp_log_type": "withdraw", - "ip_prefix": "172.31.0.15/32", - "ipv6": false, - "label": 0, - "peer_asn": 65502, - "peer_bgp_id": "192.168.0.2", - "peer_distinguisher": "0:0", - "peer_ip": "192.168.0.2", - "peer_type": "global instance", - "policy": "post-policy", - "rd": "444:2", - "safi": 128 - } - } - } -} diff --git a/tests/topotests/bgp_bmp/test_bgp_bmp_3.py b/tests/topotests/bgp_bmp/test_bgp_bmp_3.py index a108774821..212cf9e696 100644 --- a/tests/topotests/bgp_bmp/test_bgp_bmp_3.py +++ b/tests/topotests/bgp_bmp/test_bgp_bmp_3.py @@ -124,6 +124,32 @@ def test_bgp_convergence(): assert result is True, "BGP is not converging" +def _test_prefixes_syncro(policy, vrf=None, step=1): + """ + Check that the given policy has syncronised the previously received BGP + updates. + """ + tgen = get_topogen() + + prefixes = ["172.31.0.77/32", "2001::1125/128"] + # check + test_func = partial( + bmp_check_for_prefixes, + prefixes, + "update", + policy, + step, + tgen.gears["bmp1import"], + os.path.join(tgen.logdir, "bmp1import"), + tgen.gears["r1import"], + f"{CWD}/bmp1import", + UPDATE_EXPECTED_JSON, + LOC_RIB, + ) + success, res = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert success, "Checking the updated prefixes has failed ! %s" % res + + def _test_prefixes(policy, vrf=None, step=0): """ Setup the BMP monitor policy, Add and withdraw ipv4/v6 prefixes. @@ -270,6 +296,63 @@ def test_peer_down(): assert success, "Checking the updated prefixes has been failed !." +def test_reconfigure_prefixes(): + """ + Reconfigured BGP networks from R3. Check for BGP VRF update messages + """ + + tgen = get_topogen() + + prefixes = ["172.31.0.77/32", "2001::1125/128"] + bgp_configure_prefixes( + tgen.gears["r3"], + 65501, + "unicast", + prefixes, + vrf=None, + update=True, + ) + + for ipver in [4, 6]: + ref_file = "{}/r1import/show-bgp-{}-ipv{}-{}-step{}.json".format( + CWD, "vrf1", ipver, "update", 1 + ) + expected = json.loads(open(ref_file).read()) + + test_func = partial( + topotest.router_json_cmp, + tgen.gears["r1import"], + f"show bgp vrf vrf1 ipv{ipver} json", + expected, + ) + _, res = topotest.run_and_expect(test_func, None, count=30, wait=1) + assertmsg = f"r1: BGP IPv{ipver} convergence failed" + assert res is None, assertmsg + + +def test_monitor_syncro(): + """ + Checking for BMP peers down messages + """ + tgen = get_topogen() + + tgen.gears["r1import"].vtysh_cmd( + """ + configure terminal + router bgp 65501 + bmp targets bmp1 + bmp import-vrf-view vrf1 + """ + ) + + logger.info("*** Unicast prefixes pre-policy logging ***") + _test_prefixes_syncro(PRE_POLICY, vrf="vrf1") + logger.info("*** Unicast prefixes post-policy logging ***") + _test_prefixes_syncro(POST_POLICY, vrf="vrf1") + logger.info("*** Unicast prefixes loc-rib logging ***") + _test_prefixes_syncro(LOC_RIB, vrf="vrf1") + + def test_reconfigure_route_distinguisher_vrf1(): """ Checking for BMP peers down messages @@ -293,7 +376,7 @@ def test_reconfigure_route_distinguisher_vrf1(): """ ) logger.info( - "checking for BMP peer down LOC-RIB message with route-distinguisher set to 444:1" + "Checking for BMP peer down LOC-RIB message with route-distinguisher set to 444:1" ) test_func = partial( bmp_check_for_peer_message, @@ -310,7 +393,7 @@ def test_reconfigure_route_distinguisher_vrf1(): ), "Checking the BMP peer down LOC-RIB message with route-distinguisher set to 444:1 failed !." logger.info( - "checking for BMP peer up LOC-RIB messages with route-distinguisher set to 666:22" + "Checking for BMP peer up LOC-RIB messages with route-distinguisher set to 666:22" ) test_func = partial( bmp_check_for_peer_message, @@ -327,7 +410,7 @@ def test_reconfigure_route_distinguisher_vrf1(): ), "Checking the BMP peer up LOC-RIB message with route-distinguisher set to 666:22 failed !." logger.info( - "checking for BMP peer up messages with route-distinguisher set to 666:22" + "Checking for BMP peer up messages with route-distinguisher set to 666:22" ) peers = ["192.168.1.3", "192:167::3"] test_func = partial( @@ -344,6 +427,13 @@ def test_reconfigure_route_distinguisher_vrf1(): success ), "Checking the BMP peer up messages with route-distinguisher set to 666:22 failed !." + logger.info("*** Unicast prefixes pre-policy logging ***") + _test_prefixes_syncro(PRE_POLICY, vrf="vrf1", step=2) + logger.info("*** Unicast prefixes post-policy logging ***") + _test_prefixes_syncro(POST_POLICY, vrf="vrf1", step=2) + logger.info("*** Unicast prefixes loc-rib logging ***") + _test_prefixes_syncro(LOC_RIB, vrf="vrf1", step=2) + def test_bgp_routerid_changed(): """ -- 2.39.5