Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use libnetconf2 to customize my rpc #438

Open
Jarvenhuaijin opened this issue Oct 9, 2023 · 3 comments
Open

How do I use libnetconf2 to customize my rpc #438

Jarvenhuaijin opened this issue Oct 9, 2023 · 3 comments
Labels
is:question Issue is actually a question.

Comments

@Jarvenhuaijin
Copy link

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
Copy link
Member

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.

@michalvasko michalvasko added the is:question Issue is actually a question. label Oct 10, 2023
@Jarvenhuaijin
Copy link
Author

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:question Issue is actually a question.
Projects
None yet
Development

No branches or pull requests

2 participants