FD.io VPP  v19.01.2-3-gf61a1a8
Vector Packet Processing
echo_client.c
Go to the documentation of this file.
1 /*
2  * echo_client.c - vpp built-in echo client 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 <vlibapi/api.h>
20 #include <vlibmemory/api.h>
22 
24 
25 #define ECHO_CLIENT_DBG (0)
26 
27 static void
29 {
31  ASSERT (vlib_get_thread_index () == 0);
32  vlib_process_signal_event (ecm->vlib_main, ecm->cli_node_index, *code, 0);
33 }
34 
35 static void
37 {
38  if (vlib_get_thread_index () != 0)
40  sizeof (code));
41  else
42  signal_evt_to_cli_i (&code);
43 }
44 
45 static void
47 {
48  u8 *test_data = ecm->connect_test_data;
49  int test_buf_len, test_buf_offset, rv;
50  u32 bytes_this_chunk;
51 
52  test_buf_len = vec_len (test_data);
53  ASSERT (test_buf_len > 0);
54  test_buf_offset = s->bytes_sent % test_buf_len;
55  bytes_this_chunk = clib_min (test_buf_len - test_buf_offset,
56  s->bytes_to_send);
57 
58  if (!ecm->is_dgram)
59  {
60  if (ecm->no_copy)
61  {
62  svm_fifo_t *f = s->data.tx_fifo;
63  rv = clib_min (svm_fifo_max_enqueue (f), bytes_this_chunk);
67  }
68  else
69  rv = app_send_stream (&s->data, test_data + test_buf_offset,
70  bytes_this_chunk, 0);
71  }
72  else
73  {
74  if (ecm->no_copy)
75  {
76  session_dgram_hdr_t hdr;
77  svm_fifo_t *f = s->data.tx_fifo;
78  app_session_transport_t *at = &s->data.transport;
79  u32 max_enqueue = svm_fifo_max_enqueue (f);
80 
81  if (max_enqueue <= sizeof (session_dgram_hdr_t))
82  return;
83 
84  max_enqueue -= sizeof (session_dgram_hdr_t);
85  rv = clib_min (max_enqueue, bytes_this_chunk);
86 
87  hdr.data_length = rv;
88  hdr.data_offset = 0;
89  clib_memcpy_fast (&hdr.rmt_ip, &at->rmt_ip,
90  sizeof (ip46_address_t));
91  hdr.is_ip4 = at->is_ip4;
92  hdr.rmt_port = at->rmt_port;
93  clib_memcpy_fast (&hdr.lcl_ip, &at->lcl_ip,
94  sizeof (ip46_address_t));
95  hdr.lcl_port = at->lcl_port;
96  svm_fifo_enqueue_nowait (f, sizeof (hdr), (u8 *) & hdr);
100  }
101  else
102  rv = app_send_dgram (&s->data, test_data + test_buf_offset,
103  bytes_this_chunk, 0);
104  }
105 
106  /* If we managed to enqueue data... */
107  if (rv > 0)
108  {
109  /* Account for it... */
110  s->bytes_to_send -= rv;
111  s->bytes_sent += rv;
112 
113  if (ECHO_CLIENT_DBG)
114  {
115  /* *INDENT-OFF* */
116  ELOG_TYPE_DECLARE (e) =
117  {
118  .format = "tx-enq: xfer %d bytes, sent %u remain %u",
119  .format_args = "i4i4i4",
120  };
121  /* *INDENT-ON* */
122  struct
123  {
124  u32 data[3];
125  } *ed;
127  ed->data[0] = rv;
128  ed->data[1] = s->bytes_sent;
129  ed->data[2] = s->bytes_to_send;
130  }
131  }
132 }
133 
134 static void
136 {
137  svm_fifo_t *rx_fifo = s->data.rx_fifo;
138  u32 thread_index = vlib_get_thread_index ();
139  int n_read, i;
140 
141  if (ecm->test_bytes)
142  {
143  if (!ecm->is_dgram)
144  n_read = app_recv_stream (&s->data, ecm->rx_buf[thread_index],
145  vec_len (ecm->rx_buf[thread_index]));
146  else
147  n_read = app_recv_dgram (&s->data, ecm->rx_buf[thread_index],
148  vec_len (ecm->rx_buf[thread_index]));
149  }
150  else
151  {
152  n_read = svm_fifo_max_dequeue (rx_fifo);
153  svm_fifo_dequeue_drop (rx_fifo, n_read);
154  }
155 
156  if (n_read > 0)
157  {
158  if (ECHO_CLIENT_DBG)
159  {
160  /* *INDENT-OFF* */
161  ELOG_TYPE_DECLARE (e) =
162  {
163  .format = "rx-deq: %d bytes",
164  .format_args = "i4",
165  };
166  /* *INDENT-ON* */
167  struct
168  {
169  u32 data[1];
170  } *ed;
172  ed->data[0] = n_read;
173  }
174 
175  if (ecm->test_bytes)
176  {
177  for (i = 0; i < n_read; i++)
178  {
179  if (ecm->rx_buf[thread_index][i]
180  != ((s->bytes_received + i) & 0xff))
181  {
182  clib_warning ("read %d error at byte %lld, 0x%x not 0x%x",
183  n_read, s->bytes_received + i,
184  ecm->rx_buf[thread_index][i],
185  ((s->bytes_received + i) & 0xff));
186  ecm->test_failed = 1;
187  }
188  }
189  }
190  ASSERT (n_read <= s->bytes_to_receive);
191  s->bytes_to_receive -= n_read;
192  s->bytes_received += n_read;
193  }
194 }
195 
196 static uword
198  vlib_frame_t * frame)
199 {
201  int my_thread_index = vlib_get_thread_index ();
202  eclient_session_t *sp;
203  int i;
204  int delete_session;
205  u32 *connection_indices;
206  u32 *connections_this_batch;
207  u32 nconnections_this_batch;
208 
209  connection_indices = ecm->connection_index_by_thread[my_thread_index];
210  connections_this_batch =
211  ecm->connections_this_batch_by_thread[my_thread_index];
212 
213  if ((ecm->run_test != ECHO_CLIENTS_RUNNING) ||
214  ((vec_len (connection_indices) == 0)
215  && vec_len (connections_this_batch) == 0))
216  return 0;
217 
218  /* Grab another pile of connections */
219  if (PREDICT_FALSE (vec_len (connections_this_batch) == 0))
220  {
221  nconnections_this_batch =
222  clib_min (ecm->connections_per_batch, vec_len (connection_indices));
223 
224  ASSERT (nconnections_this_batch > 0);
225  vec_validate (connections_this_batch, nconnections_this_batch - 1);
226  clib_memcpy_fast (connections_this_batch,
227  connection_indices + vec_len (connection_indices)
228  - nconnections_this_batch,
229  nconnections_this_batch * sizeof (u32));
230  _vec_len (connection_indices) -= nconnections_this_batch;
231  }
232 
234  && ecm->prev_conns == vec_len (connections_this_batch)))
235  {
236  ecm->repeats++;
237  ecm->prev_conns = vec_len (connections_this_batch);
238  if (ecm->repeats == 500000)
239  {
240  clib_warning ("stuck clients");
241  }
242  }
243  else
244  {
245  ecm->prev_conns = vec_len (connections_this_batch);
246  ecm->repeats = 0;
247  }
248 
249  for (i = 0; i < vec_len (connections_this_batch); i++)
250  {
251  delete_session = 1;
252 
253  sp = pool_elt_at_index (ecm->sessions, connections_this_batch[i]);
254 
255  if (sp->bytes_to_send > 0)
256  {
257  send_data_chunk (ecm, sp);
258  delete_session = 0;
259  }
260  if (sp->bytes_to_receive > 0)
261  {
262  delete_session = 0;
263  }
264  if (PREDICT_FALSE (delete_session == 1))
265  {
266  stream_session_t *s;
267 
271 
272  if (s)
273  {
274  vnet_disconnect_args_t _a, *a = &_a;
275  a->handle = session_handle (s);
276  a->app_index = ecm->app_index;
278 
279  vec_delete (connections_this_batch, 1, i);
280  i--;
282  }
283  else
284  {
285  clib_warning ("session AWOL?");
286  vec_delete (connections_this_batch, 1, i);
287  }
288 
289  /* Kick the debug CLI process */
290  if (ecm->ready_connections == 0)
291  {
292  signal_evt_to_cli (2);
293  }
294  }
295  }
296 
297  ecm->connection_index_by_thread[my_thread_index] = connection_indices;
298  ecm->connections_this_batch_by_thread[my_thread_index] =
299  connections_this_batch;
300  return 0;
301 }
302 
303 /* *INDENT-OFF* */
305 {
306  .function = echo_client_node_fn,
307  .name = "echo-clients",
308  .type = VLIB_NODE_TYPE_INPUT,
309  .state = VLIB_NODE_STATE_DISABLED,
310 };
311 /* *INDENT-ON* */
312 
313 static int
315 {
316  api_main_t *am = &api_main;
317  vl_shmem_hdr_t *shmem_hdr;
318 
319  shmem_hdr = am->shmem_hdr;
320  ecm->vl_input_queue = shmem_hdr->vl_input_queue;
321  ecm->my_client_index = vl_api_memclnt_create_internal ("echo_client",
322  ecm->vl_input_queue);
323  return 0;
324 }
325 
326 static int
328 {
331  u32 num_threads;
332  int i;
333 
334  if (create_api_loopback (ecm))
335  return -1;
336 
337  num_threads = 1 /* main thread */ + vtm->n_threads;
338 
339  /* Init test data. Big buffer */
340  vec_validate (ecm->connect_test_data, 4 * 1024 * 1024 - 1);
341  for (i = 0; i < vec_len (ecm->connect_test_data); i++)
342  ecm->connect_test_data[i] = i & 0xff;
343 
344  vec_validate (ecm->rx_buf, num_threads - 1);
345  for (i = 0; i < num_threads; i++)
346  vec_validate (ecm->rx_buf[i], vec_len (ecm->connect_test_data) - 1);
347 
348  ecm->is_init = 1;
349 
353 
354  return 0;
355 }
356 
357 static int
359  stream_session_t * s, u8 is_fail)
360 {
362  eclient_session_t *session;
363  u32 session_index;
364  u8 thread_index;
365 
367  return -1;
368 
369  if (is_fail)
370  {
371  clib_warning ("connection %d failed!", api_context);
373  signal_evt_to_cli (-1);
374  return 0;
375  }
376 
377  thread_index = s->thread_index;
378  ASSERT (thread_index == vlib_get_thread_index ()
380 
381  if (!ecm->vpp_event_queue[thread_index])
382  ecm->vpp_event_queue[thread_index] =
384 
385  /*
386  * Setup session
387  */
389  pool_get (ecm->sessions, session);
391 
392  clib_memset (session, 0, sizeof (*session));
393  session_index = session - ecm->sessions;
394  session->bytes_to_send = ecm->bytes_to_send;
395  session->bytes_to_receive = ecm->no_return ? 0ULL : ecm->bytes_to_send;
396  session->data.rx_fifo = s->server_rx_fifo;
397  session->data.rx_fifo->client_session_index = session_index;
398  session->data.tx_fifo = s->server_tx_fifo;
399  session->data.tx_fifo->client_session_index = session_index;
400  session->data.vpp_evt_q = ecm->vpp_event_queue[thread_index];
401  session->vpp_session_handle = session_handle (s);
402 
403  if (ecm->is_dgram)
404  {
406  tc = session_get_transport (s);
407  clib_memcpy_fast (&session->data.transport, tc,
408  sizeof (session->data.transport));
409  session->data.is_dgram = 1;
410  }
411 
412  vec_add1 (ecm->connection_index_by_thread[thread_index], session_index);
414  if (ecm->ready_connections == ecm->expected_connections)
415  {
417  /* Signal the CLI process that the action is starting... */
418  signal_evt_to_cli (1);
419  }
420 
421  return 0;
422 }
423 
424 static void
426 {
428  vnet_disconnect_args_t _a = { 0 }, *a = &_a;
429 
430  if (s->session_state == SESSION_STATE_READY)
431  clib_warning ("Reset active connection %U", format_stream_session, s, 2);
432 
433  a->handle = session_handle (s);
434  a->app_index = ecm->app_index;
436  return;
437 }
438 
439 static int
441 {
442  return 0;
443 }
444 
445 static void
447 {
449  vnet_disconnect_args_t _a = { 0 }, *a = &_a;
450  a->handle = session_handle (s);
451  a->app_index = ecm->app_index;
453  return;
454 }
455 
456 void
458 {
460  vnet_disconnect_args_t _a = { 0 }, *a = &_a;
461  a->handle = session_handle (s);
462  a->app_index = ecm->app_index;
464 }
465 
466 static int
468 {
470  eclient_session_t *sp;
471 
473  {
475  return -1;
476  }
477 
478  sp = pool_elt_at_index (ecm->sessions,
479  s->server_rx_fifo->client_session_index);
480  receive_data_chunk (ecm, sp);
481 
482  if (svm_fifo_max_dequeue (s->server_rx_fifo))
483  {
484  if (svm_fifo_set_event (s->server_rx_fifo))
485  session_send_io_evt_to_thread (s->server_rx_fifo,
487  }
488  return 0;
489 }
490 
491 int
492 echo_client_add_segment_callback (u32 client_index, u64 segment_handle)
493 {
494  /* New heaps may be added */
495  return 0;
496 }
497 
498 /* *INDENT-OFF* */
500  .session_reset_callback = echo_clients_session_reset_callback,
501  .session_connected_callback = echo_clients_session_connected_callback,
502  .session_accept_callback = echo_clients_session_create_callback,
503  .session_disconnect_callback = echo_clients_session_disconnect_callback,
504  .builtin_app_rx_callback = echo_clients_rx_callback,
505  .add_segment_callback = echo_client_add_segment_callback
506 };
507 /* *INDENT-ON* */
508 
509 static clib_error_t *
510 echo_clients_attach (u8 * appns_id, u64 appns_flags, u64 appns_secret)
511 {
512  u32 prealloc_fifos, segment_size = 256 << 20;
514  vnet_app_attach_args_t _a, *a = &_a;
515  u64 options[16];
516  clib_error_t *error = 0;
517 
518  clib_memset (a, 0, sizeof (*a));
519  clib_memset (options, 0, sizeof (options));
520 
521  a->api_client_index = ecm->my_client_index;
522  a->session_cb_vft = &echo_clients;
523 
524  prealloc_fifos = ecm->prealloc_fifos ? ecm->expected_connections : 1;
525 
526  if (ecm->private_segment_size)
527  segment_size = ecm->private_segment_size;
528 
529  options[APP_OPTIONS_ACCEPT_COOKIE] = 0x12345678;
530  options[APP_OPTIONS_SEGMENT_SIZE] = segment_size;
531  options[APP_OPTIONS_ADD_SEGMENT_SIZE] = segment_size;
532  options[APP_OPTIONS_RX_FIFO_SIZE] = ecm->fifo_size;
533  options[APP_OPTIONS_TX_FIFO_SIZE] = ecm->fifo_size;
535  options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = prealloc_fifos;
536  options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
537  options[APP_OPTIONS_TLS_ENGINE] = ecm->tls_engine;
538  if (appns_id)
539  {
540  options[APP_OPTIONS_FLAGS] |= appns_flags;
541  options[APP_OPTIONS_NAMESPACE_SECRET] = appns_secret;
542  }
543  a->options = options;
544  a->namespace_id = appns_id;
545 
546  if ((error = vnet_application_attach (a)))
547  return error;
548 
549  ecm->app_index = a->app_index;
550  return 0;
551 }
552 
553 static int
555 {
557  vnet_app_detach_args_t _da, *da = &_da;
558  int rv;
559 
560  da->app_index = ecm->app_index;
561  da->api_client_index = ~0;
562  rv = vnet_application_detach (da);
563  ecm->test_client_attached = 0;
564  ecm->app_index = ~0;
565  return rv;
566 }
567 
568 static void *
570 {
571  return 0;
572 }
573 
574 /** Start a transmit thread */
575 int
577 {
578  if (ecm->client_thread_handle == 0)
579  {
580  int rv = pthread_create (&ecm->client_thread_handle,
581  NULL /*attr */ ,
583  if (rv)
584  {
585  ecm->client_thread_handle = 0;
586  return -1;
587  }
588  }
589  return 0;
590 }
591 
592 clib_error_t *
594 {
596  vnet_connect_args_t _a, *a = &_a;
597  clib_error_t *error = 0;
598  int i;
599 
600  clib_memset (a, 0, sizeof (*a));
601  for (i = 0; i < n_clients; i++)
602  {
603  a->uri = (char *) ecm->connect_uri;
604  a->api_context = i;
605  a->app_index = ecm->app_index;
606 
607  if ((error = vnet_connect_uri (a)))
608  return error;
609 
610  /* Crude pacing for call setups */
611  if ((i % 4) == 0)
612  vlib_process_suspend (vm, 10e-6);
613  ASSERT (i + 1 >= ecm->ready_connections);
614  while (i + 1 - ecm->ready_connections > 1000)
615  {
616  vlib_process_suspend (vm, 100e-6);
617  }
618  }
619  return 0;
620 }
621 
622 #define ec_cli_output(_fmt, _args...) \
623  if (!ecm->no_output) \
624  vlib_cli_output(vm, _fmt, ##_args)
625 
626 static clib_error_t *
628  unformat_input_t * input, vlib_cli_command_t * cmd)
629 {
631  vlib_thread_main_t *thread_main = vlib_get_thread_main ();
632  u64 tmp, total_bytes, appns_flags = 0, appns_secret = 0;
633  f64 test_timeout = 20.0, syn_timeout = 20.0, delta;
634  char *default_uri = "tcp://6.0.1.1/1234";
635  uword *event_data = 0, event_type;
636  f64 time_before_connects;
637  u32 n_clients = 1;
638  int preallocate_sessions = 0;
639  char *transfer_type;
640  clib_error_t *error = 0;
641  u8 *appns_id = 0;
642  int i;
643 
644  ecm->bytes_to_send = 8192;
645  ecm->no_return = 0;
646  ecm->fifo_size = 64 << 10;
647  ecm->connections_per_batch = 1000;
648  ecm->private_segment_count = 0;
649  ecm->private_segment_size = 0;
650  ecm->no_output = 0;
651  ecm->test_bytes = 0;
652  ecm->test_failed = 0;
653  ecm->vlib_main = vm;
655  ecm->no_copy = 0;
657 
658  if (thread_main->n_vlib_mains > 1)
660  vec_free (ecm->connect_uri);
661 
663  {
664  if (unformat (input, "uri %s", &ecm->connect_uri))
665  ;
666  else if (unformat (input, "nclients %d", &n_clients))
667  ;
668  else if (unformat (input, "mbytes %lld", &tmp))
669  ecm->bytes_to_send = tmp << 20;
670  else if (unformat (input, "gbytes %lld", &tmp))
671  ecm->bytes_to_send = tmp << 30;
672  else if (unformat (input, "bytes %lld", &ecm->bytes_to_send))
673  ;
674  else if (unformat (input, "test-timeout %f", &test_timeout))
675  ;
676  else if (unformat (input, "syn-timeout %f", &syn_timeout))
677  ;
678  else if (unformat (input, "no-return"))
679  ecm->no_return = 1;
680  else if (unformat (input, "fifo-size %d", &ecm->fifo_size))
681  ecm->fifo_size <<= 10;
682  else if (unformat (input, "private-segment-count %d",
683  &ecm->private_segment_count))
684  ;
685  else if (unformat (input, "private-segment-size %U",
686  unformat_memory_size, &tmp))
687  {
688  if (tmp >= 0x100000000ULL)
689  return clib_error_return
690  (0, "private segment size %lld (%llu) too large", tmp, tmp);
691  ecm->private_segment_size = tmp;
692  }
693  else if (unformat (input, "preallocate-fifos"))
694  ecm->prealloc_fifos = 1;
695  else if (unformat (input, "preallocate-sessions"))
696  preallocate_sessions = 1;
697  else
698  if (unformat (input, "client-batch %d", &ecm->connections_per_batch))
699  ;
700  else if (unformat (input, "appns %_%v%_", &appns_id))
701  ;
702  else if (unformat (input, "all-scope"))
703  appns_flags |= (APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE
704  | APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE);
705  else if (unformat (input, "local-scope"))
706  appns_flags = APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
707  else if (unformat (input, "global-scope"))
708  appns_flags = APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
709  else if (unformat (input, "secret %lu", &appns_secret))
710  ;
711  else if (unformat (input, "no-output"))
712  ecm->no_output = 1;
713  else if (unformat (input, "test-bytes"))
714  ecm->test_bytes = 1;
715  else if (unformat (input, "tls-engine %d", &ecm->tls_engine))
716  ;
717  else
718  return clib_error_return (0, "failed: unknown input `%U'",
719  format_unformat_error, input);
720  }
721 
722  /* Store cli process node index for signalling */
723  ecm->cli_node_index =
725 
726  if (ecm->is_init == 0)
727  {
728  if (echo_clients_init (vm))
729  return clib_error_return (0, "failed init");
730  }
731 
732 
733  ecm->ready_connections = 0;
734  ecm->expected_connections = n_clients;
735  ecm->rx_total = 0;
736  ecm->tx_total = 0;
737 
738  if (!ecm->connect_uri)
739  {
740  clib_warning ("No uri provided. Using default: %s", default_uri);
741  ecm->connect_uri = format (0, "%s%c", default_uri, 0);
742  }
743 
744  if (ecm->connect_uri[0] == 'u' && ecm->connect_uri[3] != 'c')
745  ecm->is_dgram = 1;
746 
747 #if ECHO_CLIENT_PTHREAD
749 #endif
750 
752  vnet_session_enable_disable (vm, 1 /* turn on session and transports */ );
754 
755  if (ecm->test_client_attached == 0)
756  {
757  if ((error = echo_clients_attach (appns_id, appns_flags, appns_secret)))
758  {
759  vec_free (appns_id);
760  clib_error_report (error);
761  return error;
762  }
763  vec_free (appns_id);
764  }
765  ecm->test_client_attached = 1;
766 
767  /* Turn on the builtin client input nodes */
768  for (i = 0; i < thread_main->n_vlib_mains; i++)
770  VLIB_NODE_STATE_POLLING);
771 
772  if (preallocate_sessions)
773  pool_init_fixed (ecm->sessions, 1.1 * n_clients);
774 
775  /* Fire off connect requests */
776  time_before_connects = vlib_time_now (vm);
777  if ((error = echo_clients_connect (vm, n_clients)))
778  goto cleanup;
779 
780  /* Park until the sessions come up, or ten seconds elapse... */
781  vlib_process_wait_for_event_or_clock (vm, syn_timeout);
782  event_type = vlib_process_get_events (vm, &event_data);
783  switch (event_type)
784  {
785  case ~0:
786  ec_cli_output ("Timeout with only %d sessions active...",
787  ecm->ready_connections);
788  error = clib_error_return (0, "failed: syn timeout with %d sessions",
789  ecm->ready_connections);
790  goto cleanup;
791 
792  case 1:
793  delta = vlib_time_now (vm) - time_before_connects;
794  if (delta != 0.0)
795  ec_cli_output ("%d three-way handshakes in %.2f seconds %.2f/s",
796  n_clients, delta, ((f64) n_clients) / delta);
797 
799  ec_cli_output ("Test started at %.6f", ecm->test_start_time);
800  break;
801 
802  default:
803  ec_cli_output ("unexpected event(1): %d", event_type);
804  error = clib_error_return (0, "failed: unexpected event(1): %d",
805  event_type);
806  goto cleanup;
807  }
808 
809  /* Now wait for the sessions to finish... */
810  vlib_process_wait_for_event_or_clock (vm, test_timeout);
811  event_type = vlib_process_get_events (vm, &event_data);
812  switch (event_type)
813  {
814  case ~0:
815  ec_cli_output ("Timeout with %d sessions still active...",
816  ecm->ready_connections);
817  error = clib_error_return (0, "failed: timeout with %d sessions",
818  ecm->ready_connections);
819  goto cleanup;
820 
821  case 2:
822  ecm->test_end_time = vlib_time_now (vm);
823  ec_cli_output ("Test finished at %.6f", ecm->test_end_time);
824  break;
825 
826  default:
827  ec_cli_output ("unexpected event(2): %d", event_type);
828  error = clib_error_return (0, "failed: unexpected event(2): %d",
829  event_type);
830  goto cleanup;
831  }
832 
833  delta = ecm->test_end_time - ecm->test_start_time;
834  if (delta != 0.0)
835  {
836  total_bytes = (ecm->no_return ? ecm->tx_total : ecm->rx_total);
837  transfer_type = ecm->no_return ? "half-duplex" : "full-duplex";
838  ec_cli_output ("%lld bytes (%lld mbytes, %lld gbytes) in %.2f seconds",
839  total_bytes, total_bytes / (1ULL << 20),
840  total_bytes / (1ULL << 30), delta);
841  ec_cli_output ("%.2f bytes/second %s", ((f64) total_bytes) / (delta),
842  transfer_type);
843  ec_cli_output ("%.4f gbit/second %s",
844  (((f64) total_bytes * 8.0) / delta / 1e9),
845  transfer_type);
846  }
847  else
848  {
849  ec_cli_output ("zero delta-t?");
850  error = clib_error_return (0, "failed: zero delta-t");
851  goto cleanup;
852  }
853 
854  if (ecm->test_bytes && ecm->test_failed)
855  error = clib_error_return (0, "failed: test bytes");
856 
857 cleanup:
860  for (i = 0; i < vec_len (ecm->connection_index_by_thread); i++)
861  {
864  }
865 
866  pool_free (ecm->sessions);
867 
868  /* Detach the application, so we can use different fifo sizes next time */
869  if (ecm->test_client_attached)
870  {
871  if (echo_clients_detach ())
872  {
873  error = clib_error_return (0, "failed: app detach");
874  ec_cli_output ("WARNING: app detach failed...");
875  }
876  }
877  if (error)
878  ec_cli_output ("test failed");
879  vec_free (ecm->connect_uri);
880  return error;
881 }
882 
883 /* *INDENT-OFF* */
884 VLIB_CLI_COMMAND (echo_clients_command, static) =
885 {
886  .path = "test echo clients",
887  .short_help = "test echo clients [nclients %d][[m|g]bytes <bytes>]"
888  "[test-timeout <time>][syn-timeout <time>][no-return][fifo-size <size>]"
889  "[private-segment-count <count>][private-segment-size <bytes>[m|g]]"
890  "[preallocate-fifos][preallocate-sessions][client-batch <batch-size>]"
891  "[uri <tcp://ip/port>][test-bytes][no-output]",
892  .function = echo_clients_command_fn,
893  .is_mp_safe = 1,
894 };
895 /* *INDENT-ON* */
896 
897 clib_error_t *
899 {
901  ecm->is_init = 0;
902  return 0;
903 }
904 
906 
907 /*
908  * fd.io coding-style-patch-verification: ON
909  *
910  * Local Variables:
911  * eval: (c-set-style "gnu")
912  * End:
913  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
int echo_client_add_segment_callback(u32 client_index, u64 segment_handle)
Definition: echo_client.c:492
vlib_main_t vlib_global_main
Definition: main.c:1857
vlib_main_t * vlib_main
Definition: echo_client.h:105
clib_error_t * echo_clients_connect(vlib_main_t *vm, u32 n_clients)
Definition: echo_client.c:593
#define clib_min(x, y)
Definition: clib.h:295
u32 vl_api_memclnt_create_internal(char *name, svm_queue_t *q)
Definition: memory_api.c:120
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:703
u8 is_ip4
set if uses ip4 networking
vlib_node_runtime_t node_runtime
Definition: node.h:577
a
Definition: bitmap.h:538
void echo_clients_session_disconnect(stream_session_t *s)
Definition: echo_client.c:457
struct _transport_connection transport_connection_t
struct _vnet_connect_args vnet_connect_args_t
static session_cb_vft_t echo_clients
Definition: echo_client.c:499
unsigned long u64
Definition: types.h:89
u32 tls_engine
TLS engine mbedtls/openssl.
Definition: echo_client.h:66
static int echo_clients_detach()
Definition: echo_client.c:554
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
#define NULL
Definition: clib.h:58
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:232
static uword echo_client_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: echo_client.c:197
u32 expected_connections
Number of clients/connections.
Definition: echo_client.h:62
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:98
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:525
eclient_session_t * sessions
Session pool, shared.
Definition: echo_client.h:73
static int app_send_stream(app_session_t *s, u8 *data, u32 len, u8 noblock)
u64 bytes_to_send
Bytes to send.
Definition: echo_client.h:59
int i
static void receive_data_chunk(echo_client_main_t *ecm, eclient_session_t *s)
Definition: echo_client.c:135
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
volatile int run_test
Signal start of test.
Definition: echo_client.h:85
transport_connection_t * session_get_transport(stream_session_t *s)
Definition: session.c:1358
static u32 svm_fifo_max_enqueue(svm_fifo_t *f)
Definition: svm_fifo.h:142
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
vlib_main_t ** vlib_mains
Definition: buffer.c:310
unsigned char u8
Definition: types.h:56
static void echo_clients_session_disconnect_callback(stream_session_t *s)
Definition: echo_client.c:446
app_session_t data
Definition: echo_client.h:34
u8 * connect_test_data
Pre-computed test data.
Definition: echo_client.h:76
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
double f64
Definition: types.h:142
#define vlib_worker_thread_barrier_sync(X)
Definition: threads.h:204
struct _svm_fifo svm_fifo_t
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:452
static void svm_fifo_enqueue_nocopy(svm_fifo_t *f, u32 bytes)
Advance tail pointer.
Definition: svm_fifo.h:227
connectionless service
clib_error_t * echo_clients_main_init(vlib_main_t *vm)
Definition: echo_client.c:898
static svm_msg_q_t * session_manager_get_vpp_event_queue(u32 thread_index)
Definition: session.h:656
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
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:546
struct _vnet_disconnect_args_t vnet_disconnect_args_t
int echo_clients_start_tx_pthread(echo_client_main_t *ecm)
Start a transmit thread.
Definition: echo_client.c:576
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
Definition: svm_fifo.h:124
struct _stream_session_cb_vft session_cb_vft_t
#define clib_error_return(e, args...)
Definition: error.h:99
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: vlib_api.c:623
u32 app_index
app index after attach
Definition: echo_client.h:53
int svm_fifo_enqueue_nowait(svm_fifo_t *f, u32 max_bytes, const u8 *copy_from_here)
Definition: svm_fifo.c:530
svm_queue_t * vl_input_queue
vpe input queue
Definition: echo_client.h:48
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
Definition: api_common.h:265
svm_msg_q_t ** vpp_event_queue
Definition: echo_client.h:49
unsigned int u32
Definition: types.h:88
struct _stream_session_t stream_session_t
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
Definition: session.c:88
struct _vnet_app_attach_args_t vnet_app_attach_args_t
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:57
static int create_api_loopback(echo_client_main_t *ecm)
Definition: echo_client.c:314
static void signal_evt_to_cli(int code)
Definition: echo_client.c:36
static clib_error_t * echo_clients_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: echo_client.c:627
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:511
volatile u32 ready_connections
Definition: echo_client.h:81
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:964
struct _unformat_input_t unformat_input_t
static session_handle_t session_handle(stream_session_t *s)
Definition: session.h:364
static void cleanup(void)
Definition: client.c:130
#define ELOG_DATA(em, f)
Definition: elog.h:481
#define PREDICT_FALSE(x)
Definition: clib.h:111
ip46_address_t rmt_ip
remote ip
u32 ** connection_index_by_thread
Definition: echo_client.h:77
u32 private_segment_count
Number of private fifo segs.
Definition: echo_client.h:64
u32 ** connections_this_batch_by_thread
active connection batch
Definition: echo_client.h:78
u32 node_index
Node index.
Definition: node.h:519
static int echo_clients_rx_callback(stream_session_t *s)
Definition: echo_client.c:467
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
Definition: session.c:1529
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:202
#define pool_free(p)
Free a pool.
Definition: pool.h:404
static int echo_clients_session_create_callback(stream_session_t *s)
Definition: echo_client.c:440
static u8 svm_fifo_set_event(svm_fifo_t *f)
Sets fifo event flag.
Definition: svm_fifo.h:167
u32 no_copy
Don&#39;t memcpy data to tx fifo.
Definition: echo_client.h:68
u32 connections_per_batch
Connections to rx/tx at once.
Definition: echo_client.h:63
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:212
static clib_error_t * echo_clients_attach(u8 *appns_id, u64 appns_flags, u64 appns_secret)
Definition: echo_client.c:510
static vlib_process_t * vlib_get_current_process(vlib_main_t *vm)
Definition: node_funcs.h:421
vlib_main_t * vm
Definition: buffer.c:301
vlib_node_registration_t echo_clients_node
(constructor) VLIB_REGISTER_NODE (echo_clients_node)
Definition: echo_client.c:304
u8 * format_stream_session(u8 *s, va_list *args)
Format stream session as per the following format.
Definition: session_cli.c:57
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
transport_service_type_t session_transport_service_type(stream_session_t *s)
Definition: session.c:1211
#define clib_warning(format, args...)
Definition: error.h:59
echo_client_main_t echo_client_main
Definition: echo_client.c:23
elog_main_t elog_main
Definition: main.h:157
int vnet_disconnect_session(vnet_disconnect_args_t *a)
#define ELOG_TYPE_DECLARE(f)
Definition: elog.h:439
u32 private_segment_size
size of private fifo segs
Definition: echo_client.h:65
static int app_recv_stream(app_session_t *s, u8 *buf, u32 len)
svm_queue_t * vl_input_queue
Definition: memory_shared.h:84
static void send_data_chunk(echo_client_main_t *ecm, eclient_session_t *s)
Definition: echo_client.c:46
#define pool_init_fixed(pool, max_elts)
initialize a fixed-size, preallocated pool
Definition: pool.h:86
static stream_session_t * session_get_from_handle_if_valid(session_handle_t handle)
Definition: session.h:399
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
#define ASSERT(truth)
u32 cli_node_index
cli process node index
Definition: echo_client.h:51
static int echo_clients_session_connected_callback(u32 app_index, u32 api_context, stream_session_t *s, u8 is_fail)
Definition: echo_client.c:358
#define vec_delete(V, N, M)
Delete N elements starting at element M.
Definition: vec.h:788
u32 my_client_index
loopback API client handle
Definition: echo_client.h:52
static int app_send_dgram(app_session_t *s, u8 *data, u32 len, u8 noblock)
#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:148
#define ECHO_CLIENT_DBG
Definition: echo_client.c:25
u16 lcl_port
local port (network order)
struct _vnet_app_detach_args_t vnet_app_detach_args_t
u8 ** rx_buf
intermediate rx buffers
Definition: echo_client.h:75
#define clib_atomic_fetch_add(a, b)
Definition: atomics.h:23
ip46_address_t lcl_ip
local ip
u8 prealloc_fifos
Request fifo preallocation.
Definition: echo_client.h:100
volatile u64 tx_total
Definition: echo_client.h:84
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 max_bytes)
Definition: svm_fifo.c:734
volatile u64 rx_total
Definition: echo_client.h:83
clib_error_t * vnet_connect_uri(vnet_connect_args_t *a)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
clib_error_t * vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
u8 * connect_uri
URI for slave&#39;s connect.
Definition: echo_client.h:58
#define ec_cli_output(_fmt, _args...)
Definition: echo_client.c:622
u64 uword
Definition: types.h:112
clib_spinlock_t sessions_lock
Definition: echo_client.h:74
static void * echo_client_thread_fn(void *arg)
Definition: echo_client.c:569
int session_send_io_evt_to_thread_custom(void *data, u32 thread_index, session_evt_type_t evt_type)
Definition: session.c:94
static void echo_clients_session_reset_callback(stream_session_t *s)
Definition: echo_client.c:425
unformat_function_t unformat_memory_size
Definition: format.h:295
static void signal_evt_to_cli_i(int *code)
Definition: echo_client.c:28
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:1468
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
pthread_t client_thread_handle
Definition: echo_client.h:79
api_main_t api_main
Definition: api_shared.c:35
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:82
static int echo_clients_init(vlib_main_t *vm)
Definition: echo_client.c:327
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
static int app_recv_dgram(app_session_t *s, u8 *buf, u32 len)
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170
u16 rmt_port
remote port (network order)