Added YANG RPC support, with example rpc documentation and testcase (test7.sh); Extended example with ietf-routing (not only ietf-ip).
This commit is contained in:
parent
f995f1e268
commit
e56cf607a3
17 changed files with 177 additions and 112 deletions
|
|
@ -196,26 +196,28 @@ catch:
|
|||
return -1;
|
||||
}
|
||||
|
||||
/*! Struct to carry info into and out of ys_find_rpc callback
|
||||
*/
|
||||
typedef struct {
|
||||
char *name; /* name of rpc */
|
||||
yang_stmt *yrpc; /* matching yang statement */
|
||||
} find_rpc_arg;
|
||||
|
||||
/*! Check yang rpc statement, return yang rpc statement if found
|
||||
*/
|
||||
static int
|
||||
ys_find_rpc(yang_stmt *ys,
|
||||
void *arg)
|
||||
{
|
||||
cxobj *xn = (cxobj*)arg;
|
||||
char *name = xml_name(xn);
|
||||
find_rpc_arg *fra = (find_rpc_arg*)arg;
|
||||
|
||||
if (ys->ys_keyword == Y_RPC && strcmp(name, ys->ys_argument) == 0){
|
||||
/*
|
||||
* XXX
|
||||
* 1. Check xn arguments with input statement.
|
||||
* 2. Send to backend as clicon_msg-encode()
|
||||
* 3. In backend to similar but there call actual backend
|
||||
*/
|
||||
if (strcmp(fra->name, ys->ys_argument) == 0){
|
||||
fra->yrpc = ys;
|
||||
return 1; /* handled */
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*! See if there is any callback registered for this tag
|
||||
*
|
||||
* @param[in] h clicon handle
|
||||
|
|
@ -234,6 +236,10 @@ netconf_plugin_callbacks(clicon_handle h,
|
|||
int retval = -1;
|
||||
netconf_reg_t *nreg;
|
||||
yang_spec *yspec;
|
||||
yang_stmt *yrpc;
|
||||
yang_stmt *yinput;
|
||||
find_rpc_arg fra = {0,0};
|
||||
int ret;
|
||||
|
||||
if (deps != NULL){
|
||||
nreg = deps;
|
||||
|
|
@ -249,8 +255,33 @@ netconf_plugin_callbacks(clicon_handle h,
|
|||
clicon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
goto done;
|
||||
}
|
||||
if (yang_apply((yang_node*)yspec, ys_find_rpc, xn) < 0)
|
||||
/* Find yang rpc statement, return yang rpc statement if found */
|
||||
fra.name = xml_name(xn);
|
||||
if ((ret = yang_apply((yang_node*)yspec, Y_RPC, ys_find_rpc, &fra)) < 0)
|
||||
goto done;
|
||||
/* Check if found */
|
||||
if (ret == 1){
|
||||
yrpc = fra.yrpc;
|
||||
if ((yinput = yang_find((yang_node*)yrpc, Y_INPUT, NULL)) != NULL){
|
||||
xml_spec_set(xn, yinput); /* needed for xml_spec_populate */
|
||||
if (xml_apply(xn, CX_ELMNT, xml_spec_populate, yinput) < 0)
|
||||
goto done;
|
||||
if (xml_apply(xn, CX_ELMNT,
|
||||
(xml_applyfn_t*)xml_yang_validate_all, NULL) < 0)
|
||||
goto done;
|
||||
if (xml_yang_validate_add(xn, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
/*
|
||||
* 1. Check xn arguments with input statement.
|
||||
* 2. Send to backend as clicon_msg-encode()
|
||||
* 3. In backend to similar but there call actual backend
|
||||
*/
|
||||
if (clicon_rpc_netconf_xml(h, xml_parent(xn), xret, NULL) < 0)
|
||||
goto done;
|
||||
retval = 1; /* handled by callback */
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue