36 svm_fifo_t *server_rx_fifo = 0, *server_tx_fifo = 0;
37 u32 fifo_segment_index;
41 u32 thread_index = tc->thread_index;
48 memset (s, 0,
sizeof (*s));
49 pool_index = s - smm->sessions[thread_index];
56 &fifo_segment_index)))
58 pool_put (smm->sessions[thread_index], s);
62 server_rx_fifo->master_session_index = pool_index;
63 server_rx_fifo->master_thread_index = thread_index;
65 server_tx_fifo->master_session_index = pool_index;
66 server_tx_fifo->master_thread_index = thread_index;
68 s->server_rx_fifo = server_rx_fifo;
69 s->server_tx_fifo = server_tx_fifo;
70 s->svm_segment_index = fifo_segment_index;
77 s->thread_index = thread_index;
78 s->session_index = pool_index;
81 s->connection_index = tc->c_index;
84 tc->s_index = s->session_index;
106 u32 to_drop = n_bytes_to_drop;
136 u32 chain_bi, len, diff;
142 if (is_in_order && offset)
170 return (rv > 0) ? (written + rv) : written;
224 int enqueued = 0, rv, in_order_off;
259 u32 thread_index = s->thread_index;
260 u32 my_enqueue_epoch = smm->current_enqueue_epoch[thread_index];
262 if (s->enqueue_epoch != my_enqueue_epoch)
264 s->enqueue_epoch = my_enqueue_epoch;
265 vec_add1 (smm->session_indices_to_enqueue_by_thread[thread_index],
266 s - smm->sessions[thread_index]);
293 if (!s->server_tx_fifo)
303 return svm_fifo_peek (s->server_tx_fifo, offset, max_bytes, buffer);
325 session_fifo_event_t evt;
327 static u32 serial_number;
343 clib_warning (
"invalid s->app_index = %d", s->app_index);
348 if (app->cb_fns.builtin_server_rx_callback)
349 return app->cb_fns.builtin_server_rx_callback (s);
355 evt.fifo = s->server_rx_fifo;
357 evt.event_id = serial_number++;
360 q = app->event_queue;
375 ed->data[0] = evt.event_id;
395 u32 *session_indices_to_enqueue;
398 session_indices_to_enqueue =
399 smm->session_indices_to_enqueue_by_thread[thread_index];
401 for (i = 0; i <
vec_len (session_indices_to_enqueue); i++)
416 smm->session_indices_to_enqueue_by_thread[thread_index] =
417 session_indices_to_enqueue;
420 smm->current_enqueue_epoch[thread_index]++;
432 u32 rx_pointer,
u32 tx_pointer)
452 tc->lcl_port, tc->rmt_port,
456 TCP_DBG (
"half-open was removed!");
470 opaque = tc->s_index;
485 new_s->app_index = app->index;
489 if (app->cb_fns.session_connected_callback (app->index, opaque, new_s,
513 server->cb_fns.session_accept_callback (s);
531 server->cb_fns.session_disconnect_callback (s);
551 pool_put (smm->sessions[s->thread_index], s);
553 memset (s, 0xFA,
sizeof (*s));
587 app->cb_fns.session_reset_callback (s);
611 s->app_index = server->index;
612 s->listener_index = listener_index;
618 server->cb_fns.session_accept_callback (s);
649 return VNET_API_ERROR_SESSION_CONNECT_FAIL;
657 handle = (((
u64) app_index) << 32) | (
u64) tc->c_index;
682 tci =
tp_vfts[s->session_type].bind (s->session_index, tep);
684 if (tci == (
u32) ~ 0)
688 s->connection_index = tci;
689 tc =
tp_vfts[s->session_type].get_listener (tci);
717 tc =
tp_vfts[s->session_type].get_listener (s->connection_index);
721 return VNET_API_ERROR_ADDRESS_NOT_IN_USE;
725 tp_vfts[s->session_type].unbind (s->connection_index);
734 static u16 serial_number = 0;
736 session_fifo_event_t evt;
740 evt.session_handle = session_handle;
741 evt.event_type = evt_type;
742 evt.event_id = serial_number++;
749 TCP_DBG (
"failed to enqueue evt");
766 tp_vfts[s->session_type].close (s->connection_index, s->thread_index);
787 tp_vfts[s->session_type].cleanup (s->connection_index, s->thread_index);
799 u32 event_queue_length = 2048;
801 if (smm->vpp_event_queues[thread_index] == 0)
806 if (smm->configured_event_queue_length)
807 event_queue_length = smm->configured_event_queue_length;
809 smm->vpp_event_queues[thread_index] =
812 sizeof (session_fifo_event_t), 0 ,
825 return SESSION_TYPE_IP4_TCP;
827 return SESSION_TYPE_IP6_TCP;
832 return SESSION_TYPE_IP4_UDP;
834 return SESSION_TYPE_IP6_UDP;
846 u32 preallocated_sessions_per_worker;
860 vec_validate (smm->session_indices_to_enqueue_by_thread, num_threads - 1);
862 vec_validate (smm->pending_event_vector, num_threads - 1);
864 vec_validate (smm->current_enqueue_epoch, num_threads - 1);
867 for (i = 0; i < num_threads; i++)
870 _vec_len (smm->free_event_vector[i]) = 0;
872 _vec_len (smm->pending_event_vector[i]) = 0;
876 vec_validate (smm->last_event_poll_by_thread, num_threads - 1);
880 for (i = 0; i <
vec_len (smm->vpp_event_queues); i++)
884 if (smm->preallocated_sessions)
886 if (num_threads == 1)
893 preallocated_sessions_per_worker =
894 (1.1 * (
f64) smm->preallocated_sessions /
895 (
f64) (num_threads - 1));
897 for (j = 1; j < num_threads; j++)
900 preallocated_sessions_per_worker);
918 u8 state = is_en ? VLIB_NODE_STATE_POLLING : VLIB_NODE_STATE_DISABLED;
967 if (
unformat (input,
"event-queue-length %d", &nitems))
970 smm->configured_event_queue_length = nitems;
972 clib_warning (
"event queue length %d too small, ignored", nitems);
974 else if (
unformat (input,
"preallocated-sessions %d",
975 &smm->preallocated_sessions))
977 else if (
unformat (input,
"v4-session-table-buckets %d",
978 &smm->configured_v4_session_table_buckets))
980 else if (
unformat (input,
"v4-halfopen-table-buckets %d",
981 &smm->configured_v4_halfopen_table_buckets))
983 else if (
unformat (input,
"v6-session-table-buckets %d",
984 &smm->configured_v6_session_table_buckets))
986 else if (
unformat (input,
"v6-halfopen-table-buckets %d",
987 &smm->configured_v6_halfopen_table_buckets))
989 else if (
unformat (input,
"v4-session-table-memory %U",
992 if (tmp >= 0x100000000)
995 smm->configured_v4_session_table_memory = tmp;
997 else if (
unformat (input,
"v4-halfopen-table-memory %U",
1000 if (tmp >= 0x100000000)
1003 smm->configured_v4_halfopen_table_memory = tmp;
1005 else if (
unformat (input,
"v6-session-table-memory %U",
1008 if (tmp >= 0x100000000)
1011 smm->configured_v6_session_table_memory = tmp;
1013 else if (
unformat (input,
"v6-halfopen-table-memory %U",
1016 if (tmp >= 0x100000000)
1019 smm->configured_v6_halfopen_table_memory = tmp;
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
int session_manager_flush_enqueue_events(u32 thread_index)
Flushes queue of sessions that are to be notified of new data enqueued events.
sll srl srl sll sra u16x4 i
static void svm_pop_heap(void *oldheap)
int segment_manager_alloc_session_fifos(segment_manager_t *sm, svm_fifo_t **server_rx_fifo, svm_fifo_t **server_tx_fifo, u32 *fifo_segment_index)
void svm_fifo_init_pointers(svm_fifo_t *f, u32 pointer)
Set fifo pointers to requested offset.
int stream_session_accept(transport_connection_t *tc, u32 listener_index, u8 sst, u8 notify)
Accept a stream session.
transport_proto_vft_t * tp_vfts
Per-type vector of transport protocol virtual function tables.
struct _transport_connection transport_connection_t
int stream_session_enqueue_data(transport_connection_t *tc, vlib_buffer_t *b, u32 offset, u8 queue_event, u8 is_in_order)
session_manager_main_t session_manager_main
struct _transport_proto_vft transport_proto_vft_t
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
int stream_session_table_del(stream_session_t *s)
int stream_session_table_del_for_tc(transport_connection_t *tc)
static u32 svm_fifo_max_enqueue(svm_fifo_t *f)
void session_node_enable_disable(u8 is_en)
vlib_node_registration_t session_queue_node
(constructor) VLIB_REGISTER_NODE (session_queue_node)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
void stream_session_half_open_table_del(transport_connection_t *tc)
struct _svm_fifo svm_fifo_t
segment_manager_t * application_get_listen_segment_manager(application_t *app, stream_session_t *s)
int application_is_proxy(application_t *app)
#define VLIB_BUFFER_NEXT_PRESENT
static clib_error_t * session_config_fn(vlib_main_t *vm, unformat_input_t *input)
#define VLIB_INIT_FUNCTION(x)
static void * svm_push_data_heap(svm_region_t *rp)
void stream_session_accept_notify(transport_connection_t *tc)
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
#define clib_error_return(e, args...)
svm_region_t * vlib_rp
Binary api segment descriptor.
void stream_session_delete_notify(transport_connection_t *tc)
Notification from transport that connection is being deleted.
int stream_session_open(u32 app_index, session_type_t st, transport_endpoint_t *rmt, transport_connection_t **res)
Ask transport to open connection to remote transport endpoint.
void stream_session_cleanup(stream_session_t *s)
Cleanup transport and session state.
void stream_session_delete(stream_session_t *s)
Cleans up session and lookup table.
struct _stream_session_t stream_session_t
void session_send_session_evt_to_thread(u64 session_handle, fifo_event_type_t evt_type, u32 thread_index)
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)
int unix_shared_memory_queue_add(unix_shared_memory_queue_t *q, u8 *elem, int nowait)
u32 stream_session_dequeue_drop(transport_connection_t *tc, u32 max_bytes)
static session_manager_main_t * vnet_get_session_manager_main()
u16 current_length
Nbytes between current data and the end of this buffer.
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.
void svm_fifo_segment_init(u64 baseva, u32 timeout_in_seconds)
#define VLIB_CONFIG_FUNCTION(x, n,...)
clib_error_t * vnet_tcp_enable_disable(vlib_main_t *vm, u8 is_en)
int stream_session_create_i(segment_manager_t *sm, transport_connection_t *tc, u8 alloc_fifos, stream_session_t **ret_s)
clib_error_t * session_manager_main_init(vlib_main_t *vm)
struct _session_manager_main session_manager_main_t
#define foreach_vlib_main(body)
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
#define TCP_DBG(_fmt, _args...)
API main structure, used by both vpp and binary API clients.
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
static u8 svm_fifo_set_event(svm_fifo_t *f)
Sets fifo event flag.
#define SESSION_EVT_DBG(_evt, _args...)
static unix_shared_memory_queue_t * session_manager_get_vpp_event_queue(u32 thread_index)
static_always_inline uword vlib_get_thread_index(void)
int stream_session_connect_notify(transport_connection_t *tc, u8 is_fail)
u32 stream_session_tx_fifo_max_dequeue(transport_connection_t *tc)
segment_manager_t * application_get_connect_segment_manager(application_t *app)
#define clib_warning(format, args...)
void stream_session_init_fifos_pointers(transport_connection_t *tc, u32 rx_pointer, u32 tx_pointer)
Init fifo tail and head pointers.
void stream_session_half_open_table_add(transport_connection_t *tc, u64 value)
struct _application application_t
int svm_fifo_enqueue_nowait(svm_fifo_t *f, u32 max_bytes, u8 *copy_from_here)
static stream_session_t * stream_session_get_if_valid(u64 si, u32 thread_index)
#define pool_init_fixed(pool, max_elts)
initialize a fixed-size, preallocated pool
void stream_session_disconnect_notify(transport_connection_t *tc)
Notification from transport that connection is being closed.
unix_shared_memory_queue_t * unix_shared_memory_queue_init(int nels, int elsize, int consumer_pid, int signal_when_queue_non_empty)
vhost_vring_state_t state
u32 next_buffer
Next buffer for this linked-list of buffers.
void stream_session_table_add_for_tc(transport_connection_t *tc, u64 value)
void stream_session_disconnect(stream_session_t *s)
Disconnect session and propagate to transport.
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
void stream_session_reset_notify(transport_connection_t *tc)
Notify application that connection has been reset.
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
int svm_fifo_enqueue_with_offset(svm_fifo_t *f, u32 offset, u32 required_bytes, u8 *copy_from_here)
int stream_session_stop_listen(stream_session_t *s)
Ask transport to stop listening on local transport endpoint.
session_type_t session_type_from_proto_and_ip(transport_proto_t proto, u8 is_ip4)
static vlib_main_t * vlib_get_main(void)
#define HALF_OPEN_LOOKUP_INVALID_VALUE
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.
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
static u64 stream_session_handle(stream_session_t *s)
template key/value backing page structure
static int stream_session_enqueue_notify(stream_session_t *s, u8 block)
Notify session peer that new data has been enqueued.
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 max_bytes)
void segment_manager_dealloc_fifos(u32 svm_segment_index, svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
void session_vpp_event_queue_allocate(session_manager_main_t *smm, u32 thread_index)
Allocate vpp event queue (once) per worker thread.
enum _transport_proto transport_proto_t
void session_lookup_init(void)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static stream_session_t * listen_session_get(session_type_t type, u32 index)
application_t * application_get(u32 index)
struct _transport_endpoint transport_endpoint_t
struct _segment_manager segment_manager_t
u64 stream_session_half_open_lookup_handle(ip46_address_t *lcl, ip46_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto)
int stream_session_listen(stream_session_t *s, transport_endpoint_t *tep)
Ask transport to listen on local transport endpoint.
static vlib_thread_main_t * vlib_get_thread_main()
static int session_enqueue_chain_tail(stream_session_t *s, vlib_buffer_t *b, u32 offset, u8 is_in_order)
Enqueue buffer chain tail.
#define CLIB_CACHE_LINE_BYTES
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
int svm_fifo_peek(svm_fifo_t *f, u32 relative_offset, u32 max_bytes, u8 *copy_here)
int stream_session_peek_bytes(transport_connection_t *tc, u8 *buffer, u32 offset, u32 max_bytes)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
application_t * application_get_if_valid(u32 index)
u8 stream_session_no_space(transport_connection_t *tc, u32 thread_index, u16 data_len)
Check if we have space in rx fifo to push more bytes.
struct _unix_shared_memory_queue unix_shared_memory_queue_t
static stream_session_t * stream_session_get(u32 si, u32 thread_index)