summaryrefslogtreecommitdiffstats
path: root/lib/northbound.h
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2018-11-03 01:16:55 +0100
committerRenato Westphal <renato@opensourcerouting.org>2018-11-26 21:28:53 +0100
commit1a4bc045deac52e5c0b66d151dbbce8cc3675497 (patch)
treefa244f4c2f65da6f20bc8b44dd78315483e47bce /lib/northbound.h
parentlib: do not subscribe to config changes on a state data tree (confd plugin) (diff)
downloadfrr-1a4bc045deac52e5c0b66d151dbbce8cc3675497.tar.xz
frr-1a4bc045deac52e5c0b66d151dbbce8cc3675497.zip
lib, tests: major rework in the operational-data callbacks
The northbound infrastructure for operational data was subpar compared to the infrastructure for configuration data. This commit addresses most of the existing problems, making it possible to write operational-data callbacks for more complex YANG models. Summary of the changes: * Add support for nested YANG lists. * Add support for leaf-lists. * Add support for leafs of type "empty". * Introduce the "show yang operational-data XPATH" command, and write an unit test for it. The main purpose of this command is to make it easier to test the operational-data northbound callbacks. * Introduce the nb_oper_data_iterate() function, that can be used to iterate over operational data. Make the CLI and sysrepo use this function. * Since ConfD has a very peculiar API, it can't reuse the nb_oper_data_iterate() like the other northbound clients. In this case, adapt the existing ConfD callbacks to support the new features (and make some performance improvements in the process). Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/northbound.h')
-rw-r--r--lib/northbound.h70
1 files changed, 55 insertions, 15 deletions
diff --git a/lib/northbound.h b/lib/northbound.h
index 68bce5b39..e26a2f861 100644
--- a/lib/northbound.h
+++ b/lib/northbound.h
@@ -21,9 +21,10 @@
#define _FRR_NORTHBOUND_H_
#include "hook.h"
-#include "yang.h"
#include "linklist.h"
#include "openbsd-tree.h"
+#include "yang.h"
+#include "yang_translator.h"
/* Forward declaration(s). */
struct vty;
@@ -211,15 +212,15 @@ struct nb_callbacks {
/*
* Operational data callback.
*
- * The callback function should return the value of a specific leaf or
- * inform if a typeless value (presence containers or leafs of type
- * empty) exists or not.
+ * The callback function should return the value of a specific leaf,
+ * leaf-list entry or inform if a typeless value (presence containers or
+ * leafs of type empty) exists or not.
*
* xpath
* YANG data path of the data we want to get.
*
* list_entry
- * Pointer to list entry.
+ * Pointer to list entry (might be NULL).
*
* Returns:
* Pointer to newly created yang_data structure, or NULL to indicate
@@ -229,22 +230,24 @@ struct nb_callbacks {
const void *list_entry);
/*
- * Operational data callback for YANG lists.
+ * Operational data callback for YANG lists and leaf-lists.
*
- * The callback function should return the next entry in the list. The
- * 'list_entry' parameter will be NULL on the first invocation.
+ * The callback function should return the next entry in the list or
+ * leaf-list. The 'list_entry' parameter will be NULL on the first
+ * invocation.
*
- * xpath
- * Data path of the YANG list.
+ * parent_list_entry
+ * Pointer to parent list entry.
*
* list_entry
- * Pointer to list entry.
+ * Pointer to (leaf-)list entry.
*
* Returns:
- * Pointer to the next entry in the list, or NULL to signal that the
- * end of the list was reached.
+ * Pointer to the next entry in the (leaf-)list, or NULL to signal
+ * that the end of the (leaf-)list was reached.
*/
- const void *(*get_next)(const char *xpath, const void *list_entry);
+ const void *(*get_next)(const void *parent_list_entry,
+ const void *list_entry);
/*
* Operational data callback for YANG lists.
@@ -270,13 +273,17 @@ struct nb_callbacks {
* The callback function should return a list entry based on the list
* keys given as a parameter.
*
+ * parent_list_entry
+ * Pointer to parent list entry.
+ *
* keys
* Structure containing the keys of the list entry.
*
* Returns:
* Pointer to the list entry if found, or NULL if not found.
*/
- const void *(*lookup_entry)(const struct yang_list_keys *keys);
+ const void *(*lookup_entry)(const void *parent_list_entry,
+ const struct yang_list_keys *keys);
/*
* RPC and action callback.
@@ -434,6 +441,14 @@ struct nb_transaction {
struct nb_config_cbs changes;
};
+/* Callback function used by nb_oper_data_iterate(). */
+typedef int (*nb_oper_data_cb)(const struct lys_node *snode,
+ struct yang_translator *translator,
+ struct yang_data *data, void *arg);
+
+/* Iterate over direct child nodes only. */
+#define NB_OPER_DATA_ITER_NORECURSE 0x0001
+
DECLARE_HOOK(nb_notification_send, (const char *xpath, struct list *arguments),
(xpath, arguments))
@@ -701,6 +716,31 @@ extern int nb_candidate_commit(struct nb_config *candidate,
const char *comment, uint32_t *transaction_id);
/*
+ * Iterate over operetional data.
+ *
+ * xpath
+ * Data path of the YANG data we want to iterate over.
+ *
+ * translator
+ * YANG module translator (might be NULL).
+ *
+ * flags
+ * NB_OPER_DATA_ITER_ flags to control how the iteration is performed.
+ *
+ * cb
+ * Function to call with each data node.
+ *
+ * arg
+ * Arbitrary argument passed as the fourth parameter in each call to 'cb'.
+ *
+ * Returns:
+ * NB_OK on success, NB_ERR otherwise.
+ */
+extern int nb_oper_data_iterate(const char *xpath,
+ struct yang_translator *translator,
+ uint32_t flags, nb_oper_data_cb cb, void *arg);
+
+/*
* Validate if the northbound operation is valid for the given node.
*
* operation