blob: 63adc2b909bb704ffa245a147dec583110e3a5a9 [file] [log] [blame]
Florin Coras04e53442017-07-16 17:12:15 -07001/*
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15
16#ifndef SRC_VNET_SESSION_STREAM_SESSION_H_
17#define SRC_VNET_SESSION_STREAM_SESSION_H_
18
Florin Coras04e53442017-07-16 17:12:15 -070019#include <svm/svm_fifo.h>
Florin Corascea194d2017-10-02 00:18:51 -070020#include <vnet/session/transport.h>
Florin Coras04e53442017-07-16 17:12:15 -070021
Florin Coras561af9b2017-12-09 10:19:43 -080022typedef u8 session_type_t;
Florin Coras04e53442017-07-16 17:12:15 -070023
24/*
25 * Application session state
26 */
27typedef enum
28{
29 SESSION_STATE_LISTENING,
30 SESSION_STATE_CONNECTING,
31 SESSION_STATE_ACCEPTING,
32 SESSION_STATE_READY,
Florin Coras7fb0fe12018-04-09 09:24:52 -070033 SESSION_STATE_OPENED,
Florin Coras568ebc72018-09-18 16:12:50 -070034 SESSION_STATE_TRANSPORT_CLOSING,
Florin Corasb2371c22018-05-31 17:14:10 -070035 SESSION_STATE_CLOSING,
Florin Coras78cc4b02018-12-20 18:24:49 -080036 SESSION_STATE_CLOSED_WAITING,
Florin Coras5a2ec8f2018-12-27 11:53:11 -080037 SESSION_STATE_TRANSPORT_CLOSED,
Florin Coras04e53442017-07-16 17:12:15 -070038 SESSION_STATE_CLOSED,
39 SESSION_STATE_N_STATES,
40} stream_session_state_t;
41
Florin Coras7fb0fe12018-04-09 09:24:52 -070042typedef struct generic_session_
Florin Corasf8f516a2018-02-08 15:10:09 -080043{
Florin Coras7fb0fe12018-04-09 09:24:52 -070044 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 */
49} generic_session_t;
Florin Corasf8f516a2018-02-08 15:10:09 -080050
Florin Coras04e53442017-07-16 17:12:15 -070051typedef struct _stream_session_t
52{
53 /** fifo pointers. Once allocated, these do not move */
54 svm_fifo_t *server_rx_fifo;
55 svm_fifo_t *server_tx_fifo;
56
57 /** Type */
Florin Coras561af9b2017-12-09 10:19:43 -080058 session_type_t session_type;
Florin Coras04e53442017-07-16 17:12:15 -070059
60 /** State */
Florin Coras1f152cd2017-08-18 19:28:03 -070061 volatile u8 session_state;
Florin Coras04e53442017-07-16 17:12:15 -070062
Florin Corasf8f516a2018-02-08 15:10:09 -080063 /** Session index in per_thread pool */
64 u32 session_index;
65
Florin Corasab2f6db2018-08-31 14:31:41 -070066 /** App worker pool index */
Florin Coras15531972018-08-12 23:50:53 -070067 u32 app_wrk_index;
Florin Corasf8f516a2018-02-08 15:10:09 -080068
Florin Coras04e53442017-07-16 17:12:15 -070069 u8 thread_index;
70
71 /** To avoid n**2 "one event per frame" check */
Florin Coraseb97e5f2018-10-15 21:35:42 -070072 u64 enqueue_epoch;
Florin Coras04e53442017-07-16 17:12:15 -070073
Florin Coras04e53442017-07-16 17:12:15 -070074 /** svm segment index where fifos were allocated */
75 u32 svm_segment_index;
76
Florin Coras04e53442017-07-16 17:12:15 -070077 /** Transport specific */
78 u32 connection_index;
79
Florin Coras371ca502018-02-21 12:07:41 -080080 union
81 {
82 /** Parent listener session if the result of an accept */
83 u32 listener_index;
Florin Corasab2f6db2018-08-31 14:31:41 -070084
85 /** Application index if a listener */
86 u32 app_index;
87 };
88
89 union
90 {
91 /** Transport app index for apps acting as transports */
92 u32 t_app_index;
93
94 /** Index in listener app's listener db */
95 u32 listener_db_index;
96
Florin Coras371ca502018-02-21 12:07:41 -080097 /** Opaque, for general use */
98 u32 opaque;
99 };
Florin Coras04e53442017-07-16 17:12:15 -0700100
Florin Coras0e9c33b2017-08-14 22:33:41 -0700101 CLIB_CACHE_LINE_ALIGN_MARK (pad);
Florin Coras04e53442017-07-16 17:12:15 -0700102} stream_session_t;
103
Florin Corasf8f516a2018-02-08 15:10:09 -0800104typedef struct local_session_
105{
106 /** fifo pointers. Once allocated, these do not move */
107 svm_fifo_t *server_rx_fifo;
108 svm_fifo_t *server_tx_fifo;
109
110 /** Type */
111 session_type_t session_type;
112
113 /** State */
114 volatile u8 session_state;
115
116 /** Session index */
117 u32 session_index;
118
119 /** Server index */
Florin Coras15531972018-08-12 23:50:53 -0700120 u32 app_wrk_index;
Florin Corasf8f516a2018-02-08 15:10:09 -0800121
Florin Corasab2f6db2018-08-31 14:31:41 -0700122 /** Port for connection. Overlaps thread_index/enqueue_epoch */
123 u16 port;
124
Florin Coraseb97e5f2018-10-15 21:35:42 -0700125 /** Partly overlaps enqueue_epoch */
126 u8 pad_epoch[7];
127
Florin Corasf8f516a2018-02-08 15:10:09 -0800128 /** Segment index where fifos were allocated */
129 u32 svm_segment_index;
130
Florin Corasab2f6db2018-08-31 14:31:41 -0700131 /** Transport listener index. Overlaps connection index */
132 u32 transport_listener_index;
Florin Corasf8f516a2018-02-08 15:10:09 -0800133
Florin Corasab2f6db2018-08-31 14:31:41 -0700134 union
135 {
136 u32 listener_index;
137 u32 app_index;
138 };
139
140 u32 listener_db_index;
Florin Corasf8f516a2018-02-08 15:10:09 -0800141
142 /** Has transport embedded when listener not purely local */
143 session_type_t listener_session_type;
144
145 /**
146 * Client data
147 */
Florin Coras15531972018-08-12 23:50:53 -0700148 u32 client_wrk_index;
Florin Corasf8f516a2018-02-08 15:10:09 -0800149 u32 client_opaque;
150
151 u64 server_evt_q;
152 u64 client_evt_q;
153
154 CLIB_CACHE_LINE_ALIGN_MARK (pad);
155} local_session_t;
156
Florin Coras371ca502018-02-21 12:07:41 -0800157#define foreach_session_endpoint_fields \
Florin Coras5665ced2018-10-25 18:03:45 -0700158 foreach_transport_endpoint_cfg_fields \
159 _(u8, transport_proto) \
Florin Coras371ca502018-02-21 12:07:41 -0800160
Florin Corascea194d2017-10-02 00:18:51 -0700161typedef struct _session_endpoint
162{
Florin Corascea194d2017-10-02 00:18:51 -0700163#define _(type, name) type name;
Florin Coras371ca502018-02-21 12:07:41 -0800164 foreach_session_endpoint_fields
Florin Corascea194d2017-10-02 00:18:51 -0700165#undef _
Florin Corascea194d2017-10-02 00:18:51 -0700166} session_endpoint_t;
167
Florin Coras5665ced2018-10-25 18:03:45 -0700168typedef struct _session_endpoint_cfg
Florin Coras371ca502018-02-21 12:07:41 -0800169{
170#define _(type, name) type name;
171 foreach_session_endpoint_fields
172#undef _
Florin Coras15531972018-08-12 23:50:53 -0700173 u32 app_wrk_index;
Florin Coras371ca502018-02-21 12:07:41 -0800174 u32 opaque;
Florin Coras8f89dd02018-03-05 16:53:07 -0800175 u8 *hostname;
Florin Coras5665ced2018-10-25 18:03:45 -0700176} session_endpoint_cfg_t;
Florin Coras371ca502018-02-21 12:07:41 -0800177
Florin Coras15531972018-08-12 23:50:53 -0700178#define SESSION_IP46_ZERO \
179{ \
180 .ip6 = { \
181 { 0, 0, }, \
182 }, \
Florin Corascea194d2017-10-02 00:18:51 -0700183}
Florin Coras5665ced2018-10-25 18:03:45 -0700184
185#define TRANSPORT_ENDPOINT_NULL \
186{ \
187 .sw_if_index = ENDPOINT_INVALID_INDEX, \
188 .ip = SESSION_IP46_ZERO, \
189 .fib_index = ENDPOINT_INVALID_INDEX, \
190 .is_ip4 = 0, \
191 .port = 0, \
192}
Florin Coras15531972018-08-12 23:50:53 -0700193#define SESSION_ENDPOINT_NULL \
194{ \
Florin Corascea194d2017-10-02 00:18:51 -0700195 .sw_if_index = ENDPOINT_INVALID_INDEX, \
Florin Coras15531972018-08-12 23:50:53 -0700196 .ip = SESSION_IP46_ZERO, \
197 .fib_index = ENDPOINT_INVALID_INDEX, \
198 .is_ip4 = 0, \
199 .port = 0, \
Florin Coras5665ced2018-10-25 18:03:45 -0700200 .peer = TRANSPORT_ENDPOINT_NULL, \
Florin Coras15531972018-08-12 23:50:53 -0700201 .transport_proto = 0, \
Florin Coras8f89dd02018-03-05 16:53:07 -0800202}
Florin Coras5665ced2018-10-25 18:03:45 -0700203#define SESSION_ENDPOINT_CFG_NULL \
Florin Coras15531972018-08-12 23:50:53 -0700204{ \
Florin Coras8f89dd02018-03-05 16:53:07 -0800205 .sw_if_index = ENDPOINT_INVALID_INDEX, \
Florin Coras15531972018-08-12 23:50:53 -0700206 .ip = SESSION_IP46_ZERO, \
207 .fib_index = ENDPOINT_INVALID_INDEX, \
208 .is_ip4 = 0, \
209 .port = 0, \
Florin Coras5665ced2018-10-25 18:03:45 -0700210 .peer = TRANSPORT_ENDPOINT_NULL, \
Florin Coras15531972018-08-12 23:50:53 -0700211 .transport_proto = 0, \
212 .app_wrk_index = ENDPOINT_INVALID_INDEX, \
213 .opaque = ENDPOINT_INVALID_INDEX, \
Florin Coras8f89dd02018-03-05 16:53:07 -0800214 .hostname = 0, \
Florin Corascea194d2017-10-02 00:18:51 -0700215}
216
217#define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
Florin Coras5665ced2018-10-25 18:03:45 -0700218#define session_endpoint_to_transport_cfg(_sep) \
219 ((transport_endpoint_cfg_t *)_sep)
Florin Corascea194d2017-10-02 00:18:51 -0700220
221always_inline u8
222session_endpoint_fib_proto (session_endpoint_t * sep)
223{
224 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
225}
226
Florin Coras04e53442017-07-16 17:12:15 -0700227#endif /* SRC_VNET_SESSION_STREAM_SESSION_H_ */
228
229/*
230 * fd.io coding-style-patch-verification: ON
231 *
232 * Local Variables:
233 * eval: (c-set-style "gnu")
234 * End:
235 */