aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/session/application_interface.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2018-08-31 14:31:41 -0700
committerDamjan Marion <dmarion@me.com>2018-09-06 08:35:51 +0000
commitab2f6dbf9f7b7164a9810f4c80c8abf8463e42ad (patch)
tree7fb4dd4c70bef17f09a88130eeadeeca86b6d09c /src/vnet/session/application_interface.c
parented234e7f151b05a5b8375dbd9f0add24fe8ebf2f (diff)
session: support multiple worker binds
Allows app workers to listen on the same session endpoint. Incoming connects are spread across the workers in a round-robin fashion Change-Id: Ib5f5817230d9abc6127a85cdbdcad70d980c0f7f Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vnet/session/application_interface.c')
-rw-r--r--src/vnet/session/application_interface.c81
1 files changed, 38 insertions, 43 deletions
diff --git a/src/vnet/session/application_interface.c b/src/vnet/session/application_interface.c
index 2e631363016..ab87def4062 100644
--- a/src/vnet/session/application_interface.c
+++ b/src/vnet/session/application_interface.c
@@ -147,11 +147,10 @@ session_endpoint_update_for_app (session_endpoint_t * sep,
}
}
-static int
-vnet_bind_i (vnet_bind_args_t * a)
+static inline int
+vnet_bind_inline (vnet_bind_args_t * a)
{
- u64 lh, ll_handle = SESSION_INVALID_HANDLE;
- u32 table_index, fib_proto;
+ u64 ll_handle = SESSION_INVALID_HANDLE;
app_worker_t *app_wrk;
application_t *app;
int rv;
@@ -163,17 +162,12 @@ vnet_bind_i (vnet_bind_args_t * a)
return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
}
app_wrk = application_get_worker (app, a->wrk_map_index);
+ a->sep_ext.app_wrk_index = app_wrk->wrk_index;
session_endpoint_update_for_app (&a->sep, app);
if (!session_endpoint_in_ns (&a->sep))
return VNET_API_ERROR_INVALID_VALUE_2;
- fib_proto = session_endpoint_fib_proto (&a->sep);
- table_index = application_session_table (app, fib_proto);
- lh = session_lookup_endpoint_listener (table_index, &a->sep, 1);
- if (lh != SESSION_INVALID_HANDLE)
- return VNET_API_ERROR_ADDRESS_IN_USE;
-
/*
* Add session endpoint to local session table. Only binds to "inaddr_any"
* (i.e., zero address) are added to local scope table.
@@ -181,8 +175,8 @@ vnet_bind_i (vnet_bind_args_t * a)
if (application_has_local_scope (app)
&& session_endpoint_is_local (&a->sep))
{
- if ((rv =
- application_start_local_listen (app_wrk, &a->sep, &a->handle)))
+ if ((rv = application_start_local_listen (app, &a->sep_ext,
+ &a->handle)))
return rv;
ll_handle = a->handle;
}
@@ -195,13 +189,17 @@ vnet_bind_i (vnet_bind_args_t * a)
*/
/* Setup listen path down to transport */
- rv = app_worker_start_listen (app_wrk, &a->sep, &a->handle);
+ rv = application_start_listen (app, &a->sep_ext, &a->handle);
if (rv && ll_handle != SESSION_INVALID_HANDLE)
- session_lookup_del_session_endpoint (table_index, &a->sep);
+ {
+ application_stop_local_listen (a->app_index, a->wrk_map_index,
+ ll_handle);
+ return rv;
+ }
/*
* Store in local table listener the index of the transport layer
- * listener. We'll need local listeners are hit and we need to
+ * listener. We'll need if if local listeners are hit and we need to
* return global handle
*/
if (ll_handle != SESSION_INVALID_HANDLE)
@@ -210,18 +208,19 @@ vnet_bind_i (vnet_bind_args_t * a)
stream_session_t *tl;
ll = application_get_local_listener_w_handle (ll_handle);
tl = listen_session_get_from_handle (a->handle);
- ll->transport_listener_index = tl->session_index;
+ if (ll->transport_listener_index == ~0)
+ ll->transport_listener_index = tl->session_index;
}
return rv;
}
-int
-vnet_unbind_i (u32 app_index, session_handle_t handle)
+static inline int
+vnet_unbind_inline (vnet_unbind_args_t * a)
{
application_t *app;
int rv;
- if (!(app = application_get_if_valid (app_index)))
+ if (!(app = application_get_if_valid (a->app_index)))
{
SESSION_DBG ("app (%d) not attached", wrk_map_index);
return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
@@ -229,7 +228,8 @@ vnet_unbind_i (u32 app_index, session_handle_t handle)
if (application_has_local_scope (app))
{
- if ((rv = application_stop_local_listen (handle, app_index)))
+ if ((rv = application_stop_local_listen (a->app_index,
+ a->wrk_map_index, a->handle)))
return rv;
}
@@ -237,7 +237,8 @@ vnet_unbind_i (u32 app_index, session_handle_t handle)
* Clear the global scope table of the listener
*/
if (application_has_global_scope (app))
- return app_worker_stop_listen (handle, app_index);
+ return application_stop_listen (a->app_index, a->wrk_map_index,
+ a->handle);
return 0;
}
@@ -247,7 +248,7 @@ application_connect (vnet_connect_args_t * a)
app_worker_t *server_wrk, *client_wrk;
u32 table_index, server_index, li;
stream_session_t *listener;
- application_t *client;
+ application_t *client, *server;
local_session_t *ll;
u8 fib_proto;
u64 lh;
@@ -283,8 +284,11 @@ application_connect (vnet_connect_args_t * a)
*/
if (server_index != a->app_index)
{
- server_wrk = app_worker_get (server_index);
- ll = application_get_local_listen_session (server_wrk, li);
+ server = application_get (server_index);
+ ll = application_get_local_listen_session (server, li);
+ listener = (stream_session_t *) ll;
+ server_wrk = application_listener_select_worker (listener,
+ 1 /* is_local */ );
return application_local_session_connect (client_wrk,
server_wrk, ll,
a->api_context);
@@ -308,13 +312,11 @@ global_scope:
listener = session_lookup_listener (table_index, &a->sep);
if (listener)
{
- server_wrk = app_worker_get (listener->app_wrk_index);
- if (server_wrk)
- {
- ll = (local_session_t *) listener;
- return application_local_session_connect (client_wrk, server_wrk,
- ll, a->api_context);
- }
+ server_wrk = application_listener_select_worker (listener,
+ 0 /* is_local */ );
+ ll = (local_session_t *) listener;
+ return application_local_session_connect (client_wrk, server_wrk, ll,
+ a->api_context);
}
/*
@@ -531,7 +533,7 @@ vnet_bind_uri (vnet_bind_args_t * a)
if (rv)
return rv;
clib_memcpy (&a->sep_ext, &sep, sizeof (sep));
- return vnet_bind_i (a);
+ return vnet_bind_inline (a);
}
int
@@ -553,8 +555,8 @@ vnet_unbind_uri (vnet_unbind_args_t * a)
(session_endpoint_t *) & sep);
if (!listener)
return VNET_API_ERROR_ADDRESS_NOT_IN_USE;
-
- return vnet_unbind_i (a->app_index, listen_session_get_handle (listener));
+ a->handle = listen_session_get_handle (listener);
+ return vnet_unbind_inline (a);
}
clib_error_t *
@@ -592,13 +594,6 @@ vnet_disconnect_session (vnet_disconnect_args_t * a)
if (!(ls = application_get_local_session_from_handle (a->handle)))
return 0;
- if (ls->app_wrk_index != a->app_index
- && ls->client_wrk_index != a->app_index)
- {
- clib_warning ("app %u is neither client nor server for session %u",
- a->app_index, a->app_index);
- return VNET_API_ERROR_INVALID_VALUE;
- }
return application_local_session_disconnect (a->app_index, ls);
}
else
@@ -620,7 +615,7 @@ clib_error_t *
vnet_bind (vnet_bind_args_t * a)
{
int rv;
- if ((rv = vnet_bind_i (a)))
+ if ((rv = vnet_bind_inline (a)))
return clib_error_return_code (0, rv, 0, "bind failed: %d", rv);
return 0;
}
@@ -629,7 +624,7 @@ clib_error_t *
vnet_unbind (vnet_unbind_args_t * a)
{
int rv;
- if ((rv = vnet_unbind_i (a->app_index, a->handle)))
+ if ((rv = vnet_unbind_inline (a)))
return clib_error_return_code (0, rv, 0, "unbind failed: %d", rv);
return 0;
}