* Performance improvement
* Added ancestor config cache indicating wether the node or an ancestor is config false or true * Improved yang cardinality lookup * Added yang_init(), called from all apps using yang
This commit is contained in:
parent
0626de9431
commit
b91ce762d5
19 changed files with 415 additions and 63 deletions
|
|
@ -568,6 +568,7 @@ main(int argc,
|
|||
*/
|
||||
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
|
||||
clicon_debug_init(dbg, NULL);
|
||||
yang_init(h);
|
||||
|
||||
/* Find and read configfile */
|
||||
if (clicon_options_main(h) < 0){
|
||||
|
|
|
|||
|
|
@ -759,8 +759,8 @@ cli_auto_show(clicon_handle h,
|
|||
cli_xml2cli(xc, prefix, gt, cligen_output); /* cli syntax */
|
||||
break;
|
||||
case FORMAT_NETCONF:
|
||||
fprintf(stdout, "<rpc xmlns=\"%s\"><edit-config><target><candidate/></target><config>",
|
||||
NETCONF_BASE_NAMESPACE);
|
||||
fprintf(stdout, "<rpc xmlns=\"%s\" %s><edit-config><target><candidate/></target><config>",
|
||||
NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
|
||||
if (pretty)
|
||||
fprintf(stdout, "\n");
|
||||
if (isroot)
|
||||
|
|
|
|||
|
|
@ -801,7 +801,7 @@ load_config_file(clicon_handle h,
|
|||
cxobj *xt = NULL;
|
||||
cxobj *x;
|
||||
cbuf *cbxml;
|
||||
char *formatstr;
|
||||
char *formatstr = NULL;
|
||||
enum format_enum format = FORMAT_XML;
|
||||
|
||||
if (cvec_len(argv) < 2 || cvec_len(argv) > 4){
|
||||
|
|
@ -908,6 +908,7 @@ save_config_file(clicon_handle h,
|
|||
char *dbstr;
|
||||
char *varstr;
|
||||
cxobj *xt = NULL;
|
||||
cxobj *x;
|
||||
cxobj *xerr;
|
||||
FILE *f = NULL;
|
||||
enum genmodel_type gt;
|
||||
|
|
@ -970,21 +971,25 @@ save_config_file(clicon_handle h,
|
|||
goto done;
|
||||
break;
|
||||
case FORMAT_TEXT:
|
||||
cli_xml2txt(xt, cligen_output, 0); /* tree-formed text */
|
||||
if (xml2txt(f, xt, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_CLI:
|
||||
if ((gt = clicon_cli_genmodel_type(h)) == GT_ERR)
|
||||
goto done;
|
||||
if (xml2cli(f, xt, prefix, gt) < 0)
|
||||
goto done;
|
||||
x = NULL;
|
||||
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
|
||||
if (xml2cli(f, x, prefix, gt) < 0)
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
case FORMAT_NETCONF:
|
||||
fprintf(f, "<rpc xmlns=\"%s\"><edit-config><target><candidate/></target><config>",
|
||||
NETCONF_BASE_NAMESPACE);
|
||||
fprintf(f, "<rpc xmlns=\"%s\" %s><edit-config><target><candidate/></target>",
|
||||
NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
|
||||
fprintf(f, "\n");
|
||||
if (clicon_xml2file(f, xt, 0, pretty) < 0)
|
||||
goto done;
|
||||
fprintf(f, "</config></edit-config></rpc>]]>]]>\n");
|
||||
fprintf(f, "</edit-config></rpc>]]>]]>\n");
|
||||
break;
|
||||
} /* switch */
|
||||
retval = 0;
|
||||
|
|
|
|||
|
|
@ -483,8 +483,8 @@ main(int argc,
|
|||
* Logs, error and debug to stderr or syslog, set debug level
|
||||
*/
|
||||
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
|
||||
|
||||
clicon_debug_init(dbg, NULL);
|
||||
yang_init(h);
|
||||
|
||||
/* Find, read and parse configfile */
|
||||
if (clicon_options_main(h) < 0){
|
||||
|
|
@ -651,7 +651,7 @@ main(int argc,
|
|||
if ((yspec = yspec_new()) == NULL)
|
||||
goto done;
|
||||
clicon_dbspec_yang_set(h, yspec);
|
||||
|
||||
|
||||
/* Load Yang modules
|
||||
* 1. Load a yang module as a specific absolute filename */
|
||||
if ((str = clicon_yang_main_file(h)) != NULL){
|
||||
|
|
|
|||
|
|
@ -710,7 +710,8 @@ main(int argc,
|
|||
*/
|
||||
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
|
||||
clicon_debug_init(dbg, NULL);
|
||||
|
||||
yang_init(h);
|
||||
|
||||
/* Find, read and parse configfile */
|
||||
if (clicon_options_main(h) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -296,6 +296,7 @@ main(int argc,
|
|||
goto done;
|
||||
}
|
||||
|
||||
yang_init(h);
|
||||
/* Find and read configfile */
|
||||
if (clicon_options_main(h) < 0)
|
||||
goto done;
|
||||
|
|
@ -375,6 +376,7 @@ main(int argc,
|
|||
if ((yspec = yspec_new()) == NULL)
|
||||
goto done;
|
||||
clicon_dbspec_yang_set(h, yspec);
|
||||
|
||||
/* Initialize plugin module by creating a handle holding plugin and callback lists */
|
||||
if (clixon_plugin_module_init(h) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -1731,6 +1731,7 @@ restconf_clixon_init(clicon_handle h,
|
|||
if ((yspec = yspec_new()) == NULL)
|
||||
goto done;
|
||||
clicon_dbspec_yang_set(h, yspec);
|
||||
|
||||
/* Load restconf plugins before yangs are loaded (eg extension callbacks) */
|
||||
if ((dir = clicon_restconf_dir(h)) != NULL)
|
||||
if (clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
|
||||
|
|
@ -1987,6 +1988,7 @@ main(int argc,
|
|||
clicon_err(OE_DAEMON, errno, "Setting signal");
|
||||
goto done;
|
||||
}
|
||||
yang_init(h);
|
||||
/* Find and read configfile */
|
||||
if (clicon_options_main(h) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -101,10 +101,11 @@ example_client_rpc(clicon_handle h,
|
|||
cva = cvec_find(cvv, "a"); /* get a cligen variable from vector */
|
||||
/* Create XML for example netconf RPC */
|
||||
if (clixon_xml_parse_va(YB_NONE, NULL, &xtop, NULL,
|
||||
"<rpc xmlns=\"%s\" username=\"%s\" message-id=\"101\">"
|
||||
"<rpc xmlns=\"%s\" username=\"%s\" %s>"
|
||||
"<example xmlns=\"urn:example:clixon\"><x>%s</x></example></rpc>",
|
||||
NETCONF_BASE_NAMESPACE,
|
||||
clicon_username_get(h),
|
||||
NETCONF_MESSAGE_ID_ATTR,
|
||||
cv_string_get(cva)) < 0)
|
||||
goto done;
|
||||
/* Skip top-level */
|
||||
|
|
|
|||
|
|
@ -99,6 +99,8 @@ save("Save candidate configuration to XML file") <filename:string>("Filename (lo
|
|||
cli("Save configuration as CLI commands"), save_config_file("candidate","filename", "cli");
|
||||
xml("Save configuration as XML"), save_config_file("candidate","filename", "xml");
|
||||
json("Save configuration as JSON"), save_config_file("candidate","filename", "json");
|
||||
text("Save configuration as TEXT"), save_config_file("candidate","filename", "text");
|
||||
netconf("Save configuration as NETCONF"), save_config_file("candidate","filename", "netconf");
|
||||
}
|
||||
load("Load configuration from XML file") <filename:string>("Filename (local filename)"),load_config_file("filename", "replace");{
|
||||
replace("Replace candidate with file contents"), load_config_file("filename", "replace");{
|
||||
|
|
|
|||
|
|
@ -139,3 +139,8 @@
|
|||
* Consider enabling this option permanently after 5.4
|
||||
*/
|
||||
#define YANG_ORDERING_WHEN_LAST
|
||||
|
||||
/*! Use Ancestor config cache
|
||||
* The cache uses two yang stmt flag bits. One to say it is active, the second its value
|
||||
*/
|
||||
#define USE_CONFIG_FLAG_CACHE
|
||||
|
|
|
|||
|
|
@ -61,6 +61,10 @@
|
|||
#define YANG_FLAG_INDEX 0x08 /* This yang node under list is (extra) index. --> you can access
|
||||
* list elements using this index with binary search */
|
||||
#endif
|
||||
#ifdef USE_CONFIG_FLAG_CACHE
|
||||
#define YANG_FLAG_CONFIG_CACHE 0x10 /* Ancestor config cache is active */
|
||||
#define YANG_FLAG_CONFIG_VALUE 0x20 /* Ancestor config cache value */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Types
|
||||
|
|
@ -272,5 +276,6 @@ int yang_type_cache_set(yang_stmt *ys, yang_stmt *resolved, int options,
|
|||
yang_stmt *yang_anydata_add(yang_stmt *yp, char *name);
|
||||
int yang_extension_value(yang_stmt *ys, char *name, char *ns, int *exist, char **value);
|
||||
int yang_sort_subelements(yang_stmt *ys);
|
||||
int yang_init(clicon_handle h);
|
||||
|
||||
#endif /* _CLIXON_YANG_H_ */
|
||||
|
|
|
|||
|
|
@ -3190,11 +3190,29 @@ yang_config_ancestor(yang_stmt *ys)
|
|||
|
||||
yp = ys;
|
||||
do {
|
||||
if (yang_config(yp) == 0)
|
||||
#ifdef USE_CONFIG_FLAG_CACHE
|
||||
if (yang_flag_get(yp, YANG_FLAG_CONFIG_CACHE))
|
||||
return yang_flag_get(yp, YANG_FLAG_CONFIG_VALUE)?1:0;
|
||||
#endif
|
||||
if (yang_config(yp) == 0){
|
||||
#ifdef USE_CONFIG_FLAG_CACHE
|
||||
yang_flag_set(yp, YANG_FLAG_CONFIG_CACHE);
|
||||
yang_flag_reset(yp, YANG_FLAG_CONFIG_VALUE);
|
||||
#endif
|
||||
return 0;
|
||||
if (yang_keyword_get(yp) == Y_INPUT || yang_keyword_get(yp) == Y_OUTPUT || yang_keyword_get(yp) == Y_NOTIFICATION)
|
||||
}
|
||||
if (yang_keyword_get(yp) == Y_INPUT || yang_keyword_get(yp) == Y_OUTPUT || yang_keyword_get(yp) == Y_NOTIFICATION){
|
||||
#ifdef USE_CONFIG_FLAG_CACHE
|
||||
yang_flag_set(yp, YANG_FLAG_CONFIG_CACHE);
|
||||
yang_flag_reset(yp, YANG_FLAG_CONFIG_VALUE);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
} while((yp = yang_parent_get(yp)) != NULL);
|
||||
#ifdef USE_CONFIG_FLAG_CACHE
|
||||
yang_flag_set(ys, YANG_FLAG_CONFIG_CACHE);
|
||||
yang_flag_set(ys, YANG_FLAG_CONFIG_VALUE);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -3678,6 +3696,12 @@ yang_sort_subelements(yang_stmt *ys)
|
|||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
yang_init(clicon_handle h)
|
||||
{
|
||||
return yang_cardinality_init(h);
|
||||
}
|
||||
|
||||
#ifdef XML_EXPLICIT_INDEX
|
||||
/*! Mark element as search_index in list
|
||||
* @retval 0 OK
|
||||
|
|
|
|||
|
|
@ -111,11 +111,11 @@ struct ycard{
|
|||
* 1 10
|
||||
* 0..1 149
|
||||
* 0..n 176 (no restrictions)
|
||||
* @note assume array is ordered wrt parent
|
||||
* @note The array MUST be ordered wrt parent and child for ycard_find_binary to use binary search
|
||||
* @note yang-version is optional in RFC6020 but mandatory in RFC7950, if not given, it defaults to 1.
|
||||
*/
|
||||
#define NMAX 1000000 /* Just a large number */
|
||||
static const struct ycard yclist[] = {
|
||||
static const struct ycard _yclist[] = {
|
||||
{Y_ACTION, Y_DESCRIPTION, 0, 1, 0},
|
||||
{Y_ACTION, Y_GROUPING, 0, NMAX, 0},
|
||||
{Y_ACTION, Y_IF_FEATURE, 0, NMAX, 0},
|
||||
|
|
@ -176,6 +176,7 @@ static const struct ycard yclist[] = {
|
|||
{Y_CASE, Y_STATUS, 0, 1, 0},
|
||||
{Y_CASE, Y_USES, 0, NMAX, 0},
|
||||
{Y_CASE, Y_WHEN, 0, 1, 0},
|
||||
{Y_CHOICE, Y_ANYDATA, 0, NMAX, 0},
|
||||
{Y_CHOICE, Y_ANYXML, 0, NMAX, 0},
|
||||
{Y_CHOICE, Y_CASE, 0, NMAX, 0},
|
||||
{Y_CHOICE, Y_CHOICE, 0, NMAX, 0},
|
||||
|
|
@ -191,7 +192,6 @@ static const struct ycard yclist[] = {
|
|||
{Y_CHOICE, Y_REFERENCE, 0, 1, 0},
|
||||
{Y_CHOICE, Y_STATUS, 0, 1, 0},
|
||||
{Y_CHOICE, Y_WHEN, 0, 1, 0},
|
||||
{Y_CHOICE, Y_ANYDATA, 0, NMAX, 0},
|
||||
{Y_CONTAINER, Y_ACTION, 0, NMAX, 0},
|
||||
{Y_CONTAINER, Y_ANYDATA, 0, NMAX, 0},
|
||||
{Y_CONTAINER, Y_ANYXML, 0, NMAX, 0},
|
||||
|
|
@ -451,37 +451,22 @@ static const struct ycard yclist[] = {
|
|||
{Y_USES, Y_REFINE, 0, NMAX, 0},
|
||||
{Y_USES, Y_STATUS, 0, 1, 0},
|
||||
{Y_USES, Y_WHEN, 0, 1, 0},
|
||||
{Y_WHEN, Y_DESCRIPTION, 0, 1, 0},
|
||||
{Y_WHEN, Y_REFERENCE, 0, 1, 0},
|
||||
{0,}
|
||||
};
|
||||
|
||||
/*! Find yang parent and child combination in yang cardinality table
|
||||
* @param[in] parent Parent Yang spec
|
||||
* @param[in] child Child yang spec if 0 first
|
||||
* @param[in] yc Yang cardinality map
|
||||
* @param[in] p If set, quit as soon as parents dont match
|
||||
* @retval NULL Not found
|
||||
* @retval yp Found
|
||||
* @note if cardinal list above is sorted, this search could do binary
|
||||
/* Search matrix for lookups */
|
||||
static const struct ycard *_yc_search[Y_SPEC][Y_SPEC] = {0,};
|
||||
|
||||
/* Set to 1 if exists in search
|
||||
* Some yang statements are not explicitly given cardinalities in RFC7950, although they are
|
||||
* present in Section 14 BNF.
|
||||
* But since the table above is from the explicit cardinalities in the RFC the others are skipped
|
||||
* and = 0 in the following vector.
|
||||
* Example: Y_REFINE
|
||||
*/
|
||||
static const struct ycard *
|
||||
ycard_find(enum rfc_6020 parent,
|
||||
enum rfc_6020 child,
|
||||
const struct ycard *yclist,
|
||||
int p)
|
||||
{
|
||||
const struct ycard *yc;
|
||||
|
||||
for (yc = &yclist[0]; (int)yc->yc_parent; yc++){
|
||||
if (yc->yc_parent == parent){
|
||||
if (!child || yc->yc_child == child)
|
||||
return yc;
|
||||
}
|
||||
else
|
||||
if (p)
|
||||
return NULL; /* premature quit */
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
static int _yc_exist[Y_SPEC] = {0,};
|
||||
|
||||
/*! Check cardinality, ie if each yang node has the expected nr of children
|
||||
* @param[in] h Clicon handle
|
||||
|
|
@ -503,16 +488,14 @@ yang_cardinality(clicon_handle h,
|
|||
int pk;
|
||||
int ck;
|
||||
int i;
|
||||
int nr;
|
||||
const struct ycard *ycplist; /* ycard parent table*/
|
||||
const struct ycard *yc;
|
||||
int order;
|
||||
yang_stmt *yprev = NULL;
|
||||
int nr;
|
||||
|
||||
pk = yang_keyword_get(yt);
|
||||
/* 0) Find parent sub-parts of cardinality vector */
|
||||
if ((ycplist = ycard_find(pk, 0, yclist, 0)) == NULL)
|
||||
goto ok; /* skip */
|
||||
if (_yc_exist[pk] == 0)
|
||||
goto ok;
|
||||
/* 1) For all children, if neither in 0..n, 0..1, 1 or 1..n ->ERROR
|
||||
* Also: check monotonically increasing order
|
||||
*/
|
||||
|
|
@ -520,10 +503,10 @@ yang_cardinality(clicon_handle h,
|
|||
ys = NULL;
|
||||
while ((ys = yn_each(yt, ys)) != NULL) {
|
||||
ck = yang_keyword_get(ys);
|
||||
if (ck == Y_UNKNOWN) /* special case */
|
||||
if (pk == Y_UNKNOWN || ck == Y_UNKNOWN) /* special case */
|
||||
continue;
|
||||
/* Find entry in yang cardinality table from parent/child keyword pair */
|
||||
if ((yc = ycard_find(pk, ck, ycplist, 1)) == NULL){
|
||||
if ((yc = _yc_search[pk][ck]) == NULL){
|
||||
clicon_err(OE_YANG, 0, "%s: \"%s\"(%s) is child of \"%s\"(%s), but should not be",
|
||||
modname,
|
||||
yang_key2str(ck),
|
||||
|
|
@ -548,16 +531,16 @@ yang_cardinality(clicon_handle h,
|
|||
yprev = ys;
|
||||
}
|
||||
/* 2) For all in 1 and 1..n list, if 0 such children ->ERROR */
|
||||
for (yc = &ycplist[0]; (int)yc->yc_parent == pk; yc++){
|
||||
for (i=0; i<Y_SPEC; i++){
|
||||
yc = _yc_search[pk][i];
|
||||
if (yc == NULL)
|
||||
continue;
|
||||
if (yc->yc_min &&
|
||||
yang_find(yt, yc->yc_child, NULL) == NULL){
|
||||
clicon_err(OE_YANG, 0, "%s: \"%s\" is missing but is mandatory child of \"%s\"",
|
||||
modname, yang_key2str(yc->yc_child), yang_key2str(pk));
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
/* 3) For all in 0..1 and 1 list, if >1 such children ->ERROR */
|
||||
for (yc = &ycplist[0]; (int)yc->yc_parent == pk; yc++){
|
||||
if (yc->yc_max<NMAX &&
|
||||
(nr = yang_match(yt, yc->yc_child, NULL)) > yc->yc_max){
|
||||
clicon_err(OE_YANG, 0, "%s: \"%s\" has %d children of type \"%s\", but only %d allowed",
|
||||
|
|
@ -569,7 +552,6 @@ yang_cardinality(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* 4) Recurse */
|
||||
i = 0;
|
||||
while (i< yang_len_get(yt)){ /* Note, children may be removed cant use yn_each */
|
||||
|
|
@ -601,7 +583,7 @@ yang_cardinality_interval(clicon_handle h,
|
|||
int retval = -1;
|
||||
const struct ycard *ycplist; /* ycard parent table*/
|
||||
|
||||
if ((ycplist = ycard_find(parent_key, child_key, yclist, 0)) == NULL){
|
||||
if ((ycplist = _yc_search[parent_key][child_key]) == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "keys %d %d do not have cardinality",
|
||||
parent_key, child_key);
|
||||
goto done;
|
||||
|
|
@ -612,3 +594,17 @@ yang_cardinality_interval(clicon_handle h,
|
|||
done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Init */
|
||||
int
|
||||
yang_cardinality_init(clicon_handle h)
|
||||
{
|
||||
const struct ycard *yc;
|
||||
|
||||
for (yc = &_yclist[0]; (int)yc->yc_parent; yc++){
|
||||
_yc_exist[yc->yc_parent] = 1;
|
||||
_yc_search[yc->yc_parent][yc->yc_child] = yc;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
* Prototypes
|
||||
*/
|
||||
int yang_cardinality(clicon_handle h, yang_stmt *yt, char *modname);
|
||||
|
||||
int yang_cardinality_interval(clicon_handle h, enum rfc_6020 parent_key, enum rfc_6020 child_key, int *min, int *max);
|
||||
int yang_cardinality_init(clicon_handle h);
|
||||
|
||||
#endif /* _CLIXON_YANG_CARDINALITY_H_ */
|
||||
|
|
|
|||
|
|
@ -271,9 +271,7 @@ edit table
|
|||
show config netconf
|
||||
EOF
|
||||
new "show config netconf"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><edit-config><target><candidate/></target><config><parameter><name>a</name><value>42</value></parameter></config></edit-config></rpc>]]>]]>'
|
||||
|
||||
endtest
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "<rpc $DEFAULTNS><edit-config><target><candidate/></target><config><parameter><name>a</name><value>42</value></parameter></config></edit-config></rpc>]]>]]>"
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "Kill backend"
|
||||
|
|
@ -287,3 +285,6 @@ if [ $BE -ne 0 ]; then
|
|||
fi
|
||||
|
||||
rm -rf $dir
|
||||
|
||||
new "endtest"
|
||||
endtest
|
||||
|
|
|
|||
|
|
@ -17,12 +17,14 @@ if [ ! -d "$OPENCONFIG" ]; then
|
|||
if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
fi
|
||||
|
||||
OCDIR=$OPENCONFIG/release/models
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>
|
||||
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>$OPENCONFIG</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>$OCDIR</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
|
|
|
|||
125
test/test_openconfig_network_instance.sh
Executable file
125
test/test_openconfig_network_instance.sh
Executable file
|
|
@ -0,0 +1,125 @@
|
|||
#!/usr/bin/env bash
|
||||
# Tests for openconfig network-instances
|
||||
# See eg https://github.com/clicon/clixon/issues/287
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
APPNAME=example
|
||||
|
||||
cfg=$dir/conf_yang.xml
|
||||
fyang=$dir/clixon-example.yang
|
||||
|
||||
new "openconfig"
|
||||
if [ ! -d "$OPENCONFIG" ]; then
|
||||
# err "Hmm Openconfig dir does not seem to exist, try git clone https://github.com/openconfig/public?"
|
||||
echo "...skipped: OPENCONFIG not set"
|
||||
if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
fi
|
||||
|
||||
OCDIR=$OPENCONFIG/release/models
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>
|
||||
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>$OCDIR</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_AUTOCLI_EXCLUDE>clixon-restconf ietf-interfaces</CLICON_CLI_AUTOCLI_EXCLUDE>
|
||||
<CLICON_CLI_GENMODEL_TYPE>VARS</CLICON_CLI_GENMODEL_TYPE>
|
||||
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>true</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
# First using ietf-interfaces (not openconfig-interfaces)
|
||||
# Example yang
|
||||
cat <<EOF > $fyang
|
||||
module clixon-example{
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:example";
|
||||
prefix ex;
|
||||
|
||||
import openconfig-network-instance {
|
||||
prefix oc-netinst;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Example system
|
||||
cat <<EOF > $dir/startup_db
|
||||
<config>
|
||||
<bgp xmlns="http://openconfig.net/yang/bgp">
|
||||
<global>
|
||||
<config>
|
||||
<as>0</as> /* XXX */
|
||||
</config>
|
||||
</global>
|
||||
</bgp>
|
||||
<network-instances xmlns="http://openconfig.net/yang/network-instance">
|
||||
<network-instance>
|
||||
<name>default</name>
|
||||
<fdb>
|
||||
<config>
|
||||
<flood-unknown-unicast-supression>false</flood-unknown-unicast-supression>
|
||||
</config>
|
||||
</fdb>
|
||||
<config>
|
||||
<type>oc-ni-types:DEFAULT_INSTANCE</type>
|
||||
<enabled>true</enabled>
|
||||
<router-id>1.2.3.4</router-id>
|
||||
</config>
|
||||
</network-instance>
|
||||
</network-instances>
|
||||
</config>
|
||||
EOF
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "kill old backend"
|
||||
sudo clixon_backend -zf $cfg
|
||||
if [ $? -ne 0 ]; then
|
||||
err
|
||||
fi
|
||||
sudo pkill -f clixon_backend # to be sure
|
||||
|
||||
new "start backend -s startup -f $cfg"
|
||||
start_backend -s startup -f $cfg
|
||||
fi
|
||||
|
||||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
new "$clixon_cli -D $DBG -1f $cfg show version"
|
||||
expectpart "$($clixon_cli -D $DBG -1f $cfg show version)" 0 "${CLIXON_VERSION}"
|
||||
|
||||
new "$clixon_cli -D $DBG -1f $cfg save config as cli"
|
||||
expectpart "$($clixon_cli -D $DBG -1f $cfg save $dir/config.cli cli)" 0 "^$"
|
||||
|
||||
new "Check saved config"
|
||||
expectpart "$(cat $dir/config.cli)" 0 "set network-instances network-instance default config type oc-ni-types:DEFAULT_INSTANCE" "set network-instances network-instance default config router-id 1.2.3.4"
|
||||
|
||||
new "load saved cli config"
|
||||
expectpart "$(cat $dir/config.cli | $clixon_cli -D $DBG -f $cfg 2>&1 > /dev/null)" 0 "^$"
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "Kill backend"
|
||||
# Check if premature kill
|
||||
pid=$(pgrep -u root -f clixon_backend)
|
||||
if [ -z "$pid" ]; then
|
||||
err "backend already dead"
|
||||
fi
|
||||
# kill backend
|
||||
stop_backend -f $cfg
|
||||
fi
|
||||
|
||||
rm -rf $dir
|
||||
|
||||
new "endtest"
|
||||
endtest
|
||||
179
test/test_openconfig_system.sh
Executable file
179
test/test_openconfig_system.sh
Executable file
|
|
@ -0,0 +1,179 @@
|
|||
#!/usr/bin/env bash
|
||||
# Run a system around openconfig interface, ie: openconfig-if-ethernet
|
||||
# Note first variant uses ietf-interfaces, maybe remove this?
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
APPNAME=example
|
||||
|
||||
cfg=$dir/conf_yang.xml
|
||||
fyang=$dir/clixon-example.yang
|
||||
|
||||
echo "...skipped: wrong"
|
||||
if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
new "openconfig"
|
||||
if [ ! -d "$OPENCONFIG" ]; then
|
||||
# err "Hmm Openconfig dir does not seem to exist, try git clone https://github.com/openconfig/public?"
|
||||
echo "...skipped: OPENCONFIG not set"
|
||||
if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
fi
|
||||
|
||||
OCDIR=$OPENCONFIG/release/models
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>
|
||||
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>$OCDIR</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_AUTOCLI_EXCLUDE>clixon-restconf ietf-interfaces</CLICON_CLI_AUTOCLI_EXCLUDE>
|
||||
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>true</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
# First using ietf-interfaces (not openconfig-interfaces)
|
||||
# Example yang
|
||||
cat <<EOF > $fyang
|
||||
module clixon-example{
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:example";
|
||||
prefix ex;
|
||||
|
||||
import openconfig-system {
|
||||
prefix oc-sys;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Example system
|
||||
cat <<EOF > $dir/startup_db
|
||||
<config>
|
||||
</config>
|
||||
EOF
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "kill old backend"
|
||||
sudo clixon_backend -zf $cfg
|
||||
if [ $? -ne 0 ]; then
|
||||
err
|
||||
fi
|
||||
sudo pkill -f clixon_backend # to be sure
|
||||
|
||||
new "start backend -s startup -f $cfg"
|
||||
start_backend -s startup -f $cfg
|
||||
fi
|
||||
|
||||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
new "$clixon_cli -D $DBG -1f $cfg show version"
|
||||
expectpart "$($clixon_cli -D $DBG -1f $cfg show version)" 0 "${CLIXON_VERSION}"
|
||||
|
||||
new "$clixon_netconf -qf $cfg"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO<rpc $DEFAULTNS><get-config><source><candidate/></source></get-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><data><interfaces xmlns=\"http://openconfig.net/yang/interfaces\"><interface><name>e</name><config><name>e</name><type>ex:eth</type><loopback-mode>false</loopback-mode><enabled>true</enabled></config><hold-time><config><up>0</up><down>0</down></config></hold-time></interface></interfaces></data></rpc-reply>]]>]]>"
|
||||
|
||||
new "cli show configuration"
|
||||
expectpart "$($clixon_cli -1 -f $cfg show conf xml)" 0 "^<interfaces xmlns=\"http://openconfig.net/yang/interfaces\">" --not-- "<oc-eth:ethernet xmlns:oc-eth=\"http://openconfig.net/yang/interfaces/ethernet\">"
|
||||
|
||||
new "cli set interfaces interface <tab> complete: e"
|
||||
expectpart "$(echo "set interfaces interface " | $clixon_cli -f $cfg)" 0 "interface e"
|
||||
|
||||
# XXX See https://github.com/clicon/clixon/issues/218
|
||||
#new "cli set interfaces interface e <tab> complete: not ethernet"
|
||||
#expectpart "$(echo "set interfaces interface e " | $clixon_cli -f $cfg)" 0 config hold-time subinterfaces --not-- ethernet
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "Kill backend"
|
||||
# Check if premature kill
|
||||
pid=$(pgrep -u root -f clixon_backend)
|
||||
if [ -z "$pid" ]; then
|
||||
err "backend already dead"
|
||||
fi
|
||||
# kill backend
|
||||
stop_backend -f $cfg
|
||||
fi
|
||||
|
||||
# Second using openconfig-interfaces instead
|
||||
# Example yang
|
||||
cat <<EOF > $fyang
|
||||
module clixon-example{
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:example";
|
||||
prefix ex;
|
||||
|
||||
import openconfig-vlan {
|
||||
prefix oc-vlan;
|
||||
}
|
||||
import openconfig-if-ethernet {
|
||||
prefix oc-eth;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Example system
|
||||
cat <<EOF > $dir/startup_db
|
||||
<config>
|
||||
<interfaces xmlns="http://openconfig.net/yang/interfaces">
|
||||
<interface>
|
||||
<name>eth1</name>
|
||||
<config>
|
||||
<name>eth1</name>
|
||||
<type>ianaift:ethernetCsmacd</type>
|
||||
<mtu>9206</mtu>
|
||||
<enabled>true</enabled>
|
||||
<oc-vlan:tpid xmlns:oc-vlan="http://openconfig.net/yang/vlan">oc-vlan-types:TPID_0X8100</oc-vlan:tpid>
|
||||
</config>
|
||||
<oc-eth:ethernet xmlns:oc-eth="http://openconfig.net/yang/interfaces/ethernet">
|
||||
<oc-eth:config>
|
||||
<oc-eth:mac-address>2c:53:4a:09:59:73</oc-eth:mac-address>
|
||||
</oc-eth:config>
|
||||
</oc-eth:ethernet>
|
||||
</interface>
|
||||
</interfaces>
|
||||
</config>
|
||||
EOF
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "kill old backend"
|
||||
sudo clixon_backend -zf $cfg
|
||||
if [ $? -ne 0 ]; then
|
||||
err
|
||||
fi
|
||||
sudo pkill -f clixon_backend # to be sure
|
||||
|
||||
new "start backend -s startup -f $cfg"
|
||||
start_backend -s startup -f $cfg
|
||||
fi
|
||||
|
||||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
new "$clixon_cli -D $DBG -1f $cfg show version"
|
||||
expectpart "$($clixon_cli -D $DBG -1f $cfg show version)" 0 "${CLIXON_VERSION}"
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "Kill backend"
|
||||
# Check if premature kill
|
||||
pid=$(pgrep -u root -f clixon_backend)
|
||||
if [ -z "$pid" ]; then
|
||||
err "backend already dead"
|
||||
fi
|
||||
# kill backend
|
||||
stop_backend -f $cfg
|
||||
fi
|
||||
|
||||
|
||||
rm -rf $dir
|
||||
|
||||
new "endtest"
|
||||
endtest
|
||||
|
|
@ -162,6 +162,7 @@ main(int argc,
|
|||
break;
|
||||
}
|
||||
clicon_debug_init(dbg, NULL);
|
||||
yang_init(h);
|
||||
|
||||
/* Parse yang */
|
||||
if (yang_file_dir){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue