summaryrefslogtreecommitdiffstats
path: root/src/plugins/sc_plugins.c
diff options
context:
space:
mode:
authorYohanPipereau <ypiperea@cisco.com>2019-02-26 11:47:26 +0100
committerYohanPipereau <ypiperea@cisco.com>2019-02-28 11:56:29 +0100
commit793682e6fcb9e39891c59c696e5f8e9c18f9d8e7 (patch)
tree3c85ee82ab556d696dc7af8a6d9f55e9a08cf7f8 /src/plugins/sc_plugins.c
parentf9393a8c15fbd63b7a0938269afa8a35ddfc4738 (diff)
This commit changes the way models are registered.
Registering a new model is now done using model_register function which is generic enough to take care of every model family (IETF, Openconfig, ...). Every model (ex: openconfig-interfaces) contain one or several xpaths. Every model (ex: openconfig-interfaces) has its own dedicated C file (ex: openconfig-interfaces.c) with its dedicated xpath_t structure in it. This structure is a mapping of all xpaths of a model to their associated callbacks. It still contains all informations needed by sr_*_subscribe functions. Thus, xpath_t is an external array used in every model, it is seen as a global symbol in shared library. And because these external arrays are passed as arguments to a function, maccros defining the size of these xpath_t arrays have been defined. datastore_e datastructure has been removed to rely on the one provided by sysrepo API. The subscription linked list which was used has been removed because sysrepo already takes care of this. Now, the same subscription_session_ctx_t is used for all subscriptions as it was the case in ietf_subscribe_events. Thus cleanup callback has been simplified to a simple sysrepo_unsubscribe instead of going through the entire Linked List. Change-Id: I43d52f619be27b6216bb3b9d197518b032306fa7 Signed-off-by: Yohan Pipereau <ypiperea@cisco.com>
Diffstat (limited to 'src/plugins/sc_plugins.c')
-rw-r--r--src/plugins/sc_plugins.c142
1 files changed, 32 insertions, 110 deletions
diff --git a/src/plugins/sc_plugins.c b/src/plugins/sc_plugins.c
index 66790a1..e0db8ed 100644
--- a/src/plugins/sc_plugins.c
+++ b/src/plugins/sc_plugins.c
@@ -22,6 +22,8 @@
#include <vapi/vxlan.api.vapi.h>
#include <vnet/interface.h>
#include <vnet/mpls/mpls_types.h>
+
+// Use VAPI macros to define symbols
DEFINE_VAPI_MSG_IDS_VPE_API_JSON;
DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON;
DEFINE_VAPI_MSG_IDS_L2_API_JSON;
@@ -30,131 +32,51 @@ DEFINE_VAPI_MSG_IDS_TAPV2_API_JSON;
DEFINE_VAPI_MSG_IDS_IPSEC_API_JSON;
DEFINE_VAPI_MSG_IDS_VXLAN_API_JSON;
-
#include "sc_plugins.h"
+#include "sc_model.h"
+
#include "ietf/ietf_interface.h"
-#include "openconfig/openconfig_plugin.h"
+#include "openconfig/openconfig_interfaces.h"
+#include "openconfig/openconfig_local_routing.h"
int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_ctx)
{
- SC_INVOKE_BEGIN;
- sr_subscription_ctx_t *subscription = NULL;
- int rc = SR_ERR_OK;
- rc = sc_connect_vpp();
- if (0 != rc)
- {
- SC_LOG_ERR("vpp connect error , with return %d.", rc);
- return SR_ERR_INTERNAL;
+ SC_INVOKE_BEGIN;
+ plugin_main_t plugin_main;
+ int rc;
+
+ rc = sc_connect_vpp();
+ if (0 != rc) {
+ SC_LOG_ERR("vpp connect error , with return %d.", rc);
+ return SR_ERR_INTERNAL;
}
- //SC_REGISTER_RPC_EVT_HANDLER(sc_ip_subscribe_route_events);
- //SC_REGISTER_RPC_EVT_HANDLER(sc_vxlan_subscribe_tunnel_events);
- //SC_REGISTER_RPC_EVT_HANDLER(sc_l2_bridge_domain_add_del_subscribe_events);
- //SC_REGISTER_RPC_EVT_HANDLER(sc_l2_interface_set_l2_bridge_subscribe_events);
+ plugin_main.session = session;
+ plugin_main.subscription = NULL;
+ /* Use the same sr_subscription_ctx for all models */
+ model_register(&plugin_main, ietf_interfaces_xpaths, IETF_INTERFACES_SIZE);
+ model_register(&plugin_main, oc_interfaces_xpaths, OC_INTERFACES_SIZE);
+ model_register(&plugin_main, oc_local_routing_xpaths, OC_LROUTING_SIZE);
- //INTERFACE
- ietf_interface_subscribe_events(session, &subscription);
+ /* set subscription as our private context */
+ *private_ctx = plugin_main.subscription;
+ SC_INVOKE_END;
- //Openconfig modules
- openconfig_plugin_init(session);
-
- /* set subscription as our private context */
- *private_ctx = subscription;
- SC_INVOKE_END;
- return SR_ERR_OK;
+ return SR_ERR_OK;
}
void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_ctx)
{
- SC_INVOKE_BEGIN;
+ SC_INVOKE_BEGIN;
- openconfig_plugin_cleanup();
+ /* subscription was set as our private context */
+ if (private_ctx != NULL)
+ sr_unsubscribe(session, private_ctx);
+ SC_LOG_DBG_MSG("unload plugin ok.");
- /* subscription was set as our private context */
- sr_unsubscribe(session, private_ctx);
- SC_LOG_DBG_MSG("unload plugin ok.");
- sc_disconnect_vpp();
- SC_LOG_DBG_MSG("plugin disconnect vpp ok.");
- SC_INVOKE_END;
-}
-
-
-///#############################
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <inttypes.h>
-sr_subscription_ctx_t *subscription = NULL;
-volatile int exit_application = 0;
-
-static void
-sigint_handler(int signum)
-{
- exit_application = 1;
+ sc_disconnect_vpp();
+ SC_LOG_DBG_MSG("plugin disconnect vpp ok.");
+ SC_INVOKE_END;
}
-int
-subscribe_all_module_events(sr_session_ctx_t *session)
-{
- sr_plugin_init_cb(session, (void**)&subscription);
- return 0;
-}
-int
-main(int argc, char **argv)
-{
- sr_conn_ctx_t *connection = NULL;
- sr_session_ctx_t *session = NULL;
- int rc = SR_ERR_OK;
-
- /* connect to vpp */
- rc = sc_connect_vpp();
- if (-1 == rc){
- fprintf(stderr, "vpp connect error");
- return -1;
- }
-
- /* connect to sysrepo */
- rc = sr_connect("cpe_application", SR_CONN_DEFAULT, &connection);
- if (SR_ERR_OK != rc) {
- fprintf(stderr, "Error by sr_connect: %s\n", sr_strerror(rc));
- goto cleanup;
- }
-
- /* start session */
- rc = sr_session_start(connection, SR_DS_STARTUP, SR_SESS_DEFAULT, &session);
- if (SR_ERR_OK != rc) {
- fprintf(stderr, "Error by sr_session_start: %s\n", sr_strerror(rc));
- goto cleanup;
- }
- /* subscribe all module events */
- rc = subscribe_all_module_events(session);
- if (SR_ERR_OK != rc) {
- fprintf(stderr, "Error by subscribe module events: %s\n", sr_strerror(rc));
- goto cleanup;
- }
-
- /* loop until ctrl-c is pressed / SIGINT is received */
- signal(SIGINT, sigint_handler);
- signal(SIGPIPE, SIG_IGN);
-
- while (!exit_application) {
- sleep(2);
- }
-
- printf("Application exit requested, exiting.\n");
-
- cleanup:
- if (NULL != subscription) {
- sr_unsubscribe(session, subscription);
- }
- if (NULL != session) {
- sr_session_stop(session);
- }
- if (NULL != connection) {
- sr_disconnect(connection);
- }
- sc_disconnect_vpp();
- return rc;
-}