24 #include <vpp/app/version.h> 28 #define TCP_BUILTIN_CLIENT_DBG (0) 54 session_fifo_event_t evt;
61 bytes_this_chunk =
vec_len (test_data) - test_buf_offset;
68 test_data + test_buf_offset);
82 .format =
"tx-enq: xfer %d bytes, sent %u remain %u",
83 .format_args =
"i4i4i4",
125 tm->
rx_buf[my_thread_index]);
140 .format =
"rx-deq: %d bytes",
149 ed->data[0] = n_read;
154 for (i = 0; i < n_read; i++)
156 if (tm->
rx_buf[my_thread_index][i]
159 clib_warning (
"read %d error at byte %lld, 0x%x not 0x%x",
161 tm->
rx_buf[my_thread_index][i],
181 u32 *connection_indices;
182 u32 *connections_this_batch;
183 u32 nconnections_this_batch;
186 connections_this_batch =
190 ((
vec_len (connection_indices) == 0)
191 &&
vec_len (connections_this_batch) == 0))
197 nconnections_this_batch =
200 ASSERT (nconnections_this_batch > 0);
201 vec_validate (connections_this_batch, nconnections_this_batch - 1);
203 connection_indices +
vec_len (connection_indices)
204 - nconnections_this_batch,
205 nconnections_this_batch *
sizeof (
u32));
206 _vec_len (connection_indices) -= nconnections_this_batch;
225 for (i = 0; i <
vec_len (connections_this_batch); i++)
243 u32 index, thread_index;
250 &index, &thread_index);
277 connections_this_batch;
285 .name =
"builtin-tcp-client",
287 .state = VLIB_NODE_STATE_DISABLED,
323 for (i = 0; i < num_threads; i++)
351 ASSERT (s->thread_index == thread_index);
364 memset (session, 0,
sizeof (*session));
365 session_index = session - tm->
sessions;
432 u32 segment_name_length, prealloc_fifos, segment_size = 2 << 20;
435 u8 segment_name[128];
439 segment_name_length =
ARRAY_LEN (segment_name);
441 memset (a, 0,
sizeof (*a));
442 memset (options, 0,
sizeof (options));
445 a->segment_name = segment_name;
446 a->segment_name_length = segment_name_length;
467 a->options = options;
468 a->namespace_id = appns_id;
508 for (i = 0; i < n_clients; i++)
510 memset (a, 0,
sizeof (*a));
512 a->uri = (
char *) uri;
533 #define CLI_OUTPUT(_fmt, _args...) \ 534 if (!tm->no_output) \ 535 vlib_cli_output(vm, _fmt, ##_args) 544 uword *event_data = 0, event_type;
545 u8 *default_connect_uri = (
u8 *)
"tcp://6.0.1.1/1234", *uri, *appns_id = 0;
546 u64 tmp, total_bytes, appns_flags = 0, appns_secret = 0;
547 f64 test_timeout = 20.0, syn_timeout = 20.0, delta;
548 f64 time_before_connects;
550 int preallocate_sessions = 0;
571 if (
unformat (input,
"nclients %d", &n_clients))
573 else if (
unformat (input,
"mbytes %lld", &tmp))
575 else if (
unformat (input,
"gbytes %lld", &tmp))
581 else if (
unformat (input,
"test-timeout %f", &test_timeout))
583 else if (
unformat (input,
"syn-timeout %f", &syn_timeout))
585 else if (
unformat (input,
"no-return"))
589 else if (
unformat (input,
"private-segment-count %d",
592 else if (
unformat (input,
"private-segment-size %U",
595 if (tmp >= 0x100000000ULL)
597 (0,
"private segment size %lld (%llu) too large", tmp, tmp);
600 else if (
unformat (input,
"preallocate-fifos"))
602 else if (
unformat (input,
"preallocate-sessions"))
603 preallocate_sessions = 1;
607 else if (
unformat (input,
"appns %_%v%_", &appns_id))
609 else if (
unformat (input,
"all-scope"))
610 appns_flags |= (APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE
611 | APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE);
612 else if (
unformat (input,
"local-scope"))
613 appns_flags = APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
614 else if (
unformat (input,
"global-scope"))
615 appns_flags = APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
616 else if (
unformat (input,
"secret %lu", &appns_secret))
618 else if (
unformat (input,
"no-output"))
620 else if (
unformat (input,
"test-bytes"))
642 uri = default_connect_uri;
646 #if TCP_BUILTIN_CLIENT_PTHREAD 670 VLIB_NODE_STATE_POLLING);
672 if (preallocate_sessions)
675 for (i = 0; i < n_clients; i++)
677 for (i = 0; i < n_clients; i++)
692 CLI_OUTPUT (
"Timeout with only %d sessions active...",
701 CLI_OUTPUT (
"%d three-way handshakes in %.2f seconds %.2f/s",
702 n_clients, delta, ((
f64) n_clients) / delta);
709 CLI_OUTPUT (
"unexpected event(1): %d", event_type);
721 CLI_OUTPUT (
"Timeout with %d sessions still active...",
733 CLI_OUTPUT (
"unexpected event(2): %d", event_type);
744 transfer_type = tm->
no_return ?
"half-duplex" :
"full-duplex";
745 CLI_OUTPUT (
"%lld bytes (%lld mbytes, %lld gbytes) in %.2f seconds",
746 total_bytes, total_bytes / (1ULL << 20),
747 total_bytes / (1ULL << 30), delta);
748 CLI_OUTPUT (
"%.2f bytes/second %s", ((
f64) total_bytes) / (delta),
751 (((
f64) total_bytes * 8.0) / delta / 1e9), transfer_type);
797 .path =
"test tcp clients",
798 .short_help =
"test tcp clients [nclients %d] [[m|g]bytes <bytes>] " 799 "[test-timeout <time>][syn-timeout <time>][no-return][fifo-size <size>]" 800 "[private-segment-count <count>][private-segment-size <bytes>[m|g]]" 801 "[preallocate-fifos][preallocate-sessions][client-batch <batch-size>]" 802 "[uri <tcp://ip/port>][test-bytes][no-output]",
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
unix_shared_memory_queue_t * vl_input_queue
vpe input queue
vlib_main_t vlib_global_main
static session_cb_vft_t builtin_clients
u32 app_index
app index after attach
static int builtin_session_connected_callback(u32 app_index, u32 api_context, stream_session_t *s, u8 is_fail)
sll srl srl sll sra u16x4 i
static void builtin_session_disconnect_callback(stream_session_t *s)
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
vlib_node_runtime_t node_runtime
u64 bytes_to_send
Bytes to send.
static void send_test_chunk(tclient_main_t *tm, session_t *s)
struct _vnet_connect_args vnet_connect_args_t
static void builtin_session_reset_callback(stream_session_t *s)
u8 * connect_uri
URI for slave's connect.
unix_shared_memory_queue_t * vl_input_queue
static f64 vlib_time_now(vlib_main_t *vm)
u32 cli_node_index
cli process node index
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
static int create_api_loopback(tclient_main_t *tm)
u32 my_client_index
loopback API client handle
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
clib_error_t * tcp_test_clients_main_init(vlib_main_t *vm)
#define CLI_OUTPUT(_fmt, _args...)
u8 ** rx_buf
intermediate rx buffers
u32 ** connections_this_batch_by_thread
active connection batch
unix_shared_memory_queue_t ** vpp_event_queue
static clib_error_t * test_tcp_clients_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
vlib_main_t ** vlib_mains
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define vlib_worker_thread_barrier_sync(X)
struct _svm_fifo svm_fifo_t
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
static void * tclient_thread_fn(void *arg)
#define VLIB_INIT_FUNCTION(x)
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
struct _vnet_disconnect_args_t vnet_disconnect_args_t
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
struct _stream_session_cb_vft session_cb_vft_t
svm_fifo_t * server_tx_fifo
u32 expected_connections
Number of clients/connections.
static void signal_evt_to_cli(int code)
#define clib_error_return(e, args...)
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
void stream_session_cleanup(stream_session_t *s)
Cleanup transport and session state.
struct _stream_session_t stream_session_t
volatile u32 ready_connections
vlib_node_registration_t builtin_client_node
(constructor) VLIB_REGISTER_NODE (builtin_client_node)
u8 prealloc_fifos
Request fifo preallocation.
struct _vnet_app_attach_args_t vnet_app_attach_args_t
static void clib_spinlock_init(clib_spinlock_t *p)
vl_shmem_hdr_t * shmem_hdr
int unix_shared_memory_queue_add(unix_shared_memory_queue_t *q, u8 *elem, int nowait)
static void session_parse_handle(u64 handle, u32 *index, u32 *thread_index)
u32 ** connection_index_by_thread
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
int start_tx_pthread(tclient_main_t *tm)
Start a transmit thread.
static void cleanup(void)
static stream_session_t * session_get_if_valid(u64 si, u32 thread_index)
u32 node_index
Node index.
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
API main structure, used by both vpp and binary API clients.
static int tcp_test_clients_init(vlib_main_t *vm)
#define pool_free(p)
Free a pool.
static u8 svm_fifo_set_event(svm_fifo_t *f)
Sets fifo event flag.
static unix_shared_memory_queue_t * session_manager_get_vpp_event_queue(u32 thread_index)
pthread_t client_thread_handle
static_always_inline uword vlib_get_thread_index(void)
static vlib_process_t * vlib_get_current_process(vlib_main_t *vm)
u8 * format_stream_session(u8 *s, va_list *args)
Format stream session as per the following format.
#define vec_free(V)
Free vector's memory (no header).
static void signal_evt_to_cli_i(int *code)
#define clib_warning(format, args...)
static int builtin_session_create_callback(stream_session_t *s)
static void receive_test_chunk(tclient_main_t *tm, session_t *s)
#define clib_memcpy(a, b, c)
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
u32 vl_api_memclnt_create_internal(char *, unix_shared_memory_queue_t *)
clib_spinlock_t sessions_lock
volatile int run_test
Signal start of test.
int vnet_disconnect_session(vnet_disconnect_args_t *a)
#define ELOG_TYPE_DECLARE(f)
int svm_fifo_enqueue_nowait(svm_fifo_t *f, u32 max_bytes, u8 *copy_from_here)
#define VLIB_CLI_COMMAND(x,...)
#define pool_put_index(p, i)
Free pool element with given index.
static clib_error_t * attach_builtin_test_clients_app(u8 *appns_id, u64 appns_flags, u64 appns_secret)
#define vec_delete(V, N, M)
Delete N elements starting at element M.
#define TCP_BUILTIN_CLIENT_DBG
#define clib_error_report(e)
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
tclient_main_t tclient_main
struct _vnet_app_detach_args_t vnet_app_detach_args_t
u32 connections_per_batch
Connections to rx/tx at once.
static int builtin_server_rx_callback(stream_session_t *s)
static u64 session_handle(stream_session_t *s)
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 max_bytes)
clib_error_t * vnet_connect_uri(vnet_connect_args_t *a)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
clib_error_t * vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
static uword builtin_client_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
clib_error_t * clients_connect(vlib_main_t *vm, u8 *uri, u32 n_clients)
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
#define VLIB_REGISTER_NODE(x,...)
static vlib_thread_main_t * vlib_get_thread_main()
u32 private_segment_size
size of private fifo segs
u32 private_segment_count
Number of private fifo segs.
int vnet_application_detach(vnet_app_detach_args_t *a)
Detach application from vpp.
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
int svm_fifo_dequeue_nowait(svm_fifo_t *f, u32 max_bytes, u8 *copy_here)
session_t * sessions
Session pool, shared.
svm_fifo_t * server_rx_fifo
u8 * connect_test_data
Pre-computed test data.