diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index f253d463..f0eb57ae 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -416,7 +416,7 @@ clixon_stats_datastore_get(clixon_handle h, return retval; } -/*! Get clixon per datastore stats +/*! Get clixon per yang-spec stats * * @param[in] h Clixon handle * @param[in] dbname Datastore name @@ -1462,13 +1462,13 @@ from_client_stats(clixon_handle h, while ((ydomain = yn_iter(ymounts, &inext)) != NULL) { domain = yang_argument_get(ydomain); /* per module-set, first configuration, then main dbspec, then mountpoints */ - cprintf(cbret, ""); - cprintf(cbret, "%s", domain); - if (clixon_stats_module_get(h, ydomain, cbret) < 0) - goto done; - if (modules){ - inext2 = 0; - while ((yspec = yn_iter(ydomain, &inext2)) != NULL) { + inext2 = 0; + while ((yspec = yn_iter(ydomain, &inext2)) != NULL) { + cprintf(cbret, ""); + cprintf(cbret, "%s/%s", domain, yang_argument_get(yspec)); + if (clixon_stats_module_get(h, ydomain, cbret) < 0) + goto done; + if (modules){ inext3 = 0; while ((ymodule = yn_iter(yspec, &inext3)) != NULL) { cprintf(cbret, "%s", yang_argument_get(ymodule)); @@ -1477,8 +1477,8 @@ from_client_stats(clixon_handle h, cprintf(cbret, ""); } } + cprintf(cbret, ""); } - cprintf(cbret, ""); } cprintf(cbret, ""); cprintf(cbret, ""); diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index 09e5365d..10cb561f 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -1883,10 +1883,10 @@ cli_show_statistics(clixon_handle h, parse_tree *pt; uint64_t nr; uint64_t tnr0; - uint64_t tnr; + uint64_t tnr = 0; size_t sz; size_t tsz0; - size_t tsz; + size_t tsz = 0; yang_stmt *ymounts; yang_stmt *ydomain; yang_stmt *yspec; @@ -1946,10 +1946,10 @@ cli_show_statistics(clixon_handle h, while ((yspec = yn_iter(ydomain, &inext2)) != NULL) { name = yang_argument_get(yspec); nr = 0; sz = 0; - if (yang_stats(ydomain, 0, &nr, &sz) < 0) + if (yang_stats(yspec, 0, &nr, &sz) < 0) goto done; - tnr = nr; - tsz = sz; + tnr += nr; + tsz += sz; if (detail) { cligen_output(stdout, "YANG-%s-%s-size: %" PRIu64 "\n", domain, name, sz); cligen_output(stdout, "YANG-%s-%s-nr: %" PRIu64 "\n", domain, name, nr); @@ -1963,8 +1963,8 @@ cli_show_statistics(clixon_handle h, } } if (detail){ - cligen_output(stdout, "YANG-total-size: %" PRIu64 "\n", sz); - cligen_output(stdout, "YANG-total-nr: %" PRIu64 "\n", sz); + cligen_output(stdout, "YANG-total-size: %" PRIu64 "\n", tsz); + cligen_output(stdout, "YANG-total-nr: %" PRIu64 "\n", tnr); } else { translatenumber(tsz, &u64, &unit); diff --git a/lib/clixon/clixon_yang.h b/lib/clixon/clixon_yang.h index 2e3ed866..b9ce42c4 100644 --- a/lib/clixon/clixon_yang.h +++ b/lib/clixon/clixon_yang.h @@ -289,7 +289,7 @@ int yang_stats(yang_stmt *y, enum rfc_6020 keyw, uint64_t *nrp, size_t *s /* Other functions */ yang_stmt *yspec_new(clixon_handle h, char *name); yang_stmt *yspec_new1(clixon_handle h, char *domain, char *name); -yang_stmt *yspec_new_shared(clixon_handle h, char *name, char *domain, yang_stmt *yspec0); +yang_stmt *yspec_new_shared(clixon_handle h, char *xpath, char *domain, char *name, yang_stmt *yspec0); yang_stmt *ydomain_new(clixon_handle h, char *domain); yang_stmt *ys_new(enum rfc_6020 keyw); yang_stmt *ys_prune(yang_stmt *yp, int i); diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index c18ac665..c9fdab3f 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -886,44 +886,38 @@ yspec_new1(clixon_handle h, /*! Create or add a shared yspec * - * @param[in] h Clixon handle - * @param[in] tag Typically an xpath, saved in cvec - * @param[in] yspec0 Input NULL if no previous shared exist, otherwise a shared yspec but new name - * @retval yspec1 New or (previously shared) - * @retval NULL Error + * @param[in] h Clixon handle + * @param[in] xpath Mount xpath, saved in cvec + * @param[in] domain YANG domain + * @param[in] domain YANG spec name + * @param[in] yspec0 Input NULL if no previous shared exist, otherwise a shared yspec but new name + * @retval yspec1 New or (previously shared) + * @retval NULL Error * @note yspec name used by concatenating domain and a unique number. */ yang_stmt * yspec_new_shared(clixon_handle h, - char *tag, + char *xpath, char *domain, + char *name, yang_stmt *yspec0) { yang_stmt *yspec1 = NULL; - cbuf *cb = NULL; - static int nr = 0; if (yspec0 != NULL){ /* shared */ yspec1 = yspec0; } else { - if ((cb = cbuf_new()) == NULL){ - clixon_err(OE_YANG, errno, "cbuf_new"); - goto done; - } - cprintf(cb, "%s%d", domain, nr++); - if ((yspec1 = yspec_new1(h, domain, cbuf_get(cb))) == NULL) + if ((yspec1 = yspec_new1(h, domain, name)) == NULL) goto done; yang_flag_set(yspec1, YANG_FLAG_SPEC_MOUNT); clixon_debug(CLIXON_DBG_YANG, "new yang-spec: %p", yspec1); } - if (yang_cvec_add(yspec1, CGV_STRING, tag) < 0){ + if (yang_cvec_add(yspec1, CGV_STRING, xpath) < 0){ yspec1 = NULL; goto done; } done: - if (cb) - cbuf_free(cb); return yspec1; } diff --git a/lib/src/clixon_yang_schema_mount.c b/lib/src/clixon_yang_schema_mount.c index 5c47a49c..3039a421 100644 --- a/lib/src/clixon_yang_schema_mount.c +++ b/lib/src/clixon_yang_schema_mount.c @@ -784,7 +784,9 @@ yang_schema_yanglib_parse_mount(clixon_handle h, yang_stmt *yspec1 = NULL; char *xpath = NULL; char *domain = NULL; + cbuf *cb = NULL; int ret; + static unsigned int nr = 0; /* 1. Get modstate (xyanglib) of node: xyanglib, by querying backend state (via callback) * XXX this xyanglib is not proper RFC8525, submodules appear as modules WHY? @@ -819,7 +821,12 @@ yang_schema_yanglib_parse_mount(clixon_handle h, if (yang_schema_find_share(h, xt, xyanglib, &yspec0) < 0) goto done; } - if ((yspec1 = yspec_new_shared(h, xpath, domain, yspec0)) < 0) + if ((cb = cbuf_new()) == NULL){ + clixon_err(OE_YANG, errno, "cbuf_new"); + goto done; + } + cprintf(cb, "%u", nr++); + if ((yspec1 = yspec_new_shared(h, xpath, domain, cbuf_get(cb), yspec0)) < 0) goto done; /* Either yspec0 = NULL and yspec1 is new, or yspec0 == yspec1 != NULL (shared) */ if (yspec0 == NULL && yspec1 != NULL){ @@ -835,6 +842,8 @@ yang_schema_yanglib_parse_mount(clixon_handle h, yspec1 = NULL; retval = 1; done: + if (cb) + cbuf_free(cb); if (xpath) free(xpath); if (yspec1) diff --git a/test/test_yang_mount_schema.sh b/test/test_yang_mount_schema.sh index f972beab..4a9b873f 100755 --- a/test/test_yang_mount_schema.sh +++ b/test/test_yang_mount_schema.sh @@ -218,7 +218,7 @@ new "get yang-lib at mountpoint" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" ">" "xmylabelclixon-mount0urn:example:mount0ymylabelclixon-mount0urn:example:mount0" new "check there is statistics from mountpoint" -expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "mylabel" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "mylabel/0" new "Add data to mounts" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "xx1" "" ""