Skip to content

Commit

Permalink
topotests: add nexthop-group allow-recursion test
Browse files Browse the repository at this point in the history
Add a nexthop group test that ensures that a recursive
next-hop is resolved in zebra.

Signed-off-by: Philippe Guibert <[email protected]>
  • Loading branch information
pguibert6WIND committed Dec 8, 2023
1 parent 309e922 commit 1d36e03
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/topotests/all_protocol_startup/r1/ip_nht.ref
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/topotests/all_protocol_startup/r1/ipv4_routes.ref
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/topotests/all_protocol_startup/r1/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 66 additions & 0 deletions tests/topotests/all_protocol_startup/test_all_protocol_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"')
Expand Down

0 comments on commit 1d36e03

Please sign in to comment.