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 86
25 #define SESSION_NODE_FRAME_SIZE 128
27 #define foreach_session_endpoint_fields \
28 foreach_transport_endpoint_cfg_fields \
29 _(u8, transport_proto) \
31 typedef struct _session_endpoint
33 #define _(type, name) type name;
34 foreach_session_endpoint_fields
38 typedef struct _session_endpoint_cfg
40 #define _(type, name) type name;
41 foreach_session_endpoint_fields
52 transport_endpt_ext_cfg_t *ext_cfg;
53 } session_endpoint_cfg_t;
55 #define SESSION_IP46_ZERO \
62 #define TRANSPORT_ENDPOINT_NULL \
64 .sw_if_index = ENDPOINT_INVALID_INDEX, \
65 .ip = SESSION_IP46_ZERO, \
66 .fib_index = ENDPOINT_INVALID_INDEX, \
70 #define SESSION_ENDPOINT_NULL \
72 .sw_if_index = ENDPOINT_INVALID_INDEX, \
73 .ip = SESSION_IP46_ZERO, \
74 .fib_index = ENDPOINT_INVALID_INDEX, \
77 .peer = TRANSPORT_ENDPOINT_NULL, \
78 .transport_proto = 0, \
80 #define SESSION_ENDPOINT_CFG_NULL \
82 .sw_if_index = ENDPOINT_INVALID_INDEX, .ip = SESSION_IP46_ZERO, \
83 .fib_index = ENDPOINT_INVALID_INDEX, .is_ip4 = 0, .port = 0, \
84 .peer = TRANSPORT_ENDPOINT_NULL, .transport_proto = 0, \
85 .app_wrk_index = ENDPOINT_INVALID_INDEX, \
86 .opaque = ENDPOINT_INVALID_INDEX, .hostname = 0, \
87 .parent_handle = SESSION_INVALID_HANDLE, .ckpair_index = 0, .ext_cfg = 0, \
90 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
91 #define session_endpoint_to_transport_cfg(_sep) \
92 ((transport_endpoint_cfg_t *)_sep)
95 session_endpoint_fib_proto (session_endpoint_t * sep)
97 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
101 session_endpoint_is_local (session_endpoint_t * sep)
103 return (ip_is_zero (&sep->ip, sep->is_ip4)
104 || ip_is_local_host (&sep->ip, sep->is_ip4));
108 session_endpoint_is_zero (session_endpoint_t * sep)
110 return ip_is_zero (&sep->ip, sep->is_ip4);
113 typedef u8 session_type_t;
114 typedef u64 session_handle_t;
118 SESSION_CLEANUP_TRANSPORT,
119 SESSION_CLEANUP_SESSION,
120 } session_cleanup_ntf_t;
122 typedef enum session_ft_action_
124 SESSION_FT_ACTION_ENQUEUED,
125 SESSION_FT_ACTION_DEQUEUED,
126 SESSION_FT_ACTION_N_ACTIONS
127 } session_ft_action_t;
132 #define foreach_session_state \
133 _(CREATED, "created") \
134 _(LISTENING, "listening") \
135 _(CONNECTING, "connecting") \
136 _(ACCEPTING, "accepting") \
138 _(OPENED, "opened") \
139 _(TRANSPORT_CLOSING, "transport-closing") \
140 _(CLOSING, "closing") \
141 _(APP_CLOSED, "app-closed") \
142 _(TRANSPORT_CLOSED, "transport-closed") \
143 _(CLOSED, "closed") \
144 _(TRANSPORT_DELETED, "transport-deleted") \
148 #define _(sym, str) SESSION_STATE_ ## sym,
149 foreach_session_state
154 #define foreach_session_flag \
155 _(RX_EVT, "rx-event") \
157 _(CUSTOM_TX, "custom-tx") \
158 _(IS_MIGRATING, "migrating") \
159 _(UNIDIRECTIONAL, "unidirectional") \
160 _(CUSTOM_FIFO_TUNING, "custom-fifo-tuning") \
162 typedef enum session_flags_bits_
164 #define _(sym, str) SESSION_F_BIT_ ## sym,
168 } session_flag_bits_t;
170 typedef enum session_flags_
172 #define _(sym, str) SESSION_F_ ## sym = 1 << SESSION_F_BIT_ ## sym,
177 typedef struct session_
179 /** Pointers to rx/tx buffers. Once allocated, these do not move */
183 /** Type built from transport and network protocol types */
184 session_type_t session_type;
186 /** State in session layer state machine. See @ref session_state_t */
187 volatile u8 session_state;
189 /** Index in thread pool where session was allocated */
192 /** Index of the app worker that owns the session */
195 /** Index of the thread that allocated the session */
198 /** Session flags. See @ref session_flags_t */
201 /** Index of the transport connection associated to the session */
202 u32 connection_index;
204 /** Index of application that owns the listener. Set only if a listener */
209 /** Parent listener session index if the result of an accept */
210 session_handle_t listener_handle;
212 /** App listener index in app's listener pool if a listener */
216 /** Opaque, for general use */
219 CLIB_CACHE_LINE_ALIGN_MARK (pad);
222 always_inline session_type_t
223 session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
225 return (proto << 1 | is_ip4);
228 always_inline transport_proto_t
229 session_type_transport_proto (session_type_t st)
235 session_type_is_ip4 (session_type_t st)
240 always_inline transport_proto_t
241 session_get_transport_proto (session_t * s)
243 return (s->session_type >> 1);
246 always_inline fib_protocol_t
247 session_get_fib_proto (session_t * s)
249 u8 is_ip4 = s->session_type & 1;
250 return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
254 session_has_transport (session_t * s)
256 return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
259 static inline transport_service_type_t
260 session_transport_service_type (session_t * s)
262 transport_proto_t tp;
263 tp = session_get_transport_proto (s);
264 return transport_protocol_service_type (tp);
267 static inline transport_tx_fn_type_t
268 session_transport_tx_fn_type (session_t * s)
270 transport_proto_t tp;
271 tp = session_get_transport_proto (s);
272 return transport_protocol_tx_fn_type (tp);
276 session_tx_is_dgram (session_t * s)
278 return (session_transport_tx_fn_type (s) == TRANSPORT_TX_DGRAM);
281 always_inline session_handle_t
282 session_handle (session_t * s)
284 return ((u64) s->thread_index << 32) | (u64) s->session_index;
288 session_index_from_handle (session_handle_t handle)
290 return handle & 0xFFFFFFFF;
294 session_thread_from_handle (session_handle_t handle)
300 session_parse_handle (session_handle_t handle, u32 * index,
303 *index = session_index_from_handle (handle);
304 *thread_index = session_thread_from_handle (handle);
307 static inline session_handle_t
308 session_make_handle (u32 session_index, u32 data)
310 return (((u64) data << 32) | (u64) session_index);
314 session_handle_index (session_handle_t ho_handle)
316 return (ho_handle & 0xffffffff);
320 session_handle_data (session_handle_t ho_handle)
322 return (ho_handle >> 32);
329 SESSION_IO_EVT_TX_FLUSH,
330 SESSION_IO_EVT_BUILTIN_RX,
331 SESSION_IO_EVT_BUILTIN_TX,
332 SESSION_CTRL_EVT_RPC,
333 SESSION_CTRL_EVT_CLOSE,
334 SESSION_CTRL_EVT_RESET,
335 SESSION_CTRL_EVT_BOUND,
336 SESSION_CTRL_EVT_UNLISTEN_REPLY,
337 SESSION_CTRL_EVT_ACCEPTED,
338 SESSION_CTRL_EVT_ACCEPTED_REPLY,
339 SESSION_CTRL_EVT_CONNECTED,
340 SESSION_CTRL_EVT_DISCONNECTED,
341 SESSION_CTRL_EVT_DISCONNECTED_REPLY,
342 SESSION_CTRL_EVT_RESET_REPLY,
343 SESSION_CTRL_EVT_REQ_WORKER_UPDATE,
344 SESSION_CTRL_EVT_WORKER_UPDATE,
345 SESSION_CTRL_EVT_WORKER_UPDATE_REPLY,
346 SESSION_CTRL_EVT_DISCONNECT,
347 SESSION_CTRL_EVT_CONNECT,
348 SESSION_CTRL_EVT_CONNECT_URI,
349 SESSION_CTRL_EVT_LISTEN,
350 SESSION_CTRL_EVT_LISTEN_URI,
351 SESSION_CTRL_EVT_UNLISTEN,
352 SESSION_CTRL_EVT_APP_DETACH,
353 SESSION_CTRL_EVT_APP_ADD_SEGMENT,
354 SESSION_CTRL_EVT_APP_DEL_SEGMENT,
355 SESSION_CTRL_EVT_MIGRATED,
356 SESSION_CTRL_EVT_CLEANUP,
357 SESSION_CTRL_EVT_APP_WRK_RPC,
358 SESSION_CTRL_EVT_TRANSPORT_ATTR,
359 SESSION_CTRL_EVT_TRANSPORT_ATTR_REPLY,
360 } session_evt_type_t;
362 #define foreach_session_ctrl_evt \
364 _ (LISTEN_URI, listen_uri) \
366 _ (UNLISTEN, unlisten) \
367 _ (UNLISTEN_REPLY, unlisten_reply) \
368 _ (ACCEPTED, accepted) \
369 _ (ACCEPTED_REPLY, accepted_reply) \
370 _ (CONNECT, connect) \
371 _ (CONNECT_URI, connect_uri) \
372 _ (CONNECTED, connected) \
373 _ (DISCONNECT, disconnect) \
374 _ (DISCONNECTED, disconnected) \
375 _ (DISCONNECTED_REPLY, disconnected_reply) \
376 _ (RESET_REPLY, reset_reply) \
377 _ (REQ_WORKER_UPDATE, req_worker_update) \
378 _ (WORKER_UPDATE, worker_update) \
379 _ (WORKER_UPDATE_REPLY, worker_update_reply) \
380 _ (APP_DETACH, app_detach) \
381 _ (APP_ADD_SEGMENT, app_add_segment) \
382 _ (APP_DEL_SEGMENT, app_del_segment) \
383 _ (MIGRATED, migrated) \
384 _ (CLEANUP, cleanup) \
385 _ (APP_WRK_RPC, app_wrk_rpc) \
386 _ (TRANSPORT_ATTR, transport_attr) \
387 _ (TRANSPORT_ATTR_REPLY, transport_attr_reply) \
388 /* Deprecated and will be removed. Use types above */
389 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
390 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
391 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
392 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
393 #define FIFO_EVENT_BUILTIN_TX SESSION_IO_EVT_BUILTIN_TX
397 SESSION_MQ_IO_EVT_RING,
398 SESSION_MQ_CTRL_EVT_RING,
400 } session_mq_rings_e;
406 } session_rpc_args_t;
415 session_handle_t session_handle;
416 session_rpc_args_t rpc_args;
423 } __clib_packed session_event_t;
425 #define SESSION_MSG_NULL { }
427 typedef struct session_dgram_pre_hdr_
431 } session_dgram_pre_hdr_t;
433 typedef struct session_dgram_header_
437 ip46_address_t rmt_ip;
438 ip46_address_t lcl_ip;
442 } __clib_packed session_dgram_hdr_t;
444 #define SESSION_CONN_ID_LEN 37
445 #define SESSION_CONN_HDR_LEN 45
447 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
448 "session conn id wrong length");
450 #define foreach_session_error \
451 _ (NONE, "no error") \
452 _ (UNKNOWN, "generic/unknown error") \
453 _ (REFUSED, "refused") \
454 _ (TIMEDOUT, "timedout") \
455 _ (ALLOC, "obj/memory allocation error") \
456 _ (OWNER, "object not owned by application") \
457 _ (NOROUTE, "no route") \
458 _ (NOINTF, "no resolving interface") \
459 _ (NOIP, "no ip for lcl interface") \
460 _ (NOPORT, "no lcl port") \
461 _ (NOSUPPORT, "not supported") \
462 _ (NOLISTEN, "not listening") \
463 _ (NOSESSION, "session does not exist") \
464 _ (NOAPP, "app not attached") \
465 _ (PORTINUSE, "lcl port in use") \
466 _ (IPINUSE, "ip in use") \
467 _ (ALREADY_LISTENING, "ip port pair already listened on") \
468 _ (INVALID_RMT_IP, "invalid remote ip") \
469 _ (INVALID_APPWRK, "invalid app worker") \
470 _ (INVALID_NS, "invalid namespace") \
471 _ (SEG_NO_SPACE, "Couldn't allocate a fifo pair") \
472 _ (SEG_NO_SPACE2, "Created segment, couldn't allocate a fifo pair") \
473 _ (SEG_CREATE, "Couldn't create a new segment") \
474 _ (FILTERED, "session filtered") \
475 _ (SCOPE, "scope not supported") \
476 _ (BAPI_NO_FD, "bapi doesn't have a socket fd") \
477 _ (BAPI_SEND_FD, "couldn't send fd over bapi socket fd") \
478 _ (BAPI_NO_REG, "app bapi registration not found") \
479 _ (MQ_MSG_ALLOC, "failed to alloc mq msg") \
480 _ (TLS_HANDSHAKE, "failed tls handshake") \
481 _ (EVENTFD_ALLOC, "failed to alloc eventfd")
483 typedef enum session_error_p_
485 #define _(sym, str) SESSION_EP_##sym,
486 foreach_session_error
491 typedef enum session_error_
493 #define _(sym, str) SESSION_E_##sym = -SESSION_EP_##sym,
494 foreach_session_error
498 #define SESSION_CLI_ID_LEN "60"
499 #define SESSION_CLI_STATE_LEN "15"
501 /* Maintained for compatibility. Will be deprecated */
502 #define SESSION_ERROR_SEG_CREATE SESSION_E_SEG_CREATE
503 #define SESSION_ERROR_NO_SPACE SESSION_E_SEG_NO_SPACE
504 #define SESSION_ERROR_NEW_SEG_NO_SPACE SESSION_E_SEG_NO_SPACE2
506 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
509 * fd.io coding-style-patch-verification: ON
512 * eval: (c-set-style "gnu")