344f4af81c648f0a6b5f1151a51f67a490b04b16
[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
534   ec_dbg ("sending test paramters to the server..");
535   if (ecm->cfg.verbose)
536     hs_test_cfg_dump (&ecm->cfg, 1);
537
538   rv = svm_fifo_enqueue (s->tx_fifo, sizeof (ecm->cfg), (u8 *) &ecm->cfg);
539   ASSERT (rv == sizeof (ecm->cfg));
540   session_send_io_evt_to_thread (s->tx_fifo, SESSION_IO_EVT_TX);
541   return 0;
542 }
543
544 static int
545 ec_ctrl_session_connected_callback (session_t *s)
546 {
547   ec_main_t *ecm = &ec_main;
548
549   s->opaque = HS_CTRL_HANDLE;
550   ecm->ctrl_session_handle = session_handle (s);
551
552   /* send test parameters to the server */
553   ec_ctrl_send (HS_TEST_CMD_SYNC);
554   return 0;
555 }
556
557 static int
558 quic_ec_session_connected_callback (u32 app_index, u32 api_context,
559                                     session_t *s, session_error_t err)
560 {
561   ec_main_t *ecm = &ec_main;
562   ec_session_t *es;
563   ec_worker_t *wrk;
564   u32 thread_index;
565
566   if (PREDICT_FALSE (api_context == HS_CTRL_HANDLE))
567     return ec_ctrl_session_connected_callback (s);
568
569   if (PREDICT_FALSE (ecm->run_test != EC_STARTING))
570     return -1;
571
572   if (err)
573     {
574       ec_err ("connection %d failed!", api_context);
575       ecm->run_test = EC_EXITING;
576       signal_evt_to_cli (EC_CLI_CONNECTS_FAILED);
577       return 0;
578     }
579
580   if (s->listener_handle == SESSION_INVALID_HANDLE)
581     return quic_ec_qsession_connected_callback (app_index, api_context, s,
582                                                 err);
583   ec_dbg ("STREAM Connection callback %d", api_context);
584
585   thread_index = s->thread_index;
586   ASSERT (thread_index == vlib_get_thread_index ()
587           || session_transport_service_type (s) == TRANSPORT_SERVICE_CL);
588
589   wrk = ec_worker_get (thread_index);
590
591   /*
592    * Setup session
593    */
594   es = ec_session_alloc (wrk);
595
596   es->bytes_to_send = ecm->bytes_to_send;
597   es->bytes_to_receive = ecm->echo_bytes ? ecm->bytes_to_send : 0ULL;
598   es->data.rx_fifo = s->rx_fifo;
599   es->data.rx_fifo->shr->client_session_index = es->data.session_index;
600   es->data.tx_fifo = s->tx_fifo;
601   es->data.tx_fifo->shr->client_session_index = es->data.session_index;
602   es->data.vpp_evt_q = wrk->vpp_event_queue;
603   es->vpp_session_handle = session_handle (s);
604   es->vpp_session_index = s->session_index;
605   s->opaque = es->data.session_index;
606
607   if (ecm->is_dgram)
608     {
609       transport_connection_t *tc;
610       tc = session_get_transport (s);
611       clib_memcpy_fast (&es->data.transport, tc, sizeof (es->data.transport));
612       es->data.is_dgram = 1;
613     }
614
615   vec_add1 (wrk->conn_indices, es->data.session_index);
616   clib_atomic_fetch_add (&ecm->ready_connections, 1);
617   if (ecm->ready_connections == ecm->expected_connections)
618     {
619       ecm->run_test = EC_RUNNING;
620       /* Signal the CLI process that the action is starting... */
621       signal_evt_to_cli (EC_CLI_CONNECTS_DONE);
622     }
623
624   return 0;
625 }
626
627 static int
628 ec_session_connected_callback (u32 app_index, u32 api_context, session_t *s,
629                                session_error_t err)
630 {
631   ec_main_t *ecm = &ec_main;
632   ec_session_t *es;
633   u32 thread_index;
634   ec_worker_t *wrk;
635
636   if (PREDICT_FALSE (ecm->run_test != EC_STARTING))
637     return -1;
638
639   if (err)
640     {
641       ec_err ("connection %d failed! %U", api_context, format_session_error,
642               err);
643       ecm->run_test = EC_EXITING;
644       signal_evt_to_cli (EC_CLI_CONNECTS_FAILED);
645       return 0;
646     }
647
648   thread_index = s->thread_index;
649   ASSERT (thread_index == vlib_get_thread_index ()
650           || session_transport_service_type (s) == TRANSPORT_SERVICE_CL);
651
652   if (PREDICT_FALSE (api_context == HS_CTRL_HANDLE))
653     return ec_ctrl_session_connected_callback (s);
654
655   wrk = ec_worker_get (thread_index);
656
657   /*
658    * Setup session
659    */
660   es = ec_session_alloc (wrk);
661
662   es->bytes_to_send = ecm->bytes_to_send;
663   es->bytes_to_receive = ecm->echo_bytes ? ecm->bytes_to_send : 0ULL;
664   es->data.rx_fifo = s->rx_fifo;
665   es->data.rx_fifo->shr->client_session_index = es->data.session_index;
666   es->data.tx_fifo = s->tx_fifo;
667   es->data.tx_fifo->shr->client_session_index = es->data.session_index;
668   es->data.vpp_evt_q = wrk->vpp_event_queue;
669   es->vpp_session_handle = session_handle (s);
670   es->vpp_session_index = s->session_index;
671   s->opaque = es->data.session_index;
672
673   if (ecm->is_dgram)
674     {
675       transport_connection_t *tc;
676       tc = session_get_transport (s);
677       clib_memcpy_fast (&es->data.transport, tc, sizeof (es->data.transport));
678       es->data.is_dgram = 1;
679     }
680
681   vec_add1 (wrk->conn_indices, es->data.session_index);
682   clib_atomic_fetch_add (&ecm->ready_connections, 1);
683   if (ecm->ready_connections == ecm->expected_connections)
684     {
685       ecm->run_test = EC_RUNNING;
686       /* Signal the CLI process that the action is starting... */
687       signal_evt_to_cli (EC_CLI_CONNECTS_DONE);
688     }
689
690   return 0;
691 }
692
693 static void
694 ec_session_reset_callback (session_t *s)
695 {
696   ec_main_t *ecm = &ec_main;
697   vnet_disconnect_args_t _a = { 0 }, *a = &_a;
698
699   if (s->session_state == SESSION_STATE_READY)
700     ec_err ("Reset active connection %U", format_session, s, 2);
701
702   a->handle = session_handle (s);
703   a->app_index = ecm->app_index;
704   vnet_disconnect_session (a);
705   return;
706 }
707
708 static int
709 ec_session_accept_callback (session_t *s)
710 {
711   return 0;
712 }
713
714 static void
715 ec_session_disconnect_callback (session_t *s)
716 {
717   ec_main_t *ecm = &ec_main;
718   vnet_disconnect_args_t _a = { 0 }, *a = &_a;
719
720   if (session_handle (s) == ecm->ctrl_session_handle)
721     {
722       ec_dbg ("ctrl session disconnect");
723       ecm->ctrl_session_handle = SESSION_INVALID_HANDLE;
724     }
725
726   a->handle = session_handle (s);
727   a->app_index = ecm->app_index;
728   vnet_disconnect_session (a);
729   return;
730 }
731
732 void
733 ec_session_disconnect (session_t *s)
734 {
735   ec_main_t *ecm = &ec_main;
736   vnet_disconnect_args_t _a = { 0 }, *a = &_a;
737   a->handle = session_handle (s);
738   a->app_index = ecm->app_index;
739   vnet_disconnect_session (a);
740 }
741
742 static int
743 ec_ctrl_session_rx_callback (session_t *s)
744 {
745   ec_main_t *ecm = &ec_main;
746   int rx_bytes;
747   hs_test_cfg_t cfg = { 0 };
748
749   rx_bytes = svm_fifo_dequeue (s->rx_fifo, sizeof (cfg), (u8 *) &cfg);
750   if (rx_bytes != sizeof (cfg))
751     {
752       ec_err ("invalid cfg length %d (expected %d)", rx_bytes, sizeof (cfg));
753       signal_evt_to_cli (EC_CLI_CONNECTS_FAILED);
754       return -1;
755     }
756
757   ec_dbg ("control message received:");
758   if (ecm->cfg.verbose)
759     hs_test_cfg_dump (&cfg, 1);
760
761   switch (cfg.cmd)
762     {
763     case HS_TEST_CMD_SYNC:
764       switch (ecm->run_test)
765         {
766         case EC_STARTING:
767           if (!hs_test_cfg_verify (&cfg, &ecm->cfg))
768             {
769               ec_err ("invalid config received from server!");
770               signal_evt_to_cli (EC_CLI_CONNECTS_FAILED);
771               return -1;
772             }
773           signal_evt_to_cli (EC_CLI_CFG_SYNC);
774           break;
775
776         case EC_RUNNING:
777           ec_dbg ("test running..");
778           break;
779
780         case EC_EXITING:
781           /* post test sync */
782           signal_evt_to_cli (EC_CLI_CFG_SYNC);
783           break;
784
785         default:
786           ec_err ("unexpected test state! %d", ecm->run_test);
787           break;
788         }
789       break;
790     case HS_TEST_CMD_START:
791       signal_evt_to_cli (EC_CLI_START);
792       break;
793     case HS_TEST_CMD_STOP:
794       signal_evt_to_cli (EC_CLI_STOP);
795       break;
796     default:
797       ec_err ("unexpected cmd! %d", cfg.cmd);
798       break;
799     }
800
801   return 0;
802 }
803
804 static int
805 ec_session_rx_callback (session_t *s)
806 {
807   ec_main_t *ecm = &ec_main;
808   ec_worker_t *wrk;
809   ec_session_t *es;
810
811   if (PREDICT_FALSE (s->opaque == HS_CTRL_HANDLE))
812     return ec_ctrl_session_rx_callback (s);
813
814   if (PREDICT_FALSE (ecm->run_test != EC_RUNNING))
815     {
816       ec_session_disconnect (s);
817       return -1;
818     }
819
820   wrk = ec_worker_get (s->thread_index);
821   es = ec_session_get (wrk, s->opaque);
822
823   receive_data_chunk (wrk, es);
824
825   if (svm_fifo_max_dequeue_cons (s->rx_fifo))
826     session_enqueue_notify (s);
827
828   return 0;
829 }
830
831 static int
832 ec_add_segment_callback (u32 app_index, u64 segment_handle)
833 {
834   /* New segments may be added */
835   return 0;
836 }
837
838 static int
839 ec_del_segment_callback (u32 app_index, u64 segment_handle)
840 {
841   return 0;
842 }
843
844 static session_cb_vft_t ec_cb_vft = {
845   .session_reset_callback = ec_session_reset_callback,
846   .session_connected_callback = ec_session_connected_callback,
847   .session_accept_callback = ec_session_accept_callback,
848   .session_disconnect_callback = ec_session_disconnect_callback,
849   .builtin_app_rx_callback = ec_session_rx_callback,
850   .add_segment_callback = ec_add_segment_callback,
851   .del_segment_callback = ec_del_segment_callback,
852 };
853
854 static clib_error_t *
855 ec_attach ()
856 {
857   vnet_app_add_cert_key_pair_args_t _ck_pair, *ck_pair = &_ck_pair;
858   ec_main_t *ecm = &ec_main;
859   vnet_app_attach_args_t _a, *a = &_a;
860   u32 prealloc_fifos;
861   u64 options[18];
862   int rv;
863
864   clib_memset (a, 0, sizeof (*a));
865   clib_memset (options, 0, sizeof (options));
866
867   a->api_client_index = ~0;
868   a->name = format (0, "echo_client");
869   if (ecm->transport_proto == TRANSPORT_PROTO_QUIC)
870     ec_cb_vft.session_connected_callback = quic_ec_session_connected_callback;
871   a->session_cb_vft = &ec_cb_vft;
872
873   prealloc_fifos = ecm->prealloc_fifos ? ecm->expected_connections : 1;
874
875   options[APP_OPTIONS_ACCEPT_COOKIE] = 0x12345678;
876   options[APP_OPTIONS_SEGMENT_SIZE] = ecm->private_segment_size;
877   options[APP_OPTIONS_ADD_SEGMENT_SIZE] = ecm->private_segment_size;
878   options[APP_OPTIONS_RX_FIFO_SIZE] = ecm->fifo_size;
879   options[APP_OPTIONS_TX_FIFO_SIZE] = ecm->fifo_size;
880   options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = ecm->private_segment_count;
881   options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = prealloc_fifos;
882   options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
883   options[APP_OPTIONS_TLS_ENGINE] = ecm->tls_engine;
884   options[APP_OPTIONS_PCT_FIRST_ALLOC] = 100;
885   options[APP_OPTIONS_FLAGS] |= ecm->attach_flags;
886   if (ecm->appns_id)
887     {
888       options[APP_OPTIONS_NAMESPACE_SECRET] = ecm->appns_secret;
889       a->namespace_id = ecm->appns_id;
890     }
891   a->options = options;
892
893   if ((rv = vnet_application_attach (a)))
894     return clib_error_return (0, "attach returned %d", rv);
895
896   ecm->app_index = a->app_index;
897   vec_free (a->name);
898
899   clib_memset (ck_pair, 0, sizeof (*ck_pair));
900   ck_pair->cert = (u8 *) test_srv_crt_rsa;
901   ck_pair->key = (u8 *) test_srv_key_rsa;
902   ck_pair->cert_len = test_srv_crt_rsa_len;
903   ck_pair->key_len = test_srv_key_rsa_len;
904   vnet_app_add_cert_key_pair (ck_pair);
905   ecm->ckpair_index = ck_pair->index;
906
907   ecm->test_client_attached = 1;
908
909   return 0;
910 }
911
912 static int
913 ec_detach ()
914 {
915   ec_main_t *ecm = &ec_main;
916   vnet_app_detach_args_t _da, *da = &_da;
917   int rv;
918
919   if (!ecm->test_client_attached)
920     return 0;
921
922   da->app_index = ecm->app_index;
923   da->api_client_index = ~0;
924   rv = vnet_application_detach (da);
925   ecm->test_client_attached = 0;
926   ecm->app_index = ~0;
927   vnet_app_del_cert_key_pair (ecm->ckpair_index);
928
929   return rv;
930 }
931
932 static int
933 ec_transport_needs_crypto (transport_proto_t proto)
934 {
935   return proto == TRANSPORT_PROTO_TLS || proto == TRANSPORT_PROTO_DTLS ||
936          proto == TRANSPORT_PROTO_QUIC;
937 }
938
939 static int
940 ec_connect_rpc (void *args)
941 {
942   ec_main_t *ecm = &ec_main;
943   vnet_connect_args_t _a = {}, *a = &_a;
944   int rv, needs_crypto;
945   u32 n_clients, ci;
946
947   n_clients = ecm->n_clients;
948   needs_crypto = ec_transport_needs_crypto (ecm->transport_proto);
949   clib_memcpy (&a->sep_ext, &ecm->connect_sep, sizeof (ecm->connect_sep));
950   a->sep_ext.transport_flags |= TRANSPORT_CFG_F_CONNECTED;
951   a->app_index = ecm->app_index;
952
953   ci = ecm->connect_conn_index;
954
955   while (ci < n_clients)
956     {
957       /* Crude pacing for call setups  */
958       if (ci - ecm->ready_connections > 128)
959         {
960           ecm->connect_conn_index = ci;
961           break;
962         }
963
964       a->api_context = ci;
965       if (needs_crypto)
966         {
967           session_endpoint_alloc_ext_cfg (&a->sep_ext,
968                                           TRANSPORT_ENDPT_EXT_CFG_CRYPTO);
969           a->sep_ext.ext_cfg->crypto.ckpair_index = ecm->ckpair_index;
970         }
971
972       rv = vnet_connect (a);
973
974       if (needs_crypto)
975         clib_mem_free (a->sep_ext.ext_cfg);
976
977       if (rv)
978         {
979           ec_err ("connect returned: %U", format_session_error, rv);
980           ecm->run_test = EC_EXITING;
981           signal_evt_to_cli (EC_CLI_CONNECTS_FAILED);
982           break;
983         }
984
985       ci += 1;
986     }
987
988   if (ci < ecm->expected_connections && ecm->run_test != EC_EXITING)
989     ec_program_connects ();
990
991   return 0;
992 }
993
994 void
995 ec_program_connects (void)
996 {
997   session_send_rpc_evt_to_thread_force (transport_cl_thread (), ec_connect_rpc,
998                                         0);
999 }
1000
1001 static clib_error_t *
1002 ec_ctrl_connect_rpc ()
1003 {
1004   session_error_t rv;
1005   ec_main_t *ecm = &ec_main;
1006   vnet_connect_args_t _a = {}, *a = &_a;
1007
1008   a->api_context = HS_CTRL_HANDLE;
1009   ecm->cfg.cmd = HS_TEST_CMD_SYNC;
1010   clib_memcpy (&a->sep_ext, &ecm->connect_sep, sizeof (ecm->connect_sep));
1011   a->sep_ext.transport_proto = TRANSPORT_PROTO_TCP;
1012   a->app_index = ecm->app_index;
1013
1014   rv = vnet_connect (a);
1015   if (rv)
1016     {
1017       ec_err ("ctrl connect returned: %U", format_session_error, rv);
1018       ecm->run_test = EC_EXITING;
1019       signal_evt_to_cli (EC_CLI_CONNECTS_FAILED);
1020     }
1021   return 0;
1022 }
1023
1024 static void
1025 ec_ctrl_connect (void)
1026 {
1027   session_send_rpc_evt_to_thread_force (transport_cl_thread (),
1028                                         ec_ctrl_connect_rpc, 0);
1029 }
1030
1031 static void
1032 ec_ctrl_session_disconnect ()
1033 {
1034   ec_main_t *ecm = &ec_main;
1035   vnet_disconnect_args_t _a, *a = &_a;
1036   session_error_t err;
1037
1038   a->handle = ecm->ctrl_session_handle;
1039   a->app_index = ecm->app_index;
1040   err = vnet_disconnect_session (a);
1041   if (err)
1042     ec_err ("vnet_disconnect_session: %U", format_session_error, err);
1043 }
1044
1045 static int
1046 ec_ctrl_test_sync ()
1047 {
1048   ec_main_t *ecm = &ec_main;
1049   ecm->cfg.test = HS_TEST_TYPE_ECHO;
1050   return ec_ctrl_send (HS_TEST_CMD_SYNC);
1051 }
1052
1053 static int
1054 ec_ctrl_test_start ()
1055 {
1056   return ec_ctrl_send (HS_TEST_CMD_START);
1057 }
1058
1059 static int
1060 ec_ctrl_test_stop ()
1061 {
1062   return ec_ctrl_send (HS_TEST_CMD_STOP);
1063 }
1064
1065 #define ec_wait_for_signal(_sig)                                              \
1066   vlib_process_wait_for_event_or_clock (vm, ecm->syn_timeout);                \
1067   event_type = vlib_process_get_events (vm, &event_data);                     \
1068   switch (event_type)                                                         \
1069     {                                                                         \
1070     case ~0:                                                                  \
1071       ec_cli ("Timeout while waiting for " #_sig);                            \
1072       error =                                                                 \
1073         clib_error_return (0, "failed: timeout while waiting for " #_sig);    \
1074       goto cleanup;                                                           \
1075     case _sig:                                                                \
1076       break;                                                                  \
1077     default:                                                                  \
1078       ec_cli ("unexpected event while waiting for " #_sig ": %d",             \
1079               event_type);                                                    \
1080       error =                                                                 \
1081         clib_error_return (0, "failed: unexpected event: %d", event_type);    \
1082       goto cleanup;                                                           \
1083     }
1084
1085 static clib_error_t *
1086 ec_command_fn (vlib_main_t *vm, unformat_input_t *input,
1087                vlib_cli_command_t *cmd)
1088 {
1089   unformat_input_t _line_input, *line_input = &_line_input;
1090   char *default_uri = "tcp://6.0.1.1/1234", *transfer_type;
1091   ec_main_t *ecm = &ec_main;
1092   uword *event_data = 0, event_type;
1093   clib_error_t *error = 0;
1094   int rv, had_config = 1;
1095   u64 tmp, total_bytes;
1096   f64 delta;
1097
1098   if (ecm->test_client_attached)
1099     return clib_error_return (0, "failed: already running!");
1100
1101   if (ec_init (vm))
1102     {
1103       error = clib_error_return (0, "failed init");
1104       goto cleanup;
1105     }
1106
1107   if (!unformat_user (input, unformat_line_input, line_input))
1108     {
1109       had_config = 0;
1110       goto parse_config;
1111     }
1112
1113   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1114     {
1115       if (unformat (line_input, "uri %s", &ecm->connect_uri))
1116         ;
1117       else if (unformat (line_input, "nclients %d", &ecm->n_clients))
1118         ;
1119       else if (unformat (line_input, "quic-streams %d", &ecm->quic_streams))
1120         ;
1121       else if (unformat (line_input, "mbytes %lld", &tmp))
1122         ecm->bytes_to_send = tmp << 20;
1123       else if (unformat (line_input, "gbytes %lld", &tmp))
1124         ecm->bytes_to_send = tmp << 30;
1125       else if (unformat (line_input, "bytes %U", unformat_memory_size,
1126                          &ecm->bytes_to_send))
1127         ;
1128       else if (unformat (line_input, "test-timeout %f", &ecm->test_timeout))
1129         ;
1130       else if (unformat (line_input, "syn-timeout %f", &ecm->syn_timeout))
1131         ;
1132       else if (unformat (line_input, "echo-bytes"))
1133         ecm->echo_bytes = 1;
1134       else if (unformat (line_input, "fifo-size %U", unformat_memory_size,
1135                          &ecm->fifo_size))
1136         ;
1137       else if (unformat (line_input, "private-segment-count %d",
1138                          &ecm->private_segment_count))
1139         ;
1140       else if (unformat (line_input, "private-segment-size %U",
1141                          unformat_memory_size, &ecm->private_segment_size))
1142         ;
1143       else if (unformat (line_input, "preallocate-fifos"))
1144         ecm->prealloc_fifos = 1;
1145       else if (unformat (line_input, "preallocate-sessions"))
1146         ecm->prealloc_sessions = 1;
1147       else if (unformat (line_input, "client-batch %d",
1148                          &ecm->connections_per_batch))
1149         ;
1150       else if (unformat (line_input, "appns %_%v%_", &ecm->appns_id))
1151         ;
1152       else if (unformat (line_input, "all-scope"))
1153         ecm->attach_flags |= (APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE |
1154                               APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE);
1155       else if (unformat (line_input, "local-scope"))
1156         ecm->attach_flags = APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
1157       else if (unformat (line_input, "global-scope"))
1158         ecm->attach_flags = APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
1159       else if (unformat (line_input, "secret %lu", &ecm->appns_secret))
1160         ;
1161       else if (unformat (line_input, "verbose"))
1162         ecm->cfg.verbose = 1;
1163       else if (unformat (line_input, "test-bytes"))
1164         ecm->cfg.test_bytes = 1;
1165       else if (unformat (line_input, "tls-engine %d", &ecm->tls_engine))
1166         ;
1167       else
1168         {
1169           error = clib_error_return (0, "failed: unknown input `%U'",
1170                                      format_unformat_error, line_input);
1171           goto cleanup;
1172         }
1173     }
1174
1175 parse_config:
1176
1177   ecm->cfg.num_test_sessions = ecm->expected_connections =
1178     ecm->n_clients * ecm->quic_streams;
1179
1180   if (!ecm->connect_uri)
1181     {
1182       ec_cli ("No uri provided. Using default: %s", default_uri);
1183       ecm->connect_uri = format (0, "%s%c", default_uri, 0);
1184     }
1185
1186   if ((rv = parse_uri ((char *) ecm->connect_uri, &ecm->connect_sep)))
1187     {
1188       error = clib_error_return (0, "Uri parse error: %d", rv);
1189       goto cleanup;
1190     }
1191   ecm->transport_proto = ecm->connect_sep.transport_proto;
1192   ecm->is_dgram = (ecm->transport_proto == TRANSPORT_PROTO_UDP);
1193
1194   if (ecm->prealloc_sessions)
1195     ec_prealloc_sessions (ecm);
1196
1197   if ((error = ec_attach ()))
1198     {
1199       clib_error_report (error);
1200       goto cleanup;
1201     }
1202
1203   if (ecm->echo_bytes)
1204     ecm->cfg.test = HS_TEST_TYPE_BI;
1205   else
1206     ecm->cfg.test = HS_TEST_TYPE_UNI;
1207
1208   ec_ctrl_connect ();
1209   ec_wait_for_signal (EC_CLI_CFG_SYNC);
1210
1211   if (ec_ctrl_test_start () < 0)
1212     {
1213       ec_cli ("failed to send start command");
1214       goto cleanup;
1215     }
1216   ec_wait_for_signal (EC_CLI_START);
1217
1218   /*
1219    * Start. Fire off connect requests
1220    */
1221
1222   /* update data port */
1223   ecm->connect_sep.port = hs_make_data_port (ecm->connect_sep.port);
1224
1225   ecm->syn_start_time = vlib_time_now (vm);
1226   ec_program_connects ();
1227
1228   /*
1229    * Park until the sessions come up, or syn_timeout seconds pass
1230    */
1231
1232   vlib_process_wait_for_event_or_clock (vm, ecm->syn_timeout);
1233   event_type = vlib_process_get_events (vm, &event_data);
1234   switch (event_type)
1235     {
1236     case ~0:
1237       ec_cli ("Timeout with only %d sessions active...",
1238               ecm->ready_connections);
1239       error = clib_error_return (0, "failed: syn timeout with %d sessions",
1240                                  ecm->ready_connections);
1241       goto stop_test;
1242
1243     case EC_CLI_CONNECTS_DONE:
1244       delta = vlib_time_now (vm) - ecm->syn_start_time;
1245       if (delta != 0.0)
1246         ec_cli ("%d three-way handshakes in %.2f seconds %.2f/s",
1247                 ecm->n_clients, delta, ((f64) ecm->n_clients) / delta);
1248       break;
1249
1250     case EC_CLI_CONNECTS_FAILED:
1251       error = clib_error_return (0, "failed: connect returned");
1252       goto stop_test;
1253
1254     default:
1255       ec_cli ("unexpected event(2): %d", event_type);
1256       error =
1257         clib_error_return (0, "failed: unexpected event(2): %d", event_type);
1258       goto stop_test;
1259     }
1260
1261   /*
1262    * Wait for the sessions to finish or test_timeout seconds pass
1263    */
1264   ecm->test_start_time = vlib_time_now (ecm->vlib_main);
1265   ec_cli ("Test started at %.6f", ecm->test_start_time);
1266   vlib_process_wait_for_event_or_clock (vm, ecm->test_timeout);
1267   event_type = vlib_process_get_events (vm, &event_data);
1268   switch (event_type)
1269     {
1270     case ~0:
1271       ec_cli ("Timeout at %.6f with %d sessions still active...",
1272               vlib_time_now (ecm->vlib_main), ecm->ready_connections);
1273       error = clib_error_return (0, "failed: timeout with %d sessions",
1274                                  ecm->ready_connections);
1275       goto stop_test;
1276
1277     case EC_CLI_TEST_DONE:
1278       ecm->test_end_time = vlib_time_now (vm);
1279       ec_cli ("Test finished at %.6f", ecm->test_end_time);
1280       break;
1281
1282     default:
1283       ec_cli ("unexpected event(3): %d", event_type);
1284       error =
1285         clib_error_return (0, "failed: unexpected event(3): %d", event_type);
1286       goto stop_test;
1287     }
1288
1289   /*
1290    * Done. Compute stats
1291    */
1292   delta = ecm->test_end_time - ecm->test_start_time;
1293   if (delta == 0.0)
1294     {
1295       ec_cli ("zero delta-t?");
1296       error = clib_error_return (0, "failed: zero delta-t");
1297       goto stop_test;
1298     }
1299
1300   total_bytes = (ecm->echo_bytes ? ecm->rx_total : ecm->tx_total);
1301   transfer_type = ecm->echo_bytes ? "full-duplex" : "half-duplex";
1302   ec_cli ("%lld bytes (%lld mbytes, %lld gbytes) in %.2f seconds", total_bytes,
1303           total_bytes / (1ULL << 20), total_bytes / (1ULL << 30), delta);
1304   ec_cli ("%.2f bytes/second %s", ((f64) total_bytes) / (delta),
1305           transfer_type);
1306   ec_cli ("%.4f gbit/second %s", (((f64) total_bytes * 8.0) / delta / 1e9),
1307           transfer_type);
1308
1309   if (ecm->cfg.test_bytes && ecm->test_failed)
1310     error = clib_error_return (0, "failed: test bytes");
1311
1312 stop_test:
1313   ecm->run_test = EC_EXITING;
1314
1315   /* send stop test command to the server */
1316   if (ec_ctrl_test_stop () < 0)
1317     {
1318       ec_cli ("failed to send stop command");
1319       goto cleanup;
1320     }
1321   ec_wait_for_signal (EC_CLI_STOP);
1322
1323   /* post test sync */
1324   if (ec_ctrl_test_sync () < 0)
1325     {
1326       ec_cli ("failed to send post sync command");
1327       goto cleanup;
1328     }
1329   ec_wait_for_signal (EC_CLI_CFG_SYNC);
1330
1331   /* disconnect control session */
1332   ec_ctrl_session_disconnect ();
1333
1334 cleanup:
1335
1336   ecm->run_test = EC_EXITING;
1337   vlib_process_wait_for_event_or_clock (vm, 10e-3);
1338
1339   /* Detach the application, so we can use different fifo sizes next time */
1340   if (ec_detach ())
1341     {
1342       error = clib_error_return (0, "failed: app detach");
1343       ec_cli ("WARNING: app detach failed...");
1344     }
1345
1346   ec_cleanup (ecm);
1347   if (had_config)
1348     unformat_free (line_input);
1349
1350   if (error)
1351     ec_cli ("test failed");
1352
1353   return error;
1354 }
1355
1356 VLIB_CLI_COMMAND (ec_command, static) = {
1357   .path = "test echo clients",
1358   .short_help =
1359     "test echo clients [nclients %d][[m|g]bytes <bytes>]"
1360     "[test-timeout <time>][syn-timeout <time>][echo-bytes][fifo-size <size>]"
1361     "[private-segment-count <count>][private-segment-size <bytes>[m|g]]"
1362     "[preallocate-fifos][preallocate-sessions][client-batch <batch-size>]"
1363     "[uri <tcp://ip/port>][test-bytes][verbose]",
1364   .function = ec_command_fn,
1365   .is_mp_safe = 1,
1366 };
1367
1368 clib_error_t *
1369 ec_main_init (vlib_main_t *vm)
1370 {
1371   ec_main_t *ecm = &ec_main;
1372   ecm->app_is_init = 0;
1373   return 0;
1374 }
1375
1376 VLIB_INIT_FUNCTION (ec_main_init);
1377
1378 /*
1379  * fd.io coding-style-patch-verification: ON
1380  *
1381  * Local Variables:
1382  * eval: (c-set-style "gnu")
1383  * End:
1384  */