aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/openconfig/openconfig_interfaces.c
diff options
context:
space:
mode:
authorjackiechen1985 <xiaobo.chen@tieto.com>2019-05-19 12:35:28 +0800
committerJunfeng Wang <drenfong.wang@intel.com>2019-05-22 04:37:38 +0000
commitce1a0daa15be4c3b7a3df64ea57ad231664e700f (patch)
treefdb1fac57156ebc6e12e8ce9cd7942a8f4023c03 /src/plugins/openconfig/openconfig_interfaces.c
parentaeb421c7219178ac464e8a2e62b35772a08a2c1c (diff)
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 <xiaobo.chen@tieto.com>
Diffstat (limited to 'src/plugins/openconfig/openconfig_interfaces.c')
-rw-r--r--src/plugins/openconfig/openconfig_interfaces.c105
1 files changed, 55 insertions, 50 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);