FD.io VPP  v17.10-9-gd594711
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 <vlibsocket/api.h>
25 #include <vpp/app/version.h>
26 
27 #define TCP_BUILTIN_CLIENT_DBG (0)
28 
29 static void
31 {
33  ASSERT (vlib_get_thread_index () == 0);
35 }
36 
37 static void
39 {
40  if (vlib_get_thread_index () != 0)
42  sizeof (code));
43  else
44  signal_evt_to_cli_i (&code);
45 }
46 
47 static void
49 {
50  u8 *test_data = tm->connect_test_data;
51  int test_buf_offset;
52  u32 bytes_this_chunk;
53  session_fifo_event_t evt;
54  static int serial_number = 0;
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  evt.event_id = serial_number++;
103 
105  (tm->vpp_event_queue[txf->master_thread_index], (u8 *) & evt,
106  0 /* do wait for mutex */ ))
107  clib_warning ("could not enqueue event");
108  }
109  }
110 }
111 
112 static void
114 {
115  svm_fifo_t *rx_fifo = s->server_rx_fifo;
116  int n_read, test_bytes = 0;
117  u32 my_thread_index = vlib_get_thread_index ();
118 
119  /* Allow enqueuing of new event */
120  // svm_fifo_unset_event (rx_fifo);
121 
122  if (test_bytes)
123  {
124  n_read = svm_fifo_dequeue_nowait (rx_fifo,
125  vec_len (tm->rx_buf[my_thread_index]),
126  tm->rx_buf[my_thread_index]);
127  }
128  else
129  {
130  n_read = svm_fifo_max_dequeue (rx_fifo);
131  svm_fifo_dequeue_drop (rx_fifo, n_read);
132  }
133 
134  if (n_read > 0)
135  {
137  {
138  /* *INDENT-OFF* */
139  ELOG_TYPE_DECLARE (e) =
140  {
141  .format = "rx-deq: %d bytes",
142  .format_args = "i4",
143  };
144  /* *INDENT-ON* */
145  struct
146  {
147  u32 data[1];
148  } *ed;
150  ed->data[0] = n_read;
151  }
152 
153  if (test_bytes)
154  {
155  int i;
156  for (i = 0; i < n_read; i++)
157  {
158  if (tm->rx_buf[my_thread_index][i]
159  != ((s->bytes_received + i) & 0xff))
160  {
161  clib_warning ("read %d error at byte %lld, 0x%x not 0x%x",
162  n_read, s->bytes_received + i,
163  tm->rx_buf[my_thread_index][i],
164  ((s->bytes_received + i) & 0xff));
165  }
166  }
167  }
168  s->bytes_to_receive -= n_read;
169  s->bytes_received += n_read;
170  }
171 }
172 
173 static uword
175  vlib_frame_t * frame)
176 {
178  int my_thread_index = vlib_get_thread_index ();
179  session_t *sp;
180  int i;
181  int delete_session;
182  u32 *connection_indices;
183  u32 *connections_this_batch;
184  u32 nconnections_this_batch;
185 
186  connection_indices = tm->connection_index_by_thread[my_thread_index];
187  connections_this_batch =
188  tm->connections_this_batch_by_thread[my_thread_index];
189 
190  if ((tm->run_test == 0) ||
191  ((vec_len (connection_indices) == 0)
192  && vec_len (connections_this_batch) == 0))
193  return 0;
194 
195  /* Grab another pile of connections */
196  if (PREDICT_FALSE (vec_len (connections_this_batch) == 0))
197  {
198  nconnections_this_batch =
199  clib_min (tm->connections_per_batch, vec_len (connection_indices));
200 
201  ASSERT (nconnections_this_batch > 0);
202  vec_validate (connections_this_batch, nconnections_this_batch - 1);
203  clib_memcpy (connections_this_batch,
204  connection_indices + vec_len (connection_indices)
205  - nconnections_this_batch,
206  nconnections_this_batch * sizeof (u32));
207  _vec_len (connection_indices) -= nconnections_this_batch;
208  }
209 
211  && tm->prev_conns == vec_len (connections_this_batch)))
212  {
213  tm->repeats++;
214  tm->prev_conns = vec_len (connections_this_batch);
215  if (tm->repeats == 500000)
216  {
217  clib_warning ("stuck clients");
218  }
219  }
220  else
221  {
222  tm->prev_conns = vec_len (connections_this_batch);
223  tm->repeats = 0;
224  }
225 
226  for (i = 0; i < vec_len (connections_this_batch); i++)
227  {
228  delete_session = 1;
229 
230  sp = pool_elt_at_index (tm->sessions, connections_this_batch[i]);
231 
232  if (sp->bytes_to_send > 0)
233  {
234  send_test_chunk (tm, sp);
235  delete_session = 0;
236  }
237  if (sp->bytes_to_receive > 0)
238  {
239  receive_test_chunk (tm, sp);
240  delete_session = 0;
241  }
242  if (PREDICT_FALSE (delete_session == 1))
243  {
244  u32 index, thread_index;
245  stream_session_t *s;
246 
247  __sync_fetch_and_add (&tm->tx_total, sp->bytes_sent);
248  __sync_fetch_and_add (&tm->rx_total, sp->bytes_received);
249 
251  &index, &thread_index);
252  s = stream_session_get_if_valid (index, thread_index);
253 
254  if (s)
255  {
256  vnet_disconnect_args_t _a, *a = &_a;
257  a->handle = stream_session_handle (s);
258  a->app_index = tm->app_index;
260 
261  vec_delete (connections_this_batch, 1, i);
262  i--;
263  __sync_fetch_and_add (&tm->ready_connections, -1);
264  }
265  else
266  clib_warning ("session AWOL?");
267 
268  /* Kick the debug CLI process */
269  if (tm->ready_connections == 0)
270  {
271  signal_evt_to_cli (2);
272  }
273  }
274  }
275 
276  tm->connection_index_by_thread[my_thread_index] = connection_indices;
277  tm->connections_this_batch_by_thread[my_thread_index] =
278  connections_this_batch;
279  return 0;
280 }
281 
282 /* *INDENT-OFF* */
284 {
285  .function = builtin_client_node_fn,
286  .name = "builtin-tcp-client",
287  .type = VLIB_NODE_TYPE_INPUT,
288  .state = VLIB_NODE_STATE_DISABLED,
289 };
290 /* *INDENT-ON* */
291 
292 static int
294 {
295  api_main_t *am = &api_main;
297 
298  shmem_hdr = am->shmem_hdr;
299  tm->vl_input_queue = shmem_hdr->vl_input_queue;
300  tm->my_client_index =
301  vl_api_memclnt_create_internal ("tcp_test_client", tm->vl_input_queue);
302  return 0;
303 }
304 
305 static int
307 {
310  u32 num_threads;
311  int i;
312 
313  if (create_api_loopback (tm))
314  return -1;
315 
316  num_threads = 1 /* main thread */ + vtm->n_threads;
317 
318  /* Init test data. Big buffer */
319  vec_validate (tm->connect_test_data, 1024 * 1024 - 1);
320  for (i = 0; i < vec_len (tm->connect_test_data); i++)
321  tm->connect_test_data[i] = i & 0xff;
322 
323  vec_validate (tm->rx_buf, num_threads - 1);
324  for (i = 0; i < num_threads; i++)
325  vec_validate (tm->rx_buf[i], vec_len (tm->connect_test_data) - 1);
326 
327  tm->is_init = 1;
328 
332 
333  return 0;
334 }
335 
336 static int
338  stream_session_t * s, u8 is_fail)
339 {
341  session_t *session;
342  u32 session_index;
343  u8 thread_index = vlib_get_thread_index ();
344 
345  if (is_fail)
346  {
347  clib_warning ("connection %d failed!", api_context);
348  signal_evt_to_cli (-1);
349  return 0;
350  }
351 
352  ASSERT (s->thread_index == thread_index);
353 
354  if (!tm->vpp_event_queue[thread_index])
355  tm->vpp_event_queue[thread_index] =
357 
358  /*
359  * Setup session
360  */
362  pool_get (tm->sessions, session);
364 
365  memset (session, 0, sizeof (*session));
366  session_index = session - tm->sessions;
367  session->bytes_to_send = tm->bytes_to_send;
368  session->bytes_to_receive = tm->no_return ? 0ULL : tm->bytes_to_send;
369  session->server_rx_fifo = s->server_rx_fifo;
370  session->server_rx_fifo->client_session_index = session_index;
371  session->server_tx_fifo = s->server_tx_fifo;
372  session->server_tx_fifo->client_session_index = session_index;
374 
375  vec_add1 (tm->connection_index_by_thread[thread_index], session_index);
376  __sync_fetch_and_add (&tm->ready_connections, 1);
378  {
379  tm->run_test = 1;
380  /* Signal the CLI process that the action is starting... */
381  signal_evt_to_cli (1);
382  }
383 
384  return 0;
385 }
386 
387 static void
389 {
390  if (s->session_state == SESSION_STATE_READY)
391  clib_warning ("Reset active connection %U", format_stream_session, s, 2);
393  return;
394 }
395 
396 static int
398 {
399  return 0;
400 }
401 
402 static void
404 {
406  vnet_disconnect_args_t _a, *a = &_a;
407  a->handle = stream_session_handle (s);
408  a->app_index = tm->app_index;
410  return;
411 }
412 
413 static int
415 {
416  return 0;
417 }
418 
419 /* *INDENT-OFF* */
421  .session_reset_callback = builtin_session_reset_callback,
422  .session_connected_callback = builtin_session_connected_callback,
423  .session_accept_callback = builtin_session_create_callback,
424  .session_disconnect_callback = builtin_session_disconnect_callback,
425  .builtin_server_rx_callback = builtin_server_rx_callback
426 };
427 /* *INDENT-ON* */
428 
429 static int
431 {
433  vnet_app_attach_args_t _a, *a = &_a;
434  u8 segment_name[128];
435  u32 segment_name_length, prealloc_fifos;
436  u64 options[16];
437 
438  segment_name_length = ARRAY_LEN (segment_name);
439 
440  memset (a, 0, sizeof (*a));
441  memset (options, 0, sizeof (options));
442 
443  a->api_client_index = tm->my_client_index;
444  a->segment_name = segment_name;
445  a->segment_name_length = segment_name_length;
446  a->session_cb_vft = &builtin_clients;
447 
448  prealloc_fifos = tm->prealloc_fifos ? tm->expected_connections : 1;
449 
450  options[SESSION_OPTIONS_ACCEPT_COOKIE] = 0x12345678;
451  options[SESSION_OPTIONS_SEGMENT_SIZE] = (2ULL << 32);
456  options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = prealloc_fifos;
457 
458  options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_BUILTIN_APP;
459 
460  a->options = options;
461 
462  if (vnet_application_attach (a))
463  return -1;
464 
465  tm->app_index = a->app_index;
466  return 0;
467 }
468 
469 static void *
470 tclient_thread_fn (void *arg)
471 {
472  return 0;
473 }
474 
475 /** Start a transmit thread */
476 int
478 {
479  if (tm->client_thread_handle == 0)
480  {
481  int rv = pthread_create (&tm->client_thread_handle,
482  NULL /*attr */ ,
483  tclient_thread_fn, 0);
484  if (rv)
485  {
486  tm->client_thread_handle = 0;
487  return -1;
488  }
489  }
490  return 0;
491 }
492 
493 void
494 clients_connect (vlib_main_t * vm, u8 * uri, u32 n_clients)
495 {
497  vnet_connect_args_t _a, *a = &_a;
498  int i;
499  for (i = 0; i < n_clients; i++)
500  {
501  memset (a, 0, sizeof (*a));
502 
503  a->uri = (char *) uri;
504  a->api_context = i;
505  a->app_index = tm->app_index;
506  a->mp = 0;
507  vnet_connect_uri (a);
508 
509  /* Crude pacing for call setups */
510  if ((i % 4) == 0)
511  vlib_process_suspend (vm, 10e-6);
512  ASSERT (i + 1 >= tm->ready_connections);
513  while (i + 1 - tm->ready_connections > 1000)
514  {
515  vlib_process_suspend (vm, 100e-6);
516  }
517  }
518 }
519 
520 static clib_error_t *
522  unformat_input_t * input,
523  vlib_cli_command_t * cmd)
524 {
526  vlib_thread_main_t *thread_main = vlib_get_thread_main ();
527  uword *event_data = 0, event_type;
528  u8 *default_connect_uri = (u8 *) "tcp://6.0.1.1/1234", *uri;
529  u64 tmp, total_bytes;
530  f64 test_timeout = 20.0, syn_timeout = 20.0, delta;
531  f64 time_before_connects;
532  u32 n_clients = 1;
533  int preallocate_sessions = 0;
534  char *transfer_type;
535  int i;
536 
537  tm->bytes_to_send = 8192;
538  tm->no_return = 0;
539  tm->fifo_size = 64 << 10;
540  tm->connections_per_batch = 1000;
541  tm->private_segment_count = 0;
542  tm->private_segment_size = 0;
543  tm->vlib_main = vm;
544  if (thread_main->n_vlib_mains > 1)
546  vec_free (tm->connect_uri);
547 
549  {
550  if (unformat (input, "nclients %d", &n_clients))
551  ;
552  else if (unformat (input, "mbytes %lld", &tmp))
553  tm->bytes_to_send = tmp << 20;
554  else if (unformat (input, "gbytes %lld", &tmp))
555  tm->bytes_to_send = tmp << 30;
556  else if (unformat (input, "bytes %lld", &tm->bytes_to_send))
557  ;
558  else if (unformat (input, "uri %s", &tm->connect_uri))
559  ;
560  else if (unformat (input, "test-timeout %f", &test_timeout))
561  ;
562  else if (unformat (input, "syn-timeout %f", &syn_timeout))
563  ;
564  else if (unformat (input, "no-return"))
565  tm->no_return = 1;
566  else if (unformat (input, "fifo-size %d", &tm->fifo_size))
567  tm->fifo_size <<= 10;
568  else if (unformat (input, "private-segment-count %d",
569  &tm->private_segment_count))
570  ;
571  else if (unformat (input, "private-segment-size %U",
572  unformat_memory_size, &tmp))
573  {
574  if (tmp >= 0x100000000ULL)
575  return clib_error_return
576  (0, "private segment size %lld (%llu) too large", tmp, tmp);
577  tm->private_segment_size = tmp;
578  }
579  else if (unformat (input, "preallocate-fifos"))
580  tm->prealloc_fifos = 1;
581  else if (unformat (input, "preallocate-sessions"))
582  preallocate_sessions = 1;
583  else
584  if (unformat (input, "client-batch %d", &tm->connections_per_batch))
585  ;
586  else
587  return clib_error_return (0, "unknown input `%U'",
588  format_unformat_error, input);
589  }
590 
591  /* Store cli process node index for signalling */
593 
594  if (tm->is_init == 0)
595  {
596  if (tcp_test_clients_init (vm))
597  return clib_error_return (0, "failed init");
598  }
599 
600 
601  tm->ready_connections = 0;
602  tm->expected_connections = n_clients;
603  tm->rx_total = 0;
604  tm->tx_total = 0;
605 
606  uri = default_connect_uri;
607  if (tm->connect_uri)
608  uri = tm->connect_uri;
609 
610 #if TCP_BUILTIN_CLIENT_PTHREAD
611  start_tx_pthread ();
612 #endif
613 
615  vnet_session_enable_disable (vm, 1 /* turn on TCP, etc. */ );
617 
618  if (tm->test_client_attached == 0)
619  {
621  {
622  return clib_error_return (0, "app attach failed");
623  }
624  }
625  tm->test_client_attached = 1;
626 
627  /* Turn on the builtin client input nodes */
628  for (i = 0; i < thread_main->n_vlib_mains; i++)
630  VLIB_NODE_STATE_POLLING);
631 
632  if (preallocate_sessions)
633  {
634  session_t *sp __attribute__ ((unused));
635  for (i = 0; i < n_clients; i++)
636  pool_get (tm->sessions, sp);
637  for (i = 0; i < n_clients; i++)
638  pool_put_index (tm->sessions, i);
639  }
640 
641  /* Fire off connect requests */
642  time_before_connects = vlib_time_now (vm);
643  clients_connect (vm, uri, n_clients);
644 
645  /* Park until the sessions come up, or ten seconds elapse... */
646  vlib_process_wait_for_event_or_clock (vm, syn_timeout);
647  event_type = vlib_process_get_events (vm, &event_data);
648  switch (event_type)
649  {
650  case ~0:
651  vlib_cli_output (vm, "Timeout with only %d sessions active...",
652  tm->ready_connections);
653  goto cleanup;
654 
655  case 1:
656  delta = vlib_time_now (vm) - time_before_connects;
657 
658  if (delta != 0.0)
659  {
661  (vm, "%d three-way handshakes in %.2f seconds, %.2f/sec",
662  n_clients, delta, ((f64) n_clients) / delta);
663  }
664 
666  vlib_cli_output (vm, "Test started at %.6f", tm->test_start_time);
667  break;
668 
669  default:
670  vlib_cli_output (vm, "unexpected event(1): %d", event_type);
671  goto cleanup;
672  }
673 
674  /* Now wait for the sessions to finish... */
675  vlib_process_wait_for_event_or_clock (vm, test_timeout);
676  event_type = vlib_process_get_events (vm, &event_data);
677  switch (event_type)
678  {
679  case ~0:
680  vlib_cli_output (vm, "Timeout with %d sessions still active...",
681  tm->ready_connections);
682  goto cleanup;
683 
684  case 2:
685  tm->test_end_time = vlib_time_now (vm);
686  vlib_cli_output (vm, "Test finished at %.6f", tm->test_end_time);
687  break;
688 
689  default:
690  vlib_cli_output (vm, "unexpected event(2): %d", event_type);
691  goto cleanup;
692  }
693 
694  delta = tm->test_end_time - tm->test_start_time;
695 
696  if (delta != 0.0)
697  {
698  total_bytes = (tm->no_return ? tm->tx_total : tm->rx_total);
699  transfer_type = tm->no_return ? "half-duplex" : "full-duplex";
700  vlib_cli_output (vm,
701  "%lld bytes (%lld mbytes, %lld gbytes) in %.2f seconds",
702  total_bytes, total_bytes / (1ULL << 20),
703  total_bytes / (1ULL << 30), delta);
704  vlib_cli_output (vm, "%.2f bytes/second %s",
705  ((f64) total_bytes) / (delta), transfer_type);
706  vlib_cli_output (vm, "%.4f gbit/second %s",
707  (((f64) total_bytes * 8.0) / delta / 1e9),
708  transfer_type);
709  }
710  else
711  vlib_cli_output (vm, "zero delta-t?");
712 
713 cleanup:
714  tm->run_test = 0;
715  for (i = 0; i < vec_len (tm->connection_index_by_thread); i++)
716  {
719  }
720 
721  pool_free (tm->sessions);
722 
723  /* Detach the application, so we can use different fifo sizes next time */
724  if (tm->test_client_attached)
725  {
726  vnet_app_detach_args_t _da, *da = &_da;
727  int rv;
728 
729  da->app_index = tm->app_index;
730 
731  rv = vnet_application_detach (da);
732  if (rv)
733  vlib_cli_output (vm, "WARNING: app detach failed...");
734  tm->test_client_attached = 0;
735  tm->app_index = ~0;
736  }
737  return 0;
738 }
739 
740 /* *INDENT-OFF* */
741 VLIB_CLI_COMMAND (test_clients_command, static) =
742 {
743  .path = "test tcp clients",
744  .short_help = "test tcp clients [nclients %d] [[m|g]bytes <bytes>] "
745  "[test-timeout <time>][syn-timeout <time>][no-return][fifo-size <size>]"
746  "[private-segment-count <count>][private-segment-size <bytes>[m|g]]"
747  "[preallocate-fifos][preallocate-sessions][client-batch <batch-size>]"
748  "[uri <tcp://ip/port>]",
749  .function = test_tcp_clients_command_fn,
750  .is_mp_safe = 1,
751 };
752 /* *INDENT-ON* */
753 
754 clib_error_t *
756 {
758  tm->is_init = 0;
759  return 0;
760 }
761 
763 
764 /*
765  * fd.io coding-style-patch-verification: ON
766  *
767  * Local Variables:
768  * eval: (c-set-style "gnu")
769  * End:
770  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:432
void test_bytes(builtin_server_main_t *bsm, int actual_transfer)
unix_shared_memory_queue_t * vl_input_queue
vpe input queue
vlib_main_t vlib_global_main
Definition: main.c:1650
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:332
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:221
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)
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
svm_fifo_t * server_rx_fifo
#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
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:241
void stream_session_cleanup(stream_session_t *s)
Cleanup transport and session state.
Definition: session.c:776
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)
u32 ** connection_index_by_thread
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:458
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:97
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:928
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:182
static int tcp_test_clients_init(vlib_main_t *vm)
#define pool_free(p)
Free a pool.
Definition: pool.h:351
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:345
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)
tclient_main_t tclient_main
#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:69
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: memory_vlib.c:1517
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:152
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
svm_fifo_t * server_tx_fifo
static stream_session_t * stream_session_get_if_valid(u64 si, u32 thread_index)
Definition: session.h:224
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
int vnet_application_attach(vnet_app_attach_args_t *a)
Attaches application.
static void stream_session_parse_handle(u64 handle, u32 *index, u32 *thread_index)
Definition: session.h:255
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:293
#define ASSERT(truth)
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
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
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 stream_session_handle(stream_session_t *s)
Definition: session.h:237
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 max_bytes)
Definition: svm_fifo.c:772
#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
static uword builtin_client_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static int attach_builtin_test_clients_app(void)
u64 vpp_session_handle
unformat_function_t unformat_memory_size
Definition: format.h:294
void clients_connect(vlib_main_t *vm, u8 *uri, u32 n_clients)
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1488
#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_connect_uri(vnet_connect_args_t *a)
int vnet_application_detach(vnet_app_detach_args_t *a)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:680
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.
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.