From 8b71e8790cd5922b52de9bef00e6cb4da651d4e9 Mon Sep 17 00:00:00 2001 From: Diogo Oliveira <14191454+dorDiogo@users.noreply.github.com> Date: Fri, 20 Jan 2023 17:08:45 -0800 Subject: [PATCH] tests: Add test to check hello padding sometimes behavior Signed-off-by: Diogo Oliveira <14191454+dorDiogo@users.noreply.github.com> --- .../r1/show_isis_interface_detail.ref | 4 +- tests/topotests/isis_topo1/test_isis_topo1.py | 92 +++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/tests/topotests/all_protocol_startup/r1/show_isis_interface_detail.ref b/tests/topotests/all_protocol_startup/r1/show_isis_interface_detail.ref index 0534b64d33..865970065c 100644 --- a/tests/topotests/all_protocol_startup/r1/show_isis_interface_detail.ref +++ b/tests/topotests/all_protocol_startup/r1/show_isis_interface_detail.ref @@ -3,7 +3,7 @@ Area test: Type: lan, Level: L1, SNPA: XXXX.XXXX.XXXX Level-1 Information: Metric: 10, Active neighbors: 0 - Hello interval: 3, Holddown count: 10 (pad) + Hello interval: 3, Holddown count: 10, Padding: yes CNSP interval: 10, PSNP interval: 2 LAN Priority: 64, is not DIS IP Prefix(es): @@ -17,7 +17,7 @@ Area test: Type: lan, Level: L2, SNPA: XXXX.XXXX.XXXX Level-2 Information: Metric: 10, Active neighbors: 0 - Hello interval: 3, Holddown count: 10 (pad) + Hello interval: 3, Holddown count: 10, Padding: yes CNSP interval: 10, PSNP interval: 2 LAN Priority: 64, is not DIS IP Prefix(es): diff --git a/tests/topotests/isis_topo1/test_isis_topo1.py b/tests/topotests/isis_topo1/test_isis_topo1.py index baacba613d..5e660ef9e1 100644 --- a/tests/topotests/isis_topo1/test_isis_topo1.py +++ b/tests/topotests/isis_topo1/test_isis_topo1.py @@ -572,6 +572,98 @@ def test_isis_advertise_passive_only(): assert result is True, result +def test_isis_hello_padding_sometimes(): + """Check that IIH packets is only padded when adjacency is still being formed + when isis hello padding sometimes is configured + """ + tgen = get_topogen() + net = get_topogen().net + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("Testing isis hello padding sometimes behavior") + r3 = tgen.gears["r3"] + + # Reduce hello-multiplier to make the adjacency go down faster. + r3.vtysh_cmd( + """ + configure + interface r3-eth0 + isis hello-multiplier 2 + """ + ) + + r1 = tgen.gears["r1"] + cmd_output = r1.vtysh_cmd( + """ + configure + interface r1-eth0 + isis hello padding sometimes + end + debug isis adj-packets + """ + ) + result = check_last_iih_packet_for_padding(r1, expect_padding=False) + assert result is True, result + + r3.vtysh_cmd( + """ + configure + interface r3-eth0 + shutdown + """ + ) + result = check_last_iih_packet_for_padding(r1, expect_padding=True) + assert result is True, result + + r3 = tgen.gears["r3"] + r3.vtysh_cmd( + """ + configure + interface r3-eth0 + no shutdown + """ + ) + result = check_last_iih_packet_for_padding(r1, expect_padding=False) + assert result is True, result + + +@retry(retry_timeout=5) +def check_last_iih_packet_for_padding(router, expect_padding): + logfilename = "{}/{}".format(router.gearlogdir, "isisd.log") + last_hello_packet_line = None + with open(logfilename, "r") as f: + lines = f.readlines() + for line in lines: + if re.search("Sending .+? IIH", line): + last_hello_packet_line = line + + if last_hello_packet_line is None: + return "Expected IIH packet in {}, but no packet found".format(logfilename) + + interface_name, packet_length = re.search( + r"Sending .+ IIH on (.+), length (\d+)", last_hello_packet_line + ).group(1, 2) + packet_length = int(packet_length) + interface_output = router.vtysh_cmd("show interface {} json".format(interface_name)) + interface_json = json.loads(interface_output) + padded_packet_length = interface_json[interface_name]["mtu"] - 3 + if expect_padding: + if packet_length == padded_packet_length: + return True + return ( + "Expected padded packet with length {}, got packet with length {}".format( + padded_packet_length, packet_length + ) + ) + if packet_length < padded_packet_length: + return True + return "Expected unpadded packet with length less than {}, got packet with length {}".format( + padded_packet_length, packet_length + ) + + @retry(retry_timeout=5) def check_advertised_prefixes(router, lsp_id, expected_prefixes): output = router.vtysh_cmd("show isis database detail {}".format(lsp_id)) -- 2.39.5