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 foreach_session_endpoint_fields \
23 foreach_transport_endpoint_cfg_fields \
24 _(u8, transport_proto) \
26 typedef struct _session_endpoint
28 #define _(type, name) type name;
29 foreach_session_endpoint_fields
33 typedef struct _session_endpoint_cfg
35 #define _(type, name) type name;
36 foreach_session_endpoint_fields
44 } session_endpoint_cfg_t;
46 #define SESSION_IP46_ZERO \
53 #define TRANSPORT_ENDPOINT_NULL \
55 .sw_if_index = ENDPOINT_INVALID_INDEX, \
56 .ip = SESSION_IP46_ZERO, \
57 .fib_index = ENDPOINT_INVALID_INDEX, \
61 #define SESSION_ENDPOINT_NULL \
63 .sw_if_index = ENDPOINT_INVALID_INDEX, \
64 .ip = SESSION_IP46_ZERO, \
65 .fib_index = ENDPOINT_INVALID_INDEX, \
68 .peer = TRANSPORT_ENDPOINT_NULL, \
69 .transport_proto = 0, \
71 #define SESSION_ENDPOINT_CFG_NULL \
73 .sw_if_index = ENDPOINT_INVALID_INDEX, \
74 .ip = SESSION_IP46_ZERO, \
75 .fib_index = ENDPOINT_INVALID_INDEX, \
78 .peer = TRANSPORT_ENDPOINT_NULL, \
79 .transport_proto = 0, \
80 .app_wrk_index = ENDPOINT_INVALID_INDEX, \
81 .opaque = ENDPOINT_INVALID_INDEX, \
85 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
86 #define session_endpoint_to_transport_cfg(_sep) \
87 ((transport_endpoint_cfg_t *)_sep)
90 session_endpoint_fib_proto (session_endpoint_t * sep)
92 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
96 session_endpoint_is_local (session_endpoint_t * sep)
98 return (ip_is_zero (&sep->ip, sep->is_ip4)
99 || ip_is_local_host (&sep->ip, sep->is_ip4));
103 session_endpoint_is_zero (session_endpoint_t * sep)
105 return ip_is_zero (&sep->ip, sep->is_ip4);
108 typedef u8 session_type_t;
109 typedef u64 session_handle_t;
116 SESSION_STATE_CREATED,
117 SESSION_STATE_LISTENING,
118 SESSION_STATE_CONNECTING,
119 SESSION_STATE_ACCEPTING,
121 SESSION_STATE_OPENED,
122 SESSION_STATE_TRANSPORT_CLOSING,
123 SESSION_STATE_CLOSING,
124 SESSION_STATE_CLOSED_WAITING,
125 SESSION_STATE_TRANSPORT_CLOSED,
126 SESSION_STATE_CLOSED,
127 SESSION_STATE_N_STATES,
130 typedef enum session_flags_
132 SESSION_F_RX_EVT = 1,
133 SESSION_F_PROXY = (1 << 1),
136 typedef struct session_
138 /** Pointers to rx/tx buffers. Once allocated, these do not move */
142 /** Type built from transport and network protocol types */
143 session_type_t session_type;
145 /** State in session layer state machine. See @ref session_state_t */
146 volatile u8 session_state;
148 /** Index in thread pool where session was allocated */
151 /** Index of the app worker that owns the session */
154 /** Index of the thread that allocated the session */
157 /** Session flags. See @ref session_flags_t */
160 /** Index of the transport connection associated to the session */
161 u32 connection_index;
163 /** Index of application that owns the listener. Set only if a listener */
168 /** Parent listener session index if the result of an accept */
169 session_handle_t listener_handle;
171 /** App listener index in app's listener pool if a listener */
175 /** Opaque, for general use */
178 CLIB_CACHE_LINE_ALIGN_MARK (pad);
181 always_inline session_type_t
182 session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
184 return (proto << 1 | is_ip4);
187 always_inline transport_proto_t
188 session_type_transport_proto (session_type_t st)
194 session_type_is_ip4 (session_type_t st)
199 always_inline transport_proto_t
200 session_get_transport_proto (session_t * s)
202 return (s->session_type >> 1);
205 always_inline fib_protocol_t
206 session_get_fib_proto (session_t * s)
208 u8 is_ip4 = s->session_type & 1;
209 return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
213 session_has_transport (session_t * s)
215 return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
218 static inline transport_service_type_t
219 session_transport_service_type (session_t * s)
221 transport_proto_t tp;
222 tp = session_get_transport_proto (s);
223 return transport_protocol_service_type (tp);
226 static inline transport_tx_fn_type_t
227 session_transport_tx_fn_type (session_t * s)
229 transport_proto_t tp;
230 tp = session_get_transport_proto (s);
231 return transport_protocol_tx_fn_type (tp);
235 session_tx_is_dgram (session_t * s)
237 return (session_transport_tx_fn_type (s) == TRANSPORT_TX_DGRAM);
240 always_inline session_handle_t
241 session_handle (session_t * s)
243 return ((u64) s->thread_index << 32) | (u64) s->session_index;
247 session_index_from_handle (session_handle_t handle)
249 return handle & 0xFFFFFFFF;
253 session_thread_from_handle (session_handle_t handle)
259 session_parse_handle (session_handle_t handle, u32 * index,
262 *index = session_index_from_handle (handle);
263 *thread_index = session_thread_from_handle (handle);
270 SESSION_IO_EVT_TX_FLUSH,
271 SESSION_IO_EVT_BUILTIN_RX,
272 SESSION_IO_EVT_BUILTIN_TX,
273 SESSION_CTRL_EVT_RPC,
274 SESSION_CTRL_EVT_CLOSE,
275 SESSION_CTRL_EVT_BOUND,
276 SESSION_CTRL_EVT_UNLISTEN_REPLY,
277 SESSION_CTRL_EVT_ACCEPTED,
278 SESSION_CTRL_EVT_ACCEPTED_REPLY,
279 SESSION_CTRL_EVT_CONNECTED,
280 SESSION_CTRL_EVT_CONNECTED_REPLY,
281 SESSION_CTRL_EVT_DISCONNECTED,
282 SESSION_CTRL_EVT_DISCONNECTED_REPLY,
283 SESSION_CTRL_EVT_RESET,
284 SESSION_CTRL_EVT_RESET_REPLY,
285 SESSION_CTRL_EVT_REQ_WORKER_UPDATE,
286 SESSION_CTRL_EVT_WORKER_UPDATE,
287 SESSION_CTRL_EVT_WORKER_UPDATE_REPLY,
288 } session_evt_type_t;
290 /* Deprecated and will be removed. Use types above */
291 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
292 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
293 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
294 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
295 #define FIFO_EVENT_BUILTIN_TX SESSION_IO_EVT_BUILTIN_TX
299 SESSION_MQ_IO_EVT_RING,
300 SESSION_MQ_CTRL_EVT_RING,
302 } session_mq_rings_e;
308 } session_rpc_args_t;
317 session_handle_t session_handle;
318 session_rpc_args_t rpc_args;
324 } __clib_packed session_event_t;
326 #define SESSION_MSG_NULL { }
328 typedef struct session_dgram_pre_hdr_
332 } session_dgram_pre_hdr_t;
334 typedef struct session_dgram_header_
338 ip46_address_t rmt_ip;
339 ip46_address_t lcl_ip;
343 } __clib_packed session_dgram_hdr_t;
345 #define SESSION_CONN_ID_LEN 37
346 #define SESSION_CONN_HDR_LEN 45
348 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
349 "session conn id wrong length");
350 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
353 * fd.io coding-style-patch-verification: ON
356 * eval: (c-set-style "gnu")