CliXoN
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions
netconf_rpc.c File Reference
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include <fcntl.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/param.h>
#include <assert.h>
#include <grp.h>
#include <cligen/cligen.h>
#include <clixon/clixon.h>
#include "clixon_netconf.h"
#include "netconf_lib.h"
#include "netconf_filter.h"
#include "netconf_plugin.h"
#include "netconf_rpc.h"

Functions

static int netconf_get_config (clicon_handle h, cxobj *xn, cxobj **xret)
 
static int get_edit_opts (cxobj *xn, enum test_option *testopt, enum error_option *erropt, cxobj **xret)
 
static int netconf_edit_config (clicon_handle h, cxobj *xn, cxobj **xret)
 
static int netconf_copy_config (clicon_handle h, cxobj *xn, cxobj **xret)
 
static int netconf_delete_config (clicon_handle h, cxobj *xn, cxobj **xret)
 
static int netconf_lock (clicon_handle h, cxobj *xn, cxobj **xret)
 
static int netconf_unlock (clicon_handle h, cxobj *xn, cxobj **xret)
 
static int netconf_close_session (clicon_handle h, cxobj *xn, cxobj **xret)
 
static int netconf_kill_session (clicon_handle h, cxobj *xn, cxobj **xret)
 
static int netconf_validate (clicon_handle h, cxobj *xn, cxobj **xret)
 
static int netconf_commit (clicon_handle h, cxobj *xn, cxobj **xret)
 
static int netconf_discard_changes (clicon_handle h, cxobj *xn, cxobj **xret)
 
static int netconf_notification_cb (int s, void *arg)
 
static int netconf_create_subscription (clicon_handle h, cxobj *xn, cxobj **xret)
 
int netconf_rpc_dispatch (clicon_handle h, cxobj *xn, cxobj **xret)
 

Function Documentation

static int get_edit_opts ( cxobj *  xn,
enum test_option testopt,
enum error_option erropt,
cxobj **  xret 
)
static
static int netconf_close_session ( clicon_handle  h,
cxobj *  xn,
cxobj **  xret 
)
static

Close a (user) session <close-session/>

Parameters
[in]xnSub-tree (under xorig) at <rpc>...</rpc> level.
[out]xretReturn XML, error or OK
static int netconf_commit ( clicon_handle  h,
cxobj *  xn,
cxobj **  xret 
)
static

Commit candidate -> running <commit> :candidate

Parameters
[in]hclicon handle
[in]xnSub-tree (under xorig) at <rpc>...</rpc> level.
[out]xretReturn XML, error or OK
static int netconf_copy_config ( clicon_handle  h,
cxobj *  xn,
cxobj **  xret 
)
static

Netconf copy configuration <copy-config> <target> <candidate> </target> <source> <url> <!- - location specifier for file containing the new configuration - -> </url> </source> <copy-config>

Parameters
[in]hclicon handle
[in]xnSub-tree (under xorig) at <rpc>...</rpc> level.
[out]xretReturn XML, error or OK
static int netconf_create_subscription ( clicon_handle  h,
cxobj *  xn,
cxobj **  xret 
)
static
static int netconf_delete_config ( clicon_handle  h,
cxobj *  xn,
cxobj **  xret 
)
static

Delete configuration <delete-config> <target> <candidate> </target> </delete-config> Delete a configuration datastore. The <running> configuration datastore cannot be deleted.

Parameters
[in]hclicon handle
[in]xnSub-tree (under xorig) at <rpc>...</rpc> level.
[out]xretReturn XML, error or OK
static int netconf_discard_changes ( clicon_handle  h,
cxobj *  xn,
cxobj **  xret 
)
static

Discard all changes in candidate / revert to running <discard-changes/> :candidate

Parameters
[in]hclicon handle
[in]xnSub-tree (under xorig) at <rpc>...</rpc> level.
[out]xretReturn XML, error or OK
static int netconf_edit_config ( clicon_handle  h,
cxobj *  xn,
cxobj **  xret 
)
static

Netconf edit configuration Write the change on a tmp file, then load that into candidate configuration. <edit-config> <target> <candidate> </target>

<!- - EITHER - ->

<config> 
    <configuration> 
        <!- - tag elements representing the data to incorporate - -> 
    </configuration> 
</config> 

<!- - OR - ->

<config-text> 
    <configuration-text> 
        <!- - tag elements inline configuration data in text format - -> 
    </configuration-text> 
</config-text> 

<!- - OR - ->

<url> 
    <!- - location specifier for file containing data - -> 
</url> 

