453cbed3859b65d8d7a32160c41489c4f7746601
[vpp.git] / src / plugins / hs_apps / echo_client.c
1 /*
2  * echo_client.c - vpp built-in echo client code
3  *
4  * Copyright (c) 2017-2019 by Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <hs_apps/echo_client.h>
19
20 static ec_main_t ec_main;
21
22 #define ec_err(_fmt, _args...) clib_warning (_fmt, ##_args);
23
24 #define ec_dbg(_fmt, _args...)                                                \
25   do                                                                          \
26     {                                                                         \
27       if (ec_main.cfg.verbose)                                                \
28         ec_err (_fmt, ##_args);                                               \
29     }                                                                         \
30   while (0)
31
32 #define ec_cli(_fmt, _args...) vlib_cli_output (vm, _fmt, ##_args)
33
34 static void
35 signal_evt_to_cli_i (void *codep)
36 {
37   ec_main_t *ecm = &ec_main;
38   int code;
39
40   ASSERT (vlib_get_thread_index () == 0);
41   code = pointer_to_uword (codep);
42   vlib_process_signal_event (ecm->vlib_main, ecm->cli_node_index, code, 0);
43 }
44
45 static void
46 signal_evt_to_cli (int code)
47 {
48   if (vlib_get_thread_index () != 0)
49     session_send_rpc_evt_to_thread_force (
50       0, signal_evt_to_cli_i, uword_to_pointer ((uword) code, void *));
51   else
52     signal_evt_to_cli_i (uword_to_pointer ((uword) code, void *));
53 }
54
55 static inline ec_worker_t *
56 ec_worker_get (u32 thread_index)
57 {
58   return vec_elt_at_index (ec_main.wrk, thread_index);
59 }
60
61 static inline ec_session_t *
62 ec_session_alloc (ec_worker_t *wrk)
63 {
64   ec_session_t *ecs;
65
66   pool_get_zero (wrk->sessions, ecs);
67   ecs->data.session_index = ecs - wrk->sessions;
68   ecs->thread_index = wrk->thread_index;
69
70   return ecs;
71 }
72
73 static inline ec_session_t *
74 ec_session_get (ec_worker_t *wrk, u32 ec_index)
75 {
76   return pool_elt_at_index (wrk->sessions, ec_index);
77 }
78
79 static void
80 send_data_chunk (ec_main_t *ecm, ec_session_t *es)
81 {
82   u8 *test_data = ecm->connect_test_data;
83   int test_buf_len, test_buf_offset, rv;
84   u32 bytes_this_chunk;
85
86   test_buf_len = vec_len (test_data);
87   ASSERT (test_buf_len > 0);
88   test_buf_offset = es->bytes_sent % test_buf_len;
89   bytes_this_chunk =
90     clib_min (test_buf_len - test_buf_offset, es->bytes_to_send);
91
92   if (!ecm->is_dgram)
93     {
94       if (ecm->no_copy)
95         {
96           svm_fifo_t *f = es->data.tx_fifo;
97           rv = clib_min (svm_fifo_max_enqueue_prod (f), bytes_this_chunk);
98           svm_fifo_enqueue_nocopy (f, rv);
99           session_send_io_evt_to_thread_custom (
100             &es->vpp_session_index, es->thread_index, SESSION_IO_EVT_TX);
101         }
102       else
103         rv = app_send_stream (&es->data, test_data + test_buf_offset,
104                               bytes_this_chunk, 0);
105     }
106   else
107     {
108       svm_fifo_t *f = es->data.tx_fifo;
109       u32 max_enqueue = svm_fifo_max_enqueue_prod (f);
110
111       if (max_enqueue < sizeof (session_dgram_hdr_t))
112         return;
113
114       max_enqueue -= sizeof (session_dgram_hdr_t);
115
116       if (ecm->no_copy)
117         {
118           session_dgram_hdr_t hdr;
119           app_session_transport_t *at = &es->data.transport;
120
121           rv = clib_min (max_enqueue, bytes_this_chunk);
122
123           hdr.data_length = rv;
124           hdr.data_offset = 0;
125           clib_memcpy_fast (&hdr.rmt_ip, &at->rmt_ip,
126                             sizeof (ip46_address_t));
127           hdr.is_ip4 = at->is_ip4;
128           hdr.rmt_port = at->rmt_port;
129           clib_memcpy_fast (&hdr.lcl_ip, &at->lcl_ip,
130                             sizeof (ip46_address_t));
131           hdr.lcl_port = at->lcl_port;
132           svm_fifo_enqueue (f, sizeof (hdr), (u8 *) & hdr);
133           svm_fifo_enqueue_nocopy (f, rv);
134           session_send_io_evt_to_thread_custom (
135             &es->vpp_session_index, es->thread_index, SESSION_IO_EVT_TX);
136         }
137       else
138         {
139           bytes_this_chunk = clib_min (bytes_this_chunk, max_enqueue);
140           bytes_this_chunk = clib_min (bytes_this_chunk, 1460);
141           rv = app_send_dgram (&es->data, test_data + test_buf_offset,
142                                bytes_this_chunk, 0);
143         }
144     }
145
146   /* If we managed to enqueue data... */
147   if (rv > 0)
148     {
149       /* Account for it... */
150       es->bytes_to_send -= rv;
151       es->bytes_sent += rv;
152
153       if (ecm->cfg.verbose)
154         {
155           ELOG_TYPE_DECLARE (e) =
156             {
157               .format = "tx-enq: xfer %d bytes, sent %u remain %u",
158               .format_args = "i4i4i4",
159             };
160           struct
161           {
162             u32 data[3];
163           } *ed;
164           ed = ELOG_DATA (&vlib_global_main.elog_main, e);
165           ed->data[0] = rv;
166           ed->data[1] = es->bytes_sent;
167           ed->data[2] = es->bytes_to_send;
168         }
169     }
170 }
171
172 static void
173 receive_data_chunk (ec_worker_t *wrk, ec_session_t *es)
174 {
175   ec_main_t *ecm = &ec_main;
176   svm_fifo_t *rx_fifo = es->data.rx_fifo;
177   int n_read, i;
178
179   if (ecm->cfg.test_bytes)
180     {
181       if (!ecm->is_dgram)
182         n_read =
183           app_recv_stream (&es->data, wrk->rx_buf, vec_len (wrk->rx_buf));
184       else
185         n_read =
186           app_recv_dgram (&es->data, wrk->rx_buf, vec_len (wrk->rx_buf));
187     }
188   else
189     {
190       n_read = svm_fifo_max_dequeue_cons (rx_fifo);
191       svm_fifo_dequeue_drop (rx_fifo, n_read);
192     }
193
194   if (n_read > 0)
195     {
196       if (ecm->cfg.verbose)
197         {
198           ELOG_TYPE_DECLARE (e) =
199             {
200               .format = "rx-deq: %d bytes",
201               .format_args = "i4",
202             };
203           struct
204           {
205             u32 data[1];
206           } *ed;
207           ed = ELOG_DATA (&vlib_global_main.elog_main, e);
208           ed->data[0] = n_read;
209         }
210
211       if (ecm->cfg.test_bytes)
212         {
213           for (i = 0; i < n_read; i++)
214             {
215               if (wrk->rx_buf[i] != ((es->bytes_received + i) & 0xff))
216                 {
217                   ec_err ("read %d error at byte %lld, 0x%x not 0x%x", n_read,
218                           es->bytes_received + i, wrk->rx_buf[i],
219                           ((es->bytes_received + i) & 0xff));
220                   ecm->test_failed = 1;
221                 }
222             }
223         }
224       ASSERT (n_read <= es->bytes_to_receive);
225       es->bytes_to_receive -= n_read;
226       es->bytes_received += n_read;
227     }
228 }
229
230 static uword
231 ec_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
232 {
233   u32 *conn_indices, *conns_this_batch, nconns_this_batch;
234   int thread_index = vm->thread_index, i, delete_session;
235   ec_main_t *ecm = &ec_main;
236   ec_worker_t *wrk;
237   ec_session_t *es;
238   session_t *s;
239
240   if (ecm->run_test != EC_RUNNING)
241     return 0;
242
243   wrk = ec_worker_get (thread_index);
244   conn_indices = wrk->conn_indices;
245   conns_this_batch = wrk->conns_this_batch;
246
247   if (((vec_len (conn_indices) == 0) && vec_len (conns_this_batch) == 0))
248     return 0;
249
250   /* Grab another pile of connections */
251   if (PREDICT_FALSE (vec_len (conns_this_batch) == 0))
252     {
253       nconns_this_batch =
254         clib_min (ecm->connections_per_batch, vec_len (conn_indices));
255
256       ASSERT (nconns_this_batch > 0);
257       vec_validate (conns_this_batch, nconns_this_batch - 1);
258       clib_memcpy_fast (conns_this_batch,
259                         conn_indices + vec_len (conn_indices) -
260                           nconns_this_batch,
261                         nconns_this_batch * sizeof (u32));
262       vec_dec_len (conn_indices, nconns_this_batch);
263     }
264
265   /*
266    * Track progress
267    */
268   if (PREDICT_FALSE (ecm->prev_conns != ecm->connections_per_batch &&
269                      ecm->prev_conns == vec_len (conns_this_batch)))
270     {
271       ecm->repeats++;
272       ecm->prev_conns = vec_len (conns_this_batch);
273       if (ecm->repeats == 500000)
274         {
275           ec_err ("stuck clients");
276         }
277     }
278   else
279     {
280       ecm->prev_conns = vec_len (conns_this_batch);
281       ecm->repeats = 0;
282     }
283
284   /*
285    * Handle connections in this batch
286    */
287   for (i = 0; i < vec_len (conns_this_batch); i++)
288     {
289       es = ec_session_get (wrk, conns_this_batch[i]);
290
291       delete_session = 1;
292
293       if (es->bytes_to_send > 0)
294         {
295           send_data_chunk (ecm, es);
296           delete_session = 0;
297         }
298
299       if (es->bytes_to_receive > 0)
300         {
301           delete_session = 0;
302         }
303
304       if (PREDICT_FALSE (delete_session == 1))
305         {
306           clib_atomic_fetch_add (&ecm->tx_total, es->bytes_sent);
307           clib_atomic_fetch_add (&ecm->rx_total, es->bytes_received);
308           s = session_get_from_handle_if_valid (es->vpp_session_handle);
309
310           if (s)
311             {
312               vnet_disconnect_args_t _a, *a = &_a;
313               a->handle = session_handle (s);
314               a->app_index = ecm->app_index;
315               vnet_disconnect_session (a);
316
317               vec_delete (conns_this_batch, 1, i);
318               i--;
319               clib_atomic_fetch_add (&ecm->ready_connections, -1);
320             }
321           else
322             {
323               ec_err ("session AWOL?");
324               vec_delete (conns_this_batch, 1, i);
325             }
326
327           /* Kick the debug CLI process */
328           if (ecm->ready_connections == 0)
329             {
330               signal_evt_to_cli (EC_CLI_TEST_DONE);
331             }
332         }
333     }
334
335   wrk->conn_indices = conn_indices;
336   wrk->conns_this_batch = conns_this_batch;
337   return 0;
338 }
339
340 VLIB_REGISTER_NODE (echo_clients_node) = {
341   .function = ec_node_fn,
342   .name = "echo-clients",
343   .type = VLIB_NODE_TYPE_INPUT,
344   .state = VLIB_NODE_STATE_DISABLED,
345 };
346
347 static void
348 ec_reset_runtime_config (ec_main_t *ecm)
349 {
350   hs_test_cfg_init (&ecm->cfg);
351   ecm->n_clients = 1;
352   ecm->quic_streams = 1;
353   ecm->bytes_to_send = 8192;
354   ecm->echo_bytes = 0;
355   ecm->fifo_size = 64 << 10;
356   ecm->connections_per_batch = 1000;
357   ecm->private_segment_count = 0;
358   ecm->private_segment_size = 256 << 20;
359   ecm->test_failed = 0;
360   ecm->tls_engine = CRYPTO_ENGINE_OPENSSL;
361   ecm->no_copy = 0;
362   ecm->run_test = EC_STARTING;
363   ecm->ready_connections = 0;
364   ecm->connect_conn_index = 0;
365   ecm->rx_total = 0;
366   ecm->tx_total = 0;
367   ecm->barrier_acq_needed = 0;
368   ecm->prealloc_sessions = 0;
369   ecm->prealloc_fifos = 0;
370   ecm->appns_id = 0;
371   ecm->appns_secret = 0;
372   ecm->attach_flags = 0;
373   ecm->syn_timeout = 20.0;
374   ecm->test_timeout = 20.0;
375   vec_free (ecm->connect_uri);
376 }
377
378 static int
379 ec_init (vlib_main_t *vm)
380 {
381   ec_main_t *ecm = &ec_main;
382   ec_worker_t *wrk;
383   u32 num_threads;
384   int i;
385
386   ec_reset_runtime_config (ecm);
387
388   /* Store cli process node index for signaling */
389   ecm->cli_node_index = vlib_get_current_process (vm)->node_runtime.node_index;
390   ecm->vlib_main = vm;
391
392   if (vlib_num_workers ())
393     {
394       /* The request came over the binary api and the inband cli handler
395        * is not mp_safe. Drop the barrier to make sure the workers are not
396        * blocked.
397        */
398       if (vlib_thread_is_main_w_barrier ())
399         {
400           ecm->barrier_acq_needed = 1;
401           vlib_worker_thread_barrier_release (vm);
402         }
403       /*
404        * There's a good chance that both the client and the server echo
405        * apps will be enabled so make sure the session queue node polls on
406        * the main thread as connections will probably be established on it.
407        */
408       vlib_node_set_state (vm, session_queue_node.index,
409                            VLIB_NODE_STATE_POLLING);
410     }
411
412   /* App init done only once */
413   if (ecm->app_is_init)
414     return 0;
415
416
417   /* Init test data. Big buffer */
418   vec_validate (ecm->connect_test_data, 4 * 1024 * 1024 - 1);
419   for (i = 0; i < vec_len (ecm->connect_test_data); i++)
420     ecm->connect_test_data[i] = i & 0xff;
421
422   num_threads = 1 /* main thread */ + vlib_num_workers ();
423   vec_validate (ecm->wrk, num_threads - 1);
424   vec_foreach (wrk, ecm->wrk)
425     {
426       vec_validate (wrk->rx_buf, vec_len (ecm->connect_test_data) - 1);
427       wrk->thread_index = wrk - ecm->wrk;
428       wrk->vpp_event_queue =
429         session_main_get_vpp_event_queue (wrk->thread_index);
430     }
431
432   ecm->app_is_init = 1;
433
434   vlib_worker_thread_barrier_sync (vm);
435   vnet_session_enable_disable (vm, 1 /* turn on session and transports */);
436
437   /* Turn on the builtin client input nodes */
438   foreach_vlib_main ()
439     vlib_node_set_state (this_vlib_main, echo_clients_node.index,
440                          VLIB_NODE_STATE_POLLING);
441
442   vlib_worker_thread_barrier_release (vm);
443
444   return 0;
445 }
446
447 static void
448 ec_prealloc_sessions (ec_main_t *ecm)
449 {
450   u32 sessions_per_wrk, n_wrks;
451   ec_worker_t *wrk;
452
453   n_wrks = vlib_num_workers () ? vlib_num_workers () : 1;
454
455   sessions_per_wrk = ecm->n_clients / n_wrks;
456   vec_foreach (wrk, ecm->wrk)
457     pool_init_fixed (wrk->sessions, 1.1 * sessions_per_wrk);
458 }
459
460 static void
461 ec_worker_cleanup (ec_worker_t *wrk)
462 {
463   pool_free (wrk->sessions);
464   vec_free (wrk->conn_indices);
465   vec_free (wrk->conns_this_batch);
466 }
467
468 static void
469 ec_cleanup (ec_main_t *ecm)
470 {
471   ec_worker_t *wrk;
472
473   vec_foreach (wrk, ecm->wrk)
474     ec_worker_cleanup (wrk);
475
476   vec_free (ecm->connect_uri);
477   vec_free (ecm->appns_id);
478
479   if (ecm->barrier_acq_needed)
480     vlib_worker_thread_barrier_sync (ecm->vlib_main);
481 }
482
483 static int
484 quic_ec_qsession_connected_callback (u32 app_index, u32 api_context,
485                                      session_t *s, session_error_t err)
486 {
487   session_endpoint_cfg_t sep = SESSION_ENDPOINT_CFG_NULL;
488   ec_main_t *ecm = &ec_main;
489   vnet_connect_args_t _a, *a = &_a;
490   u32 stream_n;
491   int rv;
492
493   ec_dbg ("QUIC Connection handle %d", session_handle (s));
494
495   a->uri = (char *) ecm->connect_uri;
496   if (parse_uri (a->uri, &sep))
497     return -1;
498   sep.parent_handle = session_handle (s);
499
500   for (stream_n = 0; stream_n < ecm->quic_streams; stream_n++)
501     {
502       clib_memset (a, 0, sizeof (*a));
503       a->app_index = ecm->app_index;
504       a->api_context = -2 - api_context;
505       clib_memcpy (&a->sep_ext, &sep, sizeof (sep));
506
507       ec_dbg ("QUIC opening stream %d", stream_n);
508       if ((rv = vnet_connect (a)))
509         {
510           clib_error ("Stream session %d opening failed: %d", stream_n, rv);
511           return -1;
512         }
513       ec_dbg ("QUIC stream %d connected", stream_n);
514     }
515   return 0;
516 }
517
518 static int
519 ec_ctrl_send (hs_test_cmd_t cmd)
520 {
521   ec_main_t *ecm = &ec_main;
522   session_t *s;
523   int rv;
524
525   ecm->cfg.cmd = cmd;
526   if (ecm->ctrl_session_handle == SESSION_INVALID_HANDLE)
527     {
528       ec_dbg ("ctrl session went away");
529       return -1;
530     }
531
532   s = session_get_from_handle_if_valid (ecm->ctrl_session_handle);
533   if (!s)
534     {
535       ec_err ("ctrl session not found");
536       return -1;
537     }
538
539   ec_dbg ("sending test paramters to the server..");
540   if (ecm->cfg.verbose)
541     hs_test_cfg_dump (&ecm->cfg, 1);
542
543   rv = svm_fifo_enqueue (s->tx_fifo, sizeof (ecm->cfg), (u8 *) &ecm->cfg);
544   ASSERT (rv == sizeof (ecm->cfg));
545   session_send_io_evt_to_thread (s->tx_fifo, SESSION_IO_EVT_TX);
546   return 0;
547 }
548
549 static int
550 ec_ctrl_session_connected_callback (session_t *s)
551 {
552   ec_main_t *ecm = &ec_main;
553
554   s->opaque = HS_CTRL_HANDLE;
555   ecm->ctrl_session_handle = session_handle (s);
556
557   /* send test parameters to the server */
558   ec_ctrl_send (HS_TEST_CMD_SYNC);
559   return 0;
560 }
561
562 static int
563 quic_ec_session_connected_callback (u32 app_index, u32 api_context,
564                                     session_t *s, session_error_t err)
565 {
566   ec_main_t *ecm = &ec_main;
567   ec_session_t *es;
568   ec_worker_t *wrk;
569   u32 thread_index;
570
571   if (PREDICT_FALSE (api_context == HS_CTRL_HANDLE))
572     return ec_ctrl_session_connected_callback (s);
573
574   if (PREDICT_FALSE (ecm->run_test != EC_STARTING))
575     return -1;
576
577   if (err)
578     {
579       ec_err ("connection %d failed!", api_context);
580       ecm->run_test = EC_EXITING;
581       signal_evt_to_cli (EC_CLI_CONNECTS_FAILED);
582       return 0;
583     }
584
585   if (s->listener_handle == SESSION_INVALID_HANDLE)
586     return quic_ec_qsession_connected_callback (app_index, api_context, s,
587                                                 err);
588   ec_dbg ("STREAM Connection callback %d", api_context);
589
590   thread_index = s->thread_index;
591   ASSERT (thread_index == vlib_get_thread_index ()
592           || session_transport_service_type (s) == TRANSPORT_SERVICE_CL);
593
594   wrk = ec_worker_get (thread_index);
595
596   /*
597    * Setup session
598    */
599   es = ec_session_alloc (wrk);
600
601   es->bytes_to_send = ecm->bytes_to_send;
602   es->bytes_to_receive = ecm->echo_bytes ? ecm->bytes_to_send : 0ULL;
603   es->data.rx_fifo = s->rx_fifo;
604   es->data.rx_fifo->shr->client_session_index = es->data.session_index;
605   es->data.tx_fifo = s->tx_fifo;
606   es->data.tx_fifo->shr->client_session_index = es->data.session_index;
607   es->data.vpp_evt_q = wrk->vpp_event_queue;
608   es->vpp_session_handle = session_handle (s);
609   es->vpp_session_index = s->session_index;
610   s->opaque = es->data.session_index;
611
612   if (ecm->is_dgram)
613     {
614       transport_connection_t *tc;
615       tc = session_get_transport (s);
616       clib_memcpy_fast (&es->data.transport, tc, sizeof (es->data.transport));
617       es->data.is_dgram = 1;
618     }
619
620   vec_add1 (wrk->conn_indices, es->data.session_index);
621   clib_atomic_fetch_add (&ecm->ready_connections, 1);
622   if (ecm->ready_connections == ecm->expected_connections)
623     {
624       ecm->run_test = EC_RUNNING;
625       /* Signal the CLI process that the action is starting... */
626       signal_evt_to_cli (EC_CLI_CONNECTS_DONE);
627     }
628
629   return 0;
630 }
631
632 static int
633 ec_session_connected_callback (u32 app_index, u32 api_context, session_t *s,
634                                session_error_t err)
635 {
636   ec_main_t *ecm = &ec_main;
637   ec_session_t *es;
638   u32 thread_index;
639   ec_worker_t *wrk;
640
641   if (PREDICT_FALSE (ecm->run_test != EC_STARTING))
642     return -1;
643
644   if (err)
645     {
646       ec_err ("connection %d failed! %U", api_context, format_session_error,
647               err);
648       ecm->run_test = EC_EXITING;
649       signal_evt_to_cli (EC_CLI_CONNECTS_FAILED);
650       return 0;
651     }
652
653   thread_index = s->thread_index;
654   ASSERT (thread_index == vlib_get_thread_index ()
655           || session_transport_service_type (s) == TRANSPORT_SERVICE_CL);
656
657   if (PREDICT_FALSE (api_context == HS_CTRL_HANDLE))
658     return ec_ctrl_session_connected_callback (s);
659
660   wrk = ec_worker_get (thread_index);
661
662   /*
663    * Setup session
664    */
665   es = ec_session_alloc (wrk);
666
667   es->bytes_to_send = ecm->bytes_to_send;
668   es->bytes_to_receive = ecm->echo_bytes ? ecm->bytes_to_send : 0ULL;
669   es->data.rx_fifo = s->rx_fifo;
670   es->data.rx_fifo->shr->client_session_index = es->data.session_index;
671   es->data.tx_fifo = s->tx_fifo;
672   es->data.tx_fifo->shr->client_session_index = es->data.session_index;
673   es->data.vpp_evt_q = wrk->vpp_event_queue;
674   es->vpp_session_handle = session_handle (s);
675   es->vpp_session_index = s->session_index;
676   s->opaque = es->data.session_index;
677
678   if (ecm->is_dgram)
679     {
680       transport_connection_t *tc;
681       tc = session_get_transport (s);
682       clib_memcpy_fast (&es->data.transport, tc, sizeof (es->data.transport));
683       es->data.is_dgram = 1;
684     }
685
686   vec_add1 (wrk->conn_indices, es->data.session_index);
687   clib_atomic_fetch_add (&ecm->ready_connections, 1);
688   if (ecm->ready_connections == ecm->expected_connections)
689     {
690       ecm->run_test = EC_RUNNING;
691       /* Signal the CLI process that the action is starting... */
692       signal_evt_to_cli (EC_CLI_CONNECTS_DONE);
693     }
694
695   return 0;
696 }
697
698 static void
699 ec_session_reset_callback (session_t *s)
700 {
701   ec_main_t *ecm = &ec_main;
702   vnet_disconnect_args_t _a = { 0 }, *a = &_a;
703
704   if (s->session_state == SESSION_STATE_READY)
705     ec_err ("Reset active connection %U", format_session, s, 2);
706
707   a->handle = session_handle (s);
708   a->app_index = ecm->app_index;
709   vnet_disconnect_session (a);
710   return;
711 }
712
713 static int
714 ec_session_accept_callback (session_t *s)
715 {
716   return 0;
717 }
718
719 static void
720 ec_session_disconnect_callback (session_t *s)
721 {
722   ec_main_t *ecm = &ec_main;
723   vnet_disconnect_args_t _a = { 0 }, *a = &_a;
724
725   if (session_handle (s) == ecm->ctrl_session_handle)
726     {
727       ec_dbg ("ctrl session disconnect");
728       ecm->ctrl_session_handle = SESSION_INVALID_HANDLE;
729     }
730
731   a->handle = session_handle (s);
732   a->app_index = ecm->app_index;
733   vnet_disconnect_session (a);
734   return;
735 }
736
737 void
738 ec_session_disconnect (session_t *s)
739 {
740   ec_main_t *ecm = &ec_main;
741   vnet_disconnect_args_t _a = { 0 }, *a = &_a;
742   a->handle = session_handle (s);
743   a->app_index = ecm->app_index;
744   vnet_disconnect_session (a);
745 }
746
747 static int
748 ec_ctrl_session_rx_callback (session_t *s)
749 {
750   ec_main_t *ecm = &ec_main;
751   int rx_bytes;
752   hs_test_cfg_t cfg = { 0 };
753
754   rx_bytes = svm_fifo_dequeue (s->rx_fifo, sizeof (cfg), (u8 *) &cfg);
755   if (rx_bytes != sizeof (cfg))
756     {
757       ec_err ("invalid cfg length %d (expected %d)", rx_bytes, sizeof (cfg));
758       signal_evt_to_cli (EC_CLI_CONNECTS_FAILED);
759       return -1;
760     }
761
762   ec_dbg ("control message received:");
763   if (ecm->cfg.verbose)
764     hs_test_cfg_dump (&cfg, 1);
765
766   switch (cfg.cmd)
767     {
768     case HS_TEST_CMD_SYNC:
769       switch (ecm->run_test)
770         {
771         case EC_STARTING:
772           if (!hs_test_cfg_verify (&cfg, &ecm->cfg))
773             {
774               ec_err ("invalid config received from server!");
775               signal_evt_to_cli (EC_CLI_CONNECTS_FAILED);
776               return -1;
777             }
778           signal_evt_to_cli (EC_CLI_CFG_SYNC);
779           break;
780
781         case EC_RUNNING:
782           ec_dbg ("test running..");
783           break;
784
785         case EC_EXITING:
786           /* post test sync */
787           signal_evt_to_cli (EC_CLI_CFG_SYNC);
788           break;
789
790         default:
791           ec_err ("unexpected test state! %d", ecm->run_test);
792           break;
793         }
794       break;
795     case HS_TEST_CMD_START:
796       signal_evt_to_cli (EC_CLI_START);
797       break;
798     case HS_TEST_CMD_STOP:
799       signal_evt_to_cli (EC_CLI_STOP);
800       break;
801     default:
802       ec_err ("unexpected cmd! %d", cfg.cmd);
803       break;
804     }
805
806   return 0;
807 }
808
809 static int
810 ec_session_rx_callback (session_t *s)
811 {
812   ec_main_t *ecm = &ec_main;
813   ec_worker_t *wrk;
814   ec_session_t *es;
815
816   if (PREDICT_FALSE (s->opaque == HS_CTRL_HANDLE))
817     return ec_ctrl_session_rx_callback (s);
818
819   if (PREDICT_FALSE (ecm->run_test != EC_RUNNING))
820     {
821       ec_session_disconnect (s);
822       return -1;
823     }
824
825   wrk = ec_worker_get (s->thread_index);
826   es = ec_session_get (wrk, s->opaque);
827
828   receive_data_chunk (wrk, es);
829
830   if (svm_fifo_max_dequeue_cons (s->rx_fifo))
831     session_enqueue_notify (s);
832
833   return 0;
834 }
835
836 static int
837 ec_add_segment_callback (u32 app_index, u64 segment_handle)
838 {
839   /* New segments may be added */
840   return 0;
841 }
842
843 static int
844 ec_del_segment_callback (u32 app_index, u64 segment_handle)
845 {
846   return 0;
847 }
848
849 static session_cb_vft_t ec_cb_vft = {
850   .session_reset_callback = ec_session_reset_callback,
851   .session_connected_callback = ec_session_connected_callback,
852   .session_accept_callback = ec_session_accept_callback,
853   .session_disconnect_callback = ec_session_disconnect_callback,
854   .builtin_app_rx_callback = ec_session_rx_callback,
855   .add_segment_callback = ec_add_segment_callback,
856   .del_segment_callback = ec_del_segment_callback,
857 };
858
859 static clib_error_t *
860 ec_attach ()
861 {
862   vnet_app_add_cert_key_pair_args_t _ck_pair, *ck_pair = &_ck_pair;
863   ec_main_t *ecm = &ec_main;
864   vnet_app_attach_args_t _a, *a = &_a;
865   u32 prealloc_fifos;
866   u64 options[18];
867   int rv;
868
869   clib_memset (a, 0, sizeof (*a));
870   clib_memset (options, 0, sizeof (options));
871
872   a->api_client_index = ~0;
873   a->name = format (0, "echo_client");
874   if (ecm->transport_proto == TRANSPORT_PROTO_QUIC)
875     ec_cb_vft.session_connected_callback = quic_ec_session_connected_callback;
876   a->session_cb_vft = &ec_cb_vft;
877
878   prealloc_fifos = ecm->prealloc_fifos ? ecm->expected_connections : 1;
879
880   options[APP_OPTIONS_ACCEPT_COOKIE] = 0x12345678;
881   options[APP_OPTIONS_SEGMENT_SIZE] = ecm->private_segment_size;
882   options[APP_OPTIONS_ADD_SEGMENT_SIZE] = ecm->private_segment_size;
883   options[APP_OPTIONS_RX_FIFO_SIZE] = ecm->fifo_size;
884   options[APP_OPTIONS_TX_FIFO_SIZE] = ecm->fifo_size;
885   options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = ecm->private_segment_count;
886   options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = prealloc_fifos;
887   options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
888   options[APP_OPTIONS_TLS_ENGINE] = ecm->tls_engine;
889   options[APP_OPTIONS_PCT_FIRST_ALLOC] = 100;
890   options[APP_OPTIONS_FLAGS] |= ecm->attach_flags;
891   if (ecm->appns_id)
892     {
893       options[APP_OPTIONS_NAMESPACE_SECRET] = ecm->appns_secret;
894       a->namespace_id = ecm->appns_id;
895     }
896   a->options = options;
897
898   if ((rv = vnet_application_attach (a)))
899     return clib_error_return (0, "attach returned %d", rv);
900
901   ecm->app_index = a->app_index;
902   vec_free (a->name);
903
904   clib_memset (ck_pair, 0, sizeof (*ck_pair));
905   ck_pair->cert = (u8 *) test_srv_crt_rsa;
906   ck_pair->key = (u8 *) test_srv_key_rsa;
907   ck_pair->cert_len = test_srv_crt_rsa_len;
908   ck_pair->key_len = test_srv_key_rsa_len;
909   vnet_app_add_cert_key_pair (ck_pair);
910   ecm->ckpair_index = ck_pair->index;
911
912   ecm->test_client_attached = 1;
913
914   return 0;
915 }
916
917 static int
918 ec_detach ()
919 {
920   ec_main_t *ecm = &ec_main;
921   vnet_app_detach_args_t _da, *da = &_da;
922   int rv;
923
924   if (!ecm->test_client_attached)
925     return 0;
926
927   da->app_index = ecm->app_index;
928   da->api_client_index = ~0;
929   rv = vnet_application_detach (da);
930   ecm->test_client_attached = 0;
931   ecm->app_index = ~0;
932   vnet_app_del_cert_key_pair (ecm->ckpair_index);
933
934   return rv;
935 }
936
937 static int
938 ec_transport_needs_crypto (transport_proto_t proto)
939 {
940   return proto == TRANSPORT_PROTO_TLS || proto == TRANSPORT_PROTO_DTLS ||
941          proto == TRANSPORT_PROTO_QUIC;
942 }
943
944 static int
945 ec_connect_rpc (void *args)
946 {
947   ec_main_t *ecm = &ec_main;
948   vnet_connect_args_t _a = {}, *a = &_a;
949   int rv, needs_crypto;
950   u32 n_clients, ci;
951
952   n_clients = ecm->n_clients;
953   needs_crypto = ec_transport_needs_crypto (ecm->transport_proto);
954   clib_memcpy (&a->sep_ext, &ecm->connect_sep, sizeof (ecm->connect_sep));
955   a->sep_ext.transport_flags |= TRANSPORT_CFG_F_CONNECTED;
956   a->app_index = ecm->app_index;
957
958   ci = ecm->connect_conn_index;
959
960   while (ci < n_clients)
961     {
962       /* Crude pacing for call setups  */
963       if (ci - ecm->ready_connections > 128)
964         {
965           ecm->connect_conn_index = ci;
966           break;
967         }
968
969       a->api_context = ci;
970       if (needs_crypto)
971         {
972           session_endpoint_alloc_ext_cfg (&a->sep_ext,
973                                           TRANSPORT_ENDPT_EXT_CFG_CRYPTO);
974           a->sep_ext.ext_cfg->crypto.ckpair_index = ecm->ckpair_index;
975         }
976
977       rv = vnet_connect (a);
978
979       if (needs_crypto)
980         clib_mem_free (a->sep_ext.ext_cfg);
981
982       if (rv)
983         {
984           ec_err ("connect returned: %U", format_session_error, rv);
985           ecm->run_test = EC_EXITING;
986           signal_evt_to_cli (EC_CLI_CONNECTS_FAILED);
987           break;
988         }
989
990       ci += 1;
991     }
992
993   if (ci < ecm->expected_connections && ecm->run_test != EC_EXITING)
994     ec_program_connects ();
995
996   return 0;
997 }
998
999 void
1000 ec_program_connects (void)
1001 {
1002   session_send_rpc_evt_to_thread_force (transport_cl_thread (), ec_connect_rpc,
1003                                         0);
1004 }
1005
1006 static clib_error_t *
1007 ec_ctrl_connect_rpc ()
1008 {
1009   session_error_t rv;
1010   ec_main_t *ecm = &ec_main;
1011   vnet_connect_args_t _a = {}, *a = &_a;
1012
1013   a->api_context = HS_CTRL_HANDLE;
1014   ecm->cfg.cmd = HS_TEST_CMD_SYNC;
1015   clib_memcpy (&a->sep_ext, &ecm->connect_sep, sizeof (ecm->connect_sep));
1016   a->sep_ext.transport_proto = TRANSPORT_PROTO_TCP;
1017   a->app_index = ecm->app_index;
1018
1019   rv = vnet_connect (a);
1020   if (rv)
1021     {
1022       ec_err ("ctrl connect returned: %U", format_session_error, rv);
1023       ecm->run_test = EC_EXITING;
1024       signal_evt_to_cli (EC_CLI_CONNECTS_FAILED);
1025     }
1026   return 0;
1027 }
1028
1029 static void
1030 ec_ctrl_connect (void)
1031 {
1032   session_send_rpc_evt_to_thread_force (transport_cl_thread (),
1033                                         ec_ctrl_connect_rpc, 0);
1034 }
1035
1036 static void
1037 ec_ctrl_session_disconnect ()
1038 {
1039   ec_main_t *ecm = &ec_main;
1040   vnet_disconnect_args_t _a, *a = &_a;
1041   session_error_t err;
1042
1043   a->handle = ecm->ctrl_session_handle;
1044   a->app_index = ecm->app_index;
1045   err = vnet_disconnect_session (a);
1046   if (err)
1047     ec_err ("vnet_disconnect_session: %U", format_session_error, err);
1048 }
1049
1050 static int
1051 ec_ctrl_test_sync ()
1052 {
1053   ec_main_t *ecm = &ec_main;
1054   ecm->cfg.test = HS_TEST_TYPE_ECHO;
1055   return ec_ctrl_send (HS_TEST_CMD_SYNC);
1056 }
1057
1058 static int
1059 ec_ctrl_test_start ()
1060 {
1061   return ec_ctrl_send (HS_TEST_CMD_START);
1062 }
1063
1064 static int
1065 ec_ctrl_test_stop ()
1066 {
1067   return ec_ctrl_send (HS_TEST_CMD_STOP);
1068 }
1069
1070 #define ec_wait_for_signal(_sig)                                              \
1071   vlib_process_wait_for_event_or_clock (vm, ecm->syn_timeout);                \
1072   event_type = vlib_process_get_events (vm, &event_data);                     \
1073   switch (event_type)                                                         \
1074     {                                                                         \
1075     case ~0:                                                                  \
1076       ec_cli ("Timeout while waiting for " #_sig);                            \
1077       error =                                                                 \
1078         clib_error_return (0, "failed: timeout while waiting for " #_sig);    \
1079       goto cleanup;                                                           \
1080     case _sig:                                                                \
1081       break;                                                                  \
1082     default:                                                                  \
1083       ec_cli ("unexpected event while waiting for " #_sig ": %d",             \
1084               event_type);                                                    \
1085       error =                                                                 \
1086         clib_error_return (0, "failed: unexpected event: %d", event_type);    \
1087       goto cleanup;                                                           \
1088     }
1089
1090 static clib_error_t *
1091 ec_command_fn (vlib_main_t *vm, unformat_input_t *input,
1092                vlib_cli_command_t *cmd)
1093 {
1094   unformat_input_t _line_input, *line_input = &_line_input;
1095   char *default_uri = "tcp://6.0.1.1/1234", *transfer_type;
1096   ec_main_t *ecm = &ec_main;
1097   uword *event_data = 0, event_type;
1098   clib_error_t *error = 0;
1099   int rv, had_config = 1;
1100   u64 tmp, total_bytes;
1101   f64 delta;
1102
1103   if (ecm->test_client_attached)
1104     return clib_error_return (0, "failed: already running!");
1105
1106   if (ec_init (vm))
1107     {
1108       error = clib_error_return (0, "failed init");
1109       goto cleanup;
1110     }
1111
1112   if (!unformat_user (input, unformat_line_input, line_input))
1113     {
1114       had_config = 0;
1115       goto parse_config;
1116     }
1117
1118   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1119     {
1120       if (unformat (line_input, "uri %s", &ecm->connect_uri))
1121         ;
1122       else if (unformat (line_input, "nclients %d", &ecm->n_clients))
1123         ;
1124       else if (unformat (line_input, "quic-streams %d", &ecm->quic_streams))
1125         ;
1126       else if (unformat (line_input, "mbytes %lld", &tmp))
1127         ecm->bytes_to_send = tmp << 20;
1128       else if (unformat (line_input, "gbytes %lld", &tmp))
1129         ecm->bytes_to_send = tmp << 30;
1130       else if (unformat (line_input, "bytes %U", unformat_memory_size,
1131                          &ecm->bytes_to_send))
1132         ;
1133       else if (unformat (line_input, "test-timeout %f", &ecm->test_timeout))
1134         ;
1135       else if (unformat (line_input, "syn-timeout %f", &ecm->syn_timeout))
1136         ;
1137       else if (unformat (line_input, "echo-bytes"))
1138         ecm->echo_bytes = 1;
1139       else if (unformat (line_input, "fifo-size %U", unformat_memory_size,
1140                          &ecm->fifo_size))
1141         ;
1142       else if (unformat (line_input, "private-segment-count %d",
1143                          &ecm->private_segment_count))
1144         ;
1145       else if (unformat (line_input, "private-segment-size %U",
1146                          unformat_memory_size, &ecm->private_segment_size))
1147         ;
1148       else if (unformat (line_input, "preallocate-fifos"))
1149         ecm->prealloc_fifos = 1;
1150       else if (unformat (line_input, "preallocate-sessions"))
1151         ecm->prealloc_sessions = 1;
1152       else if (unformat (line_input, "client-batch %d",
1153                          &ecm->connections_per_batch))
1154         ;
1155       else if (unformat (line_input, "appns %_%v%_", &ecm->appns_id))
1156         ;
1157       else if (unformat (line_input, "all-scope"))
1158         ecm->attach_flags |= (APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE |
1159                               APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE);
1160       else if (unformat (line_input, "local-scope"))
1161         ecm->attach_flags = APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
1162       else if (unformat (line_input, "global-scope"))
1163         ecm->attach_flags = APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
1164       else if (unformat (line_input, "secret %lu", &ecm->appns_secret))
1165         ;
1166       else if (unformat (line_input, "verbose"))
1167         ecm->cfg.verbose = 1;
1168       else if (unformat (line_input, "test-bytes"))
1169         ecm->cfg.test_bytes = 1;
1170       else if (unformat (line_input, "tls-engine %d", &ecm->tls_engine))
1171         ;
1172       else
1173         {
1174           error = clib_error_return (0, "failed: unknown input `%U'",
1175                                      format_unformat_error, line_input);
1176           goto cleanup;
1177         }
1178     }
1179
1180 parse_config:
1181
1182   ecm->cfg.num_test_sessions = ecm->expected_connections =
1183     ecm->n_clients * ecm->quic_streams;
1184
1185   if (!ecm->connect_uri)
1186     {
1187       ec_cli ("No uri provided. Using default: %s", default_uri);
1188       ecm->connect_uri = format (0, "%s%c", default_uri, 0);
1189     }
1190
1191   if ((rv = parse_uri ((char *) ecm->connect_uri, &ecm->connect_sep)))
1192     {
1193       error = clib_error_return (0, "Uri parse error: %d", rv);
1194       goto cleanup;
1195     }
1196   ecm->transport_proto = ecm->connect_sep.transport_proto;
1197   ecm->is_dgram = (ecm->transport_proto == TRANSPORT_PROTO_UDP);
1198
1199   if (ecm->prealloc_sessions)
1200     ec_prealloc_sessions (ecm);
1201
1202   if ((error = ec_attach ()))
1203     {
1204       clib_error_report (error);
1205       goto cleanup;
1206     }
1207
1208   if (ecm->echo_bytes)
1209     ecm->cfg.test = HS_TEST_TYPE_BI;
1210   else
1211     ecm->cfg.test = HS_TEST_TYPE_UNI;
1212
1213   ec_ctrl_connect ();
1214   ec_wait_for_signal (EC_CLI_CFG_SYNC);
1215
1216   if (ec_ctrl_test_start () < 0)
1217     {
1218       ec_cli ("failed to send start command");
1219       goto cleanup;
1220     }
1221   ec_wait_for_signal (EC_CLI_START);
1222
1223   /*
1224    * Start. Fire off connect requests
1225    */
1226
1227   /* update data port */
1228   ecm->connect_sep.port = hs_make_data_port (ecm->connect_sep.port);
1229
1230   ecm->syn_start_time = vlib_time_now (vm);
1231   ec_program_connects ();
1232
1233   /*
1234    * Park until the sessions come up, or syn_timeout seconds pass
1235    */
1236
1237   vlib_process_wait_for_event_or_clock (vm, ecm->syn_timeout);
1238   event_type = vlib_process_get_events (vm, &event_data);
1239   switch (event_type)
1240     {
1241     case ~0:
1242       ec_cli ("Timeout with only %d sessions active...",
1243               ecm->ready_connections);
1244       error = clib_error_return (0, "failed: syn timeout with %d sessions",
1245                                  ecm->ready_connections);
1246       goto stop_test;
1247
1248     case EC_CLI_CONNECTS_DONE:
1249       delta = vlib_time_now (vm) - ecm->syn_start_time;
1250       if (delta != 0.0)
1251         ec_cli ("%d three-way handshakes in %.2f seconds %.2f/s",
1252                 ecm->n_clients, delta, ((f64) ecm->n_clients) / delta);
1253       break;
1254
1255     case EC_CLI_CONNECTS_FAILED:
1256       error = clib_error_return (0, "failed: connect returned");
1257       goto stop_test;
1258
1259     default:
1260       ec_cli ("unexpected event(2): %d", event_type);
1261       error =
1262         clib_error_return (0, "failed: unexpected event(2): %d", event_type);
1263       goto stop_test;
1264     }
1265
1266   /*
1267    * Wait for the sessions to finish or test_timeout seconds pass
1268    */
1269   ecm->test_start_time = vlib_time_now (ecm->vlib_main);
1270   ec_cli ("Test started at %.6f", ecm->test_start_time);
1271   vlib_process_wait_for_event_or_clock (vm, ecm->test_timeout);
1272   event_type = vlib_process_get_events (vm, &event_data);
1273   switch (event_type)
1274     {
1275     case ~0:
1276       ec_cli ("Timeout at %.6f with %d sessions still active...",
1277               vlib_time_now (ecm->vlib_main), ecm->ready_connections);
1278       error = clib_error_return (0, "failed: timeout with %d sessions",
1279                                  ecm->ready_connections);
1280       goto stop_test;
1281
1282     case EC_CLI_TEST_DONE:
1283       ecm->test_end_time = vlib_time_now (vm);
1284       ec_cli ("Test finished at %.6f", ecm->test_end_time);
1285       break;
1286
1287     default:
1288       ec_cli ("unexpected event(3): %d", event_type);
1289       error =
1290         clib_error_return (0, "failed: unexpected event(3): %d", event_type);
1291       goto stop_test;
1292     }
1293
1294   /*
1295    * Done. Compute stats
1296    */
1297   delta = ecm->test_end_time - ecm->test_start_time;
1298   if (delta == 0.0)
1299     {
1300       ec_cli ("zero delta-t?");
1301       error = clib_error_return (0, "failed: zero delta-t");
1302       goto stop_test;
1303     }
1304
1305   total_bytes = (ecm->echo_bytes ? ecm->rx_total : ecm->tx_total);
1306   transfer_type = ecm->echo_bytes ? "full-duplex" : "half-duplex";
1307   ec_cli ("%lld bytes (%lld mbytes, %lld gbytes) in %.2f seconds", total_bytes,
1308           total_bytes / (1ULL << 20), total_bytes / (1ULL << 30), delta);
1309   ec_cli ("%.2f bytes/second %s", ((f64) total_bytes) / (delta),
1310           transfer_type);
1311   ec_cli ("%.4f gbit/second %s", (((f64) total_bytes * 8.0) / delta / 1e9),
1312           transfer_type);
1313
1314   if (ecm->cfg.test_bytes && ecm->test_failed)
1315     error = clib_error_return (0, "failed: test bytes");
1316
1317 stop_test:
1318   ecm->run_test = EC_EXITING;
1319
1320   /* send stop test command to the server */
1321   if (ec_ctrl_test_stop () < 0)
1322     {
1323       ec_cli ("failed to send stop command");
1324       goto cleanup;
1325     }
1326   ec_wait_for_signal (EC_CLI_STOP);
1327
1328   /* post test sync */
1329   if (ec_ctrl_test_sync () < 0)
1330     {
1331       ec_cli ("failed to send post sync command");
1332       goto cleanup;
1333     }
1334   ec_wait_for_signal (EC_CLI_CFG_SYNC);
1335
1336   /* disconnect control session */
1337   ec_ctrl_session_disconnect ();
1338
1339 cleanup:
1340
1341   ecm->run_test = EC_EXITING;
1342   vlib_process_wait_for_event_or_clock (vm, 10e-3);
1343
1344   /* Detach the application, so we can use different fifo sizes next time */
1345   if (ec_detach ())
1346     {
1347       error = clib_error_return (0, "failed: app detach");
1348       ec_cli ("WARNING: app detach failed...");
1349     }
1350
1351   ec_cleanup (ecm);
1352   if (had_config)
1353     unformat_free (line_input);
1354
1355   if (error)
1356     ec_cli ("test failed");
1357
1358   return error;
1359 }
1360
1361 VLIB_CLI_COMMAND (ec_command, static) = {
1362   .path = "test echo clients",
1363   .short_help =
1364     "test echo clients [nclients %d][[m|g]bytes <bytes>]"
1365     "[test-timeout <time>][syn-timeout <time>][echo-bytes][fifo-size <size>]"
1366     "[private-segment-count <count>][private-segment-size <bytes>[m|g]]"
1367     "[preallocate-fifos][preallocate-sessions][client-batch <batch-size>]"
1368     "[uri <tcp://ip/port>][test-bytes][verbose]",
1369   .function = ec_command_fn,
1370   .is_mp_safe = 1,
1371 };
1372
1373 clib_error_t *
1374 ec_main_init (vlib_main_t *vm)
1375 {
1376   ec_main_t *ecm = &ec_main;
1377   ecm->app_is_init = 0;
1378   return 0;
1379 }
1380
1381 VLIB_INIT_FUNCTION (ec_main_init);
1382
1383 /*
1384  * fd.io coding-style-patch-verification: ON
1385  *
1386  * Local Variables:
1387  * eval: (c-set-style "gnu")
1388  * End:
1389  */