blob: b08f95925104b2557bd26492c64609b2a5d14de7 [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 Corasb2371c22018-05-31 17:14:10 -070034 SESSION_STATE_CLOSING,
Florin Coras04e53442017-07-16 17:12:15 -070035 SESSION_STATE_CLOSED,
36 SESSION_STATE_N_STATES,
37} stream_session_state_t;
38
Florin Coras7fb0fe12018-04-09 09:24:52 -070039typedef struct generic_session_
Florin Corasf8f516a2018-02-08 15:10:09 -080040{
Florin Coras7fb0fe12018-04-09 09:24:52 -070041 svm_fifo_t *rx_fifo; /**< rx fifo */
42 svm_fifo_t *tx_fifo; /**< tx fifo */
43 session_type_t session_type; /**< session type */
44 volatile u8 session_state; /**< session state */
45 u32 session_index; /**< index in owning pool */
46} generic_session_t;
Florin Corasf8f516a2018-02-08 15:10:09 -080047
Florin Coras04e53442017-07-16 17:12:15 -070048typedef struct _stream_session_t
49{
50 /** fifo pointers. Once allocated, these do not move */
51 svm_fifo_t *server_rx_fifo;
52 svm_fifo_t *server_tx_fifo;
53
54 /** Type */
Florin Coras561af9b2017-12-09 10:19:43 -080055 session_type_t session_type;
Florin Coras04e53442017-07-16 17:12:15 -070056
57 /** State */
Florin Coras1f152cd2017-08-18 19:28:03 -070058 volatile u8 session_state;
Florin Coras04e53442017-07-16 17:12:15 -070059
Florin Corasf8f516a2018-02-08 15:10:09 -080060 /** Session index in per_thread pool */
61 u32 session_index;
62
Florin Corasab2f6db2018-08-31 14:31:41 -070063 /** App worker pool index */
Florin Coras15531972018-08-12 23:50:53 -070064 u32 app_wrk_index;
Florin Corasf8f516a2018-02-08 15:10:09 -080065
Florin Coras04e53442017-07-16 17:12:15 -070066 u8 thread_index;
67
68 /** To avoid n**2 "one event per frame" check */
69 u8 enqueue_epoch;
70
Florin Coras04e53442017-07-16 17:12:15 -070071 /** svm segment index where fifos were allocated */
72 u32 svm_segment_index;
73
Florin Coras04e53442017-07-16 17:12:15 -070074 /** Transport specific */
75 u32 connection_index;
76
Florin Coras371ca502018-02-21 12:07:41 -080077 union
78 {
79 /** Parent listener session if the result of an accept */
80 u32 listener_index;
Florin Corasab2f6db2018-08-31 14:31:41 -070081
82 /** Application index if a listener */
83 u32 app_index;
84 };
85
86 union
87 {
88 /** Transport app index for apps acting as transports */
89 u32 t_app_index;
90
91 /** Index in listener app's listener db */
92 u32 listener_db_index;
93
Florin Coras371ca502018-02-21 12:07:41 -080094 /** Opaque, for general use */
95 u32 opaque;
96 };
Florin Coras04e53442017-07-16 17:12:15 -070097
Florin Coras0e9c33b2017-08-14 22:33:41 -070098 CLIB_CACHE_LINE_ALIGN_MARK (pad);
Florin Coras04e53442017-07-16 17:12:15 -070099} stream_session_t;
100
Florin Corasf8f516a2018-02-08 15:10:09 -0800101typedef struct local_session_
102{
103 /** fifo pointers. Once allocated, these do not move */
104 svm_fifo_t *server_rx_fifo;
105 svm_fifo_t *server_tx_fifo;
106
107 /** Type */
108 session_type_t session_type;
109
110 /** State */
111 volatile u8 session_state;
112
113 /** Session index */
114 u32 session_index;
115
116 /** Server index */
Florin Coras15531972018-08-12 23:50:53 -0700117 u32 app_wrk_index;
Florin Corasf8f516a2018-02-08 15:10:09 -0800118
Florin Corasab2f6db2018-08-31 14:31:41 -0700119 /** Port for connection. Overlaps thread_index/enqueue_epoch */
120 u16 port;
121
Florin Corasf8f516a2018-02-08 15:10:09 -0800122 /** Segment index where fifos were allocated */
123 u32 svm_segment_index;
124
Florin Corasab2f6db2018-08-31 14:31:41 -0700125 /** Transport listener index. Overlaps connection index */
126 u32 transport_listener_index;
Florin Corasf8f516a2018-02-08 15:10:09 -0800127
Florin Corasab2f6db2018-08-31 14:31:41 -0700128 union
129 {
130 u32 listener_index;
131 u32 app_index;
132 };
133
134 u32 listener_db_index;
Florin Corasf8f516a2018-02-08 15:10:09 -0800135
136 /** Has transport embedded when listener not purely local */
137 session_type_t listener_session_type;
138
139 /**
140 * Client data
141 */
Florin Coras15531972018-08-12 23:50:53 -0700142 u32 client_wrk_index;
Florin Corasf8f516a2018-02-08 15:10:09 -0800143 u32 client_opaque;
144
145 u64 server_evt_q;
146 u64 client_evt_q;
147
148 CLIB_CACHE_LINE_ALIGN_MARK (pad);
149} local_session_t;
150
Florin Coras371ca502018-02-21 12:07:41 -0800151#define foreach_session_endpoint_fields \
152 foreach_transport_connection_fields \
153 _(u8, transport_proto) \
Florin Coras371ca502018-02-21 12:07:41 -0800154
Florin Corascea194d2017-10-02 00:18:51 -0700155typedef struct _session_endpoint
156{
Florin Corascea194d2017-10-02 00:18:51 -0700157#define _(type, name) type name;
Florin Coras371ca502018-02-21 12:07:41 -0800158 foreach_session_endpoint_fields
Florin Corascea194d2017-10-02 00:18:51 -0700159#undef _
Florin Corascea194d2017-10-02 00:18:51 -0700160} session_endpoint_t;
161
Florin Coras371ca502018-02-21 12:07:41 -0800162typedef struct _session_endpoint_extended
163{
164#define _(type, name) type name;
165 foreach_session_endpoint_fields
166#undef _
Florin Coras15531972018-08-12 23:50:53 -0700167 u32 app_wrk_index;
Florin Coras371ca502018-02-21 12:07:41 -0800168 u32 opaque;
Florin Coras8f89dd02018-03-05 16:53:07 -0800169 u8 *hostname;
Florin Coras371ca502018-02-21 12:07:41 -0800170} session_endpoint_extended_t;
171
Florin Coras15531972018-08-12 23:50:53 -0700172#define SESSION_IP46_ZERO \
173{ \
174 .ip6 = { \
175 { 0, 0, }, \
176 }, \
Florin Corascea194d2017-10-02 00:18:51 -0700177}
Florin Coras15531972018-08-12 23:50:53 -0700178#define SESSION_ENDPOINT_NULL \
179{ \
Florin Corascea194d2017-10-02 00:18:51 -0700180 .sw_if_index = ENDPOINT_INVALID_INDEX, \
Florin Coras15531972018-08-12 23:50:53 -0700181 .ip = SESSION_IP46_ZERO, \
182 .fib_index = ENDPOINT_INVALID_INDEX, \
183 .is_ip4 = 0, \
184 .port = 0, \
185 .transport_proto = 0, \
Florin Coras8f89dd02018-03-05 16:53:07 -0800186}
Florin Coras15531972018-08-12 23:50:53 -0700187#define SESSION_ENDPOINT_EXT_NULL \
188{ \
Florin Coras8f89dd02018-03-05 16:53:07 -0800189 .sw_if_index = ENDPOINT_INVALID_INDEX, \
Florin Coras15531972018-08-12 23:50:53 -0700190 .ip = SESSION_IP46_ZERO, \
191 .fib_index = ENDPOINT_INVALID_INDEX, \
192 .is_ip4 = 0, \
193 .port = 0, \
194 .transport_proto = 0, \
195 .app_wrk_index = ENDPOINT_INVALID_INDEX, \
196 .opaque = ENDPOINT_INVALID_INDEX, \
Florin Coras8f89dd02018-03-05 16:53:07 -0800197 .hostname = 0, \
Florin Corascea194d2017-10-02 00:18:51 -0700198}
199
200#define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
201
202always_inline u8
203session_endpoint_fib_proto (session_endpoint_t * sep)
204{
205 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
206}
207
Florin Coras04e53442017-07-16 17:12:15 -0700208#endif /* SRC_VNET_SESSION_STREAM_SESSION_H_ */
209
210/*
211 * fd.io coding-style-patch-verification: ON
212 *
213 * Local Variables:
214 * eval: (c-set-style "gnu")
215 * End:
216 */