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;
129 #define foreach_session_state \
130 _(CREATED, "created") \
131 _(LISTENING, "listening") \
132 _(CONNECTING, "connecting") \
133 _(ACCEPTING, "accepting") \
135 _(OPENED, "opened") \
136 _(TRANSPORT_CLOSING, "transport-closing") \
137 _(CLOSING, "closing") \
138 _(APP_CLOSED, "app-closed") \
139 _(TRANSPORT_CLOSED, "transport-closed") \
140 _(CLOSED, "closed") \
141 _(TRANSPORT_DELETED, "transport-deleted") \
145 #define _(sym, str) SESSION_STATE_ ## sym,
146 foreach_session_state
151 #define foreach_session_flag \
152 _(RX_EVT, "rx-event") \
154 _(CUSTOM_TX, "custom-tx") \
155 _(IS_MIGRATING, "migrating") \
156 _(UNIDIRECTIONAL, "unidirectional") \
158 typedef enum session_flags_bits_
160 #define _(sym, str) SESSION_F_BIT_ ## sym,
164 } session_flag_bits_t;
166 typedef enum session_flags_
168 #define _(sym, str) SESSION_F_ ## sym = 1 << SESSION_F_BIT_ ## sym,
173 typedef struct session_
175 /** Pointers to rx/tx buffers. Once allocated, these do not move */
179 /** Type built from transport and network protocol types */
180 session_type_t session_type;
182 /** State in session layer state machine. See @ref session_state_t */
183 volatile u8 session_state;
185 /** Index in thread pool where session was allocated */
188 /** Index of the app worker that owns the session */
191 /** Index of the thread that allocated the session */
194 /** Session flags. See @ref session_flags_t */
197 /** Index of the transport connection associated to the session */
198 u32 connection_index;
200 /** Index of application that owns the listener. Set only if a listener */
205 /** Parent listener session index if the result of an accept */
206 session_handle_t listener_handle;
208 /** App listener index in app's listener pool if a listener */
212 /** Opaque, for general use */
215 CLIB_CACHE_LINE_ALIGN_MARK (pad);
218 always_inline session_type_t
219 session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
221 return (proto << 1 | is_ip4);
224 always_inline transport_proto_t
225 session_type_transport_proto (session_type_t st)
231 session_type_is_ip4 (session_type_t st)
236 always_inline transport_proto_t
237 session_get_transport_proto (session_t * s)
239 return (s->session_type >> 1);
242 always_inline fib_protocol_t
243 session_get_fib_proto (session_t * s)
245 u8 is_ip4 = s->session_type & 1;
246 return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
250 session_has_transport (session_t * s)
252 return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
255 static inline transport_service_type_t
256 session_transport_service_type (session_t * s)
258 transport_proto_t tp;
259 tp = session_get_transport_proto (s);
260 return transport_protocol_service_type (tp);
263 static inline transport_tx_fn_type_t
264 session_transport_tx_fn_type (session_t * s)
266 transport_proto_t tp;
267 tp = session_get_transport_proto (s);
268 return transport_protocol_tx_fn_type (tp);
272 session_tx_is_dgram (session_t * s)
274 return (session_transport_tx_fn_type (s) == TRANSPORT_TX_DGRAM);
277 always_inline session_handle_t
278 session_handle (session_t * s)
280 return ((u64) s->thread_index << 32) | (u64) s->session_index;
284 session_index_from_handle (session_handle_t handle)
286 return handle & 0xFFFFFFFF;
290 session_thread_from_handle (session_handle_t handle)
296 session_parse_handle (session_handle_t handle, u32 * index,
299 *index = session_index_from_handle (handle);
300 *thread_index = session_thread_from_handle (handle);
303 static inline session_handle_t
304 session_make_handle (u32 session_index, u32 thread_index)
306 return (((u64) thread_index << 32) | (u64) session_index);
313 SESSION_IO_EVT_TX_FLUSH,
314 SESSION_IO_EVT_BUILTIN_RX,
315 SESSION_IO_EVT_BUILTIN_TX,
316 SESSION_CTRL_EVT_RPC,
317 SESSION_CTRL_EVT_CLOSE,
318 SESSION_CTRL_EVT_RESET,
319 SESSION_CTRL_EVT_BOUND,
320 SESSION_CTRL_EVT_UNLISTEN_REPLY,
321 SESSION_CTRL_EVT_ACCEPTED,
322 SESSION_CTRL_EVT_ACCEPTED_REPLY,
323 SESSION_CTRL_EVT_CONNECTED,
324 SESSION_CTRL_EVT_DISCONNECTED,
325 SESSION_CTRL_EVT_DISCONNECTED_REPLY,
326 SESSION_CTRL_EVT_RESET_REPLY,
327 SESSION_CTRL_EVT_REQ_WORKER_UPDATE,
328 SESSION_CTRL_EVT_WORKER_UPDATE,
329 SESSION_CTRL_EVT_WORKER_UPDATE_REPLY,
330 SESSION_CTRL_EVT_DISCONNECT,
331 SESSION_CTRL_EVT_CONNECT,
332 SESSION_CTRL_EVT_CONNECT_URI,
333 SESSION_CTRL_EVT_LISTEN,
334 SESSION_CTRL_EVT_LISTEN_URI,
335 SESSION_CTRL_EVT_UNLISTEN,
336 SESSION_CTRL_EVT_APP_DETACH,
337 } session_evt_type_t;
339 #define foreach_session_ctrl_evt \
341 _(LISTEN_URI, listen_uri) \
343 _(UNLISTEN, unlisten) \
344 _(UNLISTEN_REPLY, unlisten_reply) \
345 _(ACCEPTED, accepted) \
346 _(ACCEPTED_REPLY, accepted_reply) \
347 _(CONNECT, connect) \
348 _(CONNECT_URI, connect_uri) \
349 _(CONNECTED, connected) \
350 _(DISCONNECT, disconnect) \
351 _(DISCONNECTED, disconnected) \
352 _(DISCONNECTED_REPLY, disconnected_reply) \
353 _(RESET_REPLY, reset_reply) \
354 _(REQ_WORKER_UPDATE, req_worker_update) \
355 _(WORKER_UPDATE, worker_update) \
356 _(WORKER_UPDATE_REPLY, worker_update_reply) \
357 _(APP_DETACH, app_detach) \
360 /* Deprecated and will be removed. Use types above */
361 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
362 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
363 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
364 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
365 #define FIFO_EVENT_BUILTIN_TX SESSION_IO_EVT_BUILTIN_TX
369 SESSION_MQ_IO_EVT_RING,
370 SESSION_MQ_CTRL_EVT_RING,
372 } session_mq_rings_e;
378 } session_rpc_args_t;
387 session_handle_t session_handle;
388 session_rpc_args_t rpc_args;
395 } __clib_packed session_event_t;
397 #define SESSION_MSG_NULL { }
399 typedef struct session_dgram_pre_hdr_
403 } session_dgram_pre_hdr_t;
405 typedef struct session_dgram_header_
409 ip46_address_t rmt_ip;
410 ip46_address_t lcl_ip;
414 } __clib_packed session_dgram_hdr_t;
416 #define SESSION_CONN_ID_LEN 37
417 #define SESSION_CONN_HDR_LEN 45
419 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
420 "session conn id wrong length");
421 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
424 * fd.io coding-style-patch-verification: ON
427 * eval: (c-set-style "gnu")