FD.io VPP  v18.01.2-1-g9b554f3
Vector Packet Processing
builtin_client.c
Go to the documentation of this file.
1 /*
2  * builtin_client.c - vpp built-in tcp client/connect code
3  *
4  * Copyright (c) 2017 by Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
21 
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 #include <vpp/app/version.h>
25 
27 
28 #define TCP_BUILTIN_CLIENT_DBG (0)
29 
30 static void
32 {
34  ASSERT (vlib_get_thread_index () == 0);
36 }
37 
38 static void
40 {
41  if (vlib_get_thread_index () != 0)
43  sizeof (code));
44  else
45  signal_evt_to_cli_i (&code);
46 }
47 
48 static void
50 {
51  u8 *test_data = tm->connect_test_data;
52  int test_buf_offset;
53  u32 bytes_this_chunk;
54  session_fifo_event_t evt;
55  svm_fifo_t *txf;
56  int rv;
57 
58  ASSERT (vec_len (test_data) > 0);
59 
60  test_buf_offset = s->bytes_sent % vec_len (test_data);
61  bytes_this_chunk = vec_len (test_data) - test_buf_offset;
62 
63  bytes_this_chunk = bytes_this_chunk < s->bytes_to_send
64  ? bytes_this_chunk : s->bytes_to_send;
65 
66  txf = s->server_tx_fifo;
67  rv = svm_fifo_enqueue_nowait (txf, bytes_this_chunk,
68  test_data + test_buf_offset);
69 
70  /* If we managed to enqueue data... */
71  if (rv > 0)
72  {
73  /* Account for it... */
74  s->bytes_to_send -= rv;
75  s->bytes_sent += rv;
76 
78  {
79  /* *INDENT-OFF* */
80  ELOG_TYPE_DECLARE (e) =
81  {
82  .format = "tx-enq: xfer %d bytes, sent %u remain %u",
83  .format_args = "i4i4i4",
84  };
85  /* *INDENT-ON* */
86  struct
87  {
88  u32 data[3];
89  } *ed;
91  ed->data[0] = rv;
92  ed->data[1] = s->bytes_sent;
93  ed->data[2] = s->bytes_to_send;
94  }
95 
96  /* Poke the session layer */
97  if (svm_fifo_set_event (txf))
98  {
99  /* Fabricate TX event, send to vpp */
100  evt.fifo = txf;
101  evt.event_type = FIFO_EVENT_APP_TX;
102 
104  (tm->vpp_event_queue[txf->master_thread_index], (u8 *) & evt,
105  0 /* do wait for mutex */ ))
106  clib_warning ("could not enqueue event");
107  }
108  }
109 }
110 
111 static void
113 {
114  svm_fifo_t *rx_fifo = s->server_rx_fifo;
115  u32 my_thread_index = vlib_get_thread_index ();
116  int n_read, i;
117 
118  /* Allow enqueuing of new event */
119  // svm_fifo_unset_event (rx_fifo);
120 
121  if (tm->test_bytes)
122  {
123  n_read = svm_fifo_dequeue_nowait (rx_fifo,
124  vec_len (tm->rx_buf[my_thread_index]),
125  tm->rx_buf[my_thread_index]);
126  }
127  else
128  {
129  n_read = svm_fifo_max_dequeue (rx_fifo);
130  svm_fifo_dequeue_drop (rx_fifo, n_read);
131  }
132 
133  if (n_read > 0)
134  {
136  {
137  /* *INDENT-OFF* */
138  ELOG_TYPE_DECLARE (e) =
139  {
140  .format = "rx-deq: %d bytes",
141  .format_args = "i4",
142  };
143  /* *INDENT-ON* */
144  struct
145  {
146  u32 data[1];
147  } *ed;
149  ed->data[0] = n_read;
150  }
151 
152  if (tm->test_bytes)
153  {
154  for (i = 0; i < n_read; i++)
155  {
156  if (tm->rx_buf[my_thread_index][i]
157  != ((s->bytes_received + i) & 0xff))
158  {
159  clib_warning ("read %d error at byte %lld, 0x%x not 0x%x",
160  n_read, s->bytes_received + i,
161  tm->rx_buf[my_thread_index][i],
162  ((s->bytes_received + i) & 0xff));
163  tm->test_failed = 1;
164  }
165  }
166  }
167  s->bytes_to_receive -= n_read;
168  s->bytes_received += n_read;
169  }
170 }
171 
172 static uword
174  vlib_frame_t * frame)
175 {
177  int my_thread_index = vlib_get_thread_index ();
178  session_t *sp;
179  int i;
180  int delete_session;
181  u32 *connection_indices;
182  u32 *connections_this_batch;
183  u32 nconnections_this_batch;
184 
185  connection_indices = tm->connection_index_by_thread[my_thread_index];
186  connections_this_batch =
187  tm->connections_this_batch_by_thread[my_thread_index];
188 
189  if ((tm->run_test == 0) ||
190  ((vec_len (connection_indices) == 0)
191  && vec_len (connections_this_batch) == 0))
192  return 0;
193 
194  /* Grab another pile of connections */
195  if (PREDICT_FALSE (vec_len (connections_this_batch) == 0))
196  {
197  nconnections_this_batch =
198  clib_min (tm->connections_per_batch, vec_len (connection_indices));
199 
200  ASSERT (nconnections_this_batch > 0);
201  vec_validate (connections_this_batch, nconnections_this_batch - 1);
202  clib_memcpy (connections_this_batch,
203  connection_indices + vec_len (connection_indices)
204  - nconnections_this_batch,
205  nconnections_this_batch * sizeof (u32));
206  _vec_len (connection_indices) -= nconnections_this_batch;
207  }
208 
210  && tm->prev_conns == vec_len (connections_this_batch)))
211  {
212  tm->repeats++;
213  tm->prev_conns = vec_len (connections_this_batch);
214  if (tm->repeats == 500000)
215  {
216  clib_warning ("stuck clients");
217  }
218  }
219  else
220  {
221  tm->prev_conns = vec_len (connections_this_batch);
222  tm->repeats = 0;
223  }
224 
225  for (i = 0; i < vec_len (connections_this_batch); i++)
226  {
227  delete_session = 1;
228 
229  sp = pool_elt_at_index (tm->sessions, connections_this_batch[i]);
230 
231  if (sp->bytes_to_send > 0)
232  {
233  send_test_chunk (tm, sp);
234  delete_session = 0;
235  }
236  if (sp->bytes_to_receive > 0)
237  {
238  receive_test_chunk (tm, sp);
239  delete_session = 0;
240  }
241  if (PREDICT_FALSE (delete_session == 1))
242  {
243  u32 index, thread_index;
244  stream_session_t *s;
245 
246  __sync_fetch_and_add (&tm->tx_total, sp->bytes_sent);
247  __sync_fetch_and_add (&tm->rx_total, sp->bytes_received);
248 
250  &index, &thread_index);
251  s = session_get_if_valid (index, thread_index);
252 
253  if (s)
254  {
255  vnet_disconnect_args_t _a, *a = &_a;
256  a->handle = session_handle (s);
257  a->app_index = tm->app_index;
259 
260  vec_delete (connections_this_batch, 1, i);
261  i--;
262  __sync_fetch_and_add (&tm->ready_connections, -1);
263  }
264  else
265  clib_warning ("session AWOL?");
266 
267  /* Kick the debug CLI process */
268  if (tm->ready_connections == 0)
269  {
270  signal_evt_to_cli (2);
271  }
272  }
273  }
274 
275  tm->connection_index_by_thread[my_thread_index] = connection_indices;
276  tm->connections_this_batch_by_thread[my_thread_index] =
277  connections_this_batch;
278  return 0;
279 }
280 
281 /* *INDENT-OFF* */
283 {
284  .function = builtin_client_node_fn,
285  .name = "builtin-tcp-client",
286  .type = VLIB_NODE_TYPE_INPUT,
287  .state = VLIB_NODE_STATE_DISABLED,
288 };
289 /* *INDENT-ON* */
290 
291 static int
293 {
294  api_main_t *am = &api_main;
296 
297  shmem_hdr = am->shmem_hdr;
298  tm->vl_input_queue = shmem_hdr->vl_input_queue;
299  tm->my_client_index =
300  vl_api_memclnt_create_internal ("tcp_test_client", tm->vl_input_queue);
301  return 0;
302 }
303 
304 static int
306 {
309  u32 num_threads;
310  int i;
311 
312  if (create_api_loopback (tm))
313  return -1;
314 
315  num_threads = 1 /* main thread */ + vtm->n_threads;
316 
317  /* Init test data. Big buffer */
318  vec_validate (tm->connect_test_data, 1024 * 1024 - 1);
319  for (i = 0; i < vec_len (tm->connect_test_data); i++)
320  tm->connect_test_data[i] = i & 0xff;
321 
322  vec_validate (tm->rx_buf, num_threads - 1);
323  for (i = 0; i < num_threads; i++)
324  vec_validate (tm->rx_buf[i], vec_len (tm->connect_test_data) - 1);
325 
326  tm->is_init = 1;
327 
331 
332  return 0;
333 }
334 
335 static int
337  stream_session_t * s, u8 is_fail)
338 {
340  session_t *session;
341  u32 session_index;
342  u8 thread_index = vlib_get_thread_index ();
343 
344  if (is_fail)
345  {
346  clib_warning ("connection %d failed!", api_context);
347  signal_evt_to_cli (-1);
348  return 0;
349  }
350 
351  ASSERT (s->thread_index == thread_index);
352 
353  if (!tm->vpp_event_queue[thread_index])
354  tm->vpp_event_queue[thread_index] =
356 
357  /*
358  * Setup session
359  */
361  pool_get (tm->sessions, session);
363 
364  memset (session, 0, sizeof (*session));
365  session_index = session - tm->sessions;
366  session->bytes_to_send = tm->bytes_to_send;
367  session->bytes_to_receive = tm->no_return ? 0ULL : tm->bytes_to_send;
368  session->server_rx_fifo = s->server_rx_fifo;
369  session->server_rx_fifo->client_session_index = session_index;
370  session->server_tx_fifo = s->server_tx_fifo;
371  session->server_tx_fifo->client_session_index = session_index;
372  session->vpp_session_handle = session_handle (s);
373 
374  vec_add1 (tm->connection_index_by_thread[thread_index], session_index);
375  __sync_fetch_and_add (&tm->ready_connections, 1);
377  {
378  tm->run_test = 1;
379  /* Signal the CLI process that the action is starting... */
380  signal_evt_to_cli (1);
381  }
382 
383  return 0;
384 }
385 
386 static void
388 {
389  if (s->session_state == SESSION_STATE_READY)
390  clib_warning ("Reset active connection %U", format_stream_session, s, 2);
392  return;
393 }
394 
395 static int
397 {
398  return 0;
399 }
400 
401 static void
403 {
405  vnet_disconnect_args_t _a, *a = &_a;
406  a->handle = session_handle (s);
407  a->app_index = tm->app_index;
409  return;
410 }
411 
412 static int
414 {
415  return 0;
416 }
417 
418 /* *INDENT-OFF* */
420  .session_reset_callback = builtin_session_reset_callback,
421  .session_connected_callback = builtin_session_connected_callback,
422  .session_accept_callback = builtin_session_create_callback,
423  .session_disconnect_callback = builtin_session_disconnect_callback,
424  .builtin_server_rx_callback = builtin_server_rx_callback
425 };
426 /* *INDENT-ON* */
427 
428 static clib_error_t *
429 attach_builtin_test_clients_app (u8 * appns_id, u64 appns_flags,
430  u64 appns_secret)
431 {
432  u32 segment_name_length, prealloc_fifos, segment_size = 2 << 20;
434  vnet_app_attach_args_t _a, *a = &_a;
435  u8 segment_name[128];
436  u64 options[16];
437  clib_error_t *error = 0;
438 
439  segment_name_length = ARRAY_LEN (segment_name);
440 
441  memset (a, 0, sizeof (*a));
442  memset (options, 0, sizeof (options));
443 
444  a->api_client_index = tm->my_client_index;
445  a->segment_name = segment_name;
446  a->segment_name_length = segment_name_length;
447  a->session_cb_vft = &builtin_clients;
448 
449  prealloc_fifos = tm->prealloc_fifos ? tm->expected_connections : 1;
450 
451  if (tm->private_segment_size)
452  segment_size = tm->private_segment_size;
453 
454  options[APP_OPTIONS_ACCEPT_COOKIE] = 0x12345678;
455  options[APP_OPTIONS_SEGMENT_SIZE] = segment_size;
456  options[APP_OPTIONS_RX_FIFO_SIZE] = tm->fifo_size;
457  options[APP_OPTIONS_TX_FIFO_SIZE] = tm->fifo_size;
459  options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = prealloc_fifos;
460 
461  options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
462  if (appns_id)
463  {
464  options[APP_OPTIONS_FLAGS] |= appns_flags;
465  options[APP_OPTIONS_NAMESPACE_SECRET] = appns_secret;
466  }
467  a->options = options;
468  a->namespace_id = appns_id;
469 
470  if ((error = vnet_application_attach (a)))
471  return error;
472 
473  tm->app_index = a->app_index;
474  return 0;
475 }
476 
477 static void *
478 tclient_thread_fn (void *arg)
479 {
480  return 0;
481 }
482 
483 /** Start a transmit thread */
484 int
486 {
487  if (tm->client_thread_handle == 0)
488  {
489  int rv = pthread_create (&tm->client_thread_handle,
490  NULL /*attr */ ,
491  tclient_thread_fn, 0);
492  if (rv)
493  {
494  tm->client_thread_handle = 0;
495  return -1;
496  }
497  }
498  return 0;
499 }
500 
501 clib_error_t *
502 clients_connect (vlib_main_t * vm, u8 * uri, u32 n_clients)
503 {
505  vnet_connect_args_t _a, *a = &_a;
506  clib_error_t *error = 0;
507  int i;
508  for (i = 0; i < n_clients; i++)
509  {
510  memset (a, 0, sizeof (*a));
511 
512  a->uri = (char *) uri;
513  a->api_context = i;
514  a->app_index = tm->app_index;
515  a->mp = 0;
516 
517  if ((error = vnet_connect_uri (a)))
518  return error;
519 
520 
521  /* Crude pacing for call setups */
522  if ((i % 4) == 0)
523  vlib_process_suspend (vm, 10e-6);
524  ASSERT (i + 1 >= tm->ready_connections);
525  while (i + 1 - tm->ready_connections > 1000)
526  {
527  vlib_process_suspend (vm, 100e-6);
528  }
529  }
530  return 0;
531 }
532 
533 #define CLI_OUTPUT(_fmt, _args...) \
534  if (!tm->no_output) \
535  vlib_cli_output(vm, _fmt, ##_args)
536 
537 static clib_error_t *
539  unformat_input_t * input,
540  vlib_cli_command_t * cmd)
541 {
543  vlib_thread_main_t *thread_main = vlib_get_thread_main ();
544  uword *event_data = 0, event_type;
545  u8 *default_connect_uri = (u8 *) "tcp://6.0.1.1/1234", *uri, *appns_id = 0;
546  u64 tmp, total_bytes, appns_flags = 0, appns_secret = 0;
547  f64 test_timeout = 20.0, syn_timeout = 20.0, delta;
548  f64 time_before_connects;
549  u32 n_clients = 1;
550  int preallocate_sessions = 0;
551  char *transfer_type;
552  clib_error_t *error = 0;
553  int i;
554 
555  tm->bytes_to_send = 8192;
556  tm->no_return = 0;
557  tm->fifo_size = 64 << 10;
558  tm->connections_per_batch = 1000;
559  tm->private_segment_count = 0;
560  tm->private_segment_size = 0;
561  tm->no_output = 0;
562  tm->test_bytes = 0;
563  tm->test_failed = 0;
564  tm->vlib_main = vm;
565  if (thread_main->n_vlib_mains > 1)
567  vec_free (tm->connect_uri);
568 
570  {
571  if (unformat (input, "nclients %d", &n_clients))
572  ;
573  else if (unformat (input, "mbytes %lld", &tmp))
574  tm->bytes_to_send = tmp << 20;
575  else if (unformat (input, "gbytes %lld", &tmp))
576  tm->bytes_to_send = tmp << 30;
577  else if (unformat (input, "bytes %lld", &tm->bytes_to_send))
578  ;
579  else if (unformat (input, "uri %s", &tm->connect_uri))
580  ;
581  else if (unformat (input, "test-timeout %f", &test_timeout))
582  ;
583  else if (unformat (input, "syn-timeout %f", &syn_timeout))
584  ;
585  else if (unformat (input, "no-return"))
586  tm->no_return = 1;
587  else if (unformat (input, "fifo-size %d", &tm->fifo_size))
588  tm->fifo_size <<= 10;
589  else if (unformat (input, "private-segment-count %d",
590  &tm->private_segment_count))
591  ;
592  else if (unformat (input, "private-segment-size %U",
593  unformat_memory_size, &tmp))
594  {
595  if (tmp >= 0x100000000ULL)
596  return clib_error_return
597  (0, "private segment size %lld (%llu) too large", tmp, tmp);
598  tm->private_segment_size = tmp;
599  }
600  else if (unformat (input, "preallocate-fifos"))
601  tm->prealloc_fifos = 1;
602  else if (unformat (input, "preallocate-sessions"))
603  preallocate_sessions = 1;
604  else
605  if (unformat (input, "client-batch %d", &tm->connections_per_batch))
606  ;
607  else if (unformat (input, "appns %_%v%_", &appns_id))
608  ;
609  else if (unformat (input, "all-scope"))
610  appns_flags |= (APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE
611  | APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE);
612  else if (unformat (input, "local-scope"))
613  appns_flags = APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
614  else if (unformat (input, "global-scope"))
615  appns_flags = APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
616  else if (unformat (input, "secret %lu", &appns_secret))
617  ;
618  else if (unformat (input, "no-output"))
619  tm->no_output = 1;
620  else if (unformat (input, "test-bytes"))
621  tm->test_bytes = 1;
622  else
623  return clib_error_return (0, "unknown input `%U'",
624  format_unformat_error, input);
625  }
626 
627  /* Store cli process node index for signalling */
629 
630  if (tm->is_init == 0)
631  {
632  if (tcp_test_clients_init (vm))
633  return clib_error_return (0, "failed init");
634  }
635 
636 
637  tm->ready_connections = 0;
638  tm->expected_connections = n_clients;
639  tm->rx_total = 0;
640  tm->tx_total = 0;
641 
642  uri = default_connect_uri;
643  if (tm->connect_uri)
644  uri = tm->connect_uri;
645 
646 #if TCP_BUILTIN_CLIENT_PTHREAD
647  start_tx_pthread ();
648 #endif
649 
651  vnet_session_enable_disable (vm, 1 /* turn on TCP, etc. */ );
653 
654  if (tm->test_client_attached == 0)
655  {
656  if ((error = attach_builtin_test_clients_app (appns_id, appns_flags,
657  appns_secret)))
658  {
659  vec_free (appns_id);
660  clib_error_report (error);
661  return error;
662  }
663  vec_free (appns_id);
664  }
665  tm->test_client_attached = 1;
666 
667  /* Turn on the builtin client input nodes */
668  for (i = 0; i < thread_main->n_vlib_mains; i++)
670  VLIB_NODE_STATE_POLLING);
671 
672  if (preallocate_sessions)
673  {
674  session_t *sp __attribute__ ((unused));
675  for (i = 0; i < n_clients; i++)
676  pool_get (tm->sessions, sp);
677  for (i = 0; i < n_clients; i++)
678  pool_put_index (tm->sessions, i);
679  }
680 
681  /* Fire off connect requests */
682  time_before_connects = vlib_time_now (vm);
683  if ((error = clients_connect (vm, uri, n_clients)))
684  return error;
685 
686  /* Park until the sessions come up, or ten seconds elapse... */
687  vlib_process_wait_for_event_or_clock (vm, syn_timeout);
688  event_type = vlib_process_get_events (vm, &event_data);
689  switch (event_type)
690  {
691  case ~0:
692  CLI_OUTPUT ("Timeout with only %d sessions active...",
693  tm->ready_connections);
694  error = clib_error_return (0, "failed: syn timeout with %d sessions",
695  tm->ready_connections);
696  goto cleanup;
697 
698  case 1:
699  delta = vlib_time_now (vm) - time_before_connects;
700  if (delta != 0.0)
701  CLI_OUTPUT ("%d three-way handshakes in %.2f seconds %.2f/s",
702  n_clients, delta, ((f64) n_clients) / delta);
703 
705  CLI_OUTPUT ("Test started at %.6f", tm->test_start_time);
706  break;
707 
708  default:
709  CLI_OUTPUT ("unexpected event(1): %d", event_type);
710  error = clib_error_return (0, "failed: unexpected event(1): %d",
711  event_type);
712  goto cleanup;
713  }
714 
715  /* Now wait for the sessions to finish... */
716  vlib_process_wait_for_event_or_clock (vm, test_timeout);
717  event_type = vlib_process_get_events (vm, &event_data);
718  switch (event_type)
719  {
720  case ~0:
721  CLI_OUTPUT ("Timeout with %d sessions still active...",
722  tm->ready_connections);
723  error = clib_error_return (0, "failed: timeout with %d sessions",
724  tm->ready_connections);
725  goto cleanup;
726 
727  case 2:
728  tm->test_end_time = vlib_time_now (vm);
729  CLI_OUTPUT ("Test finished at %.6f", tm->test_end_time);
730  break;
731 
732  default:
733  CLI_OUTPUT ("unexpected event(2): %d", event_type);
734  error = clib_error_return (0, "failed: unexpected event(2): %d",
735  event_type);
736  goto cleanup;
737  }
738 
739  delta = tm->test_end_time - tm->test_start_time;
740 
741  if (delta != 0.0)
742  {
743  total_bytes = (tm->no_return ? tm->tx_total : tm->rx_total);
744  transfer_type = tm->no_return ? "half-duplex" : "full-duplex";
745  CLI_OUTPUT ("%lld bytes (%lld mbytes, %lld gbytes) in %.2f seconds",
746  total_bytes, total_bytes / (1ULL << 20),
747  total_bytes / (1ULL << 30), delta);
748  CLI_OUTPUT ("%.2f bytes/second %s", ((f64) total_bytes) / (delta),
749  transfer_type);
750  CLI_OUTPUT ("%.4f gbit/second %s",
751  (((f64) total_bytes * 8.0) / delta / 1e9), transfer_type);
752  }
753  else
754  {
755  CLI_OUTPUT ("zero delta-t?");
756  error = clib_error_return (0, "failed: zero delta-t");
757  goto cleanup;
758  }
759 
760  if (tm->test_bytes && tm->test_failed)
761  error = clib_error_return (0, "failed: test bytes");
762 
763 cleanup:
764  tm->run_test = 0;
765  for (i = 0; i < vec_len (tm->connection_index_by_thread); i++)
766  {
769  }
770 
771  pool_free (tm->sessions);
772 
773  /* Detach the application, so we can use different fifo sizes next time */
774  if (tm->test_client_attached)
775  {
776  vnet_app_detach_args_t _da, *da = &_da;
777  int rv;
778 
779  da->app_index = tm->app_index;
780  rv = vnet_application_detach (da);
781  if (rv)
782  {
783  error = clib_error_return (0, "failed: app detach");
784  CLI_OUTPUT ("WARNING: app detach failed...");
785  }
786  tm->test_client_attached = 0;
787  tm->app_index = ~0;
788  }
789  if (error)
790  CLI_OUTPUT ("test failed");
791  return error;
792 }
793 
794 /* *INDENT-OFF* */
795 VLIB_CLI_COMMAND (test_clients_command, static) =
796 {
797  .path = "test tcp clients",
798  .short_help = "test tcp clients [nclients %d] [[m|g]bytes <bytes>] "
799  "[test-timeout <time>][syn-timeout <time>][no-return][fifo-size <size>]"
800  "[private-segment-count <count>][private-segment-size <bytes>[m|g]]"
801  "[preallocate-fifos][preallocate-sessions][client-batch <batch-size>]"
802  "[uri <tcp://ip/port>][test-bytes][no-output]",
803  .function = test_tcp_clients_command_fn,
804  .is_mp_safe = 1,
805 };
806 /* *INDENT-ON* */
807 
808 clib_error_t *
810 {
812  tm->is_init = 0;
813  return 0;
814 }
815 
817 
818 /*
819  * fd.io coding-style-patch-verification: ON
820  *
821  * Local Variables:
822  * eval: (c-set-style "gnu")
823  * End:
824  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:432
unix_shared_memory_queue_t * vl_input_queue
vpe input queue
vlib_main_t vlib_global_main
Definition: main.c:1637
static session_cb_vft_t builtin_clients
u32 app_index
app index after attach
static int builtin_session_connected_callback(u32 app_index, u32 api_context, stream_session_t *s, u8 is_fail)
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
#define clib_min(x, y)
Definition: clib.h:340
static void builtin_session_disconnect_callback(stream_session_t *s)
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
Definition: node_funcs.h:699
vlib_node_runtime_t node_runtime
Definition: node.h:495
a
Definition: bitmap.h:516
u64 bytes_to_send
Bytes to send.
u64 bytes_received
static void send_test_chunk(tclient_main_t *tm, session_t *s)
struct _vnet_connect_args vnet_connect_args_t
static void builtin_session_reset_callback(stream_session_t *s)
u8 * connect_uri
URI for slave&#39;s connect.
unix_shared_memory_queue_t * vl_input_queue
Definition: api_common.h:68
#define NULL
Definition: clib.h:55
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:224
u32 cli_node_index
cli process node index
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:85
static int create_api_loopback(tclient_main_t *tm)
u32 my_client_index
loopback API client handle
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:518
clib_error_t * tcp_test_clients_main_init(vlib_main_t *vm)
#define CLI_OUTPUT(_fmt, _args...)
u64 bytes_to_receive
u8 ** rx_buf
intermediate rx buffers
u32 ** connections_this_batch_by_thread
active connection batch
unix_shared_memory_queue_t ** vpp_event_queue
static clib_error_t * test_tcp_clients_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:225
vlib_main_t ** vlib_mains
Definition: buffer.c:292
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define vlib_worker_thread_barrier_sync(X)
Definition: threads.h:212
struct _svm_fifo svm_fifo_t
u64 bytes_to_send
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
Definition: node_funcs.h:448
static void * tclient_thread_fn(void *arg)
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
Definition: node_funcs.h:542
struct _vnet_disconnect_args_t vnet_disconnect_args_t
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
Definition: svm_fifo.h:100
struct _stream_session_cb_vft session_cb_vft_t
svm_fifo_t * server_tx_fifo
u32 expected_connections
Number of clients/connections.
volatile u64 rx_total
static void signal_evt_to_cli(int code)
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned long u64
Definition: types.h:89
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
Definition: api_common.h:261
void stream_session_cleanup(stream_session_t *s)
Cleanup transport and session state.
Definition: session.c:948
struct _stream_session_t stream_session_t
volatile u32 ready_connections
vlib_node_registration_t builtin_client_node
(constructor) VLIB_REGISTER_NODE (builtin_client_node)
u8 prealloc_fifos
Request fifo preallocation.
struct _vnet_app_attach_args_t vnet_app_attach_args_t
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:33
vl_shmem_hdr_t * shmem_hdr
int unix_shared_memory_queue_add(unix_shared_memory_queue_t *q, u8 *elem, int nowait)
static void session_parse_handle(u64 handle, u32 *index, u32 *thread_index)
Definition: session.h:267
u32 ** connection_index_by_thread
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:459
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:950
int start_tx_pthread(tclient_main_t *tm)
Start a transmit thread.
struct _unformat_input_t unformat_input_t
static void cleanup(void)
Definition: client.c:90
#define ELOG_DATA(em, f)
Definition: elog.h:481
#define PREDICT_FALSE(x)
Definition: clib.h:105
static stream_session_t * session_get_if_valid(u64 si, u32 thread_index)
Definition: session.h:236
u32 node_index
Node index.
Definition: node.h:437
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
Definition: session.c:1171
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:198
static int tcp_test_clients_init(vlib_main_t *vm)
#define pool_free(p)
Free a pool.
Definition: pool.h:352
static u8 svm_fifo_set_event(svm_fifo_t *f)
Sets fifo event flag.
Definition: svm_fifo.h:123
static unix_shared_memory_queue_t * session_manager_get_vpp_event_queue(u32 thread_index)
Definition: session.h:459
api_main_t api_main
Definition: api_shared.c:35
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
pthread_t client_thread_handle
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:221
static vlib_process_t * vlib_get_current_process(vlib_main_t *vm)
Definition: node_funcs.h:417
vlib_main_t * vm
Definition: buffer.c:283
u8 * format_stream_session(u8 *s, va_list *args)
Format stream session as per the following format.
Definition: session_cli.c:52
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
vlib_main_t * vlib_main
static void signal_evt_to_cli_i(int *code)
#define clib_warning(format, args...)
Definition: error.h:59
static int builtin_session_create_callback(stream_session_t *s)
static void receive_test_chunk(tclient_main_t *tm, session_t *s)
#define clib_memcpy(a, b, c)
Definition: string.h:75
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: memory_vlib.c:1916
elog_main_t elog_main
Definition: main.h:155
u32 vl_api_memclnt_create_internal(char *, unix_shared_memory_queue_t *)
Definition: memory_vlib.c:142
clib_spinlock_t sessions_lock
volatile int run_test
Signal start of test.
int vnet_disconnect_session(vnet_disconnect_args_t *a)
#define ARRAY_LEN(x)
Definition: clib.h:59
#define ELOG_TYPE_DECLARE(f)
Definition: elog.h:439
int svm_fifo_enqueue_nowait(svm_fifo_t *f, u32 max_bytes, u8 *copy_from_here)
Definition: svm_fifo.c:533
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:294
#define ASSERT(truth)
static clib_error_t * attach_builtin_test_clients_app(u8 *appns_id, u64 appns_flags, u64 appns_secret)
unsigned int u32
Definition: types.h:88
#define vec_delete(V, N, M)
Delete N elements starting at element M.
Definition: vec.h:781
#define TCP_BUILTIN_CLIENT_DBG
#define clib_error_report(e)
Definition: error.h:113
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
Definition: node_funcs.h:147
tclient_main_t tclient_main
static int app_index
struct _vnet_app_detach_args_t vnet_app_detach_args_t
u32 connections_per_batch
Connections to rx/tx at once.
static int builtin_server_rx_callback(stream_session_t *s)
u64 uword
Definition: types.h:112
static u64 session_handle(stream_session_t *s)
Definition: session.h:249
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 max_bytes)
Definition: svm_fifo.c:772
clib_error_t * vnet_connect_uri(vnet_connect_args_t *a)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56
clib_error_t * vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
static uword builtin_client_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
u64 vpp_session_handle
unformat_function_t unformat_memory_size
Definition: format.h:294
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
clib_error_t * clients_connect(vlib_main_t *vm, u8 *uri, u32 n_clients)
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1491
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
u32 private_segment_size
size of private fifo segs
u32 private_segment_count
Number of private fifo segs.
volatile u64 tx_total
int vnet_application_detach(vnet_app_detach_args_t *a)
Detach application from vpp.
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:65
int svm_fifo_dequeue_nowait(svm_fifo_t *f, u32 max_bytes, u8 *copy_here)
Definition: svm_fifo.c:690
session_t * sessions
Session pool, shared.
svm_fifo_t * server_rx_fifo
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
u8 * connect_test_data
Pre-computed test data.