From cf871774ce87b12052d14bb912d70b416f7ed256 Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Mon, 18 Dec 2023 13:04:11 +0100 Subject: [PATCH] topotests: add vrf test to bgp_rpki_topo1 Add vrf test to bgp_rpki_topo1 Signed-off-by: Louis Scalbert --- .../topotests/bgp_rpki_topo1/r2/staticd.conf | 6 +- tests/topotests/bgp_rpki_topo1/r2/zebra.conf | 3 + tests/topotests/bgp_rpki_topo1/r3/bgpd.conf | 14 ++ tests/topotests/bgp_rpki_topo1/r3/rtrd.py | 1 + .../topotests/bgp_rpki_topo1/r3/staticd.conf | 1 + tests/topotests/bgp_rpki_topo1/r3/zebra.conf | 5 + .../bgp_rpki_topo1/test_bgp_rpki_topo1.py | 128 ++++++++++++++++-- 7 files changed, 147 insertions(+), 11 deletions(-) create mode 100644 tests/topotests/bgp_rpki_topo1/r3/bgpd.conf create mode 120000 tests/topotests/bgp_rpki_topo1/r3/rtrd.py create mode 100644 tests/topotests/bgp_rpki_topo1/r3/staticd.conf create mode 100644 tests/topotests/bgp_rpki_topo1/r3/zebra.conf diff --git a/tests/topotests/bgp_rpki_topo1/r2/staticd.conf b/tests/topotests/bgp_rpki_topo1/r2/staticd.conf index 1bb4ad1ef73d..de58ddef69e7 100644 --- a/tests/topotests/bgp_rpki_topo1/r2/staticd.conf +++ b/tests/topotests/bgp_rpki_topo1/r2/staticd.conf @@ -1 +1,5 @@ -ip route 192.0.2.1/32 192.168.1.1 \ No newline at end of file +ip route 192.0.2.1/32 192.168.1.1 +! +vrf vrf10 + ip route 192.0.2.3/32 192.168.2.3 +! diff --git a/tests/topotests/bgp_rpki_topo1/r2/zebra.conf b/tests/topotests/bgp_rpki_topo1/r2/zebra.conf index 96865f0b623f..d44a8a908836 100644 --- a/tests/topotests/bgp_rpki_topo1/r2/zebra.conf +++ b/tests/topotests/bgp_rpki_topo1/r2/zebra.conf @@ -7,3 +7,6 @@ interface vrf10 vrf vrf10 interface r2-eth0 ip address 192.168.1.2/24 ! +interface r2-eth1 vrf vrf10 + ip address 192.168.2.2/24 +! diff --git a/tests/topotests/bgp_rpki_topo1/r3/bgpd.conf b/tests/topotests/bgp_rpki_topo1/r3/bgpd.conf new file mode 100644 index 000000000000..596dc20d3321 --- /dev/null +++ b/tests/topotests/bgp_rpki_topo1/r3/bgpd.conf @@ -0,0 +1,14 @@ +router bgp 65530 + no bgp ebgp-requires-policy + no bgp network import-check + neighbor 192.0.2.2 remote-as 65002 + neighbor 192.0.2.2 timers 1 3 + neighbor 192.0.2.2 timers connect 1 + neighbor 192.0.2.2 ebgp-multihop 3 + neighbor 192.0.2.2 update-source 192.0.2.3 + address-family ipv4 unicast + network 198.51.100.0/24 + network 203.0.113.0/24 + network 10.0.0.0/24 + exit-address-family +! diff --git a/tests/topotests/bgp_rpki_topo1/r3/rtrd.py b/tests/topotests/bgp_rpki_topo1/r3/rtrd.py new file mode 120000 index 000000000000..1c5871a2ac55 --- /dev/null +++ b/tests/topotests/bgp_rpki_topo1/r3/rtrd.py @@ -0,0 +1 @@ +../r1/rtrd.py \ No newline at end of file diff --git a/tests/topotests/bgp_rpki_topo1/r3/staticd.conf b/tests/topotests/bgp_rpki_topo1/r3/staticd.conf new file mode 100644 index 000000000000..6822f7ec03f2 --- /dev/null +++ b/tests/topotests/bgp_rpki_topo1/r3/staticd.conf @@ -0,0 +1 @@ +ip route 192.0.2.2/32 192.168.2.2 diff --git a/tests/topotests/bgp_rpki_topo1/r3/zebra.conf b/tests/topotests/bgp_rpki_topo1/r3/zebra.conf new file mode 100644 index 000000000000..097511476a1a --- /dev/null +++ b/tests/topotests/bgp_rpki_topo1/r3/zebra.conf @@ -0,0 +1,5 @@ +interface lo + ip address 192.0.2.3/32 +! +interface r3-eth0 + ip address 192.168.2.3/24 \ No newline at end of file diff --git a/tests/topotests/bgp_rpki_topo1/test_bgp_rpki_topo1.py b/tests/topotests/bgp_rpki_topo1/test_bgp_rpki_topo1.py index 268a564bd974..d80c44617323 100644 --- a/tests/topotests/bgp_rpki_topo1/test_bgp_rpki_topo1.py +++ b/tests/topotests/bgp_rpki_topo1/test_bgp_rpki_topo1.py @@ -22,13 +22,17 @@ def build_topo(tgen): - for routern in range(1, 3): + for routern in range(1, 4): tgen.add_router("r{}".format(routern)) switch = tgen.add_switch("s1") switch.add_link(tgen.gears["r1"]) switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + def setup_module(mod): tgen = Topogen(build_topo, mod.__name__) @@ -49,24 +53,32 @@ def setup_module(mod): " -M bgpd_rpki" if rname == "r2" else "", ) + tgen.gears["r2"].run("ip link add vrf10 type vrf table 10") + tgen.gears["r2"].run("ip link set vrf10 up") + + tgen.gears["r2"].run("ip link set r2-eth1 master vrf10") + tgen.start_router() - r1_path = os.path.join(CWD, "r1") - log_dir = os.path.join(tgen.logdir, "r1") - pid_file = os.path.join(log_dir, "rtrd.pid") + for rname in ["r1", "r3"]: + rtr_path = os.path.join(CWD, rname) + log_dir = os.path.join(tgen.logdir, rname) + pid_file = os.path.join(log_dir, "rtrd.pid") - tgen.gears["r1"].cmd("chmod u+x {}/rtrd.py".format(r1_path)) - tgen.gears["r1"].popen("{}/rtrd.py & echo $! >{}".format(r1_path, pid_file)) + tgen.gears[rname].cmd("chmod u+x {}/rtrd.py".format(rtr_path)) + tgen.gears[rname].popen("{}/rtrd.py & echo $! >{}".format(rtr_path, pid_file)) def teardown_module(mod): tgen = get_topogen() - log_dir = os.path.join(tgen.logdir, "r1") - pid_file = os.path.join(log_dir, "rtrd.pid") + for rname in ["r1", "r3"]: + log_dir = os.path.join(tgen.logdir, rname) + pid_file = os.path.join(log_dir, "rtrd.pid") + + logger.info("{}: sending SIGTERM to rtrd RPKI server".format(rname)) + tgen.gears[rname].cmd("kill $(cat {})".format(pid_file)) - logger.info("r1: sending SIGTERM to rtrd RPKI server") - tgen.gears["r1"].cmd("kill $(cat {})".format(pid_file)) tgen.stop_topology() @@ -262,6 +274,102 @@ def test_show_bgp_rpki_route_map(): assert result is None, "Unexpected prefixes RPKI state on {}".format(rname) +def test_show_bgp_rpki_prefixes_vrf(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + step("Configure RPKI cache server on vrf10") + + rname = "r2" + tgen.gears[rname].vtysh_cmd( + """ +configure +vrf vrf10 + rpki + rpki cache 192.0.2.3 15432 preference 1 + exit +exit +""" + ) + + step("Check vrf10 RPKI prefix table") + + expected = open(os.path.join(CWD, "{}/rpki_prefix_table.json".format(rname))).read() + expected_json = json.loads(expected) + test_func = functools.partial(show_rpki_prefixes, rname, expected_json, vrf="vrf10") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see RPKI prefixes on {}".format(rname) + + for rpki_state in ["valid", "notfound", None]: + if rpki_state: + step( + "Check RPKI state of prefixes in vrf10 BGP table: {}".format(rpki_state) + ) + else: + step("Check prefixes in vrf10 BGP table") + expected = open( + os.path.join( + CWD, + "{}/bgp_table_rpki_{}.json".format( + rname, rpki_state if rpki_state else "any" + ), + ) + ).read() + expected_json = json.loads(expected) + test_func = functools.partial( + show_bgp_ipv4_table_rpki, rname, rpki_state, expected_json, vrf="vrf10" + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Unexpected prefixes RPKI state on {}".format(rname) + + +def test_show_bgp_rpki_route_map_vrf(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + step("Apply RPKI valid route-map on vrf10 neighbor") + + rname = "r2" + tgen.gears[rname].vtysh_cmd( + """ +configure +router bgp 65002 vrf vrf10 + address-family ipv4 unicast + neighbor 192.0.2.3 route-map RPKI in +""" + ) + + for rpki_state in ["valid", "notfound", None]: + if rpki_state: + step( + "Check RPKI state of prefixes in vrf10 BGP table: {}".format(rpki_state) + ) + else: + step("Check prefixes in vrf10 BGP table") + expected = open( + os.path.join( + CWD, + "{}/bgp_table_rmap_rpki_{}.json".format( + rname, rpki_state if rpki_state else "any" + ), + ) + ).read() + expected_json = json.loads(expected) + test_func = functools.partial( + show_bgp_ipv4_table_rpki, + rname, + rpki_state, + expected_json, + vrf="vrf10", + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Unexpected prefixes RPKI state on {}".format(rname) + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args))