Skip to content

Commit

Permalink
zebra: convert interface link-params packet-loss command to NB
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Ryzhov <[email protected]>
  • Loading branch information
idryzhov committed Jan 20, 2024
1 parent 4995f48 commit 45c897f
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 45 deletions.
2 changes: 1 addition & 1 deletion lib/if.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ struct if_link_params {
uint32_t min_delay; /* Link Min Delay */
uint32_t max_delay; /* Link Max Delay */
uint32_t delay_var; /* Link Delay Variation */
float pkt_loss; /* Link Packet Loss */
uint32_t pkt_loss; /* Link Packet Loss */
float res_bw; /* Residual Bandwidth */
float ava_bw; /* Available Bandwidth */
float use_bw; /* Utilized Bandwidth */
Expand Down
8 changes: 8 additions & 0 deletions yang/frr-zebra.yang
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,14 @@ module frr-zebra {
description
"Unidirectional Delay Variation";
}
leaf packet-loss {
type decimal64 {
fraction-digits 6;
range "0..50.331642";
}
description
"Unidirectional Link Packet Loss";
}
// TODO -- other link-params options
// for (experimental/partial TE use in IGP extensions)
}
Expand Down
62 changes: 18 additions & 44 deletions zebra/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -2882,8 +2882,8 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp)
" Link Delay Variation %u (micro-sec.)\n",
iflp->delay_var);
if (IS_PARAM_SET(iflp, LP_PKT_LOSS))
vty_out(vty, " Link Packet Loss %g (in %%)\n",
iflp->pkt_loss);
vty_out(vty, " Link Packet Loss %f (in %%)\n",
(double)iflp->pkt_loss * LOSS_PRECISION);
if (IS_PARAM_SET(iflp, LP_AVA_BW))
vty_out(vty, " Available Bandwidth %g (Byte/s)\n",
iflp->ava_bw);
Expand Down Expand Up @@ -3283,7 +3283,8 @@ static void if_dump_vty_json(struct vty *vty, struct interface *ifp,
iflp->delay_var);
if (IS_PARAM_SET(iflp, LP_PKT_LOSS))
json_object_double_add(json_te, "linkPacketLoss",
iflp->pkt_loss);
(double)iflp->pkt_loss *
LOSS_PRECISION);
if (IS_PARAM_SET(iflp, LP_AVA_BW))
json_object_double_add(json_te, "availableBandwidth",
iflp->ava_bw);
Expand Down Expand Up @@ -4189,47 +4190,20 @@ DEFPY_YANG (link_params_delay_var,
return nb_cli_apply_changes(vty, NULL);
}

DEFUN (link_params_pkt_loss,
link_params_pkt_loss_cmd,
"packet-loss PERCENTAGE",
"Unidirectional Link Packet Loss\n"
"percentage of total traffic by 0.000003% step and less than 50.331642%\n")
DEFPY_YANG(
link_params_pkt_loss, link_params_pkt_loss_cmd,
"[no] packet-loss ![PERCENTAGE]",
NO_STR
"Unidirectional Link Packet Loss\n"
"percentage of total traffic by 0.000003% step and less than 50.331642%\n")
{
int idx_percentage = 1;
VTY_DECLVAR_CONTEXT(interface, ifp);
struct if_link_params *iflp = if_link_params_get(ifp);
float fval;

if (sscanf(argv[idx_percentage]->arg, "%g", &fval) != 1) {
vty_out(vty, "link_params_pkt_loss: fscanf: %s\n",
safe_strerror(errno));
return CMD_WARNING_CONFIG_FAILED;
}

if (fval > MAX_PKT_LOSS)
fval = MAX_PKT_LOSS;

if (!iflp)
iflp = if_link_params_enable(ifp);

/* Update Packet Loss if needed */
link_param_cmd_set_float(ifp, &iflp->pkt_loss, LP_PKT_LOSS, fval);

return CMD_SUCCESS;
}

DEFUN (no_link_params_pkt_loss,
no_link_params_pkt_loss_cmd,
"no packet-loss",
NO_STR
"Disable Unidirectional Link Packet Loss on this interface\n")
{
VTY_DECLVAR_CONTEXT(interface, ifp);

/* Unset Packet Loss */
link_param_cmd_unset(ifp, LP_PKT_LOSS);
if (!no)
nb_cli_enqueue_change(vty, "./packet-loss", NB_OP_MODIFY,
percentage);
else
nb_cli_enqueue_change(vty, "./packet-loss", NB_OP_DESTROY, NULL);

return CMD_SUCCESS;
return nb_cli_apply_changes(vty, NULL);
}

