{
session_accepted_reply_msg_t *mp = (session_accepted_reply_msg_t *) data;
vnet_disconnect_args_t _a = { 0 }, *a = &_a;
+ stream_session_state_t old_state;
app_worker_t *app_wrk;
local_session_t *ls;
stream_session_t *s;
else
{
s = session_get_from_handle_if_valid (mp->handle);
- /* Closed while waiting for app to reply */
- if (!s || s->session_state > SESSION_STATE_READY)
+ if (!s)
return;
+
app_wrk = app_worker_get (s->app_wrk_index);
if (app_wrk->app_index != mp->context)
{
clib_warning ("app doesn't own session");
return;
}
+
+ old_state = s->session_state;
s->session_state = SESSION_STATE_READY;
if (!svm_fifo_is_empty (s->server_rx_fifo))
app_worker_lock_and_send_event (app_wrk, s, FIFO_EVENT_APP_RX);
+
+ /* Closed while waiting for app to reply. Resend disconnect */
+ if (old_state >= SESSION_STATE_TRANSPORT_CLOSING)
+ {
+ application_t *app = application_get (app_wrk->app_index);
+ app->cb_fns.session_disconnect_callback (s);
+ s->session_state = old_state;
+ return;
+ }
}
}
svm_msg_q_unlock (app_wrk->event_queue);
evt = svm_msg_q_msg_data (app_wrk->event_queue, msg);
clib_memset (evt, 0, sizeof (*evt));
- evt->event_type = SESSION_CTRL_EVT_DISCONNECTED;
+ evt->event_type = SESSION_CTRL_EVT_DISCONNECTED_REPLY;
rmp = (session_disconnected_reply_msg_t *) evt->data;
rmp->handle = mp->handle;
rmp->context = mp->context;
}
}
+static void
+session_mq_worker_update_handler (void *data)
+{
+ session_worker_update_msg_t *mp = (session_worker_update_msg_t *) data;
+ session_worker_update_reply_msg_t *rmp;
+ svm_msg_q_msg_t _msg, *msg = &_msg;
+ app_worker_t *app_wrk;
+ u32 owner_app_wrk_map;
+ session_event_t *evt;
+ stream_session_t *s;
+ application_t *app;
+
+ app = application_lookup (mp->client_index);
+ if (!app)
+ return;
+ if (!(s = session_get_from_handle_if_valid (mp->handle)))
+ {
+ clib_warning ("invalid handle %llu", mp->handle);
+ return;
+ }
+ app_wrk = app_worker_get (s->app_wrk_index);
+ if (app_wrk->app_index != app->app_index)
+ {
+ clib_warning ("app %u does not own session %llu", app->app_index,
+ mp->handle);
+ return;
+ }
+ owner_app_wrk_map = app_wrk->wrk_map_index;
+ app_wrk = application_get_worker (app, mp->wrk_index);
+
+ /* This needs to come from the new owner */
+ if (mp->req_wrk_index == owner_app_wrk_map)
+ {
+ session_req_worker_update_msg_t *wump;
+
+ svm_msg_q_lock_and_alloc_msg_w_ring (app_wrk->event_queue,
+ SESSION_MQ_CTRL_EVT_RING,
+ SVM_Q_WAIT, msg);
+ svm_msg_q_unlock (app_wrk->event_queue);
+ evt = svm_msg_q_msg_data (app_wrk->event_queue, msg);
+ clib_memset (evt, 0, sizeof (*evt));
+ evt->event_type = SESSION_CTRL_EVT_REQ_WORKER_UPDATE;
+ wump = (session_req_worker_update_msg_t *) evt->data;
+ wump->session_handle = mp->handle;
+ svm_msg_q_add (app_wrk->event_queue, msg, SVM_Q_WAIT);
+ return;
+ }
+
+ app_worker_own_session (app_wrk, s);
+
+ /*
+ * Send reply
+ */
+ svm_msg_q_lock_and_alloc_msg_w_ring (app_wrk->event_queue,
+ SESSION_MQ_CTRL_EVT_RING,
+ SVM_Q_WAIT, msg);
+ svm_msg_q_unlock (app_wrk->event_queue);
+ evt = svm_msg_q_msg_data (app_wrk->event_queue, msg);
+ clib_memset (evt, 0, sizeof (*evt));
+ evt->event_type = SESSION_CTRL_EVT_WORKER_UPDATE_REPLY;
+ rmp = (session_worker_update_reply_msg_t *) evt->data;
+ rmp->handle = mp->handle;
+ rmp->rx_fifo = pointer_to_uword (s->server_rx_fifo);
+ rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo);
+ rmp->segment_handle = session_segment_handle (s);
+ svm_msg_q_add (app_wrk->event_queue, msg, SVM_Q_WAIT);
+
+ /*
+ * Retransmit messages that may have been lost
+ */
+ if (!svm_fifo_is_empty (s->server_tx_fifo))
+ session_send_io_evt_to_thread (s->server_tx_fifo, FIFO_EVENT_APP_TX);
+
+ if (!svm_fifo_is_empty (s->server_rx_fifo))
+ app_worker_lock_and_send_event (app_wrk, s, FIFO_EVENT_APP_RX);
+
+ if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSING)
+ app->cb_fns.session_disconnect_callback (s);
+}
+
vlib_node_registration_t session_queue_node;
typedef struct
* session is not ready or closed */
if (s->session_state < SESSION_STATE_READY)
return 1;
- if (s->session_state == SESSION_STATE_CLOSED)
+ if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSED)
return 2;
}
return 0;
ctx->max_len_to_snd = max_segs * ctx->snd_mss;
}
- n_bytes_per_buf = vlib_buffer_free_list_buffer_size (vm,
- VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
+ n_bytes_per_buf = VLIB_BUFFER_DATA_SIZE;
ASSERT (n_bytes_per_buf > MAX_HDRS_LEN);
n_bytes_per_seg = MAX_HDRS_LEN + ctx->snd_mss;
ctx->n_bufs_per_seg = ceil ((f64) n_bytes_per_seg / n_bytes_per_buf);
always_inline int
session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node,
- session_event_t * e,
- stream_session_t * s, int *n_tx_packets,
+ session_manager_worker_t * wrk,
+ session_event_t * e, int *n_tx_packets,
u8 peek_data)
{
u32 next_index, next0, next1, *to_next, n_left_to_next;
u32 n_trace = vlib_get_trace_count (vm, node), n_bufs_needed = 0;
- u32 thread_index = s->thread_index, n_left, pbi;
+ u32 thread_index = vm->thread_index, n_left, pbi;
session_manager_main_t *smm = &session_manager_main;
- session_manager_worker_t *wrk = &smm->wrk[thread_index];
session_tx_context_t *ctx = &wrk->ctx;
transport_proto_t tp;
vlib_buffer_t *pb;
u16 n_bufs, rv;
- if (PREDICT_FALSE ((rv = session_tx_not_ready (s, peek_data))))
+ if (PREDICT_FALSE ((rv = session_tx_not_ready (ctx->s, peek_data))))
{
if (rv < 2)
vec_add1 (wrk->pending_event_vector, *e);
return SESSION_TX_NO_DATA;
}
- next_index = smm->session_type_to_next[s->session_type];
+ next_index = smm->session_type_to_next[ctx->s->session_type];
next0 = next1 = next_index;
- tp = session_get_transport_proto (s);
- ctx->s = s;
+ tp = session_get_transport_proto (ctx->s);
ctx->transport_vft = transport_protocol_get_vft (tp);
ctx->tc = session_tx_get_transport (ctx, peek_data);
ctx->snd_mss = ctx->transport_vft->send_mss (ctx->tc);
}
ctx->snd_space = transport_connection_snd_space (ctx->tc,
- vm->
- clib_time.last_cpu_time,
+ vm->clib_time.
+ last_cpu_time,
ctx->snd_mss);
if (ctx->snd_space == 0 || ctx->snd_mss == 0)
{
}
/* Allow enqueuing of a new event */
- svm_fifo_unset_event (s->server_tx_fifo);
+ svm_fifo_unset_event (ctx->s->server_tx_fifo);
/* Check how much we can pull. */
session_tx_set_dequeue_params (vm, ctx, VLIB_FRAME_SIZE - *n_tx_packets,
if (PREDICT_FALSE (n_trace > 0))
session_tx_trace_frame (vm, node, next_index, to_next,
- ctx->n_segs_per_evt, s, n_trace);
+ ctx->n_segs_per_evt, ctx->s, n_trace);
_vec_len (wrk->tx_buffers) = n_bufs;
*n_tx_packets += ctx->n_segs_per_evt;
/* If we couldn't dequeue all bytes mark as partially read */
ASSERT (ctx->left_to_snd == 0);
if (ctx->max_len_to_snd < ctx->max_dequeue)
- if (svm_fifo_set_event (s->server_tx_fifo))
+ if (svm_fifo_set_event (ctx->s->server_tx_fifo))
vec_add1 (wrk->pending_event_vector, *e);
if (!peek_data && ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM)
{
/* Fix dgram pre header */
if (ctx->max_len_to_snd < ctx->max_dequeue)
- svm_fifo_overwrite_head (s->server_tx_fifo, (u8 *) & ctx->hdr,
+ svm_fifo_overwrite_head (ctx->s->server_tx_fifo, (u8 *) & ctx->hdr,
sizeof (session_dgram_pre_hdr_t));
/* More data needs to be read */
- else if (svm_fifo_max_dequeue (s->server_tx_fifo) > 0)
- if (svm_fifo_set_event (s->server_tx_fifo))
+ else if (svm_fifo_max_dequeue (ctx->s->server_tx_fifo) > 0)
+ if (svm_fifo_set_event (ctx->s->server_tx_fifo))
vec_add1 (wrk->pending_event_vector, *e);
}
return SESSION_TX_OK;
int
session_tx_fifo_peek_and_snd (vlib_main_t * vm, vlib_node_runtime_t * node,
- session_event_t * e,
- stream_session_t * s, int *n_tx_pkts)
+ session_manager_worker_t * wrk,
+ session_event_t * e, int *n_tx_pkts)
{
- return session_tx_fifo_read_and_snd_i (vm, node, e, s, n_tx_pkts, 1);
+ return session_tx_fifo_read_and_snd_i (vm, node, wrk, e, n_tx_pkts, 1);
}
int
session_tx_fifo_dequeue_and_snd (vlib_main_t * vm, vlib_node_runtime_t * node,
- session_event_t * e,
- stream_session_t * s, int *n_tx_pkts)
+ session_manager_worker_t * wrk,
+ session_event_t * e, int *n_tx_pkts)
{
- return session_tx_fifo_read_and_snd_i (vm, node, e, s, n_tx_pkts, 0);
+ return session_tx_fifo_read_and_snd_i (vm, node, wrk, e, n_tx_pkts, 0);
}
int
session_tx_fifo_dequeue_internal (vlib_main_t * vm,
vlib_node_runtime_t * node,
- session_event_t * e,
- stream_session_t * s, int *n_tx_pkts)
+ session_manager_worker_t * wrk,
+ session_event_t * e, int *n_tx_pkts)
{
+ stream_session_t *s = wrk->ctx.s;
application_t *app;
+
if (PREDICT_FALSE (s->session_state == SESSION_STATE_CLOSED))
return 0;
app = application_get (s->t_app_index);
{
stream_session_t *s; /* $$$ prefetch 1 ahead maybe */
session_event_t *e;
- u8 want_tx_evt;
+ u8 need_tx_ntf;
e = &fifo_events[i];
switch (e->event_type)
clib_warning ("session was freed!");
continue;
}
-
- want_tx_evt = svm_fifo_want_tx_evt (s->server_tx_fifo);
+ wrk->ctx.s = s;
/* Spray packets in per session type frames, since they go to
* different nodes */
- rv = (smm->session_tx_fns[s->session_type]) (vm, node, e, s,
+ rv = (smm->session_tx_fns[s->session_type]) (vm, node, wrk, e,
&n_tx_packets);
if (PREDICT_TRUE (rv == SESSION_TX_OK))
{
- if (PREDICT_FALSE (want_tx_evt))
- {
- svm_fifo_set_want_tx_evt (s->server_tx_fifo, 0);
- session_dequeue_notify (s);
- }
+ need_tx_ntf = svm_fifo_needs_tx_ntf (s->server_tx_fifo,
+ wrk->ctx.max_len_to_snd);
+ if (PREDICT_FALSE (need_tx_ntf))
+ session_dequeue_notify (s);
}
else if (PREDICT_FALSE (rv == SESSION_TX_NO_BUFFERS))
{
}
break;
case FIFO_EVENT_DISCONNECT:
- /* Make sure stream disconnects run after the pending list is
- * drained */
s = session_get_from_handle_if_valid (e->session_handle);
if (PREDICT_FALSE (!s))
break;
- if (!e->postponed)
- {
- e->postponed = 1;
- vec_add1 (wrk->pending_disconnects, *e);
- continue;
- }
- /* If tx queue is still not empty, wait */
- if (svm_fifo_max_dequeue (s->server_tx_fifo))
+ /* Make sure session disconnects run after the pending list is
+ * drained, i.e., postpone if the first time. If not the first
+ * and the tx queue is still not empty, try to wait for some
+ * dispatch cycles */
+ if (!e->postponed
+ || (e->postponed < 200
+ && svm_fifo_max_dequeue (s->server_tx_fifo)))
{
+ e->postponed += 1;
vec_add1 (wrk->pending_disconnects, *e);
continue;
}
- stream_session_disconnect_transport (s);
+ session_transport_close (s);
break;
case FIFO_EVENT_BUILTIN_RX:
s = session_event_get_session (e, thread_index);
break;
case FIFO_EVENT_BUILTIN_TX:
s = session_get_from_handle_if_valid (e->session_handle);
+ wrk->ctx.s = s;
if (PREDICT_TRUE (s != 0))
- session_tx_fifo_dequeue_internal (vm, node, e, s, &n_tx_packets);
+ session_tx_fifo_dequeue_internal (vm, node, wrk, e,
+ &n_tx_packets);
break;
case FIFO_EVENT_RPC:
fp = e->rpc_args.fp;
case SESSION_CTRL_EVT_RESET_REPLY:
session_mq_reset_reply_handler (e->data);
break;
+ case SESSION_CTRL_EVT_WORKER_UPDATE:
+ session_mq_worker_update_handler (e->data);
+ break;
default:
clib_warning ("unhandled event type %d", e->event_type);
}
case FIFO_EVENT_RPC:
fformat (stdout, "[%04d] RPC call %llx with %llx\n",
- i, (u64) (e->rpc_args.fp), (u64) (e->rpc_args.arg));
+ i, (u64) (uword) (e->rpc_args.fp),
+ (u64) (uword) (e->rpc_args.arg));
break;
default: