This article is out of date!

Do not use!

Go to Online Documentation Instead!

https://docs.yumaworks.com/en/latest/dev/rpc-interface.html#rpc-data-output-handling



The server supports RPC operations defined in any YANG module, and the code can be contained in a SIL library.


In order to properly return output data the correct object templates must be used.

The "output" object must be retrieved so child nodes can be found that represent the actual data to return.


    obj_template_t *obj = RPC_MSG_METHOD(msg);
    if (obj) {
        obj = obj_find_child(obj, NULL, NCX_EL_OUTPUT);
    }
    if (obj == NULL) {
        return ERR_NCX_DEF_NOT_FOUND;  // should not happen
    }


There are 3 simple steps for returning data in an RPC operation:

  1. Create a val_value_t node for each data node to be returned
  2. Add data to the rpc_dataQ in the repsonse message
  3. Set the data type in the response message


    dlq_enque(msgindentval, &msg->rpc_dataQ);
    msg->rpc_data_type = RPC_DATA_YANG;

You can find RPC examples, such as <get-my-session> and <set-my-session> RPC, in the attached YANG module sample-mysession.yang


Since there are no input parameters for the <get-my-session> operation, there is no need for the RPC validate callback. However, the RPC invoke callback is still needed.

The <set-my-session> SIL callback code does not need to do any validation other than the YANG validation done by the server, so there is no RPC validate callback needed in this case. However, there may be Validate callback if there is a need to enforce more validation on parameters. The RPC invoke function is also allowed to return an error (e.g., resource not available). This function gets the input parameters from the message and then modifies the current session with these parameters.

The source code (SIL code for sample-mysession YANG module) sample-mysession.c and .h can be found in the attachments. The SIL library is ready to be compiled and it is modified to support <set-my-session> and <get-my-session> RPC operations.

What is left is to compile the SIL code first:


> cd  sample-mysession
> make
> make install

And then start the server with --module=sample-mysession CLI parameter:


> netconfd-pro --module=sample-mysession log-level=debug4

After that a client application can send RPC requests. The output of the <get-my-session> RPC request may look as follows:


{
    "sample-mysession:output": {
        "indent": "2",
        "linesize": "72",
        "message-indent": "-1",
        "with-defaults": "explicit"
    }
}