DEFPY_YANG (link_params_res_bw,
Expand Down Expand Up @@ -4732,7 +4706,8 @@ static int link_params_config_write(struct vty *vty, struct interface *ifp)
if (IS_PARAM_SET(iflp, LP_DELAY_VAR))
vty_out(vty, " delay-variation %u\n", iflp->delay_var);
if (IS_PARAM_SET(iflp, LP_PKT_LOSS))
vty_out(vty, " packet-loss %g\n", iflp->pkt_loss);
vty_out(vty, " packet-loss %f\n",
(double)iflp->pkt_loss * LOSS_PRECISION);
if (IS_PARAM_SET(iflp, LP_AVA_BW))
vty_out(vty, " ava-bw %g\n", iflp->ava_bw);
if (IS_PARAM_SET(iflp, LP_RES_BW))
Expand Down Expand Up @@ -4878,7 +4853,6 @@ void zebra_if_init(void)
install_element(LINK_PARAMS_NODE, &link_params_delay_cmd);
install_element(LINK_PARAMS_NODE, &link_params_delay_var_cmd);
install_element(LINK_PARAMS_NODE, &link_params_pkt_loss_cmd);
install_element(LINK_PARAMS_NODE, &no_link_params_pkt_loss_cmd);
install_element(LINK_PARAMS_NODE, &link_params_ava_bw_cmd);
install_element(LINK_PARAMS_NODE, &link_params_res_bw_cmd);
install_element(LINK_PARAMS_NODE, &link_params_use_bw_cmd);
Expand Down
7 changes: 7 additions & 0 deletions zebra/zebra_nb.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,13 @@ const struct frr_yang_module_info frr_zebra_info = {
.destroy = lib_interface_zebra_link_params_delay_variation_destroy,
}
},
{
.xpath = "/frr-interface:lib/interface/frr-zebra:zebra/link-params/packet-loss",
.cbs = {
.modify = lib_interface_zebra_link_params_packet_loss_modify,
.destroy = lib_interface_zebra_link_params_packet_loss_destroy,
}
},
{
.xpath = "/frr-interface:lib/interface/frr-zebra:zebra/state/up-count",
.cbs = {
Expand Down
4 changes: 4 additions & 0 deletions zebra/zebra_nb.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ int lib_interface_zebra_link_params_delay_variation_modify(
struct nb_cb_modify_args *args);
int lib_interface_zebra_link_params_delay_variation_destroy(
struct nb_cb_destroy_args *args);
int lib_interface_zebra_link_params_packet_loss_modify(
struct nb_cb_modify_args *args);
int lib_interface_zebra_link_params_packet_loss_destroy(
struct nb_cb_destroy_args *args);
struct yang_data *
lib_interface_zebra_state_up_count_get_elem(struct nb_cb_get_elem_args *args);
struct yang_data *
Expand Down
40 changes: 40 additions & 0 deletions zebra/zebra_nb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,46 @@ int lib_interface_zebra_link_params_delay_variation_destroy(
return NB_OK;
}

/*
* XPath: /frr-interface:lib/interface/frr-zebra:zebra/link-params/packet-loss
*/
int lib_interface_zebra_link_params_packet_loss_modify(
struct nb_cb_modify_args *args)
{
struct interface *ifp;
struct if_link_params *iflp;
double packet_loss;
uint32_t value;

if (args->event != NB_EV_APPLY)
return NB_OK;

packet_loss = yang_dnode_get_dec64(args->dnode, NULL);
value = (uint32_t)(packet_loss / LOSS_PRECISION);

ifp = nb_running_get_entry(args->dnode, NULL, true);
iflp = if_link_params_get(ifp);

link_param_cmd_set_uint32(ifp, &iflp->pkt_loss, LP_PKT_LOSS, value);

return NB_OK;
}

int lib_interface_zebra_link_params_packet_loss_destroy(
struct nb_cb_destroy_args *args)
{
struct interface *ifp;

if (args->event != NB_EV_APPLY)
return NB_OK;

ifp = nb_running_get_entry(args->dnode, NULL, true);

link_param_cmd_unset(ifp, LP_PKT_LOSS);

return NB_OK;
}

/*
* XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/l3vni-id
*/
Expand Down

0 comments on commit 45c897f

Please sign in to comment.