summaryrefslogtreecommitdiffstats
path: root/src/vnet/session/session_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/session/session_api.c')
-rwxr-xr-xsrc/vnet/session/session_api.c164
1 files changed, 138 insertions, 26 deletions
diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c
index e3e3bb3c596..8f9ce3f5a1e 100755
--- a/src/vnet/session/session_api.c
+++ b/src/vnet/session/session_api.c
@@ -43,6 +43,7 @@
#define foreach_session_api_msg \
_(MAP_ANOTHER_SEGMENT_REPLY, map_another_segment_reply) \
_(APPLICATION_ATTACH, application_attach) \
+_(APP_ATTACH, app_attach) \
_(APPLICATION_DETACH, application_detach) \
_(BIND_URI, bind_uri) \
_(UNBIND_URI, unbind_uri) \
@@ -298,7 +299,7 @@ mq_send_session_reset_cb (session_t * s)
SESSION_CTRL_EVT_RESET);
}
-static int
+int
mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context,
session_t * s, u8 is_fail)
{
@@ -378,7 +379,7 @@ done:
return 0;
}
-static int
+int
mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context,
session_handle_t handle, int rv)
{
@@ -438,13 +439,35 @@ done:
return 0;
}
+void
+mq_send_unlisten_reply (app_worker_t * app_wrk, session_handle_t sh,
+ u32 context, int rv)
+{
+ svm_msg_q_msg_t _msg, *msg = &_msg;
+ session_unlisten_reply_msg_t *ump;
+ svm_msg_q_t *app_mq;
+ session_event_t *evt;
+
+ app_mq = app_wrk->event_queue;
+ if (mq_try_lock_and_alloc_msg (app_mq, msg))
+ return;
+
+ evt = svm_msg_q_msg_data (app_mq, msg);
+ clib_memset (evt, 0, sizeof (*evt));
+ evt->event_type = SESSION_CTRL_EVT_UNLISTEN_REPLY;
+ ump = (session_unlisten_reply_msg_t *) evt->data;
+ ump->context = context;
+ ump->handle = sh;
+ ump->retval = rv;
+ svm_msg_q_add_and_unlock (app_mq, msg);
+}
+
static void
mq_send_session_migrate_cb (session_t * s, session_handle_t new_sh)
{
clib_warning ("not supported");
}
-
static session_cb_vft_t session_mq_cb_vft = {
.session_accept_callback = mq_send_session_accepted_cb,
.session_disconnect_callback = mq_send_session_disconnected_cb,
@@ -466,6 +489,7 @@ vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp)
REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY);
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static void
vl_api_application_attach_t_handler (vl_api_application_attach_t * mp)
{
@@ -564,6 +588,108 @@ done:
}
static void
+vl_api_app_attach_t_handler (vl_api_app_attach_t * mp)
+{
+ int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0;
+ vl_api_app_attach_reply_t *rmp;
+ ssvm_private_t *segp, *evt_q_segment;
+ vnet_app_attach_args_t _a, *a = &_a;
+ u8 fd_flags = 0, ctrl_thread;
+ vl_api_registration_t *reg;
+ svm_msg_q_t *ctrl_mq;
+
+ reg = vl_api_client_index_to_registration (mp->client_index);
+ if (!reg)
+ return;
+
+ if (session_main_is_enabled () == 0)
+ {
+ rv = VNET_API_ERROR_FEATURE_DISABLED;
+ goto done;
+ }
+
+ STATIC_ASSERT (sizeof (u64) * APP_OPTIONS_N_OPTIONS <=
+ sizeof (mp->options),
+ "Out of options, fix api message definition");
+
+ clib_memset (a, 0, sizeof (*a));
+ a->api_client_index = mp->client_index;
+ a->options = mp->options;
+ a->session_cb_vft = &session_mq_cb_vft;
+ if (mp->namespace_id_len > 64)
+ {
+ rv = VNET_API_ERROR_INVALID_VALUE;
+ goto done;
+ }
+
+ if (mp->namespace_id_len)
+ {
+ vec_validate (a->namespace_id, mp->namespace_id_len - 1);
+ clib_memcpy_fast (a->namespace_id, mp->namespace_id,
+ mp->namespace_id_len);
+ }
+
+ if ((rv = vnet_application_attach (a)))
+ {
+ clib_warning ("attach returned: %d", rv);
+ vec_free (a->namespace_id);
+ goto done;
+ }
+ vec_free (a->namespace_id);
+
+ /* Send event queues segment */
+ if ((evt_q_segment = session_main_get_evt_q_segment ()))
+ {
+ fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT;
+ fds[n_fds] = evt_q_segment->fd;
+ n_fds += 1;
+ }
+ /* Send fifo segment fd if needed */
+ if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD)
+ {
+ fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
+ fds[n_fds] = a->segment->fd;
+ n_fds += 1;
+ }
+ if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD)
+ {
+ fd_flags |= SESSION_FD_F_MQ_EVENTFD;
+ fds[n_fds] = svm_msg_q_get_producer_eventfd (a->app_evt_q);
+ n_fds += 1;
+ }
+
+done:
+
+ ctrl_thread = vlib_num_workers ()? 1 : 0;
+ ctrl_mq = session_main_get_vpp_event_queue (ctrl_thread);
+ /* *INDENT-OFF* */
+ REPLY_MACRO2 (VL_API_APP_ATTACH_REPLY, ({
+ if (!rv)
+ {
+ segp = a->segment;
+ rmp->app_index = clib_host_to_net_u32 (a->app_index);
+ rmp->app_mq = pointer_to_uword (a->app_evt_q);
+ rmp->vpp_ctrl_mq = pointer_to_uword (ctrl_mq);
+ rmp->vpp_ctrl_mq_thread = ctrl_thread;
+ rmp->n_fds = n_fds;
+ rmp->fd_flags = fd_flags;
+ if (vec_len (segp->name))
+ {
+ memcpy (rmp->segment_name, segp->name, vec_len (segp->name));
+ rmp->segment_name_length = vec_len (segp->name);
+ }
+ rmp->segment_size = segp->ssvm_size;
+ rmp->segment_handle = clib_host_to_net_u64 (a->segment_handle);
+ }
+ }));
+ /* *INDENT-ON* */
+
+ if (n_fds)
+ session_send_fds (reg, fds, n_fds);
+}
+
+/* ### WILL BE DEPRECATED POST 20.01 ### */
+static void
vl_api_application_detach_t_handler (vl_api_application_detach_t * mp)
{
vl_api_application_detach_reply_t *rmp;
@@ -589,6 +715,7 @@ done:
REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY);
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static void
vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp)
{
@@ -629,6 +756,7 @@ done:
}
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static void
vl_api_unbind_uri_t_handler (vl_api_unbind_uri_t * mp)
{
@@ -660,6 +788,7 @@ done:
REPLY_MACRO (VL_API_UNBIND_URI_REPLY);
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static void
vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp)
{
@@ -701,6 +830,7 @@ done:
REPLY_MACRO (VL_API_CONNECT_URI_REPLY);
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static void
vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
{
@@ -731,6 +861,7 @@ done:
REPLY_MACRO2 (VL_API_DISCONNECT_SESSION_REPLY, rmp->handle = mp->handle);
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static void
vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
mp)
@@ -762,6 +893,7 @@ vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t
clib_warning ("not implemented");
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static void
vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp)
{
@@ -811,6 +943,7 @@ done:
}
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static void
vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp)
{
@@ -839,35 +972,14 @@ vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp)
done:
REPLY_MACRO (VL_API_UNBIND_SOCK_REPLY);
- /*
- * Send reply over msg queue
- */
- svm_msg_q_msg_t _msg, *msg = &_msg;
- session_unlisten_reply_msg_t *ump;
- svm_msg_q_t *app_mq;
- session_event_t *evt;
-
- if (!app)
- return;
-
app_wrk = application_get_worker (app, a->wrk_map_index);
if (!app_wrk)
return;
- app_mq = app_wrk->event_queue;
- if (mq_try_lock_and_alloc_msg (app_mq, msg))
- return;
-
- evt = svm_msg_q_msg_data (app_mq, msg);
- clib_memset (evt, 0, sizeof (*evt));
- evt->event_type = SESSION_CTRL_EVT_UNLISTEN_REPLY;
- ump = (session_unlisten_reply_msg_t *) evt->data;
- ump->context = mp->context;
- ump->handle = mp->handle;
- ump->retval = rv;
- svm_msg_q_add_and_unlock (app_mq, msg);
+ mq_send_unlisten_reply (app_wrk, mp->handle, mp->context, rv);
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static void
vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp)
{