From 55586065c8e323155aa10f8910c1e1864e3d3166 Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Tue, 27 Feb 2024 15:42:16 +0100 Subject: [PATCH] topotests: bgp_bmp, add vpn tests Test vpn prefixes sending to BMP Signed-off-by: Farid Mihoub Signed-off-by: Louis Scalbert --- tests/topotests/bgp_bmp/r1/bgpd.conf | 26 ++++++++++++++++ tests/topotests/bgp_bmp/r2/bgpd.conf | 27 +++++++++++++++++ tests/topotests/bgp_bmp/test_bgp_bmp.py | 40 ++++++++++++++++++++++++- 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/tests/topotests/bgp_bmp/r1/bgpd.conf b/tests/topotests/bgp_bmp/r1/bgpd.conf index edca6bf1d7..24505de4a8 100644 --- a/tests/topotests/bgp_bmp/r1/bgpd.conf +++ b/tests/topotests/bgp_bmp/r1/bgpd.conf @@ -9,6 +9,14 @@ router bgp 65501 bmp connect 192.0.2.10 port 1789 min-retry 100 max-retry 10000 exit ! + address-family ipv4 vpn + neighbor 192.168.0.2 activate + neighbor 192.168.0.2 soft-reconfiguration inbound + exit-address-family + address-family ipv6 vpn + neighbor 192:168::2 activate + neighbor 192:168::2 soft-reconfiguration inbound + exit-address-family address-family ipv4 unicast neighbor 192.168.0.2 activate neighbor 192.168.0.2 soft-reconfiguration inbound @@ -20,3 +28,21 @@ router bgp 65501 neighbor 192:168::2 soft-reconfiguration inbound exit-address-family ! +router bgp 65502 vrf vrf1 + bgp router_id 192.168.0.1 + bgp log-neighbor-changes + address-family ipv4 unicast + label vpn export 101 + rd vpn export 444:1 + rt vpn both 52:100 + export vpn + import vpn + exit-address-family + address-family ipv6 unicast + label vpn export 103 + rd vpn export 555:1 + rt vpn both 54:200 + export vpn + import vpn + exit-address-family +exit diff --git a/tests/topotests/bgp_bmp/r2/bgpd.conf b/tests/topotests/bgp_bmp/r2/bgpd.conf index 7c8255a175..40e2cd5bbc 100644 --- a/tests/topotests/bgp_bmp/r2/bgpd.conf +++ b/tests/topotests/bgp_bmp/r2/bgpd.conf @@ -11,9 +11,36 @@ router bgp 65502 no neighbor 192:168::1 activate redistribute connected exit-address-family +! + address-family ipv4 vpn + neighbor 192.168.0.1 activate + exit-address-family +! + address-family ipv6 vpn + neighbor 192:168::1 activate + exit-address-family ! address-family ipv6 unicast neighbor 192:168::1 activate redistribute connected exit-address-family ! +router bgp 65502 vrf vrf1 + bgp router-id 192.168.0.2 + bgp log-neighbor-changes + no bgp network import-check + address-family ipv4 unicast + label vpn export 102 + rd vpn export 444:2 + rt vpn both 52:100 + export vpn + import vpn + exit-address-family + address-family ipv6 unicast + label vpn export 105 + rd vpn export 555:2 + rt vpn both 54:200 + export vpn + import vpn + exit-address-family +exit diff --git a/tests/topotests/bgp_bmp/test_bgp_bmp.py b/tests/topotests/bgp_bmp/test_bgp_bmp.py index 059875a1af..0c34bdfe29 100644 --- a/tests/topotests/bgp_bmp/test_bgp_bmp.py +++ b/tests/topotests/bgp_bmp/test_bgp_bmp.py @@ -174,7 +174,7 @@ def configure_prefixes(tgen, node, asn, safi, prefixes, vrf=None, update=True): Configure the bgp prefixes. """ withdraw = "no " if not update else "" - vrf = " vrf {}" if vrf else "" + vrf = " vrf {}".format(vrf) if vrf else "" for p in prefixes: ip = ip_network(p) cmd = [ @@ -216,6 +216,34 @@ def unicast_prefixes(policy): assert success, "Checking the withdrawed prefixes has been failed !." +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) + + prefixes = ["172.31.10.1/32", "2001::2222/128"] + # add prefixes + configure_prefixes(tgen, "r2", 65502, "unicast", prefixes, vrf="vrf1") + + logger.info("checking for updated prefixes") + # check + test_func = partial(check_for_prefixes, prefixes, "update", policy) + success, _ = topotest.run_and_expect(test_func, True, wait=0.5) + assert success, "Checking the updated prefixes has been failed !." + + # withdraw prefixes + configure_prefixes(tgen, "r2", 65502, "unicast", prefixes, vrf="vrf1", update=False) + logger.info("checking for withdrawed prefixes") + # check + test_func = partial(check_for_prefixes, prefixes, "withdraw", policy) + success, _ = topotest.run_and_expect(test_func, True, wait=0.5) + assert success, "Checking the withdrawed prefixes has been failed !." + + def test_bmp_server_logging(): """ Assert the logging of the bmp server. @@ -244,6 +272,16 @@ def test_bmp_bgp_unicast(): unicast_prefixes(LOC_RIB) +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) + logger.info("***** VPN prefixes post-policy logging *****") + vpn_prefixes(POST_POLICY) + logger.info("***** VPN prefixes loc-rib logging *****") + vpn_prefixes(LOC_RIB) + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) -- 2.39.5