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 Jan 23, 2024
1 parent fd90e55 commit 7f3840e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 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
51 changes: 42 additions & 9 deletions tests/topotests/all_protocol_startup/test_all_protocol_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def route_get_nhg_id(route_str):
return nhg_id


def verify_nexthop_group(nhg_id, recursive=False, ecmp=0):
def verify_nexthop_group(nhg_id, recursive=False, ecmp=0, recursive_count=None):
net = get_topogen().net
count = 0
valid = None
Expand All @@ -417,7 +417,9 @@ def verify_nexthop_group(nhg_id, recursive=False, ecmp=0):
sleep(1)
continue

if ecmp or recursive:
if recursive_count and recursive:
recursive_count = recursive_count - 1
if ecmp or (recursive and not recursive_count):
ecmpcount = re.search(r"Depends:.*\n", output)
if ecmpcount is None:
found = False
Expand All @@ -433,14 +435,13 @@ def verify_nexthop_group(nhg_id, recursive=False, ecmp=0):
sleep(1)
continue
else:
# If recursive, we need to look at its resolved group
if len(depends) != 1:
found = False
sleep(1)
continue

resolved_id = int(depends[0])
verify_nexthop_group(resolved_id, False)
verify_nexthop_group(resolved_id, recursive=recursive)
else:
installed = re.search(r"Installed", output)
if installed is None:
Expand All @@ -450,7 +451,7 @@ def verify_nexthop_group(nhg_id, recursive=False, ecmp=0):
found = True

assert valid is not None, "Nexthop Group ID=%d not marked Valid" % nhg_id
if ecmp or recursive:
if ecmp or (recursive and not recursive_count):
assert ecmpcount is not None, "Nexthop Group ID=%d has no depends" % nhg_id
if ecmp:
assert len(depends) == ecmp, (
Expand All @@ -466,10 +467,10 @@ def verify_nexthop_group(nhg_id, recursive=False, ecmp=0):
)


def verify_route_nexthop_group(route_str, recursive=False, ecmp=0):
def verify_route_nexthop_group(route_str, recursive=False, ecmp=0, recursive_count=None):
# Verify route and that zebra created NHGs for and they are valid/installed
nhg_id = route_get_nhg_id(route_str)
verify_nexthop_group(nhg_id, recursive, ecmp)
verify_nexthop_group(nhg_id, recursive, ecmp, recursive_count)


def test_nexthop_groups():
Expand Down Expand Up @@ -515,7 +516,7 @@ def test_nexthop_groups():
'vtysh -c "sharp install routes 3.3.3.1 nexthop-group basic-recursive 1"'
)

verify_route_nexthop_group("3.3.3.1/32", True)
verify_route_nexthop_group("3.3.3.1/32", True, recursive_count=3)

## Duplicate

Expand Down Expand Up @@ -613,6 +614,38 @@ def test_nexthop_groups():
% nhg_id
)

## nexthop-group ALLOWRECURSION
## create a static route, and use that static route to resolve the nexthop-group
tgen = get_topogen()
tgen.gears["r1"].vtysh_cmd(
"""
configure terminal
nexthop-group ALLOWRECURSION
allow-recursion
nexthop 192.0.2.200
"""
)
tgen.gears["r1"].vtysh_cmd(
"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(nhg_id, recursive=True, ecmp=0, recursive_count=2)

tgen.gears["r1"].vtysh_cmd("sharp remove routes 9.9.9.9 1")
tgen.gears["r1"].vtysh_cmd(
"""
configure terminal
nexthop-group ALLOWRECURSION
no allow-recursion
"""
)
output = tgen.gears["r1"].vtysh_cmd("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 Expand Up @@ -1409,7 +1442,7 @@ def test_nexthop_groups_with_route_maps():

# Create a lib nexthop-group
net["r1"].cmd(
'vtysh -c "c t" -c "nexthop-group test" -c "nexthop 1.1.1.1" -c "nexthop 1.1.1.2"'
'vtysh -c "c t" -c "nexthop-group test" -c "no allow-recursion" -c "nexthop 1.1.1.1" -c "nexthop 1.1.1.2"'
)

## Route-Map Proto Source
Expand Down

0 comments on commit 7f3840e

Please sign in to comment.