aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/hs_apps/echo_client.c67
-rw-r--r--src/plugins/hs_apps/echo_client.h7
-rw-r--r--src/plugins/hs_apps/echo_server.c49
-rw-r--r--src/plugins/hs_apps/hs_test.h19
4 files changed, 56 insertions, 86 deletions
diff --git a/src/plugins/hs_apps/echo_client.c b/src/plugins/hs_apps/echo_client.c
index 453cbed3859..d1443e75e80 100644
--- a/src/plugins/hs_apps/echo_client.c
+++ b/src/plugins/hs_apps/echo_client.c
@@ -64,7 +64,7 @@ ec_session_alloc (ec_worker_t *wrk)
ec_session_t *ecs;
pool_get_zero (wrk->sessions, ecs);
- ecs->data.session_index = ecs - wrk->sessions;
+ ecs->session_index = ecs - wrk->sessions;
ecs->thread_index = wrk->thread_index;
return ecs;
@@ -89,23 +89,24 @@ send_data_chunk (ec_main_t *ecm, ec_session_t *es)
bytes_this_chunk =
clib_min (test_buf_len - test_buf_offset, es->bytes_to_send);
- if (!ecm->is_dgram)
+ if (!es->is_dgram)
{
if (ecm->no_copy)
{
- svm_fifo_t *f = es->data.tx_fifo;
+ svm_fifo_t *f = es->tx_fifo;
rv = clib_min (svm_fifo_max_enqueue_prod (f), bytes_this_chunk);
svm_fifo_enqueue_nocopy (f, rv);
session_send_io_evt_to_thread_custom (
&es->vpp_session_index, es->thread_index, SESSION_IO_EVT_TX);
}
else
- rv = app_send_stream (&es->data, test_data + test_buf_offset,
- bytes_this_chunk, 0);
+ rv =
+ app_send_stream ((app_session_t *) es, test_data + test_buf_offset,
+ bytes_this_chunk, 0);
}
else
{
- svm_fifo_t *f = es->data.tx_fifo;
+ svm_fifo_t *f = es->tx_fifo;
u32 max_enqueue = svm_fifo_max_enqueue_prod (f);
if (max_enqueue < sizeof (session_dgram_hdr_t))
@@ -116,7 +117,7 @@ send_data_chunk (ec_main_t *ecm, ec_session_t *es)
if (ecm->no_copy)
{
session_dgram_hdr_t hdr;
- app_session_transport_t *at = &es->data.transport;
+ app_session_transport_t *at = &es->transport;
rv = clib_min (max_enqueue, bytes_this_chunk);
@@ -138,8 +139,9 @@ send_data_chunk (ec_main_t *ecm, ec_session_t *es)
{
bytes_this_chunk = clib_min (bytes_this_chunk, max_enqueue);
bytes_this_chunk = clib_min (bytes_this_chunk, 1460);
- rv = app_send_dgram (&es->data, test_data + test_buf_offset,
- bytes_this_chunk, 0);
+ rv =
+ app_send_dgram ((app_session_t *) es, test_data + test_buf_offset,
+ bytes_this_chunk, 0);
}
}
@@ -173,17 +175,13 @@ static void
receive_data_chunk (ec_worker_t *wrk, ec_session_t *es)
{
ec_main_t *ecm = &ec_main;
- svm_fifo_t *rx_fifo = es->data.rx_fifo;
+ svm_fifo_t *rx_fifo = es->rx_fifo;
int n_read, i;
if (ecm->cfg.test_bytes)
{
- if (!ecm->is_dgram)
- n_read =
- app_recv_stream (&es->data, wrk->rx_buf, vec_len (wrk->rx_buf));
- else
- n_read =
- app_recv_dgram (&es->data, wrk->rx_buf, vec_len (wrk->rx_buf));
+ n_read =
+ app_recv ((app_session_t *) es, wrk->rx_buf, vec_len (wrk->rx_buf));
}
else
{
@@ -597,27 +595,15 @@ quic_ec_session_connected_callback (u32 app_index, u32 api_context,
* Setup session
*/
es = ec_session_alloc (wrk);
+ hs_test_app_session_init (es, s);
es->bytes_to_send = ecm->bytes_to_send;
es->bytes_to_receive = ecm->echo_bytes ? ecm->bytes_to_send : 0ULL;
- es->data.rx_fifo = s->rx_fifo;
- es->data.rx_fifo->shr->client_session_index = es->data.session_index;
- es->data.tx_fifo = s->tx_fifo;
- es->data.tx_fifo->shr->client_session_index = es->data.session_index;
- es->data.vpp_evt_q = wrk->vpp_event_queue;
es->vpp_session_handle = session_handle (s);
es->vpp_session_index = s->session_index;
- s->opaque = es->data.session_index;
-
- if (ecm->is_dgram)
- {
- transport_connection_t *tc;
- tc = session_get_transport (s);
- clib_memcpy_fast (&es->data.transport, tc, sizeof (es->data.transport));
- es->data.is_dgram = 1;
- }
+ s->opaque = es->session_index;
- vec_add1 (wrk->conn_indices, es->data.session_index);
+ vec_add1 (wrk->conn_indices, es->session_index);
clib_atomic_fetch_add (&ecm->ready_connections, 1);
if (ecm->ready_connections == ecm->expected_connections)
{
@@ -663,27 +649,15 @@ ec_session_connected_callback (u32 app_index, u32 api_context, session_t *s,
* Setup session
*/
es = ec_session_alloc (wrk);
+ hs_test_app_session_init (es, s);
es->bytes_to_send = ecm->bytes_to_send;
es->bytes_to_receive = ecm->echo_bytes ? ecm->bytes_to_send : 0ULL;
- es->data.rx_fifo = s->rx_fifo;
- es->data.rx_fifo->shr->client_session_index = es->data.session_index;
- es->data.tx_fifo = s->tx_fifo;
- es->data.tx_fifo->shr->client_session_index = es->data.session_index;
- es->data.vpp_evt_q = wrk->vpp_event_queue;
es->vpp_session_handle = session_handle (s);
es->vpp_session_index = s->session_index;
- s->opaque = es->data.session_index;
-
- if (ecm->is_dgram)
- {
- transport_connection_t *tc;
- tc = session_get_transport (s);
- clib_memcpy_fast (&es->data.transport, tc, sizeof (es->data.transport));
- es->data.is_dgram = 1;
- }
+ s->opaque = es->session_index;
- vec_add1 (wrk->conn_indices, es->data.session_index);
+ vec_add1 (wrk->conn_indices, es->session_index);
clib_atomic_fetch_add (&ecm->ready_connections, 1);
if (ecm->ready_connections == ecm->expected_connections)
{
@@ -1194,7 +1168,6 @@ parse_config:
goto cleanup;
}
ecm->transport_proto = ecm->connect_sep.transport_proto;
- ecm->is_dgram = (ecm->transport_proto == TRANSPORT_PROTO_UDP);
if (ecm->prealloc_sessions)
ec_prealloc_sessions (ecm);
diff --git a/src/plugins/hs_apps/echo_client.h b/src/plugins/hs_apps/echo_client.h
index 7af4b8a5262..5868c3652ce 100644
--- a/src/plugins/hs_apps/echo_client.h
+++ b/src/plugins/hs_apps/echo_client.h
@@ -25,8 +25,10 @@
typedef struct ec_session_
{
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
- app_session_t data;
- u32 vpp_session_index;
+#define _(type, name) type name;
+ foreach_app_session_field
+#undef _
+ u32 vpp_session_index;
u32 thread_index;
u64 bytes_to_send;
u64 bytes_sent;
@@ -87,7 +89,6 @@ typedef struct
u32 private_segment_count; /**< Number of private fifo segs */
u64 private_segment_size; /**< size of private fifo segs */
u32 tls_engine; /**< TLS engine mbedtls/openssl */
- u8 is_dgram;
u32 no_copy; /**< Don't memcpy data to tx fifo */
u32 quic_streams; /**< QUIC streams per connection */
u32 ckpair_index; /**< Cert key pair for tls/quic */
diff --git a/src/plugins/hs_apps/echo_server.c b/src/plugins/hs_apps/echo_server.c
index f4f9acf1d0b..50dc03d86bd 100644
--- a/src/plugins/hs_apps/echo_server.c
+++ b/src/plugins/hs_apps/echo_server.c
@@ -25,8 +25,10 @@ static void es_set_echo_rx_callbacks (u8 no_echo);
typedef struct
{
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
- u32 session_index;
- u64 vpp_session_handle;
+#define _(type, name) type name;
+ foreach_app_session_field
+#undef _
+ u64 vpp_session_handle;
u32 vpp_session_index;
u32 rx_retries;
u8 byte_index;
@@ -57,7 +59,6 @@ typedef struct
char *server_uri; /**< Server URI */
u32 tls_engine; /**< TLS engine: mbedtls/openssl */
u32 ckpair_index; /**< Cert and key for tls/quic */
- u8 is_dgram; /**< set if transport is dgram */
/*
* Test state
@@ -128,6 +129,7 @@ es_session_alloc_and_init (session_t *s)
es_worker_t *wrk = es_worker_get (s->thread_index);
es = es_session_alloc (wrk);
+ hs_test_app_session_init (es, s);
es->vpp_session_index = s->session_index;
es->vpp_session_handle = session_handle (s);
s->opaque = es->session_index;
@@ -373,7 +375,6 @@ echo_server_rx_callback (session_t * s)
svm_fifo_t *tx_fifo, *rx_fifo;
echo_server_main_t *esm = &echo_server_main;
u32 thread_index = vlib_get_thread_index ();
- app_session_transport_t at;
es_worker_t *wrk;
es_session_t *es;
@@ -390,12 +391,9 @@ echo_server_rx_callback (session_t * s)
wrk = es_worker_get (thread_index);
max_enqueue = svm_fifo_max_enqueue_prod (tx_fifo);
+ es = es_session_get (wrk, s->opaque);
- if (!esm->is_dgram)
- {
- max_dequeue = svm_fifo_max_dequeue_cons (rx_fifo);
- }
- else
+ if (es->is_dgram)
{
session_dgram_pre_hdr_t ph;
svm_fifo_peek (rx_fifo, 0, sizeof (ph), (u8 *) & ph);
@@ -403,12 +401,14 @@ echo_server_rx_callback (session_t * s)
ASSERT (wrk->vpp_event_queue);
max_enqueue -= sizeof (session_dgram_hdr_t);
}
+ else
+ {
+ max_dequeue = svm_fifo_max_dequeue_cons (rx_fifo);
+ }
if (PREDICT_FALSE (max_dequeue == 0))
return 0;
- es = es_session_get (wrk, s->opaque);
-
/* Number of bytes we're going to copy */
max_transfer = clib_min (max_dequeue, max_enqueue);
@@ -439,18 +439,7 @@ echo_server_rx_callback (session_t * s)
}
vec_validate (wrk->rx_buf, max_transfer);
- if (!esm->is_dgram)
- {
- actual_transfer =
- app_recv_stream_raw (rx_fifo, wrk->rx_buf, max_transfer,
- 0 /* don't clear event */, 0 /* peek */);
- }
- else
- {
- actual_transfer =
- app_recv_dgram_raw (rx_fifo, wrk->rx_buf, max_transfer, &at,
- 0 /* don't clear event */, 0 /* peek */);
- }
+ actual_transfer = app_recv ((app_session_t *) es, wrk->rx_buf, max_transfer);
ASSERT (actual_transfer == max_transfer);
if (esm->cfg.test_bytes)
@@ -462,18 +451,7 @@ echo_server_rx_callback (session_t * s)
* Echo back
*/
- if (!esm->is_dgram)
- {
- n_written = app_send_stream_raw (tx_fifo, wrk->vpp_event_queue,
- wrk->rx_buf, actual_transfer,
- SESSION_IO_EVT_TX, 1 /* do_evt */, 0);
- }
- else
- {
- n_written = app_send_dgram_raw (tx_fifo, &at, wrk->vpp_event_queue,
- wrk->rx_buf, actual_transfer,
- SESSION_IO_EVT_TX, 1 /* do_evt */, 0);
- }
+ n_written = app_send ((app_session_t *) es, wrk->rx_buf, actual_transfer, 0);
if (n_written != max_transfer)
es_err ("short trout! written %u read %u", n_written, max_transfer);
@@ -772,7 +750,6 @@ echo_server_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
goto cleanup;
}
esm->transport_proto = sep.transport_proto;
- esm->is_dgram = (sep.transport_proto == TRANSPORT_PROTO_UDP);
rv = echo_server_create (vm, appns_id, appns_flags, appns_secret);
if (rv)
diff --git a/src/plugins/hs_apps/hs_test.h b/src/plugins/hs_apps/hs_test.h
index 71f417824d5..167c7957229 100644
--- a/src/plugins/hs_apps/hs_test.h
+++ b/src/plugins/hs_apps/hs_test.h
@@ -18,6 +18,7 @@
#define __included_hs_test_t__
#include <vnet/session/application_interface.h>
+#include <vnet/session/session.h>
#define HS_TEST_CFG_CTRL_MAGIC 0xfeedface
#define HS_TEST_CFG_TXBUF_SIZE_DEF 8192
@@ -190,4 +191,22 @@ hs_make_data_port (u16 p)
return clib_host_to_net_u16 (p + 1);
}
+static inline void
+hs_test_app_session_init_ (app_session_t *as, session_t *s)
+{
+ as->rx_fifo = s->rx_fifo;
+ as->tx_fifo = s->tx_fifo;
+ as->vpp_evt_q = session_main_get_vpp_event_queue (s->thread_index);
+ if (session_get_transport_proto (s) == TRANSPORT_PROTO_UDP)
+ {
+ transport_connection_t *tc;
+ tc = session_get_transport (s);
+ clib_memcpy_fast (&as->transport, tc, sizeof (as->transport));
+ as->is_dgram = 1;
+ }
+}
+
+#define hs_test_app_session_init(_as, _s) \
+ hs_test_app_session_init_ ((app_session_t *) (_as), (_s))
+
#endif /* __included_hs_test_t__ */