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 | |
| 19 | #include <vnet/vnet.h> |
| 20 | #include <svm/svm_fifo.h> |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 21 | #include <vnet/session/transport.h> |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 22 | |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 23 | typedef u8 session_type_t; |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 24 | |
| 25 | /* |
| 26 | * Application session state |
| 27 | */ |
| 28 | typedef enum |
| 29 | { |
| 30 | SESSION_STATE_LISTENING, |
| 31 | SESSION_STATE_CONNECTING, |
| 32 | SESSION_STATE_ACCEPTING, |
| 33 | SESSION_STATE_READY, |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 34 | SESSION_STATE_CONNECTING_READY, |
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 | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 39 | /* TODO convert to macro once cleanup completed */ |
| 40 | typedef 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 Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 59 | typedef 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 Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 66 | session_type_t session_type; |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 67 | |
| 68 | /** State */ |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 69 | volatile u8 session_state; |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 70 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 71 | /** Session index in per_thread pool */ |
| 72 | u32 session_index; |
| 73 | |
| 74 | /** stream server pool index */ |
| 75 | u32 app_index; |
| 76 | |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 77 | u8 thread_index; |
| 78 | |
| 79 | /** To avoid n**2 "one event per frame" check */ |
| 80 | u8 enqueue_epoch; |
| 81 | |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 82 | /** svm segment index where fifos were allocated */ |
| 83 | u32 svm_segment_index; |
| 84 | |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 85 | /** Transport specific */ |
| 86 | u32 connection_index; |
| 87 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 88 | union |
| 89 | { |
| 90 | /** Parent listener session if the result of an accept */ |
| 91 | u32 listener_index; |
| 92 | /** Opaque, for general use */ |
| 93 | u32 opaque; |
| 94 | }; |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 95 | |
Florin Coras | 0e9c33b | 2017-08-14 22:33:41 -0700 | [diff] [blame] | 96 | CLIB_CACHE_LINE_ALIGN_MARK (pad); |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 97 | } stream_session_t; |
| 98 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 99 | typedef struct local_session_ |
| 100 | { |
| 101 | /** fifo pointers. Once allocated, these do not move */ |
| 102 | svm_fifo_t *server_rx_fifo; |
| 103 | svm_fifo_t *server_tx_fifo; |
| 104 | |
| 105 | /** Type */ |
| 106 | session_type_t session_type; |
| 107 | |
| 108 | /** State */ |
| 109 | volatile u8 session_state; |
| 110 | |
| 111 | /** Session index */ |
| 112 | u32 session_index; |
| 113 | |
| 114 | /** Server index */ |
| 115 | u32 app_index; |
| 116 | |
| 117 | /** Segment index where fifos were allocated */ |
| 118 | u32 svm_segment_index; |
| 119 | |
| 120 | u32 listener_index; |
| 121 | |
| 122 | /** Port for connection */ |
| 123 | u16 port; |
| 124 | |
| 125 | /** Has transport embedded when listener not purely local */ |
| 126 | session_type_t listener_session_type; |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 127 | u32 transport_listener_index; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 128 | |
| 129 | /** |
| 130 | * Client data |
| 131 | */ |
| 132 | u32 client_index; |
| 133 | u32 client_opaque; |
| 134 | |
| 135 | u64 server_evt_q; |
| 136 | u64 client_evt_q; |
| 137 | |
| 138 | CLIB_CACHE_LINE_ALIGN_MARK (pad); |
| 139 | } local_session_t; |
| 140 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 141 | #define foreach_session_endpoint_fields \ |
| 142 | foreach_transport_connection_fields \ |
| 143 | _(u8, transport_proto) \ |
| 144 | _(u8, app_proto) \ |
| 145 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 146 | typedef struct _session_endpoint |
| 147 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 148 | #define _(type, name) type name; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 149 | foreach_session_endpoint_fields |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 150 | #undef _ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 151 | } session_endpoint_t; |
| 152 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 153 | typedef struct _session_endpoint_extended |
| 154 | { |
| 155 | #define _(type, name) type name; |
| 156 | foreach_session_endpoint_fields |
| 157 | #undef _ |
| 158 | u32 app_index; |
| 159 | u32 opaque; |
| 160 | } session_endpoint_extended_t; |
| 161 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 162 | #define SESSION_IP46_ZERO \ |
| 163 | { \ |
| 164 | .ip6 = { \ |
| 165 | { 0, 0, }, \ |
| 166 | }, \ |
| 167 | } |
| 168 | #define SESSION_ENDPOINT_NULL \ |
| 169 | { \ |
| 170 | .sw_if_index = ENDPOINT_INVALID_INDEX, \ |
| 171 | .ip = SESSION_IP46_ZERO, \ |
| 172 | .fib_index = ENDPOINT_INVALID_INDEX, \ |
| 173 | .is_ip4 = 0, \ |
| 174 | .port = 0, \ |
| 175 | .transport_proto = 0, \ |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 176 | .app_proto = 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 | */ |