Skip to content

Commit

Permalink
Merge pull request #15181 from idryzhov/zebra-mgmtd
Browse files Browse the repository at this point in the history
zebra interfaces NB conversion
  • Loading branch information
choppsv1 authored Jan 29, 2024
2 parents d4f83c2 + 15514b6 commit f8755d7
Show file tree
Hide file tree
Showing 60 changed files with 7,520 additions and 5,269 deletions.
22 changes: 8 additions & 14 deletions doc/user/zebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Standard Commands
work on non-linux systems at all. 'enable' and 'disable' will respectively turn
on and off mpls on the given interface.

.. clicmd:: multicast
.. clicmd:: multicast <enable|disable>


Enable or disable multicast flag for the interface.
Expand Down Expand Up @@ -214,20 +214,14 @@ Link Parameters Commands

.. clicmd:: link-params

Enter into the link parameters sub node. This command activates the link
parameters and allows to configure routing information that could be used
as part of Traffic Engineering on this interface. MPLS-TE must be enabled at
the OSPF (:ref:`ospf-traffic-engineering`) or ISIS
(:ref:`isis-traffic-engineering`) router level in complement to this. To
disable link parameters, use the ``no`` version of this command.

Enter into the link parameters sub node. At least 'enable' must be
set to activate the link parameters, and consequently routing
information that could be used as part of Traffic Engineering on
this interface. MPLS-TE must be enable at the OSPF
(:ref:`ospf-traffic-engineering`) or ISIS
(:ref:`isis-traffic-engineering`) router level in complement to
this.

Under link parameter statement, the following commands set the different TE values:

.. clicmd:: enable

Enable link parameters for this interface.
Under link parameter statement, the following commands set the different TE values:

.. clicmd:: metric (0-4294967295)

Expand Down
4 changes: 1 addition & 3 deletions lib/affinitymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct affinity_maps {
DECLARE_QOBJ_TYPE(affinity_maps);

extern const struct frr_yang_module_info frr_affinity_map_info;
extern const struct frr_yang_module_info frr_affinity_map_cli_info;

void affinity_map_set(const char *name, int pos);
void affinity_map_unset(const char *name);
Expand All @@ -69,9 +70,6 @@ void affinity_map_set_update_hook(void (*func)(const char *affmap_name,
uint16_t old_pos,
uint16_t new_pos));

void cli_show_affinity_map(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);

void affinity_map_init(void);


Expand Down
40 changes: 15 additions & 25 deletions lib/affinitymap_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@
#include "lib/affinitymap.h"
#include "lib/affinitymap_cli_clippy.c"

/* Route map node structure. */
static int affinity_map_config_write(struct vty *vty);
static struct cmd_node affinitymap_node = {
.name = "affinity-map",
.node = AFFMAP_NODE,
.prompt = "",
.config_write = affinity_map_config_write,
};

/* max value is EXT_ADMIN_GROUP_MAX_POSITIONS - 1 */
DEFPY_YANG_NOSH(affinity_map, affinity_map_cmd,
"affinity-map NAME$name bit-position (0-1023)$position",
Expand Down Expand Up @@ -75,33 +66,32 @@ DEFPY_YANG_NOSH(no_affinity_map, no_affinity_map_cmd,
return nb_cli_apply_changes(vty, NULL);
}

static int affinity_map_config_write(struct vty *vty)
{
const struct lyd_node *dnode;
int written = 0;

dnode = yang_dnode_get(running_config->dnode, "/frr-affinity-map:lib");
if (dnode) {
nb_cli_show_dnode_cmds(vty, dnode, false);
written = 1;
}

return written;
}

void cli_show_affinity_map(struct vty *vty, const struct lyd_node *dnode,
static void cli_show_affinity_map(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults __attribute__((__unused__)))
{
vty_out(vty, "affinity-map %s bit-position %u\n",
yang_dnode_get_string(dnode, "name"),
yang_dnode_get_uint16(dnode, "value"));
}

const struct frr_yang_module_info frr_affinity_map_cli_info = {
.name = "frr-affinity-map",
.ignore_cfg_cbs = true,
.nodes = {
{
.xpath = "/frr-affinity-map:lib/affinity-maps/affinity-map",
.cbs.cli_show = cli_show_affinity_map,
},
{
.xpath = NULL,
},
}
};

/* Initialization of affinity map vector. */
void affinity_map_init(void)
{
/* CLI commands. */
install_node(&affinitymap_node);
install_element(CONFIG_NODE, &affinity_map_cmd);
install_element(CONFIG_NODE, &no_affinity_map_cmd);
}
1 change: 0 additions & 1 deletion lib/affinitymap_northbound.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ const struct frr_yang_module_info frr_affinity_map_info = {
.cbs = {
.create = lib_affinity_map_create,
.destroy = lib_affinity_map_destroy,
.cli_show = cli_show_affinity_map,
}
},
{
Expand Down
8 changes: 8 additions & 0 deletions lib/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ struct cmd_node {
#define DEFPY_YANG(funcname, cmdname, cmdstr, helpstr) \
DEFPY_ATTR(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_YANG)

#define DEFPY_YANG_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
DEFPY_ATTR(funcname, cmdname, cmdstr, helpstr, \
CMD_ATTR_YANG | CMD_ATTR_HIDDEN)

#define DEFPY_YANG_NOSH(funcname, cmdname, cmdstr, helpstr) \
DEFPY_ATTR(funcname, cmdname, cmdstr, helpstr, \
CMD_ATTR_YANG | CMD_ATTR_NOSH)
Expand All @@ -315,6 +319,10 @@ struct cmd_node {
#define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr) \
DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_NOSH)

#define DEFUN_YANG_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, \
CMD_ATTR_YANG | CMD_ATTR_HIDDEN)

#define DEFUN_YANG_NOSH(funcname, cmdname, cmdstr, helpstr) \
DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, \
CMD_ATTR_YANG | CMD_ATTR_NOSH)
Expand Down
1 change: 1 addition & 0 deletions lib/defun_lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ SPECIAL [(),]
"DEFPY_ATTR" value = strdup(yytext); return DEFUNNY;
"DEFPY_HIDDEN" value = strdup(yytext); return DEFUNNY;
"DEFPY_YANG" value = strdup(yytext); return DEFUNNY;
"DEFPY_YANG_HIDDEN" value = strdup(yytext); return DEFUNNY;
"DEFPY_YANG_NOSH" value = strdup(yytext); return DEFUNNY;
"ALIAS" value = strdup(yytext); return DEFUNNY;
"ALIAS_HIDDEN" value = strdup(yytext); return DEFUNNY;
Expand Down
2 changes: 1 addition & 1 deletion lib/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ struct if_link_params *if_link_params_enable(struct interface *ifp)
iflp->unrsv_bw[i] = iflp->default_bw;

/* Update Link parameters status */
iflp->lp_status = LP_MAX_BW | LP_MAX_RSV_BW | LP_UNRSV_BW | LP_EXTEND_ADM_GRP;
iflp->lp_status = LP_MAX_BW | LP_MAX_RSV_BW | LP_UNRSV_BW;

/* Set TE metric equal to standard metric only if it is set */
if (ifp->metric != 0) {
Expand Down
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
4 changes: 2 additions & 2 deletions lib/mgmt_be_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "northbound.h"
#include "stream.h"
#include "sockopt.h"
#include "northbound_cli.h"

#include "lib/mgmt_be_client_clippy.c"

Expand Down Expand Up @@ -1068,7 +1069,7 @@ struct mgmt_be_client *mgmt_be_client_create(const char *client_name,

client->name = XSTRDUP(MTYPE_MGMTD_BE_CLIENT_NAME, client_name);
client->running_config = running_config;
client->candidate_config = nb_config_new(NULL);
client->candidate_config = vty_shared_candidate_config;
if (cbs)
client->cbs = *cbs;
mgmt_be_txns_init(&client->txn_head);
Expand Down Expand Up @@ -1107,7 +1108,6 @@ void mgmt_be_client_destroy(struct mgmt_be_client *client)
msg_client_cleanup(&client->client);
mgmt_be_cleanup_all_txns(client);
mgmt_be_txns_fini(&client->txn_head);
nb_config_free(client->candidate_config);

XFREE(MTYPE_MGMTD_BE_CLIENT_NAME, client->name);
XFREE(MTYPE_MGMTD_BE_CLIENT, client);
Expand Down
3 changes: 2 additions & 1 deletion lib/northbound.c
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,8 @@ void nb_init(struct event_loop *tm,
for (size_t i = 0; i < nmodules; i++) {
DEBUGD(&nb_dbg_events, "northbound: loading %s.yang",
modules[i]->name);
*loadedp++ = yang_module_load(modules[i]->name);
*loadedp++ = yang_module_load(modules[i]->name,
modules[i]->features);
}

if (explicit_compile)
Expand Down
8 changes: 8 additions & 0 deletions lib/northbound.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,14 @@ struct frr_yang_module_info {
*/
bool ignore_cfg_cbs;

/*
* The NULL-terminated list of supported features.
* Features are defined with "feature" statements in the YANG model.
* Use ["*", NULL] to enable all features.
* Use NULL to disable all features.
*/
const char **features;

/* Northbound callbacks. */
const struct {
/* Data path of this YANG node. */
Expand Down
21 changes: 21 additions & 0 deletions lib/vrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,25 @@ static int lib_vrf_destroy(struct nb_cb_destroy_args *args)
return NB_OK;
}

static void lib_vrf_cli_write(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults)
{
const char *name = yang_dnode_get_string(dnode, "name");

if (strcmp(name, VRF_DEFAULT_NAME)) {
vty_out(vty, "!\n");
vty_out(vty, "vrf %s\n", name);
}
}

static void lib_vrf_cli_write_end(struct vty *vty, const struct lyd_node *dnode)
{
const char *name = yang_dnode_get_string(dnode, "name");

if (strcmp(name, VRF_DEFAULT_NAME))
vty_out(vty, "exit-vrf\n");
}

static const void *lib_vrf_get_next(struct nb_cb_get_next_args *args)
{
struct vrf *vrfp = (struct vrf *)args->list_entry;
Expand Down Expand Up @@ -1035,6 +1054,8 @@ const struct frr_yang_module_info frr_vrf_info = {
.cbs = {
.create = lib_vrf_create,
.destroy = lib_vrf_destroy,
.cli_show = lib_vrf_cli_write,
.cli_show_end = lib_vrf_cli_write_end,
.get_next = lib_vrf_get_next,
.get_keys = lib_vrf_get_keys,
.lookup_entry = lib_vrf_lookup_entry,
Expand Down
14 changes: 1 addition & 13 deletions lib/vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ bool vty_log_commands;
static bool vty_log_commands_perm;

char const *const mgmt_daemons[] = {
"zebra",
#ifdef HAVE_RIPD
"ripd",
#endif
Expand Down Expand Up @@ -2264,19 +2265,6 @@ bool mgmt_vty_read_configs(void)

snprintf(path, sizeof(path), "%s/mgmtd.conf", frr_sysconfdir);
confp = vty_open_config(path, config_default);
if (!confp) {
char *orig;

snprintf(path, sizeof(path), "%s/zebra.conf", frr_sysconfdir);
orig = XSTRDUP(MTYPE_TMP, host_config_get());

zlog_info("mgmtd: trying backup config file: %s", path);
confp = vty_open_config(path, config_default);

host_config_set(path);
XFREE(MTYPE_TMP, orig);
}

if (confp) {
zlog_info("mgmtd: reading config file: %s", path);

Expand Down
14 changes: 9 additions & 5 deletions lib/yang.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ RB_GENERATE(yang_modules, yang_module, entry, yang_module_compare)

struct yang_modules yang_modules = RB_INITIALIZER(&yang_modules);

struct yang_module *yang_module_load(const char *module_name)
struct yang_module *yang_module_load(const char *module_name,
const char **features)
{
struct yang_module *module;
const struct lys_module *module_info;

module_info =
ly_ctx_load_module(ly_native_ctx, module_name, NULL, NULL);
module_info = ly_ctx_load_module(ly_native_ctx, module_name, NULL,
features);
if (!module_info) {
flog_err(EC_LIB_YANG_MODULE_LOAD,
"%s: failed to load data model: %s", __func__,
Expand All @@ -130,8 +131,10 @@ struct yang_module *yang_module_load(const char *module_name)

void yang_module_load_all(void)
{
static const char * const all_features[] = { "*", NULL };

for (size_t i = 0; i < array_size(frr_native_modules); i++)
yang_module_load(frr_native_modules[i]);
yang_module_load(frr_native_modules[i], (const char **)all_features);
}

struct yang_module *yang_module_find(const char *module_name)
Expand Down Expand Up @@ -625,7 +628,8 @@ struct lyd_node *yang_dnode_dup(const struct lyd_node *dnode)
{
struct lyd_node *dup = NULL;
LY_ERR err;
err = lyd_dup_siblings(dnode, NULL, LYD_DUP_RECURSIVE, &dup);
err = lyd_dup_siblings(dnode, NULL,
LYD_DUP_RECURSIVE | LYD_DUP_WITH_FLAGS, &dup);
assert(!err);
return dup;
}
Expand Down
8 changes: 7 additions & 1 deletion lib/yang.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,16 @@ extern struct yang_modules yang_modules;
* module_name
* Name of the YANG module.
*
* features
* NULL-terminated array of feature names to enable.
* If NULL, all features are disabled.
* To enable all features, use ["*", NULL].
*
* Returns:
* Pointer to newly created YANG module.
*/
extern struct yang_module *yang_module_load(const char *module_name);
extern struct yang_module *yang_module_load(const char *module_name,
const char **features);

/*
* Load all FRR native YANG models.
Expand Down
Loading

0 comments on commit f8755d7

Please sign in to comment.