25 #include <vpp/app/version.h> 41 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) 46 #define TCP_BUILTIN_CLIENT_DBG (0) 54 session_fifo_event_t evt;
55 static int serial_number = 0;
61 bytes_this_chunk =
vec_len (test_data) - test_buf_offset;
67 test_data + test_buf_offset);
81 .format =
"tx-enq: xfer %d bytes, sent %u remain %u",
82 .format_args =
"i4i4i4",
101 evt.event_id = serial_number++;
137 .format =
"rx-deq: %d bytes",
146 ed->data[0] = n_read;
152 for (i = 0; i < n_read; i++)
156 clib_warning (
"read %d error at byte %lld, 0x%x not 0x%x",
177 u32 *connection_indices;
179 u32 delta, prev_bytes_received_this_session;
186 for (i = 0; i <
vec_len (connection_indices); i++)
213 memset (dmp, 0,
sizeof (*dmp));
214 dmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION);
246 .name =
"builtin-tcp-client",
248 .state = VLIB_NODE_STATE_DISABLED,
271 uword *event_data = 0, event_type;
281 memset (mp, 0,
sizeof (*mp));
282 mp->_vl_msg_id = VL_API_MEMCLNT_CREATE;
285 strncpy ((
char *) mp->
name,
"tcp_clients_tester", sizeof (mp->
name) - 1);
308 #define foreach_tclient_static_api_msg \ 309 _(MEMCLNT_CREATE_REPLY, memclnt_create_reply) \ 317 #define _(N,n) do { \ 318 c->id = VL_API_##N; \ 320 c->handler = vl_api_##n##_t_handler; \ 321 c->cleanup = vl_noop_handler; \ 322 c->endian = vl_api_##n##_t_endian; \ 323 c->print = vl_api_##n##_t_print; \ 324 c->size = sizeof(vl_api_##n##_t); \ 327 c->message_bounce = 0; \ 328 vl_msg_api_config(c);} while (0); 389 memset (session, 0,
sizeof (*session));
390 session_index = session - tm->
sessions;
468 u8 segment_name[128];
469 u32 segment_name_length, prealloc_fifos;
472 segment_name_length =
ARRAY_LEN (segment_name);
474 memset (a, 0,
sizeof (*a));
475 memset (options, 0,
sizeof (options));
478 a->segment_name = segment_name;
479 a->segment_name_length = segment_name_length;
492 a->options = options;
531 for (i = 0; i < n_clients; i++)
533 memset (a, 0,
sizeof (*a));
535 a->uri = (
char *) uri;
553 uword *event_data = 0, event_type;
554 u8 *default_connect_uri = (
u8 *)
"tcp://6.0.1.1/1234", *uri;
555 u64 tmp, total_bytes;
556 f64 cli_timeout = 20.0, delta;
569 if (
unformat (input,
"nclients %d", &n_clients))
571 else if (
unformat (input,
"mbytes %lld", &tmp))
573 else if (
unformat (input,
"gbytes %lld", &tmp))
579 else if (
unformat (input,
"cli-timeout %f", &cli_timeout))
581 else if (
unformat (input,
"no-return"))
604 uri = default_connect_uri;
608 #if TCP_BUILTIN_CLIENT_PTHREAD 626 VLIB_NODE_STATE_POLLING);
676 transfer_type = tm->
no_return ?
"half-duplex" :
"full-duplex";
678 "%lld bytes (%lld mbytes, %lld gbytes) in %.2f seconds",
679 total_bytes, total_bytes / (1ULL << 20),
680 total_bytes / (1ULL << 30), delta);
682 ((
f64) total_bytes) / (delta), transfer_type);
684 (((
f64) total_bytes * 8.0) / delta / 1e9),
701 .path =
"test tcp clients",
702 .short_help =
"test tcp clients [nclients %d]" 703 "[iterations %d] [bytes %d] [uri tcp://6.0.1.1/1234]",
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
void test_bytes(builtin_server_main_t *bsm, int actual_transfer)
void * vl_msg_api_alloc_as_if_client(int nbytes)
unix_shared_memory_queue_t * vl_input_queue
vpe input queue
static session_cb_vft_t builtin_clients
#define hash_set(h, key, value)
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
unix_shared_memory_queue_t * vpp_event_queue
$$$ single thread
static f64 vlib_time_now(vlib_main_t *vm)
uword * session_index_by_vpp_handles
Hash table for disconnecting.
u32 cli_node_index
cli process node index
static int create_api_loopback(tclient_main_t *tm)
u32 my_client_index
loopback API client handle
static void vl_api_memclnt_create_reply_t_handler(vl_api_memclnt_create_reply_t *mp)
#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)
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).
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
struct _stream_session_t stream_session_t
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...
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.
#define clib_error_return(e, args...)
struct vl_shmem_hdr_ * shmem_hdr
volatile u32 ready_connections
static uword pointer_to_uword(const void *p)
vlib_node_registration_t builtin_client_node
(constructor) VLIB_REGISTER_NODE (builtin_client_node)
static clib_error_t * tclient_api_hookup(vlib_main_t *vm)
u8 prealloc_fifos
Request fifo preallocation.
struct _vnet_app_attach_args_t vnet_app_attach_args_t
vl_shmem_hdr_t * shmem_hdr
u8 * rx_buf
intermediate rx buffer
int unix_shared_memory_queue_add(unix_shared_memory_queue_t *q, u8 *elem, int nowait)
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)
vlib_main_t vlib_global_main
int start_tx_pthread(tclient_main_t *tm)
Start a transmit thread.
unix_shared_memory_queue_t * our_event_queue
Our event queue.
void vl_msg_api_free(void *)
static void cleanup(void)
u32 node_index
Node index.
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
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)
#define vec_free(V)
Free vector's memory (no header).
tclient_main_t tclient_main
#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)
volatile int run_test
Signal start of test.
#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,...)
int vnet_application_attach(vnet_app_attach_args_t *a)
Attaches application.
#define hash_create(elts, value_bytes)
#define vec_delete(V, N, M)
Delete N elements starting at element M.
#define TCP_BUILTIN_CLIENT_DBG
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
static vlib_main_t * vlib_get_main(void)
static int builtin_server_rx_callback(stream_session_t *s)
static u64 stream_session_handle(stream_session_t *s)
bidirectional disconnect API
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 max_bytes)
void vl_api_memclnt_create_t_handler(vl_api_memclnt_create_t *mp)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static uword builtin_client_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
vlib_main_t ** vlib_mains
static int attach_builtin_test_clients_app(void)
#define foreach_tclient_static_api_msg
void clients_connect(vlib_main_t *vm, u8 *uri, u32 n_clients)
#define VLIB_REGISTER_NODE(x,...)
static vlib_thread_main_t * vlib_get_thread_main()
int vnet_connect_uri(vnet_connect_args_t *a)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
int svm_fifo_dequeue_nowait(svm_fifo_t *f, u32 max_bytes, u8 *copy_here)
session_t * sessions
Sessions pool.
svm_fifo_t * server_rx_fifo
u8 * connect_test_data
Pre-computed test data.
static uword pool_elts(void *v)
Number of active elements in a pool.