-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Zebra resilience configuration #22330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
donaldsharp
wants to merge
2
commits into
FRRouting:master
Choose a base branch
from
donaldsharp:zebra_resilience
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| ! | ||
| hostname r1 | ||
| ! | ||
| zebra nexthop-group resilience buckets 8 idle-timer 100 unbalanced-timer 200 | ||
| ! | ||
| interface r1-eth0 | ||
| ip address 192.168.1.1/24 | ||
| ! | ||
| interface r1-eth1 | ||
| ip address 192.168.2.1/24 | ||
| ! | ||
| ip route 10.0.0.0/24 192.168.1.2 r1-eth0 | ||
| ip route 10.0.0.0/24 192.168.2.2 r1-eth1 | ||
| ! | ||
| ip route 10.1.1.0/24 192.168.1.2 r1-eth0 | ||
| ! |
186 changes: 186 additions & 0 deletions
186
tests/topotests/zebra_nhg_resilience/test_zebra_nhg_resilience.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| #!/usr/bin/env python | ||
| # SPDX-License-Identifier: ISC | ||
|
|
||
| # | ||
| # Copyright (c) 2026 by Nvidia Corporation | ||
| # Donald Sharp | ||
| # | ||
|
|
||
| """ | ||
| Test that 'zebra nexthop-group resilience ...' causes every zebra-created | ||
| multipath nexthop group to be installed as a resilient nexthop group using | ||
| the configured parameters, while singleton groups are left alone and the | ||
| configuration can be removed again. | ||
| """ | ||
|
|
||
| import os | ||
| import sys | ||
| import json | ||
| import functools | ||
| import pytest | ||
|
|
||
| CWD = os.path.dirname(os.path.realpath(__file__)) | ||
| sys.path.append(os.path.join(CWD, "../")) | ||
|
|
||
| # pylint: disable=C0413 | ||
| from lib import topotest | ||
| from lib.topogen import Topogen, TopoRouter, get_topogen | ||
| from lib.common_config import step | ||
|
|
||
| pytestmark = [pytest.mark.mgmtd, pytest.mark.staticd] | ||
|
|
||
|
|
||
| def build_topo(tgen): | ||
| tgen.add_router("r1") | ||
|
|
||
| switch = tgen.add_switch("s1") | ||
| switch.add_link(tgen.gears["r1"]) | ||
|
|
||
| switch = tgen.add_switch("s2") | ||
| switch.add_link(tgen.gears["r1"]) | ||
|
|
||
|
|
||
| def setup_module(mod): | ||
| tgen = Topogen(build_topo, mod.__name__) | ||
| tgen.start_topology() | ||
|
|
||
| for rname, router in tgen.routers().items(): | ||
| router.load_frr_config( | ||
| os.path.join(CWD, "{}/frr.conf".format(rname)), | ||
| [ | ||
| (TopoRouter.RD_MGMTD, None), | ||
| (TopoRouter.RD_ZEBRA, None), | ||
| (TopoRouter.RD_STATIC, None), | ||
| ], | ||
| ) | ||
|
|
||
| tgen.start_router() | ||
|
|
||
|
|
||
| def teardown_module(mod): | ||
| tgen = get_topogen() | ||
| tgen.stop_topology() | ||
|
|
||
|
|
||
| def _route_nhg_id(router, prefix): | ||
| """Return the nexthop group id zebra assigned to a route, or None.""" | ||
| output = json.loads(router.vtysh_cmd("show ip route {} json".format(prefix))) | ||
|
|
||
| entries = output.get(prefix) | ||
| if not entries: | ||
| return None | ||
|
|
||
| return entries[0].get("nexthopGroupId") | ||
|
|
||
|
|
||
| def _check_nhg_resilience(router, prefix, buckets, idle, unbalanced, count): | ||
| """Verify the route's nexthop group is resilient with the given params.""" | ||
| nhgid = _route_nhg_id(router, prefix) | ||
| if nhgid is None: | ||
| return "{}: no nexthop group id installed yet".format(prefix) | ||
|
|
||
| output = json.loads( | ||
| router.vtysh_cmd("show nexthop-group rib {} json".format(nhgid)) | ||
| ) | ||
|
|
||
| expected = { | ||
| str(nhgid): { | ||
| "nexthopCount": count, | ||
| "buckets": buckets, | ||
| "idleTimer": idle, | ||
| "unbalancedTimer": unbalanced, | ||
| } | ||
| } | ||
|
|
||
| return topotest.json_cmp(output, expected) | ||
|
|
||
|
|
||
| def _check_nhg_not_resilient(router, prefix): | ||
| """Verify the route's nexthop group has no resilience configured.""" | ||
| nhgid = _route_nhg_id(router, prefix) | ||
| if nhgid is None: | ||
| return "{}: no nexthop group id installed yet".format(prefix) | ||
|
|
||
| output = json.loads( | ||
| router.vtysh_cmd("show nexthop-group rib {} json".format(nhgid)) | ||
| ) | ||
|
|
||
| group = output.get(str(nhgid)) | ||
| if group is None: | ||
| return "{}: nexthop group {} not found".format(prefix, nhgid) | ||
|
|
||
| if "buckets" in group: | ||
| return "{}: nexthop group {} unexpectedly resilient: {}".format( | ||
| prefix, nhgid, group | ||
| ) | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| def test_multipath_route_is_resilient(): | ||
| tgen = get_topogen() | ||
|
|
||
| if tgen.routers_have_failure(): | ||
| pytest.skip(tgen.errors) | ||
|
|
||
| router = tgen.gears["r1"] | ||
|
|
||
| step("Multipath route inherits the configured resilience parameters") | ||
|
|
||
| test_func = functools.partial( | ||
| _check_nhg_resilience, router, "10.0.0.0/24", 8, 100, 200, 2 | ||
| ) | ||
| _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) | ||
| assert result is None, "Multipath nexthop group was not made resilient" | ||
|
|
||
|
|
||
| def test_singleton_route_is_not_resilient(): | ||
| tgen = get_topogen() | ||
|
|
||
| if tgen.routers_have_failure(): | ||
| pytest.skip(tgen.errors) | ||
|
|
||
| router = tgen.gears["r1"] | ||
|
|
||
| step("Singleton route is not made resilient") | ||
|
|
||
| test_func = functools.partial(_check_nhg_not_resilient, router, "10.1.1.0/24") | ||
| _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) | ||
| assert result is None, "Singleton nexthop group should not be resilient" | ||
|
|
||
|
|
||
| def test_resilience_removal(): | ||
| tgen = get_topogen() | ||
|
|
||
| if tgen.routers_have_failure(): | ||
| pytest.skip(tgen.errors) | ||
|
|
||
| router = tgen.gears["r1"] | ||
|
|
||
| step("Removing the configuration stops new groups from being resilient") | ||
|
|
||
| router.vtysh_cmd("configure terminal\nno zebra nexthop-group resilience") | ||
| router.vtysh_cmd( | ||
| "configure terminal\n" | ||
| "ip route 10.2.2.0/24 192.168.1.2 r1-eth0\n" | ||
| "ip route 10.2.2.0/24 192.168.2.2 r1-eth1" | ||
| ) | ||
|
|
||
| test_func = functools.partial(_check_nhg_not_resilient, router, "10.2.2.0/24") | ||
| _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) | ||
| assert ( | ||
| result is None | ||
| ), "Multipath group created after removal should not be resilient" | ||
|
|
||
| step("Existing resilient group is untouched by the removal") | ||
|
|
||
| test_func = functools.partial( | ||
| _check_nhg_resilience, router, "10.0.0.0/24", 8, 100, 200, 2 | ||
| ) | ||
| _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) | ||
| assert result is None, "Existing resilient nexthop group should be unchanged" | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| args = ["-s"] + sys.argv[1:] | ||
| sys.exit(pytest.main(args)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__init__.pyin test directoryEvery other
zebra_*topotest directory ships an__init__.py(e.g.zebra_netlink/,zebra_opaque/,zebra_reserved_ranges/, etc.). Without it, pytest running in defaultprependimport mode may fail to collect this test or, if two identically-named test files ever appear in different directories, produce anImportErrorfor a naming collision. The file is simply empty (\n), but its absence is inconsistent with the rest of the test suite and will cause problems in some CI environments.Prompt To Fix With AI