zebra: convert interface evpn mh es-df-pref command to NB

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
This commit is contained in:
Igor Ryzhov 2024-01-22 21:52:09 +02:00
parent a6db1c14a4
commit 7c6e41ecff
7 changed files with 66 additions and 31 deletions

View File

@ -2245,6 +2245,12 @@ module frr-zebra {
}
}
}
leaf df-preference {
type uint16;
default "32767";
description
"Preference value used for DF election.";
}
}
container state {
config false;

View File

@ -148,6 +148,8 @@ static int if_zebra_new_hook(struct interface *ifp)
rtadv_if_init(zebra_if);
zebra_evpn_mh_if_init(zebra_if);
memset(&zebra_if->neigh_mac[0], 0, 6);
/* Initialize installed address chains tree. */

View File

@ -2251,8 +2251,7 @@ static void zebra_evpn_es_local_info_set(struct zebra_evpn_es *es,
/* attach es to interface */
zif->es_info.es = es;
es->df_pref = zif->es_info.df_pref ? zif->es_info.df_pref
: EVPN_MH_DF_PREF_DEFAULT;
es->df_pref = zif->es_info.df_pref;
/* attach interface to es */
es->zif = zif;
@ -2706,10 +2705,9 @@ void zebra_evpn_es_cleanup(void)
}
}
static void zebra_evpn_es_df_pref_update(struct zebra_if *zif, uint16_t df_pref)
void zebra_evpn_es_df_pref_update(struct zebra_if *zif, uint16_t df_pref)
{
struct zebra_evpn_es *es;
uint16_t tmp_pref;
if (zif->es_info.df_pref == df_pref)
return;
@ -2720,13 +2718,10 @@ static void zebra_evpn_es_df_pref_update(struct zebra_if *zif, uint16_t df_pref)
if (!es)
return;
tmp_pref = zif->es_info.df_pref ? zif->es_info.df_pref
: EVPN_MH_DF_PREF_DEFAULT;
if (es->df_pref == tmp_pref)
if (es->df_pref == zif->es_info.df_pref)
return;
es->df_pref = tmp_pref;
es->df_pref = zif->es_info.df_pref;
/* run df election */
zebra_evpn_es_run_df_election(es, __func__);
/* notify bgp */
@ -3330,7 +3325,7 @@ int zebra_evpn_mh_if_write(struct vty *vty, struct interface *ifp)
vty_out(vty, " evpn mh es-id %s\n",
esi_to_str(&zif->es_info.esi, esi_buf, sizeof(esi_buf)));
if (zif->es_info.df_pref)
if (zif->es_info.df_pref != EVPN_MH_DF_PREF_DEFAULT)
vty_out(vty, " evpn mh es-df-pref %u\n", zif->es_info.df_pref);
if (zif->flags & ZIF_FLAG_EVPN_MH_UPLINK)
@ -3339,6 +3334,11 @@ int zebra_evpn_mh_if_write(struct vty *vty, struct interface *ifp)
return 0;
}
void zebra_evpn_mh_if_init(struct zebra_if *zif)
{
zif->es_info.df_pref = EVPN_MH_DF_PREF_DEFAULT;
}
#include "zebra/zebra_evpn_mh_clippy.c"
/* CLI for setting an ES in bypass mode */
DEFPY_HIDDEN(zebra_evpn_es_bypass, zebra_evpn_es_bypass_cmd,
@ -3364,28 +3364,24 @@ DEFPY_HIDDEN(zebra_evpn_es_bypass, zebra_evpn_es_bypass_cmd,
}
/* CLI for configuring DF preference part for an ES */
DEFPY(zebra_evpn_es_pref, zebra_evpn_es_pref_cmd,
"[no$no] evpn mh es-df-pref [(1-65535)$df_pref]",
NO_STR "EVPN\n" EVPN_MH_VTY_STR
"preference value used for DF election\n"
"pref\n")
DEFPY_YANG (zebra_evpn_es_pref,
zebra_evpn_es_pref_cmd,
"[no$no] evpn mh es-df-pref ![(1-65535)$df_pref]",
NO_STR
"EVPN\n"
EVPN_MH_VTY_STR
"Preference value used for DF election\n"
"Preference\n")
{
VTY_DECLVAR_CONTEXT(interface, ifp);
struct zebra_if *zif;
zif = ifp->info;
if (no) {
zebra_evpn_es_df_pref_update(zif, 0);
} else {
if (!zebra_evpn_is_if_es_capable(zif)) {
vty_out(vty,
"%% DF preference cannot be associated with this interface type\n");
return CMD_WARNING;
}
zebra_evpn_es_df_pref_update(zif, df_pref);
}
return CMD_SUCCESS;
if (!no)
nb_cli_enqueue_change(vty,
"./frr-zebra:zebra/evpn-mh/df-preference",
NB_OP_MODIFY, df_pref_str);
else
nb_cli_enqueue_change(vty,
"./frr-zebra:zebra/evpn-mh/df-preference",
NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, NULL);
}
/* CLI for setting up sysmac part of ESI on an access port */

View File

@ -388,4 +388,8 @@ void zebra_evpn_es_sys_mac_update(struct zebra_if *zif, struct ethaddr *sysmac);
void zebra_evpn_es_lid_update(struct zebra_if *zif, uint32_t lid);
void zebra_evpn_es_type0_esi_update(struct zebra_if *zif, esi_t *esi);
void zebra_evpn_es_df_pref_update(struct zebra_if *zif, uint16_t df_pref);
void zebra_evpn_mh_if_init(struct zebra_if *zif);
#endif /* _ZEBRA_EVPN_MH_H */

View File

@ -528,6 +528,12 @@ const struct frr_yang_module_info frr_zebra_info = {
.destroy = lib_interface_zebra_evpn_mh_type_3_local_discriminator_destroy,
}
},
{
.xpath = "/frr-interface:lib/interface/frr-zebra:zebra/evpn-mh/df-preference",
.cbs = {
.modify = lib_interface_zebra_evpn_mh_df_preference_modify,
}
},
{
.xpath = "/frr-interface:lib/interface/frr-zebra:zebra/state/up-count",
.cbs = {

View File

@ -177,6 +177,8 @@ int lib_interface_zebra_evpn_mh_type_3_local_discriminator_modify(
struct nb_cb_modify_args *args);
int lib_interface_zebra_evpn_mh_type_3_local_discriminator_destroy(
struct nb_cb_destroy_args *args);
int lib_interface_zebra_evpn_mh_df_preference_modify(
struct nb_cb_modify_args *args);
struct yang_data *
lib_interface_zebra_state_up_count_get_elem(struct nb_cb_get_elem_args *args);
struct yang_data *

View File

@ -2400,6 +2400,25 @@ int lib_interface_zebra_evpn_mh_type_3_local_discriminator_destroy(
return NB_OK;
}
/*
* XPath: /frr-interface:lib/interface/frr-zebra:zebra/evpn-mh/df-preference
*/
int lib_interface_zebra_evpn_mh_df_preference_modify(
struct nb_cb_modify_args *args)
{
struct interface *ifp;
uint16_t df_pref;
if (args->event != NB_EV_APPLY)
return NB_OK;
ifp = nb_running_get_entry(args->dnode, NULL, true);
df_pref = yang_dnode_get_uint16(args->dnode, NULL);
zebra_evpn_es_df_pref_update(ifp->info, df_pref);
return NB_OK;
}
/*
* XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/l3vni-id
*/