struct nb_transaction *transaction);
static void nb_transaction_apply_finish(struct nb_transaction *transaction);
+static int nb_node_check_config_only(const struct lys_node *snode, void *arg)
+{
+ bool *config_only = arg;
+
+ if (CHECK_FLAG(snode->flags, LYS_CONFIG_R)) {
+ *config_only = false;
+ return YANG_ITER_STOP;
+ }
+
+ return YANG_ITER_CONTINUE;
+}
+
static int nb_node_new_cb(const struct lys_node *snode, void *arg)
{
struct nb_node *nb_node;
if (sparent_list)
nb_node->parent_list = sparent_list->priv;
+ /* Set flags. */
+ if (CHECK_FLAG(snode->nodetype, LYS_CONTAINER | LYS_LIST)) {
+ bool config_only = true;
+
+ yang_snodes_iterate_subtree(snode, nb_node_check_config_only,
+ YANG_ITER_ALLOW_AUGMENTATIONS,
+ &config_only);
+ if (config_only)
+ SET_FLAG(nb_node->flags, F_NB_NODE_CONFIG_ONLY);
+ }
+
/*
* Link the northbound node and the libyang schema node with one
* another.
return YANG_ITER_CONTINUE;
}
+void nb_nodes_create(void)
+{
+ yang_snodes_iterate_all(nb_node_new_cb, 0, NULL);
+}
+
+void nb_nodes_delete(void)
+{
+ yang_snodes_iterate_all(nb_node_del_cb, 0, NULL);
+}
+
struct nb_node *nb_node_find(const char *xpath)
{
const struct lys_node *snode;
bool nb_operation_is_valid(enum nb_operation operation,
const struct lys_node *snode)
{
+ struct nb_node *nb_node = snode->priv;
struct lys_node_container *scontainer;
struct lys_node_leaf *sleaf;
case NB_OP_GET_NEXT:
case NB_OP_GET_KEYS:
case NB_OP_LOOKUP_ENTRY:
- if (!CHECK_FLAG(snode->flags, LYS_CONFIG_R))
- return false;
-
switch (snode->nodetype) {
case LYS_LIST:
+ if (CHECK_FLAG(nb_node->flags, F_NB_NODE_CONFIG_ONLY))
+ return false;
break;
default:
return false;
yang_module_load(modules[i]->name);
/* Create a nb_node for all YANG schema nodes. */
- yang_snodes_iterate_all(nb_node_new_cb, 0, NULL);
+ nb_nodes_create();
/* Load northbound callbacks. */
for (size_t i = 0; i < nmodules; i++)
nb_cli_terminate();
/* Delete all nb_node's from all YANG modules. */
- yang_snodes_iterate_all(nb_node_del_cb, 0, NULL);
+ nb_nodes_delete();
/* Delete the running configuration. */
nb_config_free(running_config);
/* Pointer to the nearest parent list, if any. */
struct nb_node *parent_list;
+ /* Flags. */
+ uint8_t flags;
+
#ifdef HAVE_CONFD
/* ConfD hash value corresponding to this YANG path. */
int confd_hash;
#endif
};
+/* The YANG container or list contains only config data. */
+#define F_NB_NODE_CONFIG_ONLY 0x01
struct frr_yang_module_info {
/* YANG module name. */
extern int debug_northbound;
extern struct nb_config *running_config;
+/*
+ * Create a northbound node for all YANG schema nodes.
+ */
+void nb_nodes_create(void);
+
+/*
+ * Delete all northbound nodes from all YANG schema nodes.
+ */
+void nb_nodes_delete(void);
+
/*
* Find the northbound node corresponding to a YANG data path.
*
yang_init();
- /* Load YANG module. */
- module = yang_module_load(argv[0]);
+ /* Load all FRR native models to ensure all augmentations are loaded. */
+ yang_module_load_all();
+ module = yang_module_find(argv[0]);
+ if (!module)
+ /* Non-native FRR module (e.g. modules from unit tests). */
+ module = yang_module_load(argv[0]);
+
+ /* Create a nb_node for all YANG schema nodes. */
+ nb_nodes_create();
/* Generate callback functions. */
yang_snodes_iterate_module(module->info, generate_callbacks, 0, NULL);
"};\n");
/* Cleanup and exit. */
+ nb_nodes_delete();
yang_terminate();
return 0;