FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
nsim.c
Go to the documentation of this file.
1 /*
2  * nsim.c - skeleton vpp engine plug-in
3  *
4  * Copyright (c) <current-year> <your-organization>
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 /**
19  * @file
20  * @brief Network Delay Simulator
21  */
22 /*? %%clicmd:group_label Network Delay Simulator %% ?*/
23 
24 #include <vnet/vnet.h>
25 #include <vnet/plugin/plugin.h>
26 #include <nsim/nsim.h>
27 
28 #include <vlibapi/api.h>
29 #include <vlibmemory/api.h>
30 #include <vpp/app/version.h>
31 
32 /* define message IDs */
33 #include <nsim/nsim.api_enum.h>
34 #include <nsim/nsim.api_types.h>
35 
36 #define REPLY_MSG_ID_BASE nsm->msg_id_base
38 
40 
41 /* Action functions shared between message handlers and debug CLI */
42 
43 int
45  u32 sw_if_index1, int enable_disable)
46 {
49  int rv = 0;
50 
51  if (nsm->is_configured == 0)
52  return VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
53 
54  /* Utterly wrong? */
56  sw_if_index0))
57  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
58 
60  sw_if_index1))
61  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
62 
63  /* Not a physical port? */
64  sw = vnet_get_sw_interface (nsm->vnet_main, sw_if_index0);
66  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
67 
68  sw = vnet_get_sw_interface (nsm->vnet_main, sw_if_index1);
70  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
71 
72  /* Add graph arcs for the input / wheel scraper node */
73  hw = vnet_get_hw_interface (nsm->vnet_main, sw_if_index0);
74  nsm->output_next_index0 =
77 
78  hw = vnet_get_hw_interface (nsm->vnet_main, sw_if_index1);
79  nsm->output_next_index1 =
82 
83  nsm->sw_if_index0 = sw_if_index0;
84  nsm->sw_if_index1 = sw_if_index1;
85 
86  vnet_feature_enable_disable ("device-input", "nsim",
87  sw_if_index0, enable_disable, 0, 0);
88  vnet_feature_enable_disable ("device-input", "nsim",
89  sw_if_index1, enable_disable, 0, 0);
90 
91  return rv;
92 }
93 
94 int
96  int enable_disable)
97 {
100  int rv = 0;
101 
102  if (nsm->is_configured == 0)
103  return VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
104 
105  /* Utterly wrong? */
107  sw_if_index))
108  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
109 
110  /* Not a physical port? */
113  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
114 
115  /* Add a graph arc for the input / wheel scraper node */
118  ~0);
119  /* Note: use the tx node, this pkt has already visited the output node... */
122  hw->tx_node_index);
123 
124  vnet_feature_enable_disable ("interface-output", "nsim-output-feature",
125  sw_if_index, enable_disable, 0, 0);
126  return rv;
127 }
128 
129 static nsim_wheel_t *
130 nsim_wheel_alloc (nsim_main_t * nsm, u32 wheel_slots)
131 {
132  u32 pagesize = getpagesize ();
133  nsim_wheel_t *wp;
134 
135  nsm->mmap_size = sizeof (nsim_wheel_t)
136  + wheel_slots * sizeof (nsim_wheel_entry_t);
137 
138  nsm->mmap_size += pagesize - 1;
139  nsm->mmap_size &= ~(pagesize - 1);
140 
141  wp = clib_mem_vm_alloc (nsm->mmap_size);
142  ASSERT (wp != 0);
143  wp->wheel_size = wheel_slots;
144  wp->cursize = 0;
145  wp->head = 0;
146  wp->tail = 0;
147  wp->entries = (void *) (wp + 1);
148 
149  return wp;
150 }
151 
152 static int
153 nsim_configure (nsim_main_t * nsm, f64 bandwidth, f64 delay, f64 packet_size,
154  f64 drop_fraction, f64 reorder_fraction)
155 {
156  u64 total_buffer_size_in_bytes, per_worker_buffer_size, wheel_slots_per_wrk;
157  int i, num_workers = vlib_num_workers ();
158  vlib_main_t *vm = nsm->vlib_main;
159 
160  if (bandwidth == 0.0)
161  return VNET_API_ERROR_INVALID_VALUE;
162 
163  if (delay == 0.0)
164  return VNET_API_ERROR_INVALID_VALUE_2;
165 
166  if (packet_size < 64.0 || packet_size > 9000.0)
167  return VNET_API_ERROR_INVALID_VALUE_3;
168 
169  if (reorder_fraction > 0.0 && delay == 0.0)
170  return VNET_API_ERROR_INVALID_VALUE_4;
171 
172  /* Toss the old wheel(s)... */
173  if (nsm->is_configured)
174  {
175  for (i = 0; i < vec_len (nsm->wheel_by_thread); i++)
176  {
178  nsm->wheel_by_thread[i] = 0;
179  }
180  }
181 
182  nsm->delay = delay;
183  nsm->drop_fraction = drop_fraction;
184  nsm->reorder_fraction = reorder_fraction;
185 
186  /* delay in seconds, bandwidth in bits/sec */
187  total_buffer_size_in_bytes = ((delay * bandwidth) / 8.0) + 0.5;
188 
189  /*
190  * Work out how much buffering each worker needs, assuming decent
191  * RSS behavior.
192  */
193  if (num_workers)
194  per_worker_buffer_size = total_buffer_size_in_bytes / num_workers;
195  else
196  per_worker_buffer_size = total_buffer_size_in_bytes;
197 
198  wheel_slots_per_wrk = per_worker_buffer_size / packet_size;
199  wheel_slots_per_wrk++;
200 
201  /* Save these for the show command */
202  nsm->bandwidth = bandwidth;
203  nsm->packet_size = packet_size;
204 
205  vec_validate (nsm->wheel_by_thread, num_workers);
206 
207  /* Initialize the output scheduler wheels */
208  i = (!nsm->poll_main_thread && num_workers) ? 1 : 0;
209  for (; i < num_workers + 1; i++)
210  nsm->wheel_by_thread[i] = nsim_wheel_alloc (nsm, wheel_slots_per_wrk);
211 
213 
214  /* turn on the ring scrapers */
215  i = (!nsm->poll_main_thread && num_workers) ? 1 : 0;
216  for (; i < num_workers + 1; i++)
217  {
218  vlib_main_t *this_vm = vlib_get_main_by_index (i);
219 
220  vlib_node_set_state (this_vm, nsim_input_node.index,
221  VLIB_NODE_STATE_POLLING);
222  }
223 
225 
226  nsm->is_configured = 1;
227  return 0;
228 }
229 
230 /*
231  * enable or disable the cross-connect
232  */
233 static clib_error_t *
235  unformat_input_t * input,
236  vlib_cli_command_t * cmd)
237 {
238  nsim_main_t *nsm = &nsim_main;
239  unformat_input_t _line_input, *line_input = &_line_input;
240  u32 sw_if_index0 = ~0;
241  u32 sw_if_index1 = ~0;
242  int enable_disable = 1;
243  u32 tmp;
244  int rv;
245 
246  /* Get a line of input. */
247  if (!unformat_user (input, unformat_line_input, line_input))
248  return 0;
249 
250  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
251  {
252  if (unformat (line_input, "disable"))
253  enable_disable = 0;
254  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
255  nsm->vnet_main, &tmp))
256  {
257  if (sw_if_index0 == ~0)
258  sw_if_index0 = tmp;
259  else
260  sw_if_index1 = tmp;
261  }
262  else
263  break;
264  }
265 
266  unformat_free (line_input);
267 
268  if (sw_if_index0 == ~0 || sw_if_index1 == ~0)
269  return clib_error_return (0, "Please specify two interfaces...");
270 
271  rv = nsim_cross_connect_enable_disable (nsm, sw_if_index0,
272  sw_if_index1, enable_disable);
273 
274  switch (rv)
275  {
276  case 0:
277  break;
278 
279  case VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE:
280  return clib_error_return (0, "Not configured, please 'set nsim' first");
281 
282  case VNET_API_ERROR_INVALID_SW_IF_INDEX:
283  return clib_error_return
284  (0, "Invalid interface, only works on physical ports");
285  break;
286 
287  case VNET_API_ERROR_UNIMPLEMENTED:
288  return clib_error_return (0,
289  "Device driver doesn't support redirection");
290  break;
291 
292  default:
293  return clib_error_return (0, "nsim_enable_disable returned %d", rv);
294  }
295  return 0;
296 }
297 
298 static clib_error_t *
300 {
301  nsim_main_t *nsm = &nsim_main;
302 
304  {
305  if (unformat (input, "poll-main-thread"))
306  {
307  nsm->poll_main_thread = 1;
308  }
309  else
310  {
311  return clib_error_return (0, "unknown input '%U'",
312  format_unformat_error, input);
313  }
314  }
315  return 0;
316 }
317 
319 
320 /*?
321  * Enable or disable network simulation cross-connect on two interfaces
322  * The network simulator must have already been configured, see
323  * the "nsim_configure" command.
324  *
325  * Place the interfaces into a bridge group, to ensure that
326  * interfaces are in promiscuous mode.
327  *
328  * @cliexpar
329  * To enable or disable network simulation cross-connect
330  * @clistart
331  * nsim cross-connect enable-disable TenGigabitEthernet2/0/0 TenGigabitEthernet2/0
332  * nsim cross-connect enable-disable TenGigabitEthernet2/0/0 TenGigabitEthernet2/0 disable
333  * @cliend
334  * @cliexcmd{nsim enable-disable <intfc> <intfc> [disable]}
335 ?*/
336 /* *INDENT-OFF* */
338 {
339  .path = "nsim cross-connect enable-disable",
340  .short_help =
341  "nsim cross-connect enable-disable <interface-name-1> "
342  "<interface-name-2> [disable]",
344 };
345 /* *INDENT-ON* */
346 
347 /* API message handler */
350 {
351  vl_api_nsim_cross_connect_enable_disable_reply_t *rmp;
352  nsim_main_t *nsm = &nsim_main;
353  int rv;
354  u32 sw_if_index0, sw_if_index1;
355 
356  sw_if_index0 = clib_net_to_host_u32 (mp->sw_if_index0);
357  sw_if_index1 = clib_net_to_host_u32 (mp->sw_if_index1);
358 
359  if (!vnet_sw_if_index_is_api_valid (sw_if_index0))
360  {
361  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
362  goto bad_sw_if_index;
363  }
364  if (!vnet_sw_if_index_is_api_valid (sw_if_index1))
365  {
366  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
367  goto bad_sw_if_index;
368  }
369 
370  rv = nsim_cross_connect_enable_disable (nsm, sw_if_index0, sw_if_index1,
371  (int) (mp->enable_disable));
372 
374  REPLY_MACRO (VL_API_NSIM_CROSS_CONNECT_ENABLE_DISABLE_REPLY);
375 }
376 
377 /* API message handler */
380 {
381  vl_api_nsim_output_feature_enable_disable_reply_t *rmp;
382  nsim_main_t *nsm = &nsim_main;
383  int rv;
385 
387  (int) (mp->enable_disable));
388 
390  REPLY_MACRO (VL_API_NSIM_OUTPUT_FEATURE_ENABLE_DISABLE_REPLY);
391 }
392 
393 /* API message handler */
394 static void
396 {
397  vl_api_nsim_configure_reply_t *rmp;
398  nsim_main_t *nsm = &nsim_main;
399  f64 delay, bandwidth, packet_size, drop_fraction = 0.0, reorder_rate = 0.0;
400  u32 packets_per_drop;
401  int rv;
402 
403  delay = ((f64) (ntohl (mp->delay_in_usec))) * 1e-6;
404  bandwidth = (f64) (clib_net_to_host_u64 (mp->bandwidth_in_bits_per_second));
405  packet_size = (f64) (ntohl (mp->average_packet_size));
406 
407  packets_per_drop = ntohl (mp->packets_per_drop);
408  if (packets_per_drop > 0)
409  drop_fraction = 1.0 / (f64) (packets_per_drop);
410 
411  rv = nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction,
412  reorder_rate);
413 
414  REPLY_MACRO (VL_API_NSIM_CONFIGURE_REPLY);
415 }
416 
417 static void
419 {
420  vl_api_nsim_configure_reply_t *rmp;
421  nsim_main_t *nsm = &nsim_main;
422  f64 delay, bandwidth, packet_size, drop_fraction = 0.0, reorder_rate = 0.0;
423  u32 packets_per_drop, packets_per_reorder;
424  int rv;
425 
426  delay = ((f64) (ntohl (mp->delay_in_usec))) * 1e-6;
427  bandwidth = (f64) (clib_net_to_host_u64 (mp->bandwidth_in_bits_per_second));
428  packet_size = (f64) (ntohl (mp->average_packet_size));
429 
430  packets_per_drop = ntohl (mp->packets_per_drop);
431  if (packets_per_drop > 0)
432  drop_fraction = 1.0 / (f64) (packets_per_drop);
433 
434  packets_per_reorder = ntohl (mp->packets_per_reorder);
435  if (packets_per_reorder > 0)
436  reorder_rate = 1.0 / (f64) packets_per_reorder;
437 
438  rv = nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction,
439  reorder_rate);
440 
441  REPLY_MACRO (VL_API_NSIM_CONFIGURE2_REPLY);
442 }
443 
444 
445 /*
446  * enable or disable the output_feature
447  */
448 static clib_error_t *
450  unformat_input_t * input,
451  vlib_cli_command_t * cmd)
452 {
453  nsim_main_t *nsm = &nsim_main;
454  unformat_input_t _line_input, *line_input = &_line_input;
455  u32 sw_if_index = ~0;
456  int enable_disable = 1;
457  int rv;
458 
459  /* Get a line of input. */
460  if (!unformat_user (input, unformat_line_input, line_input))
461  return 0;
462 
463  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
464  {
465  if (unformat (line_input, "disable"))
466  enable_disable = 0;
467  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
468  nsm->vnet_main, &sw_if_index))
469  ;
470  else
471  {
472  clib_error_t *error = clib_error_return (0, "unknown input `%U'",
474  line_input);
475  unformat_free (line_input);
476  return error;
477  }
478  }
479 
480  unformat_free (line_input);
481 
482  if (sw_if_index == ~0)
483  return clib_error_return (0, "Please specify one interface...");
484 
485  rv = nsim_output_feature_enable_disable (nsm, sw_if_index, enable_disable);
486 
487  switch (rv)
488  {
489  case 0:
490  break;
491 
492  case VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE:
493  return clib_error_return (0, "Not configured, please 'set nsim' first");
494 
495  case VNET_API_ERROR_INVALID_SW_IF_INDEX:
496  return clib_error_return
497  (0, "Invalid interface, only works on physical ports");
498  break;
499 
500  case VNET_API_ERROR_UNIMPLEMENTED:
501  return clib_error_return (0,
502  "Device driver doesn't support redirection");
503  break;
504 
505  default:
506  return clib_error_return
507  (0, "nsim_output_feature_enable_disable returned %d", rv);
508  }
509  return 0;
510 }
511 
512 /*?
513  * Enable or disable network simulation output feature on an interface
514  * The network simulator must have already been configured, see
515  * the "nsim_configure" command.
516  *
517  * @cliexpar
518  * To enable or disable network simulation output feature
519  * @clistart
520  * nsim output-feature enable-disable TenGigabitEthernet2/0/0
521  * nsim output-feature enable-disable TenGigabitEthernet2/0/0 disable
522  * @cliend
523  * @cliexcmd{nsim output-feature enable-disable <intfc> [disable]}
524 ?*/
525 /* *INDENT-OFF* */
527 {
528  .path = "nsim output-feature enable-disable",
529  .short_help =
530  "nsim output-feature enable-disable <interface-name> [disable]",
532 };
533 /* *INDENT-ON* */
534 
535 #include <nsim/nsim.api.c>
536 static clib_error_t *
538 {
539  nsim_main_t *nsm = &nsim_main;
540 
541  nsm->vlib_main = vm;
542  nsm->vnet_main = vnet_get_main ();
543 
544  /* Ask for a correctly-sized block of API message decode slots */
547  return 0;
548 }
549 
551 
552 /* *INDENT-OFF* */
553 VNET_FEATURE_INIT (nsim, static) =
554 {
555  .arc_name = "device-input",
556  .node_name = "nsim",
557  .runs_before = VNET_FEATURES ("ethernet-input"),
558 };
559 /* *INDENT-ON */
560 
561 /* *INDENT-OFF* */
562 VNET_FEATURE_INIT (nsim_feature, static) = {
563  .arc_name = "interface-output",
564  .node_name = "nsim-output-feature",
565  .runs_before = VNET_FEATURES ("interface-output-arc-end"),
566 };
567 /* *INDENT-ON */
568 
569 /* *INDENT-OFF* */
571 {
572  .version = VPP_BUILD_VER,
573  .description = "Network Delay Simulator",
574 };
575 /* *INDENT-ON* */
576 
577 static uword
578 unformat_delay (unformat_input_t * input, va_list * args)
579 {
580  f64 *result = va_arg (*args, f64 *);
581  f64 tmp;
582 
583  if (unformat (input, "%f us", &tmp))
584  *result = tmp * 1e-6;
585  else if (unformat (input, "%f ms", &tmp))
586  *result = tmp * 1e-3;
587  else if (unformat (input, "%f sec", &tmp))
588  *result = tmp;
589  else
590  return 0;
591 
592  return 1;
593 }
594 
595 static uword
596 unformat_bandwidth (unformat_input_t * input, va_list * args)
597 {
598  f64 *result = va_arg (*args, f64 *);
599  f64 tmp;
600 
601  if (unformat (input, "%f gbit", &tmp))
602  *result = tmp * 1e9;
603  else if (unformat (input, "%f gbyte", &tmp))
604  *result = tmp * 8e9;
605  else
606  return 0;
607  return 1;
608 }
609 
610 static u8 *
611 format_nsim_config (u8 * s, va_list * args)
612 {
613  int verbose = va_arg (*args, int);
614  nsim_main_t *nsm = &nsim_main;
615 
616  s = format (s, "configuration\n");
617  s = format (s, " delay (ms): %.2f\n", nsm->delay * 1e3);
618  if (nsm->drop_fraction)
619  s = format (s, " drop fraction: %.5f\n", nsm->drop_fraction);
620  else
621  s = format (s, " drop fraction: 0\n");
622  if (nsm->reorder_fraction)
623  s = format (s, " reorder fraction: %.5f\n", nsm->reorder_fraction);
624  else
625  s = format (s, " reorder fraction: 0\n");
626  s = format (s, " packet size: %u\n", nsm->packet_size);
627  s = format (s, " throughput (Gbps): %.2f\n", nsm->bandwidth / 1e9);
628 
629  if (verbose)
630  {
631  s = format (s, " poll main thread: %u\n", nsm->poll_main_thread);
632  s = format (s, " memory: %U bytes per thread %U bytes total\n",
634  nsm->mmap_size * vlib_num_workers ());
635  }
636 
637  s = format (s, "\n");
638 
639  if (nsm->sw_if_index0 != 0)
640  {
641  s = format (s, "cross-connect\n %U and %U\n",
644  nsm->vnet_main, nsm->sw_if_index1);
645  }
647  {
648  int i;
649  s = format (s, "output feature arcs to:\n");
650  for (i = 0; i < vec_len (nsm->output_next_index_by_sw_if_index); i++)
651  {
652  if (nsm->output_next_index_by_sw_if_index[i] != ~0)
653  s = format (s, " %U %u\n", format_vnet_sw_if_index_name,
654  nsm->vnet_main, i, i);
655  }
656  }
657  else
658  {
659  s = format (s, " nsim not enabled\n");
660  }
661 
662  return s;
663 }
664 
665 static clib_error_t *
667  unformat_input_t * input, vlib_cli_command_t * cmd)
668 {
669  f64 drop_fraction = 0.0, reorder_fraction = 0.0;
670  f64 delay, bandwidth, packet_size = 1500.0;
671  u32 packets_per_drop, packets_per_reorder;
672  nsim_main_t *nsm = &nsim_main;
673  int rv;
674 
676  {
677  if (unformat (input, "delay %U", unformat_delay, &delay))
678  ;
679  else if (unformat (input, "bandwidth %U", unformat_bandwidth,
680  &bandwidth))
681  ;
682  else if (unformat (input, "packet-size %f", &packet_size))
683  ;
684  else if (unformat (input, "packets-per-drop %d", &packets_per_drop))
685  {
686  if (packets_per_drop > 0)
687  drop_fraction = 1.0 / ((f64) packets_per_drop);
688  }
689  else if (unformat (input, "packets-per-reorder %d",
690  &packets_per_reorder))
691  {
692  if (packets_per_reorder > 0)
693  reorder_fraction = 1.0 / ((f64) packets_per_reorder);
694  }
695  else if (unformat (input, "drop-fraction %f", &drop_fraction))
696  {
697  if (drop_fraction < 0.0 || drop_fraction > 1.0)
698  return clib_error_return
699  (0, "drop fraction must be between zero and 1");
700  }
701  else if (unformat (input, "reorder-fraction %f", &reorder_fraction))
702  {
703  if (reorder_fraction < 0.0 || reorder_fraction > 1.0)
704  return clib_error_return
705  (0, "reorder fraction must be between zero and 1");
706  }
707  else if (unformat (input, "poll-main-thread"))
708  nsm->poll_main_thread = 1;
709  else
710  break;
711  }
712 
713  rv = nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction,
714  reorder_fraction);
715 
716  switch (rv)
717  {
718  case VNET_API_ERROR_INVALID_VALUE:
719  return clib_error_return (0, "invalid bandwidth %.2f", bandwidth);
720 
721  case VNET_API_ERROR_INVALID_VALUE_2:
722  return clib_error_return (0, "invalid delay %.2f", delay);
723 
724  case VNET_API_ERROR_INVALID_VALUE_3:
725  return clib_error_return (0, "invalid packet size %.2f", packet_size);
726 
727  case VNET_API_ERROR_INVALID_VALUE_4:
728  return clib_error_return (0, "invalid reorder fraction %.3f for "
729  "delay %.2f", reorder_fraction, delay);
730 
731  default:
732  return clib_error_return (0, "error %d", rv);
733 
734  case 0:
735  break;
736  }
737 
739 
740  return 0;
741 }
742 
743 /*?
744  * Configure the network simulation cross-connect
745  * Once the simulator is configured, use the "nsim enable-disable" command
746  * to set up a cross-connect with the supplied delay characteristics.
747  *
748  * The cross connect configuration may be changed without restarting vpp
749  * but it is good practice to shut down the interfaces.
750  *
751  * @cliexpar
752  * To configure the network delay simulator:
753  * @clistart
754  * set nsim delay 10.0 ms bandwidth 5.5 gbit packet-size 128
755  *
756  * @cliend
757  * @cliexcmd{set nsim delay <nn> bandwidth <bb> packet-size <nn>}
758 ?*/
759 /* *INDENT-OFF* */
761 {
762  .path = "set nsim",
763  .short_help = "set nsim delay <time> bandwidth <bps> packet-size <nbytes>\n"
764  " [packets-per-drop <nn>][drop-fraction <f64: 0.0 - 1.0>]",
765  .function = set_nsim_command_fn,
766 };
767 /* *INDENT-ON*/
768 
769 
770 static clib_error_t *
772  unformat_input_t * input, vlib_cli_command_t * cmd)
773 {
774  nsim_main_t *nsm = &nsim_main;
775  int verbose = 0;
776 
777  if (nsm->is_configured == 0)
778  return clib_error_return (0, "Network simulator not configured");
779 
780  if (unformat (input, "verbose"))
781  verbose = 1;
782 
783  vlib_cli_output (vm, "%U", format_nsim_config, verbose);
784 
785  return 0;
786 }
787 
788 /*?
789  * Display state info for the network delay simulator.
790  *
791  * @cliexpar
792  * To display the state of the network simulator
793  * @clistart
794  * show nsim verbose
795  * Network simulator cross-connects TenGigabitEthernet2/0/0 and TenGigabitEthernet2/0/1
796  * ...inserting link delay of 10.00 ms, 20.00 ms round-trip
797  * Configured bandwidth: 10.10 gbit/sec
798  * Configured packet size: 128
799  * Sim uses 157814784 bytes total
800  * @cliend
801  * @cliexcmd{show nsim}
802 ?*/
803 
804 /* *INDENT-OFF* */
806 {
807  .path = "show nsim",
808  .short_help = "Display network delay simulator configuration",
809  .function = show_nsim_command_fn,
810 };
811 /* *INDENT-ON* */
812 
813 /*
814  * fd.io coding-style-patch-verification: ON
815  *
816  * Local Variables:
817  * eval: (c-set-style "gnu")
818  * End:
819  */
vl_api_nsim_output_feature_enable_disable_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: nsim.api:51
tmp
u32 * tmp
Definition: interface_output.c:1096
VALIDATE_SW_IF_INDEX
#define VALIDATE_SW_IF_INDEX(mp)
Definition: api_helper_macros.h:281
nsim_wheel_t::tail
u32 tail
Definition: nsim.h:45
vlib_num_workers
static u32 vlib_num_workers()
Definition: threads.h:333
nsim_main_t::msg_id_base
u16 msg_id_base
Definition: nsim.h:83
api.h
vl_api_nsim_cross_connect_enable_disable_t
enable / disable the network delay simulation cross-connect
Definition: nsim.api:16
vlib_worker_thread_barrier_release
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1375
nsim_main_t::delay
f64 delay
Definition: nsim.h:102
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
vnet_sw_interface_t::type
vnet_sw_interface_type_t type
Definition: interface.h:871
set_nsim_command
static vlib_cli_command_t set_nsim_command
(constructor) VLIB_CLI_COMMAND (set_nsim_command)
Definition: nsim.c:760
vnet_sw_interface_t
Definition: interface.h:869
vlib_node_add_next
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1177
vl_api_nsim_configure2_t::packets_per_reorder
u32 packets_per_reorder
Definition: nsim.api:99
nsim_main_t::drop_fraction
f64 drop_fraction
Definition: nsim.h:105
nsim_configure
static int nsim_configure(nsim_main_t *nsm, f64 bandwidth, f64 delay, f64 packet_size, f64 drop_fraction, f64 reorder_fraction)
Definition: nsim.c:153
nsim_main_t::poll_main_thread
u32 poll_main_thread
Definition: nsim.h:107
vl_api_nsim_cross_connect_enable_disable_t_handler
static void vl_api_nsim_cross_connect_enable_disable_t_handler(vl_api_nsim_cross_connect_enable_disable_t *mp)
Definition: nsim.c:349
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
vlib_node_set_state
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:175
show_nsim_command
static vlib_cli_command_t show_nsim_command
(constructor) VLIB_CLI_COMMAND (show_nsim_command)
Definition: nsim.c:805
unformat_bandwidth
static uword unformat_bandwidth(unformat_input_t *input, va_list *args)
Definition: nsim.c:596
vl_api_nsim_output_feature_enable_disable_t
enable / disable the network delay simulation output feature
Definition: nsim.api:39
vl_api_nsim_configure2_t_handler
static void vl_api_nsim_configure2_t_handler(vl_api_nsim_configure2_t *mp)
Definition: nsim.c:418
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vl_api_nsim_configure2_t::delay_in_usec
u32 delay_in_usec
Definition: nsim.api:95
vlib_cli_command_t::path
char * path
Definition: cli.h:96
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
vnet_hw_interface_t::tx_node_index
u32 tx_node_index
Definition: interface.h:653
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
vnet_get_sw_interface
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:58
nsim_main_t::reorder_fraction
f64 reorder_fraction
Definition: nsim.h:106
nsim_main_t::vlib_main
vlib_main_t * vlib_main
Definition: nsim.h:115
unformat_input_t
struct _unformat_input_t unformat_input_t
nsim_wheel_t
Definition: nsim.h:40
set_nsim_command_fn
static clib_error_t * set_nsim_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nsim.c:666
error
Definition: cJSON.c:88
nsim_main_t::packet_size
f64 packet_size
Definition: nsim.h:104
nsim_main_t::is_configured
int is_configured
Definition: nsim.h:112
nsim_wheel_alloc
static nsim_wheel_t * nsim_wheel_alloc(nsim_main_t *nsm, u32 wheel_slots)
Definition: nsim.c:130
nsim_output_feature_enable_disable_command_fn
static clib_error_t * nsim_output_feature_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nsim.c:449
VLIB_CONFIG_FUNCTION
#define VLIB_CONFIG_FUNCTION(x, n,...)
Definition: init.h:181
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
nsim_main_t::vnet_main
vnet_main_t * vnet_main
Definition: nsim.h:116
VNET_FEATURE_INIT
VNET_FEATURE_INIT(nsim, static)
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
nsim_main_t::sw_if_index1
u32 sw_if_index1
Definition: nsim.h:89
nsim_wheel_entry_t
Definition: nsim.h:30
vnet_get_hw_interface
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface_funcs.h:44
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
vlib_worker_thread_barrier_sync
#define vlib_worker_thread_barrier_sync(X)
Definition: threads.h:173
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
nsim_main_t::sw_if_index0
u32 sw_if_index0
Definition: nsim.h:89
vlib_config_function_runtime_t
Definition: init.h:68
nsim_init
static clib_error_t * nsim_init(vlib_main_t *vm)
Definition: nsim.c:537
uword
u64 uword
Definition: types.h:112
vl_api_nsim_cross_connect_enable_disable_t::sw_if_index0
vl_api_interface_index_t sw_if_index0
Definition: nsim.api:28
nsim_main_t::bandwidth
f64 bandwidth
Definition: nsim.h:103
nsim_cross_connect_enable_disable_command_fn
static clib_error_t * nsim_cross_connect_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nsim.c:234
vl_api_nsim_configure2_t::bandwidth_in_bits_per_second
u64 bandwidth_in_bits_per_second
Definition: nsim.api:97
nsim_cross_connect_enable_disable
int nsim_cross_connect_enable_disable(nsim_main_t *nsm, u32 sw_if_index0, u32 sw_if_index1, int enable_disable)
Definition: nsim.c:44
f64
double f64
Definition: types.h:142
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
nsim_output_feature_enable_disable
int nsim_output_feature_enable_disable(nsim_main_t *nsm, u32 sw_if_index, int enable_disable)
Definition: nsim.c:95
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
clib_mem_vm_free
static void clib_mem_vm_free(void *addr, uword size)
Definition: mem.h:446
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
nsim_main
nsim_main_t nsim_main
Definition: nsim.c:39
format_memory_size
u8 * format_memory_size(u8 *s, va_list *va)
Definition: std-formats.c:209
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
vnet_interface_main_t::sw_interfaces
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:1015
nsim_main_t::wheel_by_thread
nsim_wheel_t ** wheel_by_thread
Definition: nsim.h:99
vl_api_nsim_output_feature_enable_disable_t_handler
static void vl_api_nsim_output_feature_enable_disable_t_handler(vl_api_nsim_output_feature_enable_disable_t *mp)
Definition: nsim.c:379
vl_api_nsim_configure_t::packets_per_drop
u32 packets_per_drop
Definition: nsim.api:75
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
plugin.h
show_nsim_command_fn
static clib_error_t * show_nsim_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nsim.c:771
vnet_sw_if_index_is_api_valid
static uword vnet_sw_if_index_is_api_valid(u32 sw_if_index)
Definition: api_helper_macros.h:276
vnet_hw_interface_t
Definition: interface.h:638
nsim_wheel_t::head
u32 head
Definition: nsim.h:44
unformat_delay
static uword unformat_delay(unformat_input_t *input, va_list *args)
Definition: nsim.c:578
nsim_enable_disable_command
static vlib_cli_command_t nsim_enable_disable_command
(constructor) VLIB_CLI_COMMAND (nsim_enable_disable_command)
Definition: nsim.c:337
vl_api_nsim_configure_t::average_packet_size
u32 average_packet_size
Definition: nsim.api:73
u64
unsigned long u64
Definition: types.h:89
format_vnet_sw_if_index_name
format_function_t format_vnet_sw_if_index_name
Definition: interface_funcs.h:458
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:462
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
clib_mem_vm_alloc
static void * clib_mem_vm_alloc(uword size)
Definition: mem.h:427
vec_validate_init_empty
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header,...
Definition: vec.h:570
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
vl_api_nsim_configure2_t::average_packet_size
u32 average_packet_size
Definition: nsim.api:96
nsim_wheel_t::cursize
u32 cursize
Definition: nsim.h:43
vl_api_nsim_configure2_t::packets_per_drop
u32 packets_per_drop
Definition: nsim.api:98
nsim_config
static clib_error_t * nsim_config(vlib_main_t *vm, unformat_input_t *input)
Definition: nsim.c:299
api_helper_macros.h
nsim_input_node
vlib_node_registration_t nsim_input_node
(constructor) VLIB_REGISTER_NODE (nsim_input_node)
Definition: nsim_input.c:131
vlib_get_main_by_index
static vlib_main_t * vlib_get_main_by_index(u32 thread_index)
Definition: global_funcs.h:29
nsim_main_t
Definition: nsim.h:80
vl_api_nsim_configure2_t
configure the network delay simulation cross-connect
Definition: nsim.api:86
vl_api_nsim_cross_connect_enable_disable_t::sw_if_index1
vl_api_interface_index_t sw_if_index1
Definition: nsim.api:29
nsim_wheel_t::entries
nsim_wheel_entry_t * entries
Definition: nsim.h:46
nsim_wheel_t::wheel_size
u32 wheel_size
Definition: nsim.h:42
vnet_feature_enable_disable
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: pnat_test_stubs.h:50
format_nsim_config
static u8 * format_nsim_config(u8 *s, va_list *args)
Definition: nsim.c:611
vlib_main_t
Definition: main.h:102
VNET_FEATURES
#define VNET_FEATURES(...)
Definition: feature.h:470
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vnet_hw_interface_t::output_node_index
u32 output_node_index
Definition: interface.h:653
vl_api_nsim_configure_t::delay_in_usec
u32 delay_in_usec
Definition: nsim.api:72
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
vl_api_nsim_cross_connect_enable_disable_t::enable_disable
bool enable_disable
Definition: nsim.api:25
i
int i
Definition: flowhash_template.h:376
vl_api_nsim_configure_t_handler
static void vl_api_nsim_configure_t_handler(vl_api_nsim_configure_t *mp)
Definition: nsim.c:395
rv
int __clib_unused rv
Definition: application.c:491
vl_api_nsim_configure_t::bandwidth_in_bits_per_second
u64 bandwidth_in_bits_per_second
Definition: nsim.api:74
nsim_output_feature_enable_disable_command
static vlib_cli_command_t nsim_output_feature_enable_disable_command
(constructor) VLIB_CLI_COMMAND (nsim_output_feature_enable_disable_command)
Definition: nsim.c:526
nsim_main_t::output_next_index1
u32 output_next_index1
Definition: nsim.h:90
nsim_main_t::output_next_index0
u32 output_next_index0
Definition: nsim.h:90
vnet.h
VNET_SW_INTERFACE_TYPE_HARDWARE
@ VNET_SW_INTERFACE_TYPE_HARDWARE
Definition: interface.h:764
vl_api_nsim_configure_t
configure the network delay simulation cross-connect
Definition: nsim.api:62
vl_api_nsim_output_feature_enable_disable_t::enable_disable
bool enable_disable
Definition: nsim.api:48
vlib_cli_command_t
Definition: cli.h:92
nsim_main_t::output_next_index_by_sw_if_index
u32 * output_next_index_by_sw_if_index
Definition: nsim.h:93
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
vnet_interface_main_t::output_feature_arc_index
u8 output_feature_arc_index
Definition: interface.h:1043
nsim_main_t::arc_index
u16 arc_index
Definition: nsim.h:86
nsim_main_t::mmap_size
u64 mmap_size
Definition: nsim.h:109
vnet_main_t::interface_main
vnet_interface_main_t interface_main
Definition: vnet.h:81
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
nsim.h