diff --git a/tests/topotests/bgp_bmp/bmp1/bmp-update-loc-rib-step1.json b/tests/topotests/bgp_bmp/bmp1/bmp-update-loc-rib-step1.json index ae5e921779..27f1fe6e27 100644 --- a/tests/topotests/bgp_bmp/bmp1/bmp-update-loc-rib-step1.json +++ b/tests/topotests/bgp_bmp/bmp1/bmp-update-loc-rib-step1.json @@ -14,11 +14,11 @@ "peer_type": "loc-rib instance", "policy": "loc-rib" }, - "2111::1111/128": { + "2001::1111/128": { "afi": 2, "as_path": "65501 65502", "bmp_log_type": "update", - "ip_prefix": "2111::1111/128", + "ip_prefix": "2001::1111/128", "is_filtered": false, "nxhp_ip": "192:168::2", "origin": "IGP", diff --git a/tests/topotests/bgp_bmp/bmp1/bmp-update-loc-rib-step2.json b/tests/topotests/bgp_bmp/bmp1/bmp-update-loc-rib-step2.json index 3e07369a79..0aa6bd4fea 100644 --- a/tests/topotests/bgp_bmp/bmp1/bmp-update-loc-rib-step2.json +++ b/tests/topotests/bgp_bmp/bmp1/bmp-update-loc-rib-step2.json @@ -1,11 +1,11 @@ { "loc-rib": { "update": { - "2001::2222/128": { + "2001::1111/128": { "afi": 2, "as_path": "65501 65502", "bmp_log_type": "update", - "ip_prefix": "2001::2222/128", + "ip_prefix": "2001::1111/128", "is_filtered": false, "label": 105, "nxhp_ip": "192:168::2", @@ -20,11 +20,11 @@ "rd": "555:2", "safi": 128 }, - "172.31.10.1/32": { + "172.31.0.15/32": { "afi": 1, "as_path": "65501 65502", "bmp_log_type": "update", - "ip_prefix": "172.31.10.1/32", + "ip_prefix": "172.31.0.15/32", "is_filtered": false, "label": 102, "nxhp_ip": "192.168.0.2", diff --git a/tests/topotests/bgp_bmp/bmp1/bmp-update-post-policy-step1.json b/tests/topotests/bgp_bmp/bmp1/bmp-update-post-policy-step1.json index d5d9d65182..d30ef9fd32 100644 --- a/tests/topotests/bgp_bmp/bmp1/bmp-update-post-policy-step1.json +++ b/tests/topotests/bgp_bmp/bmp1/bmp-update-post-policy-step1.json @@ -15,11 +15,11 @@ "peer_type": "global instance", "policy": "post-policy" }, - "2111::1111/128": { + "2001::1111/128": { "afi": 2, "as_path": "65501 65502", "bmp_log_type": "update", - "ip_prefix": "2111::1111/128", + "ip_prefix": "2001::1111/128", "ipv6": true, "nxhp_ip": "192:168::2", "origin": "IGP", diff --git a/tests/topotests/bgp_bmp/bmp1/bmp-update-post-policy-step2.json b/tests/topotests/bgp_bmp/bmp1/bmp-update-post-policy-step2.json index 4b49b249f0..9bf2d57769 100644 --- a/tests/topotests/bgp_bmp/bmp1/bmp-update-post-policy-step2.json +++ b/tests/topotests/bgp_bmp/bmp1/bmp-update-post-policy-step2.json @@ -1,11 +1,11 @@ { "post-policy": { "update": { - "172.31.10.1/32": { + "172.31.0.15/32": { "afi": 1, "as_path": "65501 65502", "bmp_log_type": "update", - "ip_prefix": "172.31.10.1/32", + "ip_prefix": "172.31.0.15/32", "ipv6": false, "label": 102, "nxhp_ip": "192.168.0.2", @@ -20,11 +20,11 @@ "rd": "444:2", "safi": 128 }, - "2001::2222/128": { + "2001::1111/128": { "afi": 2, "as_path": "65501 65502", "bmp_log_type": "update", - "ip_prefix": "2001::2222/128", + "ip_prefix": "2001::1111/128", "ipv6": true, "label": 105, "nxhp_ip": "192:168::2", diff --git a/tests/topotests/bgp_bmp/bmp1/bmp-update-pre-policy-step1.json b/tests/topotests/bgp_bmp/bmp1/bmp-update-pre-policy-step1.json index e11badc040..fafe6f7c21 100644 --- a/tests/topotests/bgp_bmp/bmp1/bmp-update-pre-policy-step1.json +++ b/tests/topotests/bgp_bmp/bmp1/bmp-update-pre-policy-step1.json @@ -15,11 +15,11 @@ "peer_type": "global instance", "policy": "pre-policy" }, - "2111::1111/128": { + "2001::1111/128": { "afi": 2, "as_path": "65501 65502", "bmp_log_type": "update", - "ip_prefix": "2111::1111/128", + "ip_prefix": "2001::1111/128", "ipv6": true, "nxhp_ip": "192:168::2", "origin": "IGP", diff --git a/tests/topotests/bgp_bmp/bmp1/bmp-update-pre-policy-step2.json b/tests/topotests/bgp_bmp/bmp1/bmp-update-pre-policy-step2.json index 4cd0c03b3b..95acb5903a 100644 --- a/tests/topotests/bgp_bmp/bmp1/bmp-update-pre-policy-step2.json +++ b/tests/topotests/bgp_bmp/bmp1/bmp-update-pre-policy-step2.json @@ -1,11 +1,11 @@ { "pre-policy": { "update": { - "172.31.10.1/32": { + "172.31.0.15/32": { "afi": 1, "as_path": "65501 65502", "bmp_log_type": "update", - "ip_prefix": "172.31.10.1/32", + "ip_prefix": "172.31.0.15/32", "ipv6": false, "label": 102, "nxhp_ip": "192.168.0.2", @@ -20,11 +20,11 @@ "rd": "444:2", "safi": 128 }, - "2001::2222/128": { + "2001::1111/128": { "afi": 2, "as_path": "65501 65502", "bmp_log_type": "update", - "ip_prefix": "2001::2222/128", + "ip_prefix": "2001::1111/128", "ipv6": true, "label": 105, "nxhp_ip": "192:168::2", diff --git a/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-loc-rib-step1.json b/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-loc-rib-step1.json index 345b52d4bf..3891fbb15e 100644 --- a/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-loc-rib-step1.json +++ b/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-loc-rib-step1.json @@ -11,10 +11,10 @@ "peer_type": "loc-rib instance", "policy": "loc-rib" }, - "2111::1111/128": { + "2001::1111/128": { "afi": 2, "bmp_log_type": "withdraw", - "ip_prefix": "2111::1111/128", + "ip_prefix": "2001::1111/128", "is_filtered": false, "peer_asn": 65501, "peer_bgp_id": "192.168.0.1", diff --git a/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-loc-rib-step2.json b/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-loc-rib-step2.json index 63f48533c7..1e5040ba60 100644 --- a/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-loc-rib-step2.json +++ b/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-loc-rib-step2.json @@ -1,10 +1,10 @@ { "loc-rib": { "withdraw": { - "172.31.10.1/32": { + "172.31.0.15/32": { "afi": 1, "bmp_log_type": "withdraw", - "ip_prefix": "172.31.10.1/32", + "ip_prefix": "172.31.0.15/32", "is_filtered": false, "label": 0, "peer_asn": 65501, @@ -15,10 +15,10 @@ "rd": "444:2", "safi": 128 }, - "2001::2222/128": { + "2001::1111/128": { "afi": 2, "bmp_log_type": "withdraw", - "ip_prefix": "2001::2222/128", + "ip_prefix": "2001::1111/128", "is_filtered": false, "label": 0, "peer_asn": 65501, diff --git a/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-post-policy-step1.json b/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-post-policy-step1.json index de84307a4e..3224b525e2 100644 --- a/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-post-policy-step1.json +++ b/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-post-policy-step1.json @@ -12,10 +12,10 @@ "peer_type": "global instance", "policy": "post-policy" }, - "2111::1111/128": { + "2001::1111/128": { "afi": 2, "bmp_log_type": "withdraw", - "ip_prefix": "2111::1111/128", + "ip_prefix": "2001::1111/128", "ipv6": true, "peer_asn": 65502, "peer_bgp_id": "192.168.0.2", diff --git a/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-post-policy-step2.json b/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-post-policy-step2.json index 4e1afcda22..9eb221d4d0 100644 --- a/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-post-policy-step2.json +++ b/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-post-policy-step2.json @@ -1,10 +1,10 @@ { "post-policy": { "withdraw": { - "2001::2222/128": { + "2001::1111/128": { "afi": 2, "bmp_log_type": "withdraw", - "ip_prefix": "2001::2222/128", + "ip_prefix": "2001::1111/128", "ipv6": true, "label": 0, "peer_asn": 65502, @@ -16,10 +16,10 @@ "rd": "555:2", "safi": 128 }, - "172.31.10.1/32": { + "172.31.0.15/32": { "afi": 1, "bmp_log_type": "withdraw", - "ip_prefix": "172.31.10.1/32", + "ip_prefix": "172.31.0.15/32", "ipv6": false, "label": 0, "peer_asn": 65502, diff --git a/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-pre-policy-step1.json b/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-pre-policy-step1.json index 1c34498b7a..8add68c022 100644 --- a/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-pre-policy-step1.json +++ b/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-pre-policy-step1.json @@ -12,10 +12,10 @@ "peer_type": "global instance", "policy": "pre-policy" }, - "2111::1111/128": { + "2001::1111/128": { "afi": 2, "bmp_log_type": "withdraw", - "ip_prefix": "2111::1111/128", + "ip_prefix": "2001::1111/128", "ipv6": true, "peer_asn": 65502, "peer_bgp_id": "192.168.0.2", diff --git a/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-pre-policy-step2.json b/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-pre-policy-step2.json index 0a4a6404ad..eea7501b22 100644 --- a/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-pre-policy-step2.json +++ b/tests/topotests/bgp_bmp/bmp1/bmp-withdraw-pre-policy-step2.json @@ -1,10 +1,10 @@ { "pre-policy": { "withdraw": { - "2001::2222/128": { + "2001::1111/128": { "afi": 2, "bmp_log_type": "withdraw", - "ip_prefix": "2001::2222/128", + "ip_prefix": "2001::1111/128", "ipv6": true, "label": 0, "peer_asn": 65502, @@ -16,10 +16,10 @@ "rd": "555:2", "safi": 128 }, - "172.31.10.1/32": { + "172.31.0.15/32": { "afi": 1, "bmp_log_type": "withdraw", - "ip_prefix": "172.31.10.1/32", + "ip_prefix": "172.31.0.15/32", "ipv6": false, "label": 0, "peer_asn": 65502, diff --git a/tests/topotests/bgp_bmp/r1/show-bgp-ipv4-update-step2.json b/tests/topotests/bgp_bmp/r1/show-bgp-ipv4-update-step2.json index e0eb712eff..275f7f30e9 100644 --- a/tests/topotests/bgp_bmp/r1/show-bgp-ipv4-update-step2.json +++ b/tests/topotests/bgp_bmp/r1/show-bgp-ipv4-update-step2.json @@ -2,7 +2,7 @@ "routes": { "routeDistinguishers": { "444:2": { - "172.31.10.1/32": [ + "172.31.0.15/32": [ { "bestpath": true, "pathFrom": "external", diff --git a/tests/topotests/bgp_bmp/r1/show-bgp-ipv4-withdraw-step1.json b/tests/topotests/bgp_bmp/r1/show-bgp-ipv4-withdraw-step1.json index 6a77813776..22a6c605c1 100644 --- a/tests/topotests/bgp_bmp/r1/show-bgp-ipv4-withdraw-step1.json +++ b/tests/topotests/bgp_bmp/r1/show-bgp-ipv4-withdraw-step1.json @@ -1,6 +1,6 @@ { "routes": { - "172.31.0.15/32": null + "2001::1111/128": null } } diff --git a/tests/topotests/bgp_bmp/r1/show-bgp-ipv4-withdraw-step2.json b/tests/topotests/bgp_bmp/r1/show-bgp-ipv4-withdraw-step2.json index 1c94a1a722..0f930ee71f 100644 --- a/tests/topotests/bgp_bmp/r1/show-bgp-ipv4-withdraw-step2.json +++ b/tests/topotests/bgp_bmp/r1/show-bgp-ipv4-withdraw-step2.json @@ -2,7 +2,7 @@ "routes": { "routeDistinguishers": { "444:2": { - "172.31.10.1/32": null + "2001::1111/128": null } } } diff --git a/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-update-step1.json b/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-update-step1.json index db34220149..ed5cea68ce 100644 --- a/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-update-step1.json +++ b/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-update-step1.json @@ -1,6 +1,6 @@ { "routes": { - "2111::1111/128": [ + "2001::1111/128": [ { "bestpath": true, "pathFrom": "external", diff --git a/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-update-step2.json b/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-update-step2.json index ada2c26baf..c4c0c16284 100644 --- a/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-update-step2.json +++ b/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-update-step2.json @@ -2,7 +2,7 @@ "routes": { "routeDistinguishers": { "555:2": { - "2001::2222/128": [ + "2001::1111/128": [ { "bestpath": true, "pathFrom": "external", diff --git a/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-withdraw-step1.json b/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-withdraw-step1.json index 93f4a75e8c..22a6c605c1 100644 --- a/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-withdraw-step1.json +++ b/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-withdraw-step1.json @@ -1,6 +1,6 @@ { "routes": { - "2111::1111/128": null + "2001::1111/128": null } } diff --git a/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-withdraw-step2.json b/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-withdraw-step2.json index 9703a269d5..7b652afca6 100644 --- a/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-withdraw-step2.json +++ b/tests/topotests/bgp_bmp/r1/show-bgp-ipv6-withdraw-step2.json @@ -2,7 +2,7 @@ "routes": { "routeDistinguishers": { "555:2": { - "2001::2222/128": null + "2001::1111/128": null } } } diff --git a/tests/topotests/bgp_bmp/test_bgp_bmp.py b/tests/topotests/bgp_bmp/test_bgp_bmp.py index a6344a6c0a..cb12c544ff 100644 --- a/tests/topotests/bgp_bmp/test_bgp_bmp.py +++ b/tests/topotests/bgp_bmp/test_bgp_bmp.py @@ -371,7 +371,7 @@ def configure_prefixes(tgen, node, asn, safi, prefixes, vrf=None, update=True): tgen.gears[node].vtysh_cmd("".join(cmd)) -def unicast_prefixes(policy): +def _test_prefixes(policy, vrf=None, step=0): """ Setup the BMP monitor policy, Add and withdraw ipv4/v6 prefixes. Check if the previous actions are logged in the BMP server with the right @@ -379,129 +379,43 @@ def unicast_prefixes(policy): """ tgen = get_topogen() - set_bmp_policy(tgen, "r1", 65501, "bmp1", "unicast", policy) + safi = "vpn" if vrf else "unicast" - update_seq() + set_bmp_policy(tgen, "r1", 65501, "bmp1", safi, policy) - prefixes = ["172.31.0.15/32", "2111::1111/128"] - # add prefixes - configure_prefixes(tgen, "r2", 65502, "unicast", prefixes) + prefixes = ["172.31.0.15/32", "2001::1111/128"] - for ipver in [4, 6]: - if UPDATE_EXPECTED_JSON: - continue - ref_file = "{}/r1/show-bgp-ipv{}-update-step1.json".format(CWD, ipver) - expected = json.loads(open(ref_file).read()) + for type in ("update", "withdraw"): + update_seq() - test_func = partial( - topotest.router_json_cmp, - tgen.gears["r1"], - f"show bgp ipv{ipver} json", - expected, + configure_prefixes( + tgen, "r2", 65502, "unicast", prefixes, vrf=vrf, update=(type == "update") ) - _, 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 - logger.info("checking for updated prefixes") - # check - test_func = partial(check_for_prefixes, prefixes, "update", policy, 1) - success, res = topotest.run_and_expect(test_func, None, count=30, wait=1) - assert success, "Checking the updated prefixes has been failed !. %s" % res + logger.info(f"checking for prefixes {type}") - update_seq() + for ipver in [4, 6]: + if UPDATE_EXPECTED_JSON: + continue + ref_file = "{}/r1/show-bgp-ipv{}-{}-step{}.json".format( + CWD, ipver, type, step + ) + expected = json.loads(open(ref_file).read()) - # withdraw prefixes - configure_prefixes(tgen, "r2", 65502, "unicast", prefixes, update=False) - logger.info("checking for withdrawn prefixes") + test_func = partial( + topotest.router_json_cmp, + tgen.gears["r1"], + f"show bgp ipv{ipver} {safi} 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 - for ipver in [4, 6]: - if UPDATE_EXPECTED_JSON: - continue - ref_file = "{}/r1/show-bgp-ipv{}-withdraw-step1.json".format(CWD, ipver) - expected = json.loads(open(ref_file).read()) - - test_func = partial( - topotest.router_json_cmp, - tgen.gears["r1"], - f"show bgp 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 - - # check - test_func = partial(check_for_prefixes, prefixes, "withdraw", policy, 1) - success, res = topotest.run_and_expect(test_func, None, count=30, wait=1) - assert success, "Checking the withdrawn prefixes has been failed !. %s" % res - - -def vpn_prefixes(policy): - """ - Setup the BMP monitor policy, Add and withdraw ipv4/v6 prefixes. - Check if the previous actions are logged in the BMP server with the right - message type and the right policy. - """ - tgen = get_topogen() - - set_bmp_policy(tgen, "r1", 65501, "bmp1", "vpn", policy) - - update_seq() - - prefixes = ["172.31.10.1/32", "2001::2222/128"] - - # add prefixes - configure_prefixes(tgen, "r2", 65502, "unicast", prefixes, vrf="vrf1") - - for ipver in [4, 6]: - if UPDATE_EXPECTED_JSON: - continue - ref_file = "{}/r1/show-bgp-ipv{}-update-step2.json".format(CWD, ipver) - expected = json.loads(open(ref_file).read()) - - test_func = partial( - topotest.router_json_cmp, - tgen.gears["r1"], - f"show bgp ipv{ipver} vpn 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 - - logger.info("checking for updated prefixes") - # check - test_func = partial(check_for_prefixes, prefixes, "update", policy, 2) - success, res = topotest.run_and_expect(test_func, None, count=30, wait=1) - assert success, "Checking the updated prefixes has been failed !. %s" % res - - update_seq() - - # withdraw prefixes - configure_prefixes(tgen, "r2", 65502, "unicast", prefixes, vrf="vrf1", update=False) - logger.info("checking for withdrawn prefixes") - - for ipver in [4, 6]: - if UPDATE_EXPECTED_JSON: - continue - ref_file = "{}/r1/show-bgp-ipv{}-withdraw-step2.json".format(CWD, ipver) - expected = json.loads(open(ref_file).read()) - - test_func = partial( - topotest.router_json_cmp, - tgen.gears["r1"], - f"show bgp ipv{ipver} vpn 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 - - # check - test_func = partial(check_for_prefixes, prefixes, "withdraw", policy, 2) - success, res = topotest.run_and_expect(test_func, None, count=30, wait=1) - assert success, "Checking the withdrawn prefixes has been failed !. %s" % res + # check + test_func = partial(check_for_prefixes, prefixes, type, policy, step) + 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_bmp_server_logging(): @@ -541,21 +455,21 @@ def test_bmp_bgp_unicast(): Add/withdraw bgp unicast prefixes and check the bmp logs. """ logger.info("*** Unicast prefixes pre-policy logging ***") - unicast_prefixes(PRE_POLICY) + _test_prefixes(PRE_POLICY, step=1) logger.info("*** Unicast prefixes post-policy logging ***") - unicast_prefixes(POST_POLICY) + _test_prefixes(POST_POLICY, step=1) logger.info("*** Unicast prefixes loc-rib logging ***") - unicast_prefixes(LOC_RIB) + _test_prefixes(LOC_RIB, step=1) def test_bmp_bgp_vpn(): # check for the prefixes in the BMP server logging file logger.info("***** VPN prefixes pre-policy logging *****") - vpn_prefixes(PRE_POLICY) + _test_prefixes(PRE_POLICY, vrf="vrf1", step=2) logger.info("***** VPN prefixes post-policy logging *****") - vpn_prefixes(POST_POLICY) + _test_prefixes(POST_POLICY, vrf="vrf1", step=2) logger.info("***** VPN prefixes loc-rib logging *****") - vpn_prefixes(LOC_RIB) + _test_prefixes(LOC_RIB, vrf="vrf1", step=2) def test_peer_down():