FD.io VPP  v19.08-27-gf4dcae4
Vector Packet Processing
quic_echo.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 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 <stdio.h>
17 #include <signal.h>
18 
19 #include <vlibmemory/api.h>
20 
21 #include <vpp/api/vpe_msg_enum.h>
22 #include <svm/fifo_segment.h>
23 #include <hs_apps/sapi/quic_echo.h>
25 
27 
28 /*
29  *
30  * Format functions
31  *
32  */
33 
34 u8 *
35 format_quic_echo_state (u8 * s, va_list * args)
36 {
37  u32 state = va_arg (*args, u32);
38  if (state == STATE_START)
39  return format (s, "STATE_START");
40  if (state == STATE_ATTACHED)
41  return format (s, "STATE_ATTACHED");
42  if (state == STATE_LISTEN)
43  return format (s, "STATE_LISTEN");
44  if (state == STATE_READY)
45  return format (s, "STATE_READY");
46  if (state == STATE_DATA_DONE)
47  return format (s, "STATE_DATA_DONE");
48  if (state == STATE_DISCONNECTED)
49  return format (s, "STATE_DISCONNECTED");
50  if (state == STATE_DETACHED)
51  return format (s, "STATE_DETACHED");
52  else
53  return format (s, "unknown state");
54 }
55 
56 static uword
57 unformat_close (unformat_input_t * input, va_list * args)
58 {
59  u8 *a = va_arg (*args, u8 *);
60  if (unformat (input, "Y"))
62  else if (unformat (input, "N"))
63  *a = ECHO_CLOSE_F_NONE;
64  else if (unformat (input, "W"))
66  else
67  return 0;
68  return 1;
69 }
70 
71 static uword
73 {
74  u8 *a = va_arg (*args, u8 *);
75  if (unformat (input, "start"))
76  *a = ECHO_EVT_START;
77  else if (unformat (input, "qconnected"))
79  else if (unformat (input, "qconnect"))
81  else if (unformat (input, "sconnected"))
83  else if (unformat (input, "sconnect"))
85  else if (unformat (input, "lastbyte"))
86  *a = ECHO_EVT_LAST_BYTE;
87  else if (unformat (input, "exit"))
88  *a = ECHO_EVT_EXIT;
89  else
90  return 0;
91  return 1;
92 }
93 
94 u8 *
95 echo_format_timing_event (u8 * s, va_list * args)
96 {
97  u32 timing_event = va_arg (*args, u32);
98  if (timing_event == ECHO_EVT_START)
99  return format (s, "start");
100  if (timing_event == ECHO_EVT_FIRST_QCONNECT)
101  return format (s, "qconnect");
102  if (timing_event == ECHO_EVT_LAST_QCONNECTED)
103  return format (s, "qconnected");
104  if (timing_event == ECHO_EVT_FIRST_SCONNECT)
105  return format (s, "sconnect");
106  if (timing_event == ECHO_EVT_LAST_SCONNECTED)
107  return format (s, "sconnected");
108  if (timing_event == ECHO_EVT_LAST_BYTE)
109  return format (s, "lastbyte");
110  if (timing_event == ECHO_EVT_EXIT)
111  return format (s, "exit");
112  else
113  return format (s, "unknown timing event");
114 }
115 
116 /*
117  *
118  * End of format functions
119  *
120  */
121 
122 static void
124 {
125  /* We need to prealloc to avoid vec resize in threads */
126  echo_session_t *session;
127  int n_sessions = em->n_clients * (em->n_stream_clients + 1)
128  + em->i_am_master;
129  int i;
130  for (i = 0; i < n_sessions; i++)
131  {
132  pool_get (em->sessions, session);
133  clib_memset (session, 0, sizeof (*session));
134  session->session_index = session - em->sessions;
136  session->session_state = QUIC_SESSION_STATE_INITIAL;
137  }
138 }
139 
140 static echo_session_t *
142 {
143  /* thread safe new prealloced session */
144  return pool_elt_at_index (em->sessions,
146  1));
147 }
148 
149 
150 static int
151 echo_send_rpc (echo_main_t * em, void *fp, void *arg, u32 opaque)
152 {
153  svm_msg_q_msg_t msg;
154  echo_rpc_msg_t *evt;
156  {
157  ECHO_LOG (1, "RPC lock failed");
158  return -1;
159  }
161  {
163  ECHO_LOG (1, "RPC ring is full");
164  return -2;
165  }
168  {
169  ECHO_LOG (1, "RPC msg is invalid");
171  return -2;
172  }
173  evt = (echo_rpc_msg_t *) svm_msg_q_msg_data (em->rpc_msq_queue, &msg);
174  evt->arg = arg;
175  evt->opaque = opaque;
176  evt->fp = fp;
177 
179  return 0;
180 }
181 
182 static inline void
183 echo_segment_handle_add_del (echo_main_t * em, u64 segment_handle, u8 add)
184 {
186  if (add)
187  hash_set (em->shared_segment_handles, segment_handle, 1);
188  else
189  hash_unset (em->shared_segment_handles, segment_handle);
191 }
192 
193 static inline void
195 {
197  if (sid == SESSION_INVALID_INDEX)
199  else
200  hash_set (em->session_index_by_vpp_handles, handle, sid);
202 }
203 
204 static inline echo_session_t *
206 {
207  uword *p;
209  p = hash_get (em->session_index_by_vpp_handles, handle);
211  if (!p)
212  {
213  ECHO_FAIL ("unknown handle 0x%lx", handle);
214  return 0;
215  }
216  return pool_elt_at_index (em->sessions, p[0]);
217 }
218 
219 /*
220  *
221  * Session API Calls
222  *
223  */
224 
225 void
227 {
231 
232  bmp = vl_msg_api_alloc (sizeof (*bmp));
233  clib_memset (bmp, 0, sizeof (*bmp));
234 
235  bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_ATTACH);
236  bmp->client_index = em->my_client_index;
237  bmp->context = ntohl (0xfeedface);
238  bmp->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_ACCEPT_REDIRECT;
239  bmp->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_ADD_SEGMENT;
243  bmp->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = 128 << 20;
244  bmp->options[APP_OPTIONS_SEGMENT_SIZE] = 256 << 20;
246  if (em->appns_id)
247  {
248  bmp->namespace_id_len = vec_len (em->appns_id);
250  bmp->namespace_id_len);
253  }
254  vl_msg_api_send_shmem (em->vl_input_queue, (u8 *) & bmp);
255 
256  cert_mp = vl_msg_api_alloc (sizeof (*cert_mp) + test_srv_crt_rsa_len);
257  clib_memset (cert_mp, 0, sizeof (*cert_mp));
258  cert_mp->_vl_msg_id = ntohs (VL_API_APPLICATION_TLS_CERT_ADD);
259  cert_mp->client_index = em->my_client_index;
260  cert_mp->context = ntohl (0xfeedface);
261  cert_mp->cert_len = clib_host_to_net_u16 (test_srv_crt_rsa_len);
263  vl_msg_api_send_shmem (em->vl_input_queue, (u8 *) & cert_mp);
264 
265  key_mp = vl_msg_api_alloc (sizeof (*key_mp) + test_srv_key_rsa_len);
266  clib_memset (key_mp, 0, sizeof (*key_mp) + test_srv_key_rsa_len);
267  key_mp->_vl_msg_id = ntohs (VL_API_APPLICATION_TLS_KEY_ADD);
268  key_mp->client_index = em->my_client_index;
269  key_mp->context = ntohl (0xfeedface);
270  key_mp->key_len = clib_host_to_net_u16 (test_srv_key_rsa_len);
272  vl_msg_api_send_shmem (em->vl_input_queue, (u8 *) & key_mp);
273 }
274 
275 void
277 {
279  bmp = vl_msg_api_alloc (sizeof (*bmp));
280  clib_memset (bmp, 0, sizeof (*bmp));
281 
282  bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_DETACH);
283  bmp->client_index = em->my_client_index;
284  bmp->context = ntohl (0xfeedface);
285  vl_msg_api_send_shmem (em->vl_input_queue, (u8 *) & bmp);
286 }
287 
288 static void
290 {
291  vl_api_bind_uri_t *bmp;
292  bmp = vl_msg_api_alloc (sizeof (*bmp));
293  clib_memset (bmp, 0, sizeof (*bmp));
294 
295  bmp->_vl_msg_id = ntohs (VL_API_BIND_URI);
296  bmp->client_index = em->my_client_index;
297  bmp->context = ntohl (0xfeedface);
298  memcpy (bmp->uri, em->uri, vec_len (em->uri));
299  vl_msg_api_send_shmem (em->vl_input_queue, (u8 *) & bmp);
300 }
301 
302 static void
304 {
305  vl_api_unbind_uri_t *ump;
306 
307  ump = vl_msg_api_alloc (sizeof (*ump));
308  clib_memset (ump, 0, sizeof (*ump));
309 
310  ump->_vl_msg_id = ntohs (VL_API_UNBIND_URI);
311  ump->client_index = em->my_client_index;
312  memcpy (ump->uri, em->uri, vec_len (em->uri));
313  vl_msg_api_send_shmem (em->vl_input_queue, (u8 *) & ump);
314 }
315 
316 static void
317 echo_send_connect (u8 * uri, u32 opaque)
318 {
319  echo_main_t *em = &echo_main;
321  cmp = vl_msg_api_alloc (sizeof (*cmp));
322  clib_memset (cmp, 0, sizeof (*cmp));
323  cmp->_vl_msg_id = ntohs (VL_API_CONNECT_URI);
324  cmp->client_index = em->my_client_index;
325  cmp->context = ntohl (opaque);
326  memcpy (cmp->uri, uri, vec_len (uri));
327  vl_msg_api_send_shmem (em->vl_input_queue, (u8 *) & cmp);
328 }
329 
330 static void
332 {
333  echo_main_t *em = &echo_main;
335  dmp = vl_msg_api_alloc (sizeof (*dmp));
336  clib_memset (dmp, 0, sizeof (*dmp));
337  dmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION);
338  dmp->client_index = em->my_client_index;
339  dmp->handle = s->vpp_session_handle;
340  ECHO_LOG (1, "Disconnect session 0x%lx", dmp->handle);
341  vl_msg_api_send_shmem (em->vl_input_queue, (u8 *) & dmp);
342 }
343 
344 /*
345  *
346  * End Session API Calls
347  *
348  */
349 
350 static int
352 {
353  echo_main_t *em = &echo_main;
354  f64 timeout;
355  timeout = clib_time_now (&em->clib_time) + TIMEOUT;
356  uword *segment_present;
357  ECHO_LOG (1, "Waiting for segment 0x%lx...", segment_handle);
358  while (clib_time_now (&em->clib_time) < timeout)
359  {
361  segment_present = hash_get (em->shared_segment_handles, segment_handle);
363  if (segment_present != 0)
364  return 0;
365  if (em->time_to_stop == 1)
366  return 0;
367  }
368  ECHO_LOG (1, "timeout wait_for_segment_allocation (0x%lx)", segment_handle);
369  return -1;
370 }
371 
372 static void
374 {
375  if (em->timing.events_sent & e)
376  return;
377  if (em->timing.start_event == e)
379  else if (em->timing.end_event == e)
380  em->timing.end_time = clib_time_now (&em->clib_time);
381  em->timing.events_sent |= e;
382 }
383 
384 static void
386 {
388  em->stats.rx_total, "Not enough data received");
390  em->stats.tx_total, "Not enough data sent");
393  "Some sessions are still open");
395 }
396 
397 always_inline void
399 {
400  int rv;
401  if (!svm_fifo_set_event (s->rx_fifo))
402  return;
403  if ((rv =
404  app_send_io_evt_to_vpp (s->vpp_evt_q, s->rx_fifo->master_session_index,
406  ECHO_FAIL ("app_send_io_evt_to_vpp errored %d", rv);
407  svm_fifo_clear_deq_ntf (s->rx_fifo);
408 }
409 
410 static int
412 {
413  fifo_segment_create_args_t _a, *a = &_a;
414  fifo_segment_main_t *sm = &echo_main.segment_main;
415  int rv;
416 
417  clib_memset (a, 0, sizeof (*a));
418  a->segment_name = (char *) name;
419  a->segment_type = type;
420 
421  if (type == SSVM_SEGMENT_MEMFD)
422  a->memfd_fd = fd;
423 
424  if ((rv = fifo_segment_attach (sm, a)))
425  return rv;
427  return 0;
428 }
429 
430 static void
431 stop_signal (int signum)
432 {
433  echo_main_t *em = &echo_main;
434  em->time_to_stop = 1;
435 }
436 
437 int
439 {
440  echo_main_t *em = &echo_main;
441  api_main_t *am = &api_main;
442 
443  if (em->use_sock_api)
444  {
445  if (vl_socket_client_connect ((char *) em->socket_name, name,
446  0 /* default rx, tx buffer */ ))
447  {
448  ECHO_FAIL ("socket connect failed");
449  return -1;
450  }
451 
452  if (vl_socket_client_init_shm (0, 1 /* want_pthread */ ))
453  {
454  ECHO_FAIL ("init shm api failed");
455  return -1;
456  }
457  }
458  else
459  {
460  if (vl_client_connect_to_vlib ("/vpe-api", name, 32) < 0)
461  {
462  ECHO_FAIL ("shmem connect failed");
463  return -1;
464  }
465  }
468  return 0;
469 }
470 
471 static void
473 {
474  f64 deltat = clib_time_now (&em->clib_time) - session->start;
475  ECHO_LOG (0, "Session 0x%x done in %.6fs RX[%.4f] TX[%.4f] Gbit/s\n",
476  session->vpp_session_handle, deltat,
477  (session->bytes_received * 8.0) / deltat / 1e9,
478  (session->bytes_sent * 8.0) / deltat / 1e9);
479 }
480 
481 static void
483 {
484  echo_main_t *em = &echo_main;
485  u8 *s = format (0, "%U", echo_format_timing_event, e);
486  ECHO_LOG (0, "Expected event %s to happend, which did not", s);
487  em->has_failed = 1;
488 }
489 
490 static void
492 {
493  if (!(em->timing.events_sent & em->timing.start_event))
495  if (!(em->timing.events_sent & em->timing.end_event))
497  f64 deltat = em->timing.end_time - em->timing.start_time;
498  u8 *start_evt =
500  u8 *end_evt =
502  fformat (stdout, "{\n");
503  fformat (stdout, "\"time\": \"%.9f\",\n", deltat);
504  fformat (stdout, "\"start_evt\": \"%s\",\n", start_evt);
505  fformat (stdout, "\"end_evt\": \"%s\",\n", end_evt);
506  fformat (stdout, "\"rx_data\": %lld,\n", em->stats.rx_total);
507  fformat (stdout, "\"tx_rx\": %lld,\n", em->stats.tx_total);
508  fformat (stdout, "\"closing\": {\n");
509  fformat (stdout, " \"reset\": { \"q\": %d, \"s\": %d },\n",
510  em->stats.reset_count.q, em->stats.reset_count.s);
511  fformat (stdout, " \"close\": { \"q\": %d, \"s\": %d },\n",
512  em->stats.close_count.q, em->stats.close_count.s);
513  fformat (stdout, " \"active\": { \"q\": %d, \"s\": %d },\n",
515  fformat (stdout, " \"clean\": { \"q\": %d, \"s\": %d }\n",
516  em->stats.clean_count.q, em->stats.clean_count.s);
517  fformat (stdout, "}\n");
518  fformat (stdout, "}\n");
519 }
520 
521 static void
523 {
524  u8 *s;
525  if (!(em->timing.events_sent & em->timing.start_event))
527  if (!(em->timing.events_sent & em->timing.end_event))
529  f64 deltat = em->timing.end_time - em->timing.start_time;
530  s = format (0, "%U:%U",
533  fformat (stdout, "Timing %s\n", s);
534  fformat (stdout, "-------- TX --------\n");
535  fformat (stdout, "%lld bytes (%lld mbytes, %lld gbytes) in %.6f seconds\n",
536  em->stats.tx_total, em->stats.tx_total / (1ULL << 20),
537  em->stats.tx_total / (1ULL << 30), deltat);
538  fformat (stdout, "%.4f Gbit/second\n",
539  (em->stats.tx_total * 8.0) / deltat / 1e9);
540  fformat (stdout, "-------- RX --------\n");
541  fformat (stdout, "%lld bytes (%lld mbytes, %lld gbytes) in %.6f seconds\n",
542  em->stats.rx_total, em->stats.rx_total / (1ULL << 20),
543  em->stats.rx_total / (1ULL << 30), deltat);
544  fformat (stdout, "%.4f Gbit/second\n",
545  (em->stats.rx_total * 8.0) / deltat / 1e9);
546  fformat (stdout, "--------------------\n");
547  fformat (stdout, "Received close on %dQ %dS\n", em->stats.close_count.q,
548  em->stats.close_count.s);
549  fformat (stdout, "Received reset on %dQ %dS\n", em->stats.reset_count.q,
550  em->stats.reset_count.s);
551  fformat (stdout, "Sent close on %dQ %dS\n", em->stats.active_count.q,
552  em->stats.active_count.s);
553  fformat (stdout, "Discarded %dQ %dS\n", em->stats.clean_count.q,
554  em->stats.clean_count.s);
555 }
556 
557 static void
559 {
560  /* Free marked sessions */
561  echo_session_t *s;
562  u32 *session_indexes = 0, *session_index;
563 
564  /* *INDENT-OFF* */
565  pool_foreach (s, em->sessions,
566  ({
567  if (s->session_state == QUIC_SESSION_STATE_CLOSED)
568  vec_add1 (session_indexes, s->session_index);}
569  ));
570  /* *INDENT-ON* */
571  vec_foreach (session_index, session_indexes)
572  {
573  /* Free session */
574  s = pool_elt_at_index (em->sessions, *session_index);
577  pool_put (em->sessions, s);
578  clib_memset (s, 0xfe, sizeof (*s));
579  }
580 }
581 
582 static void
584 {
585  echo_session_t *ls;
586  ASSERT (s->session_state < QUIC_SESSION_STATE_CLOSED);
587  if (s->session_type == QUIC_SESSION_TYPE_QUIC)
588  {
590  }
591  else if (s->session_type == QUIC_SESSION_TYPE_STREAM)
592  {
594  ASSERT (ls->session_type == QUIC_SESSION_TYPE_QUIC);
596  {
598  {
599  echo_send_rpc (em, echo_disconnect_session, (void *) ls, 0);
600  em->stats.active_count.q++;
601  }
603  {
604  echo_cleanup_session (em, ls);
605  em->stats.clean_count.q++;
606  }
607  }
609  }
610  ECHO_LOG (1, "Cleanup sessions (still %uQ %uS)",
612  s->session_state = QUIC_SESSION_STATE_CLOSED;
613 }
614 
615 static void
617 {
618  ECHO_LOG (1, "Closing Qsessions");
619  /* Close Quic session without streams */
620  echo_session_t *s;
621 
622  /* *INDENT-OFF* */
623  pool_foreach (s, em->sessions,
624  ({
625  if (s->session_type == QUIC_SESSION_TYPE_QUIC)
626  {
627  ECHO_LOG (1,"ACTIVE close 0x%lx", s->vpp_session_handle);
628  if (em->send_quic_disconnects == ECHO_CLOSE_F_ACTIVE)
629  {
630  echo_send_rpc (em, echo_disconnect_session, (void *) s, 0);
631  em->stats.active_count.q++;
632  }
633  else if (em->send_quic_disconnects == ECHO_CLOSE_F_NONE)
634  {
635  echo_cleanup_session (em, s);
636  em->stats.clean_count.q++;
637  }
638  }
639  }));
640  /* *INDENT-ON* */
641  em->state = STATE_DATA_DONE;
642 }
643 
644 static void
646  u32 n_read)
647 {
648  u32 i;
649  u8 expected;
650  for (i = 0; i < n_read; i++)
651  {
652  expected = (s->bytes_received + i) & 0xff;
653  if (rx_buf[i] == expected || em->max_test_msg > 0)
654  continue;
655  ECHO_LOG (0, "Session 0x%lx byte %lld was 0x%x expected 0x%x",
656  s->vpp_session_handle, s->bytes_received + i, rx_buf[i],
657  expected);
658  em->max_test_msg--;
659  if (em->max_test_msg == 0)
660  ECHO_LOG (0, "Too many errors, hiding next ones");
662  ECHO_FAIL ("test-bytes errored");
663  }
664 }
665 
666 static int
668 {
669  int n_read;
670  n_read = app_recv_stream ((app_session_t *) s, rx_buf, vec_len (rx_buf));
671  if (n_read <= 0)
672  return 0;
673  if (svm_fifo_needs_deq_ntf (s->rx_fifo, n_read))
675 
676  if (em->test_return_packets)
677  test_recv_bytes (em, s, rx_buf, n_read);
678 
679  s->bytes_received += n_read;
680  s->bytes_to_receive -= n_read;
681  return n_read;
682 }
683 
684 static int
685 send_data_chunk (echo_session_t * s, u8 * tx_buf, int offset, int len)
686 {
687  int n_sent;
688  int bytes_this_chunk = clib_min (s->bytes_to_send, len - offset);
689  if (!bytes_this_chunk)
690  return 0;
691  n_sent = app_send_stream ((app_session_t *) s, tx_buf + offset,
692  bytes_this_chunk, 0);
693  if (n_sent < 0)
694  return 0;
695  s->bytes_to_send -= n_sent;
696  s->bytes_sent += n_sent;
697  return n_sent;
698 }
699 
700 static int
702 {
703  u64 n_sent = 0;
704  while (n_sent < len && !em->time_to_stop)
705  n_sent += send_data_chunk (s, tx_buf, n_sent, len);
706  return n_sent;
707 }
708 
709 static void
711 {
712 
713  ECHO_LOG (1, "[%lu/%lu] -> S(%x) -> [%lu/%lu]",
715  s->session_index, s->bytes_sent,
716  s->bytes_sent + s->bytes_to_send);
719 
720  if (PREDICT_FALSE (em->stats.rx_total ==
721  em->n_clients * em->n_stream_clients *
722  em->bytes_to_receive))
724 }
725 
726 static inline void
728 {
729  echo_session_t *ls;
730  /* if parent has died, terminate gracefully */
732  if (ls->session_state < QUIC_SESSION_STATE_CLOSING)
733  return;
734  ECHO_LOG (2, "Session 0%lx died, close child 0x%lx", ls->vpp_session_handle,
735  s->vpp_session_handle);
737  em->stats.clean_count.s++;
739  s->session_state = QUIC_SESSION_STATE_CLOSED;
740 }
741 
742 /*
743  * Rx/Tx polling thread per connection
744  */
745 static void
747 {
748  int n_read, n_sent = 0;
749 
750  n_read = recv_data_chunk (em, s, rx_buf);
752  n_sent = send_data_chunk (s, em->connect_test_data,
753  s->bytes_sent % em->tx_buf_size,
754  em->tx_buf_size);
755  else if (em->data_source == ECHO_RX_DATA_SOURCE)
756  n_sent = mirror_data_chunk (em, s, rx_buf, n_read);
757  if (!s->bytes_to_send && !s->bytes_to_receive)
758  {
759  /* Session is done, need to close */
760  if (s->session_state == QUIC_SESSION_STATE_AWAIT_DATA)
761  s->session_state = QUIC_SESSION_STATE_CLOSING;
762  else
763  {
764  s->session_state = QUIC_SESSION_STATE_AWAIT_CLOSING;
766  {
767  echo_send_rpc (em, echo_disconnect_session, (void *) s, 0);
768  em->stats.close_count.s++;
769  }
771  {
772  s->session_state = QUIC_SESSION_STATE_CLOSING;
773  em->stats.clean_count.s++;
774  }
775  }
776  return;
777  }
778 
779  /* Check for idle clients */
780  if (em->log_lvl > 1)
781  {
782  if (n_sent || n_read)
783  s->idle_cycles = 0;
784  else if (s->idle_cycles++ == 1e7)
785  {
786  s->idle_cycles = 0;
787  ECHO_LOG (1, "Idle client TX:%dB RX:%dB", s->bytes_to_send,
788  s->bytes_to_receive);
789  ECHO_LOG (1, "Idle FIFOs TX:%dB RX:%dB",
790  svm_fifo_max_dequeue (s->tx_fifo),
791  svm_fifo_max_dequeue (s->rx_fifo));
792  ECHO_LOG (1, "Session 0x%lx state %u", s->vpp_session_handle,
793  s->session_state);
794  }
795  }
796 }
797 
798 static void *
800 {
802  echo_main_t *em = &echo_main;
803  u32 N = em->n_clients * em->n_stream_clients;
804  u32 n = (N + em->n_rx_threads - 1) / em->n_rx_threads;
805  u32 idx = (u64) arg;
806  u32 thread_n_sessions = clib_min (n, N - n * idx);
807 
808  u32 i = 0;
809  u32 n_closed_sessions = 0;
810  u32 session_index;
811  u8 *rx_buf = 0;
812  echo_session_t *s;
813  vec_validate (rx_buf, em->rx_buf_size);
814 
815  for (i = 0; !em->time_to_stop; i = (i + 1) % thread_n_sessions)
816  {
817  n_closed_sessions = i == 0 ? 0 : n_closed_sessions;
818  session_index = em->data_thread_args[n * idx + i];
819  if (session_index == SESSION_INVALID_INDEX)
820  continue;
821  s = pool_elt_at_index (em->sessions, session_index);
822  switch (s->session_state)
823  {
826  echo_handle_data (em, s, rx_buf);
828  break;
831  break;
834  echo_cleanup_session (em, s);
835  break;
837  n_closed_sessions++;
838  break;
839  }
840  if (n_closed_sessions == thread_n_sessions)
841  break;
842  }
843  pthread_exit (0);
844 }
845 
846 static void
848 {
849  echo_main_t *em = &echo_main;
850  echo_session_t *listen_session;
851  if (mp->retval)
852  {
853  ECHO_FAIL ("bind failed: %U", format_api_error,
854  clib_net_to_host_u32 (mp->retval));
855  return;
856  }
857  ECHO_LOG (0, "listening on %U:%u", format_ip46_address, mp->lcl_ip,
859  clib_net_to_host_u16 (mp->lcl_port));
860 
861  /* Allocate local session and set it up */
862  listen_session = echo_session_new (em);
863  listen_session->session_type = QUIC_SESSION_TYPE_LISTEN;
864  echo_session_handle_add_del (em, mp->handle, listen_session->session_index);
865  em->state = STATE_LISTEN;
866  em->listen_session_index = listen_session->session_index;
867 }
868 
869 static void
871 {
872  app_session_evt_t _app_evt, *app_evt = &_app_evt;
874  svm_fifo_t *rx_fifo, *tx_fifo;
875  echo_main_t *em = &echo_main;
876  echo_session_t *session, *ls;
877  /* Allocate local session and set it up */
878  session = echo_session_new (em);
879 
881  {
882  ECHO_FAIL ("wait_for_segment_allocation errored");
883  return;
884  }
885 
886  rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
887  rx_fifo->client_session_index = session->session_index;
888  tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
889  tx_fifo->client_session_index = session->session_index;
890 
891  session->rx_fifo = rx_fifo;
892  session->tx_fifo = tx_fifo;
893  session->vpp_session_handle = mp->handle;
894  session->start = clib_time_now (&em->clib_time);
895  session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
896  svm_msg_q_t *);
897  if (!(ls = echo_get_session_from_handle (em, mp->listener_handle)))
898  return;
899  session->listener_index = ls->session_index;
900 
901  /* Add it to lookup table */
902  ECHO_LOG (1, "Accepted session 0x%lx -> 0x%lx", mp->handle,
903  mp->listener_handle);
904  echo_session_handle_add_del (em, mp->handle, session->session_index);
905 
906  app_alloc_ctrl_evt_to_vpp (session->vpp_evt_q, app_evt,
908  rmp = (session_accepted_reply_msg_t *) app_evt->evt->data;
909  rmp->handle = mp->handle;
910  rmp->context = mp->context;
911  app_send_ctrl_evt_to_vpp (session->vpp_evt_q, app_evt);
912 
913  if (ls->session_type == QUIC_SESSION_TYPE_LISTEN)
914  {
916  session->session_type = QUIC_SESSION_TYPE_QUIC;
917  session->accepted_session_count = 0;
918  if (em->cb_vft.quic_accepted_cb)
919  em->cb_vft.quic_accepted_cb (mp, session->session_index);
921  }
922  else
923  {
924  session->session_type = QUIC_SESSION_TYPE_STREAM;
927  if (em->i_am_master && em->cb_vft.server_stream_accepted_cb)
928  em->cb_vft.server_stream_accepted_cb (mp, session->session_index);
929  if (!em->i_am_master && em->cb_vft.client_stream_accepted_cb)
930  em->cb_vft.client_stream_accepted_cb (mp, session->session_index);
932  }
933 
934  if (em->n_clients_connected == em->n_clients * em->n_stream_clients
935  && em->n_clients_connected != 0)
937  if (em->n_quic_clients_connected == em->n_clients
938  && em->state < STATE_READY)
939  {
941  em->state = STATE_READY;
942  if (em->n_stream_clients == 0)
944  }
945 }
946 
947 static void
949 {
950  echo_main_t *em = &echo_main;
951  echo_session_t *session, *listen_session;
952  u32 listener_index = htonl (mp->context);
953  svm_fifo_t *rx_fifo, *tx_fifo;
954 
955  if (mp->retval)
956  {
957  ECHO_FAIL ("connection failed with code: %U", format_api_error,
958  clib_net_to_host_u32 (mp->retval));
959  return;
960  }
961 
962  session = echo_session_new (em);
964  {
965  ECHO_FAIL ("wait_for_segment_allocation errored");
966  return;
967  }
968 
969  rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
970  rx_fifo->client_session_index = session->session_index;
971  tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
972  tx_fifo->client_session_index = session->session_index;
973 
974  session->rx_fifo = rx_fifo;
975  session->tx_fifo = tx_fifo;
976  session->vpp_session_handle = mp->handle;
977  session->start = clib_time_now (&em->clib_time);
978  session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
979  svm_msg_q_t *);
980 
981  echo_session_handle_add_del (em, mp->handle, session->session_index);
982 
983  if (listener_index == SESSION_INVALID_INDEX)
984  {
985  ECHO_LOG (1, "Connected session 0x%lx -> URI", mp->handle);
986  session->session_type = QUIC_SESSION_TYPE_QUIC;
987  session->accepted_session_count = 0;
988  if (em->cb_vft.quic_connected_cb)
989  em->cb_vft.quic_connected_cb (mp, session->session_index);
991  }
992  else
993  {
994  listen_session = pool_elt_at_index (em->sessions, listener_index);
995  session->listener_index = listener_index;
996  ECHO_LOG (1, "Connected session 0x%lx -> 0x%lx", mp->handle,
997  listen_session->vpp_session_handle);
998  session->session_type = QUIC_SESSION_TYPE_STREAM;
999  clib_atomic_fetch_add (&listen_session->accepted_session_count, 1);
1000  if (em->i_am_master && em->cb_vft.server_stream_connected_cb)
1001  em->cb_vft.server_stream_connected_cb (mp, session->session_index);
1002  if (!em->i_am_master && em->cb_vft.client_stream_connected_cb)
1003  em->cb_vft.client_stream_connected_cb (mp, session->session_index);
1005  }
1006 
1007  if (em->n_clients_connected == em->n_clients * em->n_stream_clients
1008  && em->n_clients_connected != 0)
1010  if (em->n_quic_clients_connected == em->n_clients
1011  && em->state < STATE_READY)
1012  {
1014  em->state = STATE_READY;
1015  if (em->n_stream_clients == 0)
1017  }
1018 }
1019 
1020 /*
1021  *
1022  * ECHO Callback definitions
1023  *
1024  */
1025 
1026 
1027 static void
1029 {
1030  echo_main_t *em = &echo_main;
1031  u8 *uri = format (0, "QUIC://session/%lu", mp->handle);
1032  u64 i;
1033 
1035  for (i = 0; i < em->n_stream_clients; i++)
1036  echo_send_rpc (em, echo_send_connect, (void *) uri, session_index);
1037 
1038  ECHO_LOG (0, "Qsession 0x%llx connected to %U:%d",
1039  mp->handle, format_ip46_address, &mp->lcl.ip,
1040  mp->lcl.is_ip4, clib_net_to_host_u16 (mp->lcl.port));
1041 }
1042 
1043 static void
1045 {
1046  echo_main_t *em = &echo_main;
1047  echo_session_t *session;
1048 
1049  session = pool_elt_at_index (em->sessions, session_index);
1050  session->bytes_to_send = em->bytes_to_send;
1051  session->bytes_to_receive = em->bytes_to_receive;
1052  session->session_state = QUIC_SESSION_STATE_READY;
1053  em->data_thread_args[em->n_clients_connected] = session->session_index;
1054 }
1055 
1056 static void
1058 {
1059  ECHO_FAIL ("Got a wrong connected on session %u [%lx]", session_index,
1060  mp->handle);
1061 }
1062 
1063 static void
1065 {
1066  echo_main_t *em = &echo_main;
1067  echo_session_t *session;
1068 
1069  session = pool_elt_at_index (em->sessions, session_index);
1070  session->bytes_to_send = em->bytes_to_send;
1071  session->bytes_to_receive = em->bytes_to_receive;
1072  em->data_thread_args[em->n_clients_connected] = session->session_index;
1073  session->session_state = QUIC_SESSION_STATE_READY;
1074 }
1075 
1076 static void
1078 {
1079  echo_main_t *em = &echo_main;
1080  ECHO_LOG (1, "Accept on QSession 0x%lx %u", mp->handle);
1081  u8 *uri = format (0, "QUIC://session/%lu", mp->handle);
1082  u32 i;
1083 
1085  for (i = 0; i < em->n_stream_clients; i++)
1086  echo_send_rpc (em, echo_send_connect, (void *) uri, session_index);
1087 }
1088 
1089 static void
1091 {
1092  ECHO_FAIL ("Got a wrong accept on session %u [%lx]", session_index,
1093  mp->handle);
1094 }
1095 
1096 static void
1098 {
1099  u8 *ip_str;
1100  ip_str = format (0, "%U", format_ip46_address, &mp->rmt.ip, mp->rmt.is_ip4);
1101  ECHO_LOG (0, "Accepted session from: %s:%d", ip_str,
1102  clib_net_to_host_u16 (mp->rmt.port));
1103 
1104 }
1105 
1107  /* Qsessions */
1108  .quic_accepted_cb = echo_on_accept_log_ip,
1109  .quic_connected_cb = echo_on_connected_connect,
1110  /* client initiated streams */
1111  .server_stream_accepted_cb = echo_on_accept_recv,
1112  .client_stream_connected_cb = echo_on_connected_send,
1113  /* server initiated streams */
1114  .client_stream_accepted_cb = echo_on_accept_error,
1115  .server_stream_connected_cb = echo_on_connected_error,
1116 };
1117 
1119  /* Qsessions */
1120  .quic_accepted_cb = echo_on_accept_connect,
1121  .quic_connected_cb = NULL,
1122  /* client initiated streams */
1123  .server_stream_accepted_cb = echo_on_accept_error,
1124  .client_stream_connected_cb = echo_on_connected_error,
1125  /* server initiated streams */
1126  .client_stream_accepted_cb = echo_on_accept_recv,
1127  .server_stream_connected_cb = echo_on_connected_send,
1128 };
1129 
1130 static uword
1132 {
1133  echo_main_t *em = &echo_main;
1134  if (unformat (input, "serverstream"))
1136  else if (unformat (input, "default"))
1137  ;
1138  else
1139  return 0;
1140  return 1;
1141 }
1142 
1143 /*
1144  *
1145  * End of ECHO callback definitions
1146  *
1147  */
1148 
1149 static void
1151 {
1152  app_session_evt_t _app_evt, *app_evt = &_app_evt;
1154  echo_main_t *em = &echo_main;
1155  echo_session_t *s;
1156  int rv = 0;
1157  ECHO_LOG (1, "passive close session 0x%lx", mp->handle);
1158  if (!(s = echo_get_session_from_handle (em, mp->handle)))
1159  return;
1160 
1161  app_alloc_ctrl_evt_to_vpp (s->vpp_evt_q, app_evt,
1163  rmp = (session_disconnected_reply_msg_t *) app_evt->evt->data;
1164  rmp->retval = rv;
1165  rmp->handle = mp->handle;
1166  rmp->context = mp->context;
1167  app_send_ctrl_evt_to_vpp (s->vpp_evt_q, app_evt);
1168 
1169  if (s->session_type == QUIC_SESSION_TYPE_STREAM)
1170  {
1171  session_print_stats (em, s);
1172  if (s->bytes_to_receive || s->bytes_to_send)
1173  s->session_state = QUIC_SESSION_STATE_AWAIT_DATA;
1174  else
1175  s->session_state = QUIC_SESSION_STATE_CLOSING;
1176  em->stats.close_count.s++;
1177  }
1178  else
1179  {
1180  echo_cleanup_session (em, s); /* We can clean Q/Lsessions right away */
1181  em->stats.close_count.q++;
1182  }
1183 }
1184 
1185 static void
1187 {
1188  app_session_evt_t _app_evt, *app_evt = &_app_evt;
1189  echo_main_t *em = &echo_main;
1191  echo_session_t *s = 0;
1192  int rv = 0;
1193 
1194  ECHO_LOG (1, "Reset session 0x%lx", mp->handle);
1195  if (!(s = echo_get_session_from_handle (em, mp->handle)))
1196  return;
1197  if (s->session_type == QUIC_SESSION_TYPE_STREAM)
1198  {
1199  em->stats.reset_count.s++;
1200  s->session_state = QUIC_SESSION_STATE_CLOSING;
1201  }
1202  else
1203  {
1204  em->stats.reset_count.q++;
1205  echo_cleanup_session (em, s); /* We can clean Q/Lsessions right away */
1206  }
1207 
1208  app_alloc_ctrl_evt_to_vpp (s->vpp_evt_q, app_evt,
1210  rmp = (session_reset_reply_msg_t *) app_evt->evt->data;
1211  rmp->retval = rv;
1212  rmp->handle = mp->handle;
1213  app_send_ctrl_evt_to_vpp (s->vpp_evt_q, app_evt);
1214 }
1215 
1216 static void
1217 handle_mq_event (session_event_t * e)
1218 {
1219  switch (e->event_type)
1220  {
1223  break;
1226  break;
1229  break;
1232  break;
1235  break;
1236  case SESSION_IO_EVT_RX:
1237  break;
1238  default:
1239  ECHO_LOG (0, "unhandled event %u", e->event_type);
1240  }
1241 }
1242 
1243 static int
1245  f64 timeout)
1246 {
1247  f64 end_time = clib_time_now (&em->clib_time) + timeout;
1248  while (!timeout || clib_time_now (&em->clib_time) < end_time)
1249  {
1250  if (em->state == state)
1251  return 0;
1252  if (em->time_to_stop)
1253  return 1;
1254  }
1255  ECHO_LOG (1, "timeout waiting for %U", format_quic_echo_state, state);
1256  return -1;
1257 }
1258 
1259 static void
1261 {
1262  echo_rpc_msg_t *rpc;
1263  svm_msg_q_msg_t msg;
1264  while (em->state < STATE_DATA_DONE && !em->time_to_stop)
1265  {
1266  if (svm_msg_q_sub (em->rpc_msq_queue, &msg, SVM_Q_TIMEDWAIT, 1))
1267  continue;
1268  rpc = svm_msg_q_msg_data (em->rpc_msq_queue, &msg);
1269  ((echo_rpc_t) rpc->fp) (rpc->arg, rpc->opaque);
1270  svm_msg_q_free_msg (em->rpc_msq_queue, &msg);
1271  }
1272 }
1273 
1274 static void *
1276 {
1278  echo_main_t *em = &echo_main;
1279  session_event_t *e;
1280  svm_msg_q_msg_t msg;
1281  int rv;
1283  if (em->state < STATE_ATTACHED || !em->our_event_queue)
1284  {
1285  ECHO_FAIL ("Application failed to attach");
1286  pthread_exit (0);
1287  }
1288 
1289  ECHO_LOG (1, "Waiting for data on %u clients", em->n_clients_connected);
1290  while (1)
1291  {
1292  if (!(rv = svm_msg_q_sub (em->our_event_queue,
1293  &msg, SVM_Q_TIMEDWAIT, 1)))
1294  {
1295  e = svm_msg_q_msg_data (em->our_event_queue, &msg);
1296  handle_mq_event (e);
1297  svm_msg_q_free_msg (em->our_event_queue, &msg);
1298  }
1299  if (rv == ETIMEDOUT
1300  && (em->time_to_stop || em->state == STATE_DETACHED))
1301  break;
1302  if (!em->n_clients_connected && !em->n_quic_clients_connected &&
1303  em->state == STATE_READY)
1304  {
1305  em->state = STATE_DATA_DONE;
1306  }
1307  }
1308  pthread_exit (0);
1309 }
1310 
1311 static void
1313 {
1314  u64 i;
1316  for (i = 0; i < em->n_clients; i++)
1319  ECHO_LOG (1, "App is ready");
1320  echo_process_rpcs (em);
1321 }
1322 
1323 static void
1325 {
1326  server_send_listen (em);
1328  ECHO_LOG (1, "App is ready");
1329  echo_process_rpcs (em);
1330  /* Cleanup */
1331  server_send_unbind (em);
1333  {
1334  ECHO_FAIL ("Timeout waiting for state disconnected");
1335  return;
1336  }
1337 }
1338 
1339 /*
1340  *
1341  * Session API handlers
1342  *
1343  */
1344 
1345 static void
1347  mp)
1348 {
1349  echo_main_t *em = &echo_main;
1350  int *fds = 0, i;
1351  u32 n_fds = 0;
1352  u64 segment_handle;
1353  segment_handle = clib_net_to_host_u64 (mp->segment_handle);
1354  ECHO_LOG (1, "Attached returned app %u", htons (mp->app_index));
1355 
1356  if (mp->retval)
1357  {
1358  ECHO_FAIL ("attach failed: %U", format_api_error,
1359  clib_net_to_host_u32 (mp->retval));
1360  return;
1361  }
1362 
1363  if (mp->segment_name_length == 0)
1364  {
1365  ECHO_FAIL ("segment_name_length zero");
1366  return;
1367  }
1368 
1371  svm_msg_q_t *);
1372 
1373  if (mp->n_fds)
1374  {
1375  vec_validate (fds, mp->n_fds);
1376  if (vl_socket_client_recv_fd_msg (fds, mp->n_fds, 5))
1377  {
1378  ECHO_FAIL ("vl_socket_client_recv_fd_msg failed");
1379  goto failed;
1380  }
1381 
1382  if (mp->fd_flags & SESSION_FD_F_VPP_MQ_SEGMENT)
1383  if (ssvm_segment_attach (0, SSVM_SEGMENT_MEMFD, fds[n_fds++]))
1384  {
1385  ECHO_FAIL ("svm_fifo_segment_attach failed");
1386  goto failed;
1387  }
1388 
1389  if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT)
1390  if (ssvm_segment_attach ((char *) mp->segment_name,
1391  SSVM_SEGMENT_MEMFD, fds[n_fds++]))
1392  {
1393  ECHO_FAIL ("svm_fifo_segment_attach ('%s') failed",
1394  mp->segment_name);
1395  goto failed;
1396  }
1397  if (mp->fd_flags & SESSION_FD_F_MQ_EVENTFD)
1398  svm_msg_q_set_consumer_eventfd (em->our_event_queue, fds[n_fds++]);
1399 
1400  vec_free (fds);
1401  }
1402  else
1403  {
1405  -1))
1406  {
1407  ECHO_FAIL ("svm_fifo_segment_attach ('%s') failed",
1408  mp->segment_name);
1409  return;
1410  }
1411  }
1412  echo_segment_handle_add_del (em, segment_handle, 1 /* add */ );
1413  ECHO_LOG (1, "Mapped segment 0x%lx", segment_handle);
1414 
1415  em->state = STATE_ATTACHED;
1416  return;
1417 failed:
1418  for (i = clib_max (n_fds - 1, 0); i < vec_len (fds); i++)
1419  close (fds[i]);
1420  vec_free (fds);
1421 }
1422 
1423 static void
1424 vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t *
1425  mp)
1426 {
1427  if (mp->retval)
1428  {
1429  ECHO_FAIL ("detach returned with err: %d", mp->retval);
1430  return;
1431  }
1432  echo_main.state = STATE_DETACHED;
1433 }
1434 
1435 
1436 static void
1438 {
1439  echo_main_t *em = &echo_main;
1440  u64 segment_handle = clib_net_to_host_u64 (mp->segment_handle);
1441  echo_segment_handle_add_del (em, segment_handle, 0 /* add */ );
1442  ECHO_LOG (1, "Unmaped segment 0x%lx", segment_handle);
1443 }
1444 
1445 static void
1447 {
1448  fifo_segment_main_t *sm = &echo_main.segment_main;
1449  fifo_segment_create_args_t _a, *a = &_a;
1450  echo_main_t *em = &echo_main;
1451  int *fds = 0, i;
1452  char *seg_name = (char *) mp->segment_name;
1453  u64 segment_handle = clib_net_to_host_u64 (mp->segment_handle);
1454 
1455  if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT)
1456  {
1457  vec_validate (fds, 1);
1458  if (vl_socket_client_recv_fd_msg (fds, 1, 5))
1459  {
1460  ECHO_FAIL ("vl_socket_client_recv_fd_msg failed");
1461  goto failed;
1462  }
1463 
1464  if (ssvm_segment_attach (seg_name, SSVM_SEGMENT_MEMFD, fds[0]))
1465  {
1466  ECHO_FAIL ("svm_fifo_segment_attach ('%s')"
1467  "failed on SSVM_SEGMENT_MEMFD", seg_name);
1468  goto failed;
1469  }
1470  vec_free (fds);
1471  }
1472  else
1473  {
1474  clib_memset (a, 0, sizeof (*a));
1475  a->segment_name = seg_name;
1476  a->segment_size = mp->segment_size;
1477  /* Attach to the segment vpp created */
1478  if (fifo_segment_attach (sm, a))
1479  {
1480  ECHO_FAIL ("svm_fifo_segment_attach ('%s') failed", seg_name);
1481  goto failed;
1482  }
1483  }
1484  echo_segment_handle_add_del (em, segment_handle, 1 /* add */ );
1485  ECHO_LOG (1, "Mapped segment 0x%lx", segment_handle);
1486  return;
1487 
1488 failed:
1489  for (i = 0; i < vec_len (fds); i++)
1490  close (fds[i]);
1491  vec_free (fds);
1492 }
1493 
1494 static void
1495 vl_api_bind_uri_reply_t_handler (vl_api_bind_uri_reply_t * mp)
1496 {
1497  echo_main_t *em = &echo_main;
1498  if (mp->retval)
1499  {
1500  ECHO_FAIL ("bind failed: %U", format_api_error,
1501  clib_net_to_host_u32 (mp->retval));
1502  return;
1503  }
1504 
1505  em->state = STATE_LISTEN;
1506 }
1507 
1508 static void
1509 vl_api_unbind_uri_reply_t_handler (vl_api_unbind_uri_reply_t * mp)
1510 {
1511  echo_session_t *listen_session;
1512  echo_main_t *em = &echo_main;
1513  if (mp->retval != 0)
1514  {
1515  ECHO_FAIL ("returned %d", ntohl (mp->retval));
1516  return;
1517  }
1518  em->state = STATE_DISCONNECTED;
1519  listen_session = pool_elt_at_index (em->sessions, em->listen_session_index);
1520  echo_cleanup_session (em, listen_session);
1521 }
1522 
1523 static void
1525  mp)
1526 {
1527  echo_main_t *em = &echo_main;
1528  echo_session_t *s;
1529 
1530  if (mp->retval)
1531  {
1532  ECHO_FAIL ("vpp complained about disconnect: %d", ntohl (mp->retval));
1533  return;
1534  }
1535 
1536  ECHO_LOG (1, "Got disonnected reply for session 0x%lx", mp->handle);
1537  if (!(s = echo_get_session_from_handle (em, mp->handle)))
1538  return;
1539  if (s->session_type == QUIC_SESSION_TYPE_STREAM)
1540  s->session_state = QUIC_SESSION_STATE_CLOSING;
1541  else
1542  echo_cleanup_session (em, s); /* We can clean Q/Lsessions right away */
1543 }
1544 
1545 static void
1547  (vl_api_application_tls_cert_add_reply_t * mp)
1548 {
1549  if (mp->retval)
1550  ECHO_FAIL ("failed to add tls cert");
1551 }
1552 
1553 static void
1555  (vl_api_application_tls_key_add_reply_t * mp)
1556 {
1557  if (mp->retval)
1558  ECHO_FAIL ("failed to add tls key");
1559 }
1560 
1561 static void
1562 vl_api_connect_uri_reply_t_handler (vl_api_connect_uri_reply_t * mp)
1563 {
1564  echo_session_t *session;
1565  echo_main_t *em = &echo_main;
1566  u8 *uri;
1567  if (!mp->retval)
1568  return;
1569  /* retry connect */
1570  if (mp->context == SESSION_INVALID_INDEX)
1571  {
1572  ECHO_LOG (1, "Retrying connect %s", em->uri);
1573  echo_send_rpc (em, echo_send_connect, (void *) em->uri,
1575  }
1576  else
1577  {
1578  session = pool_elt_at_index (em->sessions, mp->context);
1579  uri = format (0, "QUIC://session/%lu", session->vpp_session_handle);
1580  ECHO_LOG (1, "Retrying connect %s", uri);
1581  echo_send_rpc (em, echo_send_connect, (void *) uri, mp->context);
1582  }
1583 
1584 }
1585 
1586 #define foreach_quic_echo_msg \
1587 _(BIND_URI_REPLY, bind_uri_reply) \
1588 _(UNBIND_URI_REPLY, unbind_uri_reply) \
1589 _(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \
1590 _(APPLICATION_ATTACH_REPLY, application_attach_reply) \
1591 _(APPLICATION_DETACH_REPLY, application_detach_reply) \
1592 _(MAP_ANOTHER_SEGMENT, map_another_segment) \
1593 _(UNMAP_SEGMENT, unmap_segment) \
1594 _(APPLICATION_TLS_CERT_ADD_REPLY, application_tls_cert_add_reply) \
1595 _(APPLICATION_TLS_KEY_ADD_REPLY, application_tls_key_add_reply) \
1596 _(CONNECT_URI_REPLY, connect_uri_reply) \
1597 
1598 void
1600 {
1601 #define _(N,n) \
1602  vl_msg_api_set_handlers(VL_API_##N, #n, \
1603  vl_api_##n##_t_handler, \
1604  vl_noop_handler, \
1605  vl_api_##n##_t_endian, \
1606  vl_api_##n##_t_print, \
1607  sizeof(vl_api_##n##_t), 1);
1609 #undef _
1610 }
1611 
1612 /*
1613  *
1614  * End Session API handlers
1615  *
1616  */
1617 
1618 static void
1620 {
1621  fprintf (stderr,
1622  "Usage: quic_echo [socket-name SOCKET] [client|server] [uri URI] [OPTIONS]\n"
1623  "Generates traffic and assert correct teardown of the QUIC hoststack\n"
1624  "\n"
1625  " socket-name PATH Specify the binary socket path to connect to VPP\n"
1626  " use-svm-api Use SVM API to connect to VPP\n"
1627  " test-bytes[:assert] Check data correctness when receiving (assert fails on first error)\n"
1628  " fifo-size N Use N Kb fifos\n"
1629  " rx-buf N Use N Kb RX buffer\n"
1630  " tx-buf N Use N Kb TX test buffer\n"
1631  " appns NAMESPACE Use the namespace NAMESPACE\n"
1632  " all-scope all-scope option\n"
1633  " local-scope local-scope option\n"
1634  " global-scope global-scope option\n"
1635  " secret SECRET set namespace secret\n"
1636  " chroot prefix PATH Use PATH as memory root path\n"
1637  " quic-setup OPT OPT=serverstream : Client open N connections. \n"
1638  " On each one server opens M streams\n"
1639  " OPT=default : Client open N connections.\n"
1640  " On each one client opens M streams\n"
1641  " sclose=[Y|N|W] When a stream is done, pass[N] send[Y] or wait[W] for close\n"
1642  " qclose=[Y|N|W] When a connection is done pass[N] send[Y] or wait[W] for close\n"
1643  "\n"
1644  " time START:END Time between evts START & END, events being :\n"
1645  " start - Start of the app\n"
1646  " qconnect - first Connection connect sent\n"
1647  " qconnected - last Connection connected\n"
1648  " sconnect - first Stream connect sent\n"
1649  " sconnected - last Stream got connected\n"
1650  " lastbyte - Last expected byte received\n"
1651  " exit - Exiting of the app\n"
1652  " json Output global stats in json\n"
1653  " log=N Set the log level to [0: no output, 1:errors, 2:log]\n"
1654  " max-connects=N Don't do more than N parallel connect_uri\n"
1655  "\n"
1656  " nclients N[/M] Open N QUIC connections, each one with M streams (M defaults to 1)\n"
1657  " nthreads N Use N busy loop threads for data [in addition to main & msg queue]\n"
1658  " TX=1337[Kb|Mb|GB] Send 1337 [K|M|G]bytes, use TX=RX to reflect the data\n"
1659  " RX=1337[Kb|Mb|GB] Expect 1337 [K|M|G]bytes\n"
1660  "\n"
1661  "Default configuration is :\n"
1662  " server nclients 1/1 RX=64Kb TX=RX\n"
1663  " client nclients 1/1 RX=64Kb TX=64Kb\n");
1664  exit (1);
1665 }
1666 
1667 
1668 void
1669 quic_echo_process_opts (int argc, char **argv)
1670 {
1671  echo_main_t *em = &echo_main;
1672  unformat_input_t _argv, *a = &_argv;
1673  u32 tmp;
1674  u8 *chroot_prefix;
1675  u8 *uri = 0;
1676  u8 default_f_active;
1677 
1678  unformat_init_command_line (a, argv);
1680  {
1681  if (unformat (a, "chroot prefix %s", &chroot_prefix))
1682  {
1683  vl_set_memory_root_path ((char *) chroot_prefix);
1684  }
1685  else if (unformat (a, "uri %s", &uri))
1686  em->uri = format (0, "%s%c", uri, 0);
1687  else if (unformat (a, "server"))
1688  em->i_am_master = 1;
1689  else if (unformat (a, "client"))
1690  em->i_am_master = 0;
1691  else if (unformat (a, "test-bytes:assert"))
1693  else if (unformat (a, "test-bytes"))
1695  else if (unformat (a, "socket-name %s", &em->socket_name))
1696  ;
1697  else if (unformat (a, "use-svm-api"))
1698  em->use_sock_api = 0;
1699  else if (unformat (a, "fifo-size %d", &tmp))
1700  em->fifo_size = tmp << 10;
1701  else if (unformat (a, "rx-buf %d", &tmp))
1702  em->rx_buf_size = tmp << 10;
1703  else if (unformat (a, "tx-buf %d", &tmp))
1704  em->rx_buf_size = tmp << 10;
1705  else
1706  if (unformat
1707  (a, "nclients %d/%d", &em->n_clients, &em->n_stream_clients))
1708  ;
1709  else if (unformat (a, "nclients %d", &em->n_clients))
1710  ;
1711  else if (unformat (a, "nthreads %d", &em->n_rx_threads))
1712  ;
1713  else if (unformat (a, "appns %_%v%_", &em->appns_id))
1714  ;
1715  else if (unformat (a, "all-scope"))
1716  em->appns_flags |= (APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE
1717  | APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE);
1718  else if (unformat (a, "local-scope"))
1719  em->appns_flags = APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
1720  else if (unformat (a, "global-scope"))
1721  em->appns_flags = APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
1722  else if (unformat (a, "secret %lu", &em->appns_secret))
1723  ;
1724  else if (unformat (a, "quic-setup %U", echo_unformat_quic_setup_vft))
1725  ;
1726  else if (unformat (a, "TX=RX"))
1728  else if (unformat (a, "TX=%U", unformat_data, &em->bytes_to_send))
1729  ;
1730  else if (unformat (a, "RX=%U", unformat_data, &em->bytes_to_receive))
1731  ;
1732  else if (unformat (a, "json"))
1733  em->output_json = 1;
1734  else if (unformat (a, "log=%d", &em->log_lvl))
1735  ;
1736  else
1737  if (unformat
1738  (a, "sclose=%U", unformat_close, &em->send_stream_disconnects))
1739  ;
1740  else
1741  if (unformat
1742  (a, "qclose=%U", unformat_close, &em->send_quic_disconnects))
1743  ;
1744  else if (unformat (a, "time %U:%U",
1747  ;
1748  else
1750  }
1751 
1752  /* setting default for unset values
1753  *
1754  * bytes_to_send / bytes_to_receive & data_source */
1755  if (em->bytes_to_receive == (u64) ~ 0)
1756  em->bytes_to_receive = 64 << 10; /* default */
1757  if (em->bytes_to_send == (u64) ~ 0)
1758  em->bytes_to_send = 64 << 10; /* default */
1759  else if (em->bytes_to_send == 0)
1761  else
1763 
1765  em->data_source =
1767  if (em->data_source == ECHO_RX_DATA_SOURCE)
1768  em->bytes_to_send = em->bytes_to_receive;
1769 
1770  /* disconnect flags */
1771  if (em->i_am_master)
1772  default_f_active =
1774  else
1775  default_f_active =
1778  em->send_stream_disconnects = default_f_active;
1780  em->send_quic_disconnects = default_f_active;
1781 }
1782 
1783 int
1784 main (int argc, char **argv)
1785 {
1786  echo_main_t *em = &echo_main;
1787  fifo_segment_main_t *sm = &em->segment_main;
1788  char *app_name;
1789  u64 n_clients, i;
1790  svm_msg_q_cfg_t _cfg, *cfg = &_cfg;
1791  u32 rpc_queue_size = 64 << 10;
1792 
1793  clib_mem_init_thread_safe (0, 256 << 20);
1794  clib_memset (em, 0, sizeof (*em));
1795  em->session_index_by_vpp_handles = hash_create (0, sizeof (uword));
1797  em->shared_segment_handles = hash_create (0, sizeof (uword));
1799  em->socket_name = format (0, "%s%c", API_SOCKET_FILE, 0);
1800  em->use_sock_api = 1;
1801  em->fifo_size = 64 << 10;
1802  em->n_clients = 1;
1803  em->n_stream_clients = 1;
1804  em->max_test_msg = 50;
1805  em->time_to_stop = 0;
1806  em->i_am_master = 1;
1807  em->n_rx_threads = 4;
1811  em->bytes_to_receive = ~0; /* defaulted when we know if server/client */
1812  em->bytes_to_send = ~0; /* defaulted when we know if server/client */
1813  em->rx_buf_size = 1 << 20;
1814  em->tx_buf_size = 1 << 20;
1816  em->uri = format (0, "%s%c", "quic://0.0.0.0/1234", 0);
1817  em->cb_vft = default_cb_vft;
1818  quic_echo_process_opts (argc, argv);
1819 
1820  n_clients = em->n_clients * em->n_stream_clients;
1822  vec_validate (em->data_thread_args, n_clients - 1);
1823  for (i = 0; i < n_clients; i++)
1825  clib_time_init (&em->clib_time);
1829  for (i = 0; i < em->tx_buf_size; i++)
1830  em->connect_test_data[i] = i & 0xff;
1831 
1832  /* *INDENT-OFF* */
1834  {rpc_queue_size, sizeof (echo_rpc_msg_t), 0},
1835  };
1836  /* *INDENT-ON* */
1837  cfg->consumer_pid = getpid ();
1838  cfg->n_rings = 1;
1839  cfg->q_nitems = rpc_queue_size;
1840  cfg->ring_cfgs = rc;
1841  em->rpc_msq_queue = svm_msg_q_alloc (cfg);
1842 
1843  signal (SIGINT, stop_signal);
1844  signal (SIGQUIT, stop_signal);
1845  signal (SIGTERM, stop_signal);
1846  quic_echo_api_hookup (em);
1847 
1848  app_name = em->i_am_master ? "quic_echo_server" : "quic_echo_client";
1849  if (connect_to_vpp (app_name) < 0)
1850  {
1851  svm_region_exit ();
1852  ECHO_FAIL ("Couldn't connect to vpe, exiting...\n");
1853  exit (1);
1854  }
1855 
1856  echo_session_prealloc (em);
1858 
1861  {
1862  ECHO_FAIL ("Couldn't attach to vpp, did you run <session enable> ?\n");
1863  exit (1);
1864  }
1865  if (pthread_create (&em->mq_thread_handle,
1866  NULL /*attr */ , echo_mq_thread_fn, 0))
1867  {
1868  ECHO_FAIL ("pthread create errored\n");
1869  exit (1);
1870  }
1871  for (i = 0; i < em->n_rx_threads; i++)
1872  if (pthread_create (&em->data_thread_handles[i],
1873  NULL /*attr */ , echo_data_thread_fn, (void *) i))
1874  {
1875  ECHO_FAIL ("pthread create errored\n");
1876  exit (1);
1877  }
1878  if (em->i_am_master)
1879  server_run (em);
1880  else
1881  clients_run (em);
1883  if (em->output_json)
1885  else
1886  print_global_stats (em);
1887  echo_free_sessions (em);
1889  application_detach (em);
1891  {
1892  ECHO_FAIL ("ECHO-ERROR: Couldn't detach from vpp, exiting...\n");
1893  exit (1);
1894  }
1895  int *rv;
1896  pthread_join (em->mq_thread_handle, (void **) &rv);
1897  if (rv)
1898  {
1899  ECHO_FAIL ("mq pthread errored %d", rv);
1900  exit (1);
1901  }
1902  if (em->use_sock_api)
1904  else
1906  ECHO_LOG (0, "Test complete !\n");
1907  exit (em->has_failed);
1908 }
1909 
1910 /*
1911  * fd.io coding-style-patch-verification: ON
1912  *
1913  * Local Variables:
1914  * eval: (c-set-style "gnu")
1915  * End:
1916  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
static void * echo_data_thread_fn(void *arg)
Definition: quic_echo.c:799
volatile u64 accepted_session_count
Definition: quic_echo.h:74
clib_time_t clib_time
Definition: quic_echo.h:167
static u8 svm_msg_q_msg_is_invalid(svm_msg_q_msg_t *msg)
Check if message is invalid.
static void server_send_listen(echo_main_t *em)
Definition: quic_echo.c:289
#define hash_set(h, key, value)
Definition: hash.h:255
void * svm_msg_q_msg_data(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Get data for message in queue.
static u8 svm_msg_q_ring_is_full(svm_msg_q_t *mq, u32 ring_index)
teardown_stat_t clean_count
Definition: quic_echo.h:226
#define clib_min(x, y)
Definition: clib.h:295
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
Definition: lock.h:100
int vl_socket_client_init_shm(vl_api_shm_elem_config_t *config, int want_pthread)
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:78
static int wait_for_state_change(echo_main_t *em, connection_state_t state, f64 timeout)
Definition: quic_echo.c:1244
u32 listen_session_index
Definition: quic_echo.h:170
u32 listener_index
Definition: quic_echo.h:72
int vl_client_connect_to_vlib(const char *svm_name, const char *client_name, int rx_queue_size)
static void session_reset_handler(session_reset_msg_t *mp)
Definition: quic_echo.c:1186
#define hash_unset(h, key)
Definition: hash.h:261
int i_am_master
Definition: quic_echo.h:169
transport_endpoint_t rmt
a
Definition: bitmap.h:538
static void handle_mq_event(session_event_t *e)
Definition: quic_echo.c:1217
Application add TLS key.
Definition: session.api:83
clib_spinlock_t sid_vpp_handles_lock
Definition: quic_echo.h:173
static void echo_disconnect_session(echo_session_t *s, u32 opaque)
Definition: quic_echo.c:331
int max_test_msg
Definition: quic_echo.h:203
static void echo_cleanup_session(echo_main_t *em, echo_session_t *s)
Definition: quic_echo.c:583
u8 use_sock_api
Flag that decides if socket, instead of svm, api is used to connect to vpp.
Definition: quic_echo.h:189
unsigned long u64
Definition: types.h:89
int my_client_index
All VLIB-side message handlers use my_client_index to identify the queue / client.
Definition: api_common.h:311
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
#define NULL
Definition: clib.h:58
static f64 clib_time_now(clib_time_t *c)
Definition: time.h:215
u32 tx_buf_size
Definition: quic_echo.h:197
static int app_send_stream(app_session_t *s, u8 *data, u32 len, u8 noblock)
for(i=1;i<=collision_buckets;i++)
int i
format_function_t format_ip46_address
Definition: format.h:61
int vl_socket_client_connect(char *socket_path, char *client_name, u32 socket_buffer_size)
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
volatile connection_state_t state
Definition: quic_echo.h:182
u8 start_event
Definition: quic_echo.h:234
static void vl_api_unbind_uri_reply_t_handler(vl_api_unbind_uri_reply_t *mp)
Definition: quic_echo.c:1509
static void print_global_json_stats(echo_main_t *em)
Definition: quic_echo.c:491
static void * echo_mq_thread_fn(void *arg)
Definition: quic_echo.c:1275
static void vl_api_application_attach_reply_t_handler(vl_api_application_attach_reply_t *mp)
Definition: quic_echo.c:1346
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
void * vl_msg_api_alloc(int nbytes)
static void vl_api_map_another_segment_t_handler(vl_api_map_another_segment_t *mp)
Definition: quic_echo.c:1446
unsigned char u8
Definition: types.h:56
static void vl_api_application_detach_reply_t_handler(vl_api_application_detach_reply_t *mp)
Definition: quic_echo.c:1424
static int ssvm_segment_attach(char *name, ssvm_segment_type_t type, int fd)
Definition: quic_echo.c:411
foreach_app_session_field u64 vpp_session_handle
Definition: quic_echo.h:66
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
double f64
Definition: types.h:142
u8 * format_api_error(u8 *s, va_list *args)
Definition: udp_echo.c:384
static const quic_echo_cb_vft_t server_stream_cb_vft
Definition: quic_echo.c:1118
static echo_session_t * echo_session_new(echo_main_t *em)
Definition: quic_echo.c:141
struct _svm_fifo svm_fifo_t
int connect_to_vpp(char *name)
Definition: quic_echo.c:438
blocking call, returns on signal or time-out - best used in combination with condvars, with eventfds we don&#39;t yield the cpu
Definition: queue.h:46
struct echo_main_t::@481 timing
void svm_region_exit(void)
Definition: svm.c:1224
u8 output_json
Definition: quic_echo.h:201
static void stop_signal(int signum)
Definition: quic_echo.c:431
enum ssvm_segment_type_ ssvm_segment_type_t
static void app_alloc_ctrl_evt_to_vpp(svm_msg_q_t *mq, app_session_evt_t *app_evt, u8 evt_type)
volatile u32 n_clients_connected
Definition: quic_echo.h:216
#define TIMEOUT
Definition: quic_echo.h:38
static void clib_mem_set_thread_index(void)
Definition: mem.h:64
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:493
static void echo_handle_data(echo_main_t *em, echo_session_t *s, u8 *rx_buf)
Definition: quic_echo.c:746
static void vl_api_unmap_segment_t_handler(vl_api_unmap_segment_t *mp)
Definition: quic_echo.c:1437
svm_msg_q_t * svm_msg_q_alloc(svm_msg_q_cfg_t *cfg)
Allocate message queue.
Definition: message_queue.c:40
volatile u64 bytes_received
Definition: quic_echo.h:69
#define ECHO_FAIL(_fmt, _args...)
Definition: quic_echo.h:44
#define always_inline
Definition: clib.h:98
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
Fifo max bytes to dequeue.
Definition: svm_fifo.h:518
u8 * appns_id
Definition: quic_echo.h:205
static const u32 test_srv_key_rsa_len
Definition: tls_test.h:77
u32 n_rx_threads
Definition: quic_echo.h:217
static void echo_free_sessions(echo_main_t *em)
Definition: quic_echo.c:558
static uword unformat_close(unformat_input_t *input, va_list *args)
Definition: quic_echo.c:57
static int app_send_io_evt_to_vpp(svm_msg_q_t *mq, u32 session_index, u8 evt_type, u8 noblock)
Send fifo io event to vpp worker thread.
clib_spinlock_t segment_handles_lock
Definition: quic_echo.h:176
static void session_bound_handler(session_bound_msg_t *mp)
Definition: quic_echo.c:847
vhost_vring_state_t state
Definition: vhost_user.h:146
connection_state_t
Definition: quic_echo.h:110
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
Definition: api_common.h:266
unsigned int u32
Definition: types.h:88
void quic_echo_process_opts(int argc, char **argv)
Definition: quic_echo.c:1669
u32 my_client_index
Definition: quic_echo.h:163
f64 start_time
Definition: quic_echo.h:231
void vl_msg_api_send_shmem(svm_queue_t *q, u8 *elem)
u32 fifo_size
Definition: quic_echo.h:195
char * segment_name
segment name
Definition: fifo_segment.h:68
int svm_msg_q_sub(svm_msg_q_t *mq, svm_msg_q_msg_t *msg, svm_q_conditional_wait_t cond, u32 time)
Consumer dequeue one message from queue.
u32 * data_thread_args
Definition: quic_echo.h:211
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:61
vl_api_fib_path_type_t type
Definition: fib_types.api:123
int fifo_segment_attach(fifo_segment_main_t *sm, fifo_segment_create_args_t *a)
Attach as slave to a fifo segment.
Definition: fifo_segment.c:99
vpp->client unmap shared memory segment
Definition: session.api:125
void vl_set_memory_root_path(const char *name)
static void echo_session_dequeue_notify(echo_session_t *s)
Definition: quic_echo.c:398
#define hash_get(h, key)
Definition: hash.h:249
quic_echo_cb_vft_t cb_vft
Definition: quic_echo.h:177
static void echo_on_accept_connect(session_accepted_msg_t *mp, u32 session_index)
Definition: quic_echo.c:1077
static void echo_check_closed_listener(echo_main_t *em, echo_session_t *s)
Definition: quic_echo.c:727
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
static void echo_segment_handle_add_del(echo_main_t *em, u64 segment_handle, u8 add)
Definition: quic_echo.c:183
volatile u32 n_quic_clients_connected
Definition: quic_echo.h:215
static void echo_event_didnt_happen(u8 e)
Definition: quic_echo.c:482
static void vl_api_bind_uri_reply_t_handler(vl_api_bind_uri_reply_t *mp)
Definition: quic_echo.c:1495
static void quic_echo_notify_event(echo_main_t *em, echo_test_evt_t e)
Definition: quic_echo.c:373
client->vpp, attach application to session layer
Definition: session.api:27
static echo_session_t * echo_get_session_from_handle(echo_main_t *em, u64 handle)
Definition: quic_echo.c:205
void quic_echo_api_hookup(echo_main_t *em)
Definition: quic_echo.c:1599
struct _unformat_input_t unformat_input_t
uword * session_index_by_vpp_handles
Definition: quic_echo.h:172
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
static int recv_data_chunk(echo_main_t *em, echo_session_t *s, u8 *rx_buf)
Definition: quic_echo.c:667
void unformat_init_command_line(unformat_input_t *input, char *argv[])
Definition: unformat.c:1013
u64 bytes_to_send
Definition: quic_echo.h:68
static void echo_assert_test_suceeded(echo_main_t *em)
Definition: quic_echo.c:385
static void vl_api_disconnect_session_reply_t_handler(vl_api_disconnect_session_reply_t *mp)
Definition: quic_echo.c:1524
static void vl_api_application_tls_cert_add_reply_t_handler(vl_api_application_tls_cert_add_reply_t *mp)
Definition: quic_echo.c:1547
#define PREDICT_FALSE(x)
Definition: clib.h:111
Unbind a given URI.
Definition: session.api:153
#define SESSION_INVALID_INDEX
Definition: session_types.h:22
static uword echo_unformat_timing_event(unformat_input_t *input, va_list *args)
Definition: quic_echo.c:72
static void server_run(echo_main_t *em)
Definition: quic_echo.c:1324
static const char test_srv_crt_rsa[]
Definition: tls_test.h:23
fifo_segment_main_t segment_main
Definition: quic_echo.h:179
void clib_time_init(clib_time_t *c)
Definition: time.c:178
u8 name[64]
Definition: memclnt.api:152
u8 events_sent
Definition: quic_echo.h:233
void application_detach(echo_main_t *em)
Definition: quic_echo.c:276
data_source_t data_source
Definition: quic_echo.h:198
u64 bytes_to_send
Definition: quic_echo.h:193
word fformat(FILE *f, char *fmt,...)
Definition: format.c:462
u8 len
Definition: ip_types.api:90
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:203
u8 test_return_packets
Definition: quic_echo.h:192
#define clib_atomic_sub_fetch(a, b)
Definition: atomics.h:31
#define ECHO_LOG(lvl, _fmt, _args...)
Definition: quic_echo.h:53
static void app_send_ctrl_evt_to_vpp(svm_msg_q_t *mq, app_session_evt_t *app_evt)
static void echo_session_prealloc(echo_main_t *em)
Definition: quic_echo.c:123
u32 segment_size
size of the segment
Definition: fifo_segment.h:66
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
Definition: svm_fifo.h:739
echo_session_t * sessions
Definition: quic_echo.h:165
static void echo_on_accept_error(session_accepted_msg_t *mp, u32 session_index)
Definition: quic_echo.c:1090
clib_error_t * vl_socket_client_recv_fd_msg(int fds[], int n_fds, u32 wait)
static u8 svm_fifo_needs_deq_ntf(svm_fifo_t *f, u32 n_last_deq)
Check if fifo needs dequeue notification.
Definition: svm_fifo.h:830
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
static int echo_send_rpc(echo_main_t *em, void *fp, void *arg, u32 opaque)
Definition: quic_echo.c:151
void vl_socket_client_disconnect(void)
#define CHECK(x)
static void svm_msg_q_unlock(svm_msg_q_t *mq)
Unlock message queue.
static const quic_echo_cb_vft_t default_cb_vft
Definition: quic_echo.c:1106
u64 appns_secret
Definition: quic_echo.h:207
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static void print_usage_and_exit(void)
Definition: quic_echo.c:1619
static void vl_api_application_tls_key_add_reply_t_handler(vl_api_application_tls_key_add_reply_t *mp)
Definition: quic_echo.c:1555
void fifo_segment_main_init(fifo_segment_main_t *sm, u64 baseva, u32 timeout_in_seconds)
Definition: fifo_segment.c:162
uword * shared_segment_handles
Definition: quic_echo.h:175
static void clients_run(echo_main_t *em)
Definition: quic_echo.c:1312
static void echo_initiate_qsession_close_no_stream(echo_main_t *em)
Definition: quic_echo.c:616
u8 * echo_format_timing_event(u8 *s, va_list *args)
Definition: quic_echo.c:95
static void echo_on_connected_connect(session_connected_msg_t *mp, u32 session_index)
Definition: quic_echo.c:1028
volatile u8 time_to_stop
Definition: quic_echo.h:183
#define HIGH_SEGMENT_BASEVA
Definition: svm_common.h:84
static void test_recv_bytes(echo_main_t *em, echo_session_t *s, u8 *rx_buf, u32 n_read)
Definition: quic_echo.c:645
blocking call - best used in combination with condvars, for eventfds we don&#39;t yield the cpu ...
Definition: queue.h:42
static int app_recv_stream(app_session_t *s, u8 *buf, u32 len)
int memfd_fd
fd for memfd segments
Definition: fifo_segment.h:67
Application attach reply.
Definition: session.api:50
svm_queue_t * vl_input_queue
Definition: memory_shared.h:84
teardown_stat_t reset_count
Definition: quic_echo.h:223
static int wait_for_segment_allocation(u64 segment_handle)
Definition: quic_echo.c:351
static uword unformat_data(unformat_input_t *input, va_list *args)
Definition: echo_common.c:113
static const char test_srv_key_rsa[]
Definition: tls_test.h:49
f64 end_time
Definition: quic_echo.h:232
#define hash_create(elts, value_bytes)
Definition: hash.h:696
#define uword_to_pointer(u, type)
Definition: types.h:136
#define ASSERT(truth)
static uword hash_elts(void *v)
Definition: hash.h:118
void svm_msg_q_add_and_unlock(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Producer enqueue one message to queue with mutex held.
static void echo_send_connect(u8 *uri, u32 opaque)
Definition: quic_echo.c:317
volatile u32 nxt_available_sidx
Definition: quic_echo.h:218
static void session_accepted_handler(session_accepted_msg_t *mp)
Definition: quic_echo.c:870
static void echo_on_connected_error(session_connected_msg_t *mp, u32 session_index)
Definition: quic_echo.c:1057
client->vpp, attach application to session layer
Definition: session.api:95
static void echo_on_accept_recv(session_accepted_msg_t *mp, u32 session_index)
Definition: quic_echo.c:1064
static void echo_on_accept_log_ip(session_accepted_msg_t *mp, u32 session_index)
Definition: quic_echo.c:1097
static void session_connected_handler(session_connected_msg_t *mp)
Definition: quic_echo.c:948
static uword echo_unformat_quic_setup_vft(unformat_input_t *input, va_list *args)
Definition: quic_echo.c:1131
static void svm_fifo_clear_deq_ntf(svm_fifo_t *f)
Clear the want notification flag and set has notification.
Definition: svm_fifo.h:797
vpp->client, please map an additional shared memory segment
Definition: session.api:110
static void init_error_string_table(vat_main_t *vam)
Definition: api_main.c:29
u32 n_clients
Definition: quic_echo.h:213
static void echo_session_handle_add_del(echo_main_t *em, u64 handle, u32 sid)
Definition: quic_echo.c:194
int main(int argc, char **argv)
Definition: quic_echo.c:1784
void svm_msg_q_set_consumer_eventfd(svm_msg_q_t *mq, int fd)
Set event fd for queue consumer.
#define clib_max(x, y)
Definition: clib.h:288
#define clib_atomic_fetch_add(a, b)
Definition: atomics.h:23
void(* echo_rpc_t)(void *arg, u32 opaque)
Definition: quic_echo.h:239
ssvm_segment_type_t segment_type
type of segment requested
Definition: fifo_segment.h:65
#define foreach_quic_echo_msg
Definition: quic_echo.c:1586
template key/value backing page structure
Definition: bihash_doc.h:44
bidirectional disconnect API
Definition: session.api:183
enum echo_test_evt_ echo_test_evt_t
u32 n_stream_clients
Definition: quic_echo.h:214
teardown_stat_t close_count
Definition: quic_echo.h:224
static void session_disconnected_handler(session_disconnected_msg_t *mp)
Definition: quic_echo.c:1150
struct _quic_echo_cb_vft quic_echo_cb_vft_t
#define API_SOCKET_FILE
Definition: socket_api.h:25
void svm_msg_q_free_msg(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Free message buffer.
struct echo_main_t::@480 stats
volatile u64 bytes_to_receive
Definition: quic_echo.h:70
svm_msg_q_t * our_event_queue
Definition: quic_echo.h:166
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Bind to a given URI.
Definition: session.api:139
void application_send_attach(echo_main_t *em)
Definition: quic_echo.c:226
static void session_print_stats(echo_main_t *em, echo_session_t *session)
Definition: quic_echo.c:472
u64 rx_total
Definition: quic_echo.h:222
u8 * connect_test_data
Definition: quic_echo.h:191
u64 uword
Definition: types.h:112
teardown_stat_t active_count
Definition: quic_echo.h:225
u64 appns_flags
Definition: quic_echo.h:206
static void echo_on_connected_send(session_connected_msg_t *mp, u32 session_index)
Definition: quic_echo.c:1044
svm_msg_q_t * rpc_msq_queue
Definition: quic_echo.h:178
u64 tx_total
Definition: quic_echo.h:221
void vl_client_disconnect_from_vlib(void)
Application add TLS certificate.
Definition: session.api:69
u8 * format_quic_echo_state(u8 *s, va_list *args)
Definition: quic_echo.c:35
static int send_data_chunk(echo_session_t *s, u8 *tx_buf, int offset, int len)
Definition: quic_echo.c:685
#define vec_foreach(var, vec)
Vector iterator.
static void echo_update_count_on_session_close(echo_main_t *em, echo_session_t *s)
Definition: quic_echo.c:710
transport_endpoint_t lcl
Connect to a given URI.
Definition: session.api:169
pthread_t * data_thread_handles
Definition: quic_echo.h:209
static void vl_api_connect_uri_reply_t_handler(vl_api_connect_uri_reply_t *mp)
Definition: quic_echo.c:1562
static void server_send_unbind(echo_main_t *em)
Definition: quic_echo.c:303
static void echo_process_rpcs(echo_main_t *em)
Definition: quic_echo.c:1260
svm_queue_t * vl_input_queue
Definition: quic_echo.h:162
bidirectional disconnect reply API
Definition: session.api:196
u8 send_quic_disconnects
Definition: quic_echo.h:199
void * clib_mem_init_thread_safe(void *memory, uword memory_size)
Definition: mem_dlmalloc.c:226
u32 rx_buf_size
Definition: quic_echo.h:196
static int svm_msg_q_lock(svm_msg_q_t *mq)
Lock, or block trying, the message queue.
static int mirror_data_chunk(echo_main_t *em, echo_session_t *s, u8 *tx_buf, u64 len)
Definition: quic_echo.c:701
static void print_global_stats(echo_main_t *em)
Definition: quic_echo.c:522
api_main_t api_main
Definition: api_shared.c:35
echo_main_t echo_main
Definition: quic_echo.c:26
svm_msg_q_msg_t svm_msg_q_alloc_msg_w_ring(svm_msg_q_t *mq, u32 ring_index)
Allocate message buffer on ring.
u8 send_stream_disconnects
Definition: quic_echo.h:200
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static const u32 test_srv_crt_rsa_len
Definition: tls_test.h:47
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
u32 * new_segment_indices
return vec of new seg indices
Definition: fifo_segment.h:69
u64 bytes_to_receive
Definition: quic_echo.h:194
u8 * socket_name
Definition: quic_echo.h:168