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 | b2371c2 | 2018-05-31 17:14:10 -0700 | [diff] [blame] | 34 | SESSION_STATE_CLOSING, |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 35 | SESSION_STATE_CLOSED, |
| 36 | SESSION_STATE_N_STATES, |
| 37 | } stream_session_state_t; |
| 38 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 39 | typedef struct generic_session_ |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 40 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 41 | 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 Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 47 | |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 48 | typedef 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 Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 55 | session_type_t session_type; |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 56 | |
| 57 | /** State */ |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 58 | volatile u8 session_state; |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 59 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 60 | /** Session index in per_thread pool */ |
| 61 | u32 session_index; |
| 62 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 63 | /** app worker pool index */ |
| 64 | u32 app_wrk_index; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 65 | |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 66 | u8 thread_index; |
| 67 | |
| 68 | /** To avoid n**2 "one event per frame" check */ |
| 69 | u8 enqueue_epoch; |
| 70 | |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 71 | /** svm segment index where fifos were allocated */ |
| 72 | u32 svm_segment_index; |
| 73 | |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 74 | /** Transport specific */ |
| 75 | u32 connection_index; |
| 76 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 77 | union |
| 78 | { |
| 79 | /** Parent listener session if the result of an accept */ |
| 80 | u32 listener_index; |
| 81 | /** Opaque, for general use */ |
| 82 | u32 opaque; |
| 83 | }; |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 84 | |
Florin Coras | 0e9c33b | 2017-08-14 22:33:41 -0700 | [diff] [blame] | 85 | CLIB_CACHE_LINE_ALIGN_MARK (pad); |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 86 | } stream_session_t; |
| 87 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 88 | typedef struct local_session_ |
| 89 | { |
| 90 | /** fifo pointers. Once allocated, these do not move */ |
| 91 | svm_fifo_t *server_rx_fifo; |
| 92 | svm_fifo_t *server_tx_fifo; |
| 93 | |
| 94 | /** Type */ |
| 95 | session_type_t session_type; |
| 96 | |
| 97 | /** State */ |
| 98 | volatile u8 session_state; |
| 99 | |
| 100 | /** Session index */ |
| 101 | u32 session_index; |
| 102 | |
| 103 | /** Server index */ |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 104 | u32 app_wrk_index; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 105 | |
| 106 | /** Segment index where fifos were allocated */ |
| 107 | u32 svm_segment_index; |
| 108 | |
| 109 | u32 listener_index; |
| 110 | |
| 111 | /** Port for connection */ |
| 112 | u16 port; |
| 113 | |
| 114 | /** Has transport embedded when listener not purely local */ |
| 115 | session_type_t listener_session_type; |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 116 | u32 transport_listener_index; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 117 | |
| 118 | /** |
| 119 | * Client data |
| 120 | */ |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 121 | u32 client_wrk_index; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 122 | u32 client_opaque; |
| 123 | |
| 124 | u64 server_evt_q; |
| 125 | u64 client_evt_q; |
| 126 | |
| 127 | CLIB_CACHE_LINE_ALIGN_MARK (pad); |
| 128 | } local_session_t; |
| 129 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 130 | #define foreach_session_endpoint_fields \ |
| 131 | foreach_transport_connection_fields \ |
| 132 | _(u8, transport_proto) \ |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 133 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 134 | typedef struct _session_endpoint |
| 135 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 136 | #define _(type, name) type name; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 137 | foreach_session_endpoint_fields |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 138 | #undef _ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 139 | } session_endpoint_t; |
| 140 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 141 | typedef struct _session_endpoint_extended |
| 142 | { |
| 143 | #define _(type, name) type name; |
| 144 | foreach_session_endpoint_fields |
| 145 | #undef _ |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 146 | u32 app_wrk_index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 147 | u32 opaque; |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 148 | u8 *hostname; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 149 | } session_endpoint_extended_t; |
| 150 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 151 | #define SESSION_IP46_ZERO \ |
| 152 | { \ |
| 153 | .ip6 = { \ |
| 154 | { 0, 0, }, \ |
| 155 | }, \ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 156 | } |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 157 | #define SESSION_ENDPOINT_NULL \ |
| 158 | { \ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 159 | .sw_if_index = ENDPOINT_INVALID_INDEX, \ |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 160 | .ip = SESSION_IP46_ZERO, \ |
| 161 | .fib_index = ENDPOINT_INVALID_INDEX, \ |
| 162 | .is_ip4 = 0, \ |
| 163 | .port = 0, \ |
| 164 | .transport_proto = 0, \ |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 165 | } |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 166 | #define SESSION_ENDPOINT_EXT_NULL \ |
| 167 | { \ |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 168 | .sw_if_index = ENDPOINT_INVALID_INDEX, \ |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 169 | .ip = SESSION_IP46_ZERO, \ |
| 170 | .fib_index = ENDPOINT_INVALID_INDEX, \ |
| 171 | .is_ip4 = 0, \ |
| 172 | .port = 0, \ |
| 173 | .transport_proto = 0, \ |
| 174 | .app_wrk_index = ENDPOINT_INVALID_INDEX, \ |
| 175 | .opaque = ENDPOINT_INVALID_INDEX, \ |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 176 | .hostname = 0, \ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep) |
| 180 | |
| 181 | always_inline u8 |
| 182 | session_endpoint_fib_proto (session_endpoint_t * sep) |
| 183 | { |
| 184 | return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; |
| 185 | } |
| 186 | |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 187 | #endif /* SRC_VNET_SESSION_STREAM_SESSION_H_ */ |
| 188 | |
| 189 | /* |
| 190 | * fd.io coding-style-patch-verification: ON |
| 191 | * |
| 192 | * Local Variables: |
| 193 | * eval: (c-set-style "gnu") |
| 194 | * End: |
| 195 | */ |