35 u32 tries = 0, max_tries;
41 if (tries++ == max_tries)
59 evt->event_type = evt_type;
63 evt->rpc_args.fp =
data;
64 evt->rpc_args.arg = args;
69 evt->session_index = *(
u32 *) data;
89 f->master_thread_index, evt_type);
123 void (*fnp) (
void *) = fp;
133 session_event_t *evt;
242 u32 to_drop = n_bytes_to_drop;
244 while (to_drop && (next->
flags & VLIB_BUFFER_NEXT_PRESENT))
278 if (is_in_order && offset)
306 return (rv > 0) ? (written + rv) : written;
331 while ((chain_bi = (chain_b->
flags & VLIB_BUFFER_NEXT_PRESENT)
357 u8 queue_event,
u8 is_in_order)
360 int enqueued = 0, rv, in_order_off;
412 int enqueued = 0, rv, in_order_off;
471 for (i = 0; i < f->n_subscribers; i++)
568 for (i = 0; i <
vec_len (indices); i++)
600 u32 opaque = 0, new_ti, new_si;
623 opaque = tc->s_index;
655 typedef struct _session_switch_pool_args
659 u32 new_thread_index;
660 u32 new_session_index;
669 s =
session_get (args->session_index, args->thread_index);
670 s->
tx_fifo->master_session_index = args->new_session_index;
671 s->
tx_fifo->master_thread_index = args->new_thread_index;
705 rpc_args->session_index = tc->s_index;
706 rpc_args->thread_index = old_thread_index;
712 *new_session = new_s;
907 SESSION_DBG (
"Transport failed to open connection.");
908 return VNET_API_ERROR_SESSION_CONNECT;
942 SESSION_DBG (
"Transport failed to open connection.");
943 return VNET_API_ERROR_SESSION_CONNECT;
955 handle = (((
u64) app_wrk_index) << 32) | (
u64) tc->c_index;
961 tc->s_index = opaque;
971 sep->app_wrk_index = app_wrk_index;
972 sep->opaque = opaque;
1020 u32 tc_index, s_index;
1028 if (tc_index == (
u32) ~ 0)
1055 return VNET_API_ERROR_ADDRESS_NOT_IN_USE;
1156 u32 evt_q_length = 2048, evt_size =
sizeof (session_event_t);
1159 uword eqs_size = 64 << 20;
1160 pid_t vpp_pid = getpid ();
1175 eqs->
name =
format (0,
"%s%c",
"evt-qs-segment", 0);
1194 {evt_q_length, evt_size, 0}
1196 {evt_q_length >> 1, 256, 0}
1243 session_tx_fifo_dequeue_and_snd
1260 u32 next_index = ~0;
1268 if (output_node != ~0)
1314 u32 num_threads, preallocated_sessions_per_worker;
1320 if (num_threads < 1)
1326 for (i = 0; i < num_threads; i++)
1341 if (num_threads > 1)
1346 vec_validate (smm->last_event_poll_by_thread, num_threads - 1);
1360 if (num_threads == 1)
1367 preallocated_sessions_per_worker =
1369 (
f64) (num_threads - 1));
1371 for (j = 1; j < num_threads; j++)
1374 preallocated_sessions_per_worker);
1394 u8 state = is_en ? VLIB_NODE_STATE_POLLING : VLIB_NODE_STATE_DISABLED;
1400 if (have_workers && ii == 0)
1451 #if (HIGH_SEGMENT_BASEVA > (4ULL << 30)) 1473 if (
unformat (input,
"event-queue-length %d", &nitems))
1478 clib_warning (
"event queue length %d too small, ignored", nitems);
1480 else if (
unformat (input,
"preallocated-sessions %d",
1483 else if (
unformat (input,
"v4-session-table-buckets %d",
1486 else if (
unformat (input,
"v4-halfopen-table-buckets %d",
1489 else if (
unformat (input,
"v6-session-table-buckets %d",
1492 else if (
unformat (input,
"v6-halfopen-table-buckets %d",
1495 else if (
unformat (input,
"v4-session-table-memory %U",
1498 if (tmp >= 0x100000000)
1503 else if (
unformat (input,
"v4-halfopen-table-memory %U",
1506 if (tmp >= 0x100000000)
1511 else if (
unformat (input,
"v6-session-table-memory %U",
1514 if (tmp >= 0x100000000)
1519 else if (
unformat (input,
"v6-halfopen-table-memory %U",
1522 if (tmp >= 0x100000000)
1527 else if (
unformat (input,
"local-endpoints-table-memory %U",
1530 if (tmp >= 0x100000000)
1535 else if (
unformat (input,
"local-endpoints-table-buckets %d",
1538 else if (
unformat (input,
"evt_qs_memfd_seg"))
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
#define session_endpoint_to_transport_cfg(_sep)
u32 preallocated_sessions
Preallocate session config parameter.
int app_worker_lock_and_send_event(app_worker_t *app, session_t *s, u8 evt_type)
Send event to application.
void transport_close(transport_proto_t tp, u32 conn_index, u8 thread_index)
static session_open_service_fn session_open_srv_fns[TRANSPORT_N_SERVICES]
u32 connection_index
Index of the transport connection associated to the session.
uword evt_qs_segment_size
void session_flush_frames_main_thread(vlib_main_t *vm)
int app_worker_init_accepted(session_t *s)
static u8 svm_msg_q_msg_is_invalid(svm_msg_q_msg_t *msg)
Check if message is invalid.
int session_lookup_del_connection(transport_connection_t *tc)
Delete transport connection from session table.
int app_worker_reset_notify(app_worker_t *app_wrk, session_t *s)
void * svm_msg_q_msg_data(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Get data for message in queue.
static u8 svm_msg_q_ring_is_full(svm_msg_q_t *mq, u32 ring_index)
int session_open(u32 app_wrk_index, session_endpoint_t *rmt, u32 opaque)
Ask transport to open connection to remote transport endpoint.
static void svm_pop_heap(void *oldheap)
session_type_t session_type
Type built from transport and network protocol types.
#define SESSION_Q_PROCESS_FLUSH_FRAMES
svm_msg_q_t * vpp_event_queue
vpp event message queue for worker
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
session_main_t session_main
int session_tx_fifo_peek_bytes(transport_connection_t *tc, u8 *buffer, u32 offset, u32 max_bytes)
u32 session_index
Index in thread pool where session was allocated.
int session_stop_listen(session_t *s)
Ask transport to stop listening on local transport endpoint.
transport_connection_t * listen_session_get_transport(session_t *s)
static svm_msg_q_t * session_main_get_vpp_event_queue(u32 thread_index)
u32 configured_v4_halfopen_table_buckets
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
void session_transport_delete_notify(transport_connection_t *tc)
Notification from transport that connection is being deleted.
transport_connection_t * session_get_transport(session_t *s)
static f64 vlib_time_now(vlib_main_t *vm)
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
session_worker_t * wrk
Worker contexts.
static session_t * session_get_if_valid(u64 si, u32 thread_index)
#define pool_get_aligned_will_expand(P, YESNO, A)
See if pool_get will expand the pool or not.
int session_enqueue_dgram_connection(session_t *s, session_dgram_hdr_t *hdr, vlib_buffer_t *b, u8 proto, u8 queue_event)
u16 current_length
Nbytes between current data and the end of this buffer.
static int session_enqueue_notify_inline(session_t *s)
Notify session peer that new data has been enqueued.
int session_main_flush_enqueue_events(u8 transport_proto, u32 thread_index)
Flushes queue of sessions that are to be notified of new data enqueued events.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static transport_proto_t session_get_transport_proto(session_t *s)
void session_send_rpc_evt_to_thread(u32 thread_index, void *fp, void *rpc_args)
void session_transport_reset_notify(transport_connection_t *tc)
Notify application that connection has been reset.
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
int session_open_vc(u32 app_wrk_index, session_endpoint_t *rmt, u32 opaque)
void svm_fifo_dequeue_drop_all(svm_fifo_t *f)
static u32 svm_fifo_max_enqueue(svm_fifo_t *f)
ssvm_shared_header_t * sh
u32 transport_start_listen(transport_proto_t tp, u32 session_index, transport_endpoint_t *tep)
static session_t * session_get(u32 si, u32 thread_index)
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
int session_enqueue_stream_connection(transport_connection_t *tc, vlib_buffer_t *b, u32 offset, u8 queue_event, u8 is_in_order)
u64 session_lookup_half_open_handle(transport_connection_t *tc)
static session_t * session_clone_safe(u32 session_index, u32 thread_index)
u32 local_endpoints_table_memory
Transport table (preallocation) size parameters.
void session_node_enable_disable(u8 is_en)
vlib_node_registration_t session_queue_node
(constructor) VLIB_REGISTER_NODE (session_queue_node)
vlib_main_t ** vlib_mains
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
app_worker_t * application_get_worker(application_t *app, u32 wrk_map_index)
session_fifo_rx_fn session_tx_fifo_peek_and_snd
session_t * sessions
Worker session pool.
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static session_fifo_rx_fn * session_tx_fns[TRANSPORT_TX_N_FNS]
static session_handle_t session_handle(session_t *s)
struct _svm_fifo svm_fifo_t
void session_transport_closing_notify(transport_connection_t *tc)
Notification from transport that connection is being closed.
int session_open_cl(u32 app_wrk_index, session_endpoint_t *rmt, u32 opaque)
static session_worker_t * session_main_get_worker(u32 thread_index)
void session_free_w_fifos(session_t *s)
#define session_endpoint_to_transport(_sep)
void app_namespaces_init(void)
static clib_error_t * session_config_fn(vlib_main_t *vm, unformat_input_t *input)
svm_msg_q_t * svm_msg_q_alloc(svm_msg_q_cfg_t *cfg)
Allocate message queue.
int session_send_ctrl_evt_to_thread(session_t *s, session_evt_type_t evt_type)
#define VLIB_INIT_FUNCTION(x)
static void * svm_push_data_heap(svm_region_t *rp)
void segment_manager_dealloc_fifos(svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
u32 * session_type_to_next
Per session type output nodes.
static int session_enqueue_chain_tail(session_t *s, vlib_buffer_t *b, u32 offset, u8 is_in_order)
Enqueue buffer chain tail.
static void * ssvm_push_heap(ssvm_shared_header_t *sh)
#define clib_error_return(e, args...)
svm_region_t * vlib_rp
Current binary api segment descriptor.
uword session_baseva
Session ssvm segment configs.
int svm_fifo_enqueue_nowait(svm_fifo_t *f, u32 max_bytes, const u8 *copy_from_here)
vhost_vring_state_t state
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
session_event_t * free_event_vector
Vector of partially read events.
int ssvm_master_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
static void ssvm_pop_heap(void *oldheap)
#define HALF_OPEN_LOOKUP_INVALID_VALUE
int session_lookup_del_half_open(transport_connection_t *tc)
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
static clib_error_t * session_manager_main_enable(vlib_main_t *vm)
struct _transport_proto_vft transport_proto_vft_t
int session_dequeue_notify(session_t *s)
struct _session_endpoint_cfg session_endpoint_cfg_t
u32 configured_v6_halfopen_table_memory
u32 configured_v6_session_table_buckets
static session_type_t session_type_from_proto_and_ip(transport_proto_t proto, u8 is_ip4)
static void clib_rwlock_init(clib_rwlock_t *p)
int svm_msg_q_alloc_consumer_eventfd(svm_msg_q_t *mq)
Allocate event fd for queue consumer.
transport_service_type_t transport_protocol_service_type(transport_proto_t tp)
uword session_va_space_size
void session_send_rpc_evt_to_thread_force(u32 thread_index, void *fp, void *rpc_args)
u32 configured_v4_session_table_buckets
Session table size parameters.
int app_worker_accept_notify(app_worker_t *app_wrk, session_t *s)
static void svm_fifo_clear_tx_ntf(svm_fifo_t *f)
session_event_t * pending_disconnects
Vector of postponed disconnects.
u32 configured_v6_halfopen_table_buckets
u32 configured_event_queue_length
vpp fifo event queue configured length
u8 is_enabled
Session manager is enabled.
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#define pool_put(P, E)
Free an object E in pool P.
enum transport_service_type_ transport_service_type_t
#define VLIB_CONFIG_FUNCTION(x, n,...)
int session_lookup_del_session(session_t *s)
u32 wrk_index
Worker index in global worker pool.
clib_error_t * session_manager_main_init(vlib_main_t *vm)
app_worker_t * app_worker_get_if_valid(u32 wrk_index)
session_fifo_rx_fn ** session_tx_fns
Per transport rx function that can either dequeue or peek.
u64 session_segment_handle(session_t *s)
#define foreach_vlib_main(body)
void transport_cleanup(transport_proto_t tp, u32 conn_index, u8 thread_index)
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
u32 transport_stop_listen(transport_proto_t tp, u32 conn_index)
struct _session_switch_pool_args session_switch_pool_args_t
API main structure, used by both vpp and binary API clients.
clib_rwlock_t peekers_rw_locks
Peekers rw lock.
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
#define SESSION_DBG(_fmt, _args...)
static void clib_rwlock_writer_unlock(clib_rwlock_t *p)
u32 n_rings
number of msg rings
#define SESSION_EVT_DBG(_evt, _args...)
void transport_init(void)
f64 dispatch_period
Our approximation of a "complete" dispatch loop period.
session_fifo_rx_fn session_tx_fifo_dequeue_and_snd
ssvm_private_t evt_qs_segment
Event queues memfd segment initialized only if so configured.
static_always_inline uword vlib_get_thread_index(void)
int transport_connect(transport_proto_t tp, transport_endpoint_cfg_t *tep)
static vlib_process_t * vlib_get_current_process(vlib_main_t *vm)
static void svm_msg_q_unlock(svm_msg_q_t *mq)
Unlock message queue.
static transport_connection_t * transport_get_connection(transport_proto_t tp, u32 conn_index, u8 thread_index)
static void vlib_process_signal_event_mt(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Signal event to process from any thread.
void session_free(session_t *s)
#define clib_warning(format, args...)
#define SESSION_INVALID_HANDLE
void transport_init_tx_pacers_period(void)
Initialize period for tx pacers.
static int session_send_evt_to_thread(void *data, void *args, u32 thread_index, session_evt_type_t evt_type)
int session_dgram_connect_notify(transport_connection_t *tc, u32 old_thread_index, session_t **new_session)
Move dgram session to the right thread.
struct _transport_connection transport_connection_t
#define HIGH_SEGMENT_BASEVA
int app_worker_init_connected(app_worker_t *app_wrk, session_t *s)
session_event_t * pending_event_vector
Vector of active event vectors.
int session_stream_accept(transport_connection_t *tc, u32 listener_index, u8 notify)
Accept a stream session.
void transport_enable_disable(vlib_main_t *vm, u8 is_en)
static u8 vlib_thread_is_main_w_barrier(void)
static int svm_msg_q_try_lock(svm_msg_q_t *mq)
Try locking message queue.
#define pool_init_fixed(pool, max_elts)
initialize a fixed-size, preallocated pool
application_t * application_get(u32 app_index)
static u64 segment_manager_make_segment_handle(u32 segment_manager_index, u32 segment_index)
#define SESSION_Q_PROCESS_STOP
int session_listen(session_t *ls, session_endpoint_cfg_t *sep)
Ask transport to listen on session endpoint.
void session_vpp_event_queues_allocate(session_main_t *smm)
Allocate event queues in the shared-memory segment.
static int session_notify_subscribers(u32 app_index, session_t *s, svm_fifo_t *f, session_evt_type_t evt_type)
void svm_msg_q_add_and_unlock(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Producer enqueue one message to queue with mutex held.
int session_main_flush_all_enqueue_events(u8 transport_proto)
void segment_manager_main_init(segment_manager_main_init_args_t *a)
static void clib_mem_free(void *p)
enum _transport_proto transport_proto_t
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
u32 configured_v4_halfopen_table_memory
static session_t * session_alloc_for_connection(transport_connection_t *tc)
int svm_fifo_enqueue_with_offset(svm_fifo_t *f, u32 offset, u32 required_bytes, u8 *copy_from_here)
u32 configured_v4_session_table_memory
int session_stream_accept_notify(transport_connection_t *tc)
static void * clib_mem_alloc(uword size)
svm_msg_q_ring_cfg_t * ring_cfgs
array of ring cfgs
static vlib_main_t * vlib_get_main(void)
u8 thread_index
Index of the thread that allocated the session.
session_t * session_alloc(u32 thread_index)
void session_transport_cleanup(session_t *s)
Cleanup transport and session state.
static void session_enqueue_discard_chain_bytes(vlib_main_t *vm, vlib_buffer_t *b, vlib_buffer_t **chain_b, u32 n_bytes_to_drop)
Discards bytes from buffer chain.
template key/value backing page structure
static void session_switch_pool(void *cb_args)
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 max_bytes)
static transport_connection_t * transport_get_half_open(transport_proto_t tp, u32 conn_index)
u32 local_endpoints_table_buckets
app_worker_t * app_worker_get(u32 wrk_index)
u32 q_nitems
msg queue size (not rings)
static void session_program_transport_close(session_t *s)
void session_lookup_init(void)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
session_fifo_rx_fn session_tx_fifo_dequeue_internal
u32 next_buffer
Next buffer for this linked-list of buffers.
volatile u8 session_state
State in session layer state machine.
int session_enqueue_notify(session_t *s)
void session_transport_closed_notify(transport_connection_t *tc)
Notification from transport that session can be closed.
u32 * session_to_enqueue[TRANSPORT_N_PROTO]
Per-proto vector of sessions to enqueue.
void session_close(session_t *s)
Initialize session closing procedure.
VLIB buffer representation.
ssvm_private_t * session_main_get_evt_q_segment(void)
int session_send_io_evt_to_thread_custom(void *data, u32 thread_index, session_evt_type_t evt_type)
f64 last_vlib_time
vlib_time_now last time around the track
u32 app_index
Index of owning app.
static u8 svm_fifo_n_subscribers(svm_fifo_t *f)
int session_lookup_add_connection(transport_connection_t *tc, u64 value)
Add transport connection to a session table.
u32 configured_v6_session_table_memory
int session_stream_connect_notify(transport_connection_t *tc, u8 is_fail)
static vlib_thread_main_t * vlib_get_thread_main()
vlib_node_registration_t session_queue_process_node
(constructor) VLIB_REGISTER_NODE (session_queue_process_node)
static u32 vlib_num_workers()
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
int(* session_open_service_fn)(u32, session_endpoint_t *, u32)
u32 app_wrk_index
Index of the app worker that owns the session.
session_event_t * postponed_event_vector
Vector of postponed events.
u32 session_tx_fifo_dequeue_drop(transport_connection_t *tc, u32 max_bytes)
static void session_delete(session_t *s)
Cleans up session and lookup table.
int() session_fifo_rx_fn(vlib_main_t *vm, vlib_node_runtime_t *node, session_worker_t *wrk, session_event_t *e, int *n_tx_pkts)
void session_transport_close(session_t *s)
Notify transport the session can be disconnected.
int app_worker_close_notify(app_worker_t *app_wrk, session_t *s)
struct _session_endpoint session_endpoint_t
int consumer_pid
pid of msg consumer
#define CLIB_CACHE_LINE_BYTES
static transport_connection_t * transport_get_listener(transport_proto_t tp, u32 conn_index)
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
int session_open_app(u32 app_wrk_index, session_endpoint_t *rmt, u32 opaque)
void vlib_start_process(vlib_main_t *vm, uword process_index)
int svm_fifo_peek(svm_fifo_t *f, u32 relative_offset, u32 max_bytes, u8 *copy_here)
void session_register_transport(transport_proto_t transport_proto, const transport_proto_vft_t *vft, u8 is_ip4, u32 output_node)
Initialize session layer for given transport proto and ip version.
int session_lookup_add_half_open(transport_connection_t *tc, u64 value)
u8 transport_protocol_is_cl(transport_proto_t tp)
int app_worker_connect_notify(app_worker_t *app_wrk, session_t *s, u32 opaque)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
svm_msg_q_msg_t svm_msg_q_alloc_msg_w_ring(svm_msg_q_t *mq, u32 ring_index)
Allocate message buffer on ring.
static session_t * listen_session_get(u32 ls_index)
u32 listener_index
Parent listener session index if the result of an accept.