/* * Copyright (c) 2018-2019 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this * 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 SRC_VCL_VCL_PRIVATE_H_ #define SRC_VCL_VCL_PRIVATE_H_ #include #include #include #if (CLIB_DEBUG > 0) /* Set VPPCOM_DEBUG_INIT 2 for connection debug, * 3 for read/write debug output * or * export VCL_DEBUG=<#> to set dynamically. */ #define VPPCOM_DEBUG_INIT 1 #else #define VPPCOM_DEBUG_INIT 0 #endif #define VPPCOM_DEBUG vcm->debug extern __thread uword __vcl_worker_index; static inline void vcl_set_worker_index (uword wrk_index) { __vcl_worker_index = wrk_index; } static inline uword vcl_get_worker_index (void) { return __vcl_worker_index; } /* * VPPCOM Private definitions and functions. */ typedef enum { STATE_APP_START, STATE_APP_CONN_VPP, STATE_APP_ENABLED, STATE_APP_ATTACHED, STATE_APP_ADDING_WORKER, STATE_APP_ADDING_TLS_DATA, STATE_APP_FAILED, STATE_APP_READY } vcl_bapi_app_state_t; typedef enum vcl_session_state_ { VCL_STATE_CLOSED, VCL_STATE_LISTEN, VCL_STATE_READY, VCL_STATE_VPP_CLOSING, VCL_STATE_DISCONNECT, VCL_STATE_DETACHED, VCL_STATE_UPDATED, VCL_STATE_LISTEN_NO_MQ, } vcl_session_state_t; typedef struct epoll_event vppcom_epoll_event_t; typedef struct { u32 next_sh; u32 prev_sh; u32 vep_sh; vppcom_epoll_event_t ev; #define VEP_DEFAULT_ET_MASK (EPOLLIN|EPOLLOUT) #define VEP_UNSUPPORTED_EVENTS (EPOLLONESHOT|EPOLLEXCLUSIVE) u32 et_mask; } vppcom_epoll_t; /* Select uses the vcl_si_set as if a clib_bitmap. Make sure they are the * same size */ STATIC_ASSERT (sizeof (clib_bitmap_t) == sizeof (vcl_si_set), "vppcom bitmap size mismatch"); typedef struct { u8 is_ip4; ip46_address_t ip46; } vppcom_ip46_t; #define VCL_ACCEPTED_F_CLOSED (1 << 0) #define VCL_ACCEPTED_F_RESET (1 << 1) typedef struct vcl_session_msg { union { session_accepted_msg_t accepted_msg; }; u32 flags; } vcl_session_msg_t; typedef enum { VCL_SESS_ATTR_SERVER, VCL_SESS_ATTR_CUT_THRU, VCL_SESS_ATTR_VEP, VCL_SESS_ATTR_VEP_SESSION, VCL_SESS_ATTR_LISTEN, // SOL_SOCKET,SO_ACCEPTCONN VCL_SESS_ATTR_NONBLOCK, // fcntl,O_NONBLOCK VCL_SESS_ATTR_REUSEADDR, // SOL_SOCKET,SO_REUSEADDR VCL_SESS_ATTR_REUSEPORT, // SOL_SOCKET,SO_REUSEPORT VCL_SESS_ATTR_BROADCAST, // SOL_SOCKET,SO_BROADCAST VCL_SESS_ATTR_V6ONLY, // SOL_TCP,IPV6_V6ONLY VCL_SESS_ATTR_KEEPALIVE, // SOL_SOCKET,SO_KEEPALIVE VCL_SESS_ATTR_TCP_NODELAY, // SOL_TCP,TCP_NODELAY VCL_SESS_ATTR_TCP_KEEPIDLE, // SOL_TCP,TCP_KEEPIDLE VCL_SESS_ATTR_TCP_KEEPINTVL, // SOL_TCP,TCP_KEEPINTVL VCL_SESS_ATTR_SHUT_RD, VCL_SESS_ATTR_SHUT_WR, VCL_SESS_ATTR_MAX } vppcom_session_attr_t; typedef enum vcl_session_flags_ { VCL_SESSION_F_CONNECTED = 1 << 0, VCL_SESSION_F_IS_VEP = 1 << 1, VCL_SESSION_F_IS_VEP_SESSION = 1 << 2, VCL_SESSION_F_HAS_RX_EVT = 1 << 3, } __clib_packed vcl_session_flags_t; typedef struct vcl_session_ { CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); #define _(type, name) type name; foreach_app_session_field #undef _ vcl_session_flags_t flags; /**< see @ref vcl_session_flags_t */ u32 rx_bytes_pending; /**< bytes rx-ed as segs but not yet freed */ svm_fifo_t *ct_rx_fifo; svm_fifo_t *ct_tx_fifo; vcl_session_msg_t *accept_evts_fifo; u64 vpp_handle; u64 parent_handle; u32 listener_index; /**< index of parent listener (if any) */ int n_accepted_sessions; /**< sessions accepted by this listener */ vppcom_epoll_t vep; u32 attributes; /**< see @ref vppcom_session_attr_t */ int libc_epfd; u32 ckpair_index; u32 vrf; u32 sndbuf_size; // VPP-TBD: Hack until support setsockopt(SO_SNDBUF) u32 rcvbuf_size; // VPP-TBD: Hack until support setsockopt(SO_RCVBUF) u32 user_mss; // VPP-TBD: Hack until support setsockopt(TCP_MAXSEG) #if VCL_ELOG elog_track_t elog_track; #endif } vcl_session_t; typedef struct vppcom_cfg_t_ { uword heapsize; u32 max_workers; uword segment_baseva; uword segment_size; uword add_segment_size; u32 preallocated_fifo_pairs; u32 rx_fifo_size; u32 tx_fifo_size; u32 event_queue_size; u32 listen_queue_size; u8 app_proxy_transport_tcp; u8 app_proxy_transport_udp; u8 app_scope_local; u8 app_scope_global; u8 *namespace_id; u64 namespace_secret; u8 use_mq_eventfd; f64 app_timeout; f64 session_timeout; f64 accept_timeout; u32 event_ring_size; char *event_log_path; u8 *vpp_app_socket_api; /**< app socket api socket file name */ u8 *vpp_bapi_socket_name; /**< bapi socket transport socket name */ u32 tls_engine; u8 mt_wrk_supported; } vppcom_cfg_t; void vppcom_cfg (vppcom_cfg_t * vcl_cfg); typedef struct vcl_cut_through_registration_ { svm_msg_q_t *mq; svm_msg_q_t *peer_mq; u32 sid; u32 epoll_evt_conn_index; /*< mq evt connection index part of the mqs evtfd epoll (if used) */ } vcl_cut_through_registration_t; typedef struct vcl_mq_evt_conn_ { svm_msg_q_t *mq; int mq_fd; } vcl_mq_evt_conn_t; typedef struct vcl_worker_ { CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); /* Session pool */ vcl_session_t *sessions; /** Worker/thread index in current process */ u32 wrk_index; /** Worker index in vpp*/ u32 vpp_wrk_index; /** * Generic api client handle. When binary api is in used, it stores * the "client_index" and when socket api is use, it stores the sapi * client handle */ u32 api_client_handle; /** VPP binary api input queue */ svm_queue_t *vl_input_queue; /** VPP mq to be used for exchanging control messages */ svm_msg_q_t *ctrl_mq; /** Message queues epoll fd. Initialized only if using mqs with eventfds */ int mqs_epfd; /** Pool of event message queue event connections */ vcl_mq_evt_conn_t *mq_evt_conns; /** Per worker buffer for receiving mq epoll events */ struct epoll_event *mq_events; /** Hash table for disconnect processing */ uword *session_index_by_vpp_handles; /** Select bitmaps */ clib_bitmap_t *rd_bitmap; clib_bitmap_t *wr_bitmap; clib_bitmap_t *ex_bitmap; /** Our event message queue */ svm_msg_q_t *app_event_queue; /** For deadman timers */ clib_time_t clib_time; /** Vector acting as buffer f
/*
 * Copyright (c) 2017 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.
*/

#include <vppinfra/pool.h>

/* can be a very large size */
#define NELTS 1024

int
main (int argc, char *argv[])
{
  u32 *junk = 0;
  int i;
  u32 *tp = 0;
  u32 *indices = 0;

  clib_mem_init (0, 3ULL << 30);

  vec_validate (indices, NELTS - 1);
  _vec_len (indices) = 0;

  pool_init_fixed (tp, NELTS);

  for (i = 0; i < NELTS; i++)
    {
      pool_get (tp