2 * affinity map northbound implementation.
4 * Copyright 2022 Hiroki Shirokura, LINE Corporation
5 * Copyright 2022 Masakazu Asama
6 * Copyright 2022 6WIND S.A.
8 * This file is part of Free Range Routing (FRR).
10 * FRR is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2, or (at your option) any
15 * FRR is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; see the file COPYING; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "lib/command.h"
29 #include "lib/northbound.h"
30 #include "lib/affinitymap.h"
33 * XPath: /frr-affinity-map:lib/affinity-maps/affinity-map
36 static int lib_affinity_map_create(struct nb_cb_create_args
*args
)
41 static int lib_affinity_map_destroy(struct nb_cb_destroy_args
*args
)
45 name
= yang_dnode_get_string((const struct lyd_node
*)args
->dnode
,
48 switch (args
->event
) {
50 if (!affinity_map_check_use_hook(name
))
52 snprintf(args
->errmsg
, args
->errmsg_len
,
53 "affinity-map %s is used", name
);
54 return NB_ERR_VALIDATION
;
59 affinity_map_unset(name
);
66 * XPath: /frr-affinity-map:lib/affinity-maps/affinity-map/value
68 static int lib_affinity_map_value_modify(struct nb_cb_modify_args
*args
)
74 name
= yang_dnode_get_string(
75 (const struct lyd_node
*)args
->dnode
->parent
, "./name");
77 pos
= yang_dnode_get_uint16(
78 (const struct lyd_node
*)args
->dnode
->parent
, "./value");
80 switch (args
->event
) {
82 map_name
= affinity_map_name_get(pos
);
84 strncmp(map_name
, name
, AFFINITY_NAME_SIZE
) != 0) {
85 snprintf(args
->errmsg
, args
->errmsg_len
,
86 "bit-position is used by %s.", map_name
);
87 return NB_ERR_VALIDATION
;
89 if (!affinity_map_check_update_hook(name
, pos
)) {
91 args
->errmsg
, args
->errmsg_len
,
92 "affinity-map new bit-position > 31 but is used with standard admin-groups");
93 return NB_ERR_VALIDATION
;
100 affinity_map_update_hook(name
, pos
);
101 affinity_map_set(name
, pos
);
108 static int lib_affinity_map_value_destroy(struct nb_cb_destroy_args
*args
)
113 /* clang-format off */
114 const struct frr_yang_module_info frr_affinity_map_info
= {
115 .name
= "frr-affinity-map",
118 .xpath
= "/frr-affinity-map:lib/affinity-maps/affinity-map",
120 .create
= lib_affinity_map_create
,
121 .destroy
= lib_affinity_map_destroy
,
122 .cli_show
= cli_show_affinity_map
,
126 .xpath
= "/frr-affinity-map:lib/affinity-maps/affinity-map/value",
128 .modify
= lib_affinity_map_value_modify
,
129 .destroy
= lib_affinity_map_value_destroy
,