blob: 941c16d0e085fbe3d5c6318b4440323beb09cc43 [file] [log] [blame]
Florin Coras4399c2e2018-01-25 06:34:42 -08001/*
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 Coras54a51fd2019-02-07 15:34:52 -080020#include <vnet/session/session.h>
Florin Coras4399c2e2018-01-25 06:34:42 -080021
22typedef struct
23{
24 /*
25 * Server app parameters
26 */
Florin Coras3c2fed52018-07-04 04:15:05 -070027 svm_msg_q_t **vpp_queue;
Florin Coras4399c2e2018-01-25 06:34:42 -080028 svm_queue_t *vl_input_queue; /**< Sever's event queue */
29
30 u32 app_index; /**< Server app index */
31 u32 my_client_index; /**< API client handle */
32 u32 node_index; /**< process node index for evnt scheduling */
33
34 /*
35 * Config params
36 */
37 u8 no_echo; /**< Don't echo traffic */
Florin Coras7fb0fe12018-04-09 09:24:52 -070038 u32 fifo_size; /**< Fifo size */
Florin Coras4399c2e2018-01-25 06:34:42 -080039 u32 rcv_buffer_size; /**< Rcv buffer size */
40 u32 prealloc_fifos; /**< Preallocate fifos */
41 u32 private_segment_count; /**< Number of private segments */
42 u32 private_segment_size; /**< Size of private segments */
43 char *server_uri; /**< Server URI */
Florin Coras58d36f02018-03-09 13:05:53 -080044 u32 tls_engine; /**< TLS engine: mbedtls/openssl */
Florin Coras7fb0fe12018-04-09 09:24:52 -070045 u8 is_dgram; /**< set if transport is dgram */
Florin Coras4399c2e2018-01-25 06:34:42 -080046 /*
47 * Test state
48 */
49 u8 **rx_buf; /**< Per-thread RX buffer */
50 u64 byte_index;
51 u32 **rx_retries;
52
53 vlib_main_t *vlib_main;
54} echo_server_main_t;
55
56echo_server_main_t echo_server_main;
57
58int
Florin Coras288eaab2019-02-03 15:26:14 -080059echo_server_session_accept_callback (session_t * s)
Florin Coras4399c2e2018-01-25 06:34:42 -080060{
61 echo_server_main_t *esm = &echo_server_main;
62
63 esm->vpp_queue[s->thread_index] =
Florin Coras31c99552019-03-01 13:00:58 -080064 session_main_get_vpp_event_queue (s->thread_index);
Florin Coras4399c2e2018-01-25 06:34:42 -080065 s->session_state = SESSION_STATE_READY;
66 esm->byte_index = 0;
Florin Coras6f1c48d2018-05-02 14:34:32 -070067 ASSERT (vec_len (esm->rx_retries) > s->thread_index);
68 vec_validate (esm->rx_retries[s->thread_index], s->session_index);
Florin Coras4399c2e2018-01-25 06:34:42 -080069 esm->rx_retries[s->thread_index][s->session_index] = 0;
70 return 0;
71}
72
73void
Florin Coras288eaab2019-02-03 15:26:14 -080074echo_server_session_disconnect_callback (session_t * s)
Florin Coras4399c2e2018-01-25 06:34:42 -080075{
76 echo_server_main_t *esm = &echo_server_main;
Florin Coras4af830c2018-12-04 09:21:36 -080077 vnet_disconnect_args_t _a = { 0 }, *a = &_a;
Florin Coras4399c2e2018-01-25 06:34:42 -080078
79 a->handle = session_handle (s);
80 a->app_index = esm->app_index;
81 vnet_disconnect_session (a);
82}
83
84void
Florin Coras288eaab2019-02-03 15:26:14 -080085echo_server_session_reset_callback (session_t * s)
Florin Coras4399c2e2018-01-25 06:34:42 -080086{
Florin Coras4af830c2018-12-04 09:21:36 -080087 echo_server_main_t *esm = &echo_server_main;
88 vnet_disconnect_args_t _a = { 0 }, *a = &_a;
Florin Coras31c99552019-03-01 13:00:58 -080089 clib_warning ("Reset session %U", format_session, s, 2);
Florin Coras4af830c2018-12-04 09:21:36 -080090 a->handle = session_handle (s);
91 a->app_index = esm->app_index;
92 vnet_disconnect_session (a);
Florin Coras4399c2e2018-01-25 06:34:42 -080093}
94
95int
96echo_server_session_connected_callback (u32 app_index, u32 api_context,
Florin Coras288eaab2019-02-03 15:26:14 -080097 session_t * s, u8 is_fail)
Florin Coras4399c2e2018-01-25 06:34:42 -080098{
99 clib_warning ("called...");
100 return -1;
101}
102
103int
Florin Corasfa76a762018-11-29 12:40:10 -0800104echo_server_add_segment_callback (u32 client_index, u64 segment_handle)
Florin Coras4399c2e2018-01-25 06:34:42 -0800105{
Florin Corasa332c462018-01-31 06:52:17 -0800106 /* New heaps may be added */
107 return 0;
Florin Coras4399c2e2018-01-25 06:34:42 -0800108}
109
110int
111echo_server_redirect_connect_callback (u32 client_index, void *mp)
112{
113 clib_warning ("called...");
114 return -1;
115}
116
117void
118test_bytes (echo_server_main_t * esm, int actual_transfer)
119{
120 int i;
121 u32 my_thread_id = vlib_get_thread_index ();
122
123 for (i = 0; i < actual_transfer; i++)
124 {
125 if (esm->rx_buf[my_thread_id][i] != ((esm->byte_index + i) & 0xff))
126 {
127 clib_warning ("at %lld expected %d got %d", esm->byte_index + i,
128 (esm->byte_index + i) & 0xff,
129 esm->rx_buf[my_thread_id][i]);
130 }
131 }
132 esm->byte_index += actual_transfer;
133}
134
135/*
Florin Coras7fb0fe12018-04-09 09:24:52 -0700136 * If no-echo, just drop the data and be done with it.
Florin Coras4399c2e2018-01-25 06:34:42 -0800137 */
138int
Florin Coras288eaab2019-02-03 15:26:14 -0800139echo_server_builtin_server_rx_callback_no_echo (session_t * s)
Florin Coras4399c2e2018-01-25 06:34:42 -0800140{
Florin Coras288eaab2019-02-03 15:26:14 -0800141 svm_fifo_t *rx_fifo = s->rx_fifo;
Florin Coras7fb0fe12018-04-09 09:24:52 -0700142 svm_fifo_dequeue_drop (rx_fifo, svm_fifo_max_dequeue (rx_fifo));
Florin Coras4399c2e2018-01-25 06:34:42 -0800143 return 0;
144}
145
146int
Florin Coras288eaab2019-02-03 15:26:14 -0800147echo_server_rx_callback (session_t * s)
Florin Coras4399c2e2018-01-25 06:34:42 -0800148{
149 u32 n_written, max_dequeue, max_enqueue, max_transfer;
150 int actual_transfer;
151 svm_fifo_t *tx_fifo, *rx_fifo;
152 echo_server_main_t *esm = &echo_server_main;
Florin Coras4399c2e2018-01-25 06:34:42 -0800153 u32 thread_index = vlib_get_thread_index ();
Florin Coras7fb0fe12018-04-09 09:24:52 -0700154 app_session_transport_t at;
Florin Coras4399c2e2018-01-25 06:34:42 -0800155
156 ASSERT (s->thread_index == thread_index);
157
Florin Coras288eaab2019-02-03 15:26:14 -0800158 rx_fifo = s->rx_fifo;
159 tx_fifo = s->tx_fifo;
Florin Coras4399c2e2018-01-25 06:34:42 -0800160
161 ASSERT (rx_fifo->master_thread_index == thread_index);
162 ASSERT (tx_fifo->master_thread_index == thread_index);
163
Florin Coras7fb0fe12018-04-09 09:24:52 -0700164 max_enqueue = svm_fifo_max_enqueue (tx_fifo);
165 if (!esm->is_dgram)
166 {
167 max_dequeue = svm_fifo_max_dequeue (rx_fifo);
168 }
169 else
170 {
171 session_dgram_pre_hdr_t ph;
172 svm_fifo_peek (rx_fifo, 0, sizeof (ph), (u8 *) & ph);
173 max_dequeue = ph.data_length - ph.data_offset;
174 if (!esm->vpp_queue[s->thread_index])
175 {
Florin Coras3c2fed52018-07-04 04:15:05 -0700176 svm_msg_q_t *mq;
Florin Coras31c99552019-03-01 13:00:58 -0800177 mq = session_main_get_vpp_event_queue (s->thread_index);
Florin Coras3c2fed52018-07-04 04:15:05 -0700178 esm->vpp_queue[s->thread_index] = mq;
Florin Coras7fb0fe12018-04-09 09:24:52 -0700179 }
180 max_enqueue -= sizeof (session_dgram_hdr_t);
181 }
Florin Coras4399c2e2018-01-25 06:34:42 -0800182
183 if (PREDICT_FALSE (max_dequeue == 0))
184 return 0;
185
186 /* Number of bytes we're going to copy */
Florin Coras7fb0fe12018-04-09 09:24:52 -0700187 max_transfer = clib_min (max_dequeue, max_enqueue);
Florin Coras4399c2e2018-01-25 06:34:42 -0800188
189 /* No space in tx fifo */
190 if (PREDICT_FALSE (max_transfer == 0))
191 {
192 /* XXX timeout for session that are stuck */
193
194 rx_event:
195 /* Program self-tap to retry */
196 if (svm_fifo_set_event (rx_fifo))
197 {
Florin Corasf6c43132019-03-01 12:41:21 -0800198 if (session_send_io_evt_to_thread (rx_fifo,
199 SESSION_IO_EVT_BUILTIN_RX))
Florin Coras4399c2e2018-01-25 06:34:42 -0800200 clib_warning ("failed to enqueue self-tap");
201
Florin Coras7fb0fe12018-04-09 09:24:52 -0700202 vec_validate (esm->rx_retries[s->thread_index], s->session_index);
Florin Coras4399c2e2018-01-25 06:34:42 -0800203 if (esm->rx_retries[thread_index][s->session_index] == 500000)
204 {
Florin Coras31c99552019-03-01 13:00:58 -0800205 clib_warning ("session stuck: %U", format_session, s, 2);
Florin Coras4399c2e2018-01-25 06:34:42 -0800206 }
207 if (esm->rx_retries[thread_index][s->session_index] < 500001)
208 esm->rx_retries[thread_index][s->session_index]++;
209 }
210
211 return 0;
212 }
213
Florin Coras7fb0fe12018-04-09 09:24:52 -0700214 vec_validate (esm->rx_buf[thread_index], max_transfer);
215 if (!esm->is_dgram)
216 {
217 actual_transfer = app_recv_stream_raw (rx_fifo,
218 esm->rx_buf[thread_index],
219 max_transfer,
Florin Coras460dce62018-07-27 05:45:06 -0700220 0 /* don't clear event */ ,
221 0 /* peek */ );
Florin Coras7fb0fe12018-04-09 09:24:52 -0700222 }
223 else
224 {
225 actual_transfer = app_recv_dgram_raw (rx_fifo,
226 esm->rx_buf[thread_index],
227 max_transfer, &at,
Florin Coras460dce62018-07-27 05:45:06 -0700228 0 /* don't clear event */ ,
229 0 /* peek */ );
Florin Coras7fb0fe12018-04-09 09:24:52 -0700230 }
Florin Coras4399c2e2018-01-25 06:34:42 -0800231 ASSERT (actual_transfer == max_transfer);
Florin Coras7fb0fe12018-04-09 09:24:52 -0700232 /* test_bytes (esm, actual_transfer); */
Florin Coras4399c2e2018-01-25 06:34:42 -0800233
234 /*
235 * Echo back
236 */
237
Florin Coras7fb0fe12018-04-09 09:24:52 -0700238 if (!esm->is_dgram)
Florin Coras4399c2e2018-01-25 06:34:42 -0800239 {
Florin Coras7fb0fe12018-04-09 09:24:52 -0700240 n_written = app_send_stream_raw (tx_fifo,
241 esm->vpp_queue[thread_index],
242 esm->rx_buf[thread_index],
Florin Coras653e43f2019-03-04 10:56:23 -0800243 actual_transfer, SESSION_IO_EVT_TX,
244 1 /* do_evt */ , 0);
Florin Coras7fb0fe12018-04-09 09:24:52 -0700245 }
246 else
247 {
248 n_written = app_send_dgram_raw (tx_fifo, &at,
249 esm->vpp_queue[s->thread_index],
250 esm->rx_buf[thread_index],
Florin Coras653e43f2019-03-04 10:56:23 -0800251 actual_transfer, SESSION_IO_EVT_TX,
252 1 /* do_evt */ , 0);
Florin Coras4399c2e2018-01-25 06:34:42 -0800253 }
254
Florin Coras7fb0fe12018-04-09 09:24:52 -0700255 if (n_written != max_transfer)
256 clib_warning ("short trout! written %u read %u", n_written, max_transfer);
257
258 if (PREDICT_FALSE (svm_fifo_max_dequeue (rx_fifo)))
Florin Coras4399c2e2018-01-25 06:34:42 -0800259 goto rx_event;
260
261 return 0;
262}
263
264static session_cb_vft_t echo_server_session_cb_vft = {
265 .session_accept_callback = echo_server_session_accept_callback,
266 .session_disconnect_callback = echo_server_session_disconnect_callback,
267 .session_connected_callback = echo_server_session_connected_callback,
268 .add_segment_callback = echo_server_add_segment_callback,
Florin Coras371ca502018-02-21 12:07:41 -0800269 .builtin_app_rx_callback = echo_server_rx_callback,
Florin Coras4399c2e2018-01-25 06:34:42 -0800270 .session_reset_callback = echo_server_session_reset_callback
271};
272
273/* Abuse VPP's input queue */
274static int
275create_api_loopback (vlib_main_t * vm)
276{
277 echo_server_main_t *esm = &echo_server_main;
278 api_main_t *am = &api_main;
279 vl_shmem_hdr_t *shmem_hdr;
280
281 shmem_hdr = am->shmem_hdr;
282 esm->vl_input_queue = shmem_hdr->vl_input_queue;
283 esm->my_client_index = vl_api_memclnt_create_internal ("echo_server",
284 esm->vl_input_queue);
285 return 0;
286}
287
288static int
289echo_server_attach (u8 * appns_id, u64 appns_flags, u64 appns_secret)
290{
Florin Coras371ca502018-02-21 12:07:41 -0800291 vnet_app_add_tls_cert_args_t _a_cert, *a_cert = &_a_cert;
292 vnet_app_add_tls_key_args_t _a_key, *a_key = &_a_key;
Florin Coras4399c2e2018-01-25 06:34:42 -0800293 echo_server_main_t *esm = &echo_server_main;
Florin Coras4399c2e2018-01-25 06:34:42 -0800294 vnet_app_attach_args_t _a, *a = &_a;
Florin Coras371ca502018-02-21 12:07:41 -0800295 u64 options[APP_OPTIONS_N_OPTIONS];
Florin Coras4399c2e2018-01-25 06:34:42 -0800296 u32 segment_size = 512 << 20;
297
Dave Barachb7b92992018-10-17 10:38:51 -0400298 clib_memset (a, 0, sizeof (*a));
299 clib_memset (options, 0, sizeof (options));
Florin Coras4399c2e2018-01-25 06:34:42 -0800300
301 if (esm->no_echo)
Florin Coras371ca502018-02-21 12:07:41 -0800302 echo_server_session_cb_vft.builtin_app_rx_callback =
Florin Coras4399c2e2018-01-25 06:34:42 -0800303 echo_server_builtin_server_rx_callback_no_echo;
304 else
Florin Coras371ca502018-02-21 12:07:41 -0800305 echo_server_session_cb_vft.builtin_app_rx_callback =
Florin Coras4399c2e2018-01-25 06:34:42 -0800306 echo_server_rx_callback;
307
308 if (esm->private_segment_size)
309 segment_size = esm->private_segment_size;
310
311 a->api_client_index = esm->my_client_index;
312 a->session_cb_vft = &echo_server_session_cb_vft;
313 a->options = options;
314 a->options[APP_OPTIONS_SEGMENT_SIZE] = segment_size;
Florin Corasa332c462018-01-31 06:52:17 -0800315 a->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = segment_size;
Florin Coras4399c2e2018-01-25 06:34:42 -0800316 a->options[APP_OPTIONS_RX_FIFO_SIZE] = esm->fifo_size;
317 a->options[APP_OPTIONS_TX_FIFO_SIZE] = esm->fifo_size;
318 a->options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = esm->private_segment_count;
Florin Coras58d36f02018-03-09 13:05:53 -0800319 a->options[APP_OPTIONS_TLS_ENGINE] = esm->tls_engine;
Florin Coras4399c2e2018-01-25 06:34:42 -0800320 a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] =
321 esm->prealloc_fifos ? esm->prealloc_fifos : 1;
322
323 a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
324 if (appns_id)
325 {
326 a->namespace_id = appns_id;
327 a->options[APP_OPTIONS_FLAGS] |= appns_flags;
328 a->options[APP_OPTIONS_NAMESPACE_SECRET] = appns_secret;
329 }
330
331 if (vnet_application_attach (a))
332 {
333 clib_warning ("failed to attach server");
334 return -1;
335 }
336 esm->app_index = a->app_index;
Florin Coras371ca502018-02-21 12:07:41 -0800337
Dave Barachb7b92992018-10-17 10:38:51 -0400338 clib_memset (a_cert, 0, sizeof (*a_cert));
Florin Coras371ca502018-02-21 12:07:41 -0800339 a_cert->app_index = a->app_index;
340 vec_validate (a_cert->cert, test_srv_crt_rsa_len);
Dave Barach178cf492018-11-13 16:34:13 -0500341 clib_memcpy_fast (a_cert->cert, test_srv_crt_rsa, test_srv_crt_rsa_len);
Florin Coras371ca502018-02-21 12:07:41 -0800342 vnet_app_add_tls_cert (a_cert);
343
Dave Barachb7b92992018-10-17 10:38:51 -0400344 clib_memset (a_key, 0, sizeof (*a_key));
Florin Coras371ca502018-02-21 12:07:41 -0800345 a_key->app_index = a->app_index;
346 vec_validate (a_key->key, test_srv_key_rsa_len);
Dave Barach178cf492018-11-13 16:34:13 -0500347 clib_memcpy_fast (a_key->key, test_srv_key_rsa, test_srv_key_rsa_len);
Florin Coras371ca502018-02-21 12:07:41 -0800348 vnet_app_add_tls_key (a_key);
Florin Coras4399c2e2018-01-25 06:34:42 -0800349 return 0;
350}
351
352static int
353echo_server_detach (void)
354{
355 echo_server_main_t *esm = &echo_server_main;
356 vnet_app_detach_args_t _da, *da = &_da;
357 int rv;
358
359 da->app_index = esm->app_index;
360 rv = vnet_application_detach (da);
361 esm->app_index = ~0;
362 return rv;
363}
364
365static int
366echo_server_listen ()
367{
368 echo_server_main_t *esm = &echo_server_main;
Florin Corasc9940fc2019-02-05 20:55:11 -0800369 vnet_listen_args_t _a, *a = &_a;
Dave Barachb7b92992018-10-17 10:38:51 -0400370 clib_memset (a, 0, sizeof (*a));
Florin Coras4399c2e2018-01-25 06:34:42 -0800371 a->app_index = esm->app_index;
372 a->uri = esm->server_uri;
373 return vnet_bind_uri (a);
374}
375
376static int
377echo_server_create (vlib_main_t * vm, u8 * appns_id, u64 appns_flags,
378 u64 appns_secret)
379{
380 echo_server_main_t *esm = &echo_server_main;
381 vlib_thread_main_t *vtm = vlib_get_thread_main ();
382 u32 num_threads;
383 int i;
384
385 if (esm->my_client_index == (u32) ~ 0)
386 {
387 if (create_api_loopback (vm))
388 {
389 clib_warning ("failed to create api loopback");
390 return -1;
391 }
392 }
393
394 num_threads = 1 /* main thread */ + vtm->n_threads;
395 vec_validate (echo_server_main.vpp_queue, num_threads - 1);
396 vec_validate (esm->rx_buf, num_threads - 1);
397 vec_validate (esm->rx_retries, num_threads - 1);
Florin Corasc1a448b2018-04-20 10:51:49 -0700398 for (i = 0; i < vec_len (esm->rx_retries); i++)
399 vec_validate (esm->rx_retries[i],
Florin Coras31c99552019-03-01 13:00:58 -0800400 pool_elts (session_main.wrk[i].sessions));
Florin Coras81a13db2018-03-16 08:48:31 -0700401 esm->rcv_buffer_size = clib_max (esm->rcv_buffer_size, esm->fifo_size);
Florin Coras4399c2e2018-01-25 06:34:42 -0800402 for (i = 0; i < num_threads; i++)
403 vec_validate (esm->rx_buf[i], esm->rcv_buffer_size);
404
405 if (echo_server_attach (appns_id, appns_flags, appns_secret))
406 {
407 clib_warning ("failed to attach server");
408 return -1;
409 }
410 if (echo_server_listen ())
411 {
412 clib_warning ("failed to start listening");
413 if (echo_server_detach ())
414 clib_warning ("failed to detach");
415 return -1;
416 }
417 return 0;
418}
419
420static clib_error_t *
421echo_server_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
422 vlib_cli_command_t * cmd)
423{
424 echo_server_main_t *esm = &echo_server_main;
425 u8 server_uri_set = 0, *appns_id = 0;
426 u64 tmp, appns_flags = 0, appns_secret = 0;
427 char *default_uri = "tcp://0.0.0.0/1234";
Florin Corasf8f516a2018-02-08 15:10:09 -0800428 int rv, is_stop = 0;
Florin Coras4399c2e2018-01-25 06:34:42 -0800429
430 esm->no_echo = 0;
431 esm->fifo_size = 64 << 10;
432 esm->rcv_buffer_size = 128 << 10;
433 esm->prealloc_fifos = 0;
434 esm->private_segment_count = 0;
435 esm->private_segment_size = 0;
Florin Coras58d36f02018-03-09 13:05:53 -0800436 esm->tls_engine = TLS_ENGINE_OPENSSL;
Florin Coras7fb0fe12018-04-09 09:24:52 -0700437 esm->is_dgram = 0;
Florin Coras4399c2e2018-01-25 06:34:42 -0800438 vec_free (esm->server_uri);
439
440 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
441 {
442 if (unformat (input, "uri %s", &esm->server_uri))
443 server_uri_set = 1;
444 else if (unformat (input, "no-echo"))
445 esm->no_echo = 1;
446 else if (unformat (input, "fifo-size %d", &esm->fifo_size))
447 esm->fifo_size <<= 10;
448 else if (unformat (input, "rcv-buf-size %d", &esm->rcv_buffer_size))
449 ;
450 else if (unformat (input, "prealloc-fifos %d", &esm->prealloc_fifos))
451 ;
452 else if (unformat (input, "private-segment-count %d",
453 &esm->private_segment_count))
454 ;
455 else if (unformat (input, "private-segment-size %U",
456 unformat_memory_size, &tmp))
457 {
458 if (tmp >= 0x100000000ULL)
459 return clib_error_return
460 (0, "private segment size %lld (%llu) too large", tmp, tmp);
461 esm->private_segment_size = tmp;
462 }
463 else if (unformat (input, "appns %_%v%_", &appns_id))
464 ;
465 else if (unformat (input, "all-scope"))
466 appns_flags |= (APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE
467 | APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE);
468 else if (unformat (input, "local-scope"))
469 appns_flags |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
470 else if (unformat (input, "global-scope"))
471 appns_flags |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
472 else if (unformat (input, "secret %lu", &appns_secret))
473 ;
Florin Corasf8f516a2018-02-08 15:10:09 -0800474 else if (unformat (input, "stop"))
475 is_stop = 1;
Florin Coras58d36f02018-03-09 13:05:53 -0800476 else if (unformat (input, "tls-engine %d", &esm->tls_engine))
477 ;
Florin Coras4399c2e2018-01-25 06:34:42 -0800478 else
479 return clib_error_return (0, "failed: unknown input `%U'",
480 format_unformat_error, input);
481 }
482
Florin Corasf8f516a2018-02-08 15:10:09 -0800483 if (is_stop)
484 {
485 if (esm->app_index == (u32) ~ 0)
486 {
487 clib_warning ("server not running");
488 return clib_error_return (0, "failed: server not running");
489 }
490 rv = echo_server_detach ();
491 if (rv)
492 {
493 clib_warning ("failed: detach");
494 return clib_error_return (0, "failed: server detach %d", rv);
495 }
496 return 0;
497 }
498
Florin Coras4399c2e2018-01-25 06:34:42 -0800499 vnet_session_enable_disable (vm, 1 /* turn on TCP, etc. */ );
500
501 if (!server_uri_set)
502 {
503 clib_warning ("No uri provided! Using default: %s", default_uri);
504 esm->server_uri = (char *) format (0, "%s%c", default_uri, 0);
505 }
Florin Coras7fb0fe12018-04-09 09:24:52 -0700506 if (esm->server_uri[0] == 'u' && esm->server_uri[3] != 'c')
507 esm->is_dgram = 1;
Florin Coras4399c2e2018-01-25 06:34:42 -0800508
509 rv = echo_server_create (vm, appns_id, appns_flags, appns_secret);
510 vec_free (appns_id);
511 if (rv)
512 {
513 vec_free (esm->server_uri);
514 return clib_error_return (0, "failed: server_create returned %d", rv);
515 }
516
517 return 0;
518}
519
520/* *INDENT-OFF* */
521VLIB_CLI_COMMAND (echo_server_create_command, static) =
522{
523 .path = "test echo server",
524 .short_help = "test echo server proto <proto> [no echo][fifo-size <mbytes>]"
525 "[rcv-buf-size <bytes>][prealloc-fifos <count>]"
526 "[private-segment-count <count>][private-segment-size <bytes[m|g]>]"
527 "[uri <tcp://ip/port>]",
528 .function = echo_server_create_command_fn,
529};
530/* *INDENT-ON* */
531
532clib_error_t *
533echo_server_main_init (vlib_main_t * vm)
534{
535 echo_server_main_t *esm = &echo_server_main;
536 esm->my_client_index = ~0;
537 return 0;
538}
539
540VLIB_INIT_FUNCTION (echo_server_main_init);
541
542/*
543* fd.io coding-style-patch-verification: ON
544*
545* Local Variables:
546* eval: (c-set-style "gnu")
547* End:
548*/