FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
cli.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /*
16  * cli.c: command line interface
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 #include <vlib/vlib.h>
41 #include <vlib/unix/unix.h>
42 #include <vppinfra/callback.h>
43 #include <vppinfra/cpu.h>
44 #include <vppinfra/elog.h>
45 #include <unistd.h>
46 #include <ctype.h>
47 
48 /** \file src/vlib/cli.c Debug CLI Implementation
49  */
50 
51 int vl_api_set_elog_trace_api_messages (int enable);
53 
54 static void *current_traced_heap;
55 
56 /* Root of all show commands. */
57 /* *INDENT-OFF* */
59  .path = "show",
60  .short_help = "Show commands",
61 };
62 /* *INDENT-ON* */
63 
64 /* Root of all clear commands. */
65 /* *INDENT-OFF* */
67  .path = "clear",
68  .short_help = "Clear commands",
69 };
70 /* *INDENT-ON* */
71 
72 /* Root of all set commands. */
73 /* *INDENT-OFF* */
75  .path = "set",
76  .short_help = "Set commands",
77 };
78 /* *INDENT-ON* */
79 
80 /* Root of all test commands. */
81 /* *INDENT-OFF* */
83  .path = "test",
84  .short_help = "Test commands",
85 };
86 /* *INDENT-ON* */
87 
88 /* Returns bitmap of commands which match key. */
89 static uword *
91 {
92  int i, n;
93  uword *match = 0;
95 
97 
98  for (i = 0;; i++)
99  {
100  uword k;
101 
102  k = unformat_get_input (input);
103  switch (k)
104  {
105  case 'a' ... 'z':
106  case 'A' ... 'Z':
107  case '0' ... '9':
108  case '-':
109  case '_':
110  break;
111 
112  case ' ':
113  case '\t':
114  case '\r':
115  case '\n':
117  /* White space or end of input removes any non-white
118  matches that were before possible. */
119  if (i < vec_len (c->sub_command_positions)
120  && clib_bitmap_count_set_bits (match) > 1)
121  {
122  p = vec_elt_at_index (c->sub_command_positions, i);
123  for (n = 0; n < vec_len (p->bitmaps); n++)
124  match = clib_bitmap_andnot (match, p->bitmaps[n]);
125  }
126  goto done;
127 
128  default:
129  unformat_put_input (input);
130  goto done;
131  }
132 
133  if (i >= vec_len (c->sub_command_positions))
134  {
135  no_match:
136  clib_bitmap_free (match);
137  return 0;
138  }
139 
140  p = vec_elt_at_index (c->sub_command_positions, i);
141  if (vec_len (p->bitmaps) == 0)
142  goto no_match;
143 
144  n = k - p->min_char;
145  if (n < 0 || n >= vec_len (p->bitmaps))
146  goto no_match;
147 
148  if (i == 0)
149  match = clib_bitmap_dup (p->bitmaps[n]);
150  else
151  match = clib_bitmap_and (match, p->bitmaps[n]);
152 
153  if (clib_bitmap_is_zero (match))
154  goto no_match;
155  }
156 
157 done:
158  return match;
159 }
160 
161 /* Looks for string based sub-input formatted { SUB-INPUT }. */
162 uword
164 {
165  unformat_input_t *sub_input = va_arg (*args, unformat_input_t *);
166  u8 *s;
167  uword c;
168 
169  while (1)
170  {
171  c = unformat_get_input (i);
172  switch (c)
173  {
174  case ' ':
175  case '\t':
176  case '\n':
177  case '\r':
178  case '\f':
179  break;
180 
181  case '{':
182  default:
183  /* Put back paren. */
184  if (c != UNFORMAT_END_OF_INPUT)
186 
187  if (c == '{' && unformat (i, "%v", &s))
188  {
189  unformat_init_vector (sub_input, s);
190  return 1;
191  }
192  return 0;
193  }
194  }
195  return 0;
196 }
197 
198 static vlib_cli_command_t *
200 {
202  return vec_elt_at_index (cm->commands, s->index);
203 }
204 
205 static uword
207 {
208  vlib_main_t __clib_unused *vm = va_arg (*args, vlib_main_t *);
210  vlib_cli_command_t *c = va_arg (*args, vlib_cli_command_t *);
211  vlib_cli_command_t **result = va_arg (*args, vlib_cli_command_t **);
212  vlib_cli_main_t *cm = &vgm->cli_main;
213  uword *match_bitmap, is_unique, index;
214 
215  match_bitmap = vlib_cli_sub_command_match (c, i);
216  is_unique = clib_bitmap_count_set_bits (match_bitmap) == 1;
217  index = ~0;
218  if (is_unique)
219  {
220  index = clib_bitmap_first_set (match_bitmap);
221  *result = get_sub_command (cm, c, index);
222  }
223  clib_bitmap_free (match_bitmap);
224 
225  return is_unique;
226 }
227 
228 static int
229 vlib_cli_cmp_strings (void *a1, void *a2)
230 {
231  u8 *c1 = *(u8 **) a1;
232  u8 *c2 = *(u8 **) a2;
233 
234  return vec_cmp (c1, c2);
235 }
236 
237 u8 **
239 {
243  vlib_cli_main_t *vcm = &vgm->cli_main;
244  uword *match_bitmap = 0;
245  uword index, is_unique, help_next_level;
246  u8 **result = 0;
247  unformat_input_t input;
248  unformat_init_vector (&input, vec_dup (str));
249  c = vec_elt_at_index (vcm->commands, 0);
250 
251  /* remove trailing whitespace, except for one of them */
252  while (vec_len (input.buffer) >= 2 &&
253  isspace (input.buffer[vec_len (input.buffer) - 1]) &&
254  isspace (input.buffer[vec_len (input.buffer) - 2]))
255  {
256  vec_del1 (input.buffer, vec_len (input.buffer) - 1);
257  }
258 
259  /* if input is empty, directly return list of root commands */
260  if (vec_len (input.buffer) == 0 ||
261  (vec_len (input.buffer) == 1 && isspace (input.buffer[0])))
262  {
263  vec_foreach (sc, c->sub_commands)
264  {
265  vec_add1 (result, (u8 *) sc->name);
266  }
267  goto done;
268  }
269 
270  /* add a trailing '?' so that vlib_cli_sub_command_match can find
271  * all commands starting with the input string */
272  vec_add1 (input.buffer, '?');
273 
274  while (1)
275  {
276  match_bitmap = vlib_cli_sub_command_match (c, &input);
277  /* no match: return no result */
278  if (match_bitmap == 0)
279  {
280  goto done;
281  }
282  is_unique = clib_bitmap_count_set_bits (match_bitmap) == 1;
283  /* unique match: try to step one subcommand level further */
284  if (is_unique)
285  {
286  /* stop if no more input */
287  if (input.index >= vec_len (input.buffer) - 1)
288  {
289  break;
290  }
291 
292  index = clib_bitmap_first_set (match_bitmap);
293  c = get_sub_command (vcm, c, index);
294  clib_bitmap_free (match_bitmap);
295  continue;
296  }
297  /* multiple matches: stop here, return all matches */
298  break;
299  }
300 
301  /* remove trailing '?' */
302  vec_del1 (input.buffer, vec_len (input.buffer) - 1);
303 
304  /* if we have a space at the end of input, and a unique match,
305  * autocomplete the next level of subcommands */
306  help_next_level = (vec_len (str) == 0) || isspace (str[vec_len (str) - 1]);
307  /* *INDENT-OFF* */
308  clib_bitmap_foreach (index, match_bitmap) {
309  if (help_next_level && is_unique) {
310  c = get_sub_command (vcm, c, index);
311  vec_foreach (sc, c->sub_commands) {
312  vec_add1 (result, (u8*) sc->name);
313  }
314  goto done; /* break doesn't work in this macro-loop */
315  }
316  sc = &c->sub_commands[index];
317  vec_add1(result, (u8*) sc->name);
318  }
319  /* *INDENT-ON* */
320 
321 done:
322  clib_bitmap_free (match_bitmap);
323  unformat_free (&input);
324 
325  if (result)
327  return result;
328 }
329 
330 static u8 *
331 format_vlib_cli_command_help (u8 * s, va_list * args)
332 {
333  vlib_cli_command_t *c = va_arg (*args, vlib_cli_command_t *);
334  int is_long = va_arg (*args, int);
335  if (is_long && c->long_help)
336  s = format (s, "%s", c->long_help);
337  else if (c->short_help)
338  s = format (s, "%s", c->short_help);
339  else
340  s = format (s, "%v commands", c->path);
341  return s;
342 }
343 
344 static u8 *
345 format_vlib_cli_path (u8 * s, va_list * args)
346 {
347  u8 *path = va_arg (*args, u8 *);
348 
349  s = format (s, "%v", path);
350 
351  return s;
352 }
353 
354 static vlib_cli_command_t *
356 {
357  vlib_cli_command_t *c = vec_elt_at_index (cm->commands, command_index);
359 
360  if (c->function)
361  vec_add1 (subs, c[0]);
362 
363  vec_foreach (sc, c->sub_commands) subs = all_subs (cm, subs, sc->index);
364 
365  return subs;
366 }
367 
368 static int
369 vlib_cli_cmp_rule (void *a1, void *a2)
370 {
371  vlib_cli_sub_rule_t *r1 = a1;
372  vlib_cli_sub_rule_t *r2 = a2;
373 
374  return vec_cmp (r1->name, r2->name);
375 }
376 
377 static int
378 vlib_cli_cmp_command (void *a1, void *a2)
379 {
380  vlib_cli_command_t *c1 = a1;
381  vlib_cli_command_t *c2 = a2;
382 
383  return vec_cmp (c1->path, c2->path);
384 }
385 
386 static clib_error_t *
389  unformat_input_t * input,
390  uword parent_command_index)
391 {
393  vlib_cli_command_t *parent, *c;
394  clib_error_t *error = 0;
395  unformat_input_t sub_input;
396  u8 *string;
397  uword is_main_dispatch = cm == &vgm->cli_main;
398 
399  parent = vec_elt_at_index (cm->commands, parent_command_index);
400  if (is_main_dispatch && unformat (input, "help"))
401  {
402  uword help_at_end_of_line, i;
403 
404  help_at_end_of_line =
406  while (1)
407  {
408  c = parent;
409  if (unformat_user
410  (input, unformat_vlib_cli_sub_command, vm, c, &parent))
411  ;
412 
413  else if (!(unformat_check_input (input) == UNFORMAT_END_OF_INPUT))
414  goto unknown;
415 
416  else
417  break;
418  }
419 
420  /* help SUB-COMMAND => long format help.
421  "help" at end of line: show all commands. */
422  if (!help_at_end_of_line)
424  /* is_long */ 1);
425 
426  else if (vec_len (c->sub_commands) == 0)
427  vlib_cli_output (vm, "%v: no sub-commands", c->path);
428 
429  else
430  {
431  vlib_cli_sub_rule_t *sr, *subs = 0;
433 
434  vec_foreach (sc, c->sub_commands)
435  {
436  vec_add2 (subs, sr, 1);
437  sr->name = sc->name;
438  sr->command_index = sc->index;
439  sr->rule_index = ~0;
440  }
441 
443 
444  for (i = 0; i < vec_len (subs); i++)
445  {
447 
448  d = vec_elt_at_index (cm->commands, subs[i].command_index);
450  (vm, " %-30v %U", subs[i].name,
451  format_vlib_cli_command_help, d, /* is_long */ 0);
452  }
453 
454  vec_free (subs);
455  }
456  }
457 
458  else if (is_main_dispatch
459  && (unformat (input, "choices") || unformat (input, "?")))
460  {
461  vlib_cli_command_t *sub, *subs;
462 
463  subs = all_subs (cm, 0, parent_command_index);
465  vec_foreach (sub, subs)
466  vlib_cli_output (vm, " %-40U %U",
468  format_vlib_cli_command_help, sub, /* is_long */ 0);
469  vec_free (subs);
470  }
471 
472  else if (unformat (input, "comment %v", &string))
473  {
474  vec_free (string);
475  }
476 
477  else if (unformat (input, "vpplog %v", &string))
478  {
479  int i;
480  /*
481  * Delete leading whitespace, so "vpplog { this and that }"
482  * and "vpplog this" line up nicely.
483  */
484  for (i = 0; i < vec_len (string); i++)
485  if (string[i] != ' ')
486  break;
487  if (i > 0)
488  vec_delete (string, i, 0);
489 
490  vlib_log_notice (cm->log, "CLI: %v", string);
491  vec_free (string);
492  }
493 
494  else if (unformat (input, "uncomment %U",
495  unformat_vlib_cli_sub_input, &sub_input))
496  {
497  error =
498  vlib_cli_dispatch_sub_commands (vm, cm, &sub_input,
499  parent_command_index);
500  unformat_free (&sub_input);
501  }
502  else if (unformat (input, "leak-check %U",
503  unformat_vlib_cli_sub_input, &sub_input))
504  {
505  u8 *leak_report;
507  {
508  void *oldheap;
510  clib_mem_trace (0);
511  clib_mem_set_heap (oldheap);
513  }
514  clib_mem_trace (1);
515  error =
516  vlib_cli_dispatch_sub_commands (vm, cm, &sub_input,
517  parent_command_index);
518  unformat_free (&sub_input);
519 
520  /* Otherwise, the clib_error_t shows up as a leak... */
521  if (error)
522  {
523  vlib_cli_output (vm, "%v", error->what);
525  error = 0;
526  }
527 
529  leak_report = format (0, "%U", format_clib_mem_heap, 0,
530  1 /* verbose, i.e. print leaks */ );
531  clib_mem_trace (0);
532  vlib_cli_output (vm, "%v", leak_report);
533  vec_free (leak_report);
534  }
535 
536  else
537  if (unformat_user (input, unformat_vlib_cli_sub_command, vm, parent, &c))
538  {
540  uword has_sub_commands =
541  vec_len (c->sub_commands) + vec_len (c->sub_rules) > 0;
542 
543  si = input;
544  if (unformat_user (input, unformat_vlib_cli_sub_input, &sub_input))
545  si = &sub_input;
546 
547  if (has_sub_commands)
548  error = vlib_cli_dispatch_sub_commands (vm, cm, si, c - cm->commands);
549 
550  if (has_sub_commands && !error)
551  /* Found valid sub-command. */ ;
552 
553  else if (c->function)
554  {
555  clib_error_t *c_error;
556 
557  /* Skip white space for benefit of called function. */
559 
560  if (unformat (si, "?"))
561  {
562  vlib_cli_output (vm, " %-40U %U", format_vlib_cli_path, c->path, format_vlib_cli_command_help, c, /* is_long */
563  0);
564  }
565  else
566  {
568  {
569  /* *INDENT-OFF* */
570  ELOG_TYPE_DECLARE (e) =
571  {
572  .format = "cli-cmd: %s",
573  .format_args = "T4",
574  };
575  /* *INDENT-ON* */
576  struct
577  {
578  u32 c;
579  } *ed;
580  ed = ELOG_DATA (vlib_get_elog_main (), e);
581  ed->c = elog_string (vlib_get_elog_main (), "%v", c->path);
582  }
583 
584  if (!c->is_mp_safe)
586  if (PREDICT_FALSE (vec_len (cm->perf_counter_cbs) != 0))
587  clib_call_callbacks (cm->perf_counter_cbs, cm,
588  c - cm->commands, 0 /* before */ );
589 
590  c->hit_counter++;
591  c_error = c->function (vm, si, c);
592 
593  if (PREDICT_FALSE (vec_len (cm->perf_counter_cbs) != 0))
594  clib_call_callbacks (cm->perf_counter_cbs, cm,
595  c - cm->commands, 1 /* after */ );
596  if (!c->is_mp_safe)
598 
600  {
601  /* *INDENT-OFF* */
602  ELOG_TYPE_DECLARE (e) =
603  {
604  .format = "cli-cmd: %s %s",
605  .format_args = "T4T4",
606  };
607  /* *INDENT-ON* */
608  struct
609  {
610  u32 c, err;
611  } *ed;
612  ed = ELOG_DATA (vlib_get_elog_main (), e);
613  ed->c = elog_string (vlib_get_elog_main (), "%v", c->path);
614  if (c_error)
615  {
616  vec_add1 (c_error->what, 0);
617  ed->err = elog_string (vlib_get_elog_main (),
618  (char *) c_error->what);
619  _vec_len (c_error->what) -= 1;
620  }
621  else
622  ed->err = elog_string (vlib_get_elog_main (), "OK");
623  }
624 
625  if (c_error)
626  {
627  error =
628  clib_error_return (0, "%v: %v", c->path, c_error->what);
629  clib_error_free (c_error);
630  /* Free sub input. */
631  if (si != input)
632  unformat_free (si);
633 
634  return error;
635  }
636  }
637 
638  /* Free any previous error. */
640  }
641 
642  else if (!error)
643  error = clib_error_return (0, "%v: no sub-commands", c->path);
644 
645  /* Free sub input. */
646  if (si != input)
647  unformat_free (si);
648  }
649 
650  else
651  goto unknown;
652 
653  return error;
654 
655 unknown:
656  if (parent->path)
657  return clib_error_return (0, "%v: unknown input `%U'", parent->path,
658  format_unformat_error, input);
659  else
660  return clib_error_return (0, "unknown input `%U'", format_unformat_error,
661  input);
662 }
663 
664 
666  __attribute__ ((weak));
667 
668 void
670 {
671 }
672 
673 /* Process CLI input. */
674 int
676  unformat_input_t * input,
677  vlib_cli_output_function_t * function, uword function_arg)
678 {
682  vlib_cli_output_function_t *save_function;
683  uword save_function_arg;
684  int rv = 0;
685 
686  save_function = cp->output_function;
687  save_function_arg = cp->output_function_arg;
688 
689  cp->output_function = function;
690  cp->output_function_arg = function_arg;
691 
692  do
693  {
695  /* parent */ 0);
696  }
697  while (!error && !unformat (input, "%U", unformat_eof));
698 
699  if (error)
700  {
701  vlib_cli_output (vm, "%v", error->what);
703  /* clib_error_return is unfortunately often called with a '0'
704  return code */
705  rv = error->code != 0 ? error->code : -1;
707  }
708 
709  cp->output_function = save_function;
710  cp->output_function_arg = save_function_arg;
711  return rv;
712 }
713 
714 /* Output to current CLI connection. */
715 void
717 {
719  va_list va;
720  u8 *s;
721 
722  va_start (va, fmt);
723  s = va_format (0, fmt, &va);
724  va_end (va);
725 
726  /* some format functions might return 0
727  * e.g. show int addr */
728  if (NULL == s)
729  return;
730 
731  /* Terminate with \n if not present. */
732  if (vec_len (s) > 0 && s[vec_len (s) - 1] != '\n')
733  vec_add1 (s, '\n');
734 
735  if ((!cp) || (!cp->output_function))
736  fformat (stdout, "%v", s);
737  else
738  cp->output_function (cp->output_function_arg, s, vec_len (s));
739 
740  vec_free (s);
741 }
742 
743 void *vl_msg_push_heap (void) __attribute__ ((weak));
744 void *
746 {
747  return 0;
748 }
749 
750 void vl_msg_pop_heap (void *oldheap) __attribute__ ((weak));
751 void
752 vl_msg_pop_heap (void *oldheap)
753 {
754 }
755 
756 void *vlib_stats_push_heap (void *) __attribute__ ((weak));
757 void *
758 vlib_stats_push_heap (void *notused)
759 {
760  return 0;
761 }
762 
763 static clib_error_t *
765  unformat_input_t * input, vlib_cli_command_t * cmd)
766 {
768  int verbose __attribute__ ((unused)) = 0;
769  int api_segment = 0, stats_segment = 0, main_heap = 0, numa_heaps = 0;
770  int map = 0;
772  u32 index = 0;
773  int i;
775  uword was_enabled;
776 
777 
779  {
780  if (unformat (input, "verbose"))
781  verbose = 1;
782  else if (unformat (input, "api-segment"))
783  api_segment = 1;
784  else if (unformat (input, "stats-segment"))
785  stats_segment = 1;
786  else if (unformat (input, "main-heap"))
787  main_heap = 1;
788  else if (unformat (input, "numa-heaps"))
789  numa_heaps = 1;
790  else if (unformat (input, "map"))
791  map = 1;
792  else
793  {
794  error = clib_error_return (0, "unknown input `%U'",
795  format_unformat_error, input);
796  return error;
797  }
798  }
799 
800  if ((api_segment + stats_segment + main_heap + numa_heaps + map) == 0)
801  return clib_error_return
802  (0, "Need one of api-segment, stats-segment, main-heap, numa-heaps "
803  "or map");
804 
805  if (api_segment)
806  {
807  void *oldheap = vl_msg_push_heap ();
808  was_enabled = clib_mem_trace_enable_disable (0);
809  u8 *s_in_svm = format (0, "%U\n", format_clib_mem_heap, 0, 1);
810  vl_msg_pop_heap (oldheap);
811  u8 *s = vec_dup (s_in_svm);
812 
813  oldheap = vl_msg_push_heap ();
814  vec_free (s_in_svm);
815  clib_mem_trace_enable_disable (was_enabled);
816  vl_msg_pop_heap (oldheap);
817  vlib_cli_output (vm, "API segment");
818  vlib_cli_output (vm, "%v", s);
819  vec_free (s);
820  }
821  if (stats_segment)
822  {
823  void *oldheap = vlib_stats_push_heap (0);
824  was_enabled = clib_mem_trace_enable_disable (0);
825  u8 *s_in_svm = format (0, "%U\n", format_clib_mem_heap, 0, 1);
826  if (oldheap)
827  clib_mem_set_heap (oldheap);
828  u8 *s = vec_dup (s_in_svm);
829 
830  oldheap = vlib_stats_push_heap (0);
831  vec_free (s_in_svm);
832  if (oldheap)
833  {
834  clib_mem_trace_enable_disable (was_enabled);
835  clib_mem_set_heap (oldheap);
836  }
837  vlib_cli_output (vm, "Stats segment");
838  vlib_cli_output (vm, "%v", s);
839  vec_free (s);
840  }
841 
842 
843  {
844  if (main_heap)
845  {
846  /*
847  * Note: the foreach_vlib_main causes allocator traffic,
848  * so shut off tracing before we go there...
849  */
850  was_enabled = clib_mem_trace_enable_disable (0);
851 
853  {
854  vlib_cli_output (vm, "%sThread %d %s\n", index ? "\n" : "", index,
857  mm->per_cpu_mheaps[index], verbose);
858  index++;
859  }
860 
861  /* Restore the trace flag */
862  clib_mem_trace_enable_disable (was_enabled);
863  }
864  if (numa_heaps)
865  {
866  for (i = 0; i < ARRAY_LEN (mm->per_numa_mheaps); i++)
867  {
868  if (mm->per_numa_mheaps[i] == 0)
869  continue;
870  if (mm->per_numa_mheaps[i] == mm->per_cpu_mheaps[i])
871  {
872  vlib_cli_output (vm, "Numa %d uses the main heap...", i);
873  continue;
874  }
875  was_enabled = clib_mem_trace_enable_disable (0);
876 
877  vlib_cli_output (vm, "Numa %d:", i);
879  mm->per_numa_mheaps[index], verbose);
880  }
881  }
882  if (map)
883  {
885  clib_mem_vm_map_hdr_t *hdr = 0;
886  u8 *s = 0;
887  int numa = -1;
888 
889  s = format (s, "\n%-16s%7s%5s%7s%7s",
890  "StartAddr", "size", "FD", "PageSz", "Pages");
891  while ((numa = vlib_mem_get_next_numa_node (numa)) != -1)
892  s = format (s, " Numa%u", numa);
893  s = format (s, " NotMap");
894  s = format (s, " Name");
895  vlib_cli_output (vm, "%v", s);
896  vec_reset_length (s);
897 
898  while ((hdr = clib_mem_vm_get_next_map_hdr (hdr)))
899  {
900  clib_mem_get_page_stats ((void *) hdr->base_addr,
901  hdr->log2_page_sz, hdr->num_pages,
902  &stats);
903  s = format (s, "%016lx%7U",
904  hdr->base_addr, format_memory_size,
905  hdr->num_pages << hdr->log2_page_sz);
906 
907  if (hdr->fd != -1)
908  s = format (s, "%5d", hdr->fd);
909  else
910  s = format (s, "%5s", " ");
911 
912  s = format (s, "%7U%7lu",
913  format_log2_page_size, hdr->log2_page_sz,
914  hdr->num_pages);
915  while ((numa = vlib_mem_get_next_numa_node (numa)) != -1)
916  s = format (s, "%6lu", stats.per_numa[numa]);
917  s = format (s, "%7lu", stats.not_mapped);
918  s = format (s, " %s", hdr->name);
919  vlib_cli_output (vm, "%v", s);
920  vec_reset_length (s);
921  }
922  vec_free (s);
923  }
924  }
925  return 0;
926 }
927 
928 /* *INDENT-OFF* */
930  .path = "show memory",
931  .short_help = "show memory [api-segment][stats-segment][verbose]\n"
932  " [numa-heaps][map]",
933  .function = show_memory_usage,
934 };
935 /* *INDENT-ON* */
936 
937 static clib_error_t *
939  vlib_cli_command_t * cmd)
940 {
941 #define _(a,b,c) vlib_cli_output (vm, "%-25s " b, a ":", c);
942  _("Model name", "%U", format_cpu_model_name);
943  _("Microarch model (family)", "%U", format_cpu_uarch);
944  _("Flags", "%U", format_cpu_flags);
945  _("Base frequency", "%.2f GHz",
946  ((f64) vm->clib_time.clocks_per_second) * 1e-9);
947 #undef _
948  return 0;
949 }
950 
951 /*?
952  * Displays various information about the CPU.
953  *
954  * @cliexpar
955  * @cliexstart{show cpu}
956  * Model name: Intel(R) Xeon(R) CPU E5-2667 v4 @ 3.20GHz
957  * Microarchitecture: Broadwell (Broadwell-EP/EX)
958  * Flags: sse3 ssse3 sse41 sse42 avx avx2 aes
959  * Base Frequency: 3.20 GHz
960  * @cliexend
961 ?*/
962 /* *INDENT-OFF* */
964  .path = "show cpu",
965  .short_help = "Show cpu information",
966  .function = show_cpu,
967 };
968 /* *INDENT-ON* */
969 
970 static clib_error_t *
972  unformat_input_t * input,
973  vlib_cli_command_t * cmd)
974 {
976  unformat_input_t _line_input, *line_input = &_line_input;
977  int enable = 1;
978  int api_segment = 0;
979  int stats_segment = 0;
980  int main_heap = 0;
981  u32 numa_id = ~0;
982  void *oldheap;
983 
984  if (!unformat_user (input, unformat_line_input, line_input))
985  return 0;
986 
987  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
988  {
989  if (unformat (line_input, "%U", unformat_vlib_enable_disable, &enable))
990  ;
991  else if (unformat (line_input, "api-segment"))
992  api_segment = 1;
993  else if (unformat (line_input, "stats-segment"))
994  stats_segment = 1;
995  else if (unformat (line_input, "main-heap"))
996  main_heap = 1;
997  else if (unformat (line_input, "numa-heap %d", &numa_id))
998  ;
999  else
1000  {
1001  unformat_free (line_input);
1002  return clib_error_return (0, "invalid input");
1003  }
1004  }
1005  unformat_free (line_input);
1006 
1007  if ((api_segment + stats_segment + main_heap + (enable == 0)
1008  + (numa_id != ~0)) == 0)
1009  {
1010  return clib_error_return
1011  (0, "Need one of main-heap, stats-segment, api-segment,\n"
1012  "numa-heap <nn> or disable");
1013  }
1014 
1015  /* Turn off current trace, if any */
1016  if (current_traced_heap)
1017  {
1018  void *oldheap;
1020  clib_mem_trace (0);
1021  clib_mem_set_heap (oldheap);
1022  current_traced_heap = 0;
1023  }
1024 
1025  if (enable == 0)
1026  return 0;
1027 
1028  /* API segment */
1029  if (api_segment)
1030  {
1031  oldheap = vl_msg_push_heap ();
1033  clib_mem_trace (1);
1034  vl_msg_pop_heap (oldheap);
1035 
1036  }
1037 
1038  /* Stats segment */
1039  if (stats_segment)
1040  {
1041  oldheap = vlib_stats_push_heap (0);
1043  clib_mem_trace (stats_segment);
1044  /* We don't want to call vlib_stats_pop_heap... */
1045  if (oldheap)
1046  clib_mem_set_heap (oldheap);
1047  }
1048 
1049  /* main_heap */
1050  if (main_heap)
1051  {
1053  clib_mem_trace (main_heap);
1054  }
1055 
1056  if (numa_id != ~0)
1057  {
1058  if (numa_id >= ARRAY_LEN (mm->per_numa_mheaps))
1059  return clib_error_return (0, "Numa %d out of range", numa_id);
1060  if (mm->per_numa_mheaps[numa_id] == 0)
1061  return clib_error_return (0, "Numa %d heap not active", numa_id);
1062 
1063  if (mm->per_numa_mheaps[numa_id] == clib_mem_get_heap ())
1064  return clib_error_return (0, "Numa %d uses the main heap...",
1065  numa_id);
1066  current_traced_heap = mm->per_numa_mheaps[numa_id];
1068  clib_mem_trace (1);
1069  clib_mem_set_heap (oldheap);
1070  }
1071 
1072 
1073  return 0;
1074 }
1075 
1076 /* *INDENT-OFF* */
1078  .path = "memory-trace",
1079  .short_help = "memory-trace on|off [api-segment][stats-segment][main-heap]\n"
1080  " [numa-heap <numa-id>]\n",
1081  .function = enable_disable_memory_trace,
1082 };
1083 /* *INDENT-ON* */
1084 
1085 static clib_error_t *
1087  vlib_cli_command_t * cmd)
1088 {
1091  clib_file_t *f;
1092 
1093  /* environ(7) does not indicate a header for this */
1094  extern char **environ;
1095 
1096  /* Close all known open files */
1097  /* *INDENT-OFF* */
1098  pool_foreach (f, fm->file_pool)
1099  {
1100  if (f->file_descriptor > 2)
1101  close(f->file_descriptor);
1102  }
1103  /* *INDENT-ON* */
1104 
1105  /* Exec ourself */
1106  execve (vgm->name, (char **) vm->argv, environ);
1107 
1108  return 0;
1109 }
1110 
1111 /* *INDENT-OFF* */
1113  .path = "restart",
1114  .short_help = "restart process",
1115  .function = restart_cmd_fn,
1116 };
1117 /* *INDENT-ON* */
1118 
1119 #ifdef TEST_CODE
1120 /*
1121  * A trivial test harness to verify the per-process output_function
1122  * is working correcty.
1123  */
1124 
1125 static clib_error_t *
1126 sleep_ten_seconds (vlib_main_t * vm,
1127  unformat_input_t * input, vlib_cli_command_t * cmd)
1128 {
1129  u16 i;
1130  u16 my_id = rand ();
1131 
1132  vlib_cli_output (vm, "Starting 10 seconds sleep with id %u\n", my_id);
1133 
1134  for (i = 0; i < 10; i++)
1135  {
1137  vlib_cli_output (vm, "Iteration number %u, my id: %u\n", i, my_id);
1138  }
1139  vlib_cli_output (vm, "Done with sleep with id %u\n", my_id);
1140  return 0;
1141 }
1142 
1143 /* *INDENT-OFF* */
1144 VLIB_CLI_COMMAND (ping_command, static) = {
1145  .path = "test sleep",
1146  .function = sleep_ten_seconds,
1147  .short_help = "Sleep for 10 seconds",
1148 };
1149 /* *INDENT-ON* */
1150 #endif /* ifdef TEST_CODE */
1151 
1152 static uword
1153 vlib_cli_normalize_path (char *input, char **result)
1154 {
1155  char *i = input;
1156  char *s = 0;
1157  uword l = 0;
1158  uword index_of_last_space = ~0;
1159 
1160  while (*i != 0)
1161  {
1162  u8 c = *i++;
1163  /* Multiple white space -> single space. */
1164  switch (c)
1165  {
1166  case ' ':
1167  case '\t':
1168  case '\n':
1169  case '\r':
1170  if (l > 0 && s[l - 1] != ' ')
1171  {
1172  vec_add1 (s, ' ');
1173  l++;
1174  }
1175  break;
1176 
1177  default:
1178  if (l > 0 && s[l - 1] == ' ')
1179  index_of_last_space = vec_len (s);
1180  vec_add1 (s, c);
1181  l++;
1182  break;
1183  }
1184  }
1185 
1186  /* Remove any extra space at end. */
1187  if (l > 0 && s[l - 1] == ' ')
1188  _vec_len (s) -= 1;
1189 
1190  *result = s;
1191  return index_of_last_space;
1192 }
1193 
1196 {
1197  word i;
1198  for (i = vec_len (path) - 1; i >= 0; i--)
1199  {
1200  if (path[i] == ' ')
1201  return i;
1202  }
1203  return ~0;
1204 }
1205 
1206 static void
1207 add_sub_command (vlib_cli_main_t * cm, uword parent_index, uword child_index)
1208 {
1209  vlib_cli_command_t *p, *c;
1210  vlib_cli_sub_command_t *sub_c;
1211  u8 *sub_name;
1212  word i, l;
1213 
1214  p = vec_elt_at_index (cm->commands, parent_index);
1215  c = vec_elt_at_index (cm->commands, child_index);
1216 
1217  l = parent_path_len (c->path);
1218  if (l == ~0)
1219  sub_name = vec_dup ((u8 *) c->path);
1220  else
1221  {
1222  ASSERT (l + 1 < vec_len (c->path));
1223  sub_name = 0;
1224  vec_add (sub_name, c->path + l + 1, vec_len (c->path) - (l + 1));
1225  }
1226 
1227  /* "Can't happen," check mainly to shut up coverity */
1228  ALWAYS_ASSERT (sub_name != 0);
1229 
1230  if (sub_name[0] == '%')
1231  {
1232  uword *q;
1233  vlib_cli_sub_rule_t *sr;
1234 
1235  /* Remove %. */
1236  vec_delete (sub_name, 1, 0);
1237 
1238  if (!p->sub_rule_index_by_name)
1239  p->sub_rule_index_by_name = hash_create_vec ( /* initial length */ 32,
1240  sizeof (sub_name[0]),
1241  sizeof (uword));
1242  q = hash_get_mem (p->sub_rule_index_by_name, sub_name);
1243  if (q)
1244  {
1245  sr = vec_elt_at_index (p->sub_rules, q[0]);
1246  ASSERT (sr->command_index == child_index);
1247  return;
1248  }
1249 
1250  hash_set_mem (p->sub_rule_index_by_name, sub_name,
1251  vec_len (p->sub_rules));
1252  vec_add2 (p->sub_rules, sr, 1);
1253  sr->name = sub_name;
1254  sr->rule_index = sr - p->sub_rules;
1255  sr->command_index = child_index;
1256  return;
1257  }
1258 
1259  if (!p->sub_command_index_by_name)
1260  p->sub_command_index_by_name = hash_create_vec ( /* initial length */ 32,
1261  sizeof (c->path[0]),
1262  sizeof (uword));
1263 
1264  /* Check if sub-command has already been created. */
1265  if (hash_get_mem (p->sub_command_index_by_name, sub_name))
1266  {
1267  vec_free (sub_name);
1268  return;
1269  }
1270 
1271  vec_add2 (p->sub_commands, sub_c, 1);
1272  sub_c->index = child_index;
1273  sub_c->name = sub_name;
1275  sub_c - p->sub_commands);
1276 
1277  vec_validate (p->sub_command_positions, vec_len (sub_c->name) - 1);
1278  for (i = 0; i < vec_len (sub_c->name); i++)
1279  {
1280  int n;
1282 
1284 
1285  if (!pos->bitmaps)
1286  pos->min_char = sub_c->name[i];
1287 
1288  n = sub_c->name[i] - pos->min_char;
1289  if (n < 0)
1290  {
1291  pos->min_char = sub_c->name[i];
1292  vec_insert (pos->bitmaps, -n, 0);
1293  n = 0;
1294  }
1295 
1296  vec_validate (pos->bitmaps, n);
1297  pos->bitmaps[n] =
1298  clib_bitmap_ori (pos->bitmaps[n], sub_c - p->sub_commands);
1299  }
1300 }
1301 
1302 static void
1304 {
1305  uword p_len, pi, *p;
1306  char *p_path;
1307  vlib_cli_command_t *c, *parent;
1308 
1309  /* Root command (index 0) should have already been added. */
1310  ASSERT (vec_len (cm->commands) > 0);
1311 
1312  c = vec_elt_at_index (cm->commands, ci);
1313  p_len = parent_path_len (c->path);
1314 
1315  /* No space? Parent is root command. */
1316  if (p_len == ~0)
1317  {
1318  add_sub_command (cm, 0, ci);
1319  return;
1320  }
1321 
1322  p_path = 0;
1323  vec_add (p_path, c->path, p_len);
1324 
1325  p = hash_get_mem (cm->command_index_by_path, p_path);
1326 
1327  /* Parent exists? */
1328  if (!p)
1329  {
1330  /* Parent does not exist; create it. */
1331  vec_add2 (cm->commands, parent, 1);
1332  parent->path = p_path;
1333  hash_set_mem (cm->command_index_by_path, parent->path,
1334  parent - cm->commands);
1335  pi = parent - cm->commands;
1336  }
1337  else
1338  {
1339  pi = p[0];
1340  vec_free (p_path);
1341  }
1342 
1343  add_sub_command (cm, pi, ci);
1344 
1345  /* Create parent's parent. */
1346  if (!p)
1347  vlib_cli_make_parent (cm, pi);
1348 }
1349 
1352 {
1353  return (c->long_help == 0 && c->short_help == 0 && c->function == 0);
1354 }
1355 
1356 clib_error_t *
1358 {
1360  vlib_cli_main_t *cm = &vgm->cli_main;
1361  clib_error_t *error = 0;
1362  uword ci, *p;
1363  char *normalized_path;
1364 
1366  return error;
1367 
1368  (void) vlib_cli_normalize_path (c->path, &normalized_path);
1369 
1370  if (!cm->command_index_by_path)
1371  cm->command_index_by_path = hash_create_vec ( /* initial length */ 32,
1372  sizeof (c->path[0]),
1373  sizeof (uword));
1374 
1375  /* See if command already exists with given path. */
1376  p = hash_get_mem (cm->command_index_by_path, normalized_path);
1377  if (p)
1378  {
1379  vlib_cli_command_t *d;
1380 
1381  ci = p[0];
1382  d = vec_elt_at_index (cm->commands, ci);
1383 
1384  /* If existing command was created via vlib_cli_make_parent
1385  replaced it with callers data. */
1386  if (vlib_cli_command_is_empty (d))
1387  {
1388  vlib_cli_command_t save = d[0];
1389 
1391 
1392  /* Copy callers fields. */
1393  d[0] = c[0];
1394 
1395  /* Save internal fields. */
1396  d->path = save.path;
1397  d->sub_commands = save.sub_commands;
1400  d->sub_rules = save.sub_rules;
1401  }
1402  else
1403  error =
1404  clib_error_return (0, "duplicate command name with path %v",
1405  normalized_path);
1406 
1407  vec_free (normalized_path);
1408  if (error)
1409  return error;
1410  }
1411  else
1412  {
1413  /* Command does not exist: create it. */
1414 
1415  /* Add root command (index 0). */
1416  if (vec_len (cm->commands) == 0)
1417  {
1418  /* Create command with index 0; path is empty string. */
1419  vec_resize (cm->commands, 1);
1420  }
1421 
1422  ci = vec_len (cm->commands);
1423  hash_set_mem (cm->command_index_by_path, normalized_path, ci);
1424  vec_add1 (cm->commands, c[0]);
1425 
1426  c = vec_elt_at_index (cm->commands, ci);
1427  c->path = normalized_path;
1428 
1429  /* Don't inherit from registration. */
1430  c->sub_commands = 0;
1431  c->sub_command_index_by_name = 0;
1432  c->sub_command_positions = 0;
1433  }
1434 
1435  vlib_cli_make_parent (cm, ci);
1436  return 0;
1437 }
1438 
1439 #if 0
1440 /* $$$ turn back on again someday, maybe */
1441 clib_error_t *
1443 {
1444  vlib_cli_main_t *cm = &vm->cli_main;
1446  clib_error_t *error = 0;
1447  u8 *r_name;
1448  uword *p;
1449 
1450  if (!cm->parse_rule_index_by_name)
1451  cm->parse_rule_index_by_name = hash_create_vec ( /* initial length */ 32,
1452  sizeof (r->name[0]),
1453  sizeof (uword));
1454 
1455  /* Make vector copy of name. */
1456  r_name = format (0, "%s", r_reg->name);
1457 
1458  if ((p = hash_get_mem (cm->parse_rule_index_by_name, r_name)))
1459  {
1460  vec_free (r_name);
1461  return clib_error_return (0, "duplicate parse rule name `%s'",
1462  r_reg->name);
1463  }
1464 
1465  vec_add2 (cm->parse_rules, r, 1);
1466  r[0] = r_reg[0];
1467  r->name = (char *) r_name;
1468  hash_set_mem (cm->parse_rule_index_by_name, r->name, r - cm->parse_rules);
1469 
1470  return error;
1471 }
1472 
1473 static clib_error_t *vlib_cli_register_parse_rules (vlib_main_t * vm,
1475  lo,
1477  hi)
1478  __attribute__ ((unused))
1479 {
1480  clib_error_t *error = 0;
1482 
1483  for (r = lo; r < hi; r = clib_elf_section_data_next (r, 0))
1484  {
1485  if (!r->name || strlen (r->name) == 0)
1486  {
1487  error = clib_error_return (0, "parse rule with no name");
1488  goto done;
1489  }
1490 
1492  if (error)
1493  goto done;
1494  }
1495 
1496 done:
1497  return error;
1498 }
1499 #endif
1500 
1501 static clib_error_t *
1503  unformat_input_t * input,
1504  vlib_cli_command_t * cmd)
1505 {
1506  unformat_input_t _line_input, *line_input = &_line_input;
1507  int enable = 1;
1508  int api = 0, cli = 0, barrier = 0, dispatch = 0, circuit = 0;
1509  u32 circuit_node_index;
1510 
1511  if (!unformat_user (input, unformat_line_input, line_input))
1512  goto print_status;
1513 
1514  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1515  {
1516  if (unformat (line_input, "api"))
1517  api = 1;
1518  else if (unformat (line_input, "dispatch"))
1519  dispatch = 1;
1520  else if (unformat (line_input, "circuit-node %U",
1521  unformat_vlib_node, vm, &circuit_node_index))
1522  circuit = 1;
1523  else if (unformat (line_input, "cli"))
1524  cli = 1;
1525  else if (unformat (line_input, "barrier"))
1526  barrier = 1;
1527  else if (unformat (line_input, "disable"))
1528  enable = 0;
1529  else if (unformat (line_input, "enable"))
1530  enable = 1;
1531  else
1532  break;
1533  }
1534  unformat_free (line_input);
1535 
1537  (api ? enable : vl_api_get_elog_trace_api_messages ());
1539  vm->elog_trace_graph_dispatch = dispatch ?
1540  enable : vm->elog_trace_graph_dispatch;
1541  vm->elog_trace_graph_circuit = circuit ?
1542  enable : vm->elog_trace_graph_circuit;
1544  barrier ? enable : vlib_worker_threads->barrier_elog_enabled;
1545  vm->elog_trace_graph_circuit_node_index = circuit_node_index;
1546 
1547  /*
1548  * Set up start-of-buffer logic-analyzer trigger
1549  * for main loop event logs, which are fairly heavyweight.
1550  * See src/vlib/main/vlib_elog_main_loop_event(...), which
1551  * will fully disable the scheme when the elog buffer fills.
1552  */
1553  if (dispatch || circuit)
1554  {
1556 
1558  em->n_total_events + vec_len (em->event_ring);
1559  }
1560 
1561 
1562 print_status:
1563  vlib_cli_output (vm, "Current status:");
1564 
1566  (vm, " Event log API message trace: %s\n CLI command trace: %s",
1567  vl_api_get_elog_trace_api_messages ()? "on" : "off",
1568  vm->elog_trace_cli_commands ? "on" : "off");
1570  (vm, " Barrier sync trace: %s",
1571  vlib_worker_threads->barrier_elog_enabled ? "on" : "off");
1573  (vm, " Graph Dispatch: %s",
1574  vm->elog_trace_graph_dispatch ? "on" : "off");
1576  (vm, " Graph Circuit: %s",
1577  vm->elog_trace_graph_circuit ? "on" : "off");
1580  (vm, " node %U",
1582 
1583  return 0;
1584 }
1585 
1586 /*?
1587  * Control event logging of api, cli, and thread barrier events
1588  * With no arguments, displays the current trace status.
1589  * Name the event groups you wish to trace or stop tracing.
1590  *
1591  * @cliexpar
1592  * @clistart
1593  * event-logger trace api cli barrier
1594  * event-logger trace api cli barrier disable
1595  * event-logger trace dispatch
1596  * event-logger trace circuit-node ethernet-input
1597  * @cliend
1598  * @cliexcmd{event-logger trace [api][cli][barrier][disable]}
1599 ?*/
1600 /* *INDENT-OFF* */
1602 {
1603  .path = "event-logger trace",
1604  .short_help = "event-logger trace [api][cli][barrier][dispatch]\n"
1605  "[circuit-node <name> e.g. ethernet-input][disable]",
1606  .function = event_logger_trace_command_fn,
1607 };
1608 /* *INDENT-ON* */
1609 
1610 static clib_error_t *
1612  unformat_input_t * input, vlib_cli_command_t * cmd)
1613 {
1614  vlib_process_suspend (vm, 30e-3);
1615  return 0;
1616 }
1617 
1618 /* *INDENT-OFF* */
1620 {
1621  .path = "suspend",
1622  .short_help = "suspend debug CLI for 30ms",
1623  .function = suspend_command_fn,
1624  .is_mp_safe = 1,
1625 };
1626 /* *INDENT-ON* */
1627 
1628 
1629 static int
1630 sort_cmds_by_path (void *a1, void *a2)
1631 {
1632  u32 *index1 = a1;
1633  u32 *index2 = a2;
1635  vlib_cli_main_t *cm = &vgm->cli_main;
1636  vlib_cli_command_t *c1, *c2;
1637  int i, lmin;
1638 
1639  c1 = vec_elt_at_index (cm->commands, *index1);
1640  c2 = vec_elt_at_index (cm->commands, *index2);
1641 
1642  lmin = vec_len (c1->path);
1643  lmin = (vec_len (c2->path) >= lmin) ? lmin : vec_len (c2->path);
1644 
1645  for (i = 0; i < lmin; i++)
1646  {
1647  if (c1->path[i] < c2->path[i])
1648  return -1;
1649  else if (c1->path[i] > c2->path[i])
1650  return 1;
1651  }
1652 
1653  return 0;
1654 }
1655 
1656 typedef struct
1657 {
1665 
1666 static void
1668 {
1669  vlib_cli_command_t *parent;
1671  vlib_cli_walk_args_t _a, *a = &_a;
1673  int i;
1674 
1675  /* Copy args into this stack frame */
1676  *a = *aa;
1677  cm = a->cm;
1678 
1679  parent = vec_elt_at_index (cm->commands, a->parent_command_index);
1680 
1681  if (parent->function)
1682  {
1683  if (((a->show_mp_safe && parent->is_mp_safe)
1684  || (a->show_not_mp_safe && !parent->is_mp_safe))
1685  && (a->show_hit == 0 || parent->hit_counter))
1686  {
1687  vec_add1 (cm->sort_vector, a->parent_command_index);
1688  }
1689 
1690  if (a->clear_hit)
1691  parent->hit_counter = 0;
1692  }
1693 
1694  for (i = 0; i < vec_len (parent->sub_commands); i++)
1695  {
1696  sub = vec_elt_at_index (parent->sub_commands, i);
1697  a->parent_command_index = sub->index;
1699  }
1700 }
1701 
1702 static u8 *
1703 format_mp_safe (u8 * s, va_list * args)
1704 {
1705  vlib_cli_main_t *cm = va_arg (*args, vlib_cli_main_t *);
1706  int show_mp_safe = va_arg (*args, int);
1707  int show_not_mp_safe = va_arg (*args, int);
1708  int show_hit = va_arg (*args, int);
1709  int clear_hit = va_arg (*args, int);
1711  vlib_cli_walk_args_t _a, *a = &_a;
1712  int i;
1713  char *format_string = "\n%v";
1714 
1715  if (show_hit)
1716  format_string = "\n%v: %u";
1717 
1718  vec_reset_length (cm->sort_vector);
1719 
1720  a->cm = cm;
1721  a->parent_command_index = 0;
1722  a->show_mp_safe = show_mp_safe;
1723  a->show_not_mp_safe = show_not_mp_safe;
1724  a->show_hit = show_hit;
1725  a->clear_hit = clear_hit;
1726 
1728 
1730 
1731  for (i = 0; i < vec_len (cm->sort_vector); i++)
1732  {
1733  c = vec_elt_at_index (cm->commands, cm->sort_vector[i]);
1734  s = format (s, format_string, c->path, c->hit_counter);
1735  }
1736 
1737  return s;
1738 }
1739 
1740 
1741 static clib_error_t *
1743  unformat_input_t * input, vlib_cli_command_t * cmd)
1744 {
1746  int show_mp_safe = 0;
1747  int show_not_mp_safe = 0;
1748  int show_hit = 0;
1749  int clear_hit = 0;
1750 
1751  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1752  {
1753  if (unformat (input, "mp-safe"))
1754  show_mp_safe = 1;
1755  if (unformat (input, "not-mp-safe"))
1756  show_not_mp_safe = 1;
1757  else if (unformat (input, "hit"))
1758  show_hit = 1;
1759  else if (unformat (input, "clear-hit"))
1760  clear_hit = 1;
1761  else
1762  break;
1763  }
1764 
1765  /* default set: all cli commands */
1766  if (clear_hit == 0 && (show_mp_safe + show_not_mp_safe) == 0)
1767  show_mp_safe = show_not_mp_safe = 1;
1768 
1769  vlib_cli_output (vm, "%U", format_mp_safe, &vgm->cli_main, show_mp_safe,
1770  show_not_mp_safe, show_hit, clear_hit);
1771  if (clear_hit)
1772  vlib_cli_output (vm, "hit counters cleared...");
1773 
1774  return 0;
1775 }
1776 
1777 /*?
1778  * Displays debug cli command information
1779  *
1780  * @cliexpar
1781  * @cliexstart{show cli [mp-safe][not-mp-safe][hit][clear-hit]}
1782  *
1783  * "show cli" displays the entire debug cli:
1784  *
1785  * abf attach
1786  * abf policy
1787  * adjacency counters
1788  * api trace
1789  * app ns
1790  * bfd key del
1791  * ... and so on ...
1792  *
1793  * "show cli mp-safe" displays mp-safe debug CLI commands:
1794  *
1795  * abf policy
1796  * binary-api
1797  * create vhost-user
1798  * exec
1799  * ip container
1800  * ip mroute
1801  * ip probe-neighbor
1802  * ip route
1803  * ip scan-neighbor
1804  * ip table
1805  * ip6 table
1806  *
1807  * "show cli not-mp-safe" displays debug CLI commands
1808  * which cause worker thread barrier synchronization
1809  *
1810  * "show cli hit" displays commands which have been executed. Qualify
1811  * as desired with "mp-safe" or "not-mp-safe".
1812  *
1813  * "show cli clear-hit" clears the per-command hit counters.
1814  * @cliexend
1815 ?*/
1816 
1817 /* *INDENT-OFF* */
1819 {
1820  .path = "show cli",
1821  .short_help = "show cli [mp-safe][not-mp-safe][hit][clear-hit]",
1822  .function = show_cli_command_fn,
1823  .is_mp_safe = 1,
1824 };
1825 /* *INDENT-ON* */
1826 
1827 static clib_error_t *
1829 {
1831  vlib_cli_main_t *cm = &vgm->cli_main;
1832  clib_error_t *error = 0;
1833  vlib_cli_command_t *cmd;
1834 
1835  cmd = cm->cli_command_registrations;
1836 
1837  while (cmd)
1838  {
1839  error = vlib_cli_register (vm, cmd);
1840  if (error)
1841  return error;
1842  cmd = cmd->next_cli_command;
1843  }
1844 
1846  "cli", "log", 0x7FFFFFFF /* aka no rate limit */);
1847  return error;
1848 }
1849 
1851 
1852 /*
1853  * fd.io coding-style-patch-verification: ON
1854  *
1855  * Local Variables:
1856  * eval: (c-set-style "gnu")
1857  * End:
1858  */
vec_reset_length
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
Definition: vec_bootstrap.h:194
vlib.h
vlib_cli_init
static clib_error_t * vlib_cli_init(vlib_main_t *vm)
Definition: cli.c:1828
vlib_cli_parse_rule_t
Definition: cli.h:72
file_main
clib_file_main_t file_main
Definition: main.c:63
vlib_worker_thread_barrier_release
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1386
vec_add
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
Definition: vec.h:688
vlib_cli_parse_rule_t::name
char * name
Definition: cli.h:74
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
unformat_init_vector
void unformat_init_vector(unformat_input_t *input, u8 *vector_string)
Definition: unformat.c:1037
vlib_global_main_t
Definition: main.h:274
clib_mem_vm_map_hdr_t
struct _clib_mem_vm_map_hdr clib_mem_vm_map_hdr_t
clib_mem_page_stats_t
Definition: mem.h:509
show_cpu_command
static vlib_cli_command_t show_cpu_command
(constructor) VLIB_CLI_COMMAND (show_cpu_command)
Definition: cli.c:963
clib_mem_vm_get_next_map_hdr
__clib_export clib_mem_vm_map_hdr_t * clib_mem_vm_get_next_map_hdr(clib_mem_vm_map_hdr_t *hdr)
Definition: mem.c:387
current_traced_heap
static void * current_traced_heap
Definition: cli.c:54
clib_mem_get_heap
static clib_mem_heap_t * clib_mem_get_heap(void)
Definition: mem.h:359
vlib_process_t::output_function
vlib_cli_output_function_t * output_function
Definition: node.h:594
vlib_main_t::clib_time
clib_time_t clib_time
Definition: main.h:106
add_sub_command
static void add_sub_command(vlib_cli_main_t *cm, uword parent_index, uword child_index)
Definition: cli.c:1207
vlib_cli_command_t::sub_rules
vlib_cli_sub_rule_t * sub_rules
Definition: cli.h:125
vl_msg_push_heap
void * vl_msg_push_heap(void)
Definition: cli.c:745
elog.h
vlib_cli_parse_position_t::bitmaps
uword ** bitmaps
Definition: cli.h:53
vlib_cli_command_t::sub_commands
vlib_cli_sub_command_t * sub_commands
Definition: cli.h:112
f
vlib_frame_t * f
Definition: interface_output.c:1080
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
vlib_cli_sub_command_t::index
u32 index
Definition: cli.h:60
name
string name[64]
Definition: fib.api:25
vlib_cli_cmp_strings
static int vlib_cli_cmp_strings(void *a1, void *a2)
Definition: cli.c:229
vlib_cli_register
clib_error_t * vlib_cli_register(vlib_main_t *vm, vlib_cli_command_t *c)
Definition: cli.c:1357
vlib_cli_test_command
static vlib_cli_command_t vlib_cli_test_command
(constructor) VLIB_CLI_COMMAND (vlib_cli_test_command)
Definition: cli.c:82
elog_main_t::n_total_events_disable_limit
u32 n_total_events_disable_limit
When count reaches limit logging is disabled.
Definition: elog.h:139
vlib_cli_get_possible_completions
u8 ** vlib_cli_get_possible_completions(u8 *str)
Definition: cli.c:238
clib_bitmap_first_set
static uword clib_bitmap_first_set(uword *ai)
Return the lowest numbered set bit in a bitmap.
Definition: bitmap.h:391
path
vl_api_fib_path_t path
Definition: mfib_types.api:44
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
format_clib_mem_heap
u8 * format_clib_mem_heap(u8 *s, va_list *va)
Definition: mem_dlmalloc.c:422
vlib_cli_register_parse_rule
clib_error_t * vlib_cli_register_parse_rule(struct vlib_main_t *vm, vlib_cli_parse_rule_t *c)
vlib_cli_command_t::path
char * path
Definition: cli.h:96
vlib_cli_walk_args_t
Definition: cli.c:1656
suspend_command_fn
static clib_error_t * suspend_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:1611
hash_create_vec
#define hash_create_vec(elts, key_bytes, value_bytes)
Definition: hash.h:667
vlib_cli_command_is_empty
static uword vlib_cli_command_is_empty(vlib_cli_command_t *c)
Definition: cli.c:1351
event_logger_trace_command_fn
static clib_error_t * event_logger_trace_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:1502
vl_api_get_elog_trace_api_messages
int vl_api_get_elog_trace_api_messages(void)
Definition: api_shared.c:1248
u16
unsigned short u16
Definition: types.h:57
vlib_stats_push_heap
void * vlib_stats_push_heap(void *)
Definition: cli.c:758
vlib_call_init_function
#define vlib_call_init_function(vm, x)
Definition: init.h:259
vlib_main_t::elog_trace_graph_circuit_node_index
u32 elog_trace_graph_circuit_node_index
Definition: main.h:198
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
show_cli_command
static vlib_cli_command_t show_cli_command
(constructor) VLIB_CLI_COMMAND (show_cli_command)
Definition: cli.c:1818
vec_delete
#define vec_delete(V, N, M)
Delete N elements starting at element M.
Definition: vec.h:875
fm
vnet_feature_main_t * fm
Definition: nat44_ei_hairpinning.c:589
elog_string
__clib_export u32 elog_string(elog_main_t *em, char *fmt,...)
add a string to the event-log string table
Definition: elog.c:582
va_format
__clib_export u8 * va_format(u8 *s, const char *fmt, va_list *va)
Definition: format.c:391
stats
vl_api_ikev2_sa_stats_t stats
Definition: ikev2_types.api:162
clib_mem_trace_enable_disable
uword clib_mem_trace_enable_disable(uword enable)
Definition: mem_dlmalloc.c:525
clib_bitmap_andnot
static uword * clib_bitmap_andnot(uword *ai, uword *bi)
Logical operator across two bitmaps.
hi
vl_api_ip4_address_t hi
Definition: arp.api:37
vlib_cli_normalize_path
static uword vlib_cli_normalize_path(char *input, char **result)
Definition: cli.c:1153
unknown
unknown
Definition: map.api:399
clib_file_main_t
Definition: file.h:85
unformat_input_t
struct _unformat_input_t unformat_input_t
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1071
clib_mem_get_page_stats
__clib_export void clib_mem_get_page_stats(void *start, clib_mem_page_sz_t log2_page_size, uword n_pages, clib_mem_page_stats_t *stats)
Definition: mem.c:552
vlib_worker_threads
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:35
restart_cmd_fn
static clib_error_t * restart_cmd_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:1086
vlib_main_t::elog_trace_cli_commands
int elog_trace_cli_commands
Definition: main.h:195
all_subs
static vlib_cli_command_t * all_subs(vlib_cli_main_t *cm, vlib_cli_command_t *subs, u32 command_index)
Definition: cli.c:355
vec_cmp
#define vec_cmp(v1, v2)
Compare two vectors (only applicable to vectors of signed numbers).
Definition: vec.h:1033
vlib_get_global_main
static vlib_global_main_t * vlib_get_global_main(void)
Definition: global_funcs.h:50
error
Definition: cJSON.c:88
callback.h
Callback multiplex scheme For a fully worked-out example, see .../src/vlib/main.[ch] and ....
elog_main_t::event_ring
elog_event_t * event_ring
Vector of events (circular buffer).
Definition: elog.h:149
vlib_global_main_t::name
char * name
Definition: main.h:282
format_cpu_model_name
format_function_t format_cpu_model_name
Definition: cpu.h:417
api
import vnet interface_types api
Definition: sample.api:20
vlib_cli_parse_position_t::min_char
u32 min_char
Definition: cli.h:50
clib_mem_main_t
Definition: mem.h:128
format_log2_page_size
u8 * format_log2_page_size(u8 *s, va_list *va)
Definition: std-formats.c:273
vlib_unix_error_report
void vlib_unix_error_report(vlib_main_t *, clib_error_t *)
Definition: cli.c:669
vlib_global_main_t::cli_main
vlib_cli_main_t cli_main
Definition: main.h:294
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
format_vlib_cli_path
static u8 * format_vlib_cli_path(u8 *s, va_list *args)
Definition: cli.c:345
clib_mem_main_t::per_cpu_mheaps
void * per_cpu_mheaps[CLIB_MAX_MHEAPS]
Definition: mem.h:140
unformat_eof
unformat_function_t unformat_eof
Definition: format.h:285
vlib_cli_command_t::hit_counter
u32 hit_counter
Definition: cli.h:131
foreach_vlib_main
#define foreach_vlib_main()
Definition: threads.h:237
vlib_cli_walk_args_t::parent_command_index
u32 parent_command_index
Definition: cli.c:1659
vlib_cli_command_t::next_cli_command
struct vlib_cli_command_t * next_cli_command
Definition: cli.h:128
vlib_cli_command_t::sub_command_positions
vlib_cli_parse_position_t * sub_command_positions
Definition: cli.h:119
unformat_put_input
static void unformat_put_input(unformat_input_t *input)
Definition: format.h:197
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
vlib_main_t::argv
u8 ** argv
Definition: main.h:221
get_sub_command
static vlib_cli_command_t * get_sub_command(vlib_cli_main_t *cm, vlib_cli_command_t *parent, u32 si)
Definition: cli.c:199
vlib_cli_command_t::is_mp_safe
uword is_mp_safe
Definition: cli.h:109
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
ELOG_TYPE_DECLARE
#define ELOG_TYPE_DECLARE(f)
Definition: elog.h:442
vlib_main_t::elog_trace_graph_dispatch
int elog_trace_graph_dispatch
Definition: main.h:196
elog_main_t::n_total_events
u32 n_total_events
Total number of events in buffer.
Definition: elog.h:135
vlib_cli_command_t::sub_command_index_by_name
uword * sub_command_index_by_name
Definition: cli.h:115
vlib_cli_clear_command
static vlib_cli_command_t vlib_cli_clear_command
(constructor) VLIB_CLI_COMMAND (vlib_cli_clear_command)
Definition: cli.c:66
map
counters map
Definition: map.api:356
vec_add2
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:644
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
suspend_command
static vlib_cli_command_t suspend_command
(constructor) VLIB_CLI_COMMAND (suspend_command)
Definition: cli.c:1619
unformat_skip_white_space
uword unformat_skip_white_space(unformat_input_t *input)
Definition: unformat.c:821
vlib_cli_sub_rule_t::name
u8 * name
Definition: cli.h:65
vec_dup
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:444
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
clib_file
Definition: file.h:51
show_memory_usage_command
static vlib_cli_command_t show_memory_usage_command
(constructor) VLIB_CLI_COMMAND (show_memory_usage_command)
Definition: cli.c:929
clib_bitmap_count_set_bits
static uword clib_bitmap_count_set_bits(uword *ai)
Return the number of set bits in a bitmap.
Definition: bitmap.h:468
vlib_worker_thread_barrier_sync
#define vlib_worker_thread_barrier_sync(X)
Definition: threads.h:194
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
clib_mem_main_t::per_numa_mheaps
void * per_numa_mheaps[CLIB_MAX_NUMAS]
Definition: mem.h:143
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vlib_log_register_class_rate_limit
vlib_log_class_t vlib_log_register_class_rate_limit(char *class, char *subclass, u32 limit)
Definition: log.c:346
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
unformat_vlib_node
unformat_function_t unformat_vlib_node
Definition: node_funcs.h:1241
vlib_global_main
vlib_global_main_t vlib_global_main
Definition: main.c:1786
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
format_cpu_flags
format_function_t format_cpu_flags
Definition: cpu.h:418
vlib_cli_sub_rule_t::rule_index
u32 rule_index
Definition: cli.h:67
clib_bitmap_free
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
uword
u64 uword
Definition: types.h:112
vlib_cli_cmp_rule
static int vlib_cli_cmp_rule(void *a1, void *a2)
Definition: cli.c:369
vlib_cli_input
int vlib_cli_input(vlib_main_t *vm, unformat_input_t *input, vlib_cli_output_function_t *function, uword function_arg)
Definition: cli.c:675
hash_set_mem
#define hash_set_mem(h, key, value)
Definition: hash.h:275
vlib_cli_dispatch_sub_commands
static clib_error_t * vlib_cli_dispatch_sub_commands(vlib_main_t *vm, vlib_cli_main_t *cm, unformat_input_t *input, uword parent_command_index)
Definition: cli.c:387
vlib_get_elog_main
static elog_main_t * vlib_get_elog_main()
Definition: global_funcs.h:62
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
f64
double f64
Definition: types.h:142
show_cpu
static clib_error_t * show_cpu(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:938
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:591
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
vlib_cli_walk_args_t::show_mp_safe
int show_mp_safe
Definition: cli.c:1660
vlib_cli_main_t
Definition: cli.h:136
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
vlib_cli_output_function_t
void() vlib_cli_output_function_t(uword arg, u8 *buffer, uword buffer_bytes)
Definition: cli.h:134
restart_cmd
static vlib_cli_command_t restart_cmd
(constructor) VLIB_CLI_COMMAND (restart_cmd)
Definition: cli.c:1112
ALWAYS_ASSERT
#define ALWAYS_ASSERT(truth)
Definition: error_bootstrap.h:89
unformat_get_input
static uword unformat_get_input(unformat_input_t *input)
Definition: format.h:184
vlib_cli_walk_args_t::cm
vlib_cli_main_t * cm
Definition: cli.c:1658
unformat_vlib_cli_sub_input
uword unformat_vlib_cli_sub_input(unformat_input_t *i, va_list *args)
Definition: cli.c:163
vlib_mem_get_next_numa_node
static_always_inline int vlib_mem_get_next_numa_node(int numa)
Definition: mem.h:523
fmt
int cJSON_bool fmt
Definition: cJSON.h:160
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
unformat_vlib_cli_sub_command
static uword unformat_vlib_cli_sub_command(unformat_input_t *i, va_list *args)
Definition: cli.c:206
vlib_global_main_t::elog_main
elog_main_t elog_main
Definition: main.h:300
cpu.h
vlib_cli_parse_position_t
Definition: cli.h:48
parent_path_len
static uword parent_path_len(char *path)
Definition: cli.c:1195
show_cli_command_fn
static clib_error_t * show_cli_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:1742
clib_bitmap_and
static uword * clib_bitmap_and(uword *ai, uword *bi)
Logical operator across two bitmaps.
clib_elf_section_data_next
#define clib_elf_section_data_next(a, extra)
Definition: elf_clib.h:57
clib_time_t::clocks_per_second
f64 clocks_per_second
Definition: time.h:54
clib_mem_main
__clib_export clib_mem_main_t clib_mem_main
Definition: mem.c:22
vlib_main_t::elog_trace_graph_circuit
int elog_trace_graph_circuit
Definition: main.h:197
vlib_cli_walk_args_t::show_not_mp_safe
int show_not_mp_safe
Definition: cli.c:1661
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
index
u32 index
Definition: flow_types.api:221
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
enable_disable_memory_trace
static clib_error_t * enable_disable_memory_trace(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:971
format_vlib_node_name
format_function_t format_vlib_node_name
Definition: node_funcs.h:1235
vl_api_set_elog_trace_api_messages
int vl_api_set_elog_trace_api_messages(int enable)
Definition: api_shared.c:1237
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
clib_call_callbacks
#define clib_call_callbacks(h,...)
call the specified callback set
Definition: callback.h:67
vlib_process_wait_for_event_or_clock
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:755
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
vlib_cli_walk_args_t::show_hit
int show_hit
Definition: cli.c:1662
unformat_vlib_enable_disable
uword unformat_vlib_enable_disable(unformat_input_t *input, va_list *args)
Definition: format.c:116
vlib_process_suspend
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:486
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
show_memory_usage
static clib_error_t * show_memory_usage(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:764
vlib_cli_main_t::commands
vlib_cli_command_t * commands
Definition: cli.h:139
format_cpu_uarch
format_function_t format_cpu_uarch
Definition: cpu.h:416
si
vnet_sw_interface_t * si
Definition: interface_output.c:398
vlib_get_current_process
static vlib_process_t * vlib_get_current_process(vlib_main_t *vm)
Definition: node_funcs.h:448
vlib_cli_walk_args_t::clear_hit
int clear_hit
Definition: cli.c:1663
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
vlib_cli_command_t::sub_rule_index_by_name
uword * sub_rule_index_by_name
Definition: cli.h:122
vlib_worker_thread_t::barrier_elog_enabled
u8 barrier_elog_enabled
Definition: threads.h:104
vec_resize
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V,...
Definition: vec.h:296
ping_command
static vlib_cli_command_t ping_command
(constructor) VLIB_CLI_COMMAND (ping_command)
Definition: ping.c:1436
fformat
__clib_export word fformat(FILE *f, char *fmt,...)
Definition: format.c:466
vlib_log_notice
#define vlib_log_notice(...)
Definition: log.h:135
vec_sort_with_function
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:1097
vlib_cli_command_t::function
vlib_cli_command_function_t * function
Definition: cli.h:103
format_mp_safe
static u8 * format_mp_safe(u8 *s, va_list *args)
Definition: cli.c:1703
vlib_cli_make_parent
static void vlib_cli_make_parent(vlib_cli_main_t *cm, uword ci)
Definition: cli.c:1303
vlib_main_t
Definition: main.h:102
event_logger_trace_command
static vlib_cli_command_t event_logger_trace_command
(constructor) VLIB_CLI_COMMAND (event_logger_trace_command)
Definition: cli.c:1601
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
a
a
Definition: bitmap.h:544
unix.h
vl_msg_pop_heap
void vl_msg_pop_heap(void *oldheap)
Definition: cli.c:752
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
elog_main_t
Definition: elog.h:132
vlib_process_t
Definition: node.h:533
word
i64 word
Definition: types.h:111
vlib_process_t::output_function_arg
uword output_function_arg
Definition: node.h:595
clib_error_free
#define clib_error_free(e)
Definition: error.h:86
format_vlib_cli_command_help
static u8 * format_vlib_cli_command_help(u8 *s, va_list *args)
Definition: cli.c:331
vlib_cli_set_command
static vlib_cli_command_t vlib_cli_set_command
(constructor) VLIB_CLI_COMMAND (vlib_cli_set_command)
Definition: cli.c:74
rv
int __clib_unused rv
Definition: application.c:491
cli_recursive_walk
static void cli_recursive_walk(vlib_cli_walk_args_t *aa)
Definition: cli.c:1667
ELOG_DATA
#define ELOG_DATA(em, f)
Definition: elog.h:484
clib_bitmap_foreach
#define clib_bitmap_foreach(i, ai)
Macro to iterate across set bits in a bitmap.
Definition: bitmap.h:361
sort_cmds_by_path
static int sort_cmds_by_path(void *a1, void *a2)
Definition: cli.c:1630
vlib_cli_command_t
Definition: cli.h:92
vlib_cli_sub_command_match
static uword * vlib_cli_sub_command_match(vlib_cli_command_t *c, unformat_input_t *input)
Definition: cli.c:90
clib_mem_set_heap
static clib_mem_heap_t * clib_mem_set_heap(clib_mem_heap_t *heap)
Definition: mem.h:365
vlib_cli_sub_rule_t::command_index
u32 command_index
Definition: cli.h:69
vlib_cli_sub_command_t::name
u8 * name
Definition: cli.h:58
vlib_cli_sub_rule_t
Definition: cli.h:63
enable_disable_memory_trace_command
static vlib_cli_command_t enable_disable_memory_trace_command
(constructor) VLIB_CLI_COMMAND (enable_disable_memory_trace_command)
Definition: cli.c:1077
vec_insert
#define vec_insert(V, N, M)
Insert N vector elements starting at element M, initialize new elements to zero (no header,...
Definition: vec.h:775
clib_mem_trace
void clib_mem_trace(int enable)
Definition: mem_dlmalloc.c:503
lo
lo
Definition: vector_altivec.h:95
clib_error_t::what
u8 * what
Definition: clib_error.h:24
clib_bitmap_is_zero
static uword clib_bitmap_is_zero(uword *ai)
predicate function; is an entire bitmap empty?
Definition: bitmap.h:57
vec_del1
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:896
vlib_cli_cmp_command
static int vlib_cli_cmp_command(void *a1, void *a2)
Definition: cli.c:378
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
clib_bitmap_dup
#define clib_bitmap_dup(v)
Duplicate a bitmap.
Definition: bitmap.h:87
vlib_cli_show_command
static vlib_cli_command_t vlib_cli_show_command
(constructor) VLIB_CLI_COMMAND (vlib_cli_show_command)
Definition: cli.c:58
vlib_cli_sub_command_t
Definition: cli.h:56
string
const char *const string
Definition: cJSON.h:172