<default-operation>(merge | none | replace)</default-operation> 
<error-option>(stop-on-error | continue-on-error )</error-option> 
<test-option>(set | test-then-set | test-only)</test-option> 

<edit-config>

CLIXON addition: <filter type="restconf" select="/data/profile=a">

Parameters
[in]hclicon handle
[in]xnSub-tree (under xorig) at <rpc>...</rpc> level.
[out]xretReturn XML, error or OK
Return values
0OK, xret points to valid return, either ok or rpc-error
-1Error only 'config' supported error-option: only stop-on-error supported test-option: not supported
Note
erropt, testopt only supports default
static int netconf_get_config ( clicon_handle  h,
cxobj *  xn,
cxobj **  xret 
)
static

Get configuration

Parameters
[in]hClicon handle
[in]xnSub-tree (under xorig) at <rpc>...</rpc> level.
[out]xretReturn XML, error or OK
Note
filter type subtree and xpath is supported, but xpath is preferred, and better performance and tested. Please use xpath.

<get-config> <source> <candidate> | <running> </source> </get-config>

<get-config> <source> <candidate> | <running> </source> <filter type="subtree"> <configuration> <!- - tag elements for each configuration element to return - -> </configuration> </filter> </get-config>

Example: <rpc><get-config><source><running></source> <filter type="xpath" select="//SenderTwampIpv4"> </get-config></rpc>]]>]]> Variants of the functions where x-axis is the variants of the <filter> clause and y-axis is whether a <filter><configuration> or <filter select=""> is present. | no filter | filter subnet | filter xpath | --------------—+--------—+------------—+-----------—+ no config | | | | --------------—+--------—+------------—+-----------—+ config/select | - | | | --------------—+--------—+------------—+-----------—+ Example requests of each: no filter + no config <rpc><get-config><source><candidate></source></get-config></rpc>]]>]]> filter subnet + no config: <rpc><get-config><source><candidate></source><filter></get-config></rpc>]]>]]> filter xpath + select all: <rpc><get-config><source><candidate></source><filter type="xpath" select="/"></get-config></rpc>]]>]]> filter subtree + config: <rpc><get-config><source><candidate></source><filter type="subtree"><configuration><interfaces><interface><ipv4><enabled></ipv4></interface></interfaces></configuration></filter></get-config></rpc>]]>]]> filter xpath + select: <rpc><get-config><source><candidate></source><filter type="xpath" select="/interfaces/interface/ipv4"></get-config></rpc>]]>]]>

static int netconf_kill_session ( clicon_handle  h,
cxobj *  xn,
cxobj **  xret 
)
static

Kill other user sessions <kill-session> <session-id>PID</session-id> </kill-session>

Parameters
[in]xnSub-tree (under xorig) at <rpc>...</rpc> level.
[out]xretReturn XML, error or OK
static int netconf_lock ( clicon_handle  h,
cxobj *  xn,
cxobj **  xret 
)
static

Lock a database <lock> <target> <candidate> </target> </lock>

Parameters
[in]hclicon handle
[in]xnSub-tree (under xorig) at <rpc>...</rpc> level.
[out]xretReturn XML, error or OK
static int netconf_notification_cb ( int  s,
void *  arg 
)
static

Called when a notification has happened on backend and this session has registered for that event. Filter it and forward it. <notification> <eventTime>2007-07-08T00:01:00Z</eventTime> <event xmlns="http://example.com/event/1.0"> <eventClass>fault</eventClass> <reportingEntity> <card>Ethernet0</card> </reportingEntity> <severity>major</severity> </event> </notification>

int netconf_rpc_dispatch ( clicon_handle  h,
cxobj *  xn,
cxobj **  xret 
)

The central netconf rpc dispatcher. Look at first tag and dispach to sub-functions. Call plugin handler if tag not found. If not handled by any handler, return error.

Parameters
[in]hclicon handle
[in]xnSub-tree (under xorig) at <rpc>...</rpc> level.
[out]xretReturn XML, error or OK
static int netconf_unlock ( clicon_handle  h,
cxobj *  xn,
cxobj **  xret 
)
static

Unlock a database <unlock> <target> <candidate> </target> </unlock> XXX

Parameters
[in]hclicon handle
[in]xnSub-tree (under xorig) at <rpc>...</rpc> level.
[out]xretReturn XML, error or OK
static int netconf_validate ( clicon_handle  h,
cxobj *  xn,
cxobj **  xret 
)
static

Check the semantic consistency of candidate <validate> :validate

Parameters
[in]hclicon handle
[in]xnSub-tree (under xorig) at <rpc>...</rpc> level.
[out]xretReturn XML, error or OK