2 * Copyright (c) 2017 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_STREAM_SESSION_H_
17 #define SRC_VNET_SESSION_STREAM_SESSION_H_
19 #include <svm/svm_fifo.h>
20 #include <vnet/session/transport.h>
22 typedef u8 session_type_t;
25 * Application session state
29 SESSION_STATE_LISTENING,
30 SESSION_STATE_CONNECTING,
31 SESSION_STATE_ACCEPTING,
34 SESSION_STATE_TRANSPORT_CLOSING,
35 SESSION_STATE_CLOSING,
36 SESSION_STATE_CLOSED_WAITING,
37 SESSION_STATE_TRANSPORT_CLOSED,
39 SESSION_STATE_N_STATES,
40 } stream_session_state_t;
42 typedef struct generic_session_
44 svm_fifo_t *rx_fifo; /**< rx fifo */
45 svm_fifo_t *tx_fifo; /**< tx fifo */
46 session_type_t session_type; /**< session type */
47 volatile u8 session_state; /**< session state */
48 u32 session_index; /**< index in owning pool */
51 typedef struct _stream_session_t
53 /** fifo pointers. Once allocated, these do not move */
54 svm_fifo_t *server_rx_fifo;
55 svm_fifo_t *server_tx_fifo;
58 session_type_t session_type;
61 volatile u8 session_state;
63 /** Session index in per_thread pool */
66 /** App worker pool index */
71 /** To avoid n**2 "one event per frame" check */
74 /** svm segment index where fifos were allocated */
75 u32 svm_segment_index;
77 /** Transport specific */
82 /** Parent listener session if the result of an accept */
85 /** Application index if a listener */
91 /** Transport app index for apps acting as transports */
94 /** Index in listener app's listener db */
95 u32 listener_db_index;
97 /** Opaque, for general use */
101 CLIB_CACHE_LINE_ALIGN_MARK (pad);
104 typedef struct local_session_
106 /** fifo pointers. Once allocated, these do not move */
107 svm_fifo_t *server_rx_fifo;
108 svm_fifo_t *server_tx_fifo;
111 session_type_t session_type;
114 volatile u8 session_state;
122 /** Port for connection. Overlaps thread_index/enqueue_epoch */
125 /** Partly overlaps enqueue_epoch */
128 /** Segment index where fifos were allocated */
129 u32 svm_segment_index;
131 /** Transport listener index. Overlaps connection index */
132 u32 transport_listener_index;
140 u32 listener_db_index;
142 /** Has transport embedded when listener not purely local */
143 session_type_t listener_session_type;
148 u32 client_wrk_index;
154 CLIB_CACHE_LINE_ALIGN_MARK (pad);
157 #define foreach_session_endpoint_fields \
158 foreach_transport_endpoint_cfg_fields \
159 _(u8, transport_proto) \
161 typedef struct _session_endpoint
163 #define _(type, name) type name;
164 foreach_session_endpoint_fields
166 } session_endpoint_t;
168 typedef struct _session_endpoint_cfg
170 #define _(type, name) type name;
171 foreach_session_endpoint_fields
176 } session_endpoint_cfg_t;
178 #define SESSION_IP46_ZERO \
185 #define TRANSPORT_ENDPOINT_NULL \
187 .sw_if_index = ENDPOINT_INVALID_INDEX, \
188 .ip = SESSION_IP46_ZERO, \
189 .fib_index = ENDPOINT_INVALID_INDEX, \
193 #define SESSION_ENDPOINT_NULL \
195 .sw_if_index = ENDPOINT_INVALID_INDEX, \
196 .ip = SESSION_IP46_ZERO, \
197 .fib_index = ENDPOINT_INVALID_INDEX, \
200 .peer = TRANSPORT_ENDPOINT_NULL, \
201 .transport_proto = 0, \
203 #define SESSION_ENDPOINT_CFG_NULL \
205 .sw_if_index = ENDPOINT_INVALID_INDEX, \
206 .ip = SESSION_IP46_ZERO, \
207 .fib_index = ENDPOINT_INVALID_INDEX, \
210 .peer = TRANSPORT_ENDPOINT_NULL, \
211 .transport_proto = 0, \
212 .app_wrk_index = ENDPOINT_INVALID_INDEX, \
213 .opaque = ENDPOINT_INVALID_INDEX, \
217 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
218 #define session_endpoint_to_transport_cfg(_sep) \
219 ((transport_endpoint_cfg_t *)_sep)
222 session_endpoint_fib_proto (session_endpoint_t * sep)
224 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
227 #endif /* SRC_VNET_SESSION_STREAM_SESSION_H_ */
230 * fd.io coding-style-patch-verification: ON
233 * eval: (c-set-style "gnu")