Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: mgmtd: convert affinitymap to mgmtd #15153

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions isisd/isis_affinitymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ static bool isis_affinity_map_check_use(const char *affmap_name)
return false;
}

static void isis_affinity_map_update(const char *affmap_name, uint16_t old_pos,
static void isis_affinity_map_update(const struct lyd_node *dnode,
const char *affmap_name, uint16_t old_pos,
uint16_t new_pos)
{
struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT);
Expand Down Expand Up @@ -88,8 +89,6 @@ static void isis_affinity_map_update(const char *affmap_name, uint16_t old_pos,

void isis_affinity_map_init(void)
{
affinity_map_init();

affinity_map_set_check_use_hook(isis_affinity_map_check_use);
affinity_map_set_update_hook(isis_affinity_map_update);
}
Expand Down
19 changes: 12 additions & 7 deletions lib/affinitymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,18 @@ bool affinity_map_check_use_hook(const char *affmap_name)
return false;
}

bool affinity_map_check_update_hook(const char *affmap_name, uint16_t new_pos)
bool affinity_map_check_update_hook(const struct lyd_node *dnode,
const char *affmap_name, uint16_t new_pos)
{
if (affinity_map_master.check_update_hook)
return (*affinity_map_master.check_update_hook)(affmap_name,
return (*affinity_map_master.check_update_hook)(dnode,
affmap_name,
new_pos);
return true;
}

void affinity_map_update_hook(const char *affmap_name, uint16_t new_pos)
void affinity_map_update_hook(const struct lyd_node *dnode,
const char *affmap_name, uint16_t new_pos)
{
struct affinity_map *map;

Expand All @@ -149,8 +152,8 @@ void affinity_map_update_hook(const char *affmap_name, uint16_t new_pos)
/* Affinity-map creation */
return;

(*affinity_map_master.update_hook)(affmap_name, map->bit_position,
new_pos);
(*affinity_map_master.update_hook)(dnode, affmap_name,
map->bit_position, new_pos);
}


Expand All @@ -159,13 +162,15 @@ void affinity_map_set_check_use_hook(bool (*func)(const char *affmap_name))
affinity_map_master.check_use_hook = func;
}

void affinity_map_set_check_update_hook(bool (*func)(const char *affmap_name,
void affinity_map_set_check_update_hook(bool (*func)(const struct lyd_node *dnode,
const char *affmap_name,
uint16_t new_pos))
{
affinity_map_master.check_update_hook = func;
}

void affinity_map_set_update_hook(void (*func)(const char *affmap_name,
void affinity_map_set_update_hook(void (*func)(const struct lyd_node *dnode,
const char *affmap_name,
uint16_t old_pos,
uint16_t new_pos))
{
Expand Down
19 changes: 13 additions & 6 deletions lib/affinitymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,36 @@ struct affinity_maps {
struct list *maps;

bool (*check_use_hook)(const char *affmap_name);
bool (*check_update_hook)(const char *affmap_name, uint16_t new_pos);
void (*update_hook)(const char *affmap_name, uint16_t old_pos,
bool (*check_update_hook)(const struct lyd_node *dnode,
const char *affmap_name, uint16_t new_pos);
void (*update_hook)(const struct lyd_node *dnode,
const char *affmap_name, uint16_t old_pos,
uint16_t new_pos);

QOBJ_FIELDS;
};
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);
struct affinity_map *affinity_map_get(const char *name);
char *affinity_map_name_get(const int pos);

bool affinity_map_check_use_hook(const char *affmap_name);
bool affinity_map_check_update_hook(const char *affmap_name, uint16_t new_pos);
void affinity_map_update_hook(const char *affmap_name, uint16_t new_pos);
bool affinity_map_check_update_hook(const struct lyd_node *dnode,
const char *affmap_name, uint16_t new_pos);
void affinity_map_update_hook(const struct lyd_node *dnode,
const char *affmap_name, uint16_t new_pos);

void affinity_map_set_check_use_hook(bool (*func)(const char *affmap_name));
void affinity_map_set_check_update_hook(bool (*func)(const char *affmap_name,
void affinity_map_set_check_update_hook(bool (*func)(const struct lyd_node *dnode,
const char *affmap_name,
uint16_t new_pos));
void affinity_map_set_update_hook(void (*func)(const char *affmap_name,
void affinity_map_set_update_hook(void (*func)(const struct lyd_node *dnode,
const char *affmap_name,
uint16_t old_pos,
uint16_t new_pos));

Expand Down
35 changes: 13 additions & 22 deletions lib/affinitymap_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@
#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,
/* clang-format off */
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,
},
}
};

/* max value is EXT_ADMIN_GROUP_MAX_POSITIONS - 1 */
Expand Down Expand Up @@ -75,20 +81,6 @@ 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,
bool show_defaults __attribute__((__unused__)))
{
Expand All @@ -101,7 +93,6 @@ void cli_show_affinity_map(struct vty *vty, const struct lyd_node *dnode,
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);
}
22 changes: 7 additions & 15 deletions lib/affinitymap_northbound.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,19 @@ static int lib_affinity_map_destroy(struct nb_cb_destroy_args *args)
*/
static int lib_affinity_map_value_modify(struct nb_cb_modify_args *args)
{
const struct lyd_node *dnode = args->dnode;
const char *name;
char *map_name;
uint16_t pos;

name = yang_dnode_get_string(
(const struct lyd_node *)args->dnode->parent, "./name");
name = yang_dnode_get_string((const struct lyd_node *)dnode->parent,
"./name");

pos = yang_dnode_get_uint16(
(const struct lyd_node *)args->dnode->parent, "./value");
pos = yang_dnode_get_uint16((const struct lyd_node *)dnode->parent,
"./value");

switch (args->event) {
case NB_EV_VALIDATE:
map_name = affinity_map_name_get(pos);
if (map_name &&
strncmp(map_name, name, AFFINITY_NAME_SIZE) != 0) {
snprintf(args->errmsg, args->errmsg_len,
"bit-position is used by %s.", map_name);
return NB_ERR_VALIDATION;
}
if (!affinity_map_check_update_hook(name, pos)) {
if (!affinity_map_check_update_hook(dnode, name, pos)) {
snprintf(
args->errmsg, args->errmsg_len,
"affinity-map new bit-position > 31 but is used with standard admin-groups");
Expand All @@ -97,7 +90,7 @@ static int lib_affinity_map_value_modify(struct nb_cb_modify_args *args)
case NB_EV_ABORT:
break;
case NB_EV_APPLY:
affinity_map_update_hook(name, pos);
affinity_map_update_hook(dnode, name, pos);
affinity_map_set(name, pos);
break;
}
Expand All @@ -119,7 +112,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
1 change: 0 additions & 1 deletion lib/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ lib_libfrr_la_LIBADD = $(LIBCAP) $(UNWIND_LIBS) $(LIBYANG_LIBS) $(LUA_LIB) $(UST
lib_libfrr_la_SOURCES = \
lib/admin_group.c \
lib/affinitymap.c \
lib/affinitymap_cli.c \
lib/affinitymap_northbound.c \
lib/agg_table.c \
lib/atomlist.c \
Expand Down
10 changes: 10 additions & 0 deletions mgmtd/mgmt_be_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ struct mgmt_be_xpath_map {
* Each client gets their own map, but also union all the strings into the
* above map as well.
*/


static const char *const zebra_config_xpaths[] = {
"/frr-affinity-map:lib/affinity-maps/affinity-map",
"/frr-interface:lib",
"/frr-vrf:lib",
NULL,
};

#if HAVE_STATICD
static const char *const staticd_config_xpaths[] = {
"/frr-vrf:lib",
Expand All @@ -68,6 +77,7 @@ static const char *const staticd_config_xpaths[] = {
#endif

static const char *const *be_client_config_xpaths[MGMTD_BE_CLIENT_ID_MAX] = {
[MGMTD_BE_CLIENT_ID_ZEBRA] = zebra_config_xpaths,
#ifdef HAVE_STATICD
[MGMTD_BE_CLIENT_ID_STATICD] = staticd_config_xpaths,
#endif
Expand Down
17 changes: 6 additions & 11 deletions mgmtd/mgmt_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <zebra.h>
#include "lib/version.h"
#include "affinitymap.h"
#include "routemap.h"
#include "filter.h"
#include "libfrr.h"
Expand Down Expand Up @@ -141,24 +142,21 @@ static struct frr_signal_t mgmt_signals[] = {
extern const struct frr_yang_module_info frr_staticd_info;
#endif


/*
* These are stub info structs that are used to load the modules used by backend
* clients into mgmtd. The modules are used by libyang in order to support
* parsing binary data returns from the backend.
*
* These are only needed if `cli_show` commands are not defined for the module.
* When `cli_show` callbacks are defined then the non-stub frr_yang_module_info
* that contains pointers to them should be included here instead.
*/
const struct frr_yang_module_info zebra_info = {
.name = "frr-zebra",
.ignore_cfg_cbs = true,
.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,
Expand All @@ -170,6 +168,7 @@ const struct frr_yang_module_info zebra_route_map_info = {
* MGMTd.
*/
static const struct frr_yang_module_info *const mgmt_yang_modules[] = {
&frr_affinity_map_cli_info,
&frr_filter_info,
&frr_interface_info,
&frr_route_map_info,
Expand All @@ -181,7 +180,6 @@ static const struct frr_yang_module_info *const mgmt_yang_modules[] = {
*/

&zebra_info,
&affinity_map_info,
&zebra_route_map_info,

#ifdef HAVE_STATICD
Expand Down Expand Up @@ -253,9 +251,6 @@ int main(int argc, char **argv)
/* VRF commands initialization. */
vrf_cmd_init(NULL);

/* Interface commands initialization. */
if_cmd_init(NULL);

/* MGMTD related initialization. */
mgmt_init();

Expand Down
3 changes: 3 additions & 0 deletions mgmtd/mgmt_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <zebra.h>

#include "affinitymap.h"
#include "command.h"
#include "json.h"
#include "network.h"
Expand Down Expand Up @@ -566,6 +567,8 @@ void mgmt_vty_init(void)
* backend components that are moved to new MGMTD infra
* here one by one.
*/
affinity_map_init();
if_cmd_init(NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if_cmd_init is already called in mgmt_main.c. Probably makes sense to move it here together with vrf_cmd_init, but we definitely don't want double initialization.

#if HAVE_STATICD
extern void static_vty_init(void);
static_vty_init();
Expand Down
5 changes: 5 additions & 0 deletions mgmtd/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@ nodist_mgmtd_mgmtd_SOURCES += \
# end
nodist_mgmtd_libmgmt_be_nb_la_SOURCES += staticd/static_vty.c
endif

# Unconditionally YANG support

nodist_mgmtd_mgmtd_SOURCES += yang/frr-affinity-map.yang.c
mgmtd_libmgmtd_a_SOURCES += lib/affinitymap_cli.c
20 changes: 19 additions & 1 deletion tests/topotests/example_munet/test_munet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
#
# Copyright (c) 2023, LabN Consulting, L.L.C.
#
import pytest
from munet.base import get_event_loop

pytestmark = [pytest.mark.asyncio]


@pytest.fixture(scope="function")
def event_loop():
"""Create an instance of the default event loop for the session."""
loop = get_event_loop()
try:
# logging.info("event_loop_fixture: yielding with new event loop watcher")
yield loop
finally:
loop.close()


async def test_native_test(unet):
o = unet.hosts["r1"].cmd_nostatus("ip addr")
# o = unet.hosts["r1"].cmd_nostatus("ip addr")
o = "Hello World"
print(o)
2 changes: 1 addition & 1 deletion vtysh/vtysh.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern struct event_loop *master;
VTYSH_SHARPD | VTYSH_PBRD | VTYSH_STATICD | VTYSH_BFDD | \
VTYSH_FABRICD | VTYSH_VRRPD | VTYSH_PATHD | VTYSH_MGMTD
#define VTYSH_ACL VTYSH_BFDD|VTYSH_BABELD|VTYSH_BGPD|VTYSH_EIGRPD|VTYSH_ISISD|VTYSH_FABRICD|VTYSH_LDPD|VTYSH_NHRPD|VTYSH_OSPF6D|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_MGMTD
#define VTYSH_RMAP VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_FABRICD
#define VTYSH_INTERFACE_SUBSET \
VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_RIPNGD | VTYSH_OSPFD | VTYSH_OSPF6D | \
Expand Down
Loading
Loading