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