2 * echo_client.c - vpp built-in echo client code
4 * Copyright (c) 2017 by Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vnet/vnet.h>
19 #include <vlibapi/api.h>
20 #include <vlibmemory/api.h>
21 #include <vnet/session-apps/echo_client.h>
23 echo_client_main_t echo_client_main;
25 #define ECHO_CLIENT_DBG (0)
28 signal_evt_to_cli_i (int *code)
30 echo_client_main_t *ecm = &echo_client_main;
31 ASSERT (vlib_get_thread_index () == 0);
32 vlib_process_signal_event (ecm->vlib_main, ecm->cli_node_index, *code, 0);
36 signal_evt_to_cli (int code)
38 if (vlib_get_thread_index () != 0)
39 vl_api_rpc_call_main_thread (signal_evt_to_cli_i, (u8 *) & code,
42 signal_evt_to_cli_i (&code);
46 send_data_chunk (echo_client_main_t * ecm, eclient_session_t * s)
48 u8 *test_data = ecm->connect_test_data;
49 int test_buf_len, test_buf_offset, rv;
52 test_buf_len = vec_len (test_data);
53 ASSERT (test_buf_len > 0);
54 test_buf_offset = s->bytes_sent % test_buf_len;
55 bytes_this_chunk = clib_min (test_buf_len - test_buf_offset,
62 svm_fifo_t *f = s->data.tx_fifo;
63 rv = clib_min (svm_fifo_max_enqueue (f), bytes_this_chunk);
64 svm_fifo_enqueue_nocopy (f, rv);
65 session_send_io_evt_to_thread_custom (f, s->thread_index,
69 rv = app_send_stream (&s->data, test_data + test_buf_offset,
76 session_dgram_hdr_t hdr;
77 svm_fifo_t *f = s->data.tx_fifo;
78 app_session_transport_t *at = &s->data.transport;
79 u32 max_enqueue = svm_fifo_max_enqueue (f);
81 if (max_enqueue <= sizeof (session_dgram_hdr_t))
84 max_enqueue -= sizeof (session_dgram_hdr_t);
85 rv = clib_min (max_enqueue, bytes_this_chunk);
89 clib_memcpy_fast (&hdr.rmt_ip, &at->rmt_ip,
90 sizeof (ip46_address_t));
91 hdr.is_ip4 = at->is_ip4;
92 hdr.rmt_port = at->rmt_port;
93 clib_memcpy_fast (&hdr.lcl_ip, &at->lcl_ip,
94 sizeof (ip46_address_t));
95 hdr.lcl_port = at->lcl_port;
96 svm_fifo_enqueue_nowait (f, sizeof (hdr), (u8 *) & hdr);
97 svm_fifo_enqueue_nocopy (f, rv);
98 session_send_io_evt_to_thread_custom (f, s->thread_index,
102 rv = app_send_dgram (&s->data, test_data + test_buf_offset,
103 bytes_this_chunk, 0);
106 /* If we managed to enqueue data... */
109 /* Account for it... */
110 s->bytes_to_send -= rv;
116 ELOG_TYPE_DECLARE (e) =
118 .format = "tx-enq: xfer %d bytes, sent %u remain %u",
119 .format_args = "i4i4i4",
126 ed = ELOG_DATA (&vlib_global_main.elog_main, e);
128 ed->data[1] = s->bytes_sent;
129 ed->data[2] = s->bytes_to_send;
135 receive_data_chunk (echo_client_main_t * ecm, eclient_session_t * s)
137 svm_fifo_t *rx_fifo = s->data.rx_fifo;
138 u32 thread_index = vlib_get_thread_index ();
144 n_read = app_recv_stream (&s->data, ecm->rx_buf[thread_index],
145 vec_len (ecm->rx_buf[thread_index]));
147 n_read = app_recv_dgram (&s->data, ecm->rx_buf[thread_index],
148 vec_len (ecm->rx_buf[thread_index]));
152 n_read = svm_fifo_max_dequeue (rx_fifo);
153 svm_fifo_dequeue_drop (rx_fifo, n_read);
161 ELOG_TYPE_DECLARE (e) =
163 .format = "rx-deq: %d bytes",
171 ed = ELOG_DATA (&vlib_global_main.elog_main, e);
172 ed->data[0] = n_read;
177 for (i = 0; i < n_read; i++)
179 if (ecm->rx_buf[thread_index][i]
180 != ((s->bytes_received + i) & 0xff))
182 clib_warning ("read %d error at byte %lld, 0x%x not 0x%x",
183 n_read, s->bytes_received + i,
184 ecm->rx_buf[thread_index][i],
185 ((s->bytes_received + i) & 0xff));
186 ecm->test_failed = 1;
190 ASSERT (n_read <= s->bytes_to_receive);
191 s->bytes_to_receive -= n_read;
192 s->bytes_received += n_read;
197 echo_client_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
198 vlib_frame_t * frame)
200 echo_client_main_t *ecm = &echo_client_main;
201 int my_thread_index = vlib_get_thread_index ();
202 eclient_session_t *sp;
205 u32 *connection_indices;
206 u32 *connections_this_batch;
207 u32 nconnections_this_batch;
209 connection_indices = ecm->connection_index_by_thread[my_thread_index];
210 connections_this_batch =
211 ecm->connections_this_batch_by_thread[my_thread_index];
213 if ((ecm->run_test != ECHO_CLIENTS_RUNNING) ||
214 ((vec_len (connection_indices) == 0)
215 && vec_len (connections_this_batch) == 0))
218 /* Grab another pile of connections */
219 if (PREDICT_FALSE (vec_len (connections_this_batch) == 0))
221 nconnections_this_batch =
222 clib_min (ecm->connections_per_batch, vec_len (connection_indices));
224 ASSERT (nconnections_this_batch > 0);
225 vec_validate (connections_this_batch, nconnections_this_batch - 1);
226 clib_memcpy_fast (connections_this_batch,
227 connection_indices + vec_len (connection_indices)
228 - nconnections_this_batch,
229 nconnections_this_batch * sizeof (u32));
230 _vec_len (connection_indices) -= nconnections_this_batch;
233 if (PREDICT_FALSE (ecm->prev_conns != ecm->connections_per_batch
234 && ecm->prev_conns == vec_len (connections_this_batch)))
237 ecm->prev_conns = vec_len (connections_this_batch);
238 if (ecm->repeats == 500000)
240 clib_warning ("stuck clients");
245 ecm->prev_conns = vec_len (connections_this_batch);
249 for (i = 0; i < vec_len (connections_this_batch); i++)
253 sp = pool_elt_at_index (ecm->sessions, connections_this_batch[i]);
255 if (sp->bytes_to_send > 0)
257 send_data_chunk (ecm, sp);
260 if (sp->bytes_to_receive > 0)
264 if (PREDICT_FALSE (delete_session == 1))
268 clib_atomic_fetch_add (&ecm->tx_total, sp->bytes_sent);
269 clib_atomic_fetch_add (&ecm->rx_total, sp->bytes_received);
270 s = session_get_from_handle_if_valid (sp->vpp_session_handle);
274 vnet_disconnect_args_t _a, *a = &_a;
275 a->handle = session_handle (s);
276 a->app_index = ecm->app_index;
277 vnet_disconnect_session (a);
279 vec_delete (connections_this_batch, 1, i);
281 clib_atomic_fetch_add (&ecm->ready_connections, -1);
285 clib_warning ("session AWOL?");
286 vec_delete (connections_this_batch, 1, i);
289 /* Kick the debug CLI process */
290 if (ecm->ready_connections == 0)
292 signal_evt_to_cli (2);
297 ecm->connection_index_by_thread[my_thread_index] = connection_indices;
298 ecm->connections_this_batch_by_thread[my_thread_index] =
299 connections_this_batch;
304 VLIB_REGISTER_NODE (echo_clients_node) =
306 .function = echo_client_node_fn,
307 .name = "echo-clients",
308 .type = VLIB_NODE_TYPE_INPUT,
309 .state = VLIB_NODE_STATE_DISABLED,
314 create_api_loopback (echo_client_main_t * ecm)
316 api_main_t *am = &api_main;
317 vl_shmem_hdr_t *shmem_hdr;
319 shmem_hdr = am->shmem_hdr;
320 ecm->vl_input_queue = shmem_hdr->vl_input_queue;
321 ecm->my_client_index = vl_api_memclnt_create_internal ("echo_client",
322 ecm->vl_input_queue);
327 echo_clients_init (vlib_main_t * vm)
329 echo_client_main_t *ecm = &echo_client_main;
330 vlib_thread_main_t *vtm = vlib_get_thread_main ();
334 if (create_api_loopback (ecm))
337 num_threads = 1 /* main thread */ + vtm->n_threads;
339 /* Init test data. Big buffer */
340 vec_validate (ecm->connect_test_data, 4 * 1024 * 1024 - 1);
341 for (i = 0; i < vec_len (ecm->connect_test_data); i++)
342 ecm->connect_test_data[i] = i & 0xff;
344 vec_validate (ecm->rx_buf, num_threads - 1);
345 for (i = 0; i < num_threads; i++)
346 vec_validate (ecm->rx_buf[i], vec_len (ecm->connect_test_data) - 1);
350 vec_validate (ecm->connection_index_by_thread, vtm->n_vlib_mains);
351 vec_validate (ecm->connections_this_batch_by_thread, vtm->n_vlib_mains);
352 vec_validate (ecm->vpp_event_queue, vtm->n_vlib_mains);
358 echo_clients_session_connected_callback (u32 app_index, u32 api_context,
359 stream_session_t * s, u8 is_fail)
361 echo_client_main_t *ecm = &echo_client_main;
362 eclient_session_t *session;
366 if (PREDICT_FALSE (ecm->run_test != ECHO_CLIENTS_STARTING))
371 clib_warning ("connection %d failed!", api_context);
372 ecm->run_test = ECHO_CLIENTS_EXITING;
373 signal_evt_to_cli (-1);
377 thread_index = s->thread_index;
378 ASSERT (thread_index == vlib_get_thread_index ()
379 || session_transport_service_type (s) == TRANSPORT_SERVICE_CL);
381 if (!ecm->vpp_event_queue[thread_index])
382 ecm->vpp_event_queue[thread_index] =
383 session_manager_get_vpp_event_queue (thread_index);
388 clib_spinlock_lock_if_init (&ecm->sessions_lock);
389 pool_get (ecm->sessions, session);
390 clib_spinlock_unlock_if_init (&ecm->sessions_lock);
392 clib_memset (session, 0, sizeof (*session));
393 session_index = session - ecm->sessions;
394 session->bytes_to_send = ecm->bytes_to_send;
395 session->bytes_to_receive = ecm->no_return ? 0ULL : ecm->bytes_to_send;
396 session->data.rx_fifo = s->server_rx_fifo;
397 session->data.rx_fifo->client_session_index = session_index;
398 session->data.tx_fifo = s->server_tx_fifo;
399 session->data.tx_fifo->client_session_index = session_index;
400 session->data.vpp_evt_q = ecm->vpp_event_queue[thread_index];
401 session->vpp_session_handle = session_handle (s);
405 transport_connection_t *tc;
406 tc = session_get_transport (s);
407 clib_memcpy_fast (&session->data.transport, tc,
408 sizeof (session->data.transport));
409 session->data.is_dgram = 1;
412 vec_add1 (ecm->connection_index_by_thread[thread_index], session_index);
413 clib_atomic_fetch_add (&ecm->ready_connections, 1);
414 if (ecm->ready_connections == ecm->expected_connections)
416 ecm->run_test = ECHO_CLIENTS_RUNNING;
417 /* Signal the CLI process that the action is starting... */
418 signal_evt_to_cli (1);
425 echo_clients_session_reset_callback (stream_session_t * s)
427 if (s->session_state == SESSION_STATE_READY)
428 clib_warning ("Reset active connection %U", format_stream_session, s, 2);
429 stream_session_cleanup (s);
434 echo_clients_session_create_callback (stream_session_t * s)
440 echo_clients_session_disconnect_callback (stream_session_t * s)
442 echo_client_main_t *ecm = &echo_client_main;
443 vnet_disconnect_args_t _a, *a = &_a;
444 a->handle = session_handle (s);
445 a->app_index = ecm->app_index;
446 vnet_disconnect_session (a);
451 echo_clients_session_disconnect (stream_session_t * s)
453 echo_client_main_t *ecm = &echo_client_main;
454 vnet_disconnect_args_t _a, *a = &_a;
455 a->handle = session_handle (s);
456 a->app_index = ecm->app_index;
457 vnet_disconnect_session (a);
461 echo_clients_rx_callback (stream_session_t * s)
463 echo_client_main_t *ecm = &echo_client_main;
464 eclient_session_t *sp;
466 if (PREDICT_FALSE (ecm->run_test != ECHO_CLIENTS_RUNNING))
468 echo_clients_session_disconnect (s);
472 sp = pool_elt_at_index (ecm->sessions,
473 s->server_rx_fifo->client_session_index);
474 receive_data_chunk (ecm, sp);
476 if (svm_fifo_max_dequeue (s->server_rx_fifo))
478 if (svm_fifo_set_event (s->server_rx_fifo))
479 session_send_io_evt_to_thread (s->server_rx_fifo,
480 FIFO_EVENT_BUILTIN_RX);
486 echo_client_add_segment_callback (u32 client_index, const ssvm_private_t * sp)
488 /* New heaps may be added */
493 static session_cb_vft_t echo_clients = {
494 .session_reset_callback = echo_clients_session_reset_callback,
495 .session_connected_callback = echo_clients_session_connected_callback,
496 .session_accept_callback = echo_clients_session_create_callback,
497 .session_disconnect_callback = echo_clients_session_disconnect_callback,
498 .builtin_app_rx_callback = echo_clients_rx_callback,
499 .add_segment_callback = echo_client_add_segment_callback
503 static clib_error_t *
504 echo_clients_attach (u8 * appns_id, u64 appns_flags, u64 appns_secret)
506 u32 prealloc_fifos, segment_size = 256 << 20;
507 echo_client_main_t *ecm = &echo_client_main;
508 vnet_app_attach_args_t _a, *a = &_a;
510 clib_error_t *error = 0;
512 clib_memset (a, 0, sizeof (*a));
513 clib_memset (options, 0, sizeof (options));
515 a->api_client_index = ecm->my_client_index;
516 a->session_cb_vft = &echo_clients;
518 prealloc_fifos = ecm->prealloc_fifos ? ecm->expected_connections : 1;
520 if (ecm->private_segment_size)
521 segment_size = ecm->private_segment_size;
523 options[APP_OPTIONS_ACCEPT_COOKIE] = 0x12345678;
524 options[APP_OPTIONS_SEGMENT_SIZE] = segment_size;
525 options[APP_OPTIONS_ADD_SEGMENT_SIZE] = segment_size;
526 options[APP_OPTIONS_RX_FIFO_SIZE] = ecm->fifo_size;
527 options[APP_OPTIONS_TX_FIFO_SIZE] = ecm->fifo_size;
528 options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = ecm->private_segment_count;
529 options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = prealloc_fifos;
530 options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
531 options[APP_OPTIONS_TLS_ENGINE] = ecm->tls_engine;
534 options[APP_OPTIONS_FLAGS] |= appns_flags;
535 options[APP_OPTIONS_NAMESPACE_SECRET] = appns_secret;
537 a->options = options;
538 a->namespace_id = appns_id;
540 if ((error = vnet_application_attach (a)))
543 ecm->app_index = a->app_index;
548 echo_clients_detach ()
550 echo_client_main_t *ecm = &echo_client_main;
551 vnet_app_detach_args_t _da, *da = &_da;
554 da->app_index = ecm->app_index;
555 rv = vnet_application_detach (da);
556 ecm->test_client_attached = 0;
562 echo_client_thread_fn (void *arg)
567 /** Start a transmit thread */
569 echo_clients_start_tx_pthread (echo_client_main_t * ecm)
571 if (ecm->client_thread_handle == 0)
573 int rv = pthread_create (&ecm->client_thread_handle,
575 echo_client_thread_fn, 0);
578 ecm->client_thread_handle = 0;
586 echo_clients_connect (vlib_main_t * vm, u32 n_clients)
588 echo_client_main_t *ecm = &echo_client_main;
589 vnet_connect_args_t _a, *a = &_a;
590 clib_error_t *error = 0;
593 clib_memset (a, 0, sizeof (*a));
594 for (i = 0; i < n_clients; i++)
596 a->uri = (char *) ecm->connect_uri;
598 a->app_index = ecm->app_index;
600 if ((error = vnet_connect_uri (a)))
603 /* Crude pacing for call setups */
605 vlib_process_suspend (vm, 10e-6);
606 ASSERT (i + 1 >= ecm->ready_connections);
607 while (i + 1 - ecm->ready_connections > 1000)
609 vlib_process_suspend (vm, 100e-6);
615 #define ec_cli_output(_fmt, _args...) \
616 if (!ecm->no_output) \
617 vlib_cli_output(vm, _fmt, ##_args)
619 static clib_error_t *
620 echo_clients_command_fn (vlib_main_t * vm,
621 unformat_input_t * input, vlib_cli_command_t * cmd)
623 echo_client_main_t *ecm = &echo_client_main;
624 vlib_thread_main_t *thread_main = vlib_get_thread_main ();
625 u64 tmp, total_bytes, appns_flags = 0, appns_secret = 0;
626 f64 test_timeout = 20.0, syn_timeout = 20.0, delta;
627 char *default_uri = "tcp://6.0.1.1/1234";
628 uword *event_data = 0, event_type;
629 f64 time_before_connects;
631 int preallocate_sessions = 0;
633 clib_error_t *error = 0;
637 ecm->bytes_to_send = 8192;
639 ecm->fifo_size = 64 << 10;
640 ecm->connections_per_batch = 1000;
641 ecm->private_segment_count = 0;
642 ecm->private_segment_size = 0;
645 ecm->test_failed = 0;
647 ecm->tls_engine = TLS_ENGINE_OPENSSL;
649 ecm->run_test = ECHO_CLIENTS_STARTING;
651 if (thread_main->n_vlib_mains > 1)
652 clib_spinlock_init (&ecm->sessions_lock);
653 vec_free (ecm->connect_uri);
655 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
657 if (unformat (input, "uri %s", &ecm->connect_uri))
659 else if (unformat (input, "nclients %d", &n_clients))
661 else if (unformat (input, "mbytes %lld", &tmp))
662 ecm->bytes_to_send = tmp << 20;
663 else if (unformat (input, "gbytes %lld", &tmp))
664 ecm->bytes_to_send = tmp << 30;
665 else if (unformat (input, "bytes %lld", &ecm->bytes_to_send))
667 else if (unformat (input, "test-timeout %f", &test_timeout))
669 else if (unformat (input, "syn-timeout %f", &syn_timeout))
671 else if (unformat (input, "no-return"))
673 else if (unformat (input, "fifo-size %d", &ecm->fifo_size))
674 ecm->fifo_size <<= 10;
675 else if (unformat (input, "private-segment-count %d",
676 &ecm->private_segment_count))
678 else if (unformat (input, "private-segment-size %U",
679 unformat_memory_size, &tmp))
681 if (tmp >= 0x100000000ULL)
682 return clib_error_return
683 (0, "private segment size %lld (%llu) too large", tmp, tmp);
684 ecm->private_segment_size = tmp;
686 else if (unformat (input, "preallocate-fifos"))
687 ecm->prealloc_fifos = 1;
688 else if (unformat (input, "preallocate-sessions"))
689 preallocate_sessions = 1;
691 if (unformat (input, "client-batch %d", &ecm->connections_per_batch))
693 else if (unformat (input, "appns %_%v%_", &appns_id))
695 else if (unformat (input, "all-scope"))
696 appns_flags |= (APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE
697 | APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE);
698 else if (unformat (input, "local-scope"))
699 appns_flags = APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
700 else if (unformat (input, "global-scope"))
701 appns_flags = APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
702 else if (unformat (input, "secret %lu", &appns_secret))
704 else if (unformat (input, "no-output"))
706 else if (unformat (input, "test-bytes"))
708 else if (unformat (input, "tls-engine %d", &ecm->tls_engine))
711 return clib_error_return (0, "failed: unknown input `%U'",
712 format_unformat_error, input);
715 /* Store cli process node index for signalling */
716 ecm->cli_node_index =
717 vlib_get_current_process (vm)->node_runtime.node_index;
719 if (ecm->is_init == 0)
721 if (echo_clients_init (vm))
722 return clib_error_return (0, "failed init");
726 ecm->ready_connections = 0;
727 ecm->expected_connections = n_clients;
731 if (!ecm->connect_uri)
733 clib_warning ("No uri provided. Using default: %s", default_uri);
734 ecm->connect_uri = format (0, "%s%c", default_uri, 0);
737 if (ecm->connect_uri[0] == 'u' && ecm->connect_uri[3] != 'c')
740 #if ECHO_CLIENT_PTHREAD
741 echo_clients_start_tx_pthread ();
744 vlib_worker_thread_barrier_sync (vm);
745 vnet_session_enable_disable (vm, 1 /* turn on session and transports */ );
746 vlib_worker_thread_barrier_release (vm);
748 if (ecm->test_client_attached == 0)
750 if ((error = echo_clients_attach (appns_id, appns_flags, appns_secret)))
753 clib_error_report (error);
758 ecm->test_client_attached = 1;
760 /* Turn on the builtin client input nodes */
761 for (i = 0; i < thread_main->n_vlib_mains; i++)
762 vlib_node_set_state (vlib_mains[i], echo_clients_node.index,
763 VLIB_NODE_STATE_POLLING);
765 if (preallocate_sessions)
766 pool_init_fixed (ecm->sessions, 1.1 * n_clients);
768 /* Fire off connect requests */
769 time_before_connects = vlib_time_now (vm);
770 if ((error = echo_clients_connect (vm, n_clients)))
773 /* Park until the sessions come up, or ten seconds elapse... */
774 vlib_process_wait_for_event_or_clock (vm, syn_timeout);
775 event_type = vlib_process_get_events (vm, &event_data);
779 ec_cli_output ("Timeout with only %d sessions active...",
780 ecm->ready_connections);
781 error = clib_error_return (0, "failed: syn timeout with %d sessions",
782 ecm->ready_connections);
786 delta = vlib_time_now (vm) - time_before_connects;
788 ec_cli_output ("%d three-way handshakes in %.2f seconds %.2f/s",
789 n_clients, delta, ((f64) n_clients) / delta);
791 ecm->test_start_time = vlib_time_now (ecm->vlib_main);
792 ec_cli_output ("Test started at %.6f", ecm->test_start_time);
796 ec_cli_output ("unexpected event(1): %d", event_type);
797 error = clib_error_return (0, "failed: unexpected event(1): %d",
802 /* Now wait for the sessions to finish... */
803 vlib_process_wait_for_event_or_clock (vm, test_timeout);
804 event_type = vlib_process_get_events (vm, &event_data);
808 ec_cli_output ("Timeout with %d sessions still active...",
809 ecm->ready_connections);
810 error = clib_error_return (0, "failed: timeout with %d sessions",
811 ecm->ready_connections);
815 ecm->test_end_time = vlib_time_now (vm);
816 ec_cli_output ("Test finished at %.6f", ecm->test_end_time);
820 ec_cli_output ("unexpected event(2): %d", event_type);
821 error = clib_error_return (0, "failed: unexpected event(2): %d",
826 delta = ecm->test_end_time - ecm->test_start_time;
829 total_bytes = (ecm->no_return ? ecm->tx_total : ecm->rx_total);
830 transfer_type = ecm->no_return ? "half-duplex" : "full-duplex";
831 ec_cli_output ("%lld bytes (%lld mbytes, %lld gbytes) in %.2f seconds",
832 total_bytes, total_bytes / (1ULL << 20),
833 total_bytes / (1ULL << 30), delta);
834 ec_cli_output ("%.2f bytes/second %s", ((f64) total_bytes) / (delta),
836 ec_cli_output ("%.4f gbit/second %s",
837 (((f64) total_bytes * 8.0) / delta / 1e9),
842 ec_cli_output ("zero delta-t?");
843 error = clib_error_return (0, "failed: zero delta-t");
847 if (ecm->test_bytes && ecm->test_failed)
848 error = clib_error_return (0, "failed: test bytes");
851 ecm->run_test = ECHO_CLIENTS_EXITING;
852 vlib_process_wait_for_event_or_clock (vm, 10e-3);
853 for (i = 0; i < vec_len (ecm->connection_index_by_thread); i++)
855 vec_reset_length (ecm->connection_index_by_thread[i]);
856 vec_reset_length (ecm->connections_this_batch_by_thread[i]);
859 pool_free (ecm->sessions);
861 /* Detach the application, so we can use different fifo sizes next time */
862 if (ecm->test_client_attached)
864 if (echo_clients_detach ())
866 error = clib_error_return (0, "failed: app detach");
867 ec_cli_output ("WARNING: app detach failed...");
871 ec_cli_output ("test failed");
872 vec_free (ecm->connect_uri);
877 VLIB_CLI_COMMAND (echo_clients_command, static) =
879 .path = "test echo clients",
880 .short_help = "test echo clients [nclients %d][[m|g]bytes <bytes>]"
881 "[test-timeout <time>][syn-timeout <time>][no-return][fifo-size <size>]"
882 "[private-segment-count <count>][private-segment-size <bytes>[m|g]]"
883 "[preallocate-fifos][preallocate-sessions][client-batch <batch-size>]"
884 "[uri <tcp://ip/port>][test-bytes][no-output]",
885 .function = echo_clients_command_fn,
891 echo_clients_main_init (vlib_main_t * vm)
893 echo_client_main_t *ecm = &echo_client_main;
898 VLIB_INIT_FUNCTION (echo_clients_main_init);
901 * fd.io coding-style-patch-verification: ON
904 * eval: (c-set-style "gnu")