Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [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> |
| 20 | |
| 21 | typedef struct |
| 22 | { |
| 23 | /* |
| 24 | * Server app parameters |
| 25 | */ |
| 26 | svm_queue_t **vpp_queue; |
| 27 | svm_queue_t *vl_input_queue; /**< Sever's event queue */ |
| 28 | |
| 29 | u32 app_index; /**< Server app index */ |
| 30 | u32 my_client_index; /**< API client handle */ |
| 31 | u32 node_index; /**< process node index for evnt scheduling */ |
| 32 | |
| 33 | /* |
| 34 | * Config params |
| 35 | */ |
| 36 | u8 no_echo; /**< Don't echo traffic */ |
| 37 | u32 fifo_size; /**< Fifo size */ |
| 38 | u32 rcv_buffer_size; /**< Rcv buffer size */ |
| 39 | u32 prealloc_fifos; /**< Preallocate fifos */ |
| 40 | u32 private_segment_count; /**< Number of private segments */ |
| 41 | u32 private_segment_size; /**< Size of private segments */ |
| 42 | char *server_uri; /**< Server URI */ |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 43 | u32 tls_engine; /**< TLS engine: mbedtls/openssl */ |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 44 | /* |
| 45 | * Test state |
| 46 | */ |
| 47 | u8 **rx_buf; /**< Per-thread RX buffer */ |
| 48 | u64 byte_index; |
| 49 | u32 **rx_retries; |
| 50 | |
| 51 | vlib_main_t *vlib_main; |
| 52 | } echo_server_main_t; |
| 53 | |
| 54 | echo_server_main_t echo_server_main; |
| 55 | |
| 56 | int |
| 57 | echo_server_session_accept_callback (stream_session_t * s) |
| 58 | { |
| 59 | echo_server_main_t *esm = &echo_server_main; |
| 60 | |
| 61 | esm->vpp_queue[s->thread_index] = |
| 62 | session_manager_get_vpp_event_queue (s->thread_index); |
| 63 | s->session_state = SESSION_STATE_READY; |
| 64 | esm->byte_index = 0; |
| 65 | vec_validate (esm->rx_retries[s->thread_index], s->session_index); |
| 66 | esm->rx_retries[s->thread_index][s->session_index] = 0; |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | echo_server_session_disconnect_callback (stream_session_t * s) |
| 72 | { |
| 73 | echo_server_main_t *esm = &echo_server_main; |
| 74 | vnet_disconnect_args_t _a, *a = &_a; |
| 75 | |
| 76 | a->handle = session_handle (s); |
| 77 | a->app_index = esm->app_index; |
| 78 | vnet_disconnect_session (a); |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | echo_server_session_reset_callback (stream_session_t * s) |
| 83 | { |
| 84 | clib_warning ("Reset session %U", format_stream_session, s, 2); |
| 85 | stream_session_cleanup (s); |
| 86 | } |
| 87 | |
| 88 | int |
| 89 | echo_server_session_connected_callback (u32 app_index, u32 api_context, |
| 90 | stream_session_t * s, u8 is_fail) |
| 91 | { |
| 92 | clib_warning ("called..."); |
| 93 | return -1; |
| 94 | } |
| 95 | |
| 96 | int |
| 97 | echo_server_add_segment_callback (u32 client_index, const ssvm_private_t * sp) |
| 98 | { |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 99 | /* New heaps may be added */ |
| 100 | return 0; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | int |
| 104 | echo_server_redirect_connect_callback (u32 client_index, void *mp) |
| 105 | { |
| 106 | clib_warning ("called..."); |
| 107 | return -1; |
| 108 | } |
| 109 | |
| 110 | void |
| 111 | test_bytes (echo_server_main_t * esm, int actual_transfer) |
| 112 | { |
| 113 | int i; |
| 114 | u32 my_thread_id = vlib_get_thread_index (); |
| 115 | |
| 116 | for (i = 0; i < actual_transfer; i++) |
| 117 | { |
| 118 | if (esm->rx_buf[my_thread_id][i] != ((esm->byte_index + i) & 0xff)) |
| 119 | { |
| 120 | clib_warning ("at %lld expected %d got %d", esm->byte_index + i, |
| 121 | (esm->byte_index + i) & 0xff, |
| 122 | esm->rx_buf[my_thread_id][i]); |
| 123 | } |
| 124 | } |
| 125 | esm->byte_index += actual_transfer; |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * If no-echo, just read the data and be done with it |
| 130 | */ |
| 131 | int |
| 132 | echo_server_builtin_server_rx_callback_no_echo (stream_session_t * s) |
| 133 | { |
| 134 | echo_server_main_t *esm = &echo_server_main; |
| 135 | u32 my_thread_id = vlib_get_thread_index (); |
| 136 | int actual_transfer; |
| 137 | svm_fifo_t *rx_fifo; |
| 138 | |
| 139 | rx_fifo = s->server_rx_fifo; |
| 140 | |
| 141 | do |
| 142 | { |
| 143 | actual_transfer = |
| 144 | svm_fifo_dequeue_nowait (rx_fifo, esm->rcv_buffer_size, |
| 145 | esm->rx_buf[my_thread_id]); |
| 146 | } |
| 147 | while (actual_transfer > 0); |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | int |
| 152 | echo_server_rx_callback (stream_session_t * s) |
| 153 | { |
| 154 | u32 n_written, max_dequeue, max_enqueue, max_transfer; |
| 155 | int actual_transfer; |
| 156 | svm_fifo_t *tx_fifo, *rx_fifo; |
| 157 | echo_server_main_t *esm = &echo_server_main; |
| 158 | session_fifo_event_t evt; |
| 159 | u32 thread_index = vlib_get_thread_index (); |
| 160 | |
| 161 | ASSERT (s->thread_index == thread_index); |
| 162 | |
| 163 | rx_fifo = s->server_rx_fifo; |
| 164 | tx_fifo = s->server_tx_fifo; |
| 165 | |
| 166 | ASSERT (rx_fifo->master_thread_index == thread_index); |
| 167 | ASSERT (tx_fifo->master_thread_index == thread_index); |
| 168 | |
| 169 | max_dequeue = svm_fifo_max_dequeue (s->server_rx_fifo); |
| 170 | max_enqueue = svm_fifo_max_enqueue (s->server_tx_fifo); |
| 171 | |
| 172 | if (PREDICT_FALSE (max_dequeue == 0)) |
| 173 | return 0; |
| 174 | |
| 175 | /* Number of bytes we're going to copy */ |
| 176 | max_transfer = (max_dequeue < max_enqueue) ? max_dequeue : max_enqueue; |
| 177 | |
| 178 | /* No space in tx fifo */ |
| 179 | if (PREDICT_FALSE (max_transfer == 0)) |
| 180 | { |
| 181 | /* XXX timeout for session that are stuck */ |
| 182 | |
| 183 | rx_event: |
| 184 | /* Program self-tap to retry */ |
| 185 | if (svm_fifo_set_event (rx_fifo)) |
| 186 | { |
| 187 | svm_queue_t *q; |
| 188 | evt.fifo = rx_fifo; |
| 189 | evt.event_type = FIFO_EVENT_BUILTIN_RX; |
| 190 | |
| 191 | q = esm->vpp_queue[thread_index]; |
| 192 | if (PREDICT_FALSE (q->cursize == q->maxsize)) |
| 193 | clib_warning ("out of event queue space"); |
| 194 | else if (svm_queue_add (q, (u8 *) & evt, 0)) |
| 195 | clib_warning ("failed to enqueue self-tap"); |
| 196 | |
| 197 | if (esm->rx_retries[thread_index][s->session_index] == 500000) |
| 198 | { |
| 199 | clib_warning ("session stuck: %U", format_stream_session, s, 2); |
| 200 | } |
| 201 | if (esm->rx_retries[thread_index][s->session_index] < 500001) |
| 202 | esm->rx_retries[thread_index][s->session_index]++; |
| 203 | } |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | _vec_len (esm->rx_buf[thread_index]) = max_transfer; |
| 209 | |
| 210 | actual_transfer = svm_fifo_dequeue_nowait (rx_fifo, max_transfer, |
| 211 | esm->rx_buf[thread_index]); |
| 212 | ASSERT (actual_transfer == max_transfer); |
| 213 | |
| 214 | // test_bytes (esm, actual_transfer); |
| 215 | |
| 216 | /* |
| 217 | * Echo back |
| 218 | */ |
| 219 | |
| 220 | n_written = svm_fifo_enqueue_nowait (tx_fifo, actual_transfer, |
| 221 | esm->rx_buf[thread_index]); |
| 222 | |
| 223 | if (n_written != max_transfer) |
| 224 | clib_warning ("short trout!"); |
| 225 | |
| 226 | if (svm_fifo_set_event (tx_fifo)) |
| 227 | { |
| 228 | /* Fabricate TX event, send to vpp */ |
| 229 | evt.fifo = tx_fifo; |
| 230 | evt.event_type = FIFO_EVENT_APP_TX; |
| 231 | |
| 232 | if (svm_queue_add (esm->vpp_queue[s->thread_index], |
| 233 | (u8 *) & evt, 0 /* do wait for mutex */ )) |
| 234 | clib_warning ("failed to enqueue tx evt"); |
| 235 | } |
| 236 | |
| 237 | if (PREDICT_FALSE (n_written < max_dequeue)) |
| 238 | goto rx_event; |
| 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | static session_cb_vft_t echo_server_session_cb_vft = { |
| 244 | .session_accept_callback = echo_server_session_accept_callback, |
| 245 | .session_disconnect_callback = echo_server_session_disconnect_callback, |
| 246 | .session_connected_callback = echo_server_session_connected_callback, |
| 247 | .add_segment_callback = echo_server_add_segment_callback, |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 248 | .builtin_app_rx_callback = echo_server_rx_callback, |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 249 | .session_reset_callback = echo_server_session_reset_callback |
| 250 | }; |
| 251 | |
| 252 | /* Abuse VPP's input queue */ |
| 253 | static int |
| 254 | create_api_loopback (vlib_main_t * vm) |
| 255 | { |
| 256 | echo_server_main_t *esm = &echo_server_main; |
| 257 | api_main_t *am = &api_main; |
| 258 | vl_shmem_hdr_t *shmem_hdr; |
| 259 | |
| 260 | shmem_hdr = am->shmem_hdr; |
| 261 | esm->vl_input_queue = shmem_hdr->vl_input_queue; |
| 262 | esm->my_client_index = vl_api_memclnt_create_internal ("echo_server", |
| 263 | esm->vl_input_queue); |
| 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | static int |
| 268 | echo_server_attach (u8 * appns_id, u64 appns_flags, u64 appns_secret) |
| 269 | { |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 270 | vnet_app_add_tls_cert_args_t _a_cert, *a_cert = &_a_cert; |
| 271 | vnet_app_add_tls_key_args_t _a_key, *a_key = &_a_key; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 272 | echo_server_main_t *esm = &echo_server_main; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 273 | vnet_app_attach_args_t _a, *a = &_a; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 274 | u64 options[APP_OPTIONS_N_OPTIONS]; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 275 | u32 segment_size = 512 << 20; |
| 276 | |
| 277 | memset (a, 0, sizeof (*a)); |
| 278 | memset (options, 0, sizeof (options)); |
| 279 | |
| 280 | if (esm->no_echo) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 281 | echo_server_session_cb_vft.builtin_app_rx_callback = |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 282 | echo_server_builtin_server_rx_callback_no_echo; |
| 283 | else |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 284 | echo_server_session_cb_vft.builtin_app_rx_callback = |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 285 | echo_server_rx_callback; |
| 286 | |
| 287 | if (esm->private_segment_size) |
| 288 | segment_size = esm->private_segment_size; |
| 289 | |
| 290 | a->api_client_index = esm->my_client_index; |
| 291 | a->session_cb_vft = &echo_server_session_cb_vft; |
| 292 | a->options = options; |
| 293 | a->options[APP_OPTIONS_SEGMENT_SIZE] = segment_size; |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 294 | a->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = segment_size; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 295 | a->options[APP_OPTIONS_RX_FIFO_SIZE] = esm->fifo_size; |
| 296 | a->options[APP_OPTIONS_TX_FIFO_SIZE] = esm->fifo_size; |
| 297 | a->options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = esm->private_segment_count; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 298 | a->options[APP_OPTIONS_TLS_ENGINE] = esm->tls_engine; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 299 | a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = |
| 300 | esm->prealloc_fifos ? esm->prealloc_fifos : 1; |
| 301 | |
| 302 | a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN; |
| 303 | if (appns_id) |
| 304 | { |
| 305 | a->namespace_id = appns_id; |
| 306 | a->options[APP_OPTIONS_FLAGS] |= appns_flags; |
| 307 | a->options[APP_OPTIONS_NAMESPACE_SECRET] = appns_secret; |
| 308 | } |
| 309 | |
| 310 | if (vnet_application_attach (a)) |
| 311 | { |
| 312 | clib_warning ("failed to attach server"); |
| 313 | return -1; |
| 314 | } |
| 315 | esm->app_index = a->app_index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 316 | |
| 317 | memset (a_cert, 0, sizeof (*a_cert)); |
| 318 | a_cert->app_index = a->app_index; |
| 319 | vec_validate (a_cert->cert, test_srv_crt_rsa_len); |
| 320 | clib_memcpy (a_cert->cert, test_srv_crt_rsa, test_srv_crt_rsa_len); |
| 321 | vnet_app_add_tls_cert (a_cert); |
| 322 | |
| 323 | memset (a_key, 0, sizeof (*a_key)); |
| 324 | a_key->app_index = a->app_index; |
| 325 | vec_validate (a_key->key, test_srv_key_rsa_len); |
| 326 | clib_memcpy (a_key->key, test_srv_key_rsa, test_srv_key_rsa_len); |
| 327 | vnet_app_add_tls_key (a_key); |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static int |
| 332 | echo_server_detach (void) |
| 333 | { |
| 334 | echo_server_main_t *esm = &echo_server_main; |
| 335 | vnet_app_detach_args_t _da, *da = &_da; |
| 336 | int rv; |
| 337 | |
| 338 | da->app_index = esm->app_index; |
| 339 | rv = vnet_application_detach (da); |
| 340 | esm->app_index = ~0; |
| 341 | return rv; |
| 342 | } |
| 343 | |
| 344 | static int |
| 345 | echo_server_listen () |
| 346 | { |
| 347 | echo_server_main_t *esm = &echo_server_main; |
| 348 | vnet_bind_args_t _a, *a = &_a; |
| 349 | memset (a, 0, sizeof (*a)); |
| 350 | a->app_index = esm->app_index; |
| 351 | a->uri = esm->server_uri; |
| 352 | return vnet_bind_uri (a); |
| 353 | } |
| 354 | |
| 355 | static int |
| 356 | echo_server_create (vlib_main_t * vm, u8 * appns_id, u64 appns_flags, |
| 357 | u64 appns_secret) |
| 358 | { |
| 359 | echo_server_main_t *esm = &echo_server_main; |
| 360 | vlib_thread_main_t *vtm = vlib_get_thread_main (); |
| 361 | u32 num_threads; |
| 362 | int i; |
| 363 | |
| 364 | if (esm->my_client_index == (u32) ~ 0) |
| 365 | { |
| 366 | if (create_api_loopback (vm)) |
| 367 | { |
| 368 | clib_warning ("failed to create api loopback"); |
| 369 | return -1; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | num_threads = 1 /* main thread */ + vtm->n_threads; |
| 374 | vec_validate (echo_server_main.vpp_queue, num_threads - 1); |
| 375 | vec_validate (esm->rx_buf, num_threads - 1); |
| 376 | vec_validate (esm->rx_retries, num_threads - 1); |
| 377 | |
Florin Coras | 81a13db | 2018-03-16 08:48:31 -0700 | [diff] [blame] | 378 | esm->rcv_buffer_size = clib_max (esm->rcv_buffer_size, esm->fifo_size); |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 379 | for (i = 0; i < num_threads; i++) |
| 380 | vec_validate (esm->rx_buf[i], esm->rcv_buffer_size); |
| 381 | |
| 382 | if (echo_server_attach (appns_id, appns_flags, appns_secret)) |
| 383 | { |
| 384 | clib_warning ("failed to attach server"); |
| 385 | return -1; |
| 386 | } |
| 387 | if (echo_server_listen ()) |
| 388 | { |
| 389 | clib_warning ("failed to start listening"); |
| 390 | if (echo_server_detach ()) |
| 391 | clib_warning ("failed to detach"); |
| 392 | return -1; |
| 393 | } |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | static clib_error_t * |
| 398 | echo_server_create_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 399 | vlib_cli_command_t * cmd) |
| 400 | { |
| 401 | echo_server_main_t *esm = &echo_server_main; |
| 402 | u8 server_uri_set = 0, *appns_id = 0; |
| 403 | u64 tmp, appns_flags = 0, appns_secret = 0; |
| 404 | char *default_uri = "tcp://0.0.0.0/1234"; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 405 | int rv, is_stop = 0; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 406 | |
| 407 | esm->no_echo = 0; |
| 408 | esm->fifo_size = 64 << 10; |
| 409 | esm->rcv_buffer_size = 128 << 10; |
| 410 | esm->prealloc_fifos = 0; |
| 411 | esm->private_segment_count = 0; |
| 412 | esm->private_segment_size = 0; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 413 | esm->tls_engine = TLS_ENGINE_OPENSSL; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 414 | vec_free (esm->server_uri); |
| 415 | |
| 416 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 417 | { |
| 418 | if (unformat (input, "uri %s", &esm->server_uri)) |
| 419 | server_uri_set = 1; |
| 420 | else if (unformat (input, "no-echo")) |
| 421 | esm->no_echo = 1; |
| 422 | else if (unformat (input, "fifo-size %d", &esm->fifo_size)) |
| 423 | esm->fifo_size <<= 10; |
| 424 | else if (unformat (input, "rcv-buf-size %d", &esm->rcv_buffer_size)) |
| 425 | ; |
| 426 | else if (unformat (input, "prealloc-fifos %d", &esm->prealloc_fifos)) |
| 427 | ; |
| 428 | else if (unformat (input, "private-segment-count %d", |
| 429 | &esm->private_segment_count)) |
| 430 | ; |
| 431 | else if (unformat (input, "private-segment-size %U", |
| 432 | unformat_memory_size, &tmp)) |
| 433 | { |
| 434 | if (tmp >= 0x100000000ULL) |
| 435 | return clib_error_return |
| 436 | (0, "private segment size %lld (%llu) too large", tmp, tmp); |
| 437 | esm->private_segment_size = tmp; |
| 438 | } |
| 439 | else if (unformat (input, "appns %_%v%_", &appns_id)) |
| 440 | ; |
| 441 | else if (unformat (input, "all-scope")) |
| 442 | appns_flags |= (APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE |
| 443 | | APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE); |
| 444 | else if (unformat (input, "local-scope")) |
| 445 | appns_flags |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE; |
| 446 | else if (unformat (input, "global-scope")) |
| 447 | appns_flags |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE; |
| 448 | else if (unformat (input, "secret %lu", &appns_secret)) |
| 449 | ; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 450 | else if (unformat (input, "stop")) |
| 451 | is_stop = 1; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 452 | else if (unformat (input, "tls-engine %d", &esm->tls_engine)) |
| 453 | ; |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 454 | else |
| 455 | return clib_error_return (0, "failed: unknown input `%U'", |
| 456 | format_unformat_error, input); |
| 457 | } |
| 458 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 459 | if (is_stop) |
| 460 | { |
| 461 | if (esm->app_index == (u32) ~ 0) |
| 462 | { |
| 463 | clib_warning ("server not running"); |
| 464 | return clib_error_return (0, "failed: server not running"); |
| 465 | } |
| 466 | rv = echo_server_detach (); |
| 467 | if (rv) |
| 468 | { |
| 469 | clib_warning ("failed: detach"); |
| 470 | return clib_error_return (0, "failed: server detach %d", rv); |
| 471 | } |
| 472 | return 0; |
| 473 | } |
| 474 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 475 | vnet_session_enable_disable (vm, 1 /* turn on TCP, etc. */ ); |
| 476 | |
| 477 | if (!server_uri_set) |
| 478 | { |
| 479 | clib_warning ("No uri provided! Using default: %s", default_uri); |
| 480 | esm->server_uri = (char *) format (0, "%s%c", default_uri, 0); |
| 481 | } |
| 482 | |
| 483 | rv = echo_server_create (vm, appns_id, appns_flags, appns_secret); |
| 484 | vec_free (appns_id); |
| 485 | if (rv) |
| 486 | { |
| 487 | vec_free (esm->server_uri); |
| 488 | return clib_error_return (0, "failed: server_create returned %d", rv); |
| 489 | } |
| 490 | |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | /* *INDENT-OFF* */ |
| 495 | VLIB_CLI_COMMAND (echo_server_create_command, static) = |
| 496 | { |
| 497 | .path = "test echo server", |
| 498 | .short_help = "test echo server proto <proto> [no echo][fifo-size <mbytes>]" |
| 499 | "[rcv-buf-size <bytes>][prealloc-fifos <count>]" |
| 500 | "[private-segment-count <count>][private-segment-size <bytes[m|g]>]" |
| 501 | "[uri <tcp://ip/port>]", |
| 502 | .function = echo_server_create_command_fn, |
| 503 | }; |
| 504 | /* *INDENT-ON* */ |
| 505 | |
| 506 | clib_error_t * |
| 507 | echo_server_main_init (vlib_main_t * vm) |
| 508 | { |
| 509 | echo_server_main_t *esm = &echo_server_main; |
| 510 | esm->my_client_index = ~0; |
| 511 | return 0; |
| 512 | } |
| 513 | |
| 514 | VLIB_INIT_FUNCTION (echo_server_main_init); |
| 515 | |
| 516 | /* |
| 517 | * fd.io coding-style-patch-verification: ON |
| 518 | * |
| 519 | * Local Variables: |
| 520 | * eval: (c-set-style "gnu") |
| 521 | * End: |
| 522 | */ |