/* * Copyright (c) 2017-2019 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __included_session_h__ #define __included_session_h__ #include #include #include #include #include #include #define foreach_session_input_error \ _(NO_SESSION, "No session drops") \ _(NO_LISTENER, "No listener for dst port drops") \ _(ENQUEUED, "Packets pushed into rx fifo") \ _(NOT_READY, "Session not ready packets") \ _(FIFO_FULL, "Packets dropped for lack of rx fifo space") \ _(EVENT_FIFO_FULL, "Events not sent for lack of event fifo space") \ _(API_QUEUE_FULL, "Sessions not created for lack of API queue space") \ typedef enum { #define _(sym,str) SESSION_ERROR_##sym, foreach_session_input_error #undef _ SESSION_N_ERROR, } session_input_error_t; typedef struct session_tx_context_ { CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); session_t *s; transport_proto_vft_t *transport_vft; transport_connection_t *tc; transport_send_params_t sp; u32 max_dequeue; u32 left_to_snd; u32 max_len_to_snd; u16 deq_per_first_buf; u16 deq_per_buf; u16 n_segs_per_evt; u16 n_bufs_needed; u8 n_bufs_per_seg; CLIB_CACHE_LINE_ALIGN_MARK (cacheline1); session_dgram_hdr_t hdr; } session_tx_context_t; typedef struct session_evt_elt { clib_llist_anchor_t evt_list; session_event_t evt; } session_evt_elt_t; typedef struct session_ctrl_evt_data_ { u8 data[SESSION_CTRL_MSG_MAX_SIZE]; } session_evt_ctrl_data_t; typedef struct session_worker_ { CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); /** Worker session pool */ session_t *sessions; /** vpp event message queue for worker */ svm_msg_q_t *vpp_event_queue; /** vlib_time_now last time around the track */ clib_time_type_t last_vlib_time; /** vlib_time_now rounded to us precision and as u64 */ clib_us_time_t last_vlib_us_time; /** Convenience pointer to this worker's vlib_main */ vlib_main_t *vm; /** Per-proto vector of sessions to enqueue */ u32 **session_to_enqueue; /** Context for session tx */ session_tx_context_t ctx; /** Vector of tx buffer free lists */ u32 *tx_buffers; /** Pool of session event list elements */ session_evt_elt_t *event_elts; /** Pool of ctrl events data buffers */ session_evt_ctrl_data_t *ctrl_evts_data; /** Head of control events list */ clib_llist_index_t ctrl_head; /** Head of list of elements */ clib_llist_index_t new_head; /** Head of list of pending events */ clib_llist_index_t old_head; /** Peekers rw lock */ clib_rwlock_t peekers_rw_locks; /** Vector of buffers to be sent */ u32 *pending_tx_buffers; /** Vector of nexts for the pending tx buffers */ u16 *pending_tx_nexts; #if SESSION_DEBUG /** last event poll time by thread */ clib_time_type_t last_event_poll; #endif } session_worker_t; typedef int (session_fifo_rx_fn) (session_worker_t * wrk, vlib_node_runtime_t * node, session_evt_elt_t * e, int *n_tx_packets); extern session_fifo_rx_fn session_tx_fifo_peek_and_snd; extern session_fifo_rx_fn session_tx_fifo_dequeue_and_snd; extern session_fifo_rx_fn session_tx_fifo_dequeue_internal; u8 session_node_lookup_fifo_event (svm_fifo_t * f, session_event_t * e); typedef struct session_main_ { /** Worker contexts */ session_worker_t *wrk; /** Event queues memfd segment initialized only if so configured */ ssvm_private_t evt_qs_segment; /** Unique segment name counter */ u32 unique_segment_name_counter; /** Per transport rx function that can either dequeue or peek */ session_fifo_rx_fn **session_tx_fns; /** Per session type output nodes. Could optimize to group nodes by * fib but lookup would then require session type parsing in session node. * Trade memory for speed, for now */ u32 *session_type_to_next; transport_proto_t last_transport_proto_type; /* * Config parameters */ /** Session manager is enabled */ u8 is_enabled; /** Enable session manager at startup */ u8 session_enable_asap; /** vpp fifo event queue configured length */ u32 configured_event_queue_length; /** Session ssvm segment configs*/ uword session_baseva; uword session_va_space_size; uword evt_qs_segment_size; u8 evt_qs_use_memfd_seg; /** Session table size parameters */ u32 configured_v4_session_table_buckets; u32 configured_v4_session_table_memory; u32 configured_v4_halfopen_table_buckets; u32 configured_v4_halfopen_table_memory; u32 configured_v6_session_table_buckets; u32 configured_v6_session_table_memory; u32 configured_v6_halfopen_table_buckets; u32 configured_v6_halfopen_table_memory; /** Transport table (preallocation) size parameters */ u32 local_endpoints_table_memory; u32 local_endpoints_table_buckets; /** Preallocate session config parameter */ u32 preallocated_sessions; } session_main_t; extern session_main_t session_main; extern vlib_node_registration_t session_queue_node; extern vlib_node_registration_t session_queue_process_node; extern vlib_node_registration_t session_queue_pre_input_node; typedef enum session_q_process_evt_ { SESSION_Q_PROCESS_RUN_ON_MAIN = 1, SESSION_Q_PROCESS_STOP } session_q_process_evt_t; #define TRANSPORT_PROTO_INVALID (session_main.last_transport_proto_type + 1) #define TRANSPORT_N_PROTOS (session_main.last_transport_proto_type + 1) static inline session_evt_elt_t * session_evt_elt_alloc (session_worker_t * wrk) { session_evt_elt_t *elt; pool_get (wrk->event_elts, elt); return elt; } static inline void session_evt_elt_free (session_worker_t * wrk, session_evt_elt_t * elt) { pool_put (wrk->event_elts, elt); } static inline void session_evt_add_old (session_worker_t * wrk, session_evt_elt_t * elt) { clib_llist_add_tail (wrk->event_elts, evt_list, elt, pool_elt_at_index (wrk->event_elts, wrk->old_head)); } static inline void session_evt_add_head_old (session_worker_t * wrk, session_evt_elt_t * elt) { clib_llist_add (wrk->event_elts, evt_list, elt, pool_elt_at_index (wrk->event_elts, wrk->old_head)); } static inline u32 session_evt_ctrl_data_alloc (session_worker_t * wrk) { session_evt_ctrl_data_t *data; pool_get (wrk->ctrl_evts_data, data); return (data - wrk->ctrl_evts_data); } static inline session_evt_elt_t * session_evt_alloc_ctrl (session_worker_t * wrk) { session_evt_elt_t *elt; elt = session_evt_elt_alloc (wrk); clib_llist_add_tail (wrk->event_elts, evt_list, elt, pool_elt_at_index (wrk->event_elts, wrk->ctrl_head)); return elt; } static inline void * session_evt_ctrl_data (session_worker_t * wrk, session_evt_elt_t * elt) { return (void *) (pool_elt_at_index (wrk->ctrl_evts_data, elt->evt.ctrl_data_index)); } static inline void session_evt_ctrl_data_free (session_worker_t * wrk, session_evt_elt_t * elt) { ASSERT (elt->evt.event_type > SESS
/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#undef BIHASH_TYPE
#undef BIHASH_KVP_PER_PAGE

#define BIHASH_TYPE _8_8
#define BIHASH_KVP_PER_PAGE 4

#ifndef __included_bihash_8_8_h__
#define __included_bihash_8_8_h__

#include <vppinfra/heap.h>
#include <vppinfra/format.h>
#include <vppinfra/pool.h>
#include <vppinfra/xxhash.h>
#include <vppinfra/crc32.h>

/** 8 octet key, 8 octet key value pair */
typedef struct
{
  u64 key;			/**< the key */
  u64 value;			/**< the value */
} clib_bihash_kv_8_8_t;

/** Decide if a clib_bihash_kv_8_8_t instance is free
    @param v- pointer to the (key,value) pair
*/
static inline int
clib_bihash_is_free_8_8 (clib_bihash_kv_8_8_t * v)
{
  if (v->key == ~0ULL && v->value == ~0ULL)
    return 1;
  return 0;
}

/** Hash a clib_bihash_kv_8_8_t instance
    @param v - pointer to the (key,value) pair, hash the key (only)
*/
static inline u64
c