TAPI for libnetconf client functions

Overview

// global functions

void rpc_nc_libssh_thread_verbosity(rcf_rpc_server* rpcs, rpc_nc_verb_level level);
void rpc_nc_session_free(rcf_rpc_server* rpcs, struct rpc_nc_session* session);
void rpc_nc_client_init(rcf_rpc_server* rpcs);
void rpc_nc_client_destroy(rcf_rpc_server* rpcs);
int rpc_nc_client_ssh_set_username(rcf_rpc_server* rpcs, const char* username);
int rpc_nc_client_ssh_add_keypair(rcf_rpc_server* rpcs, const char* pub_key, const char* priv_key);
struct rpc_nc_session* rpc_nc_connect_ssh(rcf_rpc_server* rpcs, const char* host, uint16_t port);
RPC_NC_MSG_TYPE rpc_nc_send_rpc(rcf_rpc_server* rpcs, struct rpc_nc_session* session, struct rpc_nc_rpc* rpc, int timeout, uint64_t* msg_id);
RPC_NC_MSG_TYPE rpc_nc_recv_reply(rcf_rpc_server* rpcs, struct rpc_nc_session* session, struct rpc_nc_rpc* rpc, uint64_t msgid, int timeout, char** envp, char** op);
struct rpc_nc_rpc* rpc_nc_rpc_get(rcf_rpc_server* rpcs, const char* filter, RPC_NC_WD_MODE wd_mode);
struct rpc_nc_rpc* rpc_nc_rpc_getconfig(rcf_rpc_server* rpcs, RPC_NC_DATASTORE source, const char* filter, RPC_NC_WD_MODE wd_mode);
struct rpc_nc_rpc* rpc_nc_rpc_edit(rcf_rpc_server* rpcs, RPC_NC_DATASTORE target, RPC_NC_RPC_EDIT_DFLTOP default_op, RPC_NC_RPC_EDIT_TESTOPT test_opt, RPC_NC_RPC_EDIT_ERROPT error_opt, const char* edit_content);
struct rpc_nc_rpc* rpc_nc_rpc_copy(rcf_rpc_server* rpcs, RPC_NC_DATASTORE target, const char* url_trg, RPC_NC_DATASTORE source, const char* url_or_config_src, RPC_NC_WD_MODE wd_mode);
void rpc_nc_rpc_free(rcf_rpc_server* rpcs, struct rpc_nc_rpc* rpc);

Detailed Documentation

Global Functions

void rpc_nc_libssh_thread_verbosity(rcf_rpc_server* rpcs, rpc_nc_verb_level level)

Set libssh verbosity level

Parameters:

rps

RPC server

level

Verbosity level value

void rpc_nc_session_free(rcf_rpc_server* rpcs, struct rpc_nc_session* session)

Free the NETCONF session object.

Parameters:

rpcs

RPC server

session

Pointer to the netconf session object

void rpc_nc_client_init(rcf_rpc_server* rpcs)

Initialize libssh and/or libssl/libcrypto for use in the client.

Parameters:

rpcs

RPC server

void rpc_nc_client_destroy(rcf_rpc_server* rpcs)

Destroy all libssh and/or libssl/libcrypto dynamic memory and the client options, for both SSH and TLS, and for Call Home too.

Parameters:

rpcs

RPC server

int rpc_nc_client_ssh_set_username(rcf_rpc_server* rpcs, const char* username)

Set client SSH username used for authentication.

Parameters:

rpcs

RPC server

username

SSH user name.

Returns:

0 - on success -1 -on fault.

int rpc_nc_client_ssh_add_keypair(rcf_rpc_server* rpcs, const char* pub_key, const char* priv_key)

Add an SSH public and private key pair to be used for client authentication. Private key can be encrypted, the passphrase will be asked for before using it.

Parameters:

rpcs

RPC server

pub_key

Path to the public key.

priv_key

Path to the private key.

Returns:

0 - on success -1 -on fault.

struct rpc_nc_session* rpc_nc_connect_ssh(rcf_rpc_server* rpcs, const char* host, uint16_t port)

Connect to the NETCONF server using SSH transport (via libssh).

Parameters:

rpcs

RPC server

host

Hostname or address (both Ipv4 and IPv6 are accepted) of the target server. ‘localhost’ is used by default if NULL is specified.

port

Port number of the target server. Default value 830 is used if 0 is specified.

Returns:

pointer to the created NETCONF session structure or NULL

RPC_NC_MSG_TYPE rpc_nc_send_rpc(rcf_rpc_server* rpcs, struct rpc_nc_session* session, struct rpc_nc_rpc* rpc, int timeout, uint64_t* msg_id)

Send NETCONF RPC message via the session.

Parameters:

rpcs

TA RPC server

session

NETCONF session where the RPC will be written.

rpc

