Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | #ifndef __included_session_h__ |
| 16 | #define __included_session_h__ |
| 17 | |
| 18 | #include <vnet/session/transport.h> |
| 19 | #include <vlibmemory/unix_shared_memory_queue.h> |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 20 | #include <vnet/session/session_debug.h> |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 21 | #include <vnet/session/segment_manager.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 22 | |
| 23 | #define HALF_OPEN_LOOKUP_INVALID_VALUE ((u64)~0) |
| 24 | #define INVALID_INDEX ((u32)~0) |
| 25 | |
| 26 | /* TODO decide how much since we have pre-data as well */ |
| 27 | #define MAX_HDRS_LEN 100 /* Max number of bytes for headers */ |
| 28 | |
| 29 | typedef enum |
| 30 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 31 | FIFO_EVENT_APP_RX, |
| 32 | FIFO_EVENT_APP_TX, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 33 | FIFO_EVENT_TIMEOUT, |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 34 | FIFO_EVENT_DISCONNECT, |
Dave Barach | e5f1d27 | 2017-05-10 13:34:04 -0400 | [diff] [blame] | 35 | FIFO_EVENT_BUILTIN_RX, |
| 36 | FIFO_EVENT_RPC, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 37 | } fifo_event_type_t; |
| 38 | |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 39 | #define foreach_session_input_error \ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 40 | _(NO_SESSION, "No session drops") \ |
| 41 | _(NO_LISTENER, "No listener for dst port drops") \ |
| 42 | _(ENQUEUED, "Packets pushed into rx fifo") \ |
| 43 | _(NOT_READY, "Session not ready packets") \ |
| 44 | _(FIFO_FULL, "Packets dropped for lack of rx fifo space") \ |
| 45 | _(EVENT_FIFO_FULL, "Events not sent for lack of event fifo space") \ |
| 46 | _(API_QUEUE_FULL, "Sessions not created for lack of API queue space") \ |
| 47 | _(NEW_SEG_NO_SPACE, "Created segment, couldn't allocate a fifo pair") \ |
| 48 | _(NO_SPACE, "Couldn't allocate a fifo pair") |
| 49 | |
| 50 | typedef enum |
| 51 | { |
| 52 | #define _(sym,str) SESSION_ERROR_##sym, |
| 53 | foreach_session_input_error |
| 54 | #undef _ |
| 55 | SESSION_N_ERROR, |
| 56 | } session_error_t; |
| 57 | |
| 58 | /* Event queue input node static next indices */ |
| 59 | typedef enum |
| 60 | { |
| 61 | SESSION_QUEUE_NEXT_DROP, |
| 62 | SESSION_QUEUE_NEXT_TCP_IP4_OUTPUT, |
| 63 | SESSION_QUEUE_NEXT_IP4_LOOKUP, |
| 64 | SESSION_QUEUE_NEXT_TCP_IP6_OUTPUT, |
| 65 | SESSION_QUEUE_NEXT_IP6_LOOKUP, |
| 66 | SESSION_QUEUE_N_NEXT, |
| 67 | } session_queue_next_t; |
| 68 | |
| 69 | #define foreach_session_type \ |
| 70 | _(IP4_TCP, ip4_tcp) \ |
| 71 | _(IP4_UDP, ip4_udp) \ |
| 72 | _(IP6_TCP, ip6_tcp) \ |
| 73 | _(IP6_UDP, ip6_udp) |
| 74 | |
| 75 | typedef enum |
| 76 | { |
| 77 | #define _(A, a) SESSION_TYPE_##A, |
| 78 | foreach_session_type |
| 79 | #undef _ |
| 80 | SESSION_N_TYPES, |
| 81 | } session_type_t; |
| 82 | |
| 83 | /* |
| 84 | * Application session state |
| 85 | */ |
| 86 | typedef enum |
| 87 | { |
| 88 | SESSION_STATE_LISTENING, |
| 89 | SESSION_STATE_CONNECTING, |
| 90 | SESSION_STATE_READY, |
| 91 | SESSION_STATE_CLOSED, |
| 92 | SESSION_STATE_N_STATES, |
| 93 | } stream_session_state_t; |
| 94 | |
Dave Barach | e5f1d27 | 2017-05-10 13:34:04 -0400 | [diff] [blame] | 95 | typedef struct |
| 96 | { |
| 97 | void *fp; |
| 98 | void *arg; |
| 99 | } rpc_args_t; |
| 100 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 101 | /* *INDENT-OFF* */ |
| 102 | typedef CLIB_PACKED (struct { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 103 | union |
| 104 | { |
| 105 | svm_fifo_t * fifo; |
| 106 | u64 session_handle; |
Dave Barach | e5f1d27 | 2017-05-10 13:34:04 -0400 | [diff] [blame] | 107 | rpc_args_t rpc_args; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 108 | }; |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 109 | u8 event_type; |
| 110 | u16 event_id; |
| 111 | }) session_fifo_event_t; |
| 112 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 113 | |
| 114 | typedef struct _stream_session_t |
| 115 | { |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 116 | /** fifo pointers. Once allocated, these do not move */ |
| 117 | svm_fifo_t *server_rx_fifo; |
| 118 | svm_fifo_t *server_tx_fifo; |
| 119 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 120 | /** Type */ |
| 121 | u8 session_type; |
| 122 | |
| 123 | /** State */ |
| 124 | u8 session_state; |
| 125 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 126 | u8 thread_index; |
| 127 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 128 | /** To avoid n**2 "one event per frame" check */ |
| 129 | u8 enqueue_epoch; |
| 130 | |
Dave Barach | 1015a1e | 2017-05-08 19:15:03 -0400 | [diff] [blame] | 131 | /** Pad to a multiple of 8 octets */ |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 132 | u8 align_pad[4]; |
Dave Barach | 1015a1e | 2017-05-08 19:15:03 -0400 | [diff] [blame] | 133 | |
| 134 | /** svm segment index where fifos were allocated */ |
| 135 | u32 svm_segment_index; |
| 136 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 137 | /** Session index in per_thread pool */ |
| 138 | u32 session_index; |
| 139 | |
| 140 | /** Transport specific */ |
| 141 | u32 connection_index; |
| 142 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 143 | /** Application specific */ |
| 144 | u32 pid; |
| 145 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 146 | /** stream server pool index */ |
| 147 | u32 app_index; |
| 148 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 149 | /** Parent listener session if the result of an accept */ |
| 150 | u32 listener_index; |
Dave Barach | 1015a1e | 2017-05-08 19:15:03 -0400 | [diff] [blame] | 151 | |
| 152 | /** Opaque, pad to a 64-octet boundary */ |
| 153 | u64 opaque[2]; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 154 | } stream_session_t; |
| 155 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 156 | /* Forward definition */ |
| 157 | typedef struct _session_manager_main session_manager_main_t; |
| 158 | |
| 159 | typedef int |
| 160 | (session_fifo_rx_fn) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 161 | session_manager_main_t * smm, |
| 162 | session_fifo_event_t * e0, stream_session_t * s0, |
| 163 | u32 thread_index, int *n_tx_pkts); |
| 164 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 165 | extern session_fifo_rx_fn session_tx_fifo_peek_and_snd; |
| 166 | extern session_fifo_rx_fn session_tx_fifo_dequeue_and_snd; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 167 | |
| 168 | struct _session_manager_main |
| 169 | { |
| 170 | /** Lookup tables for established sessions and listeners */ |
| 171 | clib_bihash_16_8_t v4_session_hash; |
| 172 | clib_bihash_48_8_t v6_session_hash; |
| 173 | |
| 174 | /** Lookup tables for half-open sessions */ |
| 175 | clib_bihash_16_8_t v4_half_open_hash; |
| 176 | clib_bihash_48_8_t v6_half_open_hash; |
| 177 | |
| 178 | /** Per worker thread session pools */ |
| 179 | stream_session_t **sessions; |
| 180 | |
| 181 | /** Pool of listen sessions. Same type as stream sessions to ease lookups */ |
| 182 | stream_session_t *listen_sessions[SESSION_N_TYPES]; |
| 183 | |
| 184 | /** Sparse vector to map dst port to stream server */ |
| 185 | u16 *stream_server_by_dst_port[SESSION_N_TYPES]; |
| 186 | |
| 187 | /** per-worker enqueue epoch counters */ |
| 188 | u8 *current_enqueue_epoch; |
| 189 | |
| 190 | /** Per-worker thread vector of sessions to enqueue */ |
| 191 | u32 **session_indices_to_enqueue_by_thread; |
| 192 | |
| 193 | /** per-worker tx buffer free lists */ |
| 194 | u32 **tx_buffers; |
| 195 | |
| 196 | /** Per worker-thread vector of partially read events */ |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 197 | session_fifo_event_t **free_event_vector; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 198 | |
| 199 | /** per-worker active event vectors */ |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 200 | session_fifo_event_t **pending_event_vector; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 201 | |
| 202 | /** vpp fifo event queue */ |
| 203 | unix_shared_memory_queue_t **vpp_event_queues; |
| 204 | |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 205 | /** vpp fifo event queue configured length */ |
| 206 | u32 configured_event_queue_length; |
| 207 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 208 | /** Unique segment name counter */ |
| 209 | u32 unique_segment_name_counter; |
| 210 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 211 | /** Per transport rx function that can either dequeue or peek */ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 212 | session_fifo_rx_fn *session_tx_fns[SESSION_N_TYPES]; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 213 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 214 | u8 is_enabled; |
| 215 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 216 | /* Convenience */ |
| 217 | vlib_main_t *vlib_main; |
| 218 | vnet_main_t *vnet_main; |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 219 | |
| 220 | #if SESSION_DBG |
| 221 | /** |
| 222 | * last event poll time by thread |
| 223 | * Debug only. Will cause false cache-line sharing as-is |
| 224 | */ |
| 225 | f64 *last_event_poll_by_thread; |
| 226 | #endif |
| 227 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 228 | }; |
| 229 | |
| 230 | extern session_manager_main_t session_manager_main; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 231 | extern vlib_node_registration_t session_queue_node; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 232 | |
| 233 | /* |
| 234 | * Session manager function |
| 235 | */ |
| 236 | always_inline session_manager_main_t * |
| 237 | vnet_get_session_manager_main () |
| 238 | { |
| 239 | return &session_manager_main; |
| 240 | } |
| 241 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 242 | /* |
| 243 | * Stream session functions |
| 244 | */ |
| 245 | |
| 246 | stream_session_t *stream_session_lookup_listener4 (ip4_address_t * lcl, |
| 247 | u16 lcl_port, u8 proto); |
| 248 | stream_session_t *stream_session_lookup4 (ip4_address_t * lcl, |
| 249 | ip4_address_t * rmt, u16 lcl_port, |
| 250 | u16 rmt_port, u8 proto, |
| 251 | u32 thread_index); |
| 252 | stream_session_t *stream_session_lookup_listener6 (ip6_address_t * lcl, |
| 253 | u16 lcl_port, u8 proto); |
| 254 | stream_session_t *stream_session_lookup6 (ip6_address_t * lcl, |
| 255 | ip6_address_t * rmt, u16 lcl_port, |
| 256 | u16 rmt_port, u8, u32 thread_index); |
| 257 | transport_connection_t |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 258 | * stream_session_lookup_transport4 (ip4_address_t * lcl, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 259 | ip4_address_t * rmt, u16 lcl_port, |
| 260 | u16 rmt_port, u8 proto, |
| 261 | u32 thread_index); |
| 262 | transport_connection_t |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 263 | * stream_session_lookup_transport6 (ip6_address_t * lcl, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 264 | ip6_address_t * rmt, u16 lcl_port, |
| 265 | u16 rmt_port, u8 proto, |
| 266 | u32 thread_index); |
| 267 | stream_session_t *stream_session_lookup_listener (ip46_address_t * lcl, |
| 268 | u16 lcl_port, u8 proto); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 269 | void stream_session_table_add_for_tc (transport_connection_t * tc, u64 value); |
| 270 | int stream_session_table_del_for_tc (transport_connection_t * tc); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 271 | |
| 272 | always_inline stream_session_t * |
| 273 | stream_session_get_tsi (u64 ti_and_si, u32 thread_index) |
| 274 | { |
| 275 | ASSERT ((u32) (ti_and_si >> 32) == thread_index); |
| 276 | return pool_elt_at_index (session_manager_main.sessions[thread_index], |
| 277 | ti_and_si & 0xFFFFFFFFULL); |
| 278 | } |
| 279 | |
| 280 | always_inline stream_session_t * |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 281 | stream_session_get (u32 si, u32 thread_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 282 | { |
| 283 | return pool_elt_at_index (session_manager_main.sessions[thread_index], si); |
| 284 | } |
| 285 | |
| 286 | always_inline stream_session_t * |
| 287 | stream_session_get_if_valid (u64 si, u32 thread_index) |
| 288 | { |
| 289 | if (thread_index >= vec_len (session_manager_main.sessions)) |
| 290 | return 0; |
| 291 | |
| 292 | if (pool_is_free_index (session_manager_main.sessions[thread_index], si)) |
| 293 | return 0; |
| 294 | |
| 295 | return pool_elt_at_index (session_manager_main.sessions[thread_index], si); |
| 296 | } |
| 297 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 298 | always_inline u64 |
| 299 | stream_session_handle (stream_session_t * s) |
| 300 | { |
| 301 | return ((u64) s->thread_index << 32) | (u64) s->session_index; |
| 302 | } |
| 303 | |
| 304 | always_inline u32 |
| 305 | stream_session_index_from_handle (u64 handle) |
| 306 | { |
| 307 | return handle & 0xFFFFFFFF; |
| 308 | } |
| 309 | |
| 310 | always_inline u32 |
| 311 | stream_session_thread_from_handle (u64 handle) |
| 312 | { |
| 313 | return handle >> 32; |
| 314 | } |
| 315 | |
| 316 | always_inline void |
| 317 | stream_session_parse_handle (u64 handle, u32 * index, u32 * thread_index) |
| 318 | { |
| 319 | *index = stream_session_index_from_handle (handle); |
| 320 | *thread_index = stream_session_thread_from_handle (handle); |
| 321 | } |
| 322 | |
| 323 | always_inline stream_session_t * |
| 324 | stream_session_get_from_handle (u64 handle) |
| 325 | { |
| 326 | session_manager_main_t *smm = &session_manager_main; |
| 327 | return pool_elt_at_index (smm->sessions[stream_session_thread_from_handle |
| 328 | (handle)], |
| 329 | stream_session_index_from_handle (handle)); |
| 330 | } |
| 331 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 332 | always_inline stream_session_t * |
| 333 | stream_session_listener_get (u8 sst, u64 si) |
| 334 | { |
| 335 | return pool_elt_at_index (session_manager_main.listen_sessions[sst], si); |
| 336 | } |
| 337 | |
| 338 | always_inline u32 |
| 339 | stream_session_get_index (stream_session_t * s) |
| 340 | { |
| 341 | if (s->session_state == SESSION_STATE_LISTENING) |
| 342 | return s - session_manager_main.listen_sessions[s->session_type]; |
| 343 | |
| 344 | return s - session_manager_main.sessions[s->thread_index]; |
| 345 | } |
| 346 | |
| 347 | always_inline u32 |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 348 | stream_session_max_rx_enqueue (transport_connection_t * tc) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 349 | { |
| 350 | stream_session_t *s = stream_session_get (tc->s_index, tc->thread_index); |
| 351 | return svm_fifo_max_enqueue (s->server_rx_fifo); |
| 352 | } |
| 353 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 354 | always_inline u32 |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 355 | stream_session_rx_fifo_size (transport_connection_t * tc) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 356 | { |
| 357 | stream_session_t *s = stream_session_get (tc->s_index, tc->thread_index); |
| 358 | return s->server_rx_fifo->nitems; |
| 359 | } |
| 360 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 361 | u32 stream_session_tx_fifo_max_dequeue (transport_connection_t * tc); |
| 362 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 363 | int |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 364 | stream_session_enqueue_data (transport_connection_t * tc, vlib_buffer_t * b, |
| 365 | u32 offset, u8 queue_event, u8 is_in_order); |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 366 | int |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 367 | stream_session_peek_bytes (transport_connection_t * tc, u8 * buffer, |
| 368 | u32 offset, u32 max_bytes); |
| 369 | u32 stream_session_dequeue_drop (transport_connection_t * tc, u32 max_bytes); |
| 370 | |
Florin Coras | c28764f | 2017-04-26 00:08:42 -0700 | [diff] [blame] | 371 | void stream_session_connect_notify (transport_connection_t * tc, u8 sst, |
| 372 | u8 is_fail); |
| 373 | void stream_session_init_fifos_pointers (transport_connection_t * tc, |
| 374 | u32 rx_pointer, u32 tx_pointer); |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 375 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 376 | void stream_session_accept_notify (transport_connection_t * tc); |
| 377 | void stream_session_disconnect_notify (transport_connection_t * tc); |
| 378 | void stream_session_delete_notify (transport_connection_t * tc); |
| 379 | void stream_session_reset_notify (transport_connection_t * tc); |
| 380 | int |
| 381 | stream_session_accept (transport_connection_t * tc, u32 listener_index, |
| 382 | u8 sst, u8 notify); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 383 | int |
| 384 | stream_session_open (u32 app_index, session_type_t st, |
| 385 | transport_endpoint_t * tep, |
| 386 | transport_connection_t ** tc); |
| 387 | int stream_session_listen (stream_session_t * s, transport_endpoint_t * tep); |
| 388 | int stream_session_stop_listen (stream_session_t * s); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 389 | void stream_session_disconnect (stream_session_t * s); |
| 390 | void stream_session_cleanup (stream_session_t * s); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 391 | void session_send_session_evt_to_thread (u64 session_handle, |
| 392 | fifo_event_type_t evt_type, |
| 393 | u32 thread_index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 394 | u8 *format_stream_session (u8 * s, va_list * args); |
Dave Barach | 0194f1a | 2017-05-15 10:11:39 -0400 | [diff] [blame] | 395 | int |
| 396 | send_session_connected_callback (u32 app_index, u32 api_context, |
| 397 | stream_session_t * s, u8 is_fail); |
| 398 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 399 | |
| 400 | void session_register_transport (u8 type, const transport_proto_vft_t * vft); |
| 401 | transport_proto_vft_t *session_get_transport_vft (u8 type); |
| 402 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 403 | clib_error_t *vnet_session_enable_disable (vlib_main_t * vm, u8 is_en); |
| 404 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 405 | always_inline unix_shared_memory_queue_t * |
| 406 | session_manager_get_vpp_event_queue (u32 thread_index) |
| 407 | { |
| 408 | return session_manager_main.vpp_event_queues[thread_index]; |
| 409 | } |
| 410 | |
| 411 | int session_manager_flush_enqueue_events (u32 thread_index); |
| 412 | |
| 413 | always_inline u64 |
| 414 | listen_session_get_handle (stream_session_t * s) |
| 415 | { |
| 416 | ASSERT (s->session_state == SESSION_STATE_LISTENING); |
| 417 | return ((u64) s->session_type << 32) | s->session_index; |
| 418 | } |
| 419 | |
| 420 | always_inline stream_session_t * |
| 421 | listen_session_get_from_handle (u64 handle) |
| 422 | { |
| 423 | session_manager_main_t *smm = &session_manager_main; |
| 424 | stream_session_t *s; |
| 425 | u32 type, index; |
| 426 | type = handle >> 32; |
| 427 | index = handle & 0xFFFFFFFF; |
| 428 | |
| 429 | if (pool_is_free_index (smm->listen_sessions[type], index)) |
| 430 | return 0; |
| 431 | |
| 432 | s = pool_elt_at_index (smm->listen_sessions[type], index); |
| 433 | ASSERT (s->session_state == SESSION_STATE_LISTENING); |
| 434 | return s; |
| 435 | } |
| 436 | |
| 437 | always_inline stream_session_t * |
| 438 | listen_session_new (session_type_t type) |
| 439 | { |
| 440 | stream_session_t *s; |
Dave Barach | 1015a1e | 2017-05-08 19:15:03 -0400 | [diff] [blame] | 441 | pool_get_aligned (session_manager_main.listen_sessions[type], s, |
| 442 | CLIB_CACHE_LINE_BYTES); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 443 | memset (s, 0, sizeof (*s)); |
| 444 | |
| 445 | s->session_type = type; |
| 446 | s->session_state = SESSION_STATE_LISTENING; |
| 447 | s->session_index = s - session_manager_main.listen_sessions[type]; |
| 448 | |
| 449 | return s; |
| 450 | } |
| 451 | |
| 452 | always_inline stream_session_t * |
| 453 | listen_session_get (session_type_t type, u32 index) |
| 454 | { |
| 455 | return pool_elt_at_index (session_manager_main.listen_sessions[type], |
| 456 | index); |
| 457 | } |
| 458 | |
| 459 | always_inline void |
| 460 | listen_session_del (stream_session_t * s) |
| 461 | { |
| 462 | pool_put (session_manager_main.listen_sessions[s->session_type], s); |
| 463 | } |
| 464 | |
| 465 | always_inline u8 |
| 466 | session_manager_is_enabled () |
| 467 | { |
| 468 | return session_manager_main.is_enabled == 1; |
| 469 | } |
| 470 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 471 | #endif /* __included_session_h__ */ |
| 472 | |
| 473 | /* |
| 474 | * fd.io coding-style-patch-verification: ON |
| 475 | * |
| 476 | * Local Variables: |
| 477 | * eval: (c-set-style "gnu") |
| 478 | * End: |
| 479 | */ |