From f87ff859a6dcdf5903ef9b20b66a92f7269c7604 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Wed, 16 Oct 2024 10:32:37 +0200 Subject: [PATCH] Removed `list-pagination-partial-state` extension Refactored pagination code Reverted clixon-lib.yang to 2024-04-01 revision --- CHANGELOG.md | 2 - apps/backend/backend_get.c | 222 +++++----- apps/backend/backend_plugin.c | 36 -- apps/backend/clixon_backend_plugin.h | 6 +- apps/restconf/clixon_restconf.h | 2 +- apps/restconf/restconf_lib.c | 2 +- apps/restconf/restconf_lib.h | 2 +- lib/clixon/clixon_dispatcher.h | 21 +- lib/src/clixon_dispatcher.c | 196 +++++---- test/config.sh.in | 2 +- test/example_social.sh | 3 +- test/test_pagination_config.sh | 4 +- test/test_pagination_draft.sh | 7 +- test/test_pagination_extra.sh | 4 +- test/test_pagination_state.sh | 6 +- test/test_pattern.sh | 2 +- yang/clixon/Makefile.in | 2 +- yang/clixon/clixon-lib@2024-04-01.yang | 25 +- yang/clixon/clixon-lib@2024-08-01.yang | 541 ------------------------- 19 files changed, 286 insertions(+), 799 deletions(-) delete mode 100644 yang/clixon/clixon-lib@2024-08-01.yang diff --git a/CHANGELOG.md b/CHANGELOG.md index bb7cc4f6..5a13f89e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,8 +38,6 @@ Expected: October 2024 * New `clixon-config@2024-08-01.yang` revision * Added: `CLICON_YANG_DOMAIN_DIR` * Added: `CLICON_YANG_USE_ORIGINAL` -* New `clixon-lib@2024-08-01.yang` revision - - Added: list-pagination-partial-state extension ### API changes on existing protocol/config features diff --git a/apps/backend/backend_get.c b/apps/backend/backend_get.c index b5c634c2..9c04601e 100644 --- a/apps/backend/backend_get.c +++ b/apps/backend/backend_get.c @@ -1,7 +1,7 @@ /* * ***** BEGIN LICENSE BLOCK ***** - + Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren Copyright (C) 2017-2019 Olof Hagsand Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC(Netgate) @@ -25,7 +25,7 @@ in which case the provisions of the GPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of the GPL, and not to allow others to - use your version of this file under the terms of Apache License version 2, + use your version of this file under the terms of Apache License version 2, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under @@ -93,7 +93,7 @@ restconf_client_get_capabilities(clixon_handle h, int retval = -1; cxobj *xrstate = NULL; /* xml restconf-state node */ cbuf *cb = NULL; - + if ((xrstate = xpath_first(*xret, NULL, "restconf-state")) == NULL){ clixon_err(OE_YANG, ENOENT, "restconf-state not found in config node"); goto done; @@ -206,7 +206,7 @@ get_statedata(clixon_handle h, int ret; cbuf *cb = NULL; cxobj *xerr = NULL; - + clixon_debug(CLIXON_DBG_BACKEND, ""); if ((yspec = clicon_dbspec_yang(h)) == NULL){ clixon_err(OE_YANG, ENOENT, "No yang spec"); @@ -271,7 +271,7 @@ get_statedata(clixon_handle h, xerr = NULL; goto fail; } - /* Some state, client state, is avaliable in backend only, not in lib + /* Some state, client state, is avaliable in backend only, not in lib * Needs merge since same subtree as previous lib state */ if ((ret = backend_monitoring_state_get(h, yspec, xpath, nsc, &x1, &xerr)) < 0) @@ -325,16 +325,16 @@ get_statedata(clixon_handle h, goto done; } -/*! Help function to filter out anything that is outside of xpath +/*! Help function to filter out anything that is outside of xpath * - * Code complex to filter out anything that is outside of xpath + * Code complex to filter out anything that is outside of xpath * Actually this is a safety catch, should really be done in plugins * and modules_state functions. * But it is problematic, because defaults, at least of config data, is in place * and we need to re-add it. * Note original xpath * - * @param[in] h Clixon handle + * @param[in] h Clixon handle * @param[in] yspec Yang spec * @param[in] xret Result XML tree * @param[in] xvec xpath lookup result on xret @@ -382,7 +382,7 @@ filter_xpath_again(clixon_handle h, /*! Help function for NACM access and return message * - * @param[in] h Clixon handle + * @param[in] h Clixon handle * @param[in] xret Result XML tree * @param[in] xvec xpath lookup result on xret * @param[in] xlen length of xvec @@ -391,7 +391,7 @@ filter_xpath_again(clixon_handle h, * @param[in] username User name for NACM access * @param[in] depth Nr of levels to print, -1 is all, 0 is none * @param[in] wdef With-defaults parameter - * @param[out] cbret Return xml tree, eg ..., ..., ", NETCONF_BASE_NAMESPACE); /* OK */ @@ -456,7 +456,7 @@ element2value(clixon_handle h, { char *valstr; cxobj *x; - + *value = 0; if ((x = xml_find_type(xe, NULL, name, CX_ELMNT)) != NULL && (valstr = xml_body(x)) != NULL){ @@ -467,11 +467,11 @@ element2value(clixon_handle h, /*! Extract offset and limit from get/list-pagination * - * @param[in] h Clixon handle - * @param[in] xe Request: + * @param[in] h Clixon handle + * @param[in] xe Request: * @param[out] offset Number of entries in the working result-set that should be skipped * @param[out] limit Limits the number of entries returned from the working result-set - * @param[out] cbret Return xml tree, eg ..., ..., ..., ..., ce_id) locked = 1; else locked = 0; - if ((ret = clixon_pagination_cb_call(h, xpath, locked, - offset, limit, - xret)) < 0) - goto done; - if (ret == 0){ - if ((cberr = cbuf_new()) == NULL){ - clixon_err(OE_UNIX, errno, "cbuf_new"); - goto done; + pd.pd_where = where; + pd.pd_sort_by = sort_by; + pd.pd_direction = direction; + pd.pd_offset = offset; + pd.pd_limit = limit; + pd.pd_locked = locked; + pd.pd_xstate = xret; + clicon_ptr_get(h, "pagination-entries", (void**)&htable); + if (htable){ + if (dispatcher_call_handlers(htable, h, xpath, &pd) < 0){ + if ((cberr = cbuf_new()) == NULL){ + clixon_err(OE_UNIX, errno, "cbuf_new"); + goto done; + } + /* error reason should be in clixon_err_reason */ + cprintf(cberr, "Internal error, pagination state callback invalid return : %s", + clixon_err_reason()); + if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0) + goto done; + if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0) + goto done; + goto fail; } - /* error reason should be in clixon_err_reason */ - cprintf(cberr, "Internal error, pagination state callback invalid return : %s", - clixon_err_reason()); - if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0) - goto done; - if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0) - goto done; - goto fail; } /* System makes the binding */ @@ -580,9 +594,9 @@ get_pagination_partial(clixon_handle h, * * It is specialized enough to have its own function. Specifically, extra attributes as well * as the list-paginaiton API - * @param[in] h Clixon handle + * @param[in] h Clixon handle * @param[in] ce Client entry, for locking - * @param[in] xe Request: + * @param[in] xe Request: * @param[in] content Get config/state/both * @param[in] db Database name * @param[in] depth Depth attribute @@ -591,10 +605,10 @@ get_pagination_partial(clixon_handle h, * @param[in] nsc Namespace context of xpath * @param[in] username * @param[in] wdef With-defaults parameter, see RFC 6243 - * @param[out] cbret Return xml tree, eg ..., ..., 0) + partial_pagination_cb = 1; } } - /* first processes the "where" parameter (see Section 3.1.1) */ if ((x = xml_find_type(xe, NULL, "where", CX_ELMNT)) != NULL && (where = xml_body(x)) != NULL){ @@ -749,35 +766,32 @@ get_list_pagination(clixon_handle h, goto done; break; }/* switch content */ - switch (content){ /* Read state */ - case CONTENT_CONFIG: /* config data only */ - break; - case CONTENT_ALL: /* both config and state */ - case CONTENT_NONCONFIG: /* state data only */ - if (partial_pagination_cb) /* Partial reads, special handling */ - break; - if ((ret = get_statedata(h, xpath?xpath:"/", nsc, &xret)) < 0) - goto done; - if (ret == 0){ /* Error from callback (error in xret) */ - if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) - goto done; - goto ok; - } - /* Add defaults to state data. This consumes some cycles */ - /* Ensure all state-data is report-all */ - if (xml_global_defaults(h, xret, nsc, xpath, yspec, 1) < 0) - goto done; - /* Apply default values */ - if (xml_default_recurse(xret, 1, 0) < 0) - goto done; - } if (partial_pagination_cb) { - if ((ret = get_pagination_partial(h, ce, yspec, xpath, offset, limit, xret, cbret)) < 0) + if ((ret = get_pagination_state_partial(h, ce, yspec, xpath, + where, sort_by, direction, + offset, limit, + xret, cbret)) < 0) goto done; if (ret == 0) goto ok; } else { + if (content != CONTENT_CONFIG){ + if ((ret = get_statedata(h, xpath?xpath:"/", nsc, &xret)) < 0) + goto done; + if (ret == 0){ /* Error from callback (error in xret) */ + if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) + goto done; + goto ok; + } + /* Add defaults to state data. This consumes some cycles */ + /* Ensure all state-data is report-all */ + if (xml_global_defaults(h, xret, nsc, xpath, yspec, 1) < 0) + goto done; + /* Apply default values */ + if (xml_default_recurse(xret, 1, 0) < 0) + goto done; + } /* first processes the "where" parameter (see Section 3.1.1) */ if (where){ if (xpath_vec(xret, nsc, "%s[%s]", &xvec, &xlen, xpath?xpath:"/", where) < 0) @@ -864,10 +878,10 @@ get_list_pagination(clixon_handle h, if (filter_xpath_again(h, yspec, xret, xvec, xlen, xpath, nsc) < 0) goto done; #ifdef LIST_PAGINATION_REMAINING - /* Add remaining attribute Sec 3.1.5: - Any list or leaf-list that is limited includes, on the first element in the result set, + /* Add remaining attribute Sec 3.1.5: + Any list or leaf-list that is limited includes, on the first element in the result set, a metadata value [RFC7952] called "remaining"*/ - if (limit && x1){ + if (limit && x1){ cxobj *xa; cbuf *cba = NULL; @@ -901,16 +915,16 @@ get_list_pagination(clixon_handle h, /*! Common get/get-config code for retrieving configuration and state information. * - * @param[in] h Clixon handle + * @param[in] h Clixon handle * @param[in] ce Client entry, for locking - * @param[in] xe Request: + * @param[in] xe Request: * @param[in] content Get config/state/both * @param[in] db Database name - * @param[out] cbret Return xml tree, eg ..., ..., 0 && (ret = xml_yang_validate_add(h, xret, &xerr)) < 0) @@ -1197,8 +1211,8 @@ from_client_get_config(clixon_handle h, return retval; } -/*! Retrieve running configuration and device state information. - * +/*! Retrieve running configuration and device state + * * @param[in] h Clixon handle * @param[in] xe Request: * @param[out] cbret Return xml tree, eg ..., peer_head; + i = node->de_peer_head; while (i != NULL) { - if (strcmp(node_name, i->node_name) == 0) { + if (strcmp(node_name, i->de_node_name) == 0) { break; } - i = i->peer; + i = i->de_peer; } return i; @@ -228,10 +228,10 @@ add_peer_node(dispatcher_entry_t *node, if (node == NULL) { /* this is a new node */ - new_node->node_name = strdup(name); - new_node->peer = NULL; - new_node->children = NULL; - new_node->peer_head = new_node; + new_node->de_node_name = strdup(name); + new_node->de_peer = NULL; + new_node->de_children = NULL; + new_node->de_peer_head = new_node; return new_node; } @@ -239,27 +239,27 @@ add_peer_node(dispatcher_entry_t *node, /* possibly adding to the list */ /* search for existing, or get tail end of list */ - eptr = node->peer_head; - while (eptr->peer != NULL) { - if (strcmp(eptr->node_name, name) == 0) { + eptr = node->de_peer_head; + while (eptr->de_peer != NULL) { + if (strcmp(eptr->de_node_name, name) == 0) { free(new_node); return eptr; } - eptr = eptr->peer; + eptr = eptr->de_peer; } - // if eptr->node_name == name, we done - if (strcmp(eptr->node_name, name) == 0) { + // if eptr->de_node_name == name, we done + if (strcmp(eptr->de_node_name, name) == 0) { free(new_node); return eptr; } - new_node->node_name = strdup(name); - new_node->peer = NULL; - new_node->children = NULL; - new_node->peer_head = node->peer_head; + new_node->de_node_name = strdup(name); + new_node->de_peer = NULL; + new_node->de_children = NULL; + new_node->de_peer_head = node->de_peer_head; - eptr->peer = new_node; + eptr->de_peer = new_node; return new_node; } @@ -282,19 +282,19 @@ add_child_node(dispatcher_entry_t *node, { dispatcher_entry_t *child_ptr; - if ((child_ptr = add_peer_node(node->children, name)) == NULL) + if ((child_ptr = add_peer_node(node->de_children, name)) == NULL) return NULL; - node->children = child_ptr->peer_head; + node->de_children = child_ptr->de_peer_head; return child_ptr; } -/** +/*! * - * @param root - * @param path - * @retval - * @retval NULL Error + * @param[in] root + * @param[in] path + * @retval entry + * @retval NULL Error */ static dispatcher_entry_t * get_entry(dispatcher_entry_t *root, @@ -317,20 +317,19 @@ get_entry(dispatcher_entry_t *root, /* search down the tree */ for (int i = 0; i < split_path_len; i++) { - char *query = split_path_list[i]; if ((ptr = find_peer(ptr, query)) == NULL) { split_path_free(split_path_list, split_path_len); /* we ran out of matches, use last found handler */ return best; } - if (ptr->handler != NULL) { + if (ptr->de_handler != NULL) { /* if handler is defined, save it */ best = ptr; } /* skip to next element */ - ptr = ptr->children; + ptr = ptr->de_children; } /* clean up */ @@ -338,13 +337,14 @@ get_entry(dispatcher_entry_t *root, return best; } -/** - * given a pointer to an entry, call the handler and all - * descendant and peer handlers. +/*! Given a pointer to an entry, call the handler and all descendant and peer handlers. * - * @param entry - * @param path - * @retval + * @param[in] entry + * @param[in] handle + * @param[in] path + * @param[in] user_args + * @retval 0 OK + * @retval -1 Error */ static int call_handler_helper(dispatcher_entry_t *entry, @@ -352,17 +352,23 @@ call_handler_helper(dispatcher_entry_t *entry, char *path, void *user_args) { - if (entry->children != NULL) { - call_handler_helper(entry->children, handle, path, user_args); - } - if (entry->peer != NULL) { - call_handler_helper(entry->peer, handle, path, user_args); - } - if (entry->handler != NULL) { - (entry->handler)(handle, path, user_args, entry->arg); - } + int retval = -1; - return 1; + if (entry->de_children != NULL) { + if (call_handler_helper(entry->de_children, handle, path, user_args) < 0) + goto done; + } + if (entry->de_peer != NULL) { + if (call_handler_helper(entry->de_peer, handle, path, user_args) < 0) + goto done; + } + if (entry->de_handler != NULL) { + if ((entry->de_handler)(handle, path, user_args, entry->de_arg) < 0) + goto done; + } + retval = 0; + done: + return retval; } /* @@ -416,8 +422,8 @@ dispatcher_register_handler(dispatcher_entry_t **root, } /* when we get here, ptr points at last entry added */ - ptr->handler = x->dd_handler; - ptr->arg = x->dd_arg; + ptr->de_handler = x->dd_handler; + ptr->de_arg = x->dd_arg; /* clean up */ split_path_free(split_path_list, split_path_len); @@ -436,8 +442,7 @@ dispatcher_register_handler(dispatcher_entry_t **root, * @param[in] handle * @param[in] root * @param[in] path Note must be on the form: /a/b (no keys) - * @retval 1 OK - * @retval 0 Invalid + * @retval 0 OK * @retval -1 Error */ int @@ -446,20 +451,67 @@ dispatcher_call_handlers(dispatcher_entry_t *root, char *path, void *user_args) { - int ret = 0; + int retval = -1; dispatcher_entry_t *best; if ((best = get_entry(root, path)) == NULL){ errno = ENOENT; - return -1; + goto done; } - if (best->children != NULL) { - call_handler_helper(best->children, handle, path, user_args); + if (best->de_children != NULL) { + if (call_handler_helper(best->de_children, handle, path, user_args) < 0) + goto done; } - if (best->handler != NULL) { - ret = (*best->handler)(handle, path, user_args, best->arg); + if (best->de_handler != NULL) { + if ((*best->de_handler)(handle, path, user_args, best->de_arg) < 0) + goto done; } - return ret; + retval = 0; + done: + return retval; +} + +/*! Check if any handler is registered for the path + * @param[in] root + * @param[in] path Note must be on the form: /a/b (no keys) + * @retval 1 Yes, at least one handler + * @retval 0 No handler + * @retval -1 Error + */ +int +dispatcher_match_exact(dispatcher_entry_t *root, + char *path) +{ + int retval = -1; + dispatcher_entry_t *ptr; + dispatcher_entry_t *ptr1 = NULL; + char **split_path_list = NULL; + size_t split_path_len = 0; + char *str; + int i; + + /* cut the path up into individual elements */ + if (split_path(path, &split_path_list, &split_path_len) < 0) + goto done; + ptr = root; + /* search down the tree */ + for (i = 0; i < split_path_len; i++) { + str = split_path_list[i]; + strsep(&str, "=[]"); + str = split_path_list[i]; + if ((ptr1 = find_peer(ptr, str)) == NULL) + break; + ptr = ptr1->de_children; + } + if (i == split_path_len && ptr1 && ptr1->de_handler) + retval = 1; + else + retval = 0; + done: + /* clean up */ + if (split_path_list) + split_path_free(split_path_list, split_path_len); + return retval; } /*! Free a dispatcher tree @@ -469,12 +521,12 @@ dispatcher_free(dispatcher_entry_t *root) { if (root == NULL) return 0; - if (root->children) - dispatcher_free(root->children); - if (root->peer) - dispatcher_free(root->peer); - if (root->node_name) - free(root->node_name); + if (root->de_children) + dispatcher_free(root->de_children); + if (root->de_peer) + dispatcher_free(root->de_peer); + if (root->de_node_name) + free(root->de_node_name); free(root); return 0; } @@ -487,15 +539,15 @@ dispatcher_print(FILE *f, int level, dispatcher_entry_t *de) { - fprintf(f, "%*s%s", level*INDENT, "", de->node_name); - if (de->handler) - fprintf(f, " %p", de->handler); - if (de->arg) - fprintf(f, " (%p)", de->arg); + fprintf(f, "%*s%s", level*INDENT, "", de->de_node_name); + if (de->de_handler) + fprintf(f, " %p", de->de_handler); + if (de->de_arg) + fprintf(f, " (%p)", de->de_arg); fprintf(f, "\n"); - if (de->children) - dispatcher_print(f, level+1, de->children); - if (de->peer) - dispatcher_print(f, level, de->peer); + if (de->de_children) + dispatcher_print(f, level+1, de->de_children); + if (de->de_peer) + dispatcher_print(f, level, de->de_peer); return 0; } diff --git a/test/config.sh.in b/test/config.sh.in index b9fc13e7..f4816ae3 100755 --- a/test/config.sh.in +++ b/test/config.sh.in @@ -73,7 +73,7 @@ DATASTORE_TOP="config" # clixon yang revisions occuring in tests (see eg yang/clixon/Makefile.in) CLIXON_AUTOCLI_REV="2024-08-01" -CLIXON_LIB_REV="2024-08-01" +CLIXON_LIB_REV="2024-04-01" CLIXON_CONFIG_REV="2024-08-01" CLIXON_RESTCONF_REV="2022-08-01" CLIXON_EXAMPLE_REV="2022-11-01" diff --git a/test/example_social.sh b/test/example_social.sh index cac5363d..0a57aa01 100755 --- a/test/example_social.sh +++ b/test/example_social.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Example-social from draft-netconf-list-pagination-00.txt appendix A.1 +# Example-social from draft-netconf-list-pagination-04.txt appendix A.1 # Assumes variable fexample is set to name of yang file # Also: leaf-list member/state/numbers is added # Mark deviation from original with "Clixon" @@ -265,7 +265,6 @@ cat < $fexample list audit-log { description "List of audit logs."; - cl:list-pagination-partial-state; // Clixon leaf timestamp { type yang:date-and-time; mandatory true; diff --git a/test/test_pagination_config.sh b/test/test_pagination_config.sh index 0a16baee..0d13fdfd 100755 --- a/test/test_pagination_config.sh +++ b/test/test_pagination_config.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# List pagination tests loosely based on draft-wwlh-netconf-list-pagination-00 +# List pagination tests loosely based on draft-ietf-netconf-list-pagination-04 # The example-social yang file is used # This tests contains a large config list: members/member/favorites/uint8-numbers @@ -56,7 +56,7 @@ cat < $cfg EOF -# Based on draft-wwlh-netconf-list-pagination-00 A.2 but bob has a generated uint8-numbers list +# Based on draft-netconf-list-pagination-04.txt A.2 but bob has a generated uint8-numbers list # start file cat <<'EOF' > $dir/startup_db diff --git a/test/test_pagination_draft.sh b/test/test_pagination_draft.sh index dd4e567c..04a7565b 100755 --- a/test/test_pagination_draft.sh +++ b/test/test_pagination_draft.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash -# List pagination tests according to draft-wwlh-netconf-list-pagination-00 +# List pagination tests according to draft-ietf-netconf-list-pagination-04 # Follow the example-social example in the draft and the tests in Appendix A.2 + A.3.1/A.3.2 -# Basically only offset and limit supported # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi @@ -49,7 +48,7 @@ cat < $cfg EOF -# See draft-wwlh-netconf-list-pagination-00 A.2 (except stats and audit-log) +# See draft-netconf-list-pagination-04.txt A.2 (except stats and audit-log) # XXX: "config" without cat <<'EOF' > $dir/startup_db {"config": @@ -167,7 +166,7 @@ cat <<'EOF' > $dir/startup_db } EOF -# See draft-wwlh-netconf-list-pagination-00 A.2 (only stats and audit-log) +# See draft-netconf-list-pagination-04.txt A.2 (only stats and audit-log) cat< $fstate diff --git a/test/test_pagination_extra.sh b/test/test_pagination_extra.sh index 26a0ade3..da377bcd 100755 --- a/test/test_pagination_extra.sh +++ b/test/test_pagination_extra.sh @@ -38,7 +38,7 @@ cat < $cfg EOF -# See draft-wwlh-netconf-list-pagination-00 A.2 (except stats and audit-log) +# See draft-netconf-list-pagination-04.txt A.2 (except stats and audit-log) cat <<'EOF' > $dir/startup_db {"config": { @@ -155,7 +155,7 @@ cat <<'EOF' > $dir/startup_db } EOF -# See draft-wwlh-netconf-list-pagination-00 A.2 (only stats and audit-log) +# See draft-netconf-list-pagination-04.txt A.2 (only stats and audit-log) cat< $fstate diff --git a/test/test_pagination_state.sh b/test/test_pagination_state.sh index d37e0fe4..9e583bda 100755 --- a/test/test_pagination_state.sh +++ b/test/test_pagination_state.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# List pagination tests loosely based on draft-wwlh-netconf-list-pagination-00 +# List pagination tests loosely based on draft-ietf-netconf-list-pagination-04 # The example-social yang file is used # Three tests to get state pagination data: # 1. NETCONF get a specific list (alice->numbers) @@ -7,7 +7,6 @@ # 3. CLI get audit logs (only interactive) # This tests contains a large state list: audit-logs from the example # Only CLI is used -# Test also of list-pagination-partial-state extension # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi @@ -52,7 +51,7 @@ cat < $cfg EOF -# See draft-wwlh-netconf-list-pagination-00 A.2 (only stats and audit-log) +# See draft-netconf-list-pagination-04.txt A.2 (only stats and audit-log) cat< $fstate @@ -135,6 +134,7 @@ function testrun_stop() xpath0="/es:members/es:member[es:member-id='alice']/es:stats" xpath="$xpath0/es:numbers" + testrun_start $xpath new "NETCONF get leaf-list member/numbers 0-10 alice" diff --git a/test/test_pattern.sh b/test/test_pattern.sh index 6c198a93..1d4d4258 100755 --- a/test/test_pattern.sh +++ b/test/test_pattern.sh @@ -368,7 +368,7 @@ module pattern{ } } leaf p47 { - description "draft-wwlh-netconf-list-pagination-00 module example-social"; + description "draft-netconf-list-pagination-04 module example-social"; type string { length "1..80"; pattern '.*[\n].*' { diff --git a/yang/clixon/Makefile.in b/yang/clixon/Makefile.in index 1e2d9e79..79fd2c47 100644 --- a/yang/clixon/Makefile.in +++ b/yang/clixon/Makefile.in @@ -43,7 +43,7 @@ YANG_INSTALLDIR = @YANG_INSTALLDIR@ # Note: mirror these to test/config.sh.in YANGSPECS = clixon-config@2024-08-01.yang # 7.2 -YANGSPECS += clixon-lib@2024-08-01.yang # 7.2 +YANGSPECS += clixon-lib@2024-04-01.yang # 7.1 YANGSPECS += clixon-rfc5277@2008-07-01.yang YANGSPECS += clixon-xml-changelog@2019-03-21.yang YANGSPECS += clixon-restconf@2022-08-01.yang # 5.9 diff --git a/yang/clixon/clixon-lib@2024-04-01.yang b/yang/clixon/clixon-lib@2024-04-01.yang index fcd541bb..e8e252c3 100644 --- a/yang/clixon/clixon-lib@2024-04-01.yang +++ b/yang/clixon/clixon-lib@2024-04-01.yang @@ -22,7 +22,7 @@ module clixon-lib { "***** BEGIN LICENSE BLOCK ***** Copyright (C) 2009-2019 Olof Hagsand Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC(Netgate) - + This file is part of CLIXON Licensed under the Apache License, Version 2.0 (the \"License\"); @@ -40,7 +40,7 @@ module clixon-lib { in which case the provisions of the GPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of the GPL, and not to allow others to - use your version of this file under the terms of Apache License version 2, + use your version of this file under the terms of Apache License version 2, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under @@ -50,7 +50,7 @@ module clixon-lib { Clixon Netconf extensions for communication between clients and backend. This scheme adds: - - Added values of RFC6022 transport identityref + - Added values of RFC6022 transport identityref - RPCs for debug, stats and process-control - Informal description of attributes @@ -68,7 +68,6 @@ module clixon-lib { - objectexisted - link # For split multiple XML files "; - revision 2024-04-01 { description "Added: debug bits type @@ -100,7 +99,7 @@ module clixon-lib { } revision 2022-12-01 { description - "Added values of RFC6022 transport identityref + "Added values of RFC6022 transport identityref Added description of internal netconf attributes"; } revision 2021-12-05 { @@ -302,7 +301,7 @@ module clixon-lib { } identity netconf { description - "Just NETCONF without specific underlying transport, + "Just NETCONF without specific underlying transport, Clixon uses stdio for its netconf client and therefore does not know whether it is invoked in a script, by a NETCONF/SSH subsystem, etc"; base ncm:transport; @@ -328,7 +327,7 @@ module clixon-lib { description "When split configuration stores are used, ie CLICON_XMLDB_MULTI is set, This extension marks where in the configuration tree, one file terminates - and a new sub-file is written. + and a new sub-file is written. A designer adds the 'xmldb-split' extension to a YANG node which should be split. For example, a split could be made at mountpoints. See also the 'link 'attribute. @@ -341,7 +340,7 @@ module clixon-lib { One application is the clixon controller where multiple services can create the same object. When such a service is deleted (or changed) one needs to keep track of which service created what. - Limitations: only objects that are actually added or deleted. + Limitations: only objects that are actually added or deleted. A sub-object will not be noted"; } rpc debug { @@ -369,7 +368,7 @@ module clixon-lib { output { container global{ description - "Clixon global statistics. + "Clixon global statistics. These are global counters incremented by new() and decreased by free() calls. This number is higher than the sum of all datastore/module residing objects, since objects may be used for other purposes than datastore/modules"; @@ -406,10 +405,10 @@ module clixon-lib { } container module-sets{ list module-set{ - description "Statistics per group of module, eg top-level and mount-points"; + description "Statistics per domain, eg top-level and mount-points"; key "name"; leaf name{ - description "Name of YANG module."; + description "Name of YANG domain."; type string; } leaf nr{ @@ -456,7 +455,7 @@ module clixon-lib { rpc process-control { description "Control a specific process or daemon: start/stop, etc. - This is for direct managing of a process by the backend. + This is for direct managing of a process by the backend. Alternatively one can manage a daemon via systemd, containerd, kubernetes, etc."; input { leaf name { @@ -478,7 +477,7 @@ module clixon-lib { "Output from status rpc"; leaf active { description - "True if process is running, false if not. + "True if process is running, false if not. More specifically, there is a process-id and it exists (in Linux: kill(pid,0). Note that this is actual state and status is administrative state, which means that changing the administrative state, eg stopped->running diff --git a/yang/clixon/clixon-lib@2024-08-01.yang b/yang/clixon/clixon-lib@2024-08-01.yang deleted file mode 100644 index b614aebb..00000000 --- a/yang/clixon/clixon-lib@2024-08-01.yang +++ /dev/null @@ -1,541 +0,0 @@ -module clixon-lib { - yang-version 1.1; - namespace "http://clicon.org/lib"; - prefix cl; - - import ietf-yang-types { - prefix yang; - } - import ietf-netconf-monitoring { - prefix ncm; - } - import ietf-yang-metadata { - prefix "md"; - } - organization - "Clicon / Clixon"; - - contact - "Olof Hagsand "; - - description - "***** BEGIN LICENSE BLOCK ***** - Copyright (C) 2009-2019 Olof Hagsand - Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC(Netgate) - - This file is part of CLIXON - - Licensed under the Apache License, Version 2.0 (the \"License\"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an \"AS IS\" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - Alternatively, the contents of this file may be used under the terms of - the GNU General Public License Version 3 or later (the \"GPL\"), - in which case the provisions of the GPL are applicable instead - of those above. If you wish to allow use of your version of this file only - under the terms of the GPL, and not to allow others to - use your version of this file under the terms of Apache License version 2, - indicate your decision by deleting the provisions above and replace them with - the notice and other provisions required by the GPL. If you do not delete - the provisions above, a recipient may use your version of this file under - the terms of any one of the Apache License version 2 or the GPL. - - ***** END LICENSE BLOCK ***** - - Clixon Netconf extensions for communication between clients and backend. - This scheme adds: - - Added values of RFC6022 transport identityref - - RPCs for debug, stats and process-control - - Informal description of attributes - - Clixon also extends NETCONF for internal use with some internal attributes. These - are not visible for external usage bit belongs to the namespace of this YANG. - The internal attributes are: - - content (also RESTCONF) - - depth (also RESTCONF) - - username - - autocommit - - copystartup - - transport (see RFC6022) - - source-host (see RFC6022) - - objectcreate - - objectexisted - - link # For split multiple XML files - "; - - revision 2024-08-01 { - description - "Added: list-pagination-partial-state - Released in Clixon 7.2"; - } - revision 2024-04-01 { - description - "Added: debug bits type - Added: xmldb-split extension - Added: Default format - Released in Clixon 7.1"; - } - revision 2024-01-01 { - description - "Removed container creators from 6.5 - Released in 7.0"; - } - revision 2023-11-01 { - description - "Added ignore-compare extension - Added creator meta configuration - Removed obsolete extension autocli-op - Released in 6.5.0"; - } - revision 2023-05-01 { - description - "Restructured and extended stats rpc to schema mountpoints - Moved datastore-format typedef from clixon-config - "; - } - revision 2023-03-01 { - description - "Added creator meta-object"; - } - revision 2022-12-01 { - description - "Added values of RFC6022 transport identityref - Added description of internal netconf attributes"; - } - revision 2021-12-05 { - description - "Obsoleted: extension autocli-op"; - } - revision 2021-11-11 { - description - "Changed: RPC stats extended with YANG stats"; - } - revision 2021-03-08 { - description - "Changed: RPC process-control output to choice dependent on operation"; - } - revision 2020-12-30 { - description - "Changed: RPC process-control output parameter status to pid"; - } - revision 2020-12-08 { - description - "Added: autocli-op extension. - rpc process-control for process/daemon management - Released in clixon 4.9"; - } - revision 2020-04-23 { - description - "Added: stats RPC for clixon XML and memory statistics. - Added: restart-plugin RPC for restarting individual plugins without restarting backend."; - } - revision 2019-08-13 { - description - "No changes (reverted change)"; - } - revision 2019-06-05 { - description - "ping rpc added for liveness"; - } - revision 2019-01-02 { - description - "Released in Clixon 3.9"; - } - typedef service-operation { - type enumeration { - enum start { - description - "Start if not already running"; - } - enum stop { - description - "Stop if running"; - } - enum restart { - description - "Stop if running, then start"; - } - enum status { - description - "Check status"; - } - } - description - "Common operations that can be performed on a service"; - } - typedef datastore_format{ - description - "Datastore format (only xml and json implemented in actual data."; - type enumeration{ - enum xml{ - description - "Save and load xmldb as XML - More specifically, such a file looks like: ... provided - DATASTORE_TOP_SYMBOL is 'config'"; - } - enum json{ - description "Save and load xmldb as JSON"; - } - enum text{ - description "'Curly' C-like text format"; - } - enum cli{ - description "CLI format"; - } - enum default{ - description "Default format"; - } - } - } - typedef clixon_debug_t { - description - "Debug flags. - Flags are seperated into subject areas and detail - Can also be given directly as -D to clixon commands - Note there are also constants in the code that need to be in sync with these values"; - type bits { - /* Subjects: */ - bit default { - description "Default logs"; - position 0; - } - bit msg { - description "In/out messages"; - position 1; - } - bit init { - description "Initialization"; - position 2; - } - bit xml { - description "XML processing"; - position 3; - } - bit xpath { - description "XPath processing"; - position 4; - } - bit yang { - description "YANG processing"; - position 5; - } - bit backend { - description "Backend-specific"; - position 6; - } - bit cli { - description "CLI frontend"; - position 7; - } - bit netconf { - description "NETCONF frontend"; - position 8; - } - bit restconf { - description "RESTCONF frontend"; - position 9; - } - bit snmp { - description "SNMP frontend"; - position 10; - } - bit nacm { - description "NACM processing"; - position 11; - } - bit proc { - description "Process handling"; - position 12; - } - bit datastore { - description "Datastore xmldb management"; - position 13; - } - bit event { - description "Event processing"; - position 14; - } - bit rpc { - description "RPC handling"; - position 15; - } - bit stream { - description "Notification streams"; - position 16; - } - bit parse { - description "Parser: XML,YANG, etc"; - position 17; - } - bit app { - description "External applications"; - position 20; - } - bit app2 { - description "External application"; - position 21; - } - bit app3 { - description "External application 2"; - position 22; - } - /* Detail level: */ - bit detail { - description "Details: traces, parse trees, etc"; - position 24; - } - bit detail2 { - description "Extra details"; - position 25; - } - bit detail3 { - description "Probably more detail than you want"; - position 26; - } - } - } - identity snmp { - description - "SNMP"; - base ncm:transport; - } - identity netconf { - description - "Just NETCONF without specific underlying transport, - Clixon uses stdio for its netconf client and therefore does not know whether it is - invoked in a script, by a NETCONF/SSH subsystem, etc"; - base ncm:transport; - } - identity restconf { - description - "RESTCONF either as HTTP/1 or /2, TLS or not, reverse proxy (eg fcgi/nginx) or native"; - base ncm:transport; - } - identity cli { - description - "A CLI session"; - base ncm:transport; - } - extension list-pagination-partial-state { - description - "List should be partially read according to the clixon_pagination_cb_register API. - This is a performance enhancement of pagination state data. - This means that a special callback is used for retreiving list state which is aware of - offset/limit attributes. - In this way the non-config data can be partially read by the server, instead of reading - the whole state on every pagination request. - It affects only the server/backend-side - It only handles the offset and limit attributes, all other attributes, - such as where, sort-by, direction, etc, are ignored"; - } - extension ignore-compare { - description - "The object should be ignored when comparing device configs for equality. - The object should never be added, modified, or deleted on target. - Essentially a read-only object - One example is auto-created objects by the controller, such as uid."; - } - extension xmldb-split { - description - "When split configuration stores are used, ie CLICON_XMLDB_MULTI is set, - This extension marks where in the configuration tree, one file terminates - and a new sub-file is written. - A designer adds the 'xmldb-split' extension to a YANG node which should be split. - For example, a split could be made at mountpoints. - See also the 'link 'attribute. - "; - } - md:annotation creator { - type string; - description - "This annotation contains the name of a creator of an object. - One application is the clixon controller where multiple services can - create the same object. When such a service is deleted (or changed) one needs to keep - track of which service created what. - Limitations: only objects that are actually added or deleted. - A sub-object will not be noted"; - } - rpc debug { - description - "Set debug flags of backend. - Note only numerical values"; - input { - leaf level { - type uint32; - } - } - } - rpc ping { - description "Check aliveness of backend daemon."; - } - rpc stats { /* Could be moved to state */ - description "Clixon yang and datastore statistics."; - input { - leaf modules { - description "If enabled include per-module statistics"; - type boolean; - mandatory false; - } - } - output { - container global{ - description - "Clixon global statistics. - These are global counters incremented by new() and decreased by free() calls. - This number is higher than the sum of all datastore/module residing objects, since - objects may be used for other purposes than datastore/modules"; - leaf xmlnr{ - description - "Number of existing XML objects: number of residing xml/json objects - in the internal 'cxobj' representation."; - type uint64; - } - leaf yangnr{ - description - "Number of resident YANG objects. "; - type uint64; - } - } - container datastores{ - list datastore{ - description "Per datastore statistics for cxobj"; - key "name"; - leaf name{ - description "Name of datastore (eg running)."; - type string; - } - leaf nr{ - description "Number of XML objects. That is number of residing xml/json objects - in the internal 'cxobj' representation."; - type uint64; - } - leaf size{ - description "Size in bytes of internal datastore cache of datastore tree."; - type uint64; - } - } - } - container module-sets{ - list module-set{ - description "Statistics per domain, eg top-level and mount-points"; - key "name"; - leaf name{ - description "Name of YANG domain."; - type string; - } - leaf nr{ - description - "Total number of YANG objects in set"; - type uint64; - } - leaf size{ - description - "Total size in bytes of internal YANG object representation for module set"; - type uint64; - } - list module{ - description "Statistics per module (if modules set in input)"; - key "name"; - leaf name{ - description "Name of YANG module."; - type string; - } - leaf nr{ - description - "Number of YANG objects. That is number of residing YANG objects"; - type uint64; - } - leaf size{ - description - "Size in bytes of internal YANG object representation."; - type uint64; - } - } - } - } - } - } - rpc restart-plugin { - description "Restart specific backend plugins."; - input { - leaf-list plugin { - description "Name of plugin to restart"; - type string; - } - } - } - rpc process-control { - description - "Control a specific process or daemon: start/stop, etc. - This is for direct managing of a process by the backend. - Alternatively one can manage a daemon via systemd, containerd, kubernetes, etc."; - input { - leaf name { - description "Name of process"; - type string; - mandatory true; - } - leaf operation { - type service-operation; - mandatory true; - description - "One of the strings 'start', 'stop', 'restart', or 'status'."; - } - } - output { - choice result { - case status { - description - "Output from status rpc"; - leaf active { - description - "True if process is running, false if not. - More specifically, there is a process-id and it exists (in Linux: kill(pid,0). - Note that this is actual state and status is administrative state, - which means that changing the administrative state, eg stopped->running - may not immediately switch active to true."; - type boolean; - } - leaf description { - type string; - description "Description of process. This is a static string"; - } - leaf command { - type string; - description "Start command with arguments"; - } - leaf status { - description - "Administrative status (except on external kill where it enters stopped - directly from running): - stopped: pid=0, No process running - running: pid set, Process started and believed to be running - exiting: pid set, Process is killed by parent but not waited for"; - type string; - } - leaf starttime { - description "Time of starting process UTC"; - type yang:date-and-time; - } - leaf pid { - description "Process-id of main running process (if active)"; - type uint32; - } - } - case other { - description - "Output from start/stop/restart rpc"; - leaf ok { - type empty; - } - } - } - } - } -}