NETCONF RPC object to send via the specified session.

timeout

Timeout for writing in milliseconds. Use negative value for infinite waiting and 0 for return if data cannot be sent immediately.

msgid

If RPC was successfully sent, this is it’s message ID.

#RPC_NC_MSG_RPC

on success, #RPC_NC_MSG_WOULDBLOCK in case of a busy session, and #RPC_NC_MSG_ERROR on error.

RPC_NC_MSG_TYPE rpc_nc_recv_reply(rcf_rpc_server* rpcs, struct rpc_nc_session* session, struct rpc_nc_rpc* rpc, uint64_t msgid, int timeout, char** envp, char** op)

Receive NETCONF RPC reply.

This function can be called in a single thread only.

Parameters:

rpcs

RPC server

session

NETCONF session from which the function gets data. It must be the client side session object.

rpc

Original RPC this should be the reply to.

msgid

Expected message ID of the reply.

timeout

Timeout for reading in milliseconds. Use negative value for infinite waiting and 0 for immediate return if data are not available on the wire.

envp

Location for NETCONF rpc-reply in XML form. Optional, may be NULL.

op

Location for parsed NETCONF reply data in XML form, if any (none for <ok> or error replies). Set only on #NC_MSG_REPLY and #NC_MSG_REPLY_ERR_MSGID return. Optional, may be NULL.

#RPC_NC_MSG_REPLY

for success, #RPC_NC_MSG_WOULDBLOCK if timeout has elapsed, #RPC_NC_MSG_ERROR if reading has failed, #RPC_NC_MSG_NOTIF if a notification was read instead (call this function again to get the reply), and #RPC_NC_MSG_REPLY_ERR_MSGID if a reply with missing or wrong message-id was received.

struct rpc_nc_rpc* rpc_nc_rpc_get(rcf_rpc_server* rpcs, const char* filter, RPC_NC_WD_MODE wd_mode)

libnetconf2/messages_client.h

Note: Originally many functions in this library have argument ‘paramtype’ to specify what the function will do with pointer-type arguments. See library header. The variants are NC_PARAMTYPE_CONST: use the parameter directly, do not free NC_PARAMTYPE_FREE: use the parameter directly, free afterwards NC_PARAMTYPE_DUP_AND_FREE: make a copy of the argument, free afterwards Only the first variant looks like reasonable for TAPI RPC. So the ‘paramtype’ argument will be omitted and all functions will be called by RPC server with paramtype==NC_PARAMTYPE_CONST Create NETCONF RPC <get> object.

Parameters:

rpcs

RPC server

filter

Optional filter data, an XML subtree or XPath expression (with JSON prefixes).

wd_mode

Optional with-defaults capability mode.

Returns:

Pointer to NETCONF RPC object.

struct rpc_nc_rpc* rpc_nc_rpc_getconfig(rcf_rpc_server* rpcs, RPC_NC_DATASTORE source, const char* filter, RPC_NC_WD_MODE wd_mode)

Create NETCONF RPC <get-config>

Parameters:

rpcs

RPC server

source

Source datastore being queried.

filter

Optional filter data, an XML subtree or XPath expression (with JSON prefixes).

wd_mode

Optional with-defaults capability mode.

Returns:

Pointer to NETCONF RPC object.

struct rpc_nc_rpc* rpc_nc_rpc_edit(rcf_rpc_server* rpcs, RPC_NC_DATASTORE target, RPC_NC_RPC_EDIT_DFLTOP default_op, RPC_NC_RPC_EDIT_TESTOPT test_opt, RPC_NC_RPC_EDIT_ERROPT error_opt, const char* edit_content)

Create NETCONF RPC <edit-config>

Parameters:

rpcs

RPC server

target

Target datastore being edited.

default_op

Optional default operation.

test_opt

Optional test option.

error_opt

Optional error option.

edit_content

Config or URL where the config to perform is to be found.

Returns:

Pointer to NETCONF RPC object.

struct rpc_nc_rpc* rpc_nc_rpc_copy(rcf_rpc_server* rpcs, RPC_NC_DATASTORE target, const char* url_trg, RPC_NC_DATASTORE source, const char* url_or_config_src, RPC_NC_WD_MODE wd_mode)

Create NETCONF RPC <copy-config>

Parameters:

rpcs

RPC server

target

Target datastore being edited.

url_trg

Used instead target if the target is an URL.

source

Source datastore.

url_or_config_src

Used instead source if the source is an URL or a config.

wd_mode

Optional with-defaults capability mode.

Returns:

Pointer to NETCONF RPC object.

void rpc_nc_rpc_free(rcf_rpc_server* rpcs, struct rpc_nc_rpc* rpc)

Free the NETCONF RPC object

Parameters:

rpcs

RPC server

rpc

Pointer to RPC object to free.