Skip to content

Commit

Permalink
Autocli optimization feature for generating smaller CLISPECs for larg…
Browse files Browse the repository at this point in the history
…e YANGs using treerefs

New `grouping-treeref` option added to clixon-autocli.yang
Default is disabled, set to true to generate smaller memory footprint of clixon_cl
Add prefix "mtpoint:" to cli api-paths to identify change of yang schemas
  • Loading branch information
olofhagsand committed Jul 23, 2023
1 parent d484429 commit f526d5b
Show file tree
Hide file tree
Showing 14 changed files with 668 additions and 64 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Users may have to change how they access the system
* rpc `<stats>` is not backward compatible
* New `clixon-autocli@2023-05-01.yang` revision
* New `alias` and `skip` extensions
* New `grouping-treeref` option

### C/CLI-API changes on existing features
Developers may need to change their code
Expand All @@ -72,6 +73,9 @@ Developers may need to change their code

### Minor features

* Autocli optimization feature for generating smaller CLISPECs for large YANGs using treerefs
* New `grouping-treeref` option added to clixon-autocli.yang
* Default is disabled, set to true to generate smaller memory footprint of clixon_cli
* Changed YANG uses/grouping to keep uses statement and flag it with YANG_FLAG_USES_EXP
* Removed extras/ and build-root/ build code since they are not properly maintained
* Refactored cli-syntax code to use cligen pt_head instead (long overdue)
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/cli_auto.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ cli_auto_edit(clicon_handle h,
}
api_path_fmt = cv_string_get(cvec_i(argv, argc++));
str = cv_string_get(cvec_i(argv, argc++));
if (str && str[0] == '/'){ /* ad-hoc to see if 2nd arg is mountpoint */
mtpoint = str;
if (str && strncmp(str, "mtpoint:", strlen("mtpoint:")) == 0){
mtpoint = str + strlen("mtpoint:");
clicon_debug(1, "%s mtpoint:%s", __FUNCTION__, mtpoint);
treename = cv_string_get(cvec_i(argv, argc++));
}
Expand Down
43 changes: 43 additions & 0 deletions apps/cli/cli_autocli.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,49 @@ autocli_completion(clicon_handle h,
return retval;
}

/*! Return autocli grouping treeref option
*
* When false replaces uses with grouping, when true use tree reference
* @param[in] h Clixon handle
* @param[out] treeref grouping using treerefs enabled
* @retval -1 Error
* @retval 0 OK
*/
int
autocli_grouping_treeref(clicon_handle h,
int *treeref)
{
int retval = -1;
char *str;
uint8_t val;
char *reason = NULL;
int ret;
cxobj *xautocli;

if (treeref == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done;
}
if ((xautocli = clicon_conf_autocli(h)) == NULL){
clicon_err(OE_YANG, 0, "No clixon-autocli");
goto done;
}
if ((str = xml_find_body(xautocli, "grouping-treeref")) == NULL){
clicon_err(OE_XML, EINVAL, "No grouping-treeref rule");
goto done;
}
if ((ret = parse_bool(str, &val, &reason)) < 0){
clicon_err(OE_CFG, errno, "parse_bool");
goto done;
}
*treeref = val;
retval = 0;
done:
if (reason)
free(reason);
return retval;
}

/*! Return default autocli list keyword setting
*
* Currently only returns list-keyword-default, could be extended to rules
Expand Down
1 change: 1 addition & 0 deletions apps/cli/cli_autocli.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum autocli_op{
*/
int autocli_module(clicon_handle h, char *modname, int *enable);
int autocli_completion(clicon_handle h, int *completion);
int autocli_grouping_treeref(clicon_handle h, int *grouping_treeref);
int autocli_list_keyword(clicon_handle h, autocli_listkw_t *listkw);
int autocli_compress(clicon_handle h, yang_stmt *ys, int *compress);
int autocli_treeref_state(clicon_handle h, int *treeref_state);
Expand Down
49 changes: 38 additions & 11 deletions apps/cli/cli_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,10 @@ mtpoint_paths(yang_stmt *yspec0,
*
* @param[in] h Clicon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector: <apipathfmt> [<mointpt>], eg "/aaa/%s"
* @param[in] argv Arguments given at the callback:
* <api_path_fmt> Generated API PATH (this is added implicitly, not actually given in the cvv)
* <api_path_fmt>* Added by merge in treeref_merge_co
* [<mt-point>] Optional YANG path-arg/xpath from mount-point
* @param[in] op Operation to perform on database
* @param[in] nsctx Namespace context for last value added
* cvv first contains the complete cli string, and then a set of optional
Expand All @@ -373,35 +376,57 @@ cli_dbxml(clicon_handle h,
cvec *nsctx)
{
int retval = -1;
cbuf *api_path_fmt_cb = NULL; /* xml key format */
char *api_path_fmt; /* xml key format */
char *api_path_fmt01 = NULL;
char *api_path = NULL;
cg_var *arg;
cbuf *cb = NULL;
cxobj *xbot = NULL; /* xpath, NULL if datastore */
yang_stmt *y = NULL; /* yang spec of xpath */
cxobj *xtop = NULL; /* xpath root */
cxobj *xerr = NULL;
int ret;
cg_var *cv;
char *str;
int cvvi = 0;
char *mtpoint = NULL;
yang_stmt *yspec0 = NULL;
int argc = 0;
int i;

if (cvec_len(argv) != 1 && cvec_len(argv) != 2){
clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be xml key format string");
goto done;
}
/* Top-level yspec */
if ((yspec0 = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC");
goto done;
}
arg = cvec_i(argv, 0);
api_path_fmt = cv_string_get(arg);
if (cvec_len(argv) > 1){
arg = cvec_i(argv, 1);
mtpoint = cv_string_get(arg);
if ((api_path_fmt_cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
/* Iterate through all api_path_fmt:s, assume they start with / */
for (argc=0; argc<cvec_len(argv); argc++){
cv = cvec_i(argv, argc);
str = cv_string_get(cv);
if (str[0] != '/')
break;
}
if (argc == 0){
clicon_err(OE_PLUGIN, EINVAL, "No <api_path_fmt> in argv");
goto done;
}
/* Append a api_path_fmt from sub-parts */
for (i=argc-1; i>=0; i--){
cprintf(api_path_fmt_cb, "%s", cv_string_get(cvec_i(argv, i)));
}
api_path_fmt = cbuf_get(api_path_fmt_cb);
if (cvec_len(argv) > argc){
cv = cvec_i(argv, argc++);
str = cv_string_get(cv);
if (strncmp(str, "mtpoint:", strlen("mtpoint:")) != 0){
clicon_err(OE_PLUGIN, 0, "mtpoint does not begin with 'mtpoint:'");
goto done;
}
mtpoint = str + strlen("mtpoint:");
}
/* Remove all keywords */
if (cvec_exclude_keys(cvv) < 0)
Expand Down Expand Up @@ -483,6 +508,8 @@ cli_dbxml(clicon_handle h,
goto done;
retval = 0;
done:
if (api_path_fmt_cb)
cbuf_free(api_path_fmt_cb);
if (api_path_fmt01)
free(api_path_fmt01);
if (xerr)
Expand Down
Loading

0 comments on commit f526d5b

Please sign in to comment.