blob: 1673356769c38bd6b5eb1a524cb16a4066f820a7 [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
19#include <vnet/vnet.h>
20#include <svm/svm_fifo.h>
Florin Corascea194d2017-10-02 00:18:51 -070021#include <vnet/session/transport.h>
Florin Coras04e53442017-07-16 17:12:15 -070022
Florin Coras561af9b2017-12-09 10:19:43 -080023typedef u8 session_type_t;
Florin Coras04e53442017-07-16 17:12:15 -070024
25/*
26 * Application session state
27 */
28typedef enum
29{
30 SESSION_STATE_LISTENING,
31 SESSION_STATE_CONNECTING,
32 SESSION_STATE_ACCEPTING,
33 SESSION_STATE_READY,
Florin Coras7fb0fe12018-04-09 09:24:52 -070034 SESSION_STATE_OPENED,
Florin Corasb2371c22018-05-31 17:14:10 -070035 SESSION_STATE_CLOSING,
Florin Coras04e53442017-07-16 17:12:15 -070036 SESSION_STATE_CLOSED,
37 SESSION_STATE_N_STATES,
38} stream_session_state_t;
39
Florin Coras7fb0fe12018-04-09 09:24:52 -070040typedef struct generic_session_
Florin Corasf8f516a2018-02-08 15:10:09 -080041{
Florin Coras7fb0fe12018-04-09 09:24:52 -070042 svm_fifo_t *rx_fifo; /**< rx fifo */
43 svm_fifo_t *tx_fifo; /**< tx fifo */
44 session_type_t session_type; /**< session type */
45 volatile u8 session_state; /**< session state */
46 u32 session_index; /**< index in owning pool */
47} generic_session_t;
Florin Corasf8f516a2018-02-08 15:10:09 -080048
Florin Coras04e53442017-07-16 17:12:15 -070049typedef struct _stream_session_t
50{
51 /** fifo pointers. Once allocated, these do not move */
52 svm_fifo_t *server_rx_fifo;
53 svm_fifo_t *server_tx_fifo;
54
55 /** Type */
Florin Coras561af9b2017-12-09 10:19:43 -080056 session_type_t session_type;
Florin Coras04e53442017-07-16 17:12:15 -070057
58 /** State */
Florin Coras1f152cd2017-08-18 19:28:03 -070059 volatile u8 session_state;
Florin Coras04e53442017-07-16 17:12:15 -070060
Florin Corasf8f516a2018-02-08 15:10:09 -080061 /** Session index in per_thread pool */
62 u32 session_index;
63
64 /** stream server pool index */
65 u32 app_index;
66
Florin Coras04e53442017-07-16 17:12:15 -070067 u8 thread_index;
68
69 /** To avoid n**2 "one event per frame" check */
70 u8 enqueue_epoch;
71
Florin Coras04e53442017-07-16 17:12:15 -070072 /** svm segment index where fifos were allocated */
73 u32 svm_segment_index;
74
Florin Coras04e53442017-07-16 17:12:15 -070075 /** Transport specific */
76 u32 connection_index;
77
Florin Coras371ca502018-02-21 12:07:41 -080078 union
79 {
80 /** Parent listener session if the result of an accept */
81 u32 listener_index;
82 /** Opaque, for general use */
83 u32 opaque;
84 };
Florin Coras04e53442017-07-16 17:12:15 -070085
Florin Coras0e9c33b2017-08-14 22:33:41 -070086 CLIB_CACHE_LINE_ALIGN_MARK (pad);
Florin Coras04e53442017-07-16 17:12:15 -070087} stream_session_t;
88
Florin Corasf8f516a2018-02-08 15:10:09 -080089typedef struct local_session_
90{
91 /** fifo pointers. Once allocated, these do not move */
92 svm_fifo_t *server_rx_fifo;
93 svm_fifo_t *server_tx_fifo;
94
95 /** Type */
96 session_type_t session_type;
97
98 /** State */
99 volatile u8 session_state;
100
101 /** Session index */
102 u32 session_index;
103
104 /** Server index */
105 u32 app_index;
106
107 /** Segment index where fifos were allocated */
108 u32 svm_segment_index;
109
110 u32 listener_index;
111
112 /** Port for connection */
113 u16 port;
114
115 /** Has transport embedded when listener not purely local */
116 session_type_t listener_session_type;
Florin Coras5fda7a32018-02-14 08:04:31 -0800117 u32 transport_listener_index;
Florin Corasf8f516a2018-02-08 15:10:09 -0800118
119 /**
120 * Client data
121 */
122 u32 client_index;
123 u32 client_opaque;
124
125 u64 server_evt_q;
126 u64 client_evt_q;
127
128 CLIB_CACHE_LINE_ALIGN_MARK (pad);
129} local_session_t;
130
Florin Coras371ca502018-02-21 12:07:41 -0800131#define foreach_session_endpoint_fields \
132 foreach_transport_connection_fields \
133 _(u8, transport_proto) \
Florin Coras371ca502018-02-21 12:07:41 -0800134
Florin Corascea194d2017-10-02 00:18:51 -0700135typedef struct _session_endpoint
136{
Florin Corascea194d2017-10-02 00:18:51 -0700137#define _(type, name) type name;
Florin Coras371ca502018-02-21 12:07:41 -0800138 foreach_session_endpoint_fields
Florin Corascea194d2017-10-02 00:18:51 -0700139#undef _
Florin Corascea194d2017-10-02 00:18:51 -0700140} session_endpoint_t;
141
Florin Coras371ca502018-02-21 12:07:41 -0800142typedef struct _session_endpoint_extended
143{
144#define _(type, name) type name;
145 foreach_session_endpoint_fields
146#undef _
147 u32 app_index;
148 u32 opaque;
Florin Coras8f89dd02018-03-05 16:53:07 -0800149 u8 *hostname;
Florin Coras371ca502018-02-21 12:07:41 -0800150} session_endpoint_extended_t;
151
Florin Corascea194d2017-10-02 00:18:51 -0700152#define SESSION_IP46_ZERO \
153{ \
154 .ip6 = { \
155 { 0, 0, }, \
156 }, \
157}
158#define SESSION_ENDPOINT_NULL \
159{ \
160 .sw_if_index = ENDPOINT_INVALID_INDEX, \
161 .ip = SESSION_IP46_ZERO, \
162 .fib_index = ENDPOINT_INVALID_INDEX, \
163 .is_ip4 = 0, \
164 .port = 0, \
165 .transport_proto = 0, \
Florin Coras8f89dd02018-03-05 16:53:07 -0800166}
167#define SESSION_ENDPOINT_EXT_NULL \
168{ \
169 .sw_if_index = ENDPOINT_INVALID_INDEX, \
170 .ip = SESSION_IP46_ZERO, \
171 .fib_index = ENDPOINT_INVALID_INDEX, \
172 .is_ip4 = 0, \
173 .port = 0, \
174 .transport_proto = 0, \
175 .app_index = ENDPOINT_INVALID_INDEX, \
176 .opaque = ENDPOINT_INVALID_INDEX, \
177 .hostname = 0, \
Florin Corascea194d2017-10-02 00:18:51 -0700178}
179
180#define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
181
182always_inline u8
183session_endpoint_fib_proto (session_endpoint_t * sep)
184{
185 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
186}
187
Florin Coras04e53442017-07-16 17:12:15 -0700188#endif /* SRC_VNET_SESSION_STREAM_SESSION_H_ */
189
190/*
191 * fd.io coding-style-patch-verification: ON
192 *
193 * Local Variables:
194 * eval: (c-set-style "gnu")
195 * End:
196 */