2 * Copyright (C) 2020 NetDEF, Inc.
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)
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
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
21 #include "northbound.h"
24 #include "pathd/path_nb.h"
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
);
33 enum objfun_type type
;
34 struct of_cb_pref
*next
;
38 struct of_cb_pref
*first
;
40 struct of_cb_pref prefs
[MAX_OBJFUN_TYPE
];
43 /* clang-format off */
44 const struct frr_yang_module_info frr_pathd_info
= {
48 .xpath
= "/frr-pathd:pathd",
50 .apply_finish
= pathd_apply_finish
,
52 .priority
= NB_DFLT_PRIORITY
+ 1
55 .xpath
= "/frr-pathd:pathd/srte/segment-list",
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
,
65 .priority
= NB_DFLT_PRIORITY
- 1
68 .xpath
= "/frr-pathd:pathd/srte/segment-list/protocol-origin",
70 .modify
= pathd_srte_segment_list_protocol_origin_modify
,
72 .priority
= NB_DFLT_PRIORITY
- 1
75 .xpath
= "/frr-pathd:pathd/srte/segment-list/originator",
77 .modify
= pathd_srte_segment_list_originator_modify
,
79 .priority
= NB_DFLT_PRIORITY
- 1
82 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment",
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
,
88 .priority
= NB_DFLT_PRIORITY
- 1
91 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/sid-value",
93 .modify
= pathd_srte_segment_list_segment_sid_value_modify
,
94 .destroy
= pathd_srte_segment_list_segment_sid_value_destroy
,
96 .priority
= NB_DFLT_PRIORITY
- 1
99 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/nai",
101 .create
= dummy_create
,
102 .destroy
= pathd_srte_segment_list_segment_nai_destroy
,
103 .apply_finish
= pathd_srte_segment_list_segment_nai_apply_finish
105 .priority
= NB_DFLT_PRIORITY
- 1
108 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/nai/type",
109 .cbs
= {.modify
= dummy_modify
}
112 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/nai/local-address",
113 .cbs
= {.modify
= dummy_modify
}
116 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/nai/local-interface",
117 .cbs
= {.modify
= dummy_modify
, .destroy
= dummy_destroy
}
120 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/nai/local-prefix-len",
121 .cbs
= {.modify
= dummy_modify
, .destroy
= dummy_destroy
}
124 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/nai/remote-address",
125 .cbs
= {.modify
= dummy_modify
, .destroy
= dummy_destroy
}
128 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/nai/remote-interface",
129 .cbs
= {.modify
= dummy_modify
, .destroy
= dummy_destroy
}
132 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/nai/algorithm",
133 .cbs
= {.modify
= dummy_modify
, .destroy
= dummy_destroy
}
136 .xpath
= "/frr-pathd:pathd/srte/policy",
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
,
148 .xpath
= "/frr-pathd:pathd/srte/policy/name",
150 .modify
= pathd_srte_policy_name_modify
,
151 .cli_show
= cli_show_srte_policy_name
,
152 .destroy
= pathd_srte_policy_name_destroy
,
156 .xpath
= "/frr-pathd:pathd/srte/policy/binding-sid",
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
,
164 .xpath
= "/frr-pathd:pathd/srte/policy/is-operational",
166 .get_elem
= pathd_srte_policy_is_operational_get_elem
170 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path",
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
,
182 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/name",
184 .modify
= pathd_srte_policy_candidate_path_name_modify
,
188 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/is-best-candidate-path",
190 .get_elem
= pathd_srte_policy_candidate_path_is_best_candidate_path_get_elem
,
194 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/protocol-origin",
196 .modify
= pathd_srte_policy_candidate_path_protocol_origin_modify
,
200 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/originator",
202 .modify
= pathd_srte_policy_candidate_path_originator_modify
,
206 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/discriminator",
208 .get_elem
= pathd_srte_policy_candidate_path_discriminator_get_elem
,
212 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/type",
214 .modify
= pathd_srte_policy_candidate_path_type_modify
,
218 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/segment-list-name",
220 .destroy
= pathd_srte_policy_candidate_path_segment_list_name_destroy
,
221 .modify
= pathd_srte_policy_candidate_path_segment_list_name_modify
,
225 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/bandwidth",
227 .create
= dummy_create
,
228 .destroy
= pathd_srte_policy_candidate_path_bandwidth_destroy
,
229 .apply_finish
= pathd_srte_policy_candidate_path_bandwidth_apply_finish
233 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/bandwidth/required",
234 .cbs
= {.modify
= dummy_modify
}
237 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/bandwidth/value",
238 .cbs
= {.modify
= dummy_modify
}
241 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/affinity/exclude-any",
243 .modify
= pathd_srte_policy_candidate_path_exclude_any_modify
,
244 .destroy
= pathd_srte_policy_candidate_path_exclude_any_destroy
,
248 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/affinity/include-any",
250 .modify
= pathd_srte_policy_candidate_path_include_any_modify
,
251 .destroy
= pathd_srte_policy_candidate_path_include_any_destroy
,
255 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/affinity/include-all",
257 .modify
= pathd_srte_policy_candidate_path_include_all_modify
,
258 .destroy
= pathd_srte_policy_candidate_path_include_all_destroy
,
262 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics",
264 .create
= dummy_create
,
265 .destroy
= pathd_srte_policy_candidate_path_metrics_destroy
,
266 .apply_finish
= pathd_srte_policy_candidate_path_metrics_apply_finish
270 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics/value",
271 .cbs
= {.modify
= dummy_modify
}
274 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics/required",
275 .cbs
= {.modify
= dummy_modify
}
278 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics/is-bound",
279 .cbs
= {.modify
= dummy_modify
, .destroy
= dummy_destroy
}
282 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics/is-computed",
283 .cbs
= {.modify
= dummy_modify
, .destroy
= dummy_destroy
}
286 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/objective-function",
288 .create
= dummy_create
,
289 .destroy
= pathd_srte_policy_candidate_path_objfun_destroy
,
290 .apply_finish
= pathd_srte_policy_candidate_path_objfun_apply_finish
294 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/objective-function/required",
295 .cbs
= {.modify
= dummy_modify
}
298 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/objective-function/type",
299 .cbs
= {.modify
= dummy_modify
}
307 void iter_objfun_prefs(const struct lyd_node
*dnode
, const char* path
,
308 of_pref_cp_t fun
, void *arg
)
310 struct of_cb_args args
= {0};
311 struct of_cb_pref
*p
;
313 yang_dnode_iterate(iter_objfun_cb
, &args
, dnode
, path
);
314 for (p
= args
.first
; p
!= NULL
; p
= p
->next
)
318 int iter_objfun_cb(const struct lyd_node
*dnode
, void *arg
)
320 struct of_cb_args
*of_arg
= arg
;
321 struct of_cb_pref
*pref
;
322 struct of_cb_pref
**p
;
324 if (of_arg
->free_slot
>= MAX_OBJFUN_TYPE
)
325 return YANG_ITER_STOP
;
327 pref
= &of_arg
->prefs
[of_arg
->free_slot
++];
329 pref
->index
= yang_dnode_get_uint32(dnode
, "./index");
330 pref
->type
= yang_dnode_get_enum(dnode
, "./type");
332 /* Simplistic insertion sort */
339 if ((*p
)->index
>= pref
->index
) {
347 return YANG_ITER_CONTINUE
;
350 int dummy_create(struct nb_cb_create_args
*args
)
355 int dummy_modify(struct nb_cb_modify_args
*args
)
360 int dummy_destroy(struct nb_cb_destroy_args
*args
)