summaryrefslogtreecommitdiffstats
path: root/src/vnet/session
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/session')
-rw-r--r--src/vnet/session/application.h3
-rw-r--r--src/vnet/session/node.c127
-rw-r--r--src/vnet/session/session.c63
-rw-r--r--src/vnet/session/session.h19
-rw-r--r--src/vnet/session/session_cli.c2
-rw-r--r--src/vnet/session/session_debug.h38
-rw-r--r--src/vnet/session/transport.h2
7 files changed, 165 insertions, 89 deletions
diff --git a/src/vnet/session/application.h b/src/vnet/session/application.h
index a60a8b8b5f9..480828f7b34 100644
--- a/src/vnet/session/application.h
+++ b/src/vnet/session/application.h
@@ -45,8 +45,7 @@ typedef struct _stream_session_cb_vft
void (*session_reset_callback) (stream_session_t * s);
/* Direct RX callback, for built-in servers */
- int (*builtin_server_rx_callback) (stream_session_t * session,
- session_fifo_event_t * ep);
+ int (*builtin_server_rx_callback) (stream_session_t * session);
/* Redirect connection to local server */
int (*redirect_connect_callback) (u32 api_client_index, void *mp);
diff --git a/src/vnet/session/node.c b/src/vnet/session/node.c
index 822afebde0c..8681105c284 100644
--- a/src/vnet/session/node.c
+++ b/src/vnet/session/node.c
@@ -13,21 +13,14 @@
* limitations under the License.
*/
+#include <math.h>
#include <vlib/vlib.h>
#include <vnet/vnet.h>
-#include <vnet/pg/pg.h>
-#include <vnet/ip/ip.h>
-
#include <vnet/tcp/tcp.h>
-
-#include <vppinfra/hash.h>
-#include <vppinfra/error.h>
#include <vppinfra/elog.h>
-#include <vlibmemory/unix_shared_memory_queue.h>
-
-#include <vnet/udp/udp_packet.h>
-#include <math.h>
+#include <vnet/session/application.h>
#include <vnet/session/session_debug.h>
+#include <vlibmemory/unix_shared_memory_queue.h>
vlib_node_registration_t session_queue_node;
@@ -52,8 +45,8 @@ format_session_queue_trace (u8 * s, va_list * args)
vlib_node_registration_t session_queue_node;
-#define foreach_session_queue_error \
-_(TX, "Packets transmitted") \
+#define foreach_session_queue_error \
+_(TX, "Packets transmitted") \
_(TIMER, "Timer events")
typedef enum
@@ -91,10 +84,10 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node,
transport_proto_vft_t *transport_vft;
u32 next_index, next0, *to_next, n_left_to_next, bi0;
vlib_buffer_t *b0;
- u32 rx_offset;
+ u32 rx_offset = 0, max_dequeue0;
u16 snd_mss0;
u8 *data0;
- int i;
+ int i, n_bytes_read;
next_index = next0 = session_type_to_next[s0->session_type];
@@ -106,24 +99,33 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node,
snd_mss0 = transport_vft->send_mss (tc0);
/* Can't make any progress */
- if (snd_space0 == 0 || svm_fifo_max_dequeue (s0->server_tx_fifo) == 0
- || snd_mss0 == 0)
+ if (snd_space0 == 0 || snd_mss0 == 0)
{
vec_add1 (smm->evts_partially_read[thread_index], *e0);
return 0;
}
- ASSERT (e0->enqueue_length > 0);
-
- /* Ensure we're not writing more than transport window allows */
- max_len_to_snd0 = clib_min (e0->enqueue_length, snd_space0);
-
if (peek_data)
{
/* Offset in rx fifo from where to peek data */
rx_offset = transport_vft->tx_fifo_offset (tc0);
}
+ /* Check how much we can pull. If buffering, subtract the offset */
+ max_dequeue0 = svm_fifo_max_dequeue (s0->server_tx_fifo) - rx_offset;
+
+ /* Allow enqueuing of a new event */
+ svm_fifo_unset_event (s0->server_tx_fifo);
+
+ /* Nothing to read return */
+ if (max_dequeue0 == 0)
+ {
+ return 0;
+ }
+
+ /* Ensure we're not writing more than transport window allows */
+ max_len_to_snd0 = clib_min (max_dequeue0, snd_space0);
+
/* TODO check if transport is willing to send len_to_snd0
* bytes (Nagle) */
@@ -147,13 +149,10 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node,
* XXX 0.9 because when debugging we might not get a full frame */
if (PREDICT_FALSE (n_bufs < 0.9 * VLIB_FRAME_SIZE))
{
- /* Keep track of how much we've dequeued and exit */
- if (left_to_snd0 != max_len_to_snd0)
+ if (svm_fifo_set_event (s0->server_tx_fifo))
{
- e0->enqueue_length -= max_len_to_snd0 - left_to_snd0;
vec_add1 (smm->evts_partially_read[thread_index], *e0);
}
-
return -1;
}
@@ -198,9 +197,9 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node,
len_to_deq0 = (left_to_snd0 < snd_mss0) ? left_to_snd0 : snd_mss0;
/* *INDENT-OFF* */
- SESSION_EVT_DBG(s0, SESSION_EVT_DEQ, ({
+ SESSION_EVT_DBG(SESSION_EVT_DEQ, s0, ({
ed->data[0] = e0->event_id;
- ed->data[1] = e0->enqueue_length;
+ ed->data[1] = max_dequeue0;
ed->data[2] = len_to_deq0;
ed->data[3] = left_to_snd0;
}));
@@ -214,29 +213,30 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node,
* 2) buffer chains */
if (peek_data)
{
- int n_bytes_read;
n_bytes_read = svm_fifo_peek (s0->server_tx_fifo, s0->pid,
rx_offset, len_to_deq0, data0);
- if (n_bytes_read < 0)
+ if (n_bytes_read <= 0)
goto dequeue_fail;
/* Keep track of progress locally, transport is also supposed to
- * increment it independently when pushing header */
+ * increment it independently when pushing the header */
rx_offset += n_bytes_read;
}
else
{
- if (svm_fifo_dequeue_nowait (s0->server_tx_fifo, s0->pid,
- len_to_deq0, data0) < 0)
+ n_bytes_read = svm_fifo_dequeue_nowait (s0->server_tx_fifo,
+ s0->pid, len_to_deq0,
+ data0);
+ if (n_bytes_read <= 0)
goto dequeue_fail;
}
- b0->current_length = len_to_deq0;
+ b0->current_length = n_bytes_read;
/* Ask transport to push header */
transport_vft->push_header (tc0, b0);
- left_to_snd0 -= len_to_deq0;
+ left_to_snd0 -= n_bytes_read;
*n_tx_packets = *n_tx_packets + 1;
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
@@ -246,25 +246,31 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node,
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
- /* If we couldn't dequeue all bytes store progress */
- if (max_len_to_snd0 < e0->enqueue_length)
+ /* If we couldn't dequeue all bytes mark as partially read */
+ if (max_len_to_snd0 < max_dequeue0)
{
- e0->enqueue_length -= max_len_to_snd0;
- vec_add1 (smm->evts_partially_read[thread_index], *e0);
+ /* If we don't already have new event */
+ if (svm_fifo_set_event (s0->server_tx_fifo))
+ {
+ vec_add1 (smm->evts_partially_read[thread_index], *e0);
+ }
}
return 0;
dequeue_fail:
- /* Can't read from fifo. Store event rx progress, save as partially read,
- * return buff to free list and return */
- e0->enqueue_length -= max_len_to_snd0 - left_to_snd0;
- vec_add1 (smm->evts_partially_read[thread_index], *e0);
+ /*
+ * Can't read from fifo. If we don't already have an event, save as partially
+ * read, return buff to free list and return
+ */
+ clib_warning ("dequeue fail");
- to_next -= 1;
- n_left_to_next += 1;
+ if (svm_fifo_set_event (s0->server_tx_fifo))
+ {
+ vec_add1 (smm->evts_partially_read[thread_index], *e0);
+ }
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next + 1);
_vec_len (smm->tx_buffers[thread_index]) += 1;
- clib_warning ("dequeue fail");
return 0;
}
@@ -298,6 +304,7 @@ session_queue_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
session_fifo_event_t *my_fifo_events, *e;
u32 n_to_dequeue, n_events;
unix_shared_memory_queue_t *q;
+ application_t *app;
int n_tx_packets = 0;
u32 my_thread_index = vm->cpu_index;
int i, rv;
@@ -321,13 +328,18 @@ session_queue_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
if (n_to_dequeue == 0 && vec_len (my_fifo_events) == 0)
return 0;
+ SESSION_EVT_DBG (SESSION_EVT_DEQ_NODE, 0);
+
/*
* If we didn't manage to process previous events try going
* over them again without dequeuing new ones.
*/
/* XXX: Block senders to sessions that can't keep up */
if (vec_len (my_fifo_events) >= 100)
- goto skip_dequeue;
+ {
+ clib_warning ("too many fifo events unsolved");
+ goto skip_dequeue;
+ }
/* See you in the next life, don't be late */
if (pthread_mutex_trylock (&q->mutex))
@@ -352,19 +364,17 @@ skip_dequeue:
{
svm_fifo_t *f0; /* $$$ prefetch 1 ahead maybe */
stream_session_t *s0;
- u32 server_session_index0, server_thread_index0;
+ u32 session_index0;
session_fifo_event_t *e0;
e0 = &my_fifo_events[i];
f0 = e0->fifo;
- server_session_index0 = f0->server_session_index;
- server_thread_index0 = f0->server_thread_index;
+ session_index0 = f0->server_session_index;
/* $$$ add multiple event queues, per vpp worker thread */
- ASSERT (server_thread_index0 == my_thread_index);
+ ASSERT (f0->server_thread_index == my_thread_index);
- s0 = stream_session_get_if_valid (server_session_index0,
- my_thread_index);
+ s0 = stream_session_get_if_valid (session_index0, my_thread_index);
if (CLIB_DEBUG && !s0)
{
@@ -385,11 +395,20 @@ skip_dequeue:
rv = (smm->session_tx_fns[s0->session_type]) (vm, node, smm, e0, s0,
my_thread_index,
&n_tx_packets);
+ /* Out of buffers */
if (rv < 0)
goto done;
break;
-
+ case FIFO_EVENT_SERVER_EXIT:
+ stream_session_disconnect (s0);
+ break;
+ case FIFO_EVENT_BUILTIN_RX:
+ svm_fifo_unset_event (s0->server_rx_fifo);
+ /* Get session's server */
+ app = application_get (s0->app_index);
+ app->cb_fns.builtin_server_rx_callback (s0);
+ break;
default:
clib_warning ("unhandled event type %d", e0->event_type);
}
@@ -418,6 +437,8 @@ done:
vlib_node_increment_counter (vm, session_queue_node.index,
SESSION_QUEUE_ERROR_TX, n_tx_packets);
+ SESSION_EVT_DBG (SESSION_EVT_DEQ_NODE, 1);
+
return n_tx_packets;
}
diff --git a/src/vnet/session/session.c b/src/vnet/session/session.c
index 06e2a09af31..f10918aa3c4 100644
--- a/src/vnet/session/session.c
+++ b/src/vnet/session/session.c
@@ -804,30 +804,36 @@ stream_session_enqueue_notify (stream_session_t * s, u8 block)
/* Get session's server */
app = application_get (s->app_index);
- /* Fabricate event */
- evt.fifo = s->server_rx_fifo;
- evt.event_type = FIFO_EVENT_SERVER_RX;
- evt.event_id = serial_number++;
- evt.enqueue_length = svm_fifo_max_dequeue (s->server_rx_fifo);
-
/* Built-in server? Hand event to the callback... */
if (app->cb_fns.builtin_server_rx_callback)
- return app->cb_fns.builtin_server_rx_callback (s, &evt);
-
- /* Add event to server's event queue */
- q = app->event_queue;
+ return app->cb_fns.builtin_server_rx_callback (s);
- /* Based on request block (or not) for lack of space */
- if (block || PREDICT_TRUE (q->cursize < q->maxsize))
- unix_shared_memory_queue_add (app->event_queue, (u8 *) & evt,
- 0 /* do wait for mutex */ );
- else
- return -1;
+ /* If no event, send one */
+ if (svm_fifo_set_event (s->server_rx_fifo))
+ {
+ /* Fabricate event */
+ evt.fifo = s->server_rx_fifo;
+ evt.event_type = FIFO_EVENT_SERVER_RX;
+ evt.event_id = serial_number++;
+
+ /* Add event to server's event queue */
+ q = app->event_queue;
+
+ /* Based on request block (or not) for lack of space */
+ if (block || PREDICT_TRUE (q->cursize < q->maxsize))
+ unix_shared_memory_queue_add (app->event_queue, (u8 *) & evt,
+ 0 /* do wait for mutex */ );
+ else
+ {
+ clib_warning ("fifo full");
+ return -1;
+ }
+ }
/* *INDENT-OFF* */
- SESSION_EVT_DBG(s, SESSION_EVT_ENQ, ({
+ SESSION_EVT_DBG(SESSION_EVT_ENQ, s, ({
ed->data[0] = evt.event_id;
- ed->data[1] = evt.enqueue_length;
+ ed->data[1] = svm_fifo_max_dequeue (s->server_rx_fifo);
}));
/* *INDENT-ON* */
@@ -1192,8 +1198,29 @@ stream_session_open (u8 sst, ip46_address_t * addr, u16 port_host_byte_order,
void
stream_session_disconnect (stream_session_t * s)
{
+// session_fifo_event_t evt;
+
s->session_state = SESSION_STATE_CLOSED;
+ /* RPC to vpp evt queue in the right thread */
+
tp_vfts[s->session_type].close (s->connection_index, s->thread_index);
+
+// {
+// /* Fabricate event */
+// evt.fifo = s->server_rx_fifo;
+// evt.event_type = FIFO_EVENT_SERVER_RX;
+// evt.event_id = serial_number++;
+//
+// /* Based on request block (or not) for lack of space */
+// if (PREDICT_TRUE(q->cursize < q->maxsize))
+// unix_shared_memory_queue_add (app->event_queue, (u8 *) &evt,
+// 0 /* do wait for mutex */);
+// else
+// {
+// clib_warning("fifo full");
+// return -1;
+// }
+// }
}
/**
diff --git a/src/vnet/session/session.h b/src/vnet/session/session.h
index 96c00d87766..a39bc06ffca 100644
--- a/src/vnet/session/session.h
+++ b/src/vnet/session/session.h
@@ -33,6 +33,7 @@ typedef enum
FIFO_EVENT_SERVER_TX,
FIFO_EVENT_TIMEOUT,
FIFO_EVENT_SERVER_EXIT,
+ FIFO_EVENT_BUILTIN_RX
} fifo_event_type_t;
#define foreach_session_input_error \
@@ -91,14 +92,13 @@ typedef enum
SESSION_STATE_N_STATES,
} stream_session_state_t;
-typedef CLIB_PACKED (struct
- {
- svm_fifo_t * fifo;
- u8 event_type;
- /* $$$$ for event logging */
- u16 event_id;
- u32 enqueue_length;
- }) session_fifo_event_t;
+/* *INDENT-OFF* */
+typedef CLIB_PACKED (struct {
+ svm_fifo_t * fifo;
+ u8 event_type;
+ u16 event_id;
+}) session_fifo_event_t;
+/* *INDENT-ON* */
typedef struct _stream_session_t
{
@@ -333,7 +333,7 @@ stream_session_get_index (stream_session_t * s)
}
always_inline u32
-stream_session_max_enqueue (transport_connection_t * tc)
+stream_session_max_rx_enqueue (transport_connection_t * tc)
{
stream_session_t *s = stream_session_get (tc->s_index, tc->thread_index);
return svm_fifo_max_enqueue (s->server_rx_fifo);
@@ -346,7 +346,6 @@ stream_session_fifo_size (transport_connection_t * tc)
return s->server_rx_fifo->nitems;
}
-
int
stream_session_enqueue_data (transport_connection_t * tc, u8 * data, u16 len,
u8 queue_event);
diff --git a/src/vnet/session/session_cli.c b/src/vnet/session/session_cli.c
index b029ee6549a..38762afc8bb 100644
--- a/src/vnet/session/session_cli.c
+++ b/src/vnet/session/session_cli.c
@@ -107,7 +107,7 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
{
if (once_per_pool)
{
- str = format (str, "%-40s%-20s%-20s%-15s",
+ str = format (str, "%-50s%-20s%-20s%-15s",
"Connection", "Rx fifo", "Tx fifo",
"Session Index");
vlib_cli_output (vm, "%v", str);
diff --git a/src/vnet/session/session_debug.h b/src/vnet/session/session_debug.h
index 858f12e0287..80a97cd5f09 100644
--- a/src/vnet/session/session_debug.h
+++ b/src/vnet/session/session_debug.h
@@ -21,7 +21,8 @@
#define foreach_session_dbg_evt \
_(ENQ, "enqueue") \
- _(DEQ, "dequeue")
+ _(DEQ, "dequeue") \
+ _(DEQ_NODE, "dequeue")
typedef enum _session_evt_dbg
{
@@ -30,7 +31,10 @@ typedef enum _session_evt_dbg
#undef _
} session_evt_dbg_e;
-#if TRANSPORT_DEBUG
+#define SESSION_DBG (0)
+#define SESSION_DEQ_NODE_EVTS (0)
+
+#if TRANSPORT_DEBUG && SESSION_DBG
#define DEC_SESSION_ETD(_s, _e, _size) \
struct \
@@ -44,6 +48,12 @@ typedef enum _session_evt_dbg
ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, \
_e, _tc->elog_track)
+#define DEC_SESSION_ED(_e, _size) \
+ struct \
+ { \
+ u32 data[_size]; \
+ } * ed; \
+ ed = ELOG_DATA (&vlib_global_main.elog_main, _e)
#define SESSION_EVT_DEQ_HANDLER(_s, _body) \
{ \
@@ -67,13 +77,33 @@ typedef enum _session_evt_dbg
do { _body; } while (0); \
}
+#if SESSION_DEQ_NODE_EVTS
+#define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt) \
+{ \
+ ELOG_TYPE_DECLARE (_e) = \
+ { \
+ .format = "deq-node: %s", \
+ .format_args = "t4", \
+ .n_enum_strings = 2, \
+ .enum_strings = { \
+ "start", \
+ "end", \
+ }, \
+ }; \
+ DEC_SESSION_ED(_e, 1); \
+ ed->data[0] = _node_evt; \
+}
+#else
+#define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt)
+#endif
+
#define CONCAT_HELPER(_a, _b) _a##_b
#define CC(_a, _b) CONCAT_HELPER(_a, _b)
-#define SESSION_EVT_DBG(_s, _evt, _body) CC(_evt, _HANDLER)(_s, _body)
+#define SESSION_EVT_DBG(_evt, _args...) CC(_evt, _HANDLER)(_args)
#else
-#define SESSION_EVT_DBG(_s, _evt, _body)
+#define SESSION_EVT_DBG(_evt, _args...)
#endif
#endif /* SRC_VNET_SESSION_SESSION_DEBUG_H_ */
diff --git a/src/vnet/session/transport.h b/src/vnet/session/transport.h
index 421121d2fa6..2f912cbc987 100644
--- a/src/vnet/session/transport.h
+++ b/src/vnet/session/transport.h
@@ -38,7 +38,7 @@ typedef struct _transport_connection
u32 thread_index; /**< Worker-thread index */
#if TRANSPORT_DEBUG
- elog_track_t elog_track; /**< Debug purposes */
+ elog_track_t elog_track; /**< Event logging */
#endif
/** Macros for 'derived classes' where base is named "connection" */