From dc6ff4c0de04e79dd23cf5de27185292224c93e6 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Wed, 24 Jan 2024 22:53:00 +0200 Subject: [PATCH] lib: convert affinity-map to mgmtd Signed-off-by: Igor Ryzhov --- lib/affinitymap.h | 4 +--- lib/affinitymap_cli.c | 40 ++++++++++++++---------------------- lib/affinitymap_northbound.c | 1 - mgmtd/mgmt_main.c | 10 ++------- mgmtd/mgmt_vty.c | 2 ++ mgmtd/subdir.am | 1 + vtysh/vtysh.h | 2 +- 7 files changed, 22 insertions(+), 38 deletions(-) diff --git a/lib/affinitymap.h b/lib/affinitymap.h index f5924ca3ef6b..ebe2659bf7fc 100644 --- a/lib/affinitymap.h +++ b/lib/affinitymap.h @@ -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); @@ -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); diff --git a/lib/affinitymap_cli.c b/lib/affinitymap_cli.c index d417ae195156..73b91e775b7f 100644 --- a/lib/affinitymap_cli.c +++ b/lib/affinitymap_cli.c @@ -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", @@ -75,21 +66,7 @@ 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", @@ -97,11 +74,24 @@ void cli_show_affinity_map(struct vty *vty, const struct lyd_node *dnode, 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); } diff --git a/lib/affinitymap_northbound.c b/lib/affinitymap_northbound.c index 9daccc280067..8e84d36f2fff 100644 --- a/lib/affinitymap_northbound.c +++ b/lib/affinitymap_northbound.c @@ -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, } }, { diff --git a/mgmtd/mgmt_main.c b/mgmtd/mgmt_main.c index 8a0e25903742..e71637bbd215 100644 --- a/mgmtd/mgmt_main.c +++ b/mgmtd/mgmt_main.c @@ -17,7 +17,7 @@ #include "ripd/rip_nb.h" #include "ripngd/ripng_nb.h" #include "routing_nb.h" - +#include "affinitymap.h" /* mgmt options, we use GNU getopt library. */ static const struct option longopts[] = { @@ -169,12 +169,6 @@ const struct frr_yang_module_info zebra_info = { .nodes = { { .xpath = NULL } }, }; -const struct frr_yang_module_info affinity_map_info = { - .name = "frr-affinity-map", - .ignore_cfg_cbs = true, - .nodes = { { .xpath = NULL } }, -}; - const struct frr_yang_module_info zebra_route_map_info = { .name = "frr-zebra-route-map", .ignore_cfg_cbs = true, @@ -191,13 +185,13 @@ static const struct frr_yang_module_info *const mgmt_yang_modules[] = { &frr_route_map_cli_info, &frr_routing_info, &frr_vrf_info, + &frr_affinity_map_cli_info, /* * YANG module info used by backend clients get added here. */ &zebra_info, - &affinity_map_info, &zebra_route_map_info, #ifdef HAVE_RIPD diff --git a/mgmtd/mgmt_vty.c b/mgmtd/mgmt_vty.c index 194af13f1eb2..d5cfbbf771c4 100644 --- a/mgmtd/mgmt_vty.c +++ b/mgmtd/mgmt_vty.c @@ -8,6 +8,7 @@ #include +#include "affinitymap.h" #include "command.h" #include "filter.h" #include "json.h" @@ -570,6 +571,7 @@ void mgmt_vty_init(void) */ filter_cli_init(); route_map_cli_init(); + affinity_map_init(); /* * Initialize command handling from VTYSH connection. diff --git a/mgmtd/subdir.am b/mgmtd/subdir.am index 3d1dafabd4ee..e3008bab8c85 100644 --- a/mgmtd/subdir.am +++ b/mgmtd/subdir.am @@ -18,6 +18,7 @@ lib_LTLIBRARIES += mgmtd/libmgmt_be_nb.la mgmtd_libmgmt_be_nb_la_SOURCES = \ # end nodist_mgmtd_libmgmt_be_nb_la_SOURCES = \ + lib/affinitymap_cli.c \ # end mgmtd_libmgmt_be_nb_la_CFLAGS = $(AM_CFLAGS) -DINCLUDE_MGMTD_CMDDEFS_ONLY mgmtd_libmgmt_be_nb_la_CPPFLAGS = $(AM_CPPFLAGS) -DINCLUDE_MGMTD_CMDDEFS_ONLY diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index b1e914ebf759..4fe30777d834 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -60,7 +60,7 @@ extern struct event_loop *master; VTYSH_OSPFD | VTYSH_PBRD | VTYSH_PIMD | VTYSH_PIM6D | \ VTYSH_RIPD | VTYSH_RIPNGD | VTYSH_VRRPD | VTYSH_ZEBRA -#define VTYSH_AFFMAP VTYSH_ZEBRA | VTYSH_ISISD +#define VTYSH_AFFMAP VTYSH_ZEBRA | VTYSH_ISISD | VTYSH_MGMTD #define VTYSH_RMAP_CONFIG \ VTYSH_ZEBRA | VTYSH_OSPFD | VTYSH_OSPF6D | VTYSH_BGPD | VTYSH_ISISD | \ VTYSH_PIMD | VTYSH_EIGRPD | VTYSH_FABRICD | VTYSH_MGMTD