From c06c32e846e39237f0dae6d8e4c778b9d01f3488 Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Mon, 2 Sep 2024 17:52:13 +0200 Subject: [PATCH] tests: adapt nhrp_redundancy The test expected the NHRP shortcut on nhc1 to expire after 10s in the absence of traffic. Previous patches no longer cause shortcuts to expire unless the remote network is down or the kernel has removed neighbor entries to the remote network. Test that the shortcut only expires in these cases. Note that the shortcut mechanism is based on NHRP type 8 (NHRP traffic indication) packets that is not part of RFC2332 but of draft-detienne-dmvpn-01. The tested behavior conforms with: > an NHRP cache entry is created for TunS1 => PubS1. The entry > SHOULD NOT remain in the cache for more than the specified Hold > Time (from the NHRP Resolution Request). This NHRP cache entry > may be 'refreshed' for another hold time period prior to expiry by > receipt of another matching NHRP Resolution Request or by sending > an NHRP Resolution Request and receiving an NHRP Resolution Reply. Signed-off-by: Louis Scalbert --- .../nhrp_redundancy/test_nhrp_redundancy.py | 49 +++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/tests/topotests/nhrp_redundancy/test_nhrp_redundancy.py b/tests/topotests/nhrp_redundancy/test_nhrp_redundancy.py index 8d0e16c88921..36c4cf8f9a7a 100644 --- a/tests/topotests/nhrp_redundancy/test_nhrp_redundancy.py +++ b/tests/topotests/nhrp_redundancy/test_nhrp_redundancy.py @@ -291,6 +291,7 @@ def test_redundancy_shortcut(): check_ping("host", "10.5.5.5", True, 10, 0.5) # Now check that NHRP shortcut route installed + logger.info("Check that NHRP shortcut route installed") json_file = "{}/{}/nhrp_route_shortcut.json".format(CWD, nhc1.name) assertmsg = "No nhrp_route file found" assert os.path.isfile(json_file), assertmsg @@ -307,6 +308,7 @@ def test_redundancy_shortcut(): assertmsg = '"{}" JSON output mismatches'.format(nhc1.name) assert result is None, assertmsg + logger.info("Check the shortcut") json_file = "{}/{}/nhrp_shortcut_present.json".format(CWD, nhc1.name) expected = json.loads(open(json_file).read()) test_func = partial( @@ -320,6 +322,22 @@ def test_redundancy_shortcut(): assertmsg = '"{}" JSON output mismatches'.format(nhc1.name) assert result is None, assertmsg + +def test_redundancy_shortcut_nhc2_down(): + """ + Check that the traffic disappears after nhc2 is shutdown + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + nhc1 = tgen.gears["nhc1"] + router_list = tgen.routers() + + logger.info("Bringing down nhc2.") + shutdown_bringup_interface(tgen, "nhc2", "nhc2-gre0", False) + + logger.info("Check the shortcut disappears") # check the shortcut disappears because of no traffic json_file = "{}/{}/nhrp_shortcut_absent.json".format(CWD, nhc1.name) expected = json.loads(open(json_file).read()) @@ -335,7 +353,7 @@ def test_redundancy_shortcut(): assert result is None, assertmsg -def test_redundancy_shortcut_backup(): +def test_redundancy_shortcut_nhs1_down(): """ Stop traffic and verify next time traffic started, shortcut is initiated by backup NHS """ @@ -352,8 +370,10 @@ def test_redundancy_shortcut_backup(): # Bring down primary GRE interface and verify shortcut is not disturbed logger.info("Bringing down nhs1, primary NHRP server.") shutdown_bringup_interface(tgen, "nhs1", "nhs1-gre0", False) + logger.info("Bringing up nhc2.") + shutdown_bringup_interface(tgen, "nhc2", "nhc2-gre0", True) - # Check NHRP cache on servers and clients + logger.info("Check NHRP cache on servers and clients") for rname, router in router_list.items(): if "nh" not in rname: continue @@ -397,7 +417,7 @@ def test_redundancy_shortcut_backup(): logger.info("Check Ping IPv4 from host to nhc2 via shortcut = 10.5.5.5") check_ping("host", "10.5.5.5", True, 10, 0.5) - # Verify shortcut is present in routing table + logger.info("Check that shortcut is present in routing table") json_file = "{}/{}/nhrp_route_shortcut_nhs1_down.json".format(CWD, nhc1.name) assertmsg = "No nhrp_route file found" assert os.path.isfile(json_file), assertmsg @@ -424,7 +444,28 @@ def test_redundancy_shortcut_backup(): assertmsg = '"{}" JSON output mismatches'.format(nhc1.name) assert result is None, assertmsg - # Now verify shortcut is purged with lack of traffic + +def test_redundancy_shortcut_del_arp(): + """ + Stop traffic and verify next time traffic started, shortcut is initiated by backup NHS + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + if not _verify_iptables(): + pytest.skip("iptables not installed") + + nhc1 = tgen.gears["nhc1"] + router_list = tgen.routers() + + logger.info("Remove ARP on nhc1 to nhc2") + nhc1.cmd("ip neigh del 10.5.5.5 dev nhc1-gre0") + nhc1.cmd("ip neigh del 172.16.1.5 dev nhc1-gre0") + + logger.info( + "Check that shortcut is purged with lack of traffic and neighbor entries" + ) json_file = "{}/{}/nhrp_route_nhs1_down.json".format(CWD, nhc1.name) assertmsg = "No nhrp_route file found" assert os.path.isfile(json_file), assertmsg