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,
38 SESSION_STATE_N_STATES,
39 } stream_session_state_t;
41 typedef struct generic_session_
43 svm_fifo_t *rx_fifo; /**< rx fifo */
44 svm_fifo_t *tx_fifo; /**< tx fifo */
45 session_type_t session_type; /**< session type */
46 volatile u8 session_state; /**< session state */
47 u32 session_index; /**< index in owning pool */
50 typedef struct _stream_session_t
52 /** fifo pointers. Once allocated, these do not move */
53 svm_fifo_t *server_rx_fifo;
54 svm_fifo_t *server_tx_fifo;
57 session_type_t session_type;
60 volatile u8 session_state;
62 /** Session index in per_thread pool */
65 /** App worker pool index */
70 /** To avoid n**2 "one event per frame" check */
73 /** svm segment index where fifos were allocated */
74 u32 svm_segment_index;
76 /** Transport specific */
81 /** Parent listener session if the result of an accept */
84 /** Application index if a listener */
90 /** Transport app index for apps acting as transports */
93 /** Index in listener app's listener db */
94 u32 listener_db_index;
96 /** Opaque, for general use */
100 CLIB_CACHE_LINE_ALIGN_MARK (pad);
103 typedef struct local_session_
105 /** fifo pointers. Once allocated, these do not move */
106 svm_fifo_t *server_rx_fifo;
107 svm_fifo_t *server_tx_fifo;
110 session_type_t session_type;
113 volatile u8 session_state;
121 /** Port for connection. Overlaps thread_index/enqueue_epoch */
124 /** Partly overlaps enqueue_epoch */
127 /** Segment index where fifos were allocated */
128 u32 svm_segment_index;
130 /** Transport listener index. Overlaps connection index */
131 u32 transport_listener_index;
139 u32 listener_db_index;
141 /** Has transport embedded when listener not purely local */
142 session_type_t listener_session_type;
147 u32 client_wrk_index;
153 CLIB_CACHE_LINE_ALIGN_MARK (pad);
156 #define foreach_session_endpoint_fields \
157 foreach_transport_endpoint_cfg_fields \
158 _(u8, transport_proto) \
160 typedef struct _session_endpoint
162 #define _(type, name) type name;
163 foreach_session_endpoint_fields
165 } session_endpoint_t;
167 typedef struct _session_endpoint_cfg
169 #define _(type, name) type name;
170 foreach_session_endpoint_fields
175 } session_endpoint_cfg_t;
177 #define SESSION_IP46_ZERO \
184 #define TRANSPORT_ENDPOINT_NULL \
186 .sw_if_index = ENDPOINT_INVALID_INDEX, \
187 .ip = SESSION_IP46_ZERO, \
188 .fib_index = ENDPOINT_INVALID_INDEX, \
192 #define SESSION_ENDPOINT_NULL \
194 .sw_if_index = ENDPOINT_INVALID_INDEX, \
195 .ip = SESSION_IP46_ZERO, \
196 .fib_index = ENDPOINT_INVALID_INDEX, \
199 .peer = TRANSPORT_ENDPOINT_NULL, \
200 .transport_proto = 0, \
202 #define SESSION_ENDPOINT_CFG_NULL \
204 .sw_if_index = ENDPOINT_INVALID_INDEX, \
205 .ip = SESSION_IP46_ZERO, \
206 .fib_index = ENDPOINT_INVALID_INDEX, \
209 .peer = TRANSPORT_ENDPOINT_NULL, \
210 .transport_proto = 0, \
211 .app_wrk_index = ENDPOINT_INVALID_INDEX, \
212 .opaque = ENDPOINT_INVALID_INDEX, \
216 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
217 #define session_endpoint_to_transport_cfg(_sep) \
218 ((transport_endpoint_cfg_t *)_sep)
221 session_endpoint_fib_proto (session_endpoint_t * sep)
223 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
226 #endif /* SRC_VNET_SESSION_STREAM_SESSION_H_ */
229 * fd.io coding-style-patch-verification: ON
232 * eval: (c-set-style "gnu")