From ce1a0daa15be4c3b7a3df64ea57ad231664e700f Mon Sep 17 00:00:00 2001 From: jackiechen1985 Date: Sun, 19 May 2019 12:35:28 +0800 Subject: Introduce a new registration mechanism to sweetcomb. Sweetcomb plugins register for various [initialization] events by placing structures and __attribute__((constructor)) functions into the library. When sysrepo plugin is initializing, the framework walks constructor-generated singly-linked structure lists, calls the indicated functions. Change-Id: I0cb078391f2662e4f6dd08c1a383173f203adf2a Signed-off-by: jackiechen1985 --- src/plugins/openconfig/openconfig_local_routing.c | 124 +++++++++++----------- 1 file changed, 61 insertions(+), 63 deletions(-) (limited to 'src/plugins/openconfig/openconfig_local_routing.c') diff --git a/src/plugins/openconfig/openconfig_local_routing.c b/src/plugins/openconfig/openconfig_local_routing.c index 6a3b5bd..2d16da0 100644 --- a/src/plugins/openconfig/openconfig_local_routing.c +++ b/src/plugins/openconfig/openconfig_local_routing.c @@ -21,8 +21,7 @@ #include #include -#include "../sc_model.h" -#include "../sys_util.h" +#include #define HOP_INDEX_SIZE 10 //number of digit in max 32 bit integer @@ -400,7 +399,7 @@ oc_next_hop_state_cb(const char *xpath, sr_val_t **values, size_t *values_cnt, if (strtoul(index, NULL, 0) != reply->path[0].next_hop_id) { SRP_LOG_ERR("next hop index is %d for prefix %s", reply->path[0].next_hop_id, prefix); - SRP_LOG_ERR("before %s, stroul is %d", index, strtoul(index, NULL, 0)); + SRP_LOG_ERR("before %s, stroul is %lu", index, strtoul(index, NULL, 0)); return SR_ERR_INVAL_ARG; } @@ -468,7 +467,7 @@ oc_next_hop_interface_state_cb(const char *xpath, sr_val_t **values, if (strtoul(index, NULL, 0) != reply->path[0].next_hop_id) { SRP_LOG_ERR("next hop index is %d for prefix %s", reply->path[0].next_hop_id, prefix); - SRP_LOG_ERR("before %s, stroul is %d", index, strtoul(index, NULL, 0)); + SRP_LOG_ERR("before %s, stroul is %lu", index, strtoul(index, NULL, 0)); return SR_ERR_INVAL_ARG; } @@ -489,62 +488,61 @@ oc_next_hop_interface_state_cb(const char *xpath, sr_val_t **values, return SR_ERR_OK; } -const xpath_t oc_local_routing_xpaths[OC_LROUTING_SIZE] = { - { - .xpath = "/openconfig-local-routing:local-routes/static-routes/static/config", - .method = XPATH, - .datastore = SR_DS_RUNNING, - .cb.scb = oc_prefix_config_cb, - .private_ctx = NULL, - .priority = 0, - //.opts = SR_SUBSCR_DEFAULT - .opts = SR_SUBSCR_CTX_REUSE - }, - { - .xpath = "/openconfig-local-routing:local-routes/static-routes/static/next-hops/next-hop/config", - .method = XPATH, - .datastore = SR_DS_RUNNING, - .cb.scb = oc_next_hop_config_cb, - .private_ctx = NULL, - .priority = 0, - //.opts = SR_SUBSCR_DEFAULT - .opts = SR_SUBSCR_CTX_REUSE - }, - { - .xpath = "/openconfig-local-routing:local-routes/static-routes/static/next-hops/next-hop/interface-ref/config", - .method = XPATH, - .datastore = SR_DS_RUNNING, - .cb.scb = oc_next_hop_interface_config_cb, - .private_ctx = NULL, - .priority = 0, - //.opts = SR_SUBSCR_DEFAULT - .opts = SR_SUBSCR_CTX_REUSE - }, - { - .xpath = "/openconfig-local-routing:local-routes/static-routes/static/state", - .method = GETITEM, - .datastore = SR_DS_RUNNING, - .cb.gcb = oc_prefix_state_cb, - .private_ctx = NULL, - .priority = 0, - .opts = SR_SUBSCR_CTX_REUSE - }, - { - .xpath = "/openconfig-local-routing:local-routes/static-routes/static/next-hops/next-hop/state", - .method = GETITEM, - .datastore = SR_DS_RUNNING, - .cb.gcb = oc_next_hop_state_cb, - .private_ctx = NULL, - .priority = 0, - .opts = SR_SUBSCR_CTX_REUSE - }, - { - .xpath = "/openconfig-local-routing:local-routes/static-routes/static/next-hops/next-hop/interface-ref/state", - .method = GETITEM, - .datastore = SR_DS_RUNNING, - .cb.gcb = oc_next_hop_interface_state_cb, - .private_ctx = NULL, - .priority = 0, - .opts = SR_SUBSCR_CTX_REUSE - }, -}; +int +openconfig_local_routing_init(sc_plugin_main_t *pm) +{ + int rc = SR_ERR_OK; + SRP_LOG_DBG_MSG("Initializing openconfig-local-routing plugin."); + + rc = sr_subtree_change_subscribe(pm->session, "/openconfig-local-routing:local-routes/static-routes/static/config", + oc_prefix_config_cb, NULL, 0, SR_SUBSCR_CTX_REUSE, &pm->subscription); + if (SR_ERR_OK != rc) { + goto error; + } + + rc = sr_subtree_change_subscribe(pm->session, "/openconfig-local-routing:local-routes/static-routes/static/next-hops/next-hop/config", + oc_next_hop_config_cb, NULL, 0, SR_SUBSCR_CTX_REUSE, &pm->subscription); + if (SR_ERR_OK != rc) { + goto error; + } + + rc = sr_subtree_change_subscribe(pm->session, "/openconfig-local-routing:local-routes/static-routes/static/next-hops/next-hop/interface-ref/config", + oc_next_hop_interface_config_cb, NULL, 0, SR_SUBSCR_CTX_REUSE, &pm->subscription); + if (SR_ERR_OK != rc) { + goto error; + } + + rc = sr_dp_get_items_subscribe(pm->session, "/openconfig-local-routing:local-routes/static-routes/static/state", + oc_prefix_state_cb, NULL, SR_SUBSCR_CTX_REUSE, &pm->subscription); + if (SR_ERR_OK != rc) { + goto error; + } + + rc = sr_dp_get_items_subscribe(pm->session, "/openconfig-local-routing:local-routes/static-routes/static/next-hops/next-hop/state", + oc_next_hop_state_cb, NULL, SR_SUBSCR_CTX_REUSE, &pm->subscription); + if (SR_ERR_OK != rc) { + goto error; + } + + rc = sr_dp_get_items_subscribe(pm->session, "/openconfig-local-routing:local-routes/static-routes/static/next-hops/next-hop/interface-ref/state", + oc_next_hop_interface_state_cb, NULL, SR_SUBSCR_CTX_REUSE, &pm->subscription); + if (SR_ERR_OK != rc) { + goto error; + } + + SRP_LOG_DBG_MSG("openconfig-local-routing plugin initialized successfully."); + return SR_ERR_OK; + +error: + SRP_LOG_ERR("Error by initialization of openconfig-local-routing plugin. Error : %d", rc); + return rc; +} + +void +openconfig_local_routing_exit(__attribute__((unused)) sc_plugin_main_t *pm) +{ +} + +SC_INIT_FUNCTION(openconfig_local_routing_init); +SC_EXIT_FUNCTION(openconfig_local_routing_exit); + -- cgit 1.2.3-korg