From 1d36e037c0edac3dfab95d3659e18afc83972d84 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Fri, 8 Dec 2023 22:09:37 +0100 Subject: [PATCH] topotests: add nexthop-group allow-recursion test Add a nexthop group test that ensures that a recursive next-hop is resolved in zebra. Signed-off-by: Philippe Guibert --- .../all_protocol_startup/r1/ip_nht.ref | 8 +++ .../all_protocol_startup/r1/ipv4_routes.ref | 1 + .../all_protocol_startup/r1/zebra.conf | 4 ++ .../test_all_protocol_startup.py | 66 +++++++++++++++++++ 4 files changed, 79 insertions(+) diff --git a/tests/topotests/all_protocol_startup/r1/ip_nht.ref b/tests/topotests/all_protocol_startup/r1/ip_nht.ref index a2f3d3b0db4e..3bc2c7838d52 100644 --- a/tests/topotests/all_protocol_startup/r1/ip_nht.ref +++ b/tests/topotests/all_protocol_startup/r1/ip_nht.ref @@ -53,6 +53,10 @@ VRF default: 6.6.6.4 unresolved Client list: pbr(fd XX) +192.0.2.200 + resolved via static + via 192.168.0.208, r1-eth0 (vrf default), weight 1 + Client list: pbr(fd XX) 192.168.0.2 resolved via connected is directly connected, r1-eth0 (vrf default) @@ -61,6 +65,10 @@ VRF default: resolved via connected is directly connected, r1-eth0 (vrf default) Client list: static(fd XX) +192.168.0.208 + resolved via connected + is directly connected, r1-eth0 (vrf default) + Client list: static(fd XX) 192.168.7.10 resolved via connected is directly connected, r1-eth7 (vrf default) diff --git a/tests/topotests/all_protocol_startup/r1/ipv4_routes.ref b/tests/topotests/all_protocol_startup/r1/ipv4_routes.ref index a4a4aba3d181..c9c08dff7ec2 100644 --- a/tests/topotests/all_protocol_startup/r1/ipv4_routes.ref +++ b/tests/topotests/all_protocol_startup/r1/ipv4_routes.ref @@ -28,6 +28,7 @@ S>* 1.1.1.5/32 [1/0] is directly connected, r1-eth5, weight 1, XX:XX:XX S>* 1.1.1.6/32 [1/0] is directly connected, r1-eth6, weight 1, XX:XX:XX S>* 1.1.1.7/32 [1/0] is directly connected, r1-eth7, weight 1, XX:XX:XX S>* 1.1.1.8/32 [1/0] is directly connected, r1-eth8, weight 1, XX:XX:XX +S>* 192.0.2.0/24 [1/0] via 192.168.0.208, r1-eth0, weight 1, XX:XX:XX S>* 4.5.6.10/32 [1/0] via 192.168.0.2, r1-eth0, weight 1, XX:XX:XX S>* 4.5.6.11/32 [1/0] via 192.168.0.2, r1-eth0, weight 1, XX:XX:XX S>* 4.5.6.12/32 [1/0] is directly connected, r1-eth0, weight 1, XX:XX:XX diff --git a/tests/topotests/all_protocol_startup/r1/zebra.conf b/tests/topotests/all_protocol_startup/r1/zebra.conf index c5ef79630e21..76dbbdc042a4 100644 --- a/tests/topotests/all_protocol_startup/r1/zebra.conf +++ b/tests/topotests/all_protocol_startup/r1/zebra.conf @@ -46,6 +46,10 @@ ip route 4.5.6.16/32 192.168.0.4 10 ip route 4.5.6.17/32 192.168.0.2 tag 9000 ip route 4.5.6.17/32 192.168.0.2 tag 10000 +# Create a static route to test recursive +# resolution +ip route 192.0.2.0/24 192.168.0.208 + ! interface r1-eth0 description to sw0 - no routing protocol diff --git a/tests/topotests/all_protocol_startup/test_all_protocol_startup.py b/tests/topotests/all_protocol_startup/test_all_protocol_startup.py index ca340749feb7..9dc317655177 100644 --- a/tests/topotests/all_protocol_startup/test_all_protocol_startup.py +++ b/tests/topotests/all_protocol_startup/test_all_protocol_startup.py @@ -466,6 +466,49 @@ def verify_nexthop_group(nhg_id, recursive=False, ecmp=0): ) +def verify_nexthop_group_recursive(nhg_id): + net = get_topogen().net + count = 0 + valid = None + ecmpcount = None + depends = None + resolved_id = None + installed = None + found = False + + while not found and count < 10: + count += 1 + # Verify NHG is valid/installed + output = net["r1"].cmd('vtysh -c "show nexthop-group rib %d"' % nhg_id) + valid = re.search(r"Valid", output) + if valid is None: + found = False + sleep(1) + continue + + ecmpcount = re.search(r"Depends:.*\n", output) + if ecmpcount is None: + found = False + sleep(1) + continue + + # list of IDs in group + depends = re.findall(r"\((\d+)\)", ecmpcount.group(0)) + + installed = re.search(r"Installed", output) + if installed is None: + found = False + sleep(1) + continue + found = True + + assert valid is not None, "Nexthop Group ID=%d not marked Valid" % nhg_id + assert ecmpcount is not None, "Nexthop Group ID=%d has no depends" % nhg_id + assert len(depends) == 1, ( + "Nexthop Group ID=%d should only have one recursive depend" % nhg_id + ) + + def verify_route_nexthop_group(route_str, recursive=False, ecmp=0): # Verify route and that zebra created NHGs for and they are valid/installed nhg_id = route_get_nhg_id(route_str) @@ -613,6 +656,29 @@ def test_nexthop_groups(): % nhg_id ) + ## nexthop-group allow-recursion + ## create a static route, and use that static route to resolve the nexthop-group + net["r1"].cmd('vtysh -c "c t" -c "zebra nexthop-group keep 10"') + net["r1"].cmd( + 'vtysh -c "c t" -c "nexthop-group allowrecursion" -c "allow-recursion" -c "nexthop 192.0.2.200"' + ) + net["r1"].cmd( + 'vtysh -c "sharp install routes 9.9.9.9 nexthop-group allowrecursion 1"' + ) + nhg_id = route_get_nhg_id("9.9.9.9/32") + verify_nexthop_group_recursive(nhg_id) + + net["r1"].cmd('vtysh -c "sharp remove routes 9.9.9.9 1"') + net["r1"].cmd( + 'vtysh -c "c t" -c "nexthop-group allowrecursion" -c "no allow-recursion"' + ) + output = net["r1"].cmd('vtysh -c "show nexthop-group rib %d"' % nhg_id) + found = re.search(r"Time to Deletion", output) + assert found is not None, ( + "Route 9.9.9.9/32 with Nexthop Group ID=%d is not scheduled for removal" + % nhg_id + ) + ## Remove all NHG routes net["r1"].cmd('vtysh -c "sharp remove routes 2.2.2.1 1"')