zebra: convert interface bandwidth command to NB

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
This commit is contained in:
Igor Ryzhov 2024-01-17 17:24:44 +02:00
parent edd3c63170
commit 0c2c01c151
4 changed files with 11 additions and 47 deletions

View File

@ -1993,6 +1993,7 @@ module frr-zebra {
type uint32 { type uint32 {
range "1..100000"; range "1..100000";
} }
units "megabits/sec";
description description
"Link bandwidth informational parameter, in megabits."; "Link bandwidth informational parameter, in megabits.";
} }

View File

@ -3868,52 +3868,23 @@ int if_no_shutdown(struct interface *ifp)
return 0; return 0;
} }
DEFUN (bandwidth_if, DEFPY_YANG (bandwidth_if,
bandwidth_if_cmd, bandwidth_if_cmd,
"bandwidth (1-100000)", "[no] bandwidth ![(1-100000)]$bw",
"Set bandwidth informational parameter\n"
"Bandwidth in megabits\n")
{
int idx_number = 1;
VTY_DECLVAR_CONTEXT(interface, ifp);
unsigned int bandwidth;
bandwidth = strtol(argv[idx_number]->arg, NULL, 10);
/* bandwidth range is <1-100000> */
if (bandwidth < 1 || bandwidth > 100000) {
vty_out(vty, "Bandwidth is invalid\n");
return CMD_WARNING_CONFIG_FAILED;
}
ifp->bandwidth = bandwidth;
/* force protocols to recalculate routes due to cost change */
if (if_is_operative(ifp))
zebra_interface_up_update(ifp);
return CMD_SUCCESS;
}
DEFUN (no_bandwidth_if,
no_bandwidth_if_cmd,
"no bandwidth [(1-100000)]",
NO_STR NO_STR
"Set bandwidth informational parameter\n" "Set bandwidth informational parameter\n"
"Bandwidth in megabits\n") "Bandwidth in megabits\n")
{ {
VTY_DECLVAR_CONTEXT(interface, ifp); if (!no)
nb_cli_enqueue_change(vty, "./frr-zebra:zebra/bandwidth",
NB_OP_CREATE, bw_str);
else
nb_cli_enqueue_change(vty, "./frr-zebra:zebra/bandwidth",
NB_OP_DESTROY, NULL);
ifp->bandwidth = 0; return nb_cli_apply_changes(vty, NULL);
/* force protocols to recalculate routes due to cost change */
if (if_is_operative(ifp))
zebra_interface_up_update(ifp);
return CMD_SUCCESS;
} }
struct cmd_node link_params_node = { struct cmd_node link_params_node = {
.name = "link-params", .name = "link-params",
.node = LINK_PARAMS_NODE, .node = LINK_PARAMS_NODE,
@ -5515,7 +5486,6 @@ void zebra_if_init(void)
install_element(INTERFACE_NODE, &linkdetect_cmd); install_element(INTERFACE_NODE, &linkdetect_cmd);
install_element(INTERFACE_NODE, &shutdown_if_cmd); install_element(INTERFACE_NODE, &shutdown_if_cmd);
install_element(INTERFACE_NODE, &bandwidth_if_cmd); install_element(INTERFACE_NODE, &bandwidth_if_cmd);
install_element(INTERFACE_NODE, &no_bandwidth_if_cmd);
install_element(INTERFACE_NODE, &ip_address_cmd); install_element(INTERFACE_NODE, &ip_address_cmd);
install_element(INTERFACE_NODE, &no_ip_address_cmd); install_element(INTERFACE_NODE, &no_ip_address_cmd);
install_element(INTERFACE_NODE, &ip_address_peer_cmd); install_element(INTERFACE_NODE, &ip_address_peer_cmd);

View File

@ -344,13 +344,6 @@ const struct frr_yang_module_info frr_zebra_info = {
.destroy = lib_interface_zebra_mpls_destroy, .destroy = lib_interface_zebra_mpls_destroy,
} }
}, },
{
.xpath = "/frr-interface:lib/interface/frr-zebra:zebra/bandwidth",
.cbs = {
.modify = lib_interface_zebra_bandwidth_modify,
.destroy = lib_interface_zebra_bandwidth_destroy,
}
},
{ {
.xpath = "/frr-interface:lib/interface/frr-zebra:zebra/link-params/legacy-admin-group", .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/link-params/legacy-admin-group",
.cbs = { .cbs = {

View File

@ -1140,7 +1140,7 @@ int lib_interface_zebra_bandwidth_modify(struct nb_cb_modify_args *args)
uint32_t bandwidth; uint32_t bandwidth;
ifp = nb_running_get_entry(args->dnode, NULL, true); ifp = nb_running_get_entry(args->dnode, NULL, true);
bandwidth = yang_dnode_get_uint32(args->dnode, "bandwidth"); bandwidth = yang_dnode_get_uint32(args->dnode, NULL);
ifp->bandwidth = bandwidth; ifp->bandwidth = bandwidth;