CESNET / libnetconf2

C NETCONF library
BSD 3-Clause "New" or "Revised" License
203 stars 147 forks source link

How do I use libnetconf2 to customize my rpc #438

Open Jarvenhuaijin opened 1 year ago

Jarvenhuaijin commented 1 year ago

I created a new yang file based on the work of others, and compiled it according to the sample server and client

module demo-mac {
    namespace "urn:demo:demo-mac";
    prefix demo-mac;
    rpc mac-address-clear {
        input {
            leaf mac-address-type {
                type enumeration {
                    enum dynamic;
                    enum static;
                    enum filter;
                }
            }
        }
        output {
            leaf result {
                type int32;
            }
        }
    }
}

The following is the rpc reply that handles the model on the server side.

if (!strcmp("mac-address-clear", rpc->schema->name))
    {
        struct lyd_node *data;
        LY_ERR err = lyd_new_path(NULL, nc_session_get_ctx(session) , "/demo-mac:mac-address-clear/result", "1", LYD_NEW_PATH_OUTPUT, &data);

        Debug("err: %d", err);

        return nc_server_reply_data(data, NC_WD_EXPLICIT, NC_PARAMTYPE_FREE);
    }

I have tried to execute the above callback no matter what the client sends, but the terminal shows the following error, and I exactly executed this sentence

ly_ctx_load_module(*context, "demo-mac", NULL, NULL)
libyang[0]: No module with namespace "urn:demo:demo-mac" in the context. (path: Line number 1.)
Session 1 [ERR]: Received an invalid message (No module with namespace "urn:demo:demo-mac" in the context.).
ERR_MSG_CLEANUP:Couldn't receive a reply from the server

How can I make a custom rpc request in my client and correctly progress it in my server.

michalvasko commented 1 year ago

It would seem ly_ctx_load_module(*context, "demo-mac", NULL, NULL) fails to load the module, I guess you are not even checking for errors. If you have not set up the search directory correctly, use lys_parse_path() instead.

Jarvenhuaijin commented 1 year ago

My server got its returned ly_error type is correctly loaded into the module, now I want to know how the client custom rpc send instead of through ietf standards, is using the nc_rpc_act_generic function?

michalvasko commented 1 year ago

Yes, create the RPC using libyang and then send it by calling nc_rpc_act_generic().