blob: c0fdb1316036d59e102e23ac6d6468431fb647f1 [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>
20
21typedef struct
22{
23 /*
24 * Server app parameters
25 */
Florin Coras3c2fed52018-07-04 04:15:05 -070026 svm_msg_q_t **vpp_queue;
Florin Coras4399c2e2018-01-25 06:34:42 -080027 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 */
Florin Coras7fb0fe12018-04-09 09:24:52 -070037 u32 fifo_size; /**< Fifo size */
Florin Coras4399c2e2018-01-25 06:34:42 -080038 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 Coras58d36f02018-03-09 13:05:53 -080043 u32 tls_engine; /**< TLS engine: mbedtls/openssl */
Florin Coras7fb0fe12018-04-09 09:24:52 -070044 u8 is_dgram; /**< set if transport is dgram */
Florin Coras4399c2e2018-01-25 06:34:42 -080045 /*
46 * Test state
47 */
48 u8 **rx_buf; /**< Per-thread RX buffer */
49 u64 byte_index;
50 u32 **rx_retries;
51
52 vlib_main_t *vlib_main;
53} echo_server_main_t;
54
55echo_server_main_t echo_server_main;
56
57int
58echo_server_session_accept_callback (stream_session_t * s)
59{
60 echo_server_main_t *esm = &echo_server_main;
61
62 esm->vpp_queue[s->thread_index] =
63 session_manager_get_vpp_event_queue (s->thread_index);
64 s->session_state = SESSION_STATE_READY;
65 esm->byte_index = 0;
Florin Coras6f1c48d2018-05-02 14:34:32 -070066 ASSERT (vec_len (esm->rx_retries) > s->thread_index);
67 vec_validate (esm->rx_retries[s->thread_index], s->session_index);
Florin Coras4399c2e2018-01-25 06:34:42 -080068 esm->rx_retries[s->thread_index][s->session_index] = 0;
69 return 0;
70}
71
72void
73echo_server_session_disconnect_callback (stream_session_t * s)
74{
75 echo_server_main_t *esm = &echo_server_main;
Florin Coras4af830c2018-12-04 09:21:36 -080076 vnet_disconnect_args_t _a = { 0 }, *a = &_a;
Florin Coras4399c2e2018-01-25 06:34:42 -080077
78 a->handle = session_handle (s);
79 a->app_index = esm->app_index;
80 vnet_disconnect_session (a);
81}
82
83void
84echo_server_session_reset_callback (stream_session_t * s)
85{
Florin Coras4af830c2018-12-04 09:21:36 -080086 echo_server_main_t *esm = &echo_server_main;
87 vnet_disconnect_args_t _a = { 0 }, *a = &_a;
Florin Coras4399c2e2018-01-25 06:34:42 -080088 clib_warning ("Reset session %U", format_stream_session, s, 2);
Florin Coras4af830c2018-12-04 09:21:36 -080089 a->handle = session_handle (s);
90 a->app_index = esm->app_index;
91 vnet_disconnect_session (a);
Florin Coras4399c2e2018-01-25 06:34:42 -080092}
93
94int
95echo_server_session_connected_callback (u32 app_index, u32 api_context,
96 stream_session_t * s, u8 is_fail)
97{
98 clib_warning ("called...");
99 return -1;
100}
101
102int
Florin Corasfa76a762018-11-29 12:40:10 -0800103echo_server_add_segment_callback (u32 client_index, u64 segment_handle)
Florin Coras4399c2e2018-01-25 06:34:42 -0800104{
Florin Corasa332c462018-01-31 06:52:17 -0800105 /* New heaps may be added */
106 return 0;
Florin Coras4399c2e2018-01-25 06:34:42 -0800107}
108
109int
110echo_server_redirect_connect_callback (u32 client_index, void *mp)
111{
112 clib_warning ("called...");
113 return -1;
114}
115
116void
117test_bytes (echo_server_main_t * esm, int actual_transfer)
118{
119 int i;
120 u32 my_thread_id = vlib_get_thread_index ();
121
122 for (i = 0; i < actual_transfer; i++)
123 {
124 if (esm->rx_buf[my_thread_id][i] != ((esm->byte_index + i) & 0xff))
125 {
126 clib_warning ("at %lld expected %d got %d", esm->byte_index + i,
127 (esm->byte_index + i) & 0xff,
128 esm->rx_buf[my_thread_id][i]);
129 }
130 }
131 esm->byte_index += actual_transfer;
132}
133
134/*
Florin Coras7fb0fe12018-04-09 09:24:52 -0700135 * If no-echo, just drop the data and be done with it.
Florin Coras4399c2e2018-01-25 06:34:42 -0800136 */
137int
138echo_server_builtin_server_rx_callback_no_echo (stream_session_t * s)
139{
Florin Coras7fb0fe12018-04-09 09:24:52 -0700140 svm_fifo_t *rx_fifo = s->server_rx_fifo;
141 svm_fifo_dequeue_drop (rx_fifo, svm_fifo_max_dequeue (rx_fifo));
Florin Coras4399c2e2018-01-25 06:34:42 -0800142 return 0;
143}
144
145int
146echo_server_rx_callback (stream_session_t * s)
147{
148 u32 n_written, max_dequeue, max_enqueue, max_transfer;
149 int actual_transfer;
150 svm_fifo_t *tx_fifo, *rx_fifo;
151 echo_server_main_t *esm = &echo_server_main;
Florin Coras4399c2e2018-01-25 06:34:42 -0800152 u32 thread_index = vlib_get_thread_index ();
Florin Coras7fb0fe12018-04-09 09:24:52 -0700153 app_session_transport_t at;
Florin Coras4399c2e2018-01-25 06:34:42 -0800154
155 ASSERT (s->thread_index == thread_index);
156
157 rx_fifo = s->server_rx_fifo;
158 tx_fifo = s->server_tx_fifo;
159
160 ASSERT (rx_fifo->master_thread_index == thread_index);
161 ASSERT (tx_fifo->master_thread_index == thread_index);
162
Florin Coras7fb0fe12018-04-09 09:24:52 -0700163 max_enqueue = svm_fifo_max_enqueue (tx_fifo);
164 if (!esm->is_dgram)
165 {
166 max_dequeue = svm_fifo_max_dequeue (rx_fifo);
167 }
168 else
169 {
170 session_dgram_pre_hdr_t ph;
171 svm_fifo_peek (rx_fifo, 0, sizeof (ph), (u8 *) & ph);
172 max_dequeue = ph.data_length - ph.data_offset;
173 if (!esm->vpp_queue[s->thread_index])
174 {
Florin Coras3c2fed52018-07-04 04:15:05 -0700175 svm_msg_q_t *mq;
176 mq = session_manager_get_vpp_event_queue (s->thread_index);
177 esm->vpp_queue[s->thread_index] = mq;
Florin Coras7fb0fe12018-04-09 09:24:52 -0700178 }
179 max_enqueue -= sizeof (session_dgram_hdr_t);
180 }
Florin Coras4399c2e2018-01-25 06:34:42 -0800181
182 if (PREDICT_FALSE (max_dequeue == 0))
183 return 0;
184
185 /* Number of bytes we're going to copy */
Florin Coras7fb0fe12018-04-09 09:24:52 -0700186 max_transfer = clib_min (max_dequeue, max_enqueue);
Florin Coras4399c2e2018-01-25 06:34:42 -0800187
188 /* No space in tx fifo */
189 if (PREDICT_FALSE (max_transfer == 0))
190 {
191 /* XXX timeout for session that are stuck */
192
193 rx_event:
194 /* Program self-tap to retry */
195 if (svm_fifo_set_event (rx_fifo))
196 {
Florin Coras3c2fed52018-07-04 04:15:05 -0700197 if (session_send_io_evt_to_thread (rx_fifo, FIFO_EVENT_BUILTIN_RX))
Florin Coras4399c2e2018-01-25 06:34:42 -0800198 clib_warning ("failed to enqueue self-tap");
199
Florin Coras7fb0fe12018-04-09 09:24:52 -0700200 vec_validate (esm->rx_retries[s->thread_index], s->session_index);
Florin Coras4399c2e2018-01-25 06:34:42 -0800201 if (esm->rx_retries[thread_index][s->session_index] == 500000)
202 {
203 clib_warning ("session stuck: %U", format_stream_session, s, 2);
204 }
205 if (esm->rx_retries[thread_index][s->session_index] < 500001)
206 esm->rx_retries[thread_index][s->session_index]++;
207 }
208
209 return 0;
210 }
211
Florin Coras7fb0fe12018-04-09 09:24:52 -0700212 vec_validate (esm->rx_buf[thread_index], max_transfer);
213 if (!esm->is_dgram)
214 {
215 actual_transfer = app_recv_stream_raw (rx_fifo,
216 esm->rx_buf[thread_index],
217 max_transfer,
Florin Coras460dce62018-07-27 05:45:06 -0700218 0 /* don't clear event */ ,
219 0 /* peek */ );
Florin Coras7fb0fe12018-04-09 09:24:52 -0700220 }
221 else
222 {
223 actual_transfer = app_recv_dgram_raw (rx_fifo,
224 esm->rx_buf[thread_index],
225 max_transfer, &at,
Florin Coras460dce62018-07-27 05:45:06 -0700226 0 /* don't clear event */ ,
227 0 /* peek */ );
Florin Coras7fb0fe12018-04-09 09:24:52 -0700228 }
Florin Coras4399c2e2018-01-25 06:34:42 -0800229 ASSERT (actual_transfer == max_transfer);
Florin Coras7fb0fe12018-04-09 09:24:52 -0700230 /* test_bytes (esm, actual_transfer); */
Florin Coras4399c2e2018-01-25 06:34:42 -0800231
232 /*
233 * Echo back
234 */
235
Florin Coras7fb0fe12018-04-09 09:24:52 -0700236 if (!esm->is_dgram)
Florin Coras4399c2e2018-01-25 06:34:42 -0800237 {
Florin Coras7fb0fe12018-04-09 09:24:52 -0700238 n_written = app_send_stream_raw (tx_fifo,
239 esm->vpp_queue[thread_index],
240 esm->rx_buf[thread_index],
Florin Coras460dce62018-07-27 05:45:06 -0700241 actual_transfer, FIFO_EVENT_APP_TX, 0);
Florin Coras7fb0fe12018-04-09 09:24:52 -0700242 }
243 else
244 {
245 n_written = app_send_dgram_raw (tx_fifo, &at,
246 esm->vpp_queue[s->thread_index],
247 esm->rx_buf[thread_index],
Florin Coras460dce62018-07-27 05:45:06 -0700248 actual_transfer, FIFO_EVENT_APP_TX, 0);
Florin Coras4399c2e2018-01-25 06:34:42 -0800249 }
250
Florin Coras7fb0fe12018-04-09 09:24:52 -0700251 if (n_written != max_transfer)
252 clib_warning ("short trout! written %u read %u", n_written, max_transfer);
253
254 if (PREDICT_FALSE (svm_fifo_max_dequeue (rx_fifo)))
Florin Coras4399c2e2018-01-25 06:34:42 -0800255 goto rx_event;
256
257 return 0;
258}
259
260static session_cb_vft_t echo_server_session_cb_vft = {
261 .session_accept_callback = echo_server_session_accept_callback,
262 .session_disconnect_callback = echo_server_session_disconnect_callback,
263 .session_connected_callback = echo_server_session_connected_callback,
264 .add_segment_callback = echo_server_add_segment_callback,
Florin Coras371ca502018-02-21 12:07:41 -0800265 .builtin_app_rx_callback = echo_server_rx_callback,
Florin Coras4399c2e2018-01-25 06:34:42 -0800266 .session_reset_callback = echo_server_session_reset_callback
267};
268
269/* Abuse VPP's input queue */
270static int
271create_api_loopback (vlib_main_t * vm)
272{
273 echo_server_main_t *esm = &echo_server_main;
274 api_main_t *am = &api_main;
275 vl_shmem_hdr_t *shmem_hdr;
276
277 shmem_hdr = am->shmem_hdr;
278 esm->vl_input_queue = shmem_hdr->vl_input_queue;
279 esm->my_client_index = vl_api_memclnt_create_internal ("echo_server",
280 esm->vl_input_queue);
281 return 0;
282}
283
284static int
285echo_server_attach (u8 * appns_id, u64 appns_flags, u64 appns_secret)
286{
Florin Coras371ca502018-02-21 12:07:41 -0800287 vnet_app_add_tls_cert_args_t _a_cert, *a_cert = &_a_cert;
288 vnet_app_add_tls_key_args_t _a_key, *a_key = &_a_key;
Florin Coras4399c2e2018-01-25 06:34:42 -0800289 echo_server_main_t *esm = &echo_server_main;
Florin Coras4399c2e2018-01-25 06:34:42 -0800290 vnet_app_attach_args_t _a, *a = &_a;
Florin Coras371ca502018-02-21 12:07:41 -0800291 u64 options[APP_OPTIONS_N_OPTIONS];
Florin Coras4399c2e2018-01-25 06:34:42 -0800292 u32 segment_size = 512 << 20;
293
Dave Barachb7b92992018-10-17 10:38:51 -0400294 clib_memset (a, 0, sizeof (*a));
295 clib_memset (options, 0, sizeof (options));
Florin Coras4399c2e2018-01-25 06:34:42 -0800296
297 if (esm->no_echo)
Florin Coras371ca502018-02-21 12:07:41 -0800298 echo_server_session_cb_vft.builtin_app_rx_callback =
Florin Coras4399c2e2018-01-25 06:34:42 -0800299 echo_server_builtin_server_rx_callback_no_echo;
300 else
Florin Coras371ca502018-02-21 12:07:41 -0800301 echo_server_session_cb_vft.builtin_app_rx_callback =
Florin Coras4399c2e2018-01-25 06:34:42 -0800302 echo_server_rx_callback;
303
304 if (esm->private_segment_size)
305 segment_size = esm->private_segment_size;
306
307 a->api_client_index = esm->my_client_index;
308 a->session_cb_vft = &echo_server_session_cb_vft;
309 a->options = options;
310 a->options[APP_OPTIONS_SEGMENT_SIZE] = segment_size;
Florin Corasa332c462018-01-31 06:52:17 -0800311 a->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = segment_size;
Florin Coras4399c2e2018-01-25 06:34:42 -0800312 a->options[APP_OPTIONS_RX_FIFO_SIZE] = esm->fifo_size;
313 a->options[APP_OPTIONS_TX_FIFO_SIZE] = esm->fifo_size;
314 a->options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = esm->private_segment_count;
Florin Coras58d36f02018-03-09 13:05:53 -0800315 a->options[APP_OPTIONS_TLS_ENGINE] = esm->tls_engine;
Florin Coras4399c2e2018-01-25 06:34:42 -0800316 a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] =
317 esm->prealloc_fifos ? esm->prealloc_fifos : 1;
318
319 a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
320 if (appns_id)
321 {
322 a->namespace_id = appns_id;
323 a->options[APP_OPTIONS_FLAGS] |= appns_flags;
324 a->options[APP_OPTIONS_NAMESPACE_SECRET] = appns_secret;
325 }
326
327 if (vnet_application_attach (a))
328 {
329 clib_warning ("failed to attach server");
330 return -1;
331 }
332 esm->app_index = a->app_index;
Florin Coras371ca502018-02-21 12:07:41 -0800333
Dave Barachb7b92992018-10-17 10:38:51 -0400334 clib_memset (a_cert, 0, sizeof (*a_cert));
Florin Coras371ca502018-02-21 12:07:41 -0800335 a_cert->app_index = a->app_index;
336 vec_validate (a_cert->cert, test_srv_crt_rsa_len);
Dave Barach178cf492018-11-13 16:34:13 -0500337 clib_memcpy_fast (a_cert->cert, test_srv_crt_rsa, test_srv_crt_rsa_len);
Florin Coras371ca502018-02-21 12:07:41 -0800338 vnet_app_add_tls_cert (a_cert);
339
Dave Barachb7b92992018-10-17 10:38:51 -0400340 clib_memset (a_key, 0, sizeof (*a_key));
Florin Coras371ca502018-02-21 12:07:41 -0800341 a_key->app_index = a->app_index;
342 vec_validate (a_key->key, test_srv_key_rsa_len);
Dave Barach178cf492018-11-13 16:34:13 -0500343 clib_memcpy_fast (a_key->key, test_srv_key_rsa, test_srv_key_rsa_len);
Florin Coras371ca502018-02-21 12:07:41 -0800344 vnet_app_add_tls_key (a_key);
Florin Coras4399c2e2018-01-25 06:34:42 -0800345 return 0;
346}
347
348static int
349echo_server_detach (void)
350{
351 echo_server_main_t *esm = &echo_server_main;
352 vnet_app_detach_args_t _da, *da = &_da;
353 int rv;
354
355 da->app_index = esm->app_index;
356 rv = vnet_application_detach (da);
357 esm->app_index = ~0;
358 return rv;
359}
360
361static int
362echo_server_listen ()
363{
364 echo_server_main_t *esm = &echo_server_main;
365 vnet_bind_args_t _a, *a = &_a;
Dave Barachb7b92992018-10-17 10:38:51 -0400366 clib_memset (a, 0, sizeof (*a));
Florin Coras4399c2e2018-01-25 06:34:42 -0800367 a->app_index = esm->app_index;
368 a->uri = esm->server_uri;
369 return vnet_bind_uri (a);
370}
371
372static int
373echo_server_create (vlib_main_t * vm, u8 * appns_id, u64 appns_flags,
374 u64 appns_secret)
375{
376 echo_server_main_t *esm = &echo_server_main;
377 vlib_thread_main_t *vtm = vlib_get_thread_main ();
378 u32 num_threads;
379 int i;
380
381 if (esm->my_client_index == (u32) ~ 0)
382 {
383 if (create_api_loopback (vm))
384 {
385 clib_warning ("failed to create api loopback");
386 return -1;
387 }
388 }
389
390 num_threads = 1 /* main thread */ + vtm->n_threads;
391 vec_validate (echo_server_main.vpp_queue, num_threads - 1);
392 vec_validate (esm->rx_buf, num_threads - 1);
393 vec_validate (esm->rx_retries, num_threads - 1);
Florin Corasc1a448b2018-04-20 10:51:49 -0700394 for (i = 0; i < vec_len (esm->rx_retries); i++)
395 vec_validate (esm->rx_retries[i],
Florin Coras5a7ca7b2018-10-30 12:01:48 -0700396 pool_elts (session_manager_main.wrk[i].sessions));
Florin Coras81a13db2018-03-16 08:48:31 -0700397 esm->rcv_buffer_size = clib_max (esm->rcv_buffer_size, esm->fifo_size);
Florin Coras4399c2e2018-01-25 06:34:42 -0800398 for (i = 0; i < num_threads; i++)
399 vec_validate (esm->rx_buf[i], esm->rcv_buffer_size);
400
401 if (echo_server_attach (appns_id, appns_flags, appns_secret))
402 {
403 clib_warning ("failed to attach server");
404 return -1;
405 }
406 if (echo_server_listen ())
407 {
408 clib_warning ("failed to start listening");
409 if (echo_server_detach ())
410 clib_warning ("failed to detach");
411 return -1;
412 }
413 return 0;
414}
415
416static clib_error_t *
417echo_server_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
418 vlib_cli_command_t * cmd)
419{
420 echo_server_main_t *esm = &echo_server_main;
421 u8 server_uri_set = 0, *appns_id = 0;
422 u64 tmp, appns_flags = 0, appns_secret = 0;
423 char *default_uri = "tcp://0.0.0.0/1234";
Florin Corasf8f516a2018-02-08 15:10:09 -0800424 int rv, is_stop = 0;
Florin Coras4399c2e2018-01-25 06:34:42 -0800425
426 esm->no_echo = 0;
427 esm->fifo_size = 64 << 10;
428 esm->rcv_buffer_size = 128 << 10;
429 esm->prealloc_fifos = 0;
430 esm->private_segment_count = 0;
431 esm->private_segment_size = 0;
Florin Coras58d36f02018-03-09 13:05:53 -0800432 esm->tls_engine = TLS_ENGINE_OPENSSL;
Florin Coras7fb0fe12018-04-09 09:24:52 -0700433 esm->is_dgram = 0;
Florin Coras4399c2e2018-01-25 06:34:42 -0800434 vec_free (esm->server_uri);
435
436 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
437 {
438 if (unformat (input, "uri %s", &esm->server_uri))
439 server_uri_set = 1;
440 else if (unformat (input, "no-echo"))
441 esm->no_echo = 1;
442 else if (unformat (input, "fifo-size %d", &esm->fifo_size))
443 esm->fifo_size <<= 10;
444 else if (unformat (input, "rcv-buf-size %d", &esm->rcv_buffer_size))
445 ;
446 else if (unformat (input, "prealloc-fifos %d", &esm->prealloc_fifos))
447 ;
448 else if (unformat (input, "private-segment-count %d",
449 &esm->private_segment_count))
450 ;
451 else if (unformat (input, "private-segment-size %U",
452 unformat_memory_size, &tmp))
453 {
454 if (tmp >= 0x100000000ULL)
455 return clib_error_return
456 (0, "private segment size %lld (%llu) too large", tmp, tmp);
457 esm->private_segment_size = tmp;
458 }
459 else if (unformat (input, "appns %_%v%_", &appns_id))
460 ;
461 else if (unformat (input, "all-scope"))
462 appns_flags |= (APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE
463 | APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE);
464 else if (unformat (input, "local-scope"))
465 appns_flags |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
466 else if (unformat (input, "global-scope"))
467 appns_flags |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
468 else if (unformat (input, "secret %lu", &appns_secret))
469 ;
Florin Corasf8f516a2018-02-08 15:10:09 -0800470 else if (unformat (input, "stop"))
471 is_stop = 1;
Florin Coras58d36f02018-03-09 13:05:53 -0800472 else if (unformat (input, "tls-engine %d", &esm->tls_engine))
473 ;
Florin Coras4399c2e2018-01-25 06:34:42 -0800474 else
475 return clib_error_return (0, "failed: unknown input `%U'",
476 format_unformat_error, input);
477 }
478
Florin Corasf8f516a2018-02-08 15:10:09 -0800479 if (is_stop)
480 {
481 if (esm->app_index == (u32) ~ 0)
482 {
483 clib_warning ("server not running");
484 return clib_error_return (0, "failed: server not running");
485 }
486 rv = echo_server_detach ();
487 if (rv)
488 {
489 clib_warning ("failed: detach");
490 return clib_error_return (0, "failed: server detach %d", rv);
491 }
492 return 0;
493 }
494
Florin Coras4399c2e2018-01-25 06:34:42 -0800495 vnet_session_enable_disable (vm, 1 /* turn on TCP, etc. */ );
496
497 if (!server_uri_set)
498 {
499 clib_warning ("No uri provided! Using default: %s", default_uri);
500 esm->server_uri = (char *) format (0, "%s%c", default_uri, 0);
501 }
Florin Coras7fb0fe12018-04-09 09:24:52 -0700502 if (esm->server_uri[0] == 'u' && esm->server_uri[3] != 'c')
503 esm->is_dgram = 1;
Florin Coras4399c2e2018-01-25 06:34:42 -0800504
505 rv = echo_server_create (vm, appns_id, appns_flags, appns_secret);
506 vec_free (appns_id);
507 if (rv)
508 {
509 vec_free (esm->server_uri);
510 return clib_error_return (0, "failed: server_create returned %d", rv);
511 }
512
513 return 0;
514}
515
516/* *INDENT-OFF* */
517VLIB_CLI_COMMAND (echo_server_create_command, static) =
518{
519 .path = "test echo server",
520 .short_help = "test echo server proto <proto> [no echo][fifo-size <mbytes>]"
521 "[rcv-buf-size <bytes>][prealloc-fifos <count>]"
522 "[private-segment-count <count>][private-segment-size <bytes[m|g]>]"
523 "[uri <tcp://ip/port>]",
524 .function = echo_server_create_command_fn,
525};
526/* *INDENT-ON* */
527
528clib_error_t *
529echo_server_main_init (vlib_main_t * vm)
530{
531 echo_server_main_t *esm = &echo_server_main;
532 esm->my_client_index = ~0;
533 return 0;
534}
535
536VLIB_INIT_FUNCTION (echo_server_main_init);
537
538/*
539* fd.io coding-style-patch-verification: ON
540*
541* Local Variables:
542* eval: (c-set-style "gnu")
543* End:
544*/