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