]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib,yang,zebra: add affinity-map support
authorLouis Scalbert <louis.scalbert@6wind.com>
Thu, 3 Nov 2022 13:30:23 +0000 (14:30 +0100)
committerLouis Scalbert <louis.scalbert@6wind.com>
Thu, 9 Feb 2023 14:48:21 +0000 (15:48 +0100)
Add the affinity-map global command to zebra. The syntax is:

> affinity-map NAME bit-position (0-1023)

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
15 files changed:
lib/affinitymap.c [new file with mode: 0644]
lib/affinitymap.h [new file with mode: 0644]
lib/affinitymap_cli.c [new file with mode: 0644]
lib/affinitymap_northbound.c [new file with mode: 0644]
lib/command.h
lib/subdir.am
lib/yang.c
vtysh/vtysh.c
vtysh/vtysh.h
vtysh/vtysh_config.c
yang/frr-affinity-map.yang [new file with mode: 0644]
yang/frr-zebra.yang
yang/subdir.am
zebra/main.c
zebra/zebra_vty.c

diff --git a/lib/affinitymap.c b/lib/affinitymap.c
new file mode 100644 (file)
index 0000000..62c9c0d
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Affinity map function.
+ *
+ * Copyright 2022 Hiroki Shirokura, LINE Corporation
+ * Copyright 2022 Masakazu Asama
+ * Copyright 2022 6WIND S.A.
+ *
+ * This file is part of Free Range Routing (FRR).
+ *
+ * FRR is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * FRR is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <zebra.h>
+
+#include "linklist.h"
+#include "memory.h"
+#include "command.h"
+#include "vector.h"
+#include "prefix.h"
+#include "vty.h"
+#include "affinitymap.h"
+#include "command.h"
+#include "log.h"
+#include "hash.h"
+#include "libfrr.h"
+#include "lib_errors.h"
+#include "table.h"
+#include "json.h"
+#include "jhash.h"
+
+DEFINE_MTYPE_STATIC(LIB, AFFINITY_MAP, "Affinity map");
+DEFINE_MTYPE(LIB, AFFINITY_MAP_NAME, "Affinity map name");
+DEFINE_MTYPE_STATIC(LIB, AFFINITY_MAP_INDEX, "Affinity map index");
+
+DEFINE_QOBJ_TYPE(affinity_maps);
+DEFINE_QOBJ_TYPE(affinity_map);
+
+struct affinity_maps affinity_map_master = {NULL};
+
+static void affinity_map_free(struct affinity_map *map)
+{
+       XFREE(MTYPE_AFFINITY_MAP, map);
+}
+
+void affinity_map_set(const char *name, int pos)
+{
+       struct listnode *node;
+       struct affinity_map *map;
+
+       if (!affinity_map_master.maps)
+               affinity_map_master.maps = list_new();
+
+       for (ALL_LIST_ELEMENTS_RO(affinity_map_master.maps, node, map)) {
+               if (strncmp(name, map->name, AFFINITY_NAME_SIZE) != 0)
+                       continue;
+               map->bit_position = pos;
+               return;
+       }
+
+       map = XCALLOC(MTYPE_AFFINITY_MAP, sizeof(*map));
+       map->bit_position = pos;
+       snprintf(map->name, sizeof(map->name), "%s", name);
+       listnode_add(affinity_map_master.maps, map);
+}
+
+void affinity_map_unset(const char *name)
+{
+       struct listnode *node, *nnode;
+       struct affinity_map *map;
+
+       if (!affinity_map_master.maps)
+               return;
+
+       for (ALL_LIST_ELEMENTS(affinity_map_master.maps, node, nnode, map)) {
+               if (strncmp(name, map->name, AFFINITY_NAME_SIZE) != 0)
+                       continue;
+               listnode_delete(affinity_map_master.maps, map);
+               affinity_map_free(map);
+               return;
+       }
+}
+
+struct affinity_map *affinity_map_get(const char *name)
+{
+       struct listnode *node;
+       struct affinity_map *map;
+
+       if (!affinity_map_master.maps)
+               return NULL;
+
+       for (ALL_LIST_ELEMENTS_RO(affinity_map_master.maps, node, map))
+               if (strncmp(name, map->name, AFFINITY_NAME_SIZE) == 0)
+                       return map;
+       return NULL;
+}
+
+
+char *affinity_map_name_get(int pos)
+{
+       struct listnode *node;
+       struct affinity_map *map;
+
+       if (!affinity_map_master.maps)
+               return NULL;
+
+       for (ALL_LIST_ELEMENTS_RO(affinity_map_master.maps, node, map))
+               if (map->bit_position == pos)
+                       return map->name;
+       return NULL;
+}
diff --git a/lib/affinitymap.h b/lib/affinitymap.h
new file mode 100644 (file)
index 0000000..323439c
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Affinity-map function.
+ *
+ * Copyright 2022 Hiroki Shirokura, LINE Corporation
+ * Copyright 2022 Masakazu Asama
+ * Copyright 2022 6WIND S.A.
+ *
+ * This file is part of Free Range Routing (FRR).
+ *
+ * FRR is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * FRR is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _ZEBRA_AFFINITYMAP_H
+#define _ZEBRA_AFFINITYMAP_H
+
+#include "typesafe.h"
+#include "prefix.h"
+#include "memory.h"
+#include "qobj.h"
+#include "vty.h"
+#include "lib/plist.h"
+#include "lib/plist_int.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define AFFINITY_NAME_SIZE 32
+
+struct affinity_map {
+       char name[AFFINITY_NAME_SIZE];
+       uint16_t bit_position;
+
+       QOBJ_FIELDS;
+};
+DECLARE_QOBJ_TYPE(affinity_map);
+
+struct affinity_maps {
+       struct list *maps;
+
+       QOBJ_FIELDS;
+};
+DECLARE_QOBJ_TYPE(affinity_maps);
+
+extern const struct frr_yang_module_info frr_affinity_map_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);
+
+void cli_show_affinity_map(struct vty *vty, const struct lyd_node *dnode,
+                          bool show_defaults);
+
+void affinity_map_init(void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ZEBRA_AFFINITYMAP_H */
diff --git a/lib/affinitymap_cli.c b/lib/affinitymap_cli.c
new file mode 100644 (file)
index 0000000..a2d5e8e
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Affinity map northbound CLI implementation.
+ *
+ * Copyright 2022 Hiroki Shirokura, LINE Corporation
+ * Copyright 2022 Masakazu Asama
+ * Copyright 2022 6WIND S.A.
+ *
+ *
+ * This file is part of Free Range Routing (FRR).
+ *
+ * FRR is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * FRR is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <zebra.h>
+
+#include "lib/command.h"
+#include "lib/northbound_cli.h"
+#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",
+               "Affinity map configuration\n"
+               "Affinity attribute name\n"
+               "Bit position for affinity attribute value\n"
+               "Bit position\n")
+{
+       char xpathr[XPATH_MAXLEN];
+
+       snprintf(
+               xpathr, sizeof(xpathr),
+               "/frr-affinity-map:lib/affinity-maps/affinity-map[name='%s']/value",
+               name);
+       nb_cli_enqueue_change(vty, xpathr, NB_OP_MODIFY, position_str);
+       return nb_cli_apply_changes(vty, NULL);
+}
+
+/* max value is EXT_ADMIN_GROUP_MAX_POSITIONS - 1 */
+DEFPY_YANG_NOSH(no_affinity_map, no_affinity_map_cmd,
+               "no affinity-map NAME$name [bit-position (0-1023)$position]",
+               NO_STR
+               "Affinity map configuration\n"
+               "Affinity attribute name\n"
+               "Bit position for affinity attribute value\n"
+               "Bit position\n")
+{
+       char xpathr[XPATH_MAXLEN];
+
+       snprintf(xpathr, sizeof(xpathr),
+                "/frr-affinity-map:lib/affinity-maps/affinity-map[name='%s']",
+                name);
+       nb_cli_enqueue_change(vty, xpathr, NB_OP_DESTROY, NULL);
+       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__)))
+{
+       vty_out(vty, "affinity-map %s bit-position %u\n",
+               yang_dnode_get_string(dnode, "./name"),
+               yang_dnode_get_uint16(dnode, "./value"));
+}
+
+/* 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
new file mode 100644 (file)
index 0000000..5082a8b
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * affinity map northbound implementation.
+ *
+ * Copyright 2022 Hiroki Shirokura, LINE Corporation
+ * Copyright 2022 Masakazu Asama
+ * Copyright 2022 6WIND S.A.
+ *
+ * This file is part of Free Range Routing (FRR).
+ *
+ * FRR is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * FRR is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <zebra.h>
+
+#include "lib/command.h"
+#include "lib/log.h"
+#include "lib/northbound.h"
+#include "lib/affinitymap.h"
+
+/*
+ * XPath: /frr-affinity-map:lib/affinity-maps/affinity-map
+ */
+
+static int lib_affinity_map_create(struct nb_cb_create_args *args)
+{
+       return NB_OK;
+}
+
+static int lib_affinity_map_destroy(struct nb_cb_destroy_args *args)
+{
+       const char *name;
+
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               name = yang_dnode_get_string(
+                       (const struct lyd_node *)args->dnode, "./name");
+               affinity_map_unset(name);
+               break;
+       }
+       return NB_OK;
+}
+
+/*
+ * XPath: /frr-affinity-map:lib/affinity-maps/affinity-map/value
+ */
+static int lib_affinity_map_value_modify(struct nb_cb_modify_args *args)
+{
+       const char *name;
+       char *map_name;
+       uint16_t pos;
+
+       name = yang_dnode_get_string(
+               (const struct lyd_node *)args->dnode->parent, "./name");
+
+       pos = yang_dnode_get_uint16(
+               (const struct lyd_node *)args->dnode->parent, "./value");
+
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+               map_name = affinity_map_name_get(pos);
+               if (!map_name)
+                       return NB_OK;
+               if (strncmp(map_name, name, AFFINITY_NAME_SIZE) == 0)
+                       return NB_ERR_NO_CHANGES;
+               snprintf(args->errmsg, args->errmsg_len,
+                        "bit-position is used by %s.", map_name);
+               return NB_ERR_VALIDATION;
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               affinity_map_set(name, pos);
+               break;
+       }
+
+       return NB_OK;
+}
+
+static int lib_affinity_map_value_destroy(struct nb_cb_destroy_args *args)
+{
+       return NB_OK;
+}
+
+/* clang-format off */
+const struct frr_yang_module_info frr_affinity_map_info = {
+       .name = "frr-affinity-map",
+       .nodes = {
+               {
+                       .xpath = "/frr-affinity-map:lib/affinity-maps/affinity-map",
+                       .cbs = {
+                               .create = lib_affinity_map_create,
+                               .destroy = lib_affinity_map_destroy,
+                               .cli_show = cli_show_affinity_map,
+                       }
+               },
+               {
+                       .xpath = "/frr-affinity-map:lib/affinity-maps/affinity-map/value",
+                       .cbs = {
+                               .modify = lib_affinity_map_value_modify,
+                               .destroy = lib_affinity_map_value_destroy,
+                       }
+               },
+               {
+                       .xpath = NULL,
+               },
+       }
+};
index 8f5d96053cb10fdf1df07222516d8071225d8292..5aaa6d6cd8b5ece1aae1f27089b5c53e81dc4c47 100644 (file)
@@ -90,6 +90,7 @@ struct host {
 };
 
 /* List of CLI nodes. Please remember to update the name array in command.c. */
