}
static void
-send_data_chunk (echo_client_main_t * ecm, session_t * s)
+send_data_chunk (echo_client_main_t * ecm, eclient_session_t * s)
{
u8 *test_data = ecm->connect_test_data;
int test_buf_len, test_buf_offset, rv;
u32 bytes_this_chunk;
- ASSERT (vec_len (test_data) > 0);
test_buf_len = vec_len (test_data);
+ ASSERT (test_buf_len > 0);
test_buf_offset = s->bytes_sent % test_buf_len;
bytes_this_chunk = clib_min (test_buf_len - test_buf_offset,
s->bytes_to_send);
if (!ecm->is_dgram)
- rv = app_send_stream (&s->data, test_data + test_buf_offset,
- bytes_this_chunk, 0);
+ {
+ if (ecm->no_copy)
+ {
+ svm_fifo_t *f = s->data.tx_fifo;
+ rv = clib_min (svm_fifo_max_enqueue (f), bytes_this_chunk);
+ svm_fifo_enqueue_nocopy (f, rv);
+ session_send_io_evt_to_thread_custom (f, s->thread_index,
+ FIFO_EVENT_APP_TX);
+ }
+ else
+ rv = app_send_stream (&s->data, test_data + test_buf_offset,
+ bytes_this_chunk, 0);
+ }
else
- rv = app_send_dgram (&s->data, test_data + test_buf_offset,
- bytes_this_chunk, 0);
+ {
+ if (ecm->no_copy)
+ {
+ session_dgram_hdr_t hdr;
+ svm_fifo_t *f = s->data.tx_fifo;
+ app_session_transport_t *at = &s->data.transport;
+ u32 max_enqueue = svm_fifo_max_enqueue (f);
+
+ if (max_enqueue <= sizeof (session_dgram_hdr_t))
+ return;
+
+ max_enqueue -= sizeof (session_dgram_hdr_t);
+ rv = clib_min (max_enqueue, bytes_this_chunk);
+
+ hdr.data_length = rv;
+ hdr.data_offset = 0;
+ clib_memcpy_fast (&hdr.rmt_ip, &at->rmt_ip,
+ sizeof (ip46_address_t));
+ hdr.is_ip4 = at->is_ip4;
+ hdr.rmt_port = at->rmt_port;
+ clib_memcpy_fast (&hdr.lcl_ip, &at->lcl_ip,
+ sizeof (ip46_address_t));
+ hdr.lcl_port = at->lcl_port;
+ svm_fifo_enqueue_nowait (f, sizeof (hdr), (u8 *) & hdr);
+ svm_fifo_enqueue_nocopy (f, rv);
+ session_send_io_evt_to_thread_custom (f, s->thread_index,
+ FIFO_EVENT_APP_TX);
+ }
+ else
+ rv = app_send_dgram (&s->data, test_data + test_buf_offset,
+ bytes_this_chunk, 0);
+ }
/* If we managed to enqueue data... */
if (rv > 0)
}
static void
-receive_data_chunk (echo_client_main_t * ecm, session_t * s)
+receive_data_chunk (echo_client_main_t * ecm, eclient_session_t * s)
{
svm_fifo_t *rx_fifo = s->data.rx_fifo;
u32 thread_index = vlib_get_thread_index ();
{
echo_client_main_t *ecm = &echo_client_main;
int my_thread_index = vlib_get_thread_index ();
- session_t *sp;
+ eclient_session_t *sp;
int i;
int delete_session;
u32 *connection_indices;
connections_this_batch =
ecm->connections_this_batch_by_thread[my_thread_index];
- if ((ecm->run_test == 0) ||
+ if ((ecm->run_test != ECHO_CLIENTS_RUNNING) ||
((vec_len (connection_indices) == 0)
&& vec_len (connections_this_batch) == 0))
return 0;
ASSERT (nconnections_this_batch > 0);
vec_validate (connections_this_batch, nconnections_this_batch - 1);
- clib_memcpy (connections_this_batch,
- connection_indices + vec_len (connection_indices)
- - nconnections_this_batch,
- nconnections_this_batch * sizeof (u32));
+ clib_memcpy_fast (connections_this_batch,
+ connection_indices + vec_len (connection_indices)
+ - nconnections_this_batch,
+ nconnections_this_batch * sizeof (u32));
_vec_len (connection_indices) -= nconnections_this_batch;
}
{
stream_session_t *s;
- __sync_fetch_and_add (&ecm->tx_total, sp->bytes_sent);
- __sync_fetch_and_add (&ecm->rx_total, sp->bytes_received);
+ clib_atomic_fetch_add (&ecm->tx_total, sp->bytes_sent);
+ clib_atomic_fetch_add (&ecm->rx_total, sp->bytes_received);
s = session_get_from_handle_if_valid (sp->vpp_session_handle);
if (s)
vec_delete (connections_this_batch, 1, i);
i--;
- __sync_fetch_and_add (&ecm->ready_connections, -1);
+ clib_atomic_fetch_add (&ecm->ready_connections, -1);
}
else
{
stream_session_t * s, u8 is_fail)
{
echo_client_main_t *ecm = &echo_client_main;
- session_t *session;
+ eclient_session_t *session;
u32 session_index;
- u8 thread_index = vlib_get_thread_index ();
+ u8 thread_index;
+
+ if (PREDICT_FALSE (ecm->run_test != ECHO_CLIENTS_STARTING))
+ return -1;
if (is_fail)
{
clib_warning ("connection %d failed!", api_context);
+ ecm->run_test = ECHO_CLIENTS_EXITING;
signal_evt_to_cli (-1);
return 0;
}
- ASSERT (s->thread_index == thread_index);
+ thread_index = s->thread_index;
+ ASSERT (thread_index == vlib_get_thread_index ()
+ || session_transport_service_type (s) == TRANSPORT_SERVICE_CL);
if (!ecm->vpp_event_queue[thread_index])
ecm->vpp_event_queue[thread_index] =
pool_get (ecm->sessions, session);
clib_spinlock_unlock_if_init (&ecm->sessions_lock);
- memset (session, 0, sizeof (*session));
+ clib_memset (session, 0, sizeof (*session));
session_index = session - ecm->sessions;
session->bytes_to_send = ecm->bytes_to_send;
session->bytes_to_receive = ecm->no_return ? 0ULL : ecm->bytes_to_send;
{
transport_connection_t *tc;
tc = session_get_transport (s);
- clib_memcpy (&session->data.transport, tc,
- sizeof (session->data.transport));
+ clib_memcpy_fast (&session->data.transport, tc,
+ sizeof (session->data.transport));
session->data.is_dgram = 1;
}
vec_add1 (ecm->connection_index_by_thread[thread_index], session_index);
- __sync_fetch_and_add (&ecm->ready_connections, 1);
+ clib_atomic_fetch_add (&ecm->ready_connections, 1);
if (ecm->ready_connections == ecm->expected_connections)
{
- ecm->run_test = 1;
+ ecm->run_test = ECHO_CLIENTS_RUNNING;
/* Signal the CLI process that the action is starting... */
signal_evt_to_cli (1);
}
return;
}
+void
+echo_clients_session_disconnect (stream_session_t * s)
+{
+ echo_client_main_t *ecm = &echo_client_main;
+ vnet_disconnect_args_t _a, *a = &_a;
+ a->handle = session_handle (s);
+ a->app_index = ecm->app_index;
+ vnet_disconnect_session (a);
+}
+
static int
echo_clients_rx_callback (stream_session_t * s)
{
echo_client_main_t *ecm = &echo_client_main;
- session_t *sp;
+ eclient_session_t *sp;
+
+ if (PREDICT_FALSE (ecm->run_test != ECHO_CLIENTS_RUNNING))
+ {
+ echo_clients_session_disconnect (s);
+ return -1;
+ }
sp = pool_elt_at_index (ecm->sessions,
s->server_rx_fifo->client_session_index);
if (svm_fifo_max_dequeue (s->server_rx_fifo))
{
- session_fifo_event_t evt;
- svm_queue_t *q;
if (svm_fifo_set_event (s->server_rx_fifo))
- {
- evt.fifo = s->server_rx_fifo;
- evt.event_type = FIFO_EVENT_BUILTIN_RX;
- q = session_manager_get_vpp_event_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");
- }
+ session_send_io_evt_to_thread (s->server_rx_fifo,
+ FIFO_EVENT_BUILTIN_RX);
}
return 0;
}
u64 options[16];
clib_error_t *error = 0;
- memset (a, 0, sizeof (*a));
- memset (options, 0, sizeof (options));
+ clib_memset (a, 0, sizeof (*a));
+ clib_memset (options, 0, sizeof (options));
a->api_client_index = ecm->my_client_index;
a->session_cb_vft = &echo_clients;
clib_error_t *error = 0;
int i;
- memset (a, 0, sizeof (*a));
+ clib_memset (a, 0, sizeof (*a));
for (i = 0; i < n_clients; i++)
{
a->uri = (char *) ecm->connect_uri;
ecm->test_failed = 0;
ecm->vlib_main = vm;
ecm->tls_engine = TLS_ENGINE_OPENSSL;
+ ecm->no_copy = 0;
+ ecm->run_test = ECHO_CLIENTS_STARTING;
if (thread_main->n_vlib_mains > 1)
clib_spinlock_init (&ecm->sessions_lock);
VLIB_NODE_STATE_POLLING);
if (preallocate_sessions)
- {
- session_t *sp __attribute__ ((unused));
- for (i = 0; i < n_clients; i++)
- pool_get (ecm->sessions, sp);
- for (i = 0; i < n_clients; i++)
- pool_put_index (ecm->sessions, i);
- }
+ pool_init_fixed (ecm->sessions, 1.1 * n_clients);
/* Fire off connect requests */
time_before_connects = vlib_time_now (vm);
if ((error = echo_clients_connect (vm, n_clients)))
- return error;
+ goto cleanup;
/* Park until the sessions come up, or ten seconds elapse... */
vlib_process_wait_for_event_or_clock (vm, syn_timeout);
error = clib_error_return (0, "failed: test bytes");
cleanup:
- ecm->run_test = 0;
+ ecm->run_test = ECHO_CLIENTS_EXITING;
+ vlib_process_wait_for_event_or_clock (vm, 10e-3);
for (i = 0; i < vec_len (ecm->connection_index_by_thread); i++)
{
vec_reset_length (ecm->connection_index_by_thread[i]);