From 45c897f563272d542c4c230e4e4b08b057462f65 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Sat, 20 Jan 2024 03:55:42 +0200 Subject: [PATCH] zebra: convert interface link-params packet-loss command to NB Signed-off-by: Igor Ryzhov --- lib/if.h | 2 +- yang/frr-zebra.yang | 8 ++++++ zebra/interface.c | 62 ++++++++++++----------------------------- zebra/zebra_nb.c | 7 +++++ zebra/zebra_nb.h | 4 +++ zebra/zebra_nb_config.c | 40 ++++++++++++++++++++++++++ 6 files changed, 78 insertions(+), 45 deletions(-) diff --git a/lib/if.h b/lib/if.h index fd5f6f7502e6..548a91b9480d 100644 --- a/lib/if.h +++ b/lib/if.h @@ -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 */ diff --git a/yang/frr-zebra.yang b/yang/frr-zebra.yang index fce8cc23f358..35109016f003 100644 --- a/yang/frr-zebra.yang +++ b/yang/frr-zebra.yang @@ -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) } diff --git a/zebra/interface.c b/zebra/interface.c index 0d4d37ef5ab7..0d9e3a9abeca 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -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); @@ -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); @@ -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, @@ -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)) @@ -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); diff --git a/zebra/zebra_nb.c b/zebra/zebra_nb.c index d5ed6a87cfe5..774af9d26b42 100644 --- a/zebra/zebra_nb.c +++ b/zebra/zebra_nb.c @@ -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 = { diff --git a/zebra/zebra_nb.h b/zebra/zebra_nb.h index bda1b6efcdc4..0c366131fc61 100644 --- a/zebra/zebra_nb.h +++ b/zebra/zebra_nb.h @@ -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 * diff --git a/zebra/zebra_nb_config.c b/zebra/zebra_nb_config.c index ded740595833..4ac81d3c5d60 100644 --- a/zebra/zebra_nb_config.c +++ b/zebra/zebra_nb_config.c @@ -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 */