From: Louis Scalbert Date: Fri, 30 Aug 2024 12:12:27 +0000 (+0200) Subject: tests: fix nhs1 down check in nhrp_redundancy X-Git-Tag: docker/10.0.3~44^2~4 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=5e2143d46e140f480ca5c79d30961f40ebfc42ca;p=matthieu%2Ffrr.git tests: fix nhs1 down check in nhrp_redundancy Fully check the NHRP convergence after setting nhs1 down. Otherwise the ping may pass because the previous shortcut is still present. Signed-off-by: Louis Scalbert (cherry picked from commit 9aa78070e0048ec54c07726b8a5bd3b33331257b) --- diff --git a/tests/topotests/nhrp_redundancy/nhc1/nhrp_cache_nhs1_down.json b/tests/topotests/nhrp_redundancy/nhc1/nhrp_cache_nhs1_down.json new file mode 100644 index 0000000000..7ceebc321e --- /dev/null +++ b/tests/topotests/nhrp_redundancy/nhc1/nhrp_cache_nhs1_down.json @@ -0,0 +1,40 @@ +{ + "attr": { + "entriesCount": 3 + }, + "table": [ + { + "interface": "nhc1-gre0", + "type": "nhs", + "protocol": "176.16.1.2", + "nbma": "192.168.1.2", + "claimed_nbma": "192.168.1.2", + "used": false, + "timeout": true, + "auth": false, + "identity": "" + }, + { + "interface": "nhc1-gre0", + "type": "local", + "protocol": "176.16.1.4", + "nbma": "192.168.2.4", + "claimed_nbma": "192.168.2.4", + "used": false, + "timeout": false, + "auth": false, + "identity": "-" + }, + { + "interface": "nhc1-gre0", + "type": "nhs", + "protocol": "176.16.1.3", + "nbma": "192.168.1.3", + "claimed_nbma": "192.168.1.3", + "used": false, + "timeout": true, + "auth": false, + "identity": "" + } + ] +} \ No newline at end of file diff --git a/tests/topotests/nhrp_redundancy/nhc1/nhrp_route_shortcut_nhs1_down.json b/tests/topotests/nhrp_redundancy/nhc1/nhrp_route_shortcut_nhs1_down.json new file mode 100644 index 0000000000..38e5000324 --- /dev/null +++ b/tests/topotests/nhrp_redundancy/nhc1/nhrp_route_shortcut_nhs1_down.json @@ -0,0 +1,96 @@ +{ + "5.5.5.0\/24": [ + { + "prefix": "5.5.5.0\/24", + "protocol": "nhrp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 10, + "metric": 0, + "installed": true, + "internalNextHopNum": 1, + "internalNextHopActiveNum": 1, + "nexthops": [ + { + "fib": true, + "ip": "176.16.1.5", + "afi": "ipv4", + "interfaceName": "nhc1-gre0", + "active": true + } + ] + } + ], + "176.16.1.1\/32": null, + "176.16.1.2\/32": [ + { + "prefix": "176.16.1.2\/32", + "protocol": "nhrp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 10, + "metric": 0, + "installed": true, + "internalNextHopNum": 1, + "internalNextHopActiveNum": 1, + "nexthops": [ + { + "fib": true, + "directlyConnected": true, + "interfaceName": "nhc1-gre0", + "active": true + } + ] + } + ], + "176.16.1.3\/32": [ + { + "prefix": "176.16.1.3\/32", + "protocol": "nhrp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 10, + "metric": 0, + "installed": true, + "internalNextHopNum": 1, + "internalNextHopActiveNum": 1, + "nexthops": [ + { + "fib": true, + "directlyConnected": true, + "interfaceName": "nhc1-gre0", + "active": true + } + ] + } + ], + "176.16.1.5\/32": [ + { + "prefix": "176.16.1.5\/32", + "protocol": "nhrp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 10, + "metric": 0, + "installed": true, + "internalNextHopNum": 1, + "internalNextHopActiveNum": 1, + "nexthops": [ + { + "fib": true, + "directlyConnected": true, + "interfaceName": "nhc1-gre0", + "active": true + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/topotests/nhrp_redundancy/nhc2/nhrp_cache_nhs1_down.json b/tests/topotests/nhrp_redundancy/nhc2/nhrp_cache_nhs1_down.json new file mode 100644 index 0000000000..a76c85231d --- /dev/null +++ b/tests/topotests/nhrp_redundancy/nhc2/nhrp_cache_nhs1_down.json @@ -0,0 +1,40 @@ +{ + "attr": { + "entriesCount": 3 + }, + "table": [ + { + "interface": "nhc2-gre0", + "type": "nhs", + "protocol": "176.16.1.2", + "nbma": "192.168.1.2", + "claimed_nbma": "192.168.1.2", + "used": false, + "timeout": true, + "auth": false, + "identity": "" + }, + { + "interface": "nhc2-gre0", + "type": "nhs", + "protocol": "176.16.1.3", + "nbma": "192.168.1.3", + "claimed_nbma": "192.168.1.3", + "used": false, + "timeout": true, + "auth": false, + "identity": "" + }, + { + "interface": "nhc2-gre0", + "type": "local", + "protocol": "176.16.1.5", + "nbma": "192.168.2.5", + "claimed_nbma": "192.168.2.5", + "used": false, + "timeout": false, + "auth": false, + "identity": "-" + } + ] +} \ No newline at end of file diff --git a/tests/topotests/nhrp_redundancy/nhc2/nhrp_route_nhs1_down.json b/tests/topotests/nhrp_redundancy/nhc2/nhrp_route_nhs1_down.json new file mode 100644 index 0000000000..fd7c4c8f39 --- /dev/null +++ b/tests/topotests/nhrp_redundancy/nhc2/nhrp_route_nhs1_down.json @@ -0,0 +1,49 @@ +{ + "176.16.1.1\/32": null, + "176.16.1.2\/32": [ + { + "prefix": "176.16.1.2\/32", + "protocol": "nhrp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 10, + "metric": 0, + "installed": true, + "internalNextHopNum": 1, + "internalNextHopActiveNum": 1, + "nexthops": [ + { + "fib": true, + "directlyConnected": true, + "interfaceName": "nhc2-gre0", + "active": true + } + ] + } + ], + "176.16.1.3\/32": [ + { + "prefix": "176.16.1.3\/32", + "protocol": "nhrp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 10, + "metric": 0, + "installed": true, + "internalNextHopNum": 1, + "internalNextHopActiveNum": 1, + "nexthops": [ + { + "fib": true, + "directlyConnected": true, + "interfaceName": "nhc2-gre0", + "active": true + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/topotests/nhrp_redundancy/nhs2/nhrp_cache_nhs1_down.json b/tests/topotests/nhrp_redundancy/nhs2/nhrp_cache_nhs1_down.json new file mode 100644 index 0000000000..c0538203c7 --- /dev/null +++ b/tests/topotests/nhrp_redundancy/nhs2/nhrp_cache_nhs1_down.json @@ -0,0 +1,40 @@ +{ + "attr": { + "entriesCount": 3 + }, + "table": [ + { + "interface": "nhs2-gre0", + "type": "local", + "protocol": "176.16.1.2", + "nbma": "192.168.1.2", + "claimed_nbma": "192.168.1.2", + "used": false, + "timeout": false, + "auth": false, + "identity": "-" + }, + { + "interface": "nhs2-gre0", + "type": "dynamic", + "protocol": "176.16.1.4", + "nbma": "192.168.2.4", + "claimed_nbma": "192.168.2.4", + "used": false, + "timeout": true, + "auth": false, + "identity": "" + }, + { + "interface": "nhs2-gre0", + "type": "dynamic", + "protocol": "176.16.1.5", + "nbma": "192.168.2.5", + "claimed_nbma": "192.168.2.5", + "used": false, + "timeout": true, + "auth": false, + "identity": "" + } + ] +} \ No newline at end of file diff --git a/tests/topotests/nhrp_redundancy/nhs2/nhrp_route_nhs1_down.json b/tests/topotests/nhrp_redundancy/nhs2/nhrp_route_nhs1_down.json new file mode 100644 index 0000000000..25086be7e8 --- /dev/null +++ b/tests/topotests/nhrp_redundancy/nhs2/nhrp_route_nhs1_down.json @@ -0,0 +1,48 @@ +{ + "176.16.1.4\/32": [ + { + "prefix": "176.16.1.4\/32", + "protocol": "nhrp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 10, + "metric": 0, + "installed": true, + "internalNextHopNum": 1, + "internalNextHopActiveNum": 1, + "nexthops": [ + { + "fib": true, + "directlyConnected": true, + "interfaceName": "nhs2-gre0", + "active": true + } + ] + } + ], + "176.16.1.5\/32": [ + { + "prefix": "176.16.1.5\/32", + "protocol": "nhrp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 10, + "metric": 0, + "installed": true, + "internalNextHopNum": 1, + "internalNextHopActiveNum": 1, + "nexthops": [ + { + "fib": true, + "directlyConnected": true, + "interfaceName": "nhs2-gre0", + "active": true + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/topotests/nhrp_redundancy/nhs3/nhrp_cache_nhs1_down.json b/tests/topotests/nhrp_redundancy/nhs3/nhrp_cache_nhs1_down.json new file mode 100644 index 0000000000..9bcf0f78c2 --- /dev/null +++ b/tests/topotests/nhrp_redundancy/nhs3/nhrp_cache_nhs1_down.json @@ -0,0 +1,40 @@ +{ + "attr": { + "entriesCount": 3 + }, + "table": [ + { + "interface": "nhs3-gre0", + "type": "dynamic", + "protocol": "176.16.1.4", + "nbma": "192.168.2.4", + "claimed_nbma": "192.168.2.4", + "used": false, + "timeout": true, + "auth": false, + "identity": "" + }, + { + "interface": "nhs3-gre0", + "type": "local", + "protocol": "176.16.1.3", + "nbma": "192.168.1.3", + "claimed_nbma": "192.168.1.3", + "used": false, + "timeout": false, + "auth": false, + "identity": "-" + }, + { + "interface": "nhs3-gre0", + "type": "dynamic", + "protocol": "176.16.1.5", + "nbma": "192.168.2.5", + "claimed_nbma": "192.168.2.5", + "used": false, + "timeout": true, + "auth": false, + "identity": "" + } + ] +} \ No newline at end of file diff --git a/tests/topotests/nhrp_redundancy/nhs3/nhrp_route_nhs1_down.json b/tests/topotests/nhrp_redundancy/nhs3/nhrp_route_nhs1_down.json new file mode 100644 index 0000000000..a5a493c973 --- /dev/null +++ b/tests/topotests/nhrp_redundancy/nhs3/nhrp_route_nhs1_down.json @@ -0,0 +1,48 @@ +{ + "176.16.1.4\/32": [ + { + "prefix": "176.16.1.4\/32", + "protocol": "nhrp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 10, + "metric": 0, + "installed": true, + "internalNextHopNum": 1, + "internalNextHopActiveNum": 1, + "nexthops": [ + { + "fib": true, + "directlyConnected": true, + "interfaceName": "nhs3-gre0", + "active": true + } + ] + } + ], + "176.16.1.5\/32": [ + { + "prefix": "176.16.1.5\/32", + "protocol": "nhrp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 10, + "metric": 0, + "installed": true, + "internalNextHopNum": 1, + "internalNextHopActiveNum": 1, + "nexthops": [ + { + "fib": true, + "directlyConnected": true, + "interfaceName": "nhs3-gre0", + "active": true + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/topotests/nhrp_redundancy/test_nhrp_redundancy.py b/tests/topotests/nhrp_redundancy/test_nhrp_redundancy.py index 441bd56adf..f45006bd27 100644 --- a/tests/topotests/nhrp_redundancy/test_nhrp_redundancy.py +++ b/tests/topotests/nhrp_redundancy/test_nhrp_redundancy.py @@ -306,7 +306,6 @@ def verify_shortcut_path(): def test_redundancy_shortcut(): """ Assert that if shortcut created and then NHS goes down, there is no traffic disruption - Stop traffic and verify next time traffic started, shortcut is initiated by backup NHS """ tgen = get_topogen() if tgen.routers_have_failure(): @@ -364,10 +363,66 @@ def test_redundancy_shortcut(): assertmsg = '"{}" JSON output mismatches'.format(nhc1.name) assert result is None, assertmsg + +def test_redundancy_shortcut_backup(): + """ + 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() + # 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) + # Check NHRP cache on servers and clients + for rname, router in router_list.items(): + if "nh" not in rname: + continue + if "nhs1" in rname: + continue + + json_file = "{}/{}/nhrp_cache_nhs1_down.json".format(CWD, router.name) + expected = json.loads(open(json_file).read()) + test_func = partial( + topotest.router_json_cmp, router, "show ip nhrp cache json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=40, wait=0.5) + + output = router.vtysh_cmd("show ip nhrp cache") + logger.info(output) + + assertmsg = '"{}" JSON output mismatches'.format(router.name) + assert result is None, assertmsg + + # Check NHRP IPV4 routes on servers and clients + logger.info("Checking IPv4 routes for convergence") + for rname, router in router_list.items(): + if "nh" not in rname: + continue + if "nhs1" in rname: + continue + + json_file = "{}/{}/nhrp_route_nhs1_down.json".format(CWD, router.name) + expected = json.loads(open(json_file).read()) + test_func = partial( + topotest.router_json_cmp, router, "show ip route nhrp json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=40, wait=0.5) + + output = router.vtysh_cmd("show ip route nhrp") + logger.info(output) + + assertmsg = '"{}" JSON output mismatches'.format(router.name) + assert result is None, assertmsg + # Verify shortcut is still active host = tgen.gears["host"] logger.info("Check Ping IPv4 from host to nhc2 via shortcut = 5.5.5.5") @@ -380,6 +435,20 @@ def test_redundancy_shortcut(): else: logger.info("Check Ping IPv4 from host to nhc2 via shortcut OK") + # Verify 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 + + expected = json.loads(open(json_file).read()) + test_func = partial( + topotest.router_json_cmp, nhc1, "show ip route nhrp json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=40, wait=0.5) + + output = nhc1.vtysh_cmd("show ip route nhrp") + logger.info(output) + # Now verify shortcut is purged with lack of traffic json_file = "{}/{}/nhrp_route_nhs1_down.json".format(CWD, nhc1.name) assertmsg = "No nhrp_route file found"