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_LISTENER_PREFIX 0x5FFFFFFF
24 #define foreach_session_endpoint_fields \
25 foreach_transport_endpoint_cfg_fields \
26 _(u8, transport_proto) \
28 typedef struct _session_endpoint
30 #define _(type, name) type name;
31 foreach_session_endpoint_fields
35 typedef struct _session_endpoint_cfg
37 #define _(type, name) type name;
38 foreach_session_endpoint_fields
45 } session_endpoint_cfg_t;
47 #define SESSION_IP46_ZERO \
54 #define TRANSPORT_ENDPOINT_NULL \
56 .sw_if_index = ENDPOINT_INVALID_INDEX, \
57 .ip = SESSION_IP46_ZERO, \
58 .fib_index = ENDPOINT_INVALID_INDEX, \
62 #define SESSION_ENDPOINT_NULL \
64 .sw_if_index = ENDPOINT_INVALID_INDEX, \
65 .ip = SESSION_IP46_ZERO, \
66 .fib_index = ENDPOINT_INVALID_INDEX, \
69 .peer = TRANSPORT_ENDPOINT_NULL, \
70 .transport_proto = 0, \
72 #define SESSION_ENDPOINT_CFG_NULL \
74 .sw_if_index = ENDPOINT_INVALID_INDEX, \
75 .ip = SESSION_IP46_ZERO, \
76 .fib_index = ENDPOINT_INVALID_INDEX, \
79 .peer = TRANSPORT_ENDPOINT_NULL, \
80 .transport_proto = 0, \
81 .app_wrk_index = ENDPOINT_INVALID_INDEX, \
82 .opaque = ENDPOINT_INVALID_INDEX, \
86 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
87 #define session_endpoint_to_transport_cfg(_sep) \
88 ((transport_endpoint_cfg_t *)_sep)
91 session_endpoint_fib_proto (session_endpoint_t * sep)
93 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
97 session_endpoint_is_local (session_endpoint_t * sep)
99 return (ip_is_zero (&sep->ip, sep->is_ip4)
100 || ip_is_local_host (&sep->ip, sep->is_ip4));
104 session_endpoint_is_zero (session_endpoint_t * sep)
106 return ip_is_zero (&sep->ip, sep->is_ip4);
109 typedef u8 session_type_t;
110 typedef u64 session_handle_t;
113 * Application session state
117 SESSION_STATE_CREATED,
118 SESSION_STATE_LISTENING,
119 SESSION_STATE_CONNECTING,
120 SESSION_STATE_ACCEPTING,
122 SESSION_STATE_OPENED,
123 SESSION_STATE_TRANSPORT_CLOSING,
124 SESSION_STATE_CLOSING,
125 SESSION_STATE_CLOSED_WAITING,
126 SESSION_STATE_TRANSPORT_CLOSED,
127 SESSION_STATE_CLOSED,
128 SESSION_STATE_N_STATES,
131 typedef struct generic_session_
133 svm_fifo_t *rx_fifo; /**< rx fifo */
134 svm_fifo_t *tx_fifo; /**< tx fifo */
135 session_type_t session_type; /**< session type */
136 volatile u8 session_state; /**< session state */
137 u32 session_index; /**< index in owning pool */
140 typedef struct session_
142 /** fifo pointers. Once allocated, these do not move */
147 session_type_t session_type;
150 volatile u8 session_state;
152 /** Session index in per_thread pool */
155 /** App worker pool index */
160 /** To avoid n**2 "one event per frame" check */
163 /** svm segment index where fifos were allocated */
164 u32 svm_segment_index;
166 /** Transport specific */
167 u32 connection_index;
171 /** Parent listener session if the result of an accept */
174 /** Application index if a listener */
180 /** Transport app index for apps acting as transports */
183 /** App listener index */
186 /** Opaque, for general use */
190 CLIB_CACHE_LINE_ALIGN_MARK (pad);
193 always_inline session_type_t
194 session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
196 return (proto << 1 | is_ip4);
199 always_inline transport_proto_t
200 session_type_transport_proto (session_type_t st)
206 session_type_is_ip4 (session_type_t st)
211 always_inline transport_proto_t
212 session_get_transport_proto (session_t * s)
214 return (s->session_type >> 1);
217 always_inline fib_protocol_t
218 session_get_fib_proto (session_t * s)
220 u8 is_ip4 = s->session_type & 1;
221 return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
225 session_has_transport (session_t * s)
227 return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
230 static inline transport_service_type_t
231 session_transport_service_type (session_t * s)
233 transport_proto_t tp;
234 tp = session_get_transport_proto (s);
235 return transport_protocol_service_type (tp);
238 static inline transport_tx_fn_type_t
239 session_transport_tx_fn_type (session_t * s)
241 transport_proto_t tp;
242 tp = session_get_transport_proto (s);
243 return transport_protocol_tx_fn_type (tp);
247 session_tx_is_dgram (session_t * s)
249 return (session_transport_tx_fn_type (s) == TRANSPORT_TX_DGRAM);
252 always_inline session_handle_t
253 session_handle (session_t * s)
255 return ((u64) s->thread_index << 32) | (u64) s->session_index;
259 session_index_from_handle (session_handle_t handle)
261 return handle & 0xFFFFFFFF;
265 session_thread_from_handle (session_handle_t handle)
271 session_parse_handle (session_handle_t handle, u32 * index,
274 *index = session_index_from_handle (handle);
275 *thread_index = session_thread_from_handle (handle);
282 SESSION_IO_EVT_TX_FLUSH,
283 SESSION_IO_EVT_BUILTIN_RX,
284 SESSION_IO_EVT_BUILTIN_TX,
285 SESSION_CTRL_EVT_RPC,
286 SESSION_CTRL_EVT_CLOSE,
287 SESSION_CTRL_EVT_BOUND,
288 SESSION_CTRL_EVT_UNLISTEN_REPLY,
289 SESSION_CTRL_EVT_ACCEPTED,
290 SESSION_CTRL_EVT_ACCEPTED_REPLY,
291 SESSION_CTRL_EVT_CONNECTED,
292 SESSION_CTRL_EVT_CONNECTED_REPLY,
293 SESSION_CTRL_EVT_DISCONNECTED,
294 SESSION_CTRL_EVT_DISCONNECTED_REPLY,
295 SESSION_CTRL_EVT_RESET,
296 SESSION_CTRL_EVT_RESET_REPLY,
297 SESSION_CTRL_EVT_REQ_WORKER_UPDATE,
298 SESSION_CTRL_EVT_WORKER_UPDATE,
299 SESSION_CTRL_EVT_WORKER_UPDATE_REPLY,
300 } session_evt_type_t;
302 /* Deprecated and will be removed. Use types above */
303 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
304 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
305 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
306 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
307 #define FIFO_EVENT_BUILTIN_TX SESSION_IO_EVT_BUILTIN_TX
311 SESSION_MQ_IO_EVT_RING,
312 SESSION_MQ_CTRL_EVT_RING,
314 } session_mq_rings_e;
320 } session_rpc_args_t;
330 session_handle_t session_handle;
331 session_rpc_args_t rpc_args;
337 } __clib_packed session_event_t;
340 #define SESSION_MSG_NULL { }
342 typedef struct session_dgram_pre_hdr_
346 } session_dgram_pre_hdr_t;
349 typedef CLIB_PACKED (struct session_dgram_header_
353 ip46_address_t rmt_ip;
354 ip46_address_t lcl_ip;
358 }) session_dgram_hdr_t;
361 #define SESSION_CONN_ID_LEN 37
362 #define SESSION_CONN_HDR_LEN 45
364 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
365 "session conn id wrong length");
366 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
369 * fd.io coding-style-patch-verification: ON
372 * eval: (c-set-style "gnu")