22 #define ECHO_SERVER_DBG (0) 23 #define DBG(_fmt, _args...) \ 24 if (ECHO_SERVER_DBG) \ 25 clib_warning (_fmt, ##_args) 154 for (i = 0; i < actual_transfer; i++)
160 esm->
rx_buf[my_thread_id][i]);
180 u32 n_written, max_dequeue, max_enqueue, max_transfer;
192 ASSERT (rx_fifo->master_thread_index == thread_index);
193 ASSERT (tx_fifo->master_thread_index == thread_index);
204 max_dequeue = ph.data_length - ph.data_offset;
218 max_transfer =
clib_min (max_dequeue, max_enqueue);
249 esm->
rx_buf[thread_index],
257 esm->
rx_buf[thread_index],
262 ASSERT (actual_transfer == max_transfer);
273 esm->
rx_buf[thread_index],
281 esm->
rx_buf[thread_index],
286 if (n_written != max_transfer)
287 clib_warning (
"short trout! written %u read %u", n_written, max_transfer);
327 u32 segment_size = 512 << 20;
361 a->namespace_id = appns_id;
374 a_cert->app_index = a->app_index;
380 a_key->app_index = a->app_index;
440 for (i = 0; i < num_threads; i++)
463 u8 server_uri_set = 0, *appns_id = 0;
464 u64 tmp, appns_flags = 0, appns_secret = 0;
465 char *default_uri =
"tcp://0.0.0.0/1234";
482 else if (
unformat (input,
"no-echo"))
490 else if (
unformat (input,
"private-segment-count %d",
493 else if (
unformat (input,
"private-segment-size %U",
496 if (tmp >= 0x100000000ULL)
498 (0,
"private segment size %lld (%llu) too large", tmp, tmp);
501 else if (
unformat (input,
"appns %_%v%_", &appns_id))
503 else if (
unformat (input,
"all-scope"))
504 appns_flags |= (APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE
505 | APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE);
506 else if (
unformat (input,
"local-scope"))
507 appns_flags |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
508 else if (
unformat (input,
"global-scope"))
509 appns_flags |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
510 else if (
unformat (input,
"secret %lu", &appns_secret))
541 clib_warning (
"No uri provided! Using default: %s", default_uri);
548 esm->
is_dgram = (sep.transport_proto == TRANSPORT_PROTO_UDP);
564 .path =
"test echo server",
565 .short_help =
"test echo server proto <proto> [no echo][fifo-size <mbytes>]" 566 "[rcv-buf-size <bytes>][prealloc-fifos <count>]" 567 "[private-segment-count <count>][private-segment-size <bytes[m|g]>]" 568 "[uri <tcp://ip/port>]",
static int echo_server_listen()
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static int app_recv_stream_raw(svm_fifo_t *f, u8 *buf, u32 len, u8 clear_evt, u8 peek)
int echo_server_session_accept_callback(session_t *s)
u32 vl_api_memclnt_create_internal(char *name, svm_queue_t *q)
static u32 svm_fifo_max_enqueue_prod(svm_fifo_t *f)
Maximum number of bytes that can be enqueued into fifo.
u8 * format_session(u8 *s, va_list *args)
Format stream session as per the following format.
session_main_t session_main
u32 session_index
Index in thread pool where session was allocated.
u8 no_echo
Don't echo traffic.
static svm_msg_q_t * session_main_get_vpp_event_queue(u32 thread_index)
#define clib_memcpy_fast(a, b, c)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
void echo_server_session_disconnect_callback(session_t *s)
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
session_worker_t * wrk
Worker contexts.
u32 private_segment_size
Size of private segments.
static int echo_server_detach(void)
int svm_fifo_peek(svm_fifo_t *f, u32 offset, u32 len, u8 *dst)
Peek data from fifo.
int quic_echo_server_session_accept_callback(session_t *s)
struct _vnet_application_add_tls_cert_args_t vnet_app_add_tls_cert_args_t
u32 tls_engine
TLS engine: mbedtls/openssl.
clib_error_t * vnet_app_add_tls_cert(vnet_app_add_tls_cert_args_t *a)
struct _vnet_bind_args_t vnet_listen_args_t
session_t * sessions
Worker session pool.
static session_handle_t session_handle(session_t *s)
u32 my_client_index
API client handle.
int(* builtin_app_rx_callback)(session_t *session)
Direct RX callback for built-in application.
u32 prealloc_fifos
Preallocate fifos.
#define VLIB_INIT_FUNCTION(x)
struct _vnet_disconnect_args_t vnet_disconnect_args_t
svm_queue_t * vl_input_queue
Sever's event queue.
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 clib_error_return(e, args...)
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
static int echo_server_attach(u8 *appns_id, u64 appns_flags, u64 appns_secret)
echo_server_main_t echo_server_main
static int app_recv_dgram_raw(svm_fifo_t *f, u8 *buf, u32 len, app_session_transport_t *at, u8 clear_evt, u8 peek)
struct _vnet_app_attach_args_t vnet_app_attach_args_t
struct _session_endpoint_cfg session_endpoint_cfg_t
clib_error_t * vnet_app_add_tls_key(vnet_app_add_tls_key_args_t *a)
#define DBG(_fmt, _args...)
int echo_server_session_connected_callback(u32 app_index, u32 api_context, session_t *s, session_error_t err)
void echo_server_session_reset_callback(session_t *s)
static const char test_srv_crt_rsa[]
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
static int app_send_dgram_raw(svm_fifo_t *f, app_session_transport_t *at, svm_msg_q_t *vpp_evt_q, u8 *data, u32 len, u8 evt_type, u8 do_evt, u8 noblock)
static clib_error_t * echo_server_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u32 app_index
Server app index.
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.
void test_bytes(echo_server_main_t *esm, int actual_transfer)
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
session_handle_t listener_handle
Parent listener session index if the result of an accept.
static_always_inline uword vlib_get_thread_index(void)
clib_error_t * echo_server_main_init(vlib_main_t *vm)
sll srl srl sll sra u16x4 i
static int create_api_loopback(vlib_main_t *vm)
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
u32 node_index
process node index for event scheduling
svm_queue_t * vl_input_queue
static const char test_srv_key_rsa[]
#define VLIB_CLI_COMMAND(x,...)
int echo_server_builtin_server_rx_callback_no_echo(session_t *s)
int echo_server_redirect_connect_callback(u32 client_index, void *mp)
int vnet_application_detach(vnet_app_detach_args_t *a)
Detach application from vpp.
struct _vnet_application_add_tls_key_args_t vnet_app_add_tls_key_args_t
int echo_server_rx_callback(session_t *s)
struct _vnet_app_detach_args_t vnet_app_detach_args_t
int quic_echo_server_qsession_accept_callback(session_t *s)
u8 thread_index
Index of the thread that allocated the session.
int parse_uri(char *uri, session_endpoint_cfg_t *sep)
int echo_server_add_segment_callback(u32 client_index, u64 segment_handle)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
volatile u8 session_state
State in session layer state machine.
u8 ** rx_buf
Per-thread RX buffer.
u32 opaque
Opaque, for general use.
int vnet_bind_uri(vnet_listen_args_t *a)
static int app_send_stream_raw(svm_fifo_t *f, svm_msg_q_t *vpp_evt_q, u8 *data, u32 len, u8 evt_type, u8 do_evt, u8 noblock)
char * server_uri
Server URI.
int vnet_disconnect_session(vnet_disconnect_args_t *a)
u64 listener_handle
Session handle of the root listener.
#define SESSION_ENDPOINT_CFG_NULL
u32 private_segment_count
Number of private segments.
struct _svm_queue svm_queue_t
static api_main_t * vlibapi_get_main(void)
static struct option options[]
u8 is_dgram
set if transport is dgram
static vlib_thread_main_t * vlib_get_thread_main()
u32 rcv_buffer_size
Rcv buffer size.
enum session_error_ session_error_t
int(* session_accept_callback)(session_t *new_session)
Notify server of newly accepted session.
static int echo_server_create(vlib_main_t *vm, u8 *appns_id, u64 appns_flags, u64 appns_secret)
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 len)
Dequeue and drop bytes from fifo.
struct _svm_fifo svm_fifo_t
struct session_dgram_header_ session_dgram_hdr_t
static session_cb_vft_t echo_server_session_cb_vft
static const u32 test_srv_crt_rsa_len
static uword pool_elts(void *v)
Number of active elements in a pool.