2 * Copyright (c) 2017-2019 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef SRC_VNET_SESSION_SESSION_TYPES_H_
17 #define SRC_VNET_SESSION_SESSION_TYPES_H_
19 #include <svm/svm_fifo.h>
20 #include <vnet/session/transport_types.h>
22 #define SESSION_INVALID_INDEX ((u32)~0)
23 #define SESSION_INVALID_HANDLE ((u64)~0)
24 #define SESSION_CTRL_MSG_MAX_SIZE 84
26 #define foreach_session_endpoint_fields \
27 foreach_transport_endpoint_cfg_fields \
28 _(u8, transport_proto) \
30 typedef struct _session_endpoint
32 #define _(type, name) type name;
33 foreach_session_endpoint_fields
37 typedef struct _session_endpoint_cfg
39 #define _(type, name) type name;
40 foreach_session_endpoint_fields
49 } session_endpoint_cfg_t;
51 #define SESSION_IP46_ZERO \
58 #define TRANSPORT_ENDPOINT_NULL \
60 .sw_if_index = ENDPOINT_INVALID_INDEX, \
61 .ip = SESSION_IP46_ZERO, \
62 .fib_index = ENDPOINT_INVALID_INDEX, \
66 #define SESSION_ENDPOINT_NULL \
68 .sw_if_index = ENDPOINT_INVALID_INDEX, \
69 .ip = SESSION_IP46_ZERO, \
70 .fib_index = ENDPOINT_INVALID_INDEX, \
73 .peer = TRANSPORT_ENDPOINT_NULL, \
74 .transport_proto = 0, \
76 #define SESSION_ENDPOINT_CFG_NULL \
78 .sw_if_index = ENDPOINT_INVALID_INDEX, \
79 .ip = SESSION_IP46_ZERO, \
80 .fib_index = ENDPOINT_INVALID_INDEX, \
83 .peer = TRANSPORT_ENDPOINT_NULL, \
84 .transport_proto = 0, \
85 .app_wrk_index = ENDPOINT_INVALID_INDEX, \
86 .opaque = ENDPOINT_INVALID_INDEX, \
88 .parent_handle = SESSION_INVALID_HANDLE, \
92 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
93 #define session_endpoint_to_transport_cfg(_sep) \
94 ((transport_endpoint_cfg_t *)_sep)
97 session_endpoint_fib_proto (session_endpoint_t * sep)
99 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
103 session_endpoint_is_local (session_endpoint_t * sep)
105 return (ip_is_zero (&sep->ip, sep->is_ip4)
106 || ip_is_local_host (&sep->ip, sep->is_ip4));
110 session_endpoint_is_zero (session_endpoint_t * sep)
112 return ip_is_zero (&sep->ip, sep->is_ip4);
115 typedef u8 session_type_t;
116 typedef u64 session_handle_t;
120 SESSION_CLEANUP_TRANSPORT,
121 SESSION_CLEANUP_SESSION,
122 } session_cleanup_ntf_t;
127 #define foreach_session_state \
128 _(CREATED, "created") \
129 _(LISTENING, "listening") \
130 _(CONNECTING, "connecting") \
131 _(ACCEPTING, "accepting") \
133 _(OPENED, "opened") \
134 _(TRANSPORT_CLOSING, "transport-closing") \
135 _(CLOSING, "closing") \
136 _(APP_CLOSED, "app-closed") \
137 _(TRANSPORT_CLOSED, "transport-closed") \
138 _(TRANSPORT_DELETED, "transport-deleted") \
139 _(CLOSED, "closed") \
143 #define _(sym, str) SESSION_STATE_ ## sym,
144 foreach_session_state
149 typedef enum session_flags_
151 SESSION_F_RX_EVT = 1,
152 SESSION_F_PROXY = (1 << 1),
153 SESSION_F_CUSTOM_TX = (1 << 2),
154 SESSION_F_IS_MIGRATING = (1 << 3),
157 typedef struct session_
159 /** Pointers to rx/tx buffers. Once allocated, these do not move */
163 /** Type built from transport and network protocol types */
164 session_type_t session_type;
166 /** State in session layer state machine. See @ref session_state_t */
167 volatile u8 session_state;
169 /** Index in thread pool where session was allocated */
172 /** Index of the app worker that owns the session */
175 /** Index of the thread that allocated the session */
178 /** Session flags. See @ref session_flags_t */
181 /** Index of the transport connection associated to the session */
182 u32 connection_index;
184 /** Index of application that owns the listener. Set only if a listener */
189 /** Parent listener session index if the result of an accept */
190 session_handle_t listener_handle;
192 /** App listener index in app's listener pool if a listener */
196 /** Opaque, for general use */
199 CLIB_CACHE_LINE_ALIGN_MARK (pad);
202 always_inline session_type_t
203 session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
205 return (proto << 1 | is_ip4);
208 always_inline transport_proto_t
209 session_type_transport_proto (session_type_t st)
215 session_type_is_ip4 (session_type_t st)
220 always_inline transport_proto_t
221 session_get_transport_proto (session_t * s)
223 return (s->session_type >> 1);
226 always_inline fib_protocol_t
227 session_get_fib_proto (session_t * s)
229 u8 is_ip4 = s->session_type & 1;
230 return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
234 session_has_transport (session_t * s)
236 return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
239 static inline transport_service_type_t
240 session_transport_service_type (session_t * s)
242 transport_proto_t tp;
243 tp = session_get_transport_proto (s);
244 return transport_protocol_service_type (tp);
247 static inline transport_tx_fn_type_t
248 session_transport_tx_fn_type (session_t * s)
250 transport_proto_t tp;
251 tp = session_get_transport_proto (s);
252 return transport_protocol_tx_fn_type (tp);
256 session_tx_is_dgram (session_t * s)
258 return (session_transport_tx_fn_type (s) == TRANSPORT_TX_DGRAM);
261 always_inline session_handle_t
262 session_handle (session_t * s)
264 return ((u64) s->thread_index << 32) | (u64) s->session_index;
268 session_index_from_handle (session_handle_t handle)
270 return handle & 0xFFFFFFFF;
274 session_thread_from_handle (session_handle_t handle)
280 session_parse_handle (session_handle_t handle, u32 * index,
283 *index = session_index_from_handle (handle);
284 *thread_index = session_thread_from_handle (handle);
287 static inline session_handle_t
288 session_make_handle (u32 session_index, u32 thread_index)
290 return (((u64) thread_index << 32) | (u64) session_index);
297 SESSION_IO_EVT_TX_FLUSH,
298 SESSION_IO_EVT_BUILTIN_RX,
299 SESSION_IO_EVT_BUILTIN_TX,
300 SESSION_CTRL_EVT_RPC,
301 SESSION_CTRL_EVT_CLOSE,
302 SESSION_CTRL_EVT_RESET,
303 SESSION_CTRL_EVT_BOUND,
304 SESSION_CTRL_EVT_UNLISTEN_REPLY,
305 SESSION_CTRL_EVT_ACCEPTED,
306 SESSION_CTRL_EVT_ACCEPTED_REPLY,
307 SESSION_CTRL_EVT_CONNECTED,
308 SESSION_CTRL_EVT_DISCONNECTED,
309 SESSION_CTRL_EVT_DISCONNECTED_REPLY,
310 SESSION_CTRL_EVT_RESET_REPLY,
311 SESSION_CTRL_EVT_REQ_WORKER_UPDATE,
312 SESSION_CTRL_EVT_WORKER_UPDATE,
313 SESSION_CTRL_EVT_WORKER_UPDATE_REPLY,
314 SESSION_CTRL_EVT_DISCONNECT,
315 SESSION_CTRL_EVT_CONNECT,
316 SESSION_CTRL_EVT_CONNECT_URI,
317 SESSION_CTRL_EVT_LISTEN,
318 SESSION_CTRL_EVT_LISTEN_URI,
319 SESSION_CTRL_EVT_UNLISTEN,
320 SESSION_CTRL_EVT_APP_DETACH,
321 } session_evt_type_t;
323 #define foreach_session_ctrl_evt \
325 _(LISTEN_URI, listen_uri) \
327 _(UNLISTEN, unlisten) \
328 _(UNLISTEN_REPLY, unlisten_reply) \
329 _(ACCEPTED, accepted) \
330 _(ACCEPTED_REPLY, accepted_reply) \
331 _(CONNECT, connect) \
332 _(CONNECT_URI, connect_uri) \
333 _(CONNECTED, connected) \
334 _(DISCONNECT, disconnect) \
335 _(DISCONNECTED, disconnected) \
336 _(DISCONNECTED_REPLY, disconnected_reply) \
337 _(RESET_REPLY, reset_reply) \
338 _(REQ_WORKER_UPDATE, req_worker_update) \
339 _(WORKER_UPDATE, worker_update) \
340 _(WORKER_UPDATE_REPLY, worker_update_reply) \
341 _(APP_DETACH, app_detach) \
344 /* Deprecated and will be removed. Use types above */
345 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
346 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
347 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
348 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
349 #define FIFO_EVENT_BUILTIN_TX SESSION_IO_EVT_BUILTIN_TX
353 SESSION_MQ_IO_EVT_RING,
354 SESSION_MQ_CTRL_EVT_RING,
356 } session_mq_rings_e;
362 } session_rpc_args_t;
371 session_handle_t session_handle;
372 session_rpc_args_t rpc_args;
379 } __clib_packed session_event_t;
381 #define SESSION_MSG_NULL { }
383 typedef struct session_dgram_pre_hdr_
387 } session_dgram_pre_hdr_t;
389 typedef struct session_dgram_header_
393 ip46_address_t rmt_ip;
394 ip46_address_t lcl_ip;
398 } __clib_packed session_dgram_hdr_t;
400 #define SESSION_CONN_ID_LEN 37
401 #define SESSION_CONN_HDR_LEN 45
403 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
404 "session conn id wrong length");
405 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
408 * fd.io coding-style-patch-verification: ON
411 * eval: (c-set-style "gnu")