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 .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
,
64 .priority
= NB_DFLT_PRIORITY
- 1
67 .xpath
= "/frr-pathd:pathd/srte/segment-list/protocol-origin",
69 .modify
= pathd_srte_segment_list_protocol_origin_modify
,
71 .priority
= NB_DFLT_PRIORITY
- 1
74 .xpath
= "/frr-pathd:pathd/srte/segment-list/originator",
76 .modify
= pathd_srte_segment_list_originator_modify
,
78 .priority
= NB_DFLT_PRIORITY
- 1
81 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment",
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
,
87 .priority
= NB_DFLT_PRIORITY
- 1
90 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/sid-value",
92 .modify
= pathd_srte_segment_list_segment_sid_value_modify
,
94 .priority
= NB_DFLT_PRIORITY
- 1
97 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/nai",
99 .create
= dummy_create
,
100 .destroy
= pathd_srte_segment_list_segment_nai_destroy
,
101 .apply_finish
= pathd_srte_segment_list_segment_nai_apply_finish
103 .priority
= NB_DFLT_PRIORITY
- 1
106 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/nai/type",
107 .cbs
= {.modify
= dummy_modify
}
110 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/nai/local-address",
111 .cbs
= {.modify
= dummy_modify
}
114 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/nai/local-interface",
115 .cbs
= {.modify
= dummy_modify
, .destroy
= dummy_destroy
}
118 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/nai/remote-address",
119 .cbs
= {.modify
= dummy_modify
, .destroy
= dummy_destroy
}
122 .xpath
= "/frr-pathd:pathd/srte/segment-list/segment/nai/remote-interface",
123 .cbs
= {.modify
= dummy_modify
, .destroy
= dummy_destroy
}
126 .xpath
= "/frr-pathd:pathd/srte/policy",
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
,
137 .xpath
= "/frr-pathd:pathd/srte/policy/name",
139 .modify
= pathd_srte_policy_name_modify
,
140 .cli_show
= cli_show_srte_policy_name
,
141 .destroy
= pathd_srte_policy_name_destroy
,
145 .xpath
= "/frr-pathd:pathd/srte/policy/binding-sid",
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
,
153 .xpath
= "/frr-pathd:pathd/srte/policy/is-operational",
155 .get_elem
= pathd_srte_policy_is_operational_get_elem
159 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path",
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
,
170 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/name",
172 .modify
= pathd_srte_policy_candidate_path_name_modify
,
176 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/is-best-candidate-path",
178 .get_elem
= pathd_srte_policy_candidate_path_is_best_candidate_path_get_elem
,
182 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/protocol-origin",
184 .modify
= pathd_srte_policy_candidate_path_protocol_origin_modify
,
188 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/originator",
190 .modify
= pathd_srte_policy_candidate_path_originator_modify
,
194 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/discriminator",
196 .get_elem
= pathd_srte_policy_candidate_path_discriminator_get_elem
,
200 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/type",
202 .modify
= pathd_srte_policy_candidate_path_type_modify
,
206 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/segment-list-name",
208 .destroy
= pathd_srte_policy_candidate_path_segment_list_name_destroy
,
209 .modify
= pathd_srte_policy_candidate_path_segment_list_name_modify
,
213 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/bandwidth",
215 .create
= dummy_create
,
216 .destroy
= pathd_srte_policy_candidate_path_bandwidth_destroy
,
217 .apply_finish
= pathd_srte_policy_candidate_path_bandwidth_apply_finish
221 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/bandwidth/required",
222 .cbs
= {.modify
= dummy_modify
}
225 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/bandwidth/value",
226 .cbs
= {.modify
= dummy_modify
}
229 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/affinity/exclude-any",
231 .modify
= pathd_srte_policy_candidate_path_exclude_any_modify
,
232 .destroy
= pathd_srte_policy_candidate_path_exclude_any_destroy
,
236 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/affinity/include-any",
238 .modify
= pathd_srte_policy_candidate_path_include_any_modify
,
239 .destroy
= pathd_srte_policy_candidate_path_include_any_destroy
,
243 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/affinity/include-all",
245 .modify
= pathd_srte_policy_candidate_path_include_all_modify
,
246 .destroy
= pathd_srte_policy_candidate_path_include_all_destroy
,
250 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics",
252 .create
= dummy_create
,
253 .destroy
= pathd_srte_policy_candidate_path_metrics_destroy
,
254 .apply_finish
= pathd_srte_policy_candidate_path_metrics_apply_finish
258 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics/value",
259 .cbs
= {.modify
= dummy_modify
}
262 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics/required",
263 .cbs
= {.modify
= dummy_modify
}
266 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics/is-bound",
267 .cbs
= {.modify
= dummy_modify
, .destroy
= dummy_destroy
}
270 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/metrics/is-computed",
271 .cbs
= {.modify
= dummy_modify
, .destroy
= dummy_destroy
}
274 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/objective-function",
276 .create
= dummy_create
,
277 .destroy
= pathd_srte_policy_candidate_path_objfun_destroy
,
278 .apply_finish
= pathd_srte_policy_candidate_path_objfun_apply_finish
282 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/objective-function/required",
283 .cbs
= {.modify
= dummy_modify
}
286 .xpath
= "/frr-pathd:pathd/srte/policy/candidate-path/constraints/objective-function/type",
287 .cbs
= {.modify
= dummy_modify
}
295 void iter_objfun_prefs(const struct lyd_node
*dnode
, const char* path
,
296 of_pref_cp_t fun
, void *arg
)
298 struct of_cb_args args
= {0};
299 struct of_cb_pref
*p
;
301 yang_dnode_iterate(iter_objfun_cb
, &args
, dnode
, path
);
302 for (p
= args
.first
; p
!= NULL
; p
= p
->next
)
306 int iter_objfun_cb(const struct lyd_node
*dnode
, void *arg
)
308 struct of_cb_args
*of_arg
= arg
;
309 struct of_cb_pref
*pref
;
310 struct of_cb_pref
**p
;
312 if (of_arg
->free_slot
>= MAX_OBJFUN_TYPE
)
313 return YANG_ITER_STOP
;
315 pref
= &of_arg
->prefs
[of_arg
->free_slot
++];
317 pref
->index
= yang_dnode_get_uint32(dnode
, "./index");
318 pref
->type
= yang_dnode_get_enum(dnode
, "./type");
320 /* Simplistic insertion sort */
327 if ((*p
)->index
>= pref
->index
) {
335 return YANG_ITER_CONTINUE
;
338 int dummy_create(struct nb_cb_create_args
*args
)
343 int dummy_modify(struct nb_cb_modify_args
*args
)
348 int dummy_destroy(struct nb_cb_destroy_args
*args
)