+/* clang-format off */
 enum node_type {
        AUTH_NODE,               /* Authentication mode of vty interface. */
        VIEW_NODE,               /* View node. Default mode of vty interface. */
@@ -106,6 +107,7 @@ enum node_type {
        EXTLOG_NODE,             /* RFC5424 & co. extended syslog */
        KEYCHAIN_NODE,           /* Key-chain node. */
        KEYCHAIN_KEY_NODE,       /* Key-chain key node. */
+       AFFMAP_NODE,             /* Affinity map node. */
        IP_NODE,                 /* Static ip route node. */
        VRF_NODE,                /* VRF mode node. */
        INTERFACE_NODE,          /* Interface mode node. */
@@ -186,6 +188,7 @@ enum node_type {
        BMP_NODE,               /* BMP config under router bgp */
        NODE_TYPE_MAX, /* maximum */
 };
+/* clang-format on */
 
 extern vector cmdvec;
 extern const struct message tokennames[];
index 18e9825a7a302fa5cc6a59977c6747504f6e79f1..faf77abad95756ad5d60db78de7bc4f0f27b3163 100644 (file)
@@ -7,6 +7,9 @@ lib_libfrr_la_LDFLAGS = $(LIB_LDFLAGS) -version-info 0:0:0 -Xlinker -e_libfrr_ve
 lib_libfrr_la_LIBADD = $(LIBCAP) $(UNWIND_LIBS) $(LIBYANG_LIBS) $(LUA_LIB) $(UST_LIBS) $(LIBCRYPT) $(LIBDL) $(LIBM)
 
 lib_libfrr_la_SOURCES = \
+       lib/affinitymap.c \
+       lib/affinitymap_cli.c \
+       lib/affinitymap_northbound.c \
        lib/agg_table.c \
        lib/atomlist.c \
        lib/base64.c \
@@ -127,6 +130,7 @@ lib_libfrr_la_SOURCES = \
        # end
 
 nodist_lib_libfrr_la_SOURCES = \
+       yang/frr-affinity-map.yang.c \
        yang/frr-filter.yang.c \
        yang/frr-interface.yang.c \
        yang/frr-route-map.yang.c \
@@ -146,6 +150,7 @@ lib_libfrr_la_SOURCES += lib/db.c
 endif
 
 clippy_scan += \
+       lib/affinitymap_cli.c \
        lib/if.c \
        lib/filter_cli.c \
        lib/log_vty.c \
@@ -159,6 +164,7 @@ clippy_scan += \
        # end
 
 pkginclude_HEADERS += \
+       lib/affinitymap.h \
        lib/agg_table.h \
        lib/atomlist.h \
        lib/base64.h \
index ef1cf898aaf4fec6347430e0a1f520a8fece8c65..ec8de85e900c67ba1c14788c74a975452fc45e90 100644 (file)
@@ -88,6 +88,7 @@ static const char *const frr_native_modules[] = {
        "frr-interface",
        "frr-vrf",
        "frr-routing",
+       "frr-affinity-map",
        "frr-route-map",
        "frr-nexthop",
        "frr-ripd",
index acc984ced70cd20f9524da8018fa3215b4025396..2538d2073da81a57519e476ace8764b2b54f9a2a 100644 (file)
@@ -2216,6 +2216,29 @@ DEFUNSH(VTYSH_PATHD, pcep_cli_pcep_pce_config, pcep_cli_pcep_pce_config_cmd,
 
 #endif /* HAVE_PATHD */
 
+/* max value is EXT_ADMIN_GROUP_MAX_POSITIONS - 1 */
+DEFUNSH(VTYSH_AFFMAP, affinity_map, vtysh_affinity_map_cmd,
+       "affinity-map NAME bit-position (0-1023)",
+       "Affinity map configuration\n"
+       "Affinity attribute name\n"
+       "Bit position for affinity attribute value\n"
+       "Bit position\n")
+{
+       return CMD_SUCCESS;
+}
+
+/* max value is EXT_ADMIN_GROUP_MAX_POSITIONS - 1 */
+DEFUNSH(VTYSH_AFFMAP, no_affinity_map, vtysh_no_affinity_map_cmd,
+       "no affinity-map NAME$name [bit-position (0-1023)$position]",
+       NO_STR
+       "Affinity map configuration\n"
+       "Affinity attribute name\n"
+       "Bit position for affinity attribute value\n"
+       "Bit position\n")
+{
+       return CMD_SUCCESS;
+}
+
 DEFUNSH(VTYSH_RMAP, vtysh_route_map, vtysh_route_map_cmd,
        "route-map RMAP_NAME <deny|permit> (1-65535)",
        "Create route-map or enter route-map command mode\n"
@@ -4850,6 +4873,9 @@ void vtysh_init_vty(void)
        install_element(VRF_NODE, &vtysh_exit_vrf_cmd);
        install_element(VRF_NODE, &vtysh_quit_vrf_cmd);
 
+       install_element(CONFIG_NODE, &vtysh_affinity_map_cmd);
+       install_element(CONFIG_NODE, &vtysh_no_affinity_map_cmd);
+
        install_node(&rmap_node);
        install_element(CONFIG_NODE, &vtysh_route_map_cmd);
        install_element(RMAP_NODE, &vtysh_exit_rmap_cmd);
index 1de4ab0179973992e3dce43805788e74162a4912..e551f4e9fc6a363ef0174d698a38cb961efa3ddc 100644 (file)
@@ -59,6 +59,7 @@ extern struct thread_master *master;
  * things like prefix lists are not even initialised) */
 #define VTYSH_ALL        VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_LDPD|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_PIM6D|VTYSH_NHRPD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_SHARPD|VTYSH_PBRD|VTYSH_STATICD|VTYSH_BFDD|VTYSH_FABRICD|VTYSH_VRRPD|VTYSH_PATHD
 #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
 #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 | \
index ac32f0a774bdb851e507ad6050cfe63a92ab2998..6dce99a5742018c5604d7f5511f2c03886e38f81 100644 (file)
@@ -395,6 +395,9 @@ void vtysh_config_parse_line(void *arg, const char *line)
                else if (strncmp(line, "router openfabric", strlen("router openfabric"))
                         == 0)
                        config = config_get(OPENFABRIC_NODE, line);
+               else if (strncmp(line, "affinity-map",
+                                strlen("affinity-map")) == 0)
+                       config = config_get(AFFMAP_NODE, line);
                else if (strncmp(line, "route-map", strlen("route-map")) == 0)
                        config = config_get(RMAP_NODE, line);
                else if (strncmp(line, "no route-map", strlen("no route-map"))
@@ -526,14 +529,15 @@ void vtysh_config_parse_line(void *arg, const char *line)
 /* Macro to check delimiter is needed between each configuration line
  * or not. */
 #define NO_DELIMITER(I)                                                        \
-       ((I) == ACCESS_NODE || (I) == PREFIX_NODE || (I) == IP_NODE            \
-        || (I) == AS_LIST_NODE || (I) == COMMUNITY_LIST_NODE                  \
-        || (I) == COMMUNITY_ALIAS_NODE || (I) == ACCESS_IPV6_NODE             \
-        || (I) == ACCESS_MAC_NODE || (I) == PREFIX_IPV6_NODE                  \
-        || (I) == FORWARDING_NODE || (I) == DEBUG_NODE || (I) == AAA_NODE     \
-        || (I) == VRF_DEBUG_NODE || (I) == NORTHBOUND_DEBUG_NODE              \
-        || (I) == RMAP_DEBUG_NODE || (I) == RESOLVER_DEBUG_NODE               \
-        || (I) == MPLS_NODE || (I) == KEYCHAIN_KEY_NODE)
+       ((I) == AFFMAP_NODE || (I) == ACCESS_NODE || (I) == PREFIX_NODE ||     \
+        (I) == IP_NODE || (I) == AS_LIST_NODE ||                              \
+        (I) == COMMUNITY_LIST_NODE || (I) == COMMUNITY_ALIAS_NODE ||          \
+        (I) == ACCESS_IPV6_NODE || (I) == ACCESS_MAC_NODE ||                  \
+        (I) == PREFIX_IPV6_NODE || (I) == FORWARDING_NODE ||                  \
+        (I) == DEBUG_NODE || (I) == AAA_NODE || (I) == VRF_DEBUG_NODE ||      \
+        (I) == NORTHBOUND_DEBUG_NODE || (I) == RMAP_DEBUG_NODE ||             \
+        (I) == RESOLVER_DEBUG_NODE || (I) == MPLS_NODE ||                     \
+        (I) == KEYCHAIN_KEY_NODE)
 
 static void configvec_dump(vector vec, bool nested)
 {
diff --git a/yang/frr-affinity-map.yang b/yang/frr-affinity-map.yang
new file mode 100644 (file)
index 0000000..c4377e6
--- /dev/null
@@ -0,0 +1,81 @@
+module frr-affinity-map {
+  yang-version 1.1;
+  namespace "http://frrouting.org/yang/affinity-map";
+  prefix frr-affinity-map;
+
+  import ietf-inet-types {
+    prefix inet;
+  }
+
+  import frr-filter {
+    prefix filter;
+  }
+
+  import frr-interface {
+    prefix frr-interface;
+  }
+
+  organization
+    "FRRouting";
+  contact
+    "FRR Users List:       <mailto:frog@lists.frrouting.org>
+     FRR Development List: <mailto:dev@lists.frrouting.org>";
+  description
+    "This module defines route map settings
+
+     Copyright 2022 FRRouting
+
+     Redistribution and use in source and binary forms, with or without
+     modification, are permitted provided that the following conditions
+     are met:
+
+     1. Redistributions of source code must retain the above copyright notice,
+     this list of conditions and the following disclaimer.
+
+     2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+
+     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+     \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+     A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+     HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+     LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.";
+
+  revision 2022-11-03 {
+    description
+      "Initial revision";
+  }
+
+  container lib {
+    container affinity-maps {
+      description
+        "Affinity Mapping Table";
+      list affinity-map {
+        key "name";
+        description
+          "Affinity Mapping configuration";
+        leaf name {
+          type string {
+            length "1..32";
+          }
+          description
+            "Affinity Name";
+        }
+        leaf value {
+          type uint16 {
+            range "0..1023";
+          }
+          description
+            "Bit position";
+        }
+      }
+    }
+  }
+}
index a2c6bb4c2b8f496ad98c2ac21d5a9019d4e614ae..3bf5203fb87362b444ce9161e78e6e4623b01c04 100644 (file)
@@ -11,6 +11,10 @@ module frr-zebra {
     prefix inet;
   }
 
+  import frr-affinity-map {
+    prefix frr-affinity-map;
+  }
+
   import frr-route-map {
     prefix frr-route-map;
   }
index 80028fcb18294bebd03dca35e7d1319097c8a61c..82a6a01474a46a1906c980c5a4e2a9c35b00f4b1 100644 (file)
@@ -19,6 +19,7 @@ EXTRA_DIST += yang/embedmodel.py
 # global symbols :(.  Just put it in the daemon.  Dynamic libraries.so work
 # without problems, as seen in libfrr.
 
+dist_yangmodels_DATA += yang/frr-affinity-map.yang
 dist_yangmodels_DATA += yang/frr-filter.yang
 dist_yangmodels_DATA += yang/frr-module-translator.yang
 dist_yangmodels_DATA += yang/frr-nexthop.yang
index e38f9a85e3b1eb45a2668ffc78fe69fcbfb97206..e38f20371031982728049ccab0bec57e4613517d 100644 (file)
@@ -33,6 +33,7 @@
 #include "sigevent.h"
 #include "vrf.h"
 #include "libfrr.h"
+#include "affinitymap.h"
 #include "routemap.h"
 #include "routing_nb.h"
 
@@ -259,6 +260,7 @@ struct frr_signal_t zebra_signals[] = {
        },
 };
 
+/* clang-format off */
 static const struct frr_yang_module_info *const zebra_yang_modules[] = {
        &frr_filter_info,
        &frr_interface_info,
@@ -266,8 +268,10 @@ static const struct frr_yang_module_info *const zebra_yang_modules[] = {
        &frr_zebra_info,
        &frr_vrf_info,
        &frr_routing_info,
+       &frr_affinity_map_info,
        &frr_zebra_route_map_info,
 };
+/* clang-format on */
 
 FRR_DAEMON_INFO(
        zebra, ZEBRA, .vty_port = ZEBRA_VTY_PORT, .flags = FRR_NO_ZCLIENT,
index d96ee4890fe610cf1aaf869608f26928ae89a81f..15ae47dfed55c7cd30f94ca6f1649d00e3bdffec 100644 (file)
@@ -34,6 +34,7 @@
 #include "srcdest_table.h"
 #include "vxlan.h"
 #include "termtable.h"
+#include "affinitymap.h"
 
 #include "zebra/zebra_router.h"
 #include "zebra/zserv.h"
@@ -4496,6 +4497,8 @@ void zebra_vty_init(void)
        /* Route-map */
        zebra_route_map_init();
 
+       affinity_map_init();
+
        install_node(&ip_node);
        install_node(&protocol_node);