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