tcp: fix fin_wait_1 condition to send fin
[vpp.git] / src / vnet / session / stream_session.h
1 /*
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 <svm/svm_fifo.h>
20 #include <vnet/session/transport.h>
21
22 typedef u8 session_type_t;
23
24 /*
25  * Application session state
26  */
27 typedef enum
28 {
29   SESSION_STATE_LISTENING,
30   SESSION_STATE_CONNECTING,
31   SESSION_STATE_ACCEPTING,
32   SESSION_STATE_READY,
33   SESSION_STATE_OPENED,
34   SESSION_STATE_TRANSPORT_CLOSING,
35   SESSION_STATE_CLOSING,
36   SESSION_STATE_CLOSED_WAITING,
37   SESSION_STATE_CLOSED,
38   SESSION_STATE_N_STATES,
39 } stream_session_state_t;
40
41 typedef struct generic_session_
42 {
43   svm_fifo_t *rx_fifo;          /**< rx fifo */
44   svm_fifo_t *tx_fifo;          /**< tx fifo */
45   session_type_t session_type;  /**< session type */
46   volatile u8 session_state;    /**< session state */
47   u32 session_index;            /**< index in owning pool */
48 } generic_session_t;
49
50 typedef struct _stream_session_t
51 {
52   /** fifo pointers. Once allocated, these do not move */
53   svm_fifo_t *server_rx_fifo;
54   svm_fifo_t *server_tx_fifo;
55
56   /** Type */
57   session_type_t session_type;
58
59   /** State */
60   volatile u8 session_state;
61
62   /** Session index in per_thread pool */
63   u32 session_index;
64
65   /** App worker pool index */
66   u32 app_wrk_index;
67
68   u8 thread_index;
69
70   /** To avoid n**2 "one event per frame" check */
71   u64 enqueue_epoch;
72
73   /** svm segment index where fifos were allocated */
74   u32 svm_segment_index;
75
76   /** Transport specific */
77   u32 connection_index;
78
79   union
80   {
81     /** Parent listener session if the result of an accept */
82     u32 listener_index;
83
84     /** Application index if a listener */
85     u32 app_index;
86   };
87
88   union
89   {
90     /** Transport app index for apps acting as transports */
91     u32 t_app_index;
92
93     /** Index in listener app's listener db */
94     u32 listener_db_index;
95
96     /** Opaque, for general use */
97     u32 opaque;
98   };
99
100     CLIB_CACHE_LINE_ALIGN_MARK (pad);
101 } stream_session_t;
102
103 typedef struct local_session_
104 {
105   /** fifo pointers. Once allocated, these do not move */
106   svm_fifo_t *server_rx_fifo;
107   svm_fifo_t *server_tx_fifo;
108
109   /** Type */
110   session_type_t session_type;
111
112   /** State */
113   volatile u8 session_state;
114
115   /** Session index */
116   u32 session_index;
117
118   /** Server index */
119   u32 app_wrk_index;
120
121   /** Port for connection. Overlaps thread_index/enqueue_epoch */
122   u16 port;
123
124   /** Partly overlaps enqueue_epoch */
125   u8 pad_epoch[7];
126
127   /** Segment index where fifos were allocated */
128   u32 svm_segment_index;
129
130   /** Transport listener index. Overlaps connection index */
131   u32 transport_listener_index;
132
133   union
134   {
135     u32 listener_index;
136     u32 app_index;
137   };
138
139   u32 listener_db_index;
140
141   /** Has transport embedded when listener not purely local */
142   session_type_t listener_session_type;
143
144   /**
145    * Client data
146    */
147   u32 client_wrk_index;
148   u32 client_opaque;
149
150   u64 server_evt_q;
151   u64 client_evt_q;
152
153     CLIB_CACHE_LINE_ALIGN_MARK (pad);
154 } local_session_t;
155
156 #define foreach_session_endpoint_fields                         \
157   foreach_transport_endpoint_cfg_fields                         \
158   _(u8, transport_proto)                                        \
159
160 typedef struct _session_endpoint
161 {
162 #define _(type, name) type name;
163   foreach_session_endpoint_fields
164 #undef _
165 } session_endpoint_t;
166
167 typedef struct _session_endpoint_cfg
168 {
169 #define _(type, name) type name;
170   foreach_session_endpoint_fields
171 #undef _
172   u32 app_wrk_index;
173   u32 opaque;
174   u8 *hostname;
175 } session_endpoint_cfg_t;
176
177 #define SESSION_IP46_ZERO                       \
178 {                                               \
179     .ip6 = {                                    \
180         { 0, 0, },                              \
181     },                                          \
182 }
183
184 #define TRANSPORT_ENDPOINT_NULL                 \
185 {                                               \
186   .sw_if_index = ENDPOINT_INVALID_INDEX,        \
187   .ip = SESSION_IP46_ZERO,                      \
188   .fib_index = ENDPOINT_INVALID_INDEX,          \
189   .is_ip4 = 0,                                  \
190   .port = 0,                                    \
191 }
192 #define SESSION_ENDPOINT_NULL                   \
193 {                                               \
194   .sw_if_index = ENDPOINT_INVALID_INDEX,        \
195   .ip = SESSION_IP46_ZERO,                      \
196   .fib_index = ENDPOINT_INVALID_INDEX,          \
197   .is_ip4 = 0,                                  \
198   .port = 0,                                    \
199   .peer = TRANSPORT_ENDPOINT_NULL,              \
200   .transport_proto = 0,                         \
201 }
202 #define SESSION_ENDPOINT_CFG_NULL               \
203 {                                               \
204   .sw_if_index = ENDPOINT_INVALID_INDEX,        \
205   .ip = SESSION_IP46_ZERO,                      \
206   .fib_index = ENDPOINT_INVALID_INDEX,          \
207   .is_ip4 = 0,                                  \
208   .port = 0,                                    \
209   .peer = TRANSPORT_ENDPOINT_NULL,              \
210   .transport_proto = 0,                         \
211   .app_wrk_index = ENDPOINT_INVALID_INDEX,      \
212   .opaque = ENDPOINT_INVALID_INDEX,             \
213   .hostname = 0,                                \
214 }
215
216 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
217 #define session_endpoint_to_transport_cfg(_sep)         \
218   ((transport_endpoint_cfg_t *)_sep)
219
220 always_inline u8
221 session_endpoint_fib_proto (session_endpoint_t * sep)
222 {
223   return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
224 }
225
226 #endif /* SRC_VNET_SESSION_STREAM_SESSION_H_ */
227
228 /*
229  * fd.io coding-style-patch-verification: ON
230  *
231  * Local Variables:
232  * eval: (c-set-style "gnu")
233  * End:
234  */