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
51 } session_endpoint_cfg_t;
53 #define SESSION_IP46_ZERO \
60 #define TRANSPORT_ENDPOINT_NULL \
62 .sw_if_index = ENDPOINT_INVALID_INDEX, \
63 .ip = SESSION_IP46_ZERO, \
64 .fib_index = ENDPOINT_INVALID_INDEX, \
68 #define SESSION_ENDPOINT_NULL \
70 .sw_if_index = ENDPOINT_INVALID_INDEX, \
71 .ip = SESSION_IP46_ZERO, \
72 .fib_index = ENDPOINT_INVALID_INDEX, \
75 .peer = TRANSPORT_ENDPOINT_NULL, \
76 .transport_proto = 0, \
78 #define SESSION_ENDPOINT_CFG_NULL \
80 .sw_if_index = ENDPOINT_INVALID_INDEX, \
81 .ip = SESSION_IP46_ZERO, \
82 .fib_index = ENDPOINT_INVALID_INDEX, \
85 .peer = TRANSPORT_ENDPOINT_NULL, \
86 .transport_proto = 0, \
87 .app_wrk_index = ENDPOINT_INVALID_INDEX, \
88 .opaque = ENDPOINT_INVALID_INDEX, \
90 .parent_handle = SESSION_INVALID_HANDLE, \
94 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
95 #define session_endpoint_to_transport_cfg(_sep) \
96 ((transport_endpoint_cfg_t *)_sep)
99 session_endpoint_fib_proto (session_endpoint_t * sep)
101 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
105 session_endpoint_is_local (session_endpoint_t * sep)
107 return (ip_is_zero (&sep->ip, sep->is_ip4)
108 || ip_is_local_host (&sep->ip, sep->is_ip4));
112 session_endpoint_is_zero (session_endpoint_t * sep)
114 return ip_is_zero (&sep->ip, sep->is_ip4);
117 typedef u8 session_type_t;
118 typedef u64 session_handle_t;
122 SESSION_CLEANUP_TRANSPORT,
123 SESSION_CLEANUP_SESSION,
124 } session_cleanup_ntf_t;
126 typedef enum session_ft_action_
128 SESSION_FT_ACTION_ENQUEUED,
129 SESSION_FT_ACTION_DEQUEUED,
130 SESSION_FT_ACTION_N_ACTIONS
131 } session_ft_action_t;
136 #define foreach_session_state \
137 _(CREATED, "created") \
138 _(LISTENING, "listening") \
139 _(CONNECTING, "connecting") \
140 _(ACCEPTING, "accepting") \
142 _(OPENED, "opened") \
143 _(TRANSPORT_CLOSING, "transport-closing") \
144 _(CLOSING, "closing") \
145 _(APP_CLOSED, "app-closed") \
146 _(TRANSPORT_CLOSED, "transport-closed") \
147 _(CLOSED, "closed") \
148 _(TRANSPORT_DELETED, "transport-deleted") \
152 #define _(sym, str) SESSION_STATE_ ## sym,
153 foreach_session_state
158 #define foreach_session_flag \
159 _(RX_EVT, "rx-event") \
161 _(CUSTOM_TX, "custom-tx") \
162 _(IS_MIGRATING, "migrating") \
163 _(UNIDIRECTIONAL, "unidirectional") \
164 _(CUSTOM_FIFO_TUNING, "custom-fifo-tuning") \
166 typedef enum session_flags_bits_
168 #define _(sym, str) SESSION_F_BIT_ ## sym,
172 } session_flag_bits_t;
174 typedef enum session_flags_
176 #define _(sym, str) SESSION_F_ ## sym = 1 << SESSION_F_BIT_ ## sym,
181 typedef struct session_
183 /** Pointers to rx/tx buffers. Once allocated, these do not move */
187 /** Type built from transport and network protocol types */
188 session_type_t session_type;
190 /** State in session layer state machine. See @ref session_state_t */
191 volatile u8 session_state;
193 /** Index in thread pool where session was allocated */
196 /** Index of the app worker that owns the session */
199 /** Index of the thread that allocated the session */
202 /** Session flags. See @ref session_flags_t */
205 /** Index of the transport connection associated to the session */
206 u32 connection_index;
208 /** Index of application that owns the listener. Set only if a listener */
213 /** Parent listener session index if the result of an accept */
214 session_handle_t listener_handle;
216 /** App listener index in app's listener pool if a listener */
220 /** Opaque, for general use */
223 CLIB_CACHE_LINE_ALIGN_MARK (pad);
226 always_inline session_type_t
227 session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
229 return (proto << 1 | is_ip4);
232 always_inline transport_proto_t
233 session_type_transport_proto (session_type_t st)
239 session_type_is_ip4 (session_type_t st)
244 always_inline transport_proto_t
245 session_get_transport_proto (session_t * s)
247 return (s->session_type >> 1);
250 always_inline fib_protocol_t
251 session_get_fib_proto (session_t * s)
253 u8 is_ip4 = s->session_type & 1;
254 return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
258 session_has_transport (session_t * s)
260 return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
263 static inline transport_service_type_t
264 session_transport_service_type (session_t * s)
266 transport_proto_t tp;
267 tp = session_get_transport_proto (s);
268 return transport_protocol_service_type (tp);
271 static inline transport_tx_fn_type_t
272 session_transport_tx_fn_type (session_t * s)
274 transport_proto_t tp;
275 tp = session_get_transport_proto (s);
276 return transport_protocol_tx_fn_type (tp);
280 session_tx_is_dgram (session_t * s)
282 return (session_transport_tx_fn_type (s) == TRANSPORT_TX_DGRAM);
285 always_inline session_handle_t
286 session_handle (session_t * s)
288 return ((u64) s->thread_index << 32) | (u64) s->session_index;
292 session_index_from_handle (session_handle_t handle)
294 return handle & 0xFFFFFFFF;
298 session_thread_from_handle (session_handle_t handle)
304 session_parse_handle (session_handle_t handle, u32 * index,
307 *index = session_index_from_handle (handle);
308 *thread_index = session_thread_from_handle (handle);
311 static inline session_handle_t
312 session_make_handle (u32 session_index, u32 thread_index)
314 return (((u64) thread_index << 32) | (u64) session_index);
321 SESSION_IO_EVT_TX_FLUSH,
322 SESSION_IO_EVT_BUILTIN_RX,
323 SESSION_IO_EVT_BUILTIN_TX,
324 SESSION_CTRL_EVT_RPC,
325 SESSION_CTRL_EVT_CLOSE,
326 SESSION_CTRL_EVT_RESET,
327 SESSION_CTRL_EVT_BOUND,
328 SESSION_CTRL_EVT_UNLISTEN_REPLY,
329 SESSION_CTRL_EVT_ACCEPTED,
330 SESSION_CTRL_EVT_ACCEPTED_REPLY,
331 SESSION_CTRL_EVT_CONNECTED,
332 SESSION_CTRL_EVT_DISCONNECTED,
333 SESSION_CTRL_EVT_DISCONNECTED_REPLY,
334 SESSION_CTRL_EVT_RESET_REPLY,
335 SESSION_CTRL_EVT_REQ_WORKER_UPDATE,
336 SESSION_CTRL_EVT_WORKER_UPDATE,
337 SESSION_CTRL_EVT_WORKER_UPDATE_REPLY,
338 SESSION_CTRL_EVT_DISCONNECT,
339 SESSION_CTRL_EVT_CONNECT,
340 SESSION_CTRL_EVT_CONNECT_URI,
341 SESSION_CTRL_EVT_LISTEN,
342 SESSION_CTRL_EVT_LISTEN_URI,
343 SESSION_CTRL_EVT_UNLISTEN,
344 SESSION_CTRL_EVT_APP_DETACH,
345 SESSION_CTRL_EVT_APP_ADD_SEGMENT,
346 SESSION_CTRL_EVT_APP_DEL_SEGMENT,
347 SESSION_CTRL_EVT_MIGRATED,
348 SESSION_CTRL_EVT_CLEANUP,
349 } session_evt_type_t;
351 #define foreach_session_ctrl_evt \
353 _(LISTEN_URI, listen_uri) \
355 _(UNLISTEN, unlisten) \
356 _(UNLISTEN_REPLY, unlisten_reply) \
357 _(ACCEPTED, accepted) \
358 _(ACCEPTED_REPLY, accepted_reply) \
359 _(CONNECT, connect) \
360 _(CONNECT_URI, connect_uri) \
361 _(CONNECTED, connected) \
362 _(DISCONNECT, disconnect) \
363 _(DISCONNECTED, disconnected) \
364 _(DISCONNECTED_REPLY, disconnected_reply) \
365 _(RESET_REPLY, reset_reply) \
366 _(REQ_WORKER_UPDATE, req_worker_update) \
367 _(WORKER_UPDATE, worker_update) \
368 _(WORKER_UPDATE_REPLY, worker_update_reply) \
369 _(APP_DETACH, app_detach) \
370 _(APP_ADD_SEGMENT, app_add_segment) \
371 _(APP_DEL_SEGMENT, app_del_segment) \
372 _(MIGRATED, migrated) \
373 _(CLEANUP, cleanup) \
375 /* Deprecated and will be removed. Use types above */
376 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
377 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
378 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
379 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
380 #define FIFO_EVENT_BUILTIN_TX SESSION_IO_EVT_BUILTIN_TX
384 SESSION_MQ_IO_EVT_RING,
385 SESSION_MQ_CTRL_EVT_RING,
387 } session_mq_rings_e;
393 } session_rpc_args_t;
402 session_handle_t session_handle;
403 session_rpc_args_t rpc_args;
410 } __clib_packed session_event_t;
412 #define SESSION_MSG_NULL { }
414 typedef struct session_dgram_pre_hdr_
418 } session_dgram_pre_hdr_t;
420 typedef struct session_dgram_header_
424 ip46_address_t rmt_ip;
425 ip46_address_t lcl_ip;
429 } __clib_packed session_dgram_hdr_t;
431 #define SESSION_CONN_ID_LEN 37
432 #define SESSION_CONN_HDR_LEN 45
434 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
435 "session conn id wrong length");
436 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
439 * fd.io coding-style-patch-verification: ON
442 * eval: (c-set-style "gnu")