diff options
| author | Russ White <russ@riw.us> | 2018-11-29 15:19:38 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-29 15:19:38 -0500 |
| commit | 9f7b49e1057b2a950240813bf538e46b4f1566c4 (patch) | |
| tree | e429cd55fb72ad7573194686de10d0dd70baee56 /lib/yang_translator.c | |
| parent | c4affc7bc0204ac6da2d931dc4385c3189173542 (diff) | |
| parent | 9c47203310828d015de45eceabce074133220435 (diff) | |
Merge pull request #3342 from opensourcerouting/nb-operational-data
Northbound: improved support for YANG-modeled operational data
Diffstat (limited to 'lib/yang_translator.c')
| -rw-r--r-- | lib/yang_translator.c | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/lib/yang_translator.c b/lib/yang_translator.c index 02da3ebd6a..c3092e56e5 100644 --- a/lib/yang_translator.c +++ b/lib/yang_translator.c @@ -351,7 +351,7 @@ int yang_translate_dnode(const struct yang_translator *translator, int dir, ly_ctx = ly_native_ctx; else ly_ctx = translator->ly_ctx; - new = yang_dnode_new(ly_ctx); + new = yang_dnode_new(ly_ctx, false); /* Iterate over all nodes from the data tree. */ LY_TREE_FOR (*dnode, root) { @@ -400,24 +400,28 @@ error: return YANG_TRANSLATE_FAILURE; } -static void yang_translator_validate_cb(const struct lys_node *snode_custom, - void *arg1, void *arg2) +struct translator_validate_args { + struct yang_translator *translator; + unsigned int errors; +}; + +static int yang_translator_validate_cb(const struct lys_node *snode_custom, + void *arg) { - struct yang_translator *translator = arg1; - unsigned int *errors = arg2; + struct translator_validate_args *args = arg; struct yang_mapping_node *mapping; const struct lys_node *snode_native; const struct lys_type *stype_custom, *stype_native; char xpath[XPATH_MAXLEN]; yang_snode_get_path(snode_custom, YANG_PATH_DATA, xpath, sizeof(xpath)); - mapping = yang_mapping_lookup(translator, YANG_TRANSLATE_TO_NATIVE, - xpath); + mapping = yang_mapping_lookup(args->translator, + YANG_TRANSLATE_TO_NATIVE, xpath); if (!mapping) { flog_warn(EC_LIB_YANG_TRANSLATOR_LOAD, "%s: missing mapping for \"%s\"", __func__, xpath); - *errors += 1; - return; + args->errors += 1; + return YANG_ITER_CONTINUE; } snode_native = @@ -433,12 +437,14 @@ static void yang_translator_validate_cb(const struct lys_node *snode_custom, EC_LIB_YANG_TRANSLATOR_LOAD, "%s: YANG types are incompatible (xpath: \"%s\")", __func__, xpath); - *errors += 1; - return; + args->errors += 1; + return YANG_ITER_CONTINUE; } /* TODO: check if the value spaces are identical. */ } + + return YANG_ITER_CONTINUE; } /* @@ -449,32 +455,36 @@ static unsigned int yang_translator_validate(struct yang_translator *translator) { struct yang_tmodule *tmodule; struct listnode *ln; - unsigned int errors = 0; + struct translator_validate_args args; + + args.translator = translator; + args.errors = 0; for (ALL_LIST_ELEMENTS_RO(translator->modules, ln, tmodule)) { - yang_module_snodes_iterate( + yang_snodes_iterate_module( tmodule->module, yang_translator_validate_cb, YANG_ITER_FILTER_NPCONTAINERS | YANG_ITER_FILTER_LIST_KEYS | YANG_ITER_FILTER_INPUT_OUTPUT, - translator, &errors); + &args); } - if (errors) + if (args.errors) flog_warn( EC_LIB_YANG_TRANSLATOR_LOAD, "%s: failed to validate \"%s\" module translator: %u error(s)", - __func__, translator->family, errors); + __func__, translator->family, args.errors); - return errors; + return args.errors; } -static void yang_module_nodes_count_cb(const struct lys_node *snode, void *arg1, - void *arg2) +static int yang_module_nodes_count_cb(const struct lys_node *snode, void *arg) { - unsigned int *total = arg1; + unsigned int *total = arg; *total += 1; + + return YANG_ITER_CONTINUE; } /* Calculate the number of nodes for the given module. */ @@ -482,11 +492,11 @@ static unsigned int yang_module_nodes_count(const struct lys_module *module) { unsigned int total = 0; - yang_module_snodes_iterate(module, yang_module_nodes_count_cb, + yang_snodes_iterate_module(module, yang_module_nodes_count_cb, YANG_ITER_FILTER_NPCONTAINERS | YANG_ITER_FILTER_LIST_KEYS | YANG_ITER_FILTER_INPUT_OUTPUT, - &total, NULL); + &total); return total; } |
