aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/openconfig
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/openconfig')
-rw-r--r--src/plugins/openconfig/openconfig_interfaces.c105
-rw-r--r--src/plugins/openconfig/openconfig_local_routing.c124
2 files changed, 116 insertions, 113 deletions
diff --git a/src/plugins/openconfig/openconfig_interfaces.c b/src/plugins/openconfig/openconfig_interfaces.c
index 7242c2b..67b9a3c 100644
--- a/src/plugins/openconfig/openconfig_interfaces.c
+++ b/src/plugins/openconfig/openconfig_interfaces.c
@@ -21,8 +21,7 @@
#include <scvpp/interface.h>
#include <scvpp/ip.h>
-#include "../sc_model.h"
-#include "../sys_util.h"
+#include <sc_plugins.h>
// XPATH: /openconfig-interfaces:interfaces/interface[name='%s']/config/
static int openconfig_interfaces_interfaces_interface_config_cb(
@@ -590,52 +589,58 @@ static int openconfig_interfaces_interfaces_interface_subinterfaces_subinterface
return SR_ERR_OK;
}
-const xpath_t oc_interfaces_xpaths[OC_INTERFACES_SIZE] = {
- {
- .xpath = "/openconfig-interfaces:interfaces/interface/config",
- .method = XPATH,
- .datastore = SR_DS_RUNNING,
- .cb.scb = openconfig_interfaces_interfaces_interface_config_cb,
- .private_ctx = NULL,
- .priority = 98,
- //.opts = SR_SUBSCR_DEFAULT
- .opts = SR_SUBSCR_CTX_REUSE
- },
- {
- .xpath = "/openconfig-interfaces:interfaces/interface/state",
- .method = GETITEM,
- .datastore = SR_DS_RUNNING,
- .cb.gcb = openconfig_interfaces_interfaces_interface_state_cb,
- .private_ctx = NULL,
- .priority = 98,
- .opts = SR_SUBSCR_CTX_REUSE
- },
- {
- .xpath = "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/state",
- .method = GETITEM,
- .datastore = SR_DS_RUNNING,
- .cb.gcb = openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_state_cb,
- .private_ctx = NULL,
- .priority = 99,
- .opts = SR_SUBSCR_CTX_REUSE
- },
- {
- .xpath = "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/openconfig-if-ip:ipv4/openconfig-if-ip:addresses/openconfig-if-ip:address/openconfig-if-ip:config",
- .method = XPATH,
- .datastore = SR_DS_RUNNING,
- .cb.scb = openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_oc_ip_ipv4_oc_ip_addresses_oc_ip_address_oc_ip_config_cb,
- .private_ctx = NULL,
- .priority = 100,
- //.opts = SR_SUBSCR_DEFAULT
- .opts = SR_SUBSCR_CTX_REUSE
- },
- {
- .xpath = "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/openconfig-if-ip:ipv4/openconfig-if-ip:addresses/openconfig-if-ip:address/openconfig-if-ip:state",
- .method = GETITEM,
- .datastore = SR_DS_RUNNING,
- .cb.gcb = openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_oc_ip_ipv4_oc_ip_addresses_oc_ip_address_oc_ip_state_cb,
- .private_ctx = NULL,
- .priority = 100,
- .opts = SR_SUBSCR_CTX_REUSE
+int
+openconfig_interface_init(sc_plugin_main_t *pm)
+{
+ int rc = SR_ERR_OK;
+ SRP_LOG_DBG_MSG("Initializing openconfig-interfaces plugin.");
+
+ rc = sr_subtree_change_subscribe(pm->session, "/openconfig-interfaces:interfaces/interface/config",
+ openconfig_interfaces_interfaces_interface_config_cb, NULL, 98, SR_SUBSCR_CTX_REUSE, &pm->subscription);
+ if (SR_ERR_OK != rc) {
+ goto error;
+ }
+
+ rc = sr_dp_get_items_subscribe(pm->session, "/openconfig-interfaces:interfaces/interface/state",
+ openconfig_interfaces_interfaces_interface_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-interfaces:interfaces/interface/subinterfaces/subinterface/state",
+ openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_state_cb, NULL, SR_SUBSCR_CTX_REUSE, &pm->subscription);
+ if (SR_ERR_OK != rc) {
+ goto error;
+ }
+
+ rc = sr_subtree_change_subscribe(pm->session,
+ "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/openconfig-if-ip:ipv4/openconfig-if-ip:addresses/openconfig-if-ip:address/openconfig-if-ip:config",
+ openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_oc_ip_ipv4_oc_ip_addresses_oc_ip_address_oc_ip_config_cb,
+ NULL, 100, SR_SUBSCR_CTX_REUSE, &pm->subscription);
+ if (SR_ERR_OK != rc) {
+ goto error;
+ }
+
+ rc = sr_dp_get_items_subscribe(pm->session,
+ "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/openconfig-if-ip:ipv4/openconfig-if-ip:addresses/openconfig-if-ip:address/openconfig-if-ip:state",
+ openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_oc_ip_ipv4_oc_ip_addresses_oc_ip_address_oc_ip_state_cb,
+ NULL, SR_SUBSCR_CTX_REUSE, &pm->subscription);
+ if (SR_ERR_OK != rc) {
+ goto error;
}
-};
+
+ SRP_LOG_DBG_MSG("openconfig-interfaces plugin initialized successfully.");
+ return SR_ERR_OK;
+
+error:
+ SRP_LOG_ERR("Error by initialization of openconfig-interfaces plugin. Error : %d", rc);
+ return rc;
+}
+
+void
+openconfig_interface_exit(__attribute__((unused)) sc_plugin_main_t *pm)
+{
+}
+
+SC_INIT_FUNCTION(openconfig_interface_init);
+SC_EXIT_FUNCTION(openconfig_interface_exit);
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 <scvpp/interface.h>
#include <scvpp/ip.h>
-#include "../sc_model.h"
-#include "../sys_util.h"
+#include <sc_plugins.h>
#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);
+