experimental netconf yang spec

This commit is contained in:
Olof hagsand 2017-12-08 19:37:09 +01:00
parent 822aac18a1
commit 056b5c97dd
16 changed files with 250 additions and 147 deletions

View file

@ -167,6 +167,9 @@ int clicon_dbspec_yang_set(clicon_handle h, struct yang_spec *ys);
char *clicon_dbspec_name(clicon_handle h);
int clicon_dbspec_name_set(clicon_handle h, char *name);
yang_spec *clicon_netconf_yang(clicon_handle h);
int clicon_netconf_yang_set(clicon_handle h, struct yang_spec *ys);
plghndl_t clicon_xmldb_plugin_get(clicon_handle h);
int clicon_xmldb_plugin_set(clicon_handle h, plghndl_t handle);

View file

@ -223,7 +223,8 @@ cg_var *ys_parse(yang_stmt *ys, enum cv_type cvtype);
int ys_parse_sub(yang_stmt *ys);
int yang_mandatory(yang_stmt *ys);
int yang_config(yang_stmt *ys);
int yang_spec_main(clicon_handle h, FILE *f, int printspec);
yang_spec *yang_spec_netconf(clicon_handle h);
yang_spec *yang_spec_main(clicon_handle h);
cvec *yang_arg2cvec(yang_stmt *ys, char *delimi);
int yang_key_match(yang_node *yn, char *name);

View file

@ -382,8 +382,6 @@ clicon_options_main(clicon_handle h)
/* Read configfile */
if (clicon_option_readfile_xml(copt, configfile, yspec) < 0)
goto done;
if (yspec)
yspec_free(yspec);
}
else {
#ifdef CONFIG_COMPAT
@ -402,6 +400,9 @@ clicon_options_main(clicon_handle h)
}
retval = 0;
done:
if (yspec) /* The clixon yang-spec is not used after this */
yspec_free(yspec);
return retval;
}
@ -704,7 +705,7 @@ clicon_quiet_mode_set(clicon_handle h, int val)
return clicon_option_int_set(h, "CLICON_QUIET", val);
}
/*! Get YANG specification
/*! Get YANG specification for application
* Must use hash functions directly since they are not strings.
*/
yang_spec *
@ -719,7 +720,7 @@ clicon_dbspec_yang(clicon_handle h)
return NULL;
}
/*! Set yang database specification
/*! Set yang specification for application
* ys must be a malloced pointer
*/
int
@ -736,6 +737,39 @@ clicon_dbspec_yang_set(clicon_handle h,
return 0;
}
/*! Get YANG NETCONF specification
* Must use hash functions directly since they are not strings.
*/
yang_spec *
clicon_netconf_yang(clicon_handle h)
{
clicon_hash_t *cdat = clicon_data(h);
size_t len;
void *p;
if ((p = hash_value(cdat, "netconf_yang", &len)) != NULL)
return *(yang_spec **)p;
return NULL;
}
/*! Set yang netconf specification
* ys must be a malloced pointer
*/
int
clicon_netconf_yang_set(clicon_handle h,
struct yang_spec *ys)
{
clicon_hash_t *cdat = clicon_data(h);
/* It is the pointer to ys that should be copied by hash,
so we send a ptr to the ptr to indicate what to copy.
*/
if (hash_add(cdat, "netconf_yang", &ys, sizeof(ys)) == NULL)
return -1;
return 0;
}
/*! Get dbspec name as read from spec. Can be used in CLI '@' syntax.
* XXX: this we muśt change,...
*/

View file

