blob: 5c4601daa3106ebcfb610125a82964ae1edf56a4 [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 Coras3cbc04b2017-10-02 00:18:51 -070034 SESSION_STATE_CONNECTING_READY,
Florin Coras04e53442017-07-16 17:12:15 -070035 SESSION_STATE_CLOSED,
36 SESSION_STATE_N_STATES,
37} stream_session_state_t;
38
Florin Corasf8f516a2018-02-08 15:10:09 -080039/* TODO convert to macro once cleanup completed */
40typedef struct app_session_
41{
42 /** fifo pointers. Once allocated, these do not move */
43 svm_fifo_t *server_rx_fifo;
44 svm_fifo_t *server_tx_fifo;
45
46 /** Type */
47 session_type_t session_type;
48
49 /** State */
50 volatile u8 session_state;
51
52 /** Session index in owning pool */
53 u32 session_index;
54
55 /** Application index */
56 u32 app_index;
57} app_session_t;
58
Florin Coras04e53442017-07-16 17:12:15 -070059typedef struct _stream_session_t
60{
61 /** fifo pointers. Once allocated, these do not move */
62 svm_fifo_t *server_rx_fifo;
63 svm_fifo_t *server_tx_fifo;
64
65 /** Type */
Florin Coras561af9b2017-12-09 10:19:43 -080066 session_type_t session_type;
Florin Coras04e53442017-07-16 17:12:15 -070067
68 /** State */
Florin Coras1f152cd2017-08-18 19:28:03 -070069 volatile u8 session_state;
Florin Coras04e53442017-07-16 17:12:15 -070070
Florin Corasf8f516a2018-02-08 15:10:09 -080071 /** Session index in per_thread pool */
72 u32 session_index;
73
74 /** stream server pool index */
75 u32 app_index;
76
Florin Coras04e53442017-07-16 17:12:15 -070077 u8 thread_index;
78
79 /** To avoid n**2 "one event per frame" check */
80 u8 enqueue_epoch;
81
Florin Coras04e53442017-07-16 17:12:15 -070082 /** svm segment index where fifos were allocated */
83 u32 svm_segment_index;
84
Florin Coras04e53442017-07-16 17:12:15 -070085 /** Transport specific */
86 u32 connection_index;
87
Florin Coras04e53442017-07-16 17:12:15 -070088 /** Parent listener session if the result of an accept */
89 u32 listener_index;
90
Florin Coras0e9c33b2017-08-14 22:33:41 -070091 CLIB_CACHE_LINE_ALIGN_MARK (pad);
Florin Coras04e53442017-07-16 17:12:15 -070092} stream_session_t;
93
Florin Corasf8f516a2018-02-08 15:10:09 -080094typedef struct local_session_
95{
96 /** fifo pointers. Once allocated, these do not move */
97 svm_fifo_t *server_rx_fifo;
98 svm_fifo_t *server_tx_fifo;
99
100 /** Type */
101 session_type_t session_type;
102
103 /** State */
104 volatile u8 session_state;
105
106 /** Session index */
107 u32 session_index;
108
109 /** Server index */
110 u32 app_index;
111
112 /** Segment index where fifos were allocated */
113 u32 svm_segment_index;
114
115 u32 listener_index;
116
117 /** Port for connection */
118 u16 port;
119
120 /** Has transport embedded when listener not purely local */
121 session_type_t listener_session_type;
Florin Coras5fda7a32018-02-14 08:04:31 -0800122 u32 transport_listener_index;
Florin Corasf8f516a2018-02-08 15:10:09 -0800123
124 /**
125 * Client data
126 */
127 u32 client_index;
128 u32 client_opaque;
129
130 u64 server_evt_q;
131 u64 client_evt_q;
132
133 CLIB_CACHE_LINE_ALIGN_MARK (pad);
134} local_session_t;
135
Florin Corascea194d2017-10-02 00:18:51 -0700136typedef struct _session_endpoint
137{
138 /*
139 * Network specific
140 */
141#define _(type, name) type name;
142 foreach_transport_connection_fields
143#undef _
144 /*
145 * Session specific
146 */
147 u8 transport_proto; /**< transport protocol for session */
148} session_endpoint_t;
149
150#define SESSION_IP46_ZERO \
151{ \
152 .ip6 = { \
153 { 0, 0, }, \
154 }, \
155}
156#define SESSION_ENDPOINT_NULL \
157{ \
158 .sw_if_index = ENDPOINT_INVALID_INDEX, \
159 .ip = SESSION_IP46_ZERO, \
160 .fib_index = ENDPOINT_INVALID_INDEX, \
161 .is_ip4 = 0, \
162 .port = 0, \
163 .transport_proto = 0, \
164}
165
166#define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
167
168always_inline u8
169session_endpoint_fib_proto (session_endpoint_t * sep)
170{
171 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
172}
173
Florin Coras04e53442017-07-16 17:12:15 -0700174#endif /* SRC_VNET_SESSION_STREAM_SESSION_H_ */
175
176/*
177 * fd.io coding-style-patch-verification: ON
178 *
179 * Local Variables:
180 * eval: (c-set-style "gnu")
181 * End:
182 */