aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/sc_plugins.c
diff options
context:
space:
mode:
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;
-}