}
static inline int
-session_stream_connect_notify_inline (transport_connection_t * tc, u8 is_fail,
+session_stream_connect_notify_inline (transport_connection_t * tc,
+ session_error_t err,
session_state_t opened_state)
{
u32 opaque = 0, new_ti, new_si;
opaque = tc->s_index;
- if (is_fail)
- return app_worker_connect_notify (app_wrk, s, opaque);
+ if (err)
+ return app_worker_connect_notify (app_wrk, s, err, opaque);
s = session_alloc_for_connection (tc);
s->session_state = SESSION_STATE_CONNECTING;
new_si = s->session_index;
new_ti = s->thread_index;
- if (app_worker_init_connected (app_wrk, s))
+ if ((err = app_worker_init_connected (app_wrk, s)))
{
session_free (s);
- app_worker_connect_notify (app_wrk, 0, opaque);
+ app_worker_connect_notify (app_wrk, 0, err, opaque);
return -1;
}
s->session_state = opened_state;
session_lookup_add_connection (tc, session_handle (s));
- if (app_worker_connect_notify (app_wrk, s, opaque))
+ if (app_worker_connect_notify (app_wrk, s, SESSION_E_NONE, opaque))
{
s = session_get (new_si, new_ti);
session_free_w_fifos (s);
}
int
-session_stream_connect_notify (transport_connection_t * tc, u8 is_fail)
+session_stream_connect_notify (transport_connection_t * tc,
+ session_error_t err)
{
- return session_stream_connect_notify_inline (tc, is_fail,
- SESSION_STATE_READY);
+ return session_stream_connect_notify_inline (tc, err, SESSION_STATE_READY);
}
int
-session_ho_stream_connect_notify (transport_connection_t * tc, u8 is_fail)
+session_ho_stream_connect_notify (transport_connection_t * tc,
+ session_error_t err)
{
- return session_stream_connect_notify_inline (tc, is_fail,
- SESSION_STATE_OPENED);
+ return session_stream_connect_notify_inline (tc, err, SESSION_STATE_OPENED);
+}
+
+static void
+session_switch_pool_reply (void *arg)
+{
+ u32 session_index = pointer_to_uword (arg);
+ segment_manager_t *sm;
+ app_worker_t *app_wrk;
+ session_t *s;
+
+ s = session_get_if_valid (session_index, vlib_get_thread_index ());
+ if (!s)
+ return;
+
+ app_wrk = app_worker_get_if_valid (s->app_wrk_index);
+ if (!app_wrk)
+ return;
+
+ /* Attach fifos to the right session and segment slice */
+ sm = app_worker_get_connect_segment_manager (app_wrk);
+ segment_manager_attach_fifo (sm, s->rx_fifo, s);
+ segment_manager_attach_fifo (sm, s->tx_fifo, s);
+
+ /* Notify app that it has data on the new session */
+ session_enqueue_notify (s);
}
typedef struct _session_switch_pool_args
session_switch_pool (void *cb_args)
{
session_switch_pool_args_t *args = (session_switch_pool_args_t *) cb_args;
+ session_handle_t new_sh;
+ segment_manager_t *sm;
app_worker_t *app_wrk;
session_t *s;
+ void *rargs;
ASSERT (args->thread_index == vlib_get_thread_index ());
s = session_get (args->session_index, args->thread_index);
- s->tx_fifo->master_session_index = args->new_session_index;
- s->tx_fifo->master_thread_index = args->new_thread_index;
+
transport_cleanup (session_get_transport_proto (s), s->connection_index,
s->thread_index);
+ new_sh = session_make_handle (args->new_session_index,
+ args->new_thread_index);
+
app_wrk = app_worker_get_if_valid (s->app_wrk_index);
if (app_wrk)
{
- session_handle_t new_sh;
- new_sh = session_make_handle (args->new_session_index,
- args->new_thread_index);
- app_worker_migrate_notify (app_wrk, s, new_sh);
+ /* Cleanup fifo segment slice state for fifos */
+ sm = app_worker_get_connect_segment_manager (app_wrk);
+ segment_manager_detach_fifo (sm, s->rx_fifo);
+ segment_manager_detach_fifo (sm, s->tx_fifo);
- /* Trigger app read on the new thread */
- session_enqueue_notify_thread (new_sh);
+ /* Notify app, using old session, about the migration event */
+ app_worker_migrate_notify (app_wrk, s, new_sh);
}
+ /* Trigger app read and fifo updates on the new thread */
+ rargs = uword_to_pointer (args->new_session_index, void *);
+ session_send_rpc_evt_to_thread (args->new_thread_index,
+ session_switch_pool_reply, rargs);
+
session_free (s);
clib_mem_free (cb_args);
}
*/
new_s = session_clone_safe (tc->s_index, old_thread_index);
new_s->connection_index = tc->c_index;
- new_s->rx_fifo->master_session_index = new_s->session_index;
- new_s->rx_fifo->master_thread_index = new_s->thread_index;
new_s->session_state = SESSION_STATE_READY;
new_s->flags |= SESSION_F_IS_MIGRATING;
+
session_lookup_add_connection (tc, session_handle (new_s));
/*
return 0;
}
+int
+session_dgram_accept (transport_connection_t * tc, u32 listener_index,
+ u32 thread_index)
+{
+ app_worker_t *app_wrk;
+ session_t *s;
+ int rv;
+
+ s = session_alloc_for_connection (tc);
+ s->listener_handle = ((u64) thread_index << 32) | (u64) listener_index;
+
+ if ((rv = app_worker_init_accepted (s)))
+ {
+ session_free (s);
+ return rv;
+ }
+
+ app_wrk = app_worker_get (s->app_wrk_index);
+ if ((rv = app_worker_accept_notify (app_wrk, s)))
+ {
+ session_free_w_fifos (s);
+ return rv;
+ }
+
+ s->session_state = SESSION_STATE_READY;
+ session_lookup_add_connection (tc, session_handle (s));
+
+ return 0;
+}
+
int
session_open_cl (u32 app_wrk_index, session_endpoint_t * rmt, u32 opaque)
{
if (rv < 0)
{
SESSION_DBG ("Transport failed to open connection.");
- return VNET_API_ERROR_SESSION_CONNECT;
+ return rv;
}
tc = transport_get_half_open (rmt->transport_proto, (u32) rv);
sh = session_handle (s);
session_lookup_add_connection (tc, sh);
- return app_worker_connect_notify (app_wrk, s, opaque);
+ return app_worker_connect_notify (app_wrk, s, SESSION_E_NONE, opaque);
}
int
if (rv < 0)
{
SESSION_DBG ("Transport failed to open connection.");
- return VNET_API_ERROR_SESSION_CONNECT;
+ return rv;
}
tc = transport_get_half_open (rmt->transport_proto, (u32) rv);
session_listen (session_t * ls, session_endpoint_cfg_t * sep)
{
transport_endpoint_t *tep;
- u32 tc_index, s_index;
+ int tc_index;
+ u32 s_index;
/* Transport bind/listen */
tep = session_endpoint_to_transport (sep);
tc_index = transport_start_listen (session_get_transport_proto (ls),
s_index, tep);
- if (tc_index == (u32) ~ 0)
- return -1;
+ if (tc_index < 0)
+ return tc_index;
/* Attach transport to session. Lookup tables are populated by the app
* worker because local tables (for ct sessions) are not backed by a fib */
transport_connection_t *tc;
if (s->session_state != SESSION_STATE_LISTENING)
- return -1;
+ return SESSION_E_NOLISTEN;
tc = transport_get_listener (tp, s->connection_index);
+
+ /* If no transport, assume everything was cleaned up already */
if (!tc)
- return VNET_API_ERROR_ADDRESS_NOT_IN_USE;
+ return SESSION_E_NONE;
if (!(tc->flags & TRANSPORT_CONNECTION_F_NO_LOOKUP))
session_lookup_del_connection (tc);
+
transport_stop_listen (tp, s->connection_index);
return 0;
}