]> git.proxmox.com Git - mirror_frr.git/blob - pathd/path_nb.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / pathd / path_nb.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2020 NetDEF, Inc.
4 */
5
6 #include <zebra.h>
7
8 #include "northbound.h"
9 #include "libfrr.h"
10
11 #include "pathd/path_nb.h"
12
13 static int iter_objfun_cb(const struct lyd_node *dnode, void *arg);
14 static int dummy_create(struct nb_cb_create_args *args);
15 static int dummy_modify(struct nb_cb_modify_args *args);
16 static int dummy_destroy(struct nb_cb_destroy_args *args);
17
18 struct of_cb_pref {
19 uint32_t index;
20 enum objfun_type type;
21 struct of_cb_pref *next;
22 };
23
24 struct of_cb_args {
25 struct of_cb_pref *first;
26 uint32_t free_slot;
27 struct of_cb_pref prefs[MAX_OBJFUN_TYPE];
28 };
29
30 /* clang-format off */
31 const struct frr_yang_module_info frr_pathd_info = {
32 .name = "frr-pathd",
33 .nodes = {
34 {
35 .xpath = "/frr-pathd:pathd",
36 .cbs = {
37 .apply_finish = pathd_apply_finish,
38 },
39 .priority = NB_DFLT_PRIORITY + 1
40 },
41 {
42 .xpath = "/frr-pathd:pathd/srte/segment-list",
43 .cbs = {
44 .create = pathd_srte_segment_list_create,
45 .cli_show = cli_show_srte_segment_list,
46 .cli_show_end = cli_show_srte_segment_list_end,
47 .destroy = pathd_srte_segment_list_destroy,
48 .get_next = pathd_srte_segment_list_get_next,
49 .get_keys = pathd_srte_segment_list_get_keys,
50 .lookup_entry = pathd_srte_segment_list_lookup_entry,
51 },
52 .priority = NB_DFLT_PRIORITY - 1
53 },
54 {
55 .xpath = "/frr-pathd:pathd/srte/segment-list/protocol-origin",
56 .cbs = {
57 .modify = pathd_srte_segment_list_protocol_origin_modify,
58 },
59 .priority = NB_DFLT_PRIORITY - 1
60 },
61 {
62 .xpath = "/frr-pathd:pathd/srte/segment-list/originator",
63 .cbs = {
64 .modify = pathd_srte_segment_list_originator_modify,
65 },
66 .priority = NB_DFLT_PRIORITY - 1
67 },
68 {
69 .xpath = "/frr-pathd:pathd/srte/segment-list/segment",
70 .cbs = {
71 .create = pathd_srte_segment_list_segment_create,
72 .cli_show = cli_show_srte_segment_list_segment,
73 .destroy = pathd_srte_segment_list_segment_destroy,
74 },
75 .priority = NB_DFLT_PRIORITY - 1
76 },
77 {
78 .xpath = "/frr-pathd:pathd/srte/segment-list/segment/sid-value",
79 .cbs = {
80 .modify = pathd_srte_segment_list_segment_sid_value_modify,
81 .destroy = pathd_srte_segment_list_segment_sid_value_destroy,
82 },
83 .priority = NB_DFLT_PRIORITY - 1
84 },
85 {
86 .xpath = "/frr-pathd:pathd/srte/segment-list/segment/nai",
87 .cbs = {
88 .create = dummy_create,
89 .destroy = pathd_srte_segment_list_segment_nai_destroy,
90 .apply_finish = pathd_srte_segment_list_segment_nai_apply_finish
91 },
92 .priority = NB_DFLT_PRIORITY - 1
93 },
94 {
95 .xpath = "/frr-pathd:pathd/srte/segment-list/segment/nai/type",
96 .cbs = {.modify = dummy_modify}
97 },
98 {
99 .xpath = "/frr-pathd:pathd/srte/segment-list/segment/nai/local-address",
100 .cbs = {.modify = dummy_modify}
101 },
102 {
103 .xpath = "/frr-pathd:pathd/srte/segment-list/segment/nai/local-interface",
104 .cbs = {.modify = dummy_modify, .destroy = dummy_destroy}
105 },
106 {
107 .xpath = "/frr-pathd:pathd/srte/segment-list/segment/nai/local-prefix-len",
108 .cbs = {.modify = dummy_modify, .destroy = dummy_destroy}
109 },
110 {
111 .xpath = "/frr-pathd:pathd/srte/segment-list/segment/nai/remote-address",
112 .cbs = {.modify = dummy_modify, .destroy = dummy_destroy}
113 },
114 {
115 .xpath = "/frr-pathd:pathd/srte/segment-list/segment/nai/remote-interface",
116 .cbs = {.modify = dummy_modify, .destroy = dummy_destroy}
117 },
118 {
119 .xpath = "/frr-pathd:pathd/srte/segment-list/segment/nai/algorithm",
120 .cbs = {.modify = dummy_modify, .destroy = dummy_destroy}
121 },
122 {
123 .xpath = "/frr-pathd:pathd/srte/policy",
124 .cbs = {
125 .create = pathd_srte_policy_create,
126 .cli_show = cli_show_srte_policy,
127 .cli_show_end = cli_show_srte_policy_end,
128 .destroy = pathd_srte_policy_destroy,
129 .get_next = pathd_srte_policy_get_next,
130 .get_keys = pathd_srte_policy_get_keys,
131 .lookup_entry = pathd_srte_policy_lookup_entry,
132 }
133 },
134 {
135 .xpath = "/frr-pathd:pathd/srte/policy/name",
136 .cbs = {
137 .modify = pathd_srte_policy_name_modify,
138 .cli_show = cli_show_srte_policy_name,
139 .destroy = pathd_srte_policy_name_destroy,
140 }
141 },
142 {
143 .xpath = "/frr-pathd:pathd/srte/policy/binding-sid",
144 .cbs = {
145 .modify = pathd_srte_policy_binding_sid_modify,
146 .cli_show = cli_show_srte_policy_binding_sid,
147 .destroy = pathd_srte_policy_binding_sid_destroy,
148 }
149 },
150 {
151 .xpath = "/frr-pathd:pathd/srte/policy/is-operational",
152 .cbs = {
153 .get_elem = pathd_srte_policy_is_operational_get_elem
154 }
155 },
156 {
157 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path",
158 .cbs = {
159 .create = pathd_srte_policy_candidate_path_create,
160 .cli_show = cli_show_srte_policy_candidate_path,
161 .cli_show_end = cli_show_srte_policy_candidate_path_end,
162 .destroy = pathd_srte_policy_candidate_path_destroy,
163 .get_next = pathd_srte_policy_candidate_path_get_next,
164 .get_keys = pathd_srte_policy_candidate_path_get_keys,
165 .lookup_entry = pathd_srte_policy_candidate_path_lookup_entry,
166 }
167 },
168 {
169 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/name",
170 .cbs = {
171 .modify = pathd_srte_policy_candidate_path_name_modify,
172 }
173 },
174 {
175 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/is-best-candidate-path",
176 .cbs = {
177 .get_elem = pathd_srte_policy_candidate_path_is_best_candidate_path_get_elem,
178 }
179 },
180 {
181 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/protocol-origin",
182 .cbs = {
183 .modify = pathd_srte_policy_candidate_path_protocol_origin_modify,
184 }
185 },
186 {
187 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/originator",
188 .cbs = {
189 .modify = pathd_srte_policy_candidate_path_originator_modify,
190 }
191 },
192 {
193 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/discriminator",
194 .cbs = {
195 .get_elem = pathd_srte_policy_candidate_path_discriminator_get_elem,
196 }
197 },
198 {
199 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/type",
200 .cbs = {
201 .modify = pathd_srte_policy_candidate_path_type_modify,
202 }
203 },
204 {
205 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/segment-list-name",
206 .cbs = {
207 .destroy = pathd_srte_policy_candidate_path_segment_list_name_destroy,
208 .modify = pathd_srte_policy_candidate_path_segment_list_name_modify,
209 }
210 },
211 {
212 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/constraints/bandwidth",
213 .cbs = {
214 .create = dummy_create,
215 .destroy = pathd_srte_policy_candidate_path_bandwidth_destroy,
216 .apply_finish = pathd_srte_policy_candidate_path_bandwidth_apply_finish
217 }
218 },
219 {
220 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/constraints/bandwidth/required",
221 .cbs = {.modify = dummy_modify}
222 },
223 {
224 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/constraints/bandwidth/value",
225 .cbs = {.modify = dummy_modify}
226 },
227 {
228 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/constraints/affinity/exclude-any",
229 .cbs = {
230 .modify = pathd_srte_policy_candidate_path_exclude_any_modify,
231 .destroy = pathd_srte_policy_candidate_path_exclude_any_destroy,
232 }
233 },
234 {
235 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/constraints/affinity/include-any",
236 .cbs = {
237 .modify = pathd_srte_policy_candidate_path_include_any_modify,
238 .destroy = pathd_srte_policy_candidate_path_include_any_destroy,
239 }
240 },
241 {
242 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/constraints/affinity/include-all",
243 .cbs = {
244 .modify = pathd_srte_policy_candidate_path_include_all_modify,
245 .destroy = pathd_srte_policy_candidate_path_include_all_destroy,
246 }
247 },
248 {
249 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics",
250 .cbs = {
251 .create = dummy_create,
252 .destroy = pathd_srte_policy_candidate_path_metrics_destroy,
253 .apply_finish = pathd_srte_policy_candidate_path_metrics_apply_finish
254 }
255 },
256 {
257 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics/value",
258 .cbs = {.modify = dummy_modify}
259 },
260 {
261 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics/required",
262 .cbs = {.modify = dummy_modify}
263 },
264 {
265 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics/is-bound",
266 .cbs = {.modify = dummy_modify, .destroy = dummy_destroy}
267 },
268 {
269 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics/is-computed",
270 .cbs = {.modify = dummy_modify, .destroy = dummy_destroy}
271 },
272 {
273 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/constraints/objective-function",
274 .cbs = {
275 .create = dummy_create,
276 .destroy = pathd_srte_policy_candidate_path_objfun_destroy,
277 .apply_finish = pathd_srte_policy_candidate_path_objfun_apply_finish
278 }
279 },
280 {
281 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/constraints/objective-function/required",
282 .cbs = {.modify = dummy_modify}
283 },
284 {
285 .xpath = "/frr-pathd:pathd/srte/policy/candidate-path/constraints/objective-function/type",
286 .cbs = {.modify = dummy_modify}
287 },
288 {
289 .xpath = NULL,
290 },
291 }
292 };
293
294 void iter_objfun_prefs(const struct lyd_node *dnode, const char* path,
295 of_pref_cp_t fun, void *arg)
296 {
297 struct of_cb_args args = {0};
298 struct of_cb_pref *p;
299
300 yang_dnode_iterate(iter_objfun_cb, &args, dnode, "%s", path);
301 for (p = args.first; p != NULL; p = p->next)
302 fun(p->type, arg);
303 }
304
305 int iter_objfun_cb(const struct lyd_node *dnode, void *arg)
306 {
307 struct of_cb_args *of_arg = arg;
308 struct of_cb_pref *pref;
309 struct of_cb_pref **p;
310
311 if (of_arg->free_slot >= MAX_OBJFUN_TYPE)
312 return YANG_ITER_STOP;
313
314 pref = &of_arg->prefs[of_arg->free_slot++];
315
316 pref->index = yang_dnode_get_uint32(dnode, "./index");
317 pref->type = yang_dnode_get_enum(dnode, "./type");
318
319 /* Simplistic insertion sort */
320 p = &of_arg->first;
321 while (true) {
322 if (*p == NULL) {
323 *p = pref;
324 break;
325 }
326 if ((*p)->index >= pref->index) {
327 pref->next = *p;
328 *p = pref;
329 break;
330 }
331 p = &(*p)->next;
332 }
333
334 return YANG_ITER_CONTINUE;
335 }
336
337 int dummy_create(struct nb_cb_create_args *args)
338 {
339 return NB_OK;
340 }
341
342 int dummy_modify(struct nb_cb_modify_args *args)
343 {
344 return NB_OK;
345 }
346
347 int dummy_destroy(struct nb_cb_destroy_args *args)
348 {
349 return NB_OK;
350 }