]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 2018 NetDEF, Inc. | |
3 | * Renato Westphal | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the Free | |
7 | * Software Foundation; either version 2 of the License, or (at your option) | |
8 | * any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; see the file COPYING; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | */ | |
19 | ||
20 | #ifndef _FRR_NORTHBOUND_H_ | |
21 | #define _FRR_NORTHBOUND_H_ | |
22 | ||
23 | #include "thread.h" | |
24 | #include "hook.h" | |
25 | #include "linklist.h" | |
26 | #include "openbsd-tree.h" | |
27 | #include "yang.h" | |
28 | #include "yang_translator.h" | |
29 | ||
30 | #ifdef __cplusplus | |
31 | extern "C" { | |
32 | #endif | |
33 | ||
34 | /* Forward declaration(s). */ | |
35 | struct vty; | |
36 | ||
37 | /* Northbound events. */ | |
38 | enum nb_event { | |
39 | /* | |
40 | * The configuration callback is supposed to verify that the changes are | |
41 | * valid and can be applied. | |
42 | */ | |
43 | NB_EV_VALIDATE, | |
44 | ||
45 | /* | |
46 | * The configuration callback is supposed to prepare all resources | |
47 | * required to apply the changes. | |
48 | */ | |
49 | NB_EV_PREPARE, | |
50 | ||
51 | /* | |
52 | * Transaction has failed, the configuration callback needs to release | |
53 | * all resources previously allocated. | |
54 | */ | |
55 | NB_EV_ABORT, | |
56 | ||
57 | /* | |
58 | * The configuration changes need to be applied. The changes can't be | |
59 | * rejected at this point (errors are logged and ignored). | |
60 | */ | |
61 | NB_EV_APPLY, | |
62 | }; | |
63 | ||
64 | /* | |
65 | * Northbound operations. | |
66 | * | |
67 | * Refer to the documentation comments of nb_callbacks for more details. | |
68 | */ | |
69 | enum nb_operation { | |
70 | NB_OP_CREATE, | |
71 | NB_OP_MODIFY, | |
72 | NB_OP_DESTROY, | |
73 | NB_OP_MOVE, | |
74 | NB_OP_APPLY_FINISH, | |
75 | NB_OP_GET_ELEM, | |
76 | NB_OP_GET_NEXT, | |
77 | NB_OP_GET_KEYS, | |
78 | NB_OP_LOOKUP_ENTRY, | |
79 | NB_OP_RPC, | |
80 | }; | |
81 | ||
82 | union nb_resource { | |
83 | int fd; | |
84 | void *ptr; | |
85 | }; | |
86 | ||
87 | struct nb_callbacks { | |
88 | /* | |
89 | * Configuration callback. | |
90 | * | |
91 | * A presence container, list entry, leaf-list entry or leaf of type | |
92 | * empty has been created. | |
93 | * | |
94 | * For presence-containers and list entries, the callback is supposed to | |
95 | * initialize the default values of its children (if any) from the YANG | |
96 | * models. | |
97 | * | |
98 | * event | |
99 | * The transaction phase. Refer to the documentation comments of | |
100 | * nb_event for more details. | |
101 | * | |
102 | * dnode | |
103 | * libyang data node that is being created. | |
104 | * | |
105 | * resource | |
106 | * Pointer to store resource(s) allocated during the NB_EV_PREPARE | |
107 | * phase. The same pointer can be used during the NB_EV_ABORT and | |
108 | * NB_EV_APPLY phases to either release or make use of the allocated | |
109 | * resource(s). It's set to NULL when the event is NB_EV_VALIDATE. | |
110 | * | |
111 | * Returns: | |
112 | * - NB_OK on success. | |
113 | * - NB_ERR_VALIDATION when a validation error occurred. | |
114 | * - NB_ERR_RESOURCE when the callback failed to allocate a resource. | |
115 | * - NB_ERR_INCONSISTENCY when an inconsistency was detected. | |
116 | * - NB_ERR for other errors. | |
117 | */ | |
118 | int (*create)(enum nb_event event, const struct lyd_node *dnode, | |
119 | union nb_resource *resource); | |
120 | ||
121 | /* | |
122 | * Configuration callback. | |
123 | * | |
124 | * The value of a leaf has been modified. | |
125 | * | |
126 | * List keys don't need to implement this callback. When a list key is | |
127 | * modified, the northbound treats this as if the list was deleted and a | |
128 | * new one created with the updated key value. | |
129 | * | |
130 | * event | |
131 | * The transaction phase. Refer to the documentation comments of | |
132 | * nb_event for more details. | |
133 | * | |
134 | * dnode | |
135 | * libyang data node that is being modified | |
136 | * | |
137 | * resource | |
138 | * Pointer to store resource(s) allocated during the NB_EV_PREPARE | |
139 | * phase. The same pointer can be used during the NB_EV_ABORT and | |
140 | * NB_EV_APPLY phases to either release or make use of the allocated | |
141 | * resource(s). It's set to NULL when the event is NB_EV_VALIDATE. | |
142 | * | |
143 | * Returns: | |
144 | * - NB_OK on success. | |
145 | * - NB_ERR_VALIDATION when a validation error occurred. | |
146 | * - NB_ERR_RESOURCE when the callback failed to allocate a resource. | |
147 | * - NB_ERR_INCONSISTENCY when an inconsistency was detected. | |
148 | * - NB_ERR for other errors. | |
149 | */ | |
150 | int (*modify)(enum nb_event event, const struct lyd_node *dnode, | |
151 | union nb_resource *resource); | |
152 | ||
153 | /* | |
154 | * Configuration callback. | |
155 | * | |
156 | * A presence container, list entry, leaf-list entry or optional leaf | |
157 | * has been deleted. | |
158 | * | |
159 | * The callback is supposed to delete the entire configuration object, | |
160 | * including its children when they exist. | |
161 | * | |
162 | * event | |
163 | * The transaction phase. Refer to the documentation comments of | |
164 | * nb_event for more details. | |
165 | * | |
166 | * dnode | |
167 | * libyang data node that is being deleted. | |
168 | * | |
169 | * Returns: | |
170 | * - NB_OK on success. | |
171 | * - NB_ERR_VALIDATION when a validation error occurred. | |
172 | * - NB_ERR_INCONSISTENCY when an inconsistency was detected. | |
173 | * - NB_ERR for other errors. | |
174 | */ | |
175 | int (*destroy)(enum nb_event event, const struct lyd_node *dnode); | |
176 | ||
177 | /* | |
178 | * Configuration callback. | |
179 | * | |
180 | * A list entry or leaf-list entry has been moved. Only applicable when | |
181 | * the "ordered-by user" statement is present. | |
182 | * | |
183 | * event | |
184 | * The transaction phase. Refer to the documentation comments of | |
185 | * nb_event for more details. | |
186 | * | |
187 | * dnode | |
188 | * libyang data node that is being moved. | |
189 | * | |
190 | * Returns: | |
191 | * - NB_OK on success. | |
192 | * - NB_ERR_VALIDATION when a validation error occurred. | |
193 | * - NB_ERR_INCONSISTENCY when an inconsistency was detected. | |
194 | * - NB_ERR for other errors. | |
195 | */ | |
196 | int (*move)(enum nb_event event, const struct lyd_node *dnode); | |
197 | ||
198 | /* | |
199 | * Optional configuration callback. | |
200 | * | |
201 | * The 'apply_finish' callbacks are called after all other callbacks | |
202 | * during the apply phase (NB_EV_APPLY). These callbacks are called only | |
203 | * under one of the following two cases: | |
204 | * - The data node has been created or modified (but not deleted); | |
205 | * - Any change was made within the descendants of the data node (e.g. a | |
206 | * child leaf was modified, created or deleted). | |
207 | * | |
208 | * In the second case above, the 'apply_finish' callback is called only | |
209 | * once even if multiple changes occurred within the descendants of the | |
210 | * data node. | |
211 | * | |
212 | * dnode | |
213 | * libyang data node associated with the 'apply_finish' callback. | |
214 | */ | |
215 | void (*apply_finish)(const struct lyd_node *dnode); | |
216 | ||
217 | /* | |
218 | * Operational data callback. | |
219 | * | |
220 | * The callback function should return the value of a specific leaf, | |
221 | * leaf-list entry or inform if a typeless value (presence containers or | |
222 | * leafs of type empty) exists or not. | |
223 | * | |
224 | * xpath | |
225 | * YANG data path of the data we want to get. | |
226 | * | |
227 | * list_entry | |
228 | * Pointer to list entry (might be NULL). | |
229 | * | |
230 | * Returns: | |
231 | * Pointer to newly created yang_data structure, or NULL to indicate | |
232 | * the absence of data. | |
233 | */ | |
234 | struct yang_data *(*get_elem)(const char *xpath, | |
235 | const void *list_entry); | |
236 | ||
237 | /* | |
238 | * Operational data callback for YANG lists and leaf-lists. | |
239 | * | |
240 | * The callback function should return the next entry in the list or | |
241 | * leaf-list. The 'list_entry' parameter will be NULL on the first | |
242 | * invocation. | |
243 | * | |
244 | * parent_list_entry | |
245 | * Pointer to parent list entry. | |
246 | * | |
247 | * list_entry | |
248 | * Pointer to (leaf-)list entry. | |
249 | * | |
250 | * Returns: | |
251 | * Pointer to the next entry in the (leaf-)list, or NULL to signal | |
252 | * that the end of the (leaf-)list was reached. | |
253 | */ | |
254 | const void *(*get_next)(const void *parent_list_entry, | |
255 | const void *list_entry); | |
256 | ||
257 | /* | |
258 | * Operational data callback for YANG lists. | |
259 | * | |
260 | * The callback function should fill the 'keys' parameter based on the | |
261 | * given list_entry. Keyless lists don't need to implement this | |
262 | * callback. | |
263 | * | |
264 | * list_entry | |
265 | * Pointer to list entry. | |
266 | * | |
267 | * keys | |
268 | * Structure to be filled based on the attributes of the provided | |
269 | * list entry. | |
270 | * | |
271 | * Returns: | |
272 | * NB_OK on success, NB_ERR otherwise. | |
273 | */ | |
274 | int (*get_keys)(const void *list_entry, struct yang_list_keys *keys); | |
275 | ||
276 | /* | |
277 | * Operational data callback for YANG lists. | |
278 | * | |
279 | * The callback function should return a list entry based on the list | |
280 | * keys given as a parameter. Keyless lists don't need to implement this | |
281 | * callback. | |
282 | * | |
283 | * parent_list_entry | |
284 | * Pointer to parent list entry. | |
285 | * | |
286 | * keys | |
287 | * Structure containing the keys of the list entry. | |
288 | * | |
289 | * Returns: | |
290 | * Pointer to the list entry if found, or NULL if not found. | |
291 | */ | |
292 | const void *(*lookup_entry)(const void *parent_list_entry, | |
293 | const struct yang_list_keys *keys); | |
294 | ||
295 | /* | |
296 | * RPC and action callback. | |
297 | * | |
298 | * Both 'input' and 'output' are lists of 'yang_data' structures. The | |
299 | * callback should fetch all the input parameters from the 'input' list, | |
300 | * and add output parameters to the 'output' list if necessary. | |
301 | * | |
302 | * xpath | |
303 | * XPath of the YANG RPC or action. | |
304 | * | |
305 | * input | |
306 | * Read-only list of input parameters. | |
307 | * | |
308 | * output | |
309 | * List of output parameters to be populated by the callback. | |
310 | * | |
311 | * Returns: | |
312 | * NB_OK on success, NB_ERR otherwise. | |
313 | */ | |
314 | int (*rpc)(const char *xpath, const struct list *input, | |
315 | struct list *output); | |
316 | ||
317 | /* | |
318 | * Optional callback to show the CLI command associated to the given | |
319 | * YANG data node. | |
320 | * | |
321 | * vty | |
322 | * The vty terminal to dump the configuration to. | |
323 | * | |
324 | * dnode | |
325 | * libyang data node that should be shown in the form of a CLI | |
326 | * command. | |
327 | * | |
328 | * show_defaults | |
329 | * Specify whether to display default configuration values or not. | |
330 | * This parameter can be ignored most of the time since the | |
331 | * northbound doesn't call this callback for default leaves or | |
332 | * non-presence containers that contain only default child nodes. | |
333 | * The exception are commands associated to multiple configuration | |
334 | * nodes, in which case it might be desirable to hide one or more | |
335 | * parts of the command when this parameter is set to false. | |
336 | */ | |
337 | void (*cli_show)(struct vty *vty, struct lyd_node *dnode, | |
338 | bool show_defaults); | |
339 | }; | |
340 | ||
341 | /* | |
342 | * Northbound-specific data that is allocated for each schema node of the native | |
343 | * YANG modules. | |
344 | */ | |
345 | struct nb_node { | |
346 | /* Back pointer to the libyang schema node. */ | |
347 | const struct lys_node *snode; | |
348 | ||
349 | /* Data path of this YANG node. */ | |
350 | char xpath[XPATH_MAXLEN]; | |
351 | ||
352 | /* Priority - lower priorities are processed first. */ | |
353 | uint32_t priority; | |
354 | ||
355 | /* Callbacks implemented for this node. */ | |
356 | struct nb_callbacks cbs; | |
357 | ||
358 | /* | |
359 | * Pointer to the parent node (disconsidering non-presence containers). | |
360 | */ | |
361 | struct nb_node *parent; | |
362 | ||
363 | /* Pointer to the nearest parent list, if any. */ | |
364 | struct nb_node *parent_list; | |
365 | ||
366 | /* Flags. */ | |
367 | uint8_t flags; | |
368 | ||
369 | #ifdef HAVE_CONFD | |
370 | /* ConfD hash value corresponding to this YANG path. */ | |
371 | int confd_hash; | |
372 | #endif | |
373 | }; | |
374 | /* The YANG container or list contains only config data. */ | |
375 | #define F_NB_NODE_CONFIG_ONLY 0x01 | |
376 | /* The YANG list doesn't contain key leafs. */ | |
377 | #define F_NB_NODE_KEYLESS_LIST 0x02 | |
378 | ||
379 | struct frr_yang_module_info { | |
380 | /* YANG module name. */ | |
381 | const char *name; | |
382 | ||
383 | /* Northbound callbacks. */ | |
384 | const struct { | |
385 | /* Data path of this YANG node. */ | |
386 | const char *xpath; | |
387 | ||
388 | /* Callbacks implemented for this node. */ | |
389 | struct nb_callbacks cbs; | |
390 | ||
391 | /* Priority - lower priorities are processed first. */ | |
392 | uint32_t priority; | |
393 | } nodes[]; | |
394 | }; | |
395 | ||
396 | /* Northbound error codes. */ | |
397 | enum nb_error { | |
398 | NB_OK = 0, | |
399 | NB_ERR, | |
400 | NB_ERR_NO_CHANGES, | |
401 | NB_ERR_NOT_FOUND, | |
402 | NB_ERR_LOCKED, | |
403 | NB_ERR_VALIDATION, | |
404 | NB_ERR_RESOURCE, | |
405 | NB_ERR_INCONSISTENCY, | |
406 | }; | |
407 | ||
408 | /* Default priority. */ | |
409 | #define NB_DFLT_PRIORITY (UINT32_MAX / 2) | |
410 | ||
411 | /* Default maximum of configuration rollbacks to store. */ | |
412 | #define NB_DLFT_MAX_CONFIG_ROLLBACKS 20 | |
413 | ||
414 | /* Northbound clients. */ | |
415 | enum nb_client { | |
416 | NB_CLIENT_CLI = 0, | |
417 | NB_CLIENT_CONFD, | |
418 | NB_CLIENT_SYSREPO, | |
419 | }; | |
420 | ||
421 | /* Northbound configuration. */ | |
422 | struct nb_config { | |
423 | struct lyd_node *dnode; | |
424 | uint32_t version; | |
425 | }; | |
426 | ||
427 | /* Northbound configuration callback. */ | |
428 | struct nb_config_cb { | |
429 | RB_ENTRY(nb_config_cb) entry; | |
430 | enum nb_operation operation; | |
431 | char xpath[XPATH_MAXLEN]; | |
432 | const struct nb_node *nb_node; | |
433 | const struct lyd_node *dnode; | |
434 | }; | |
435 | RB_HEAD(nb_config_cbs, nb_config_cb); | |
436 | RB_PROTOTYPE(nb_config_cbs, nb_config_cb, entry, nb_config_cb_compare); | |
437 | ||
438 | /* Northbound configuration change. */ | |
439 | struct nb_config_change { | |
440 | struct nb_config_cb cb; | |
441 | union nb_resource resource; | |
442 | bool prepare_ok; | |
443 | }; | |
444 | ||
445 | /* Northbound configuration transaction. */ | |
446 | struct nb_transaction { | |
447 | enum nb_client client; | |
448 | char comment[80]; | |
449 | struct nb_config *config; | |
450 | struct nb_config_cbs changes; | |
451 | }; | |
452 | ||
453 | /* Callback function used by nb_oper_data_iterate(). */ | |
454 | typedef int (*nb_oper_data_cb)(const struct lys_node *snode, | |
455 | struct yang_translator *translator, | |
456 | struct yang_data *data, void *arg); | |
457 | ||
458 | /* Iterate over direct child nodes only. */ | |
459 | #define NB_OPER_DATA_ITER_NORECURSE 0x0001 | |
460 | ||
461 | DECLARE_HOOK(nb_notification_send, (const char *xpath, struct list *arguments), | |
462 | (xpath, arguments)) | |
463 | ||
464 | extern int debug_northbound; | |
465 | extern struct nb_config *running_config; | |
466 | ||
467 | /* | |
468 | * Create a northbound node for all YANG schema nodes. | |
469 | */ | |
470 | void nb_nodes_create(void); | |
471 | ||
472 | /* | |
473 | * Delete all northbound nodes from all YANG schema nodes. | |
474 | */ | |
475 | void nb_nodes_delete(void); | |
476 | ||
477 | /* | |
478 | * Find the northbound node corresponding to a YANG data path. | |
479 | * | |
480 | * xpath | |
481 | * XPath to search for (with or without predicates). | |
482 | * | |
483 | * Returns: | |
484 | * Pointer to northbound node if found, NULL otherwise. | |
485 | */ | |
486 | extern struct nb_node *nb_node_find(const char *xpath); | |
487 | ||
488 | /* | |
489 | * Create a new northbound configuration. | |
490 | * | |
491 | * dnode | |
492 | * Pointer to a libyang data node containing the configuration data. If NULL | |
493 | * is given, an empty configuration will be created. | |
494 | * | |
495 | * Returns: | |
496 | * Pointer to newly created northbound configuration. | |
497 | */ | |
498 | extern struct nb_config *nb_config_new(struct lyd_node *dnode); | |
499 | ||
500 | /* | |
501 | * Delete a northbound configuration. | |
502 | * | |
503 | * config | |
504 | * Pointer to the config that is going to be deleted. | |
505 | */ | |
506 | extern void nb_config_free(struct nb_config *config); | |
507 | ||
508 | /* | |
509 | * Duplicate a northbound configuration. | |
510 | * | |
511 | * config | |
512 | * Northbound configuration to duplicate. | |
513 | * | |
514 | * Returns: | |
515 | * Pointer to duplicated configuration. | |
516 | */ | |
517 | extern struct nb_config *nb_config_dup(const struct nb_config *config); | |
518 | ||
519 | /* | |
520 | * Merge one configuration into another. | |
521 | * | |
522 | * config_dst | |
523 | * Configuration to merge to. | |
524 | * | |
525 | * config_src | |
526 | * Configuration to merge config_dst with. | |
527 | * | |
528 | * preserve_source | |
529 | * Specify whether config_src should be deleted or not after the merge | |
530 | * operation. | |
531 | * | |
532 | * Returns: | |
533 | * NB_OK on success, NB_ERR otherwise. | |
534 | */ | |
535 | extern int nb_config_merge(struct nb_config *config_dst, | |
536 | struct nb_config *config_src, bool preserve_source); | |
537 | ||
538 | /* | |
539 | * Replace one configuration by another. | |
540 | * | |
541 | * config_dst | |
542 | * Configuration to be replaced. | |
543 | * | |
544 | * config_src | |
545 | * Configuration to replace config_dst. | |
546 | * | |
547 | * preserve_source | |
548 | * Specify whether config_src should be deleted or not after the replace | |
549 | * operation. | |
550 | */ | |
551 | extern void nb_config_replace(struct nb_config *config_dst, | |
552 | struct nb_config *config_src, | |
553 | bool preserve_source); | |
554 | ||
555 | /* | |
556 | * Edit a candidate configuration. | |
557 | * | |
558 | * candidate | |
559 | * Candidate configuration to edit. | |
560 | * | |
561 | * nb_node | |
562 | * Northbound node associated to the configuration being edited. | |
563 | * | |
564 | * operation | |
565 | * Operation to apply. | |
566 | * | |
567 | * xpath | |
568 | * XPath of the configuration node being edited. | |
569 | * | |
570 | * previous | |
571 | * Previous value of the configuration node. Should be used only when the | |
572 | * operation is NB_OP_MOVE, otherwise this parameter is ignored. | |
573 | * | |
574 | * data | |
575 | * New value of the configuration node. | |
576 | * | |
577 | * Returns: | |
578 | * - NB_OK on success. | |
579 | * - NB_ERR_NOT_FOUND when the element to be deleted was not found. | |
580 | * - NB_ERR for other errors. | |
581 | */ | |
582 | extern int nb_candidate_edit(struct nb_config *candidate, | |
583 | const struct nb_node *nb_node, | |
584 | enum nb_operation operation, const char *xpath, | |
585 | const struct yang_data *previous, | |
586 | const struct yang_data *data); | |
587 | ||
588 | /* | |
589 | * Check if a candidate configuration is outdated and needs to be updated. | |
590 | * | |
591 | * candidate | |
592 | * Candidate configuration to check. | |
593 | * | |
594 | * Returns: | |
595 | * true if the candidate is outdated, false otherwise. | |
596 | */ | |
597 | extern bool nb_candidate_needs_update(const struct nb_config *candidate); | |
598 | ||
599 | /* | |
600 | * Update a candidate configuration by rebasing the changes on top of the latest | |
601 | * running configuration. Resolve conflicts automatically by giving preference | |
602 | * to the changes done in the candidate configuration. | |
603 | * | |
604 | * candidate | |
605 | * Candidate configuration to update. | |
606 | * | |
607 | * Returns: | |
608 | * NB_OK on success, NB_ERR otherwise. | |
609 | */ | |
610 | extern int nb_candidate_update(struct nb_config *candidate); | |
611 | ||
612 | /* | |
613 | * Validate a candidate configuration. Perform both YANG syntactic/semantic | |
614 | * validation and code-level validation using the northbound callbacks. | |
615 | * | |
616 | * WARNING: the candidate can be modified as part of the validation process | |
617 | * (e.g. add default nodes). | |
618 | * | |
619 | * candidate | |
620 | * Candidate configuration to validate. | |
621 | * | |
622 | * Returns: | |
623 | * NB_OK on success, NB_ERR_VALIDATION otherwise. | |
624 | */ | |
625 | extern int nb_candidate_validate(struct nb_config *candidate); | |
626 | ||
627 | /* | |
628 | * Create a new configuration transaction but do not commit it yet. Only | |
629 | * validate the candidate and prepare all resources required to apply the | |
630 | * configuration changes. | |
631 | * | |
632 | * candidate | |
633 | * Candidate configuration to commit. | |
634 | * | |
635 | * client | |
636 | * Northbound client performing the commit. | |
637 | * | |
638 | * comment | |
639 | * Optional comment describing the commit. | |
640 | * | |
641 | * transaction | |
642 | * Output parameter providing the created transaction when one is created | |
643 | * successfully. In this case, it must be either aborted using | |
644 | * nb_candidate_commit_abort() or committed using | |
645 | * nb_candidate_commit_apply(). | |
646 | * | |
647 | * Returns: | |
648 | * - NB_OK on success. | |
649 | * - NB_ERR_NO_CHANGES when the candidate is identical to the running | |
650 | * configuration. | |
651 | * - NB_ERR_LOCKED when there's already another transaction in progress. | |
652 | * - NB_ERR_VALIDATION when the candidate fails the validation checks. | |
653 | * - NB_ERR_RESOURCE when the system fails to allocate resources to apply | |
654 | * the candidate configuration. | |
655 | * - NB_ERR for other errors. | |
656 | */ | |
657 | extern int nb_candidate_commit_prepare(struct nb_config *candidate, | |
658 | enum nb_client client, | |
659 | const char *comment, | |
660 | struct nb_transaction **transaction); | |
661 | ||
662 | /* | |
663 | * Abort a previously created configuration transaction, releasing all resources | |
664 | * allocated during the preparation phase. | |
665 | * | |
666 | * transaction | |
667 | * Candidate configuration to abort. It's consumed by this function. | |
668 | */ | |
669 | extern void nb_candidate_commit_abort(struct nb_transaction *transaction); | |
670 | ||
671 | /* | |
672 | * Commit a previously created configuration transaction. | |
673 | * | |
674 | * transaction | |
675 | * Configuration transaction to commit. It's consumed by this function. | |
676 | * | |
677 | * save_transaction | |
678 | * Specify whether the transaction should be recorded in the transactions log | |
679 | * or not. | |
680 | * | |
681 | * transaction_id | |
682 | * Optional output parameter providing the ID of the committed transaction. | |
683 | */ | |
684 | extern void nb_candidate_commit_apply(struct nb_transaction *transaction, | |
685 | bool save_transaction, | |
686 | uint32_t *transaction_id); | |
687 | ||
688 | /* | |
689 | * Create a new transaction to commit a candidate configuration. This is a | |
690 | * convenience function that performs the two-phase commit protocol | |
691 | * transparently to the user. The cost is reduced flexibility, since | |
692 | * network-wide and multi-daemon transactions require the network manager to | |
693 | * take into account the results of the preparation phase of multiple managed | |
694 | * entities. | |
695 | * | |
696 | * candidate | |
697 | * Candidate configuration to commit. It's preserved regardless if the commit | |
698 | * operation fails or not. | |
699 | * | |
700 | * client | |
701 | * Northbound client performing the commit. | |
702 | * | |
703 | * save_transaction | |
704 | * Specify whether the transaction should be recorded in the transactions log | |
705 | * or not. | |
706 | * | |
707 | * comment | |
708 | * Optional comment describing the commit. | |
709 | * | |
710 | * transaction_id | |
711 | * Optional output parameter providing the ID of the committed transaction. | |
712 | * | |
713 | * Returns: | |
714 | * - NB_OK on success. | |
715 | * - NB_ERR_NO_CHANGES when the candidate is identical to the running | |
716 | * configuration. | |
717 | * - NB_ERR_LOCKED when there's already another transaction in progress. | |
718 | * - NB_ERR_VALIDATION when the candidate fails the validation checks. | |
719 | * - NB_ERR_RESOURCE when the system fails to allocate resources to apply | |
720 | * the candidate configuration. | |
721 | * - NB_ERR for other errors. | |
722 | */ | |
723 | extern int nb_candidate_commit(struct nb_config *candidate, | |
724 | enum nb_client client, bool save_transaction, | |
725 | const char *comment, uint32_t *transaction_id); | |
726 | ||
727 | /* | |
728 | * Iterate over operetional data. | |
729 | * | |
730 | * xpath | |
731 | * Data path of the YANG data we want to iterate over. | |
732 | * | |
733 | * translator | |
734 | * YANG module translator (might be NULL). | |
735 | * | |
736 | * flags | |
737 | * NB_OPER_DATA_ITER_ flags to control how the iteration is performed. | |
738 | * | |
739 | * cb | |
740 | * Function to call with each data node. | |
741 | * | |
742 | * arg | |
743 | * Arbitrary argument passed as the fourth parameter in each call to 'cb'. | |
744 | * | |
745 | * Returns: | |
746 | * NB_OK on success, NB_ERR otherwise. | |
747 | */ | |
748 | extern int nb_oper_data_iterate(const char *xpath, | |
749 | struct yang_translator *translator, | |
750 | uint32_t flags, nb_oper_data_cb cb, void *arg); | |
751 | ||
752 | /* | |
753 | * Validate if the northbound operation is valid for the given node. | |
754 | * | |
755 | * operation | |
756 | * Operation we want to check. | |
757 | * | |
758 | * snode | |
759 | * libyang schema node we want to check. | |
760 | * | |
761 | * Returns: | |
762 | * true if the operation is valid, false otherwise. | |
763 | */ | |
764 | extern bool nb_operation_is_valid(enum nb_operation operation, | |
765 | const struct lys_node *snode); | |
766 | ||
767 | /* | |
768 | * Send a YANG notification. This is a no-op unless the 'nb_notification_send' | |
769 | * hook was registered by a northbound plugin. | |
770 | * | |
771 | * xpath | |
772 | * XPath of the YANG notification. | |
773 | * | |
774 | * arguments | |
775 | * Linked list containing the arguments that should be sent. This list is | |
776 | * deleted after being used. | |
777 | * | |
778 | * Returns: | |
779 | * NB_OK on success, NB_ERR otherwise. | |
780 | */ | |
781 | extern int nb_notification_send(const char *xpath, struct list *arguments); | |
782 | ||
783 | /* | |
784 | * Return a human-readable string representing a northbound event. | |
785 | * | |
786 | * event | |
787 | * Northbound event. | |
788 | * | |
789 | * Returns: | |
790 | * String representation of the given northbound event. | |
791 | */ | |
792 | extern const char *nb_event_name(enum nb_event event); | |
793 | ||
794 | /* | |
795 | * Return a human-readable string representing a northbound operation. | |
796 | * | |
797 | * operation | |
798 | * Northbound operation. | |
799 | * | |
800 | * Returns: | |
801 | * String representation of the given northbound operation. | |
802 | */ | |
803 | extern const char *nb_operation_name(enum nb_operation operation); | |
804 | ||
805 | /* | |
806 | * Return a human-readable string representing a northbound error. | |
807 | * | |
808 | * error | |
809 | * Northbound error. | |
810 | * | |
811 | * Returns: | |
812 | * String representation of the given northbound error. | |
813 | */ | |
814 | extern const char *nb_err_name(enum nb_error error); | |
815 | ||
816 | /* | |
817 | * Return a human-readable string representing a northbound client. | |
818 | * | |
819 | * client | |
820 | * Northbound client. | |
821 | * | |
822 | * Returns: | |
823 | * String representation of the given northbound client. | |
824 | */ | |
825 | extern const char *nb_client_name(enum nb_client client); | |
826 | ||
827 | /* | |
828 | * Initialize the northbound layer. Should be called only once during the | |
829 | * daemon initialization process. | |
830 | * | |
831 | * modules | |
832 | * Array of YANG modules to parse and initialize. | |
833 | * | |
834 | * nmodules | |
835 | * Size of the modules array. | |
836 | */ | |
837 | extern void nb_init(struct thread_master *tm, const struct frr_yang_module_info *modules[], | |
838 | size_t nmodules); | |
839 | ||
840 | /* | |
841 | * Finish the northbound layer gracefully. Should be called only when the daemon | |
842 | * is exiting. | |
843 | */ | |
844 | extern void nb_terminate(void); | |
845 | ||
846 | #ifdef __cplusplus | |
847 | } | |
848 | #endif | |
849 | ||
850 | #endif /* _FRR_NORTHBOUND_H_ */ |