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
50 } session_endpoint_cfg_t;
52 #define SESSION_IP46_ZERO \
59 #define TRANSPORT_ENDPOINT_NULL \
61 .sw_if_index = ENDPOINT_INVALID_INDEX, \
62 .ip = SESSION_IP46_ZERO, \
63 .fib_index = ENDPOINT_INVALID_INDEX, \
67 #define SESSION_ENDPOINT_NULL \
69 .sw_if_index = ENDPOINT_INVALID_INDEX, \
70 .ip = SESSION_IP46_ZERO, \
71 .fib_index = ENDPOINT_INVALID_INDEX, \
74 .peer = TRANSPORT_ENDPOINT_NULL, \
75 .transport_proto = 0, \
77 #define SESSION_ENDPOINT_CFG_NULL \
79 .sw_if_index = ENDPOINT_INVALID_INDEX, \
80 .ip = SESSION_IP46_ZERO, \
81 .fib_index = ENDPOINT_INVALID_INDEX, \
84 .peer = TRANSPORT_ENDPOINT_NULL, \
85 .transport_proto = 0, \
86 .app_wrk_index = ENDPOINT_INVALID_INDEX, \
87 .opaque = ENDPOINT_INVALID_INDEX, \
89 .parent_handle = SESSION_INVALID_HANDLE, \
93 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
94 #define session_endpoint_to_transport_cfg(_sep) \
95 ((transport_endpoint_cfg_t *)_sep)
98 session_endpoint_fib_proto (session_endpoint_t * sep)
100 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
104 session_endpoint_is_local (session_endpoint_t * sep)
106 return (ip_is_zero (&sep->ip, sep->is_ip4)
107 || ip_is_local_host (&sep->ip, sep->is_ip4));
111 session_endpoint_is_zero (session_endpoint_t * sep)
113 return ip_is_zero (&sep->ip, sep->is_ip4);
116 typedef u8 session_type_t;
117 typedef u64 session_handle_t;
121 SESSION_CLEANUP_TRANSPORT,
122 SESSION_CLEANUP_SESSION,
123 } session_cleanup_ntf_t;
128 #define foreach_session_state \
129 _(CREATED, "created") \
130 _(LISTENING, "listening") \
131 _(CONNECTING, "connecting") \
132 _(ACCEPTING, "accepting") \
134 _(OPENED, "opened") \
135 _(TRANSPORT_CLOSING, "transport-closing") \
136 _(CLOSING, "closing") \
137 _(APP_CLOSED, "app-closed") \
138 _(TRANSPORT_CLOSED, "transport-closed") \
139 _(CLOSED, "closed") \
140 _(TRANSPORT_DELETED, "transport-deleted") \
144 #define _(sym, str) SESSION_STATE_ ## sym,
145 foreach_session_state
150 typedef enum session_flags_
152 SESSION_F_RX_EVT = 1,
153 SESSION_F_PROXY = (1 << 1),
154 SESSION_F_CUSTOM_TX = (1 << 2),
155 SESSION_F_IS_MIGRATING = (1 << 3),
158 typedef struct session_
160 /** Pointers to rx/tx buffers. Once allocated, these do not move */
164 /** Type built from transport and network protocol types */
165 session_type_t session_type;
167 /** State in session layer state machine. See @ref session_state_t */
168 volatile u8 session_state;
170 /** Index in thread pool where session was allocated */
173 /** Index of the app worker that owns the session */
176 /** Index of the thread that allocated the session */
179 /** Session flags. See @ref session_flags_t */
182 /** Index of the transport connection associated to the session */
183 u32 connection_index;
185 /** Index of application that owns the listener. Set only if a listener */
190 /** Parent listener session index if the result of an accept */
191 session_handle_t listener_handle;
193 /** App listener index in app's listener pool if a listener */
197 /** Opaque, for general use */
200 CLIB_CACHE_LINE_ALIGN_MARK (pad);
203 always_inline session_type_t
204 session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
206 return (proto << 1 | is_ip4);
209 always_inline transport_proto_t
210 session_type_transport_proto (session_type_t st)
216 session_type_is_ip4 (session_type_t st)
221 always_inline transport_proto_t
222 session_get_transport_proto (session_t * s)
224 return (s->session_type >> 1);
227 always_inline fib_protocol_t
228 session_get_fib_proto (session_t * s)
230 u8 is_ip4 = s->session_type & 1;
231 return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
235 session_has_transport (session_t * s)
237 return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
240 static inline transport_service_type_t
241 session_transport_service_type (session_t * s)
243 transport_proto_t tp;
244 tp = session_get_transport_proto (s);
245 return transport_protocol_service_type (tp);
248 static inline transport_tx_fn_type_t
249 session_transport_tx_fn_type (session_t * s)
251 transport_proto_t tp;
252 tp = session_get_transport_proto (s);
253 return transport_protocol_tx_fn_type (tp);
257 session_tx_is_dgram (session_t * s)
259 return (session_transport_tx_fn_type (s) == TRANSPORT_TX_DGRAM);
262 always_inline session_handle_t
263 session_handle (session_t * s)
265 return ((u64) s->thread_index << 32) | (u64) s->session_index;
269 session_index_from_handle (session_handle_t handle)
271 return handle & 0xFFFFFFFF;
275 session_thread_from_handle (session_handle_t handle)
281 session_parse_handle (session_handle_t handle, u32 * index,
284 *index = session_index_from_handle (handle);
285 *thread_index = session_thread_from_handle (handle);
288 static inline session_handle_t
289 session_make_handle (u32 session_index, u32 thread_index)
291 return (((u64) thread_index << 32) | (u64) session_index);
298 SESSION_IO_EVT_TX_FLUSH,
299 SESSION_IO_EVT_BUILTIN_RX,
300 SESSION_IO_EVT_BUILTIN_TX,
301 SESSION_CTRL_EVT_RPC,
302 SESSION_CTRL_EVT_CLOSE,
303 SESSION_CTRL_EVT_RESET,
304 SESSION_CTRL_EVT_BOUND,
305 SESSION_CTRL_EVT_UNLISTEN_REPLY,
306 SESSION_CTRL_EVT_ACCEPTED,
307 SESSION_CTRL_EVT_ACCEPTED_REPLY,
308 SESSION_CTRL_EVT_CONNECTED,
309 SESSION_CTRL_EVT_DISCONNECTED,
310 SESSION_CTRL_EVT_DISCONNECTED_REPLY,
311 SESSION_CTRL_EVT_RESET_REPLY,
312 SESSION_CTRL_EVT_REQ_WORKER_UPDATE,
313 SESSION_CTRL_EVT_WORKER_UPDATE,
314 SESSION_CTRL_EVT_WORKER_UPDATE_REPLY,
315 SESSION_CTRL_EVT_DISCONNECT,
316 SESSION_CTRL_EVT_CONNECT,
317 SESSION_CTRL_EVT_CONNECT_URI,
318 SESSION_CTRL_EVT_LISTEN,
319 SESSION_CTRL_EVT_LISTEN_URI,
320 SESSION_CTRL_EVT_UNLISTEN,
321 SESSION_CTRL_EVT_APP_DETACH,
322 } session_evt_type_t;
324 #define foreach_session_ctrl_evt \
326 _(LISTEN_URI, listen_uri) \
328 _(UNLISTEN, unlisten) \
329 _(UNLISTEN_REPLY, unlisten_reply) \
330 _(ACCEPTED, accepted) \
331 _(ACCEPTED_REPLY, accepted_reply) \
332 _(CONNECT, connect) \
333 _(CONNECT_URI, connect_uri) \
334 _(CONNECTED, connected) \
335 _(DISCONNECT, disconnect) \
336 _(DISCONNECTED, disconnected) \
337 _(DISCONNECTED_REPLY, disconnected_reply) \
338 _(RESET_REPLY, reset_reply) \
339 _(REQ_WORKER_UPDATE, req_worker_update) \
340 _(WORKER_UPDATE, worker_update) \
341 _(WORKER_UPDATE_REPLY, worker_update_reply) \
342 _(APP_DETACH, app_detach) \
345 /* Deprecated and will be removed. Use types above */
346 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
347 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
348 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
349 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
350 #define FIFO_EVENT_BUILTIN_TX SESSION_IO_EVT_BUILTIN_TX
354 SESSION_MQ_IO_EVT_RING,
355 SESSION_MQ_CTRL_EVT_RING,
357 } session_mq_rings_e;
363 } session_rpc_args_t;
372 session_handle_t session_handle;
373 session_rpc_args_t rpc_args;
380 } __clib_packed session_event_t;
382 #define SESSION_MSG_NULL { }
384 typedef struct session_dgram_pre_hdr_
388 } session_dgram_pre_hdr_t;
390 typedef struct session_dgram_header_
394 ip46_address_t rmt_ip;
395 ip46_address_t lcl_ip;
399 } __clib_packed session_dgram_hdr_t;
401 #define SESSION_CONN_ID_LEN 37
402 #define SESSION_CONN_HDR_LEN 45
404 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
405 "session conn id wrong length");
406 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
409 * fd.io coding-style-patch-verification: ON
412 * eval: (c-set-style "gnu")