25 #define ECHO_CLIENT_DBG (0) 26 #define DBG(_fmt, _args...) \ 27 if (ECHO_CLIENT_DBG) \ 28 clib_warning (_fmt, ##_args) 52 int test_buf_len, test_buf_offset, rv;
55 test_buf_len =
vec_len (test_data);
57 test_buf_offset = s->
bytes_sent % test_buf_len;
58 bytes_this_chunk =
clib_min (test_buf_len - test_buf_offset,
91 rv =
clib_min (max_enqueue, bytes_this_chunk);
96 sizeof (ip46_address_t));
100 sizeof (ip46_address_t));
110 bytes_this_chunk =
clib_min (bytes_this_chunk, max_enqueue);
112 bytes_this_chunk, 0);
128 .format =
"tx-enq: xfer %d bytes, sent %u remain %u",
129 .format_args =
"i4i4i4",
173 .format =
"rx-deq: %d bytes",
182 ed->data[0] = n_read;
187 for (i = 0; i < n_read; i++)
189 if (ecm->
rx_buf[thread_index][i]
192 clib_warning (
"read %d error at byte %lld, 0x%x not 0x%x",
194 ecm->
rx_buf[thread_index][i],
200 ASSERT (n_read <= s->bytes_to_receive);
215 u32 *connection_indices;
216 u32 *connections_this_batch;
217 u32 nconnections_this_batch;
220 connections_this_batch =
224 ((
vec_len (connection_indices) == 0)
225 &&
vec_len (connections_this_batch) == 0))
231 nconnections_this_batch =
234 ASSERT (nconnections_this_batch > 0);
235 vec_validate (connections_this_batch, nconnections_this_batch - 1);
237 connection_indices +
vec_len (connection_indices)
238 - nconnections_this_batch,
239 nconnections_this_batch *
sizeof (
u32));
240 _vec_len (connection_indices) -= nconnections_this_batch;
259 for (i = 0; i <
vec_len (connections_this_batch); i++)
309 connections_this_batch;
317 .name =
"echo-clients",
319 .state = VLIB_NODE_STATE_DISABLED,
355 for (i = 0; i < num_threads; i++)
389 for (stream_n = 0; stream_n < ecm->
quic_streams; stream_n++)
393 a->api_context = -1 - api_context;
396 DBG (
"QUIC opening stream %d", stream_n);
399 clib_error (
"Stream session %d opening failed: %d", stream_n, rv);
402 DBG (
"QUIC stream %d connected", stream_n);
438 DBG (
"STREAM Connection callback %d", api_context);
456 session_index = session - ecm->
sessions;
460 session->
data.rx_fifo->client_session_index = session_index;
462 session->
data.tx_fifo->client_session_index = session_index;
471 sizeof (session->
data.transport));
472 session->
data.is_dgram = 1;
523 session_index = session - ecm->
sessions;
527 session->
data.rx_fifo->client_session_index = session_index;
529 session->
data.tx_fifo->client_session_index = session_index;
538 sizeof (session->
data.transport));
539 session->
data.is_dgram = 1;
642 u32 prealloc_fifos, segment_size = 256 << 20;
678 a->namespace_id = appns_id;
686 a_cert->app_index = a->app_index;
692 a_key->app_index = a->app_index;
707 da->api_client_index = ~0;
747 for (i = 0; i < n_clients; i++)
771 #define ec_cli_output(_fmt, _args...) \ 772 if (!ecm->no_output) \ 773 vlib_cli_output(vm, _fmt, ##_args) 781 u64 tmp, total_bytes, appns_flags = 0, appns_secret = 0;
782 f64 test_timeout = 20.0, syn_timeout = 20.0, delta;
783 char *default_uri =
"tcp://6.0.1.1/1234";
784 uword *event_data = 0, event_type;
785 f64 time_before_connects;
787 int preallocate_sessions = 0;
818 else if (
unformat (input,
"nclients %d", &n_clients))
822 else if (
unformat (input,
"mbytes %lld", &tmp))
824 else if (
unformat (input,
"gbytes %lld", &tmp))
828 else if (
unformat (input,
"test-timeout %f", &test_timeout))
830 else if (
unformat (input,
"syn-timeout %f", &syn_timeout))
832 else if (
unformat (input,
"no-return"))
836 else if (
unformat (input,
"private-segment-count %d",
839 else if (
unformat (input,
"private-segment-size %U",
842 if (tmp >= 0x100000000ULL)
844 (0,
"private segment size %lld (%llu) too large", tmp, tmp);
847 else if (
unformat (input,
"preallocate-fifos"))
849 else if (
unformat (input,
"preallocate-sessions"))
850 preallocate_sessions = 1;
854 else if (
unformat (input,
"appns %_%v%_", &appns_id))
856 else if (
unformat (input,
"all-scope"))
857 appns_flags |= (APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE
858 | APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE);
859 else if (
unformat (input,
"local-scope"))
860 appns_flags = APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
861 else if (
unformat (input,
"global-scope"))
862 appns_flags = APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
863 else if (
unformat (input,
"secret %lu", &appns_secret))
865 else if (
unformat (input,
"no-output"))
867 else if (
unformat (input,
"test-bytes"))
894 clib_warning (
"No uri provided. Using default: %s", default_uri);
901 ecm->
is_dgram = (sep.transport_proto == TRANSPORT_PROTO_UDP);
903 #if ECHO_CLIENT_PTHREAD 926 VLIB_NODE_STATE_POLLING);
928 if (preallocate_sessions)
953 ec_cli_output (
"%d three-way handshakes in %.2f seconds %.2f/s",
954 n_clients, delta, ((
f64) n_clients) / delta);
995 transfer_type = ecm->
no_return ?
"half-duplex" :
"full-duplex";
996 ec_cli_output (
"%lld bytes (%lld mbytes, %lld gbytes) in %.2f seconds",
997 total_bytes, total_bytes / (1ULL << 20),
998 total_bytes / (1ULL << 30), delta);
1002 (((
f64) total_bytes * 8.0) / delta / 1e9),
1045 .path =
"test echo clients",
1046 .short_help =
"test echo clients [nclients %d][[m|g]bytes <bytes>]" 1047 "[test-timeout <time>][syn-timeout <time>][no-return][fifo-size <size>]" 1048 "[private-segment-count <count>][private-segment-size <bytes>[m|g]]" 1049 "[preallocate-fifos][preallocate-sessions][client-batch <batch-size>]" 1050 "[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) ...
int echo_client_add_segment_callback(u32 client_index, u64 segment_handle)
vlib_main_t vlib_global_main
clib_error_t * echo_clients_connect(vlib_main_t *vm, u32 n_clients)
static int echo_clients_session_create_callback(session_t *s)
u32 vl_api_memclnt_create_internal(char *name, svm_queue_t *q)
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...
u8 is_ip4
set if uses ip4 networking
static u32 svm_fifo_max_enqueue_prod(svm_fifo_t *f)
Maximum number of bytes that can be enqueued into fifo.
vlib_node_runtime_t node_runtime
u8 * format_session(u8 *s, va_list *args)
Format stream session as per the following format.
struct _vnet_connect_args vnet_connect_args_t
static session_cb_vft_t echo_clients
#define clib_error(format, args...)
static svm_msg_q_t * session_main_get_vpp_event_queue(u32 thread_index)
u32 tls_engine
TLS engine mbedtls/openssl.
static int echo_clients_detach()
#define clib_memcpy_fast(a, b, c)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
transport_connection_t * session_get_transport(session_t *s)
static f64 vlib_time_now(vlib_main_t *vm)
static uword echo_client_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
u32 expected_connections
Number of clients/connections.
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
eclient_session_t * sessions
Session pool, shared.
static int app_send_stream(app_session_t *s, u8 *data, u32 len, u8 noblock)
u64 bytes_to_send
Bytes to send.
void svm_fifo_enqueue_nocopy(svm_fifo_t *f, u32 len)
Advance tail.
static void receive_data_chunk(echo_client_main_t *ecm, eclient_session_t *s)
volatile int run_test
Signal start of test.
u32 quic_streams
QUIC streams per connection.
void(* session_reset_callback)(session_t *s)
Notify app that session was reset.
struct _vnet_application_add_tls_cert_args_t vnet_app_add_tls_cert_args_t
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
vlib_main_t ** vlib_mains
void echo_clients_session_disconnect(session_t *s)
clib_error_t * vnet_app_add_tls_cert(vnet_app_add_tls_cert_args_t *a)
u8 * connect_test_data
Pre-computed test data.
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static int quic_echo_clients_session_connected_callback(u32 app_index, u32 api_context, session_t *s, session_error_t err)
#define vlib_worker_thread_barrier_sync(X)
static session_handle_t session_handle(session_t *s)
#define clib_memcpy(d, s, n)
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
clib_error_t * echo_clients_main_init(vlib_main_t *vm)
#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
int echo_clients_start_tx_pthread(echo_client_main_t *ecm)
Start a transmit thread.
static const u32 test_srv_key_rsa_len
static u32 svm_fifo_max_dequeue_cons(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for consumer.
#define DBG(_fmt, _args...)
#define clib_error_return(e, args...)
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
u32 app_index
app index after attach
svm_queue_t * vl_input_queue
vpe input queue
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
svm_msg_q_t ** vpp_event_queue
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
#define SESSION_INVALID_HANDLE
struct _vnet_app_attach_args_t vnet_app_attach_args_t
static void echo_clients_session_disconnect_callback(session_t *s)
static void clib_spinlock_init(clib_spinlock_t *p)
struct _session_endpoint_cfg session_endpoint_cfg_t
static int create_api_loopback(echo_client_main_t *ecm)
static void signal_evt_to_cli(int code)
clib_error_t * vnet_app_add_tls_key(vnet_app_add_tls_key_args_t *a)
static clib_error_t * echo_clients_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
volatile u32 ready_connections
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
static void cleanup(void)
int svm_fifo_enqueue(svm_fifo_t *f, u32 len, const u8 *src)
Enqueue data to fifo.
ip46_address_t rmt_ip
remote ip
u32 ** connection_index_by_thread
u32 private_segment_count
Number of private fifo segs.
u32 ** connections_this_batch_by_thread
active connection batch
u32 node_index
Node index.
static const char test_srv_crt_rsa[]
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.
int vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
static session_t * session_get_from_handle_if_valid(session_handle_t handle)
static void echo_clients_session_reset_callback(session_t *s)
#define pool_free(p)
Free a pool.
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
u32 no_copy
Don't memcpy data to tx fifo.
u32 connections_per_batch
Connections to rx/tx at once.
static int echo_clients_rx_callback(session_t *s)
int(* session_connected_callback)(u32 app_wrk_index, u32 opaque, session_t *s, session_error_t code)
Connection request callback.
#define VLIB_REGISTER_NODE(x,...)
session_handle_t listener_handle
Parent listener session index if the result of an accept.
static_always_inline uword vlib_get_thread_index(void)
static clib_error_t * echo_clients_attach(u8 *appns_id, u64 appns_flags, u64 appns_secret)
static vlib_process_t * vlib_get_current_process(vlib_main_t *vm)
vlib_node_registration_t echo_clients_node
(constructor) VLIB_REGISTER_NODE (echo_clients_node)
sll srl srl sll sra u16x4 i
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
echo_client_main_t echo_client_main
struct _transport_connection transport_connection_t
#define ELOG_TYPE_DECLARE(f)
u32 private_segment_size
size of private fifo segs
static int app_recv_stream(app_session_t *s, u8 *buf, u32 len)
svm_queue_t * vl_input_queue
static void send_data_chunk(echo_client_main_t *ecm, eclient_session_t *s)
#define pool_init_fixed(pool, max_elts)
initialize a fixed-size, preallocated pool
vlib_main_t vlib_node_runtime_t * node
static const char test_srv_key_rsa[]
#define VLIB_CLI_COMMAND(x,...)
u32 cli_node_index
cli process node index
#define vec_delete(V, N, M)
Delete N elements starting at element M.
u32 my_client_index
loopback API client handle
int vnet_application_detach(vnet_app_detach_args_t *a)
Detach application from vpp.
static int app_send_dgram(app_session_t *s, u8 *data, u32 len, u8 noblock)
struct _vnet_application_add_tls_key_args_t vnet_app_add_tls_key_args_t
#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.
u16 lcl_port
local port (network order)
struct _vnet_app_detach_args_t vnet_app_detach_args_t
u8 ** rx_buf
intermediate rx buffers
int vnet_connect(vnet_connect_args_t *a)
u8 thread_index
Index of the thread that allocated the session.
#define clib_atomic_fetch_add(a, b)
ip46_address_t lcl_ip
local ip
u8 prealloc_fifos
Request fifo preallocation.
u32 ** quic_session_index_by_thread
int parse_uri(char *uri, session_endpoint_cfg_t *sep)
static int echo_clients_session_connected_callback(u32 app_index, u32 api_context, session_t *s, session_error_t err)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
volatile u8 session_state
State in session layer state machine.
u8 * connect_uri
URI for slave's connect.
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
#define ec_cli_output(_fmt, _args...)
clib_spinlock_t sessions_lock
static void * echo_client_thread_fn(void *arg)
int vnet_disconnect_session(vnet_disconnect_args_t *a)
#define SESSION_ENDPOINT_CFG_NULL
int session_send_io_evt_to_thread_custom(void *data, u32 thread_index, session_evt_type_t evt_type)
static void signal_evt_to_cli_i(int *code)
static api_main_t * vlibapi_get_main(void)
static struct option options[]
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
static vlib_thread_main_t * vlib_get_thread_main()
enum session_error_ session_error_t
int vnet_connect_uri(vnet_connect_args_t *a)
pthread_t client_thread_handle
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 len)
Dequeue and drop bytes from fifo.
static transport_service_type_t session_transport_service_type(session_t *s)
struct _svm_fifo svm_fifo_t
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
struct session_dgram_header_ session_dgram_hdr_t
static int echo_clients_init(vlib_main_t *vm)
static const u32 test_srv_crt_rsa_len
static int app_recv_dgram(app_session_t *s, u8 *buf, u32 len)
u16 rmt_port
remote port (network order)
static int quic_echo_clients_qsession_connected_callback(u32 app_index, u32 api_context, session_t *s, session_error_t err)