summaryrefslogtreecommitdiffstats
path: root/src/vnet/session-apps/echo_server.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/session-apps/echo_server.c')
-rw-r--r--src/vnet/session-apps/echo_server.c104
1 files changed, 62 insertions, 42 deletions
diff --git a/src/vnet/session-apps/echo_server.c b/src/vnet/session-apps/echo_server.c
index 0bde2e4995f..85e6c299919 100644
--- a/src/vnet/session-apps/echo_server.c
+++ b/src/vnet/session-apps/echo_server.c
@@ -34,13 +34,14 @@ typedef struct
* Config params
*/
u8 no_echo; /**< Don't echo traffic */
- u32 fifo_size; /**< Fifo size */
+ u32 fifo_size; /**< Fifo size */
u32 rcv_buffer_size; /**< Rcv buffer size */
u32 prealloc_fifos; /**< Preallocate fifos */
u32 private_segment_count; /**< Number of private segments */
u32 private_segment_size; /**< Size of private segments */
char *server_uri; /**< Server URI */
u32 tls_engine; /**< TLS engine: mbedtls/openssl */
+ u8 is_dgram; /**< set if transport is dgram */
/*
* Test state
*/
@@ -126,25 +127,13 @@ test_bytes (echo_server_main_t * esm, int actual_transfer)
}
/*
- * If no-echo, just read the data and be done with it
+ * If no-echo, just drop the data and be done with it.
*/
int
echo_server_builtin_server_rx_callback_no_echo (stream_session_t * s)
{
- echo_server_main_t *esm = &echo_server_main;
- u32 my_thread_id = vlib_get_thread_index ();
- int actual_transfer;
- svm_fifo_t *rx_fifo;
-
- rx_fifo = s->server_rx_fifo;
-
- do
- {
- actual_transfer =
- svm_fifo_dequeue_nowait (rx_fifo, esm->rcv_buffer_size,
- esm->rx_buf[my_thread_id]);
- }
- while (actual_transfer > 0);
+ svm_fifo_t *rx_fifo = s->server_rx_fifo;
+ svm_fifo_dequeue_drop (rx_fifo, svm_fifo_max_dequeue (rx_fifo));
return 0;
}
@@ -157,6 +146,8 @@ echo_server_rx_callback (stream_session_t * s)
echo_server_main_t *esm = &echo_server_main;
session_fifo_event_t evt;
u32 thread_index = vlib_get_thread_index ();
+ app_session_transport_t at;
+ svm_queue_t *q;
ASSERT (s->thread_index == thread_index);
@@ -166,14 +157,29 @@ echo_server_rx_callback (stream_session_t * s)
ASSERT (rx_fifo->master_thread_index == thread_index);
ASSERT (tx_fifo->master_thread_index == thread_index);
- max_dequeue = svm_fifo_max_dequeue (s->server_rx_fifo);
- max_enqueue = svm_fifo_max_enqueue (s->server_tx_fifo);
+ max_enqueue = svm_fifo_max_enqueue (tx_fifo);
+ if (!esm->is_dgram)
+ {
+ max_dequeue = svm_fifo_max_dequeue (rx_fifo);
+ }
+ else
+ {
+ session_dgram_pre_hdr_t ph;
+ svm_fifo_peek (rx_fifo, 0, sizeof (ph), (u8 *) & ph);
+ max_dequeue = ph.data_length - ph.data_offset;
+ if (!esm->vpp_queue[s->thread_index])
+ {
+ q = session_manager_get_vpp_event_queue (s->thread_index);
+ esm->vpp_queue[s->thread_index] = q;
+ }
+ max_enqueue -= sizeof (session_dgram_hdr_t);
+ }
if (PREDICT_FALSE (max_dequeue == 0))
return 0;
/* Number of bytes we're going to copy */
- max_transfer = (max_dequeue < max_enqueue) ? max_dequeue : max_enqueue;
+ max_transfer = clib_min (max_dequeue, max_enqueue);
/* No space in tx fifo */
if (PREDICT_FALSE (max_transfer == 0))
@@ -184,16 +190,16 @@ echo_server_rx_callback (stream_session_t * s)
/* Program self-tap to retry */
if (svm_fifo_set_event (rx_fifo))
{
- svm_queue_t *q;
evt.fifo = rx_fifo;
evt.event_type = FIFO_EVENT_BUILTIN_RX;
- q = esm->vpp_queue[thread_index];
+ q = esm->vpp_queue[s->thread_index];
if (PREDICT_FALSE (q->cursize == q->maxsize))
clib_warning ("out of event queue space");
else if (svm_queue_add (q, (u8 *) & evt, 0))
clib_warning ("failed to enqueue self-tap");
+ vec_validate (esm->rx_retries[s->thread_index], s->session_index);
if (esm->rx_retries[thread_index][s->session_index] == 500000)
{
clib_warning ("session stuck: %U", format_stream_session, s, 2);
@@ -205,36 +211,47 @@ echo_server_rx_callback (stream_session_t * s)
return 0;
}
- _vec_len (esm->rx_buf[thread_index]) = max_transfer;
-
- actual_transfer = svm_fifo_dequeue_nowait (rx_fifo, max_transfer,
- esm->rx_buf[thread_index]);
+ vec_validate (esm->rx_buf[thread_index], max_transfer);
+ if (!esm->is_dgram)
+ {
+ actual_transfer = app_recv_stream_raw (rx_fifo,
+ esm->rx_buf[thread_index],
+ max_transfer,
+ 0 /* don't clear event */ );
+ }
+ else
+ {
+ actual_transfer = app_recv_dgram_raw (rx_fifo,
+ esm->rx_buf[thread_index],
+ max_transfer, &at,
+ 0 /* don't clear event */ );
+ }
ASSERT (actual_transfer == max_transfer);
-
-// test_bytes (esm, actual_transfer);
+ /* test_bytes (esm, actual_transfer); */
/*
* Echo back
*/
- n_written = svm_fifo_enqueue_nowait (tx_fifo, actual_transfer,
- esm->rx_buf[thread_index]);
-
- if (n_written != max_transfer)
- clib_warning ("short trout!");
-
- if (svm_fifo_set_event (tx_fifo))
+ if (!esm->is_dgram)
{
- /* Fabricate TX event, send to vpp */
- evt.fifo = tx_fifo;
- evt.event_type = FIFO_EVENT_APP_TX;
-
- if (svm_queue_add (esm->vpp_queue[s->thread_index],
- (u8 *) & evt, 0 /* do wait for mutex */ ))
- clib_warning ("failed to enqueue tx evt");
+ n_written = app_send_stream_raw (tx_fifo,
+ esm->vpp_queue[thread_index],
+ esm->rx_buf[thread_index],
+ actual_transfer, 0);
}
+ else
+ {
+ n_written = app_send_dgram_raw (tx_fifo, &at,
+ esm->vpp_queue[s->thread_index],
+ esm->rx_buf[thread_index],
+ actual_transfer, 0);
+ }
+
+ if (n_written != max_transfer)
+ clib_warning ("short trout! written %u read %u", n_written, max_transfer);
- if (PREDICT_FALSE (n_written < max_dequeue))
+ if (PREDICT_FALSE (svm_fifo_max_dequeue (rx_fifo)))
goto rx_event;
return 0;
@@ -411,6 +428,7 @@ echo_server_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
esm->private_segment_count = 0;
esm->private_segment_size = 0;
esm->tls_engine = TLS_ENGINE_OPENSSL;
+ esm->is_dgram = 0;
vec_free (esm->server_uri);
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
@@ -479,6 +497,8 @@ echo_server_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
clib_warning ("No uri provided! Using default: %s", default_uri);
esm->server_uri = (char *) format (0, "%s%c", default_uri, 0);
}
+ if (esm->server_uri[0] == 'u' && esm->server_uri[3] != 'c')
+ esm->is_dgram = 1;
rv = echo_server_create (vm, appns_id, appns_flags, appns_secret);
vec_free (appns_id);