Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-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 | #include <vnet/vnet.h> |
| 17 | #include <vlibmemory/api.h> |
| 18 | #include <vnet/session/application.h> |
| 19 | #include <vnet/session/application_interface.h> |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 20 | #include <vnet/session-apps/proxy.h> |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 21 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 22 | proxy_main_t proxy_main; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 23 | |
Florin Coras | cd330c8 | 2018-05-09 17:33:00 -0700 | [diff] [blame] | 24 | typedef struct |
| 25 | { |
| 26 | char uri[128]; |
| 27 | u32 app_index; |
| 28 | u32 api_context; |
| 29 | } proxy_connect_args_t; |
| 30 | |
| 31 | static void |
| 32 | proxy_cb_fn (void *data, u32 data_len) |
| 33 | { |
| 34 | proxy_connect_args_t *pa = (proxy_connect_args_t *) data; |
| 35 | vnet_connect_args_t a; |
| 36 | |
Florin Coras | 8966638 | 2018-11-09 13:40:02 -0800 | [diff] [blame] | 37 | memset (&a, 0, sizeof (a)); |
Florin Coras | cd330c8 | 2018-05-09 17:33:00 -0700 | [diff] [blame] | 38 | a.api_context = pa->api_context; |
| 39 | a.app_index = pa->app_index; |
| 40 | a.uri = pa->uri; |
| 41 | vnet_connect_uri (&a); |
| 42 | } |
| 43 | |
| 44 | static void |
| 45 | proxy_call_main_thread (vnet_connect_args_t * a) |
| 46 | { |
| 47 | if (vlib_get_thread_index () == 0) |
| 48 | { |
| 49 | vnet_connect_uri (a); |
| 50 | } |
| 51 | else |
| 52 | { |
| 53 | proxy_connect_args_t args; |
| 54 | args.api_context = a->api_context; |
| 55 | args.app_index = a->app_index; |
| 56 | clib_memcpy (args.uri, a->uri, vec_len (a->uri)); |
| 57 | vl_api_rpc_call_main_thread (proxy_cb_fn, (u8 *) & args, sizeof (args)); |
| 58 | } |
| 59 | } |
| 60 | |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 61 | static void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 62 | delete_proxy_session (session_t * s, int is_active_open) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 63 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 64 | proxy_main_t *pm = &proxy_main; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 65 | proxy_session_t *ps = 0; |
| 66 | vnet_disconnect_args_t _a, *a = &_a; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 67 | session_t *active_open_session = 0; |
| 68 | session_t *server_session = 0; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 69 | uword *p; |
| 70 | u64 handle; |
| 71 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 72 | handle = session_handle (s); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 73 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 74 | clib_spinlock_lock_if_init (&pm->sessions_lock); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 75 | if (is_active_open) |
| 76 | { |
| 77 | active_open_session = s; |
| 78 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 79 | p = hash_get (pm->proxy_session_by_active_open_handle, handle); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 80 | if (p == 0) |
| 81 | { |
| 82 | clib_warning ("proxy session for %s handle %lld (%llx) AWOL", |
| 83 | is_active_open ? "active open" : "server", |
| 84 | handle, handle); |
| 85 | } |
Florin Coras | cd330c8 | 2018-05-09 17:33:00 -0700 | [diff] [blame] | 86 | else if (!pool_is_free_index (pm->sessions, p[0])) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 87 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 88 | ps = pool_elt_at_index (pm->sessions, p[0]); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 89 | if (ps->vpp_server_handle != ~0) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 90 | server_session = session_get_from_handle (ps->vpp_server_handle); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 91 | else |
| 92 | server_session = 0; |
| 93 | } |
| 94 | } |
| 95 | else |
| 96 | { |
| 97 | server_session = s; |
| 98 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 99 | p = hash_get (pm->proxy_session_by_server_handle, handle); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 100 | if (p == 0) |
| 101 | { |
| 102 | clib_warning ("proxy session for %s handle %lld (%llx) AWOL", |
| 103 | is_active_open ? "active open" : "server", |
| 104 | handle, handle); |
| 105 | } |
Florin Coras | cd330c8 | 2018-05-09 17:33:00 -0700 | [diff] [blame] | 106 | else if (!pool_is_free_index (pm->sessions, p[0])) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 107 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 108 | ps = pool_elt_at_index (pm->sessions, p[0]); |
Florin Coras | 70816f0 | 2018-05-14 01:44:01 -0700 | [diff] [blame] | 109 | if (ps->vpp_active_open_handle != ~0) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 110 | active_open_session = session_get_from_handle |
Florin Coras | 70816f0 | 2018-05-14 01:44:01 -0700 | [diff] [blame] | 111 | (ps->vpp_active_open_handle); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 112 | else |
| 113 | active_open_session = 0; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | if (ps) |
| 118 | { |
| 119 | if (CLIB_DEBUG > 0) |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 120 | clib_memset (ps, 0xFE, sizeof (*ps)); |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 121 | pool_put (pm->sessions, ps); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 122 | } |
| 123 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 124 | clib_spinlock_unlock_if_init (&pm->sessions_lock); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 125 | |
| 126 | if (active_open_session) |
| 127 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 128 | a->handle = session_handle (active_open_session); |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 129 | a->app_index = pm->active_open_app_index; |
| 130 | hash_unset (pm->proxy_session_by_active_open_handle, |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 131 | session_handle (active_open_session)); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 132 | vnet_disconnect_session (a); |
| 133 | } |
| 134 | |
| 135 | if (server_session) |
| 136 | { |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 137 | a->handle = session_handle (server_session); |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 138 | a->app_index = pm->server_app_index; |
| 139 | hash_unset (pm->proxy_session_by_server_handle, |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 140 | session_handle (server_session)); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 141 | vnet_disconnect_session (a); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | static int |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 146 | proxy_accept_callback (session_t * s) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 147 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 148 | proxy_main_t *pm = &proxy_main; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 149 | |
| 150 | s->session_state = SESSION_STATE_READY; |
| 151 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 152 | clib_spinlock_lock_if_init (&pm->sessions_lock); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | static void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 158 | proxy_disconnect_callback (session_t * s) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 159 | { |
| 160 | delete_proxy_session (s, 0 /* is_active_open */ ); |
| 161 | } |
| 162 | |
| 163 | static void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 164 | proxy_reset_callback (session_t * s) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 165 | { |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame^] | 166 | clib_warning ("Reset session %U", format_session, s, 2); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 167 | delete_proxy_session (s, 0 /* is_active_open */ ); |
| 168 | } |
| 169 | |
| 170 | static int |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 171 | proxy_connected_callback (u32 app_index, u32 api_context, |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 172 | session_t * s, u8 is_fail) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 173 | { |
| 174 | clib_warning ("called..."); |
| 175 | return -1; |
| 176 | } |
| 177 | |
| 178 | static int |
Florin Coras | fa76a76 | 2018-11-29 12:40:10 -0800 | [diff] [blame] | 179 | proxy_add_segment_callback (u32 client_index, u64 segment_handle) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 180 | { |
| 181 | clib_warning ("called..."); |
| 182 | return -1; |
| 183 | } |
| 184 | |
| 185 | static int |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 186 | proxy_rx_callback (session_t * s) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 187 | { |
| 188 | u32 max_dequeue; |
| 189 | int actual_transfer __attribute__ ((unused)); |
| 190 | svm_fifo_t *tx_fifo, *rx_fifo; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 191 | proxy_main_t *pm = &proxy_main; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 192 | u32 thread_index = vlib_get_thread_index (); |
| 193 | vnet_connect_args_t _a, *a = &_a; |
| 194 | proxy_session_t *ps; |
| 195 | int proxy_index; |
| 196 | uword *p; |
| 197 | svm_fifo_t *active_open_tx_fifo; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 198 | |
| 199 | ASSERT (s->thread_index == thread_index); |
| 200 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 201 | clib_spinlock_lock_if_init (&pm->sessions_lock); |
| 202 | p = hash_get (pm->proxy_session_by_server_handle, session_handle (s)); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 203 | |
| 204 | if (PREDICT_TRUE (p != 0)) |
| 205 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 206 | clib_spinlock_unlock_if_init (&pm->sessions_lock); |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 207 | active_open_tx_fifo = s->rx_fifo; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * Send event for active open tx fifo |
| 211 | */ |
| 212 | if (svm_fifo_set_event (active_open_tx_fifo)) |
| 213 | { |
Florin Coras | cd330c8 | 2018-05-09 17:33:00 -0700 | [diff] [blame] | 214 | u32 ao_thread_index = active_open_tx_fifo->master_thread_index; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 215 | if (session_send_io_evt_to_thread_custom (active_open_tx_fifo, |
| 216 | ao_thread_index, |
Florin Coras | f6c4313 | 2019-03-01 12:41:21 -0800 | [diff] [blame] | 217 | SESSION_IO_EVT_TX)) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 218 | clib_warning ("failed to enqueue tx evt"); |
| 219 | } |
| 220 | } |
| 221 | else |
| 222 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 223 | rx_fifo = s->rx_fifo; |
| 224 | tx_fifo = s->tx_fifo; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 225 | |
| 226 | ASSERT (rx_fifo->master_thread_index == thread_index); |
| 227 | ASSERT (tx_fifo->master_thread_index == thread_index); |
| 228 | |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 229 | max_dequeue = svm_fifo_max_dequeue (s->rx_fifo); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 230 | |
| 231 | if (PREDICT_FALSE (max_dequeue == 0)) |
| 232 | return 0; |
| 233 | |
| 234 | actual_transfer = svm_fifo_peek (rx_fifo, 0 /* relative_offset */ , |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 235 | max_dequeue, pm->rx_buf[thread_index]); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 236 | |
| 237 | /* $$$ your message in this space: parse url, etc. */ |
| 238 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 239 | clib_memset (a, 0, sizeof (*a)); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 240 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 241 | clib_spinlock_lock_if_init (&pm->sessions_lock); |
| 242 | pool_get (pm->sessions, ps); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 243 | clib_memset (ps, 0, sizeof (*ps)); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 244 | ps->server_rx_fifo = rx_fifo; |
| 245 | ps->server_tx_fifo = tx_fifo; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 246 | ps->vpp_server_handle = session_handle (s); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 247 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 248 | proxy_index = ps - pm->sessions; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 249 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 250 | hash_set (pm->proxy_session_by_server_handle, ps->vpp_server_handle, |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 251 | proxy_index); |
| 252 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 253 | clib_spinlock_unlock_if_init (&pm->sessions_lock); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 254 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 255 | a->uri = (char *) pm->client_uri; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 256 | a->api_context = proxy_index; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 257 | a->app_index = pm->active_open_app_index; |
Florin Coras | cd330c8 | 2018-05-09 17:33:00 -0700 | [diff] [blame] | 258 | proxy_call_main_thread (a); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 264 | static session_cb_vft_t proxy_session_cb_vft = { |
| 265 | .session_accept_callback = proxy_accept_callback, |
| 266 | .session_disconnect_callback = proxy_disconnect_callback, |
| 267 | .session_connected_callback = proxy_connected_callback, |
| 268 | .add_segment_callback = proxy_add_segment_callback, |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 269 | .builtin_app_rx_callback = proxy_rx_callback, |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 270 | .session_reset_callback = proxy_reset_callback |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 271 | }; |
| 272 | |
| 273 | static int |
| 274 | active_open_connected_callback (u32 app_index, u32 opaque, |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 275 | session_t * s, u8 is_fail) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 276 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 277 | proxy_main_t *pm = &proxy_main; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 278 | proxy_session_t *ps; |
| 279 | u8 thread_index = vlib_get_thread_index (); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 280 | |
| 281 | if (is_fail) |
| 282 | { |
| 283 | clib_warning ("connection %d failed!", opaque); |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | * Setup proxy session handle. |
| 289 | */ |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 290 | clib_spinlock_lock_if_init (&pm->sessions_lock); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 291 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 292 | ps = pool_elt_at_index (pm->sessions, opaque); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 293 | ps->vpp_active_open_handle = session_handle (s); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 294 | |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 295 | s->tx_fifo = ps->server_rx_fifo; |
| 296 | s->rx_fifo = ps->server_tx_fifo; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 297 | |
| 298 | /* |
| 299 | * Reset the active-open tx-fifo master indices so the active-open session |
| 300 | * will receive data, etc. |
| 301 | */ |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 302 | s->tx_fifo->master_session_index = s->session_index; |
| 303 | s->tx_fifo->master_thread_index = s->thread_index; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 304 | |
| 305 | /* |
| 306 | * Account for the active-open session's use of the fifos |
| 307 | * so they won't disappear until the last session which uses |
| 308 | * them disappears |
| 309 | */ |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 310 | s->tx_fifo->refcnt++; |
| 311 | s->rx_fifo->refcnt++; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 312 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 313 | hash_set (pm->proxy_session_by_active_open_handle, |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 314 | ps->vpp_active_open_handle, opaque); |
| 315 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 316 | clib_spinlock_unlock_if_init (&pm->sessions_lock); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 317 | |
| 318 | /* |
| 319 | * Send event for active open tx fifo |
| 320 | */ |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 321 | ASSERT (s->thread_index == thread_index); |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 322 | if (svm_fifo_set_event (s->tx_fifo)) |
Florin Coras | f6c4313 | 2019-03-01 12:41:21 -0800 | [diff] [blame] | 323 | session_send_io_evt_to_thread (s->tx_fifo, SESSION_IO_EVT_TX); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 324 | |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | static void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 329 | active_open_reset_callback (session_t * s) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 330 | { |
| 331 | delete_proxy_session (s, 1 /* is_active_open */ ); |
| 332 | } |
| 333 | |
| 334 | static int |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 335 | active_open_create_callback (session_t * s) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 336 | { |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | static void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 341 | active_open_disconnect_callback (session_t * s) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 342 | { |
| 343 | delete_proxy_session (s, 1 /* is_active_open */ ); |
| 344 | } |
| 345 | |
| 346 | static int |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 347 | active_open_rx_callback (session_t * s) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 348 | { |
Florin Coras | cd330c8 | 2018-05-09 17:33:00 -0700 | [diff] [blame] | 349 | svm_fifo_t *proxy_tx_fifo; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 350 | |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 351 | proxy_tx_fifo = s->rx_fifo; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 352 | |
| 353 | /* |
| 354 | * Send event for server tx fifo |
| 355 | */ |
Florin Coras | cd330c8 | 2018-05-09 17:33:00 -0700 | [diff] [blame] | 356 | if (svm_fifo_set_event (proxy_tx_fifo)) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 357 | { |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 358 | u8 thread_index = proxy_tx_fifo->master_thread_index; |
| 359 | return session_send_io_evt_to_thread_custom (proxy_tx_fifo, |
| 360 | thread_index, |
Florin Coras | f6c4313 | 2019-03-01 12:41:21 -0800 | [diff] [blame] | 361 | SESSION_IO_EVT_TX); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | /* *INDENT-OFF* */ |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 368 | static session_cb_vft_t active_open_clients = { |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 369 | .session_reset_callback = active_open_reset_callback, |
| 370 | .session_connected_callback = active_open_connected_callback, |
| 371 | .session_accept_callback = active_open_create_callback, |
| 372 | .session_disconnect_callback = active_open_disconnect_callback, |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 373 | .builtin_app_rx_callback = active_open_rx_callback |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 374 | }; |
| 375 | /* *INDENT-ON* */ |
| 376 | |
| 377 | |
| 378 | static void |
| 379 | create_api_loopbacks (vlib_main_t * vm) |
| 380 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 381 | proxy_main_t *pm = &proxy_main; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 382 | api_main_t *am = &api_main; |
| 383 | vl_shmem_hdr_t *shmem_hdr; |
| 384 | |
| 385 | shmem_hdr = am->shmem_hdr; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 386 | pm->vl_input_queue = shmem_hdr->vl_input_queue; |
| 387 | pm->server_client_index = |
| 388 | vl_api_memclnt_create_internal ("proxy_server", pm->vl_input_queue); |
| 389 | pm->active_open_client_index = |
| 390 | vl_api_memclnt_create_internal ("proxy_active_open", pm->vl_input_queue); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | static int |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 394 | proxy_server_attach () |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 395 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 396 | proxy_main_t *pm = &proxy_main; |
Florin Coras | ff6e769 | 2017-12-11 04:59:01 -0800 | [diff] [blame] | 397 | u64 options[APP_OPTIONS_N_OPTIONS]; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 398 | vnet_app_attach_args_t _a, *a = &_a; |
Florin Coras | ff6e769 | 2017-12-11 04:59:01 -0800 | [diff] [blame] | 399 | u32 segment_size = 512 << 20; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 400 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 401 | clib_memset (a, 0, sizeof (*a)); |
| 402 | clib_memset (options, 0, sizeof (options)); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 403 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 404 | if (pm->private_segment_size) |
| 405 | segment_size = pm->private_segment_size; |
| 406 | a->api_client_index = pm->server_client_index; |
| 407 | a->session_cb_vft = &proxy_session_cb_vft; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 408 | a->options = options; |
Florin Coras | ff6e769 | 2017-12-11 04:59:01 -0800 | [diff] [blame] | 409 | a->options[APP_OPTIONS_SEGMENT_SIZE] = segment_size; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 410 | a->options[APP_OPTIONS_RX_FIFO_SIZE] = pm->fifo_size; |
| 411 | a->options[APP_OPTIONS_TX_FIFO_SIZE] = pm->fifo_size; |
| 412 | a->options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = pm->private_segment_count; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 413 | a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = |
Florin Coras | 25579b4 | 2018-06-06 17:55:02 -0700 | [diff] [blame] | 414 | pm->prealloc_fifos ? pm->prealloc_fifos : 0; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 415 | |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 416 | a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 417 | |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 418 | if (vnet_application_attach (a)) |
| 419 | { |
| 420 | clib_warning ("failed to attach server"); |
| 421 | return -1; |
| 422 | } |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 423 | pm->server_app_index = a->app_index; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | static int |
| 429 | active_open_attach (void) |
| 430 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 431 | proxy_main_t *pm = &proxy_main; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 432 | vnet_app_attach_args_t _a, *a = &_a; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 433 | u64 options[16]; |
| 434 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 435 | clib_memset (a, 0, sizeof (*a)); |
| 436 | clib_memset (options, 0, sizeof (options)); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 437 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 438 | a->api_client_index = pm->active_open_client_index; |
| 439 | a->session_cb_vft = &active_open_clients; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 440 | |
Florin Coras | ff6e769 | 2017-12-11 04:59:01 -0800 | [diff] [blame] | 441 | options[APP_OPTIONS_ACCEPT_COOKIE] = 0x12345678; |
| 442 | options[APP_OPTIONS_SEGMENT_SIZE] = 512 << 20; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 443 | options[APP_OPTIONS_RX_FIFO_SIZE] = pm->fifo_size; |
| 444 | options[APP_OPTIONS_TX_FIFO_SIZE] = pm->fifo_size; |
| 445 | options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = pm->private_segment_count; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 446 | options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = |
Florin Coras | 25579b4 | 2018-06-06 17:55:02 -0700 | [diff] [blame] | 447 | pm->prealloc_fifos ? pm->prealloc_fifos : 0; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 448 | |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 449 | options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 450 | | APP_OPTIONS_FLAGS_IS_PROXY; |
| 451 | |
| 452 | a->options = options; |
| 453 | |
| 454 | if (vnet_application_attach (a)) |
| 455 | return -1; |
| 456 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 457 | pm->active_open_app_index = a->app_index; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | static int |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 463 | proxy_server_listen () |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 464 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 465 | proxy_main_t *pm = &proxy_main; |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 466 | vnet_listen_args_t _a, *a = &_a; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 467 | clib_memset (a, 0, sizeof (*a)); |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 468 | a->app_index = pm->server_app_index; |
| 469 | a->uri = (char *) pm->server_uri; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 470 | return vnet_bind_uri (a); |
| 471 | } |
| 472 | |
| 473 | static int |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 474 | proxy_server_create (vlib_main_t * vm) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 475 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 476 | proxy_main_t *pm = &proxy_main; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 477 | vlib_thread_main_t *vtm = vlib_get_thread_main (); |
| 478 | u32 num_threads; |
| 479 | int i; |
| 480 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 481 | if (pm->server_client_index == (u32) ~ 0) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 482 | create_api_loopbacks (vm); |
| 483 | |
| 484 | num_threads = 1 /* main thread */ + vtm->n_threads; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 485 | vec_validate (proxy_main.server_event_queue, num_threads - 1); |
| 486 | vec_validate (proxy_main.active_open_event_queue, num_threads - 1); |
| 487 | vec_validate (pm->rx_buf, num_threads - 1); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 488 | |
| 489 | for (i = 0; i < num_threads; i++) |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 490 | vec_validate (pm->rx_buf[i], pm->rcv_buffer_size); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 491 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 492 | if (proxy_server_attach ()) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 493 | { |
| 494 | clib_warning ("failed to attach server app"); |
| 495 | return -1; |
| 496 | } |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 497 | if (proxy_server_listen ()) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 498 | { |
| 499 | clib_warning ("failed to start listening"); |
| 500 | return -1; |
| 501 | } |
| 502 | if (active_open_attach ()) |
| 503 | { |
| 504 | clib_warning ("failed to attach active open app"); |
| 505 | return -1; |
| 506 | } |
| 507 | |
| 508 | for (i = 0; i < num_threads; i++) |
| 509 | { |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame^] | 510 | pm->active_open_event_queue[i] = session_main_get_vpp_event_queue (i); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 511 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 512 | ASSERT (pm->active_open_event_queue[i]); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 513 | |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame^] | 514 | pm->server_event_queue[i] = session_main_get_vpp_event_queue (i); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | static clib_error_t * |
| 521 | proxy_server_create_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 522 | vlib_cli_command_t * cmd) |
| 523 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 524 | proxy_main_t *pm = &proxy_main; |
| 525 | char *default_server_uri = "tcp://0.0.0.0/23"; |
| 526 | char *default_client_uri = "tcp://6.0.2.2/23"; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 527 | int rv; |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 528 | u64 tmp; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 529 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 530 | pm->fifo_size = 64 << 10; |
| 531 | pm->rcv_buffer_size = 1024; |
| 532 | pm->prealloc_fifos = 0; |
| 533 | pm->private_segment_count = 0; |
| 534 | pm->private_segment_size = 0; |
| 535 | pm->server_uri = 0; |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 536 | |
| 537 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 538 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 539 | if (unformat (input, "fifo-size %d", &pm->fifo_size)) |
| 540 | pm->fifo_size <<= 10; |
| 541 | else if (unformat (input, "rcv-buf-size %d", &pm->rcv_buffer_size)) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 542 | ; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 543 | else if (unformat (input, "prealloc-fifos %d", &pm->prealloc_fifos)) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 544 | ; |
| 545 | else if (unformat (input, "private-segment-count %d", |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 546 | &pm->private_segment_count)) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 547 | ; |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 548 | else if (unformat (input, "private-segment-size %U", |
| 549 | unformat_memory_size, &tmp)) |
| 550 | { |
| 551 | if (tmp >= 0x100000000ULL) |
| 552 | return clib_error_return |
| 553 | (0, "private segment size %lld (%llu) too large", tmp, tmp); |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 554 | pm->private_segment_size = tmp; |
Dave Barach | 91f3e74 | 2017-09-01 19:12:11 -0400 | [diff] [blame] | 555 | } |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 556 | else if (unformat (input, "server-uri %s", &pm->server_uri)) |
Florin Coras | ee7e1f5 | 2018-01-11 02:23:35 -0800 | [diff] [blame] | 557 | ; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 558 | else if (unformat (input, "client-uri %s", &pm->client_uri)) |
Florin Coras | cd330c8 | 2018-05-09 17:33:00 -0700 | [diff] [blame] | 559 | pm->client_uri = format (0, "%s%c", pm->client_uri, 0); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 560 | else |
| 561 | return clib_error_return (0, "unknown input `%U'", |
| 562 | format_unformat_error, input); |
| 563 | } |
| 564 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 565 | if (!pm->server_uri) |
| 566 | { |
| 567 | clib_warning ("No server-uri provided, Using default: %s", |
| 568 | default_server_uri); |
| 569 | pm->server_uri = format (0, "%s%c", default_server_uri, 0); |
| 570 | } |
| 571 | if (!pm->client_uri) |
| 572 | { |
| 573 | clib_warning ("No client-uri provided, Using default: %s", |
| 574 | default_client_uri); |
| 575 | pm->client_uri = format (0, "%s%c", default_client_uri, 0); |
| 576 | } |
Florin Coras | ee7e1f5 | 2018-01-11 02:23:35 -0800 | [diff] [blame] | 577 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 578 | vnet_session_enable_disable (vm, 1 /* turn on session and transport */ ); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 579 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 580 | rv = proxy_server_create (vm); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 581 | switch (rv) |
| 582 | { |
| 583 | case 0: |
| 584 | break; |
| 585 | default: |
| 586 | return clib_error_return (0, "server_create returned %d", rv); |
| 587 | } |
| 588 | |
| 589 | return 0; |
| 590 | } |
| 591 | |
| 592 | /* *INDENT-OFF* */ |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 593 | VLIB_CLI_COMMAND (proxy_create_command, static) = |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 594 | { |
| 595 | .path = "test proxy server", |
Florin Coras | ee7e1f5 | 2018-01-11 02:23:35 -0800 | [diff] [blame] | 596 | .short_help = "test proxy server [server-uri <tcp://ip/port>]" |
| 597 | "[client-uri <tcp://ip/port>][fifo-size <nn>][rcv-buf-size <nn>]" |
| 598 | "[prealloc-fifos <nn>][private-segment-size <mem>]" |
| 599 | "[private-segment-count <nn>]", |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 600 | .function = proxy_server_create_command_fn, |
| 601 | }; |
| 602 | /* *INDENT-ON* */ |
| 603 | |
| 604 | clib_error_t * |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 605 | proxy_main_init (vlib_main_t * vm) |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 606 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 607 | proxy_main_t *pm = &proxy_main; |
| 608 | pm->server_client_index = ~0; |
| 609 | pm->active_open_client_index = ~0; |
| 610 | pm->proxy_session_by_active_open_handle = hash_create (0, sizeof (uword)); |
| 611 | pm->proxy_session_by_server_handle = hash_create (0, sizeof (uword)); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 612 | |
| 613 | return 0; |
| 614 | } |
| 615 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 616 | VLIB_INIT_FUNCTION (proxy_main_init); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 617 | |
| 618 | /* |
| 619 | * fd.io coding-style-patch-verification: ON |
| 620 | * |
| 621 | * Local Variables: |
| 622 | * eval: (c-set-style "gnu") |
| 623 | * End: |
| 624 | */ |