Skip to content

Commit

Permalink
Merge pull request #18284 from FRRouting/mergify/bp/dev/10.3/pr-18263
Browse files Browse the repository at this point in the history
staticd: Add `no` form for `static-sids` command (backport #18263)
  • Loading branch information
Jafaral authored Feb 28, 2025
2 parents 3a8426f + dc9c6ad commit 13b386b
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 2 deletions.
4 changes: 4 additions & 0 deletions staticd/static_nb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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/" \
Expand Down
16 changes: 14 additions & 2 deletions staticd/static_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
79 changes: 79 additions & 0 deletions tests/topotests/static_srv6_sids/test_static_srv6_sids.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,85 @@ def check_srv6_static_sids(router, expected_file):
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))
9 changes: 9 additions & 0 deletions vtysh/vtysh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 13b386b

Please sign in to comment.