blob: 30178d7a4539a199a12fa78d67b2eb17d1d659d7 [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 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
Florin Corasab2f6db2018-08-31 14:31:41 -070064 /** App worker pool index */
Florin Coras15531972018-08-12 23:50:53 -070065 u32 app_wrk_index;
Florin Corasf8f516a2018-02-08 15:10:09 -080066
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;
Florin Corasab2f6db2018-08-31 14:31:41 -070082
83 /** Application index if a listener */
84 u32 app_index;
85 };
86
87 union
88 {
89 /** Transport app index for apps acting as transports */
90 u32 t_app_index;
91
92 /** Index in listener app's listener db */
93 u32 listener_db_index;
94
Florin Coras371ca502018-02-21 12:07:41 -080095 /** Opaque, for general use */
96 u32 opaque;
97 };
Florin Coras04e53442017-07-16 17:12:15 -070098
Florin Coras0e9c33b2017-08-14 22:33:41 -070099 CLIB_CACHE_LINE_ALIGN_MARK (pad);
Florin Coras04e53442017-07-16 17:12:15 -0700100} stream_session_t;
101
Florin Corasf8f516a2018-02-08 15:10:09 -0800102typedef struct local_session_
103{
104 /** fifo pointers. Once allocated, these do not move */
105 svm_fifo_t *server_rx_fifo;
106 svm_fifo_t *server_tx_fifo;
107
108 /** Type */
109 session_type_t session_type;
110
111 /** State */
112 volatile u8 session_state;
113
114 /** Session index */
115 u32 session_index;
116
117 /** Server index */
Florin Coras15531972018-08-12 23:50:53 -0700118 u32 app_wrk_index;
Florin Corasf8f516a2018-02-08 15:10:09 -0800119
Florin Corasab2f6db2018-08-31 14:31:41 -0700120 /** Port for connection. Overlaps thread_index/enqueue_epoch */
121 u16 port;
122
Florin Corasf8f516a2018-02-08 15:10:09 -0800123 /** Segment index where fifos were allocated */
124 u32 svm_segment_index;
125
Florin Corasab2f6db2018-08-31 14:31:41 -0700126 /** Transport listener index. Overlaps connection index */
127 u32 transport_listener_index;
Florin Corasf8f516a2018-02-08 15:10:09 -0800128
Florin Corasab2f6db2018-08-31 14:31:41 -0700129 union
130 {
131 u32 listener_index;
132 u32 app_index;
133 };
134
135 u32 listener_db_index;
Florin Corasf8f516a2018-02-08 15:10:09 -0800136
137 /** Has transport embedded when listener not purely local */
138 session_type_t listener_session_type;
139
140 /**
141 * Client data
142 */
Florin Coras15531972018-08-12 23:50:53 -0700143 u32 client_wrk_index;
Florin Corasf8f516a2018-02-08 15:10:09 -0800144 u32 client_opaque;
145
146 u64 server_evt_q;
147 u64 client_evt_q;
148
149 CLIB_CACHE_LINE_ALIGN_MARK (pad);
150} local_session_t;
151
Florin Coras371ca502018-02-21 12:07:41 -0800152#define foreach_session_endpoint_fields \
153 foreach_transport_connection_fields \
154 _(u8, transport_proto) \
Florin Coras371ca502018-02-21 12:07:41 -0800155
Florin Corascea194d2017-10-02 00:18:51 -0700156typedef struct _session_endpoint
157{
Florin Corascea194d2017-10-02 00:18:51 -0700158#define _(type, name) type name;
Florin Coras371ca502018-02-21 12:07:41 -0800159 foreach_session_endpoint_fields
Florin Corascea194d2017-10-02 00:18:51 -0700160#undef _
Florin Corascea194d2017-10-02 00:18:51 -0700161} session_endpoint_t;
162
Florin Coras371ca502018-02-21 12:07:41 -0800163typedef struct _session_endpoint_extended
164{
165#define _(type, name) type name;
166 foreach_session_endpoint_fields
167#undef _
Florin Coras15531972018-08-12 23:50:53 -0700168 u32 app_wrk_index;
Florin Coras371ca502018-02-21 12:07:41 -0800169 u32 opaque;
Florin Coras8f89dd02018-03-05 16:53:07 -0800170 u8 *hostname;
Florin Coras371ca502018-02-21 12:07:41 -0800171} session_endpoint_extended_t;
172
Florin Coras15531972018-08-12 23:50:53 -0700173#define SESSION_IP46_ZERO \
174{ \
175 .ip6 = { \
176 { 0, 0, }, \
177 }, \
Florin Corascea194d2017-10-02 00:18:51 -0700178}
Florin Coras15531972018-08-12 23:50:53 -0700179#define SESSION_ENDPOINT_NULL \
180{ \
Florin Corascea194d2017-10-02 00:18:51 -0700181 .sw_if_index = ENDPOINT_INVALID_INDEX, \
Florin Coras15531972018-08-12 23:50:53 -0700182 .ip = SESSION_IP46_ZERO, \
183 .fib_index = ENDPOINT_INVALID_INDEX, \
184 .is_ip4 = 0, \
185 .port = 0, \
186 .transport_proto = 0, \
Florin Coras8f89dd02018-03-05 16:53:07 -0800187}
Florin Coras15531972018-08-12 23:50:53 -0700188#define SESSION_ENDPOINT_EXT_NULL \
189{ \
Florin Coras8f89dd02018-03-05 16:53:07 -0800190 .sw_if_index = ENDPOINT_INVALID_INDEX, \
Florin Coras15531972018-08-12 23:50:53 -0700191 .ip = SESSION_IP46_ZERO, \
192 .fib_index = ENDPOINT_INVALID_INDEX, \
193 .is_ip4 = 0, \
194 .port = 0, \
195 .transport_proto = 0, \
196 .app_wrk_index = ENDPOINT_INVALID_INDEX, \
197 .opaque = ENDPOINT_INVALID_INDEX, \
Florin Coras8f89dd02018-03-05 16:53:07 -0800198 .hostname = 0, \
Florin Corascea194d2017-10-02 00:18:51 -0700199}
200
201#define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
202
203always_inline u8
204session_endpoint_fib_proto (session_endpoint_t * sep)
205{
206 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
207}
208
Florin Coras04e53442017-07-16 17:12:15 -0700209#endif /* SRC_VNET_SESSION_STREAM_SESSION_H_ */
210
211/*
212 * fd.io coding-style-patch-verification: ON
213 *
214 * Local Variables:
215 * eval: (c-set-style "gnu")
216 * End:
217 */