FD.io VPP  v21.01.1
Vector Packet Processing
vcl_test_server.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-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 <unistd.h>
17 #include <errno.h>
18 #include <sys/types.h>
19 #include <sys/socket.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <time.h>
23 #include <ctype.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <hs_apps/vcl/vcl_test.h>
27 #include <sys/epoll.h>
28 #include <vppinfra/mem.h>
29 #include <pthread.h>
30 
31 typedef struct
32 {
33  uint8_t is_alloc;
34  int fd;
35  uint8_t *buf;
36  uint32_t buf_size;
39  vppcom_endpt_t endpt;
40  uint8_t ip[16];
41  vppcom_data_segment_t ds[2];
43 
44 typedef struct
45 {
46  uint16_t port;
47  uint32_t address_ip6;
50  vppcom_endpt_t endpt;
52 
53 typedef struct
54 {
55  uint32_t wrk_index;
56  int listen_fd;
57  int epfd;
58  struct epoll_event wait_events[VCL_TEST_CFG_MAX_EPOLL_EVENTS];
61  int nfds;
62  pthread_t thread_handle;
64 
65 typedef struct
66 {
69 
70  struct sockaddr_storage servaddr;
71  volatile int worker_fails;
72  volatile int active_workers;
75 
76 static __thread int __wrk_index = 0;
77 
79 
80 static inline void
81 conn_pool_expand (vcl_test_server_worker_t * wrk, size_t expand_size)
82 {
83  vcl_test_server_conn_t *conn_pool;
84  size_t new_size = wrk->conn_pool_size + expand_size;
85  int i;
86 
87  conn_pool = realloc (wrk->conn_pool, new_size * sizeof (*wrk->conn_pool));
88  if (conn_pool)
89  {
90  for (i = wrk->conn_pool_size; i < new_size; i++)
91  {
92  vcl_test_server_conn_t *conn = &conn_pool[i];
93  memset (conn, 0, sizeof (*conn));
94  vcl_test_cfg_init (&conn->cfg);
95  vcl_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
96  &conn->buf, &conn->buf_size);
97  conn->cfg.txbuf_size = conn->cfg.rxbuf_size;
98  }
99 
100  wrk->conn_pool = conn_pool;
101  wrk->conn_pool_size = new_size;
102  }
103  else
104  {
105  vterr ("conn_pool_expand()", -errno);
106  }
107 }
108 
109 static inline vcl_test_server_conn_t *
111 {
112  int i, expand = 0;
113 
114 again:
115  for (i = 0; i < wrk->conn_pool_size; i++)
116  {
117  if (!wrk->conn_pool[i].is_alloc)
118  {
119  wrk->conn_pool[i].endpt.ip = wrk->conn_pool[i].ip;
120  wrk->conn_pool[i].is_alloc = 1;
121  return (&wrk->conn_pool[i]);
122  }
123  }
124 
125  if (expand == 0)
126  {
127  conn_pool_expand (wrk, 2 * wrk->conn_pool_size);
128  expand = 1;
129  goto again;
130  }
131  vtwrn ("Failed to allocate connection even after expand");
132  return 0;
133 }
134 
135 static inline void
137 {
138  conn->fd = 0;
139  conn->is_alloc = 0;
140 }
141 
142 static inline void
144 {
145  conn->cfg = *rx_cfg;
146  vcl_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
147  &conn->buf, &conn->buf_size);
148  conn->cfg.txbuf_size = conn->cfg.rxbuf_size;
149 
150  if (conn->cfg.verbose)
151  {
152  vtinf ("(fd %d): Replying to cfg message!\n", conn->fd);
153  vcl_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
154  }
155  (void) vcl_test_write (conn->fd, (uint8_t *) & conn->cfg,
156  sizeof (conn->cfg), NULL, conn->cfg.verbose);
157 }
158 
159 static void
161  vcl_test_server_conn_t * conn, vcl_test_cfg_t * rx_cfg)
162 {
163  u8 is_bi = rx_cfg->test == VCL_TEST_TYPE_BI;
165  char buf[64];
166  int i;
167 
168  if (rx_cfg->ctrl_handle == conn->fd)
169  {
170  for (i = 0; i < wrk->conn_pool_size; i++)
171  {
172  tc = &wrk->conn_pool[i];
173  if (tc->cfg.ctrl_handle != conn->fd)
174  continue;
175 
176  vcl_test_stats_accumulate (&conn->stats, &tc->stats);
177  if (vcl_comp_tspec (&conn->stats.stop, &tc->stats.stop) < 0)
178  conn->stats.stop = tc->stats.stop;
179  /* Client delays sending of disconnect */
180  conn->stats.stop.tv_sec -= VCL_TEST_DELAY_DISCONNECT;
181  if (conn->cfg.verbose)
182  {
183  snprintf (buf, sizeof (buf), "SERVER (fd %d) RESULTS", tc->fd);
184  vcl_test_stats_dump (buf, &tc->stats, 1 /* show_rx */ ,
185  is_bi /* show tx */ , conn->cfg.verbose);
186  }
187  }
188 
189  vcl_test_stats_dump ("SERVER RESULTS", &conn->stats, 1 /* show_rx */ ,
190  is_bi /* show_tx */ , conn->cfg.verbose);
191  vcl_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
192  if (conn->cfg.verbose)
193  {
194  vtinf (" vcl server main\n"
196  " buf: %p\n"
197  " buf size: %u (0x%08x)\n"
199  conn->buf, conn->buf_size, conn->buf_size);
200  }
201 
202  sync_config_and_reply (conn, rx_cfg);
203  memset (&conn->stats, 0, sizeof (conn->stats));
204  }
205  else
206  {
207  if (rx_cfg->ctrl_handle == ~0)
208  {
209  rx_cfg->ctrl_handle = conn->fd;
210  vtinf ("Set control fd %d for test!", conn->fd);
211  }
212  else
213  {
214  vtinf ("Starting %s-directional Stream Test (fd %d)!",
215  is_bi ? "Bi" : "Uni", conn->fd);
216  }
217 
218  sync_config_and_reply (conn, rx_cfg);
219 
220  /* read the 1st chunk, record start time */
221  memset (&conn->stats, 0, sizeof (conn->stats));
222  clock_gettime (CLOCK_REALTIME, &conn->stats.start);
223  }
224 }
225 
226 static inline void
227 vts_server_rx (vcl_test_server_conn_t * conn, int rx_bytes)
228 {
230  int client_fd = conn->fd;
231 
232  if (conn->cfg.test == VCL_TEST_TYPE_BI)
233  {
234  if (vsm->use_ds)
235  {
236  (void) vcl_test_write (client_fd, conn->ds[0].data, conn->ds[0].len,
237  &conn->stats, conn->cfg.verbose);
238  if (conn->ds[1].len)
239  (void) vcl_test_write (client_fd, conn->ds[1].data,
240  conn->ds[1].len, &conn->stats,
241  conn->cfg.verbose);
242  }
243  else
244  (void) vcl_test_write (client_fd, conn->buf, rx_bytes, &conn->stats,
245  conn->cfg.verbose);
246  }
247 
248  if (vsm->use_ds)
249  vppcom_session_free_segments (conn->fd, rx_bytes);
250 
251  if (conn->stats.rx_bytes >= conn->cfg.total_bytes)
252  clock_gettime (CLOCK_REALTIME, &conn->stats.stop);
253 }
254 
255 static void
256 vts_copy_ds (void *buf, vppcom_data_segment_t * ds, u32 max_bytes)
257 {
258  uint32_t n_bytes = 0, ds_idx = 0, to_copy;
259 
260  while (n_bytes < max_bytes)
261  {
262  to_copy = clib_min (ds[ds_idx].len, max_bytes - n_bytes);
263  clib_memcpy_fast (buf + n_bytes, ds[ds_idx].data, to_copy);
264  n_bytes += to_copy;
265  ds_idx += 1;
266  }
267 }
268 
269 static void
271 {
273  int tx_bytes, nbytes, pos;
274 
275  if (vsm->use_ds)
276  vts_copy_ds (conn->buf, conn->ds, rx_bytes);
277 
278  /* If it looks vaguely like a string, make sure it's terminated */
279  pos = rx_bytes < conn->buf_size ? rx_bytes : conn->buf_size - 1;
280  ((char *) conn->buf)[pos] = 0;
281  vtinf ("(fd %d): RX (%d bytes) - '%s'", conn->fd, rx_bytes, conn->buf);
282 
283  if (conn->cfg.verbose)
284  vtinf ("(fd %d): Echoing back", conn->fd);
285 
286  nbytes = strlen ((const char *) conn->buf) + 1;
287  tx_bytes = vcl_test_write (conn->fd, conn->buf, nbytes, &conn->stats,
288  conn->cfg.verbose);
289  if (tx_bytes >= 0)
290  vtinf ("(fd %d): TX (%d bytes) - '%s'", conn->fd, tx_bytes, conn->buf);
291 }
292 
293 static void
295 {
297  struct epoll_event ev;
298  int rv, client_fd;
299 
300  conn = conn_pool_alloc (wrk);
301  if (!conn)
302  {
303  vtwrn ("No free connections!");
304  return;
305  }
306 
307  client_fd = vppcom_session_accept (listen_fd, &conn->endpt, 0);
308  if (client_fd < 0)
309  {
310  vterr ("vppcom_session_accept()", client_fd);
311  return;
312  }
313  conn->fd = client_fd;
314 
315  vtinf ("Got a connection -- fd = %d (0x%08x) on listener fd = %d (0x%08x)",
316  client_fd, client_fd, listen_fd, listen_fd);
317 
318  ev.events = EPOLLIN;
319  ev.data.u64 = conn - wrk->conn_pool;
320  rv = vppcom_epoll_ctl (wrk->epfd, EPOLL_CTL_ADD, client_fd, &ev);
321  if (rv < 0)
322  {
323  vterr ("vppcom_epoll_ctl()", rv);
324  return;
325  }
326  wrk->nfds++;
327 }
328 
329 static void
331 {
332  fprintf (stderr,
333  "vcl_test_server [OPTIONS] <port>\n"
334  " OPTIONS\n"
335  " -h Print this message and exit.\n"
336  " -6 Use IPv6\n"
337  " -w <num> Number of workers\n"
338  " -p <PROTO> Use <PROTO> transport layer\n"
339  " -D Use UDP transport layer\n"
340  " -L Use TLS transport layer\n");
341  exit (1);
342 }
343 
344 static void
346 {
347  struct sockaddr_storage *servaddr = &vsm->servaddr;
348  memset (servaddr, 0, sizeof (*servaddr));
349 
350  if (vsm->cfg.address_ip6)
351  {
352  struct sockaddr_in6 *server_addr = (struct sockaddr_in6 *) servaddr;
353  server_addr->sin6_family = AF_INET6;
354  server_addr->sin6_addr = in6addr_any;
355  server_addr->sin6_port = htons (vsm->cfg.port);
356  }
357  else
358  {
359  struct sockaddr_in *server_addr = (struct sockaddr_in *) servaddr;
360  server_addr->sin_family = AF_INET;
361  server_addr->sin_addr.s_addr = htonl (INADDR_ANY);
362  server_addr->sin_port = htons (vsm->cfg.port);
363  }
364 
365  if (vsm->cfg.address_ip6)
366  {
367  struct sockaddr_in6 *server_addr = (struct sockaddr_in6 *) servaddr;
368  vsm->cfg.endpt.is_ip4 = 0;
369  vsm->cfg.endpt.ip = (uint8_t *) & server_addr->sin6_addr;
370  vsm->cfg.endpt.port = (uint16_t) server_addr->sin6_port;
371  }
372  else
373  {
374  struct sockaddr_in *server_addr = (struct sockaddr_in *) servaddr;
375  vsm->cfg.endpt.is_ip4 = 1;
376  vsm->cfg.endpt.ip = (uint8_t *) & server_addr->sin_addr;
377  vsm->cfg.endpt.port = (uint16_t) server_addr->sin_port;
378  }
379 }
380 
381 static void
383  char **argv)
384 {
385  int v, c;
386 
387  vsm->cfg.proto = VPPCOM_PROTO_TCP;
388 
389  opterr = 0;
390  while ((c = getopt (argc, argv, "6DLsw:hp:")) != -1)
391  switch (c)
392  {
393  case '6':
394  vsm->cfg.address_ip6 = 1;
395  break;
396 
397  case 'p':
398  if (vppcom_unformat_proto (&vsm->cfg.proto, optarg))
399  vtwrn ("Invalid vppcom protocol %s, defaulting to TCP", optarg);
400  break;
401 
402  case 'D':
403  vsm->cfg.proto = VPPCOM_PROTO_UDP;
404  break;
405 
406  case 'L':
407  vsm->cfg.proto = VPPCOM_PROTO_TLS;
408  break;
409 
410  case 'w':
411  v = atoi (optarg);
412  if (v > 1)
413  vsm->cfg.workers = v;
414  else
415  vtwrn ("Invalid number of workers %d", v);
416  break;
417  case 's':
418  vsm->use_ds = 1;
419  break;
420  case '?':
421  switch (optopt)
422  {
423  case 'w':
424  case 'p':
425  vtwrn ("Option `-%c' requires an argument.", optopt);
426  break;
427  default:
428  if (isprint (optopt))
429  vtwrn ("Unknown option `-%c'.", optopt);
430  else
431  vtwrn ("Unknown option character `\\x%x'.", optopt);
432  }
433  /* fall thru */
434  case 'h':
435  default:
437  }
438 
439  if (argc < (optind + 1))
440  {
441  fprintf (stderr, "SERVER: ERROR: Insufficient number of arguments!\n");
443  }
444 
445  if (sscanf (argv[optind], "%d", &v) == 1)
446  vsm->cfg.port = (uint16_t) v;
447  else
448  {
449  fprintf (stderr, "SERVER: ERROR: Invalid port (%s)!\n", argv[optind]);
451  }
452 
454 }
455 
456 static void
458  int listener_fd)
459 {
460  if ((vppcom_session_n_accepted (listener_fd) == 0) &
461  vppcom_session_is_connectable_listener (listener_fd))
462  {
463  vtinf ("Connected Listener fd %x has no more sessions", listener_fd);
464  vppcom_session_close (listener_fd);
465  wrk->nfds--;
466  }
467 }
468 
469 int
471  vcl_test_server_conn_t * conn, int rx_bytes)
472 {
473  int listener_fd;
474  if (rx_cfg->verbose)
475  {
476  vtinf ("(fd %d): Received a cfg msg!", conn->fd);
477  vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
478  }
479 
480  if (rx_bytes != sizeof (*rx_cfg))
481  {
482  vtinf ("(fd %d): Invalid cfg msg size %d expected %lu!", conn->fd,
483  rx_bytes, sizeof (*rx_cfg));
484  conn->cfg.rxbuf_size = 0;
485  conn->cfg.num_writes = 0;
486  if (conn->cfg.verbose)
487  {
488  vtinf ("(fd %d): Replying to cfg msg", conn->fd);
489  vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
490  }
491  vcl_test_write (conn->fd, (uint8_t *) & conn->cfg,
492  sizeof (conn->cfg), NULL, conn->cfg.verbose);
493  return -1;
494  }
495 
496  switch (rx_cfg->test)
497  {
498  case VCL_TEST_TYPE_NONE:
499  case VCL_TEST_TYPE_ECHO:
500  sync_config_and_reply (conn, rx_cfg);
501  break;
502 
503  case VCL_TEST_TYPE_BI:
504  case VCL_TEST_TYPE_UNI:
505  vts_server_start_stop (wrk, conn, rx_cfg);
506  break;
507 
508  case VCL_TEST_TYPE_EXIT:
509  vtinf ("Session fd %d closing!", conn->fd);
510  clock_gettime (CLOCK_REALTIME, &conn->stats.stop);
511  listener_fd = vppcom_session_listener (conn->fd);
512  vppcom_session_close (conn->fd);
513  conn_pool_free (conn);
514  wrk->nfds--;
515  vts_clean_connected_listeners (wrk, listener_fd);
516  break;
517 
518  default:
519  vtwrn ("Unknown test type %d", rx_cfg->test);
520  vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
521  break;
522  }
523 
524  return 0;
525 }
526 
527 static void
529 {
531  struct epoll_event listen_ev;
532  int rv;
533 
534  __wrk_index = wrk->wrk_index;
535 
536  vtinf ("Initializing worker ...");
537 
539  if (wrk->wrk_index)
540  if (vppcom_worker_register ())
541  vtfail ("vppcom_worker_register()", 1);
542 
543  wrk->listen_fd = vppcom_session_create (vsm->cfg.proto,
544  0 /* is_nonblocking */ );
545  if (wrk->listen_fd < 0)
546  vtfail ("vppcom_session_create()", wrk->listen_fd);
547 
548  if (vsm->cfg.proto == VPPCOM_PROTO_UDP)
549  {
550  vppcom_session_attr (wrk->listen_fd, VPPCOM_ATTR_SET_CONNECTED, 0, 0);
551  }
552 
553  if (vsm->cfg.proto == VPPCOM_PROTO_TLS
554  || vsm->cfg.proto == VPPCOM_PROTO_QUIC)
555  {
556  vppcom_session_tls_add_cert (wrk->listen_fd, vcl_test_crt_rsa,
558  vppcom_session_tls_add_key (wrk->listen_fd, vcl_test_key_rsa,
560  }
561 
562  rv = vppcom_session_bind (wrk->listen_fd, &vsm->cfg.endpt);
563  if (rv < 0)
564  vtfail ("vppcom_session_bind()", rv);
565 
566  if (!(vsm->cfg.proto == VPPCOM_PROTO_UDP))
567  {
568  rv = vppcom_session_listen (wrk->listen_fd, 10);
569  if (rv < 0)
570  vtfail ("vppcom_session_listen()", rv);
571  }
572 
573  wrk->epfd = vppcom_epoll_create ();
574  if (wrk->epfd < 0)
575  vtfail ("vppcom_epoll_create()", wrk->epfd);
576 
577  listen_ev.events = EPOLLIN;
578  listen_ev.data.u32 = ~0;
579  rv = vppcom_epoll_ctl (wrk->epfd, EPOLL_CTL_ADD, wrk->listen_fd,
580  &listen_ev);
581  if (rv < 0)
582  vtfail ("vppcom_epoll_ctl", rv);
583 
584  vsm->active_workers += 1;
585  vtinf ("Waiting for a client to connect on port %d ...", vsm->cfg.port);
586 }
587 
588 static int
590 {
591  if (conn->cfg.test == VCL_TEST_TYPE_ECHO)
592  return 1;
593 
594  return (conn->stats.rx_bytes < 128
595  || conn->stats.rx_bytes > conn->cfg.total_bytes);
596 }
597 
598 static vcl_test_cfg_t *
600 {
602 
603  if (vsm->use_ds)
604  {
605  /* We could avoid the copy if the first segment is big enough but this
606  * just simplifies things */
607  vts_copy_ds (conn->buf, conn->ds, sizeof (vcl_test_cfg_t));
608  }
609  return (vcl_test_cfg_t *) conn->buf;
610 }
611 
612 static inline int
614 {
616  if (vsm->use_ds)
617  return vcl_test_read_ds (conn->fd, conn->ds, &conn->stats);
618  else
619  return vcl_test_read (conn->fd, conn->buf, conn->buf_size, &conn->stats);
620 }
621 
622 static inline int
624 {
626 
627  if (vsm->use_ds)
628  return isascii (conn->ds[0].data[0]);
629  else
630  return isascii (conn->buf[0]);
631 }
632 
633 static void *
634 vts_worker_loop (void *arg)
635 {
637  vcl_test_server_worker_t *wrk = arg;
639  int i, rx_bytes, num_ev, listener_fd;
640  vcl_test_cfg_t *rx_cfg;
641 
642  if (wrk->wrk_index)
643  vts_worker_init (wrk);
644 
645  while (1)
646  {
647  num_ev = vppcom_epoll_wait (wrk->epfd, wrk->wait_events,
649  if (num_ev < 0)
650  {
651  vterr ("vppcom_epoll_wait()", num_ev);
652  goto fail;
653  }
654  else if (num_ev == 0)
655  {
656  vtinf ("vppcom_epoll_wait() timeout!");
657  continue;
658  }
659  for (i = 0; i < num_ev; i++)
660  {
661  conn = &wrk->conn_pool[wrk->wait_events[i].data.u32];
662  if (wrk->wait_events[i].events & (EPOLLHUP | EPOLLRDHUP))
663  {
664  vtinf ("Closing session %d on HUP", conn->fd);
665  listener_fd = vppcom_session_listener (conn->fd);
666  vppcom_session_close (conn->fd);
667  wrk->nfds--;
668  vts_clean_connected_listeners (wrk, listener_fd);
669  if (!wrk->nfds)
670  {
671  vtinf ("All client connections closed\n");
672  goto done;
673  }
674  continue;
675  }
676  if (wrk->wait_events[i].data.u32 == ~0)
677  {
678  vts_new_client (wrk, wrk->listen_fd);
679  continue;
680  }
681  else if (vppcom_session_is_connectable_listener (conn->fd))
682  {
683  vts_new_client (wrk, conn->fd);
684  continue;
685  }
686 
687  if (EPOLLIN & wrk->wait_events[i].events)
688  {
689  read_again:
690  rx_bytes = vts_conn_read (conn);
691 
692  if (rx_bytes <= 0)
693  {
694  if (errno == ECONNRESET)
695  {
696  vtinf ("Connection reset by remote peer.\n");
697  goto fail;
698  }
699  else
700  continue;
701  }
702 
703  if (vts_conn_expect_config (conn))
704  {
705  rx_cfg = vts_conn_read_config (conn);
706  if (rx_cfg->magic == VCL_TEST_CFG_CTRL_MAGIC)
707  {
708  if (vsm->use_ds)
709  vppcom_session_free_segments (conn->fd, rx_bytes);
710  vts_handle_cfg (wrk, rx_cfg, conn, rx_bytes);
711  if (!wrk->nfds)
712  {
713  vtinf ("All client connections closed\n");
714  goto done;
715  }
716  continue;
717  }
718  }
719  if ((conn->cfg.test == VCL_TEST_TYPE_UNI)
720  || (conn->cfg.test == VCL_TEST_TYPE_BI))
721  {
722  vts_server_rx (conn, rx_bytes);
723  if (vppcom_session_attr (conn->fd, VPPCOM_ATTR_GET_NREAD, 0,
724  0) > 0)
725  goto read_again;
726  continue;
727  }
728  if (vts_conn_has_ascii (conn))
729  {
730  vts_server_echo (conn, rx_bytes);
731  }
732  else
733  {
734  vtwrn ("FIFO not drained! extra bytes %d", rx_bytes);
735  }
736  }
737  else
738  {
739  vtwrn ("Unhandled event");
740  goto fail;
741  }
742  }
743  }
744 
745 fail:
746  vsm->worker_fails -= 1;
747 
748 done:
749  vppcom_session_close (wrk->listen_fd);
750  if (wrk->conn_pool)
751  free (wrk->conn_pool);
752  vsm->active_workers -= 1;
753  return 0;
754 }
755 
756 int
757 main (int argc, char **argv)
758 {
760  int rv, i;
761 
762  clib_mem_init_thread_safe (0, 64 << 20);
764  vsm->cfg.workers = 1;
765  vsm->active_workers = 0;
766  vcl_test_server_process_opts (vsm, argc, argv);
767 
768  rv = vppcom_app_create ("vcl_test_server");
769  if (rv)
770  vtfail ("vppcom_app_create()", rv);
771 
772  vsm->workers = calloc (vsm->cfg.workers, sizeof (*vsm->workers));
773  vts_worker_init (&vsm->workers[0]);
774  for (i = 1; i < vsm->cfg.workers; i++)
775  {
776  vsm->workers[i].wrk_index = i;
777  rv = pthread_create (&vsm->workers[i].thread_handle, NULL,
778  vts_worker_loop, (void *) &vsm->workers[i]);
779  }
780  vts_worker_loop (&vsm->workers[0]);
781 
782  while (vsm->active_workers > 0)
783  ;
784 
785  vppcom_app_destroy ();
786  free (vsm->workers);
787 
788  return vsm->worker_fails;
789 }
790 
791 /*
792  * fd.io coding-style-patch-verification: ON
793  *
794  * Local Variables:
795  * eval: (c-set-style "gnu")
796  * End:
797  */
int vts_handle_cfg(vcl_test_server_worker_t *wrk, vcl_test_cfg_t *rx_cfg, vcl_test_server_conn_t *conn, int rx_bytes)
static void conn_pool_free(vcl_test_server_conn_t *conn)
static int vts_conn_has_ascii(vcl_test_server_conn_t *conn)
#define clib_min(x, y)
Definition: clib.h:328
struct sockaddr_storage servaddr
uint32_t vcl_test_crt_rsa_len
Definition: vcl_test.h:154
struct timespec stop
Definition: vcl_test.h:111
Optimized string handling code, including c11-compliant "safe C library" variants.
static void sync_config_and_reply(vcl_test_server_conn_t *conn, vcl_test_cfg_t *rx_cfg)
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
vppcom_endpt_t endpt
static int vcl_test_read_ds(int fd, vppcom_data_segment_t *ds, vcl_test_stats_t *stats)
Definition: vcl_test.h:447
static void vcl_test_server_process_opts(vcl_test_server_main_t *vsm, int argc, char **argv)
struct epoll_event wait_events[VCL_TEST_CFG_MAX_EPOLL_EVENTS]
vppcom_data_segment_t ds[2]
static int vts_conn_read(vcl_test_server_conn_t *conn)
static void conn_pool_expand(vcl_test_server_worker_t *wrk, size_t expand_size)
#define VCL_TEST_DELAY_DISCONNECT
Definition: vcl_test.h:70
unsigned char u8
Definition: types.h:56
#define VCL_TEST_SERVER_PORT
Definition: vcl_test.h:59
u8 data[128]
Definition: ipsec_types.api:90
struct timespec start
Definition: vcl_test.h:110
uint64_t num_writes
Definition: vcl_test.h:96
static void print_usage_and_exit(void)
static void vts_server_echo(vcl_test_server_conn_t *conn, int rx_bytes)
uint64_t txbuf_size
Definition: vcl_test.h:95
static void vcl_test_stats_dump(char *header, vcl_test_stats_t *stats, uint8_t show_rx, uint8_t show_tx, uint8_t verbose)
Definition: vcl_test.h:326
unsigned int u32
Definition: types.h:88
#define vterr(_fn, _rv)
Definition: vcl_test.h:33
static vcl_test_server_main_t vcl_server_main
static void * vts_worker_loop(void *arg)
char vcl_test_key_rsa[]
Definition: vcl_test.h:156
#define VCL_TEST_CFG_MAX_EPOLL_EVENTS
Definition: vcl_test.h:68
uint32_t verbose
Definition: vcl_test.h:91
#define VCL_TEST_SEPARATOR_STRING
Definition: vcl_test.h:71
static void vcl_test_cfg_dump(vcl_test_cfg_t *cfg, uint8_t is_client)
Definition: vcl_test.h:288
static void vts_server_rx(vcl_test_server_conn_t *conn, int rx_bytes)
#define VCL_TEST_CFG_CTRL_MAGIC
Definition: vcl_test.h:62
static void vts_new_client(vcl_test_server_worker_t *wrk, int listen_fd)
u8 len
Definition: ip_types.api:103
static void vts_server_start_stop(vcl_test_server_worker_t *wrk, vcl_test_server_conn_t *conn, vcl_test_cfg_t *rx_cfg)
static void vts_worker_init(vcl_test_server_worker_t *wrk)
svmdb_client_t * c
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
vcl_test_server_cfg_t cfg
uint64_t rxbuf_size
Definition: vcl_test.h:94
static void vcl_test_cfg_init(vcl_test_cfg_t *cfg)
Definition: vcl_test.h:200
vcl_test_stats_t stats
char vcl_test_crt_rsa[]
Definition: vcl_test.h:130
void free(void *p)
Definition: mem.c:42
vcl_test_server_conn_t * conn_pool
uint32_t magic
Definition: vcl_test.h:84
#define vtinf(_fmt, _args...)
Definition: vcl_test.h:42
static void vcl_test_buf_alloc(vcl_test_cfg_t *cfg, uint8_t is_rxbuf, uint8_t **buf, uint32_t *bufsize)
Definition: vcl_test.h:229
static vcl_test_cfg_t * vts_conn_read_config(vcl_test_server_conn_t *conn)
static int vcl_test_read(int fd, uint8_t *buf, uint32_t nbytes, vcl_test_stats_t *stats)
Definition: vcl_test.h:407
uint32_t ctrl_handle
Definition: vcl_test.h:87
int main(int argc, char **argv)
void * realloc(void *p, size_t size)
Definition: mem.c:67
static int vcl_test_write(int fd, uint8_t *buf, uint32_t nbytes, vcl_test_stats_t *stats, uint32_t verbose)
Definition: vcl_test.h:485
uint32_t vcl_test_key_rsa_len
Definition: vcl_test.h:184
vl_api_address_t ip
Definition: l2.api:501
static vcl_test_server_conn_t * conn_pool_alloc(vcl_test_server_worker_t *wrk)
void * calloc(size_t nmemb, size_t size)
Definition: mem.c:54
static void vts_clean_connected_listeners(vcl_test_server_worker_t *wrk, int listener_fd)
uint32_t test
Definition: vcl_test.h:86
static int vcl_comp_tspec(struct timespec *a, struct timespec *b)
Definition: vcl_test.h:392
static void vcl_test_stats_accumulate(vcl_test_stats_t *accum, vcl_test_stats_t *incr)
Definition: vcl_test.h:187
vcl_test_server_worker_t * workers
#define vtfail(_fn, _rv)
Definition: vcl_test.h:25
static void vts_copy_ds(void *buf, vppcom_data_segment_t *ds, u32 max_bytes)
static void vcl_test_init_endpoint_addr(vcl_test_server_main_t *vsm)
void * clib_mem_init_thread_safe(void *memory, uword memory_size)
Definition: mem_dlmalloc.c:280
volatile int active_workers
uint64_t rx_bytes
Definition: vcl_test.h:103
uint64_t total_bytes
Definition: vcl_test.h:97
#define VCL_TEST_CFG_MAX_TEST_SESS
Definition: vcl_test.h:67
#define vtwrn(_fmt, _args...)
Definition: vcl_test.h:39
static int vts_conn_expect_config(vcl_test_server_conn_t *conn)