diff options
Diffstat (limited to 'lib/northbound_sysrepo.c')
| -rw-r--r-- | lib/northbound_sysrepo.c | 70 |
1 files changed, 60 insertions, 10 deletions
diff --git a/lib/northbound_sysrepo.c b/lib/northbound_sysrepo.c index f426f52bd9..4359c39caf 100644 --- a/lib/northbound_sysrepo.c +++ b/lib/northbound_sysrepo.c @@ -22,6 +22,7 @@ #include "log.h" #include "lib_errors.h" #include "command.h" +#include "debug.h" #include "memory.h" #include "libfrr.h" #include "version.h" @@ -33,6 +34,8 @@ DEFINE_MTYPE_STATIC(LIB, SYSREPO, "Sysrepo module") +static struct debug nb_dbg_client_sysrepo = {0, "Northbound client: Sysrepo"}; + static struct thread_master *master; static struct list *sysrepo_threads; static sr_session_ctx_t *session; @@ -455,7 +458,7 @@ static int frr_sr_config_rpc_cb(const char *xpath, const sr_val_t *sr_input, } /* Execute callback registered for this XPath. */ - if (nb_node->cbs.rpc(xpath, input, output) != NB_OK) { + if (nb_callback_rpc(nb_node, xpath, input, output) != NB_OK) { flog_warn(EC_LIB_NB_CB_RPC, "%s: rpc callback failed: %s", __func__, xpath); ret = SR_ERR_OPERATION_FAILED; @@ -701,9 +704,9 @@ static int frr_sr_subscribe_state(const struct lys_node *snode, void *arg) return YANG_ITER_CONTINUE; nb_node = snode->priv; - if (debug_northbound) - zlog_debug("%s: providing data to '%s'", __func__, - nb_node->xpath); + + DEBUGD(&nb_dbg_client_sysrepo, "%s: providing data to '%s'", __func__, + nb_node->xpath); ret = sr_dp_get_items_subscribe( session, nb_node->xpath, frr_sr_state_cb, NULL, @@ -725,9 +728,9 @@ static int frr_sr_subscribe_rpc(const struct lys_node *snode, void *arg) return YANG_ITER_CONTINUE; nb_node = snode->priv; - if (debug_northbound) - zlog_debug("%s: providing RPC to '%s'", __func__, - nb_node->xpath); + + DEBUGD(&nb_dbg_client_sysrepo, "%s: providing RPC to '%s'", __func__, + nb_node->xpath); ret = sr_rpc_subscribe(session, nb_node->xpath, frr_sr_config_rpc_cb, NULL, SR_SUBSCR_CTX_REUSE, @@ -749,9 +752,9 @@ static int frr_sr_subscribe_action(const struct lys_node *snode, void *arg) return YANG_ITER_CONTINUE; nb_node = snode->priv; - if (debug_northbound) - zlog_debug("%s: providing action to '%s'", __func__, - nb_node->xpath); + + DEBUGD(&nb_dbg_client_sysrepo, "%s: providing action to '%s'", __func__, + nb_node->xpath); ret = sr_action_subscribe(session, nb_node->xpath, frr_sr_config_rpc_cb, NULL, SR_SUBSCR_CTX_REUSE, @@ -763,6 +766,52 @@ static int frr_sr_subscribe_action(const struct lys_node *snode, void *arg) return YANG_ITER_CONTINUE; } +/* CLI commands. */ +DEFUN (debug_nb_sr, + debug_nb_sr_cmd, + "[no] debug northbound client sysrepo", + NO_STR + DEBUG_STR + "Northbound debugging\n" + "Northbound client\n" + "Sysrepo\n") +{ + uint32_t mode = DEBUG_NODE2MODE(vty->node); + bool no = strmatch(argv[0]->text, "no"); + + DEBUG_MODE_SET(&nb_dbg_client_sysrepo, mode, !no); + + return CMD_SUCCESS; +} + +static int frr_sr_debug_config_write(struct vty *vty) +{ + if (DEBUG_MODE_CHECK(&nb_dbg_client_sysrepo, DEBUG_MODE_CONF)) + vty_out(vty, "debug northbound client sysrepo\n"); + + return 0; +} + +static int frr_sr_debug_set_all(uint32_t flags, bool set) +{ + DEBUG_FLAGS_SET(&nb_dbg_client_sysrepo, flags, set); + + /* If all modes have been turned off, don't preserve options. */ + if (!DEBUG_MODE_CHECK(&nb_dbg_client_sysrepo, DEBUG_MODE_ALL)) + DEBUG_CLEAR(&nb_dbg_client_sysrepo); + + return 0; +} + +static void frr_sr_cli_init(void) +{ + hook_register(nb_client_debug_config_write, frr_sr_debug_config_write); + hook_register(nb_client_debug_set_all, frr_sr_debug_set_all); + + install_element(ENABLE_NODE, &debug_nb_sr_cmd); + install_element(CONFIG_NODE, &debug_nb_sr_cmd); +} + /* FRR's Sysrepo initialization. */ static int frr_sr_init(const char *program_name) { @@ -851,6 +900,7 @@ static int frr_sr_module_late_init(struct thread_master *tm) } hook_register(frr_fini, frr_sr_finish); + frr_sr_cli_init(); return 0; } |
