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

netopeer2-cli cmd_establishpush() cannot be called multiple times for serving multiple notifications through separate callbacks #1600

Open
SamSKore opened this issue Jul 3, 2024 · 7 comments
Labels
is:question Issue is actually a question.

Comments

@SamSKore
Copy link

SamSKore commented Jul 3, 2024

Hi,

I'm trying to establish notifications with 2 different datastores which will be served by 2 different callbacks.

  1. datastore running with filter-xpath <module_1> --on-change
  2. datastore operational with filter-xpath <module_2> --on-change

by changing the cmd_establishpush() for nc_recv_notif_dispatch_data(), I'm giving callback_1 in case of module_1 and callback_2 in case of module_2.

But it is not creating 2 separate threads for handling above 2 different notifications. What I understood at high level is that atomicity is being maintained. But if there are different callbacks which can handle the data separately for different notifications, it should not affect the atomicity.

Can you tell how can I achieve it?

@michalvasko
Copy link
Member

Please include more details, what threads are you talking about and about what atomicity? nc_recv_notif_dispatch_data() should create a thread every time it is called.

@michalvasko michalvasko added the is:question Issue is actually a question. label Jul 4, 2024
@SamSKore
Copy link
Author

SamSKore commented Jul 4, 2024

Hi Michal,

File name: netopeer2/cli/commands.c
Function name: int cmd_establishpush(const char *arg, char **tmp_config_file)

after handling of all command line args, following is the code:

 /* create request */
     if (periodic) {
         rpc = nc_rpc_establishpush_periodic(datastore, filter, stop, encoding, period, anchor, NC_PARAMTYPE_CONST);
     } else {
         rpc = nc_rpc_establishpush_onchange(datastore, filter, stop, encoding, damp_period, sync_on_start,
                 (const char **)excluded_change, NC_PARAMTYPE_CONST);
     }
     if (!rpc) {
         ERROR(__func__, "RPC creation failed.");
         goto fail;
     }

    /* create notification thread so that notifications can immediately be received */
    if (!nc_session_ntf_thread_running(session)) {
        if (!output) {
            output = stdout;
        }
        printf("calling nc_recv_notif_dispatch_data clb: %p\n", push_notif_clb);
        ret = nc_recv_notif_dispatch_data(session, push_notif_clb, output, cli_ntf_free_data);
        if (ret) {
            ERROR(__func__, "Failed to create notification thread.");
            goto fail;
        }
    }

    ret = cli_send_recv(rpc, stdout, 0, timeout);
    if (ret) {
        goto fail;
    }

The condition if (!nc_session_ntf_thread_running(session)) is not letting another thread to be created.
The function nc_session_ntf_thread_running is defined in libnetconf2/src/session_client.c

@michalvasko
Copy link
Member

Ah, you are talking about netopeer2-cli. Then you are out of luck, we are still keeping it as a rather simple single-session NETCONF client and there is no point for it to create more notification threads.

@SamSKore
Copy link
Author

SamSKore commented Jul 4, 2024

Hi Michal, Thanks for confirming.
If that is not planned yet, I think at least we shall have some parameter, based on which we could separate out the processing of notifications in order to process the data.
for ex. We could have one notification coming for running datastore, another might have been configured for getting operational datastore changes or may be a specific xpath.

This can be done by the id received as the response of the establish-push rpc. This id can be returned from or be updated in cli_send_rcv to keep the processing of the data coming from multiple notifications separate.

Currently lyd_print_file is just printing it out inside cli_send_rcv and returning back.

@michalvasko
Copy link
Member

we could separate out the processing of notifications in order to process the data

What exactly do you mean by this? How do you want to separate them? There is only one stdout.

@SamSKore
Copy link
Author

SamSKore commented Jul 5, 2024

Okay I can understand that the netopeer2-cli is all about receiving the replies of the rpc and printing them out on stdout.
What I'm trying to do with it is taking the data out from the lyd_node* to process it further for my application.
So thought there shall be some way to fetch the data out of multiple notifications without mixing them.

@michalvasko
Copy link
Member

I think you will have to create several NETCONF sessions, each with a subscription for this use-case (so you cannot use netopeer2-cli).

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