diff options
| author | Jafar Al-Gharaibeh <jafar@atcorp.com> | 2025-02-28 14:46:40 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-28 14:46:40 -0600 |
| commit | 13b386b65795f1b79968e251365e870e1309734d (patch) | |
| tree | d585660b2fdb4648bf7e48108de7844ef862a892 | |
| parent | 3a8426fe4da6415e47c2d26c07f0cebb9e96432f (diff) | |
| parent | dc9c6adf4d112f7f94d194a413e32f4698eafea5 (diff) | |
Merge pull request #18284 from FRRouting/mergify/bp/dev/10.3/pr-18263
staticd: Add `no` form for `static-sids` command (backport #18263)
| -rw-r--r-- | staticd/static_nb.h | 4 | ||||
| -rw-r--r-- | staticd/static_vty.c | 16 | ||||
| -rw-r--r-- | tests/topotests/static_srv6_sids/expected_srv6_sids_delete_all.json | 1 | ||||
| -rwxr-xr-x | tests/topotests/static_srv6_sids/test_static_srv6_sids.py | 79 | ||||
| -rw-r--r-- | vtysh/vtysh.c | 9 |
5 files changed, 107 insertions, 2 deletions
diff --git a/staticd/static_nb.h b/staticd/static_nb.h index aa11f34021..4902327b95 100644 --- a/staticd/static_nb.h +++ b/staticd/static_nb.h @@ -172,6 +172,10 @@ int routing_control_plane_protocols_name_validate( "frr-staticd:staticd/segment-routing/srv6" /* srv6/static-sids */ +#define FRR_STATIC_SRV6_STATIC_SIDS_XPATH \ + FRR_STATIC_SRV6_INFO_KEY_XPATH \ + "/static-sids" + #define FRR_STATIC_SRV6_SID_KEY_XPATH \ FRR_STATIC_SRV6_INFO_KEY_XPATH \ "/static-sids/" \ diff --git a/staticd/static_vty.c b/staticd/static_vty.c index f93e81e8dc..13a61e52c7 100644 --- a/staticd/static_vty.c +++ b/staticd/static_vty.c @@ -1174,10 +1174,22 @@ DEFUN_YANG_NOSH (no_static_srv6, no_static_srv6_cmd, return nb_cli_apply_changes(vty, "%s", xpath); } -DEFUN_NOSH (static_srv6_sids, static_srv6_sids_cmd, - "static-sids", +DEFPY_YANG_NOSH (static_srv6_sids, static_srv6_sids_cmd, + "[no] static-sids", + NO_STR "Segment Routing SRv6 SIDs\n") { + char xpath[XPATH_MAXLEN]; + + if (no) { + snprintf(xpath, sizeof(xpath), FRR_STATIC_SRV6_STATIC_SIDS_XPATH, + "frr-staticd:staticd", "staticd", VRF_DEFAULT_NAME); + + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + + return nb_cli_apply_changes(vty, "%s", xpath); + } + VTY_PUSH_CONTEXT_NULL(SRV6_SIDS_NODE); return CMD_SUCCESS; } diff --git a/tests/topotests/static_srv6_sids/expected_srv6_sids_delete_all.json b/tests/topotests/static_srv6_sids/expected_srv6_sids_delete_all.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/tests/topotests/static_srv6_sids/expected_srv6_sids_delete_all.json @@ -0,0 +1 @@ +{}
\ No newline at end of file diff --git a/tests/topotests/static_srv6_sids/test_static_srv6_sids.py b/tests/topotests/static_srv6_sids/test_static_srv6_sids.py index cdcc6fd29e..4bed5bf788 100755 --- a/tests/topotests/static_srv6_sids/test_static_srv6_sids.py +++ b/tests/topotests/static_srv6_sids/test_static_srv6_sids.py @@ -172,6 +172,85 @@ def test_srv6_static_sids_sid_readd(): check_srv6_static_sids(router, "expected_srv6_sids.json") +def test_srv6_static_sids_sid_delete_all(): + """ + Remove all static SIDs and verify they get removed + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + router = tgen.gears["r1"] + + def _check_srv6_static_sids(router, expected_route_file): + logger.info("checking zebra srv6 static sids") + output = json.loads(router.vtysh_cmd("show ipv6 route static json")) + expected = open_json_file("{}/{}".format(CWD, expected_route_file)) + return topotest.json_cmp(output, expected, exact=True) + + def check_srv6_static_sids(router, expected_file): + func = functools.partial(_check_srv6_static_sids, router, expected_file) + _, result = topotest.run_and_expect(func, None, count=15, wait=1) + assert result is None, "Failed" + + router.vtysh_cmd( + """ + configure terminal + segment-routing + srv6 + no static-sids + """ + ) + + # FOR DEVELOPER: + # If you want to stop some specific line and start interactive shell, + # please use tgen.mininet_cli() to start it. + + logger.info("Test for srv6 sids configuration") + check_srv6_static_sids(router, "expected_srv6_sids_delete_all.json") + + +def test_srv6_static_sids_sid_readd_all(): + """ + Re-add the static SIDs and verify the routing table + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + router = tgen.gears["r1"] + + def _check_srv6_static_sids(router, expected_route_file): + logger.info("checking zebra srv6 static sids") + output = json.loads(router.vtysh_cmd("show ipv6 route static json")) + expected = open_json_file("{}/{}".format(CWD, expected_route_file)) + return topotest.json_cmp(output, expected) + + def check_srv6_static_sids(router, expected_file): + func = functools.partial(_check_srv6_static_sids, router, expected_file) + _, result = topotest.run_and_expect(func, None, count=15, wait=1) + assert result is None, "Failed" + + router.vtysh_cmd( + """ + configure terminal + segment-routing + srv6 + static-sids + sid fcbb:bbbb:1::/48 locator MAIN behavior uN + sid fcbb:bbbb:1:fe10::/64 locator MAIN behavior uDT4 vrf Vrf10 + sid fcbb:bbbb:1:fe20::/64 locator MAIN behavior uDT6 vrf Vrf20 + sid fcbb:bbbb:1:fe30::/64 locator MAIN behavior uDT46 vrf Vrf30 + sid fcbb:bbbb:1:fe40::/64 locator MAIN behavior uA interface sr0 nexthop 2001::2 + """ + ) + + # FOR DEVELOPER: + # If you want to stop some specific line and start interactive shell, + # please use tgen.mininet_cli() to start it. + + logger.info("Test for srv6 sids configuration") + check_srv6_static_sids(router, "expected_srv6_sids.json") + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 0559e89f92..31e7ce12ba 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -1708,6 +1708,14 @@ DEFUNSH(VTYSH_MGMTD, srv6_sids, srv6_sids_cmd, return CMD_SUCCESS; } +DEFUNSH(VTYSH_MGMTD, no_srv6_sids, no_srv6_sids_cmd, + "no static-sids", + NO_STR + "Segment-Routing SRv6 SIDs configuration\n") +{ + return CMD_SUCCESS; +} + DEFUNSH(VTYSH_ZEBRA, srv6_locators, srv6_locators_cmd, "locators", "Segment-Routing SRv6 locators configuration\n") @@ -5543,6 +5551,7 @@ void vtysh_init_vty(void) install_element(SRV6_NODE, &vtysh_end_all_cmd); install_element(SRV6_NODE, &srv6_encap_cmd); install_element(SRV6_NODE, &srv6_sids_cmd); + install_element(SRV6_NODE, &no_srv6_sids_cmd); install_element(SRV6_SIDS_NODE, &exit_srv6_sids_config_cmd); install_element(SRV6_SIDS_NODE, &vtysh_end_all_cmd); |
