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 } session_endpoint_cfg_t;
54 #define SESSION_IP46_ZERO \
61 #define TRANSPORT_ENDPOINT_NULL \
63 .sw_if_index = ENDPOINT_INVALID_INDEX, \
64 .ip = SESSION_IP46_ZERO, \
65 .fib_index = ENDPOINT_INVALID_INDEX, \
69 #define SESSION_ENDPOINT_NULL \
71 .sw_if_index = ENDPOINT_INVALID_INDEX, \
72 .ip = SESSION_IP46_ZERO, \
73 .fib_index = ENDPOINT_INVALID_INDEX, \
76 .peer = TRANSPORT_ENDPOINT_NULL, \
77 .transport_proto = 0, \
79 #define SESSION_ENDPOINT_CFG_NULL \
81 .sw_if_index = ENDPOINT_INVALID_INDEX, \
82 .ip = SESSION_IP46_ZERO, \
83 .fib_index = ENDPOINT_INVALID_INDEX, \
86 .peer = TRANSPORT_ENDPOINT_NULL, \
87 .transport_proto = 0, \
88 .app_wrk_index = ENDPOINT_INVALID_INDEX, \
89 .opaque = ENDPOINT_INVALID_INDEX, \
91 .parent_handle = SESSION_INVALID_HANDLE, \
95 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
96 #define session_endpoint_to_transport_cfg(_sep) \
97 ((transport_endpoint_cfg_t *)_sep)
100 session_endpoint_fib_proto (session_endpoint_t * sep)
102 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
106 session_endpoint_is_local (session_endpoint_t * sep)
108 return (ip_is_zero (&sep->ip, sep->is_ip4)
109 || ip_is_local_host (&sep->ip, sep->is_ip4));
113 session_endpoint_is_zero (session_endpoint_t * sep)
115 return ip_is_zero (&sep->ip, sep->is_ip4);
118 typedef u8 session_type_t;
119 typedef u64 session_handle_t;
123 SESSION_CLEANUP_TRANSPORT,
124 SESSION_CLEANUP_SESSION,
125 } session_cleanup_ntf_t;
127 typedef enum session_ft_action_
129 SESSION_FT_ACTION_ENQUEUED,
130 SESSION_FT_ACTION_DEQUEUED,
131 SESSION_FT_ACTION_N_ACTIONS
132 } session_ft_action_t;
137 #define foreach_session_state \
138 _(CREATED, "created") \
139 _(LISTENING, "listening") \
140 _(CONNECTING, "connecting") \
141 _(ACCEPTING, "accepting") \
143 _(OPENED, "opened") \
144 _(TRANSPORT_CLOSING, "transport-closing") \
145 _(CLOSING, "closing") \
146 _(APP_CLOSED, "app-closed") \
147 _(TRANSPORT_CLOSED, "transport-closed") \
148 _(CLOSED, "closed") \
149 _(TRANSPORT_DELETED, "transport-deleted") \
153 #define _(sym, str) SESSION_STATE_ ## sym,
154 foreach_session_state
159 #define foreach_session_flag \
160 _(RX_EVT, "rx-event") \
162 _(CUSTOM_TX, "custom-tx") \
163 _(IS_MIGRATING, "migrating") \
164 _(UNIDIRECTIONAL, "unidirectional") \
165 _(CUSTOM_FIFO_TUNING, "custom-fifo-tuning") \
167 typedef enum session_flags_bits_
169 #define _(sym, str) SESSION_F_BIT_ ## sym,
173 } session_flag_bits_t;
175 typedef enum session_flags_
177 #define _(sym, str) SESSION_F_ ## sym = 1 << SESSION_F_BIT_ ## sym,
182 typedef struct session_
184 /** Pointers to rx/tx buffers. Once allocated, these do not move */
188 /** Type built from transport and network protocol types */
189 session_type_t session_type;
191 /** State in session layer state machine. See @ref session_state_t */
192 volatile u8 session_state;
194 /** Index in thread pool where session was allocated */
197 /** Index of the app worker that owns the session */
200 /** Index of the thread that allocated the session */
203 /** Session flags. See @ref session_flags_t */
206 /** Index of the transport connection associated to the session */
207 u32 connection_index;
209 /** Index of application that owns the listener. Set only if a listener */
214 /** Parent listener session index if the result of an accept */
215 session_handle_t listener_handle;
217 /** App listener index in app's listener pool if a listener */
221 /** Opaque, for general use */
224 CLIB_CACHE_LINE_ALIGN_MARK (pad);
227 always_inline session_type_t
228 session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
230 return (proto << 1 | is_ip4);
233 always_inline transport_proto_t
234 session_type_transport_proto (session_type_t st)
240 session_type_is_ip4 (session_type_t st)
245 always_inline transport_proto_t
246 session_get_transport_proto (session_t * s)
248 return (s->session_type >> 1);
251 always_inline fib_protocol_t
252 session_get_fib_proto (session_t * s)
254 u8 is_ip4 = s->session_type & 1;
255 return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
259 session_has_transport (session_t * s)
261 return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
264 static inline transport_service_type_t
265 session_transport_service_type (session_t * s)
267 transport_proto_t tp;
268 tp = session_get_transport_proto (s);
269 return transport_protocol_service_type (tp);
272 static inline transport_tx_fn_type_t
273 session_transport_tx_fn_type (session_t * s)
275 transport_proto_t tp;
276 tp = session_get_transport_proto (s);
277 return transport_protocol_tx_fn_type (tp);
281 session_tx_is_dgram (session_t * s)
283 return (session_transport_tx_fn_type (s) == TRANSPORT_TX_DGRAM);
286 always_inline session_handle_t
287 session_handle (session_t * s)
289 return ((u64) s->thread_index << 32) | (u64) s->session_index;
293 session_index_from_handle (session_handle_t handle)
295 return handle & 0xFFFFFFFF;
299 session_thread_from_handle (session_handle_t handle)
305 session_parse_handle (session_handle_t handle, u32 * index,
308 *index = session_index_from_handle (handle);
309 *thread_index = session_thread_from_handle (handle);
312 static inline session_handle_t
313 session_make_handle (u32 session_index, u32 data)
315 return (((u64) data << 32) | (u64) session_index);
319 session_handle_index (session_handle_t ho_handle)
321 return (ho_handle & 0xffffffff);
325 session_handle_data (session_handle_t ho_handle)
327 return (ho_handle >> 32);
334 SESSION_IO_EVT_TX_FLUSH,
335 SESSION_IO_EVT_BUILTIN_RX,
336 SESSION_IO_EVT_BUILTIN_TX,
337 SESSION_CTRL_EVT_RPC,
338 SESSION_CTRL_EVT_CLOSE,
339 SESSION_CTRL_EVT_RESET,
340 SESSION_CTRL_EVT_BOUND,
341 SESSION_CTRL_EVT_UNLISTEN_REPLY,
342 SESSION_CTRL_EVT_ACCEPTED,
343 SESSION_CTRL_EVT_ACCEPTED_REPLY,
344 SESSION_CTRL_EVT_CONNECTED,
345 SESSION_CTRL_EVT_DISCONNECTED,
346 SESSION_CTRL_EVT_DISCONNECTED_REPLY,
347 SESSION_CTRL_EVT_RESET_REPLY,
348 SESSION_CTRL_EVT_REQ_WORKER_UPDATE,
349 SESSION_CTRL_EVT_WORKER_UPDATE,
350 SESSION_CTRL_EVT_WORKER_UPDATE_REPLY,
351 SESSION_CTRL_EVT_DISCONNECT,
352 SESSION_CTRL_EVT_CONNECT,
353 SESSION_CTRL_EVT_CONNECT_URI,
354 SESSION_CTRL_EVT_LISTEN,
355 SESSION_CTRL_EVT_LISTEN_URI,
356 SESSION_CTRL_EVT_UNLISTEN,
357 SESSION_CTRL_EVT_APP_DETACH,
358 SESSION_CTRL_EVT_APP_ADD_SEGMENT,
359 SESSION_CTRL_EVT_APP_DEL_SEGMENT,
360 SESSION_CTRL_EVT_MIGRATED,
361 SESSION_CTRL_EVT_CLEANUP,
362 SESSION_CTRL_EVT_APP_WRK_RPC,
363 SESSION_CTRL_EVT_TRANSPORT_ATTR,
364 SESSION_CTRL_EVT_TRANSPORT_ATTR_REPLY,
365 } session_evt_type_t;
367 #define foreach_session_ctrl_evt \
369 _ (LISTEN_URI, listen_uri) \
371 _ (UNLISTEN, unlisten) \
372 _ (UNLISTEN_REPLY, unlisten_reply) \
373 _ (ACCEPTED, accepted) \
374 _ (ACCEPTED_REPLY, accepted_reply) \
375 _ (CONNECT, connect) \
376 _ (CONNECT_URI, connect_uri) \
377 _ (CONNECTED, connected) \
378 _ (DISCONNECT, disconnect) \
379 _ (DISCONNECTED, disconnected) \
380 _ (DISCONNECTED_REPLY, disconnected_reply) \
381 _ (RESET_REPLY, reset_reply) \
382 _ (REQ_WORKER_UPDATE, req_worker_update) \
383 _ (WORKER_UPDATE, worker_update) \
384 _ (WORKER_UPDATE_REPLY, worker_update_reply) \
385 _ (APP_DETACH, app_detach) \
386 _ (APP_ADD_SEGMENT, app_add_segment) \
387 _ (APP_DEL_SEGMENT, app_del_segment) \
388 _ (MIGRATED, migrated) \
389 _ (CLEANUP, cleanup) \
390 _ (APP_WRK_RPC, app_wrk_rpc) \
391 _ (TRANSPORT_ATTR, transport_attr) \
392 _ (TRANSPORT_ATTR_REPLY, transport_attr_reply) \
393 /* Deprecated and will be removed. Use types above */
394 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
395 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
396 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
397 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
398 #define FIFO_EVENT_BUILTIN_TX SESSION_IO_EVT_BUILTIN_TX
402 SESSION_MQ_IO_EVT_RING,
403 SESSION_MQ_CTRL_EVT_RING,
405 } session_mq_rings_e;
411 } session_rpc_args_t;
420 session_handle_t session_handle;
421 session_rpc_args_t rpc_args;
428 } __clib_packed session_event_t;
430 #define SESSION_MSG_NULL { }
432 typedef struct session_dgram_pre_hdr_
436 } session_dgram_pre_hdr_t;
438 typedef struct session_dgram_header_
442 ip46_address_t rmt_ip;
443 ip46_address_t lcl_ip;
447 } __clib_packed session_dgram_hdr_t;
449 #define SESSION_CONN_ID_LEN 37
450 #define SESSION_CONN_HDR_LEN 45
452 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
453 "session conn id wrong length");
455 #define foreach_session_error \
456 _ (NONE, "no error") \
457 _ (UNKNOWN, "generic/unknown error") \
458 _ (REFUSED, "refused") \
459 _ (TIMEDOUT, "timedout") \
460 _ (ALLOC, "obj/memory allocation error") \
461 _ (OWNER, "object not owned by application") \
462 _ (NOROUTE, "no route") \
463 _ (NOINTF, "no resolving interface") \
464 _ (NOIP, "no ip for lcl interface") \
465 _ (NOPORT, "no lcl port") \
466 _ (NOSUPPORT, "not supported") \
467 _ (NOLISTEN, "not listening") \
468 _ (NOSESSION, "session does not exist") \
469 _ (NOAPP, "app not attached") \
470 _ (PORTINUSE, "lcl port in use") \
471 _ (IPINUSE, "ip in use") \
472 _ (ALREADY_LISTENING, "ip port pair already listened on") \
473 _ (INVALID_RMT_IP, "invalid remote ip") \
474 _ (INVALID_APPWRK, "invalid app worker") \
475 _ (INVALID_NS, "invalid namespace") \
476 _ (SEG_NO_SPACE, "Couldn't allocate a fifo pair") \
477 _ (SEG_NO_SPACE2, "Created segment, couldn't allocate a fifo pair") \
478 _ (SEG_CREATE, "Couldn't create a new segment") \
479 _ (FILTERED, "session filtered") \
480 _ (SCOPE, "scope not supported") \
481 _ (BAPI_NO_FD, "bapi doesn't have a socket fd") \
482 _ (BAPI_SEND_FD, "couldn't send fd over bapi socket fd") \
483 _ (BAPI_NO_REG, "app bapi registration not found") \
484 _ (MQ_MSG_ALLOC, "failed to alloc mq msg") \
485 _ (TLS_HANDSHAKE, "failed tls handshake") \
486 _ (EVENTFD_ALLOC, "failed to alloc eventfd")
488 typedef enum session_error_p_
490 #define _(sym, str) SESSION_EP_##sym,
491 foreach_session_error
496 typedef enum session_error_
498 #define _(sym, str) SESSION_E_##sym = -SESSION_EP_##sym,
499 foreach_session_error
503 #define SESSION_CLI_ID_LEN "60"
504 #define SESSION_CLI_STATE_LEN "15"
506 /* Maintained for compatibility. Will be deprecated */
507 #define SESSION_ERROR_SEG_CREATE SESSION_E_SEG_CREATE
508 #define SESSION_ERROR_NO_SPACE SESSION_E_SEG_NO_SPACE
509 #define SESSION_ERROR_NEW_SEG_NO_SPACE SESSION_E_SEG_NO_SPACE2
511 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
514 * fd.io coding-style-patch-verification: ON
517 * eval: (c-set-style "gnu")