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