@ -136,7 +136,7 @@ xml_parse_qname(struct xml_parse_yacc_arg *ya,
{
int retval = -1;
cxobj *x;
yang_stmt *y=NULL; /* yang node */
yang_stmt *y = NULL; /* yang node */
cxobj *xp; /* xml parent */
xp = ya->ya_xparent;

View file

@ -1527,7 +1527,7 @@ yang_parse_recurse(clicon_handle h,
if ((nr = yang_parse_find_match(h, yang_dir, module, fbuf)) < 0)
goto done;
if (nr == 0){
clicon_err(OE_YANG, errno, "No matching %s yang files found (expected modulenameor absolute filename)", module);
clicon_err(OE_YANG, errno, "No matching %s yang files found (expected module name or absolute filename)", module);
goto done;
}
}
@ -1820,7 +1820,6 @@ yang_abs_schema_nodeid(yang_spec *yspec,
yang_stmt *ymod;
char *id;
char *prefix = NULL;
yang_stmt *yprefix;
/* check absolute schema_nodeid */
@ -2024,24 +2023,36 @@ yang_config(yang_stmt *ys)
return 1;
}
/*! Utility function for handling yang parsing and translation to key format
/*! Parse netconf yang spec, used by netconf client and as internal protocol */
yang_spec *
yang_spec_netconf(clicon_handle h)
{
yang_spec *yspec = NULL;
if ((yspec = yspec_new()) == NULL)
goto done;
if (yang_parse(h, CLIXON_DATADIR, "ietf-netconf", NULL, yspec) < 0){
yspec_free(yspec); yspec = NULL;
goto done;
}
clicon_netconf_yang_set(h, yspec);
done:
return yspec;
}
/*! Read, parse and save application yang specification as option
* @param h clicon handle
* @param f file to print to (if printspec enabled)
* @param printspec print database (YANG) specification as read from file
*/
int
yang_spec_main(clicon_handle h,
FILE *f,
int printspec)
yang_spec*
yang_spec_main(clicon_handle h)
{
yang_spec *yspec;
yang_spec *yspec = NULL;
char *yang_dir;
char *yang_module;
char *yang_revision;
int retval = -1;
if ((yspec = yspec_new()) == NULL)
goto done;
if ((yang_dir = clicon_yang_dir(h)) == NULL){
clicon_err(OE_FATAL, 0, "CLICON_YANG_DIR option not set");
goto done;
@ -2052,14 +2063,15 @@ yang_spec_main(clicon_handle h,
goto done;
}
yang_revision = clicon_yang_module_revision(h);
if (yang_parse(h, yang_dir, yang_module, yang_revision, yspec) < 0)
if ((yspec = yspec_new()) == NULL)
goto done;
if (yang_parse(h, yang_dir, yang_module, yang_revision, yspec) < 0){
yspec_free(yspec); yspec = NULL;
goto done;
}
clicon_dbspec_yang_set(h, yspec);
if (printspec)
yang_print(f, (yang_node*)yspec);
retval = 0;
done:
return retval;
return yspec;
}
/*! Given a yang node, translate the argument string to a cv vector

View file

@ -184,7 +184,8 @@ clicon_yang_debug(int d)
also called from yacc generated code *
*/
void
clixon_yang_parseerror(void *_yy, char *s)
clixon_yang_parseerror(void *_yy,
char *s)
{
clicon_err(OE_YANG, 0, "%s on line %d: %s at or before: '%s'",
_YY->yy_name,
@ -195,7 +196,8 @@ clixon_yang_parseerror(void *_yy, char *s)
}
int
yang_parse_init(struct clicon_yang_yacc_arg *yy, yang_spec *ysp)
yang_parse_init(struct clicon_yang_yacc_arg *yy,
yang_spec *ysp)
{
return 0;
}
@ -219,7 +221,8 @@ ystack_pop(struct clicon_yang_yacc_arg *yy)
}
struct ys_stack *
ystack_push(struct clicon_yang_yacc_arg *yy, yang_node *yn)
ystack_push(struct clicon_yang_yacc_arg *yy,
yang_node *yn)
{
struct ys_stack *ystack;
@ -240,8 +243,8 @@ ystack_push(struct clicon_yang_yacc_arg *yy, yang_node *yn)
*/
static yang_stmt *
ysp_add(struct clicon_yang_yacc_arg *yy,
enum rfc_6020 keyword,
char *argument)
enum rfc_6020 keyword,
char *argument)
{
struct ys_stack *ystack = yy->yy_stack;
yang_stmt *ys = NULL;
@ -272,7 +275,9 @@ ysp_add(struct clicon_yang_yacc_arg *yy,
/*! combination of ysp_add and ysp_push for sub-modules */
static yang_stmt *
ysp_add_push(struct clicon_yang_yacc_arg *yy, int keyword, char *argument)
ysp_add_push(struct clicon_yang_yacc_arg *yy,
int keyword,
char *argument)
{
yang_stmt *ys;
@ -286,7 +291,8 @@ ysp_add_push(struct clicon_yang_yacc_arg *yy, int keyword, char *argument)
/* identifier-ref-arg-str has a [prefix :] id and prefix_id joins the id with an
optional prefix into a single string */
static char*
prefix_id_join(char *prefix, char *id)
prefix_id_join(char *prefix,
char *id)
{
char *str;
int len;
@ -333,7 +339,7 @@ module_stmt : K_MODULE id_arg_str
}
'{' module_substmts '}'
{ if (ystack_pop(_yy) < 0) _YYERROR("2");
clicon_debug(2,"module -> id-arg-str { module-substmts }");}
clicon_debug(2,"module_stmt -> id-arg-str { module-substmts }");}
;
module_substmts : module_substmts module_substmt
@ -693,7 +699,7 @@ anyxml_substmt : when_stmt { clicon_debug(2,"anyxml-substmt -> when-st
| status_stmt { clicon_debug(2,"anyxml-substmt -> status-stmt"); }
| description_stmt { clicon_debug(2,"anyxml-substmt -> description-stmt"); }
| reference_stmt { clicon_debug(2,"anyxml-substmt -> reference-stmt"); }
| ustring ':' ustring ';' { clicon_debug(2,"anyxml-substmt -> anyxml extension"); }
| ustring ':' ustring ';' { free($1); free($3); clicon_debug(2,"anyxml-substmt -> anyxml extension"); }
;
/* uses */