]>
Commit | Line | Data |
---|---|---|
05a12619 LS |
1 | /* |
2 | * affinity map northbound implementation. | |
3 | * | |
4 | * Copyright 2022 Hiroki Shirokura, LINE Corporation | |
5 | * Copyright 2022 Masakazu Asama | |
6 | * Copyright 2022 6WIND S.A. | |
7 | * | |
8 | * This file is part of Free Range Routing (FRR). | |
9 | * | |
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 | |
13 | * later version. | |
14 | * | |
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. | |
19 | * | |
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 | |
23 | */ | |
24 | ||
25 | #include <zebra.h> | |
26 | ||
27 | #include "lib/command.h" | |
28 | #include "lib/log.h" | |
29 | #include "lib/northbound.h" | |
30 | #include "lib/affinitymap.h" | |
31 | ||
32 | /* | |
33 | * XPath: /frr-affinity-map:lib/affinity-maps/affinity-map | |
34 | */ | |
35 | ||
36 | static int lib_affinity_map_create(struct nb_cb_create_args *args) | |
37 | { | |
38 | return NB_OK; | |
39 | } | |
40 | ||
41 | static int lib_affinity_map_destroy(struct nb_cb_destroy_args *args) | |
42 | { | |
43 | const char *name; | |
44 | ||
ae251b86 LS |
45 | name = yang_dnode_get_string((const struct lyd_node *)args->dnode, |
46 | "./name"); | |
47 | ||
05a12619 LS |
48 | switch (args->event) { |
49 | case NB_EV_VALIDATE: | |
ae251b86 LS |
50 | if (!affinity_map_check_use_hook(name)) |
51 | break; | |
52 | snprintf(args->errmsg, args->errmsg_len, | |
53 | "affinity-map %s is used", name); | |
54 | return NB_ERR_VALIDATION; | |
05a12619 LS |
55 | case NB_EV_PREPARE: |
56 | case NB_EV_ABORT: | |
57 | break; | |
58 | case NB_EV_APPLY: | |
05a12619 LS |
59 | affinity_map_unset(name); |
60 | break; | |
61 | } | |
62 | return NB_OK; | |
63 | } | |
64 | ||
65 | /* | |
66 | * XPath: /frr-affinity-map:lib/affinity-maps/affinity-map/value | |
67 | */ | |
68 | static int lib_affinity_map_value_modify(struct nb_cb_modify_args *args) | |
69 | { | |
70 | const char *name; | |
71 | char *map_name; | |
72 | uint16_t pos; | |
73 | ||
74 | name = yang_dnode_get_string( | |
75 | (const struct lyd_node *)args->dnode->parent, "./name"); | |
76 | ||
77 | pos = yang_dnode_get_uint16( | |
78 | (const struct lyd_node *)args->dnode->parent, "./value"); | |
79 | ||
80 | switch (args->event) { | |
81 | case NB_EV_VALIDATE: | |
82 | map_name = affinity_map_name_get(pos); | |
ae251b86 LS |
83 | if (map_name && |
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; | |
88 | } | |
89 | if (!affinity_map_check_update_hook(name, pos)) { | |
90 | snprintf( | |
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; | |
94 | } | |
95 | break; | |
05a12619 LS |
96 | case NB_EV_PREPARE: |
97 | case NB_EV_ABORT: | |
98 | break; | |
99 | case NB_EV_APPLY: | |
ae251b86 | 100 | affinity_map_update_hook(name, pos); |
05a12619 LS |
101 | affinity_map_set(name, pos); |
102 | break; | |
103 | } | |
104 | ||
105 | return NB_OK; | |
106 | } | |
107 | ||
108 | static int lib_affinity_map_value_destroy(struct nb_cb_destroy_args *args) | |
109 | { | |
110 | return NB_OK; | |
111 | } | |
112 | ||
113 | /* clang-format off */ | |
114 | const struct frr_yang_module_info frr_affinity_map_info = { | |
115 | .name = "frr-affinity-map", | |
116 | .nodes = { | |
117 | { | |
118 | .xpath = "/frr-affinity-map:lib/affinity-maps/affinity-map", | |
119 | .cbs = { | |
120 | .create = lib_affinity_map_create, | |
121 | .destroy = lib_affinity_map_destroy, | |
122 | .cli_show = cli_show_affinity_map, | |
123 | } | |
124 | }, | |
125 | { | |
126 | .xpath = "/frr-affinity-map:lib/affinity-maps/affinity-map/value", | |
127 | .cbs = { | |
128 | .modify = lib_affinity_map_value_modify, | |
129 | .destroy = lib_affinity_map_value_destroy, | |
130 | } | |
131 | }, | |
132 | { | |
133 | .xpath = NULL, | |
134 | }, | |
135 | } | |
136 | }; |