FD.io VPP  v18.07.1-19-g511ce25
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/cpu.h>
43 #include <unistd.h>
44 #include <ctype.h>
45 
46 /* Root of all show commands. */
47 /* *INDENT-OFF* */
48 VLIB_CLI_COMMAND (vlib_cli_show_command, static) = {
49  .path = "show",
50  .short_help = "Show commands",
51 };
52 /* *INDENT-ON* */
53 
54 /* Root of all clear commands. */
55 /* *INDENT-OFF* */
56 VLIB_CLI_COMMAND (vlib_cli_clear_command, static) = {
57  .path = "clear",
58  .short_help = "Clear commands",
59 };
60 /* *INDENT-ON* */
61 
62 /* Root of all set commands. */
63 /* *INDENT-OFF* */
64 VLIB_CLI_COMMAND (vlib_cli_set_command, static) = {
65  .path = "set",
66  .short_help = "Set commands",
67 };
68 /* *INDENT-ON* */
69 
70 /* Root of all test commands. */
71 /* *INDENT-OFF* */
72 VLIB_CLI_COMMAND (vlib_cli_test_command, static) = {
73  .path = "test",
74  .short_help = "Test commands",
75 };
76 /* *INDENT-ON* */
77 
78 /* Returns bitmap of commands which match key. */
79 static uword *
81 {
82  int i, n;
83  uword *match = 0;
85 
87 
88  for (i = 0;; i++)
89  {
90  uword k;
91 
92  k = unformat_get_input (input);
93  switch (k)
94  {
95  case 'a' ... 'z':
96  case 'A' ... 'Z':
97  case '0' ... '9':
98  case '-':
99  case '_':
100  break;
101 
102  case ' ':
103  case '\t':
104  case '\r':
105  case '\n':
107  /* White space or end of input removes any non-white
108  matches that were before possible. */
109  if (i < vec_len (c->sub_command_positions)
110  && clib_bitmap_count_set_bits (match) > 1)
111  {
113  for (n = 0; n < vec_len (p->bitmaps); n++)
114  match = clib_bitmap_andnot (match, p->bitmaps[n]);
115  }
116  goto done;
117 
118  default:
119  unformat_put_input (input);
120  goto done;
121  }
122 
123  if (i >= vec_len (c->sub_command_positions))
124  {
125  no_match:
126  clib_bitmap_free (match);
127  return 0;
128  }
129 
131  if (vec_len (p->bitmaps) == 0)
132  goto no_match;
133 
134  n = k - p->min_char;
135  if (n < 0 || n >= vec_len (p->bitmaps))
136  goto no_match;
137 
138  if (i == 0)
139  match = clib_bitmap_dup (p->bitmaps[n]);
140  else
141  match = clib_bitmap_and (match, p->bitmaps[n]);
142 
143  if (clib_bitmap_is_zero (match))
144  goto no_match;
145  }
146 
147 done:
148  return match;
149 }
150 
151 /* Looks for string based sub-input formatted { SUB-INPUT }. */
152 uword
154 {
155  unformat_input_t *sub_input = va_arg (*args, unformat_input_t *);
156  u8 *s;
157  uword c;
158 
159  while (1)
160  {
161  c = unformat_get_input (i);
162  switch (c)
163  {
164  case ' ':
165  case '\t':
166  case '\n':
167  case '\r':
168  case '\f':
169  break;
170 
171  case '{':
172  default:
173  /* Put back paren. */
174  if (c != UNFORMAT_END_OF_INPUT)
175  unformat_put_input (i);
176 
177  if (c == '{' && unformat (i, "%v", &s))
178  {
179  unformat_init_vector (sub_input, s);
180  return 1;
181  }
182  return 0;
183  }
184  }
185  return 0;
186 }
187 
188 static vlib_cli_command_t *
190 {
192  return vec_elt_at_index (cm->commands, s->index);
193 }
194 
195 static uword
197 {
198  vlib_main_t *vm = va_arg (*args, vlib_main_t *);
199  vlib_cli_command_t *c = va_arg (*args, vlib_cli_command_t *);
200  vlib_cli_command_t **result = va_arg (*args, vlib_cli_command_t **);
201  vlib_cli_main_t *cm = &vm->cli_main;
202  uword *match_bitmap, is_unique, index;
203 
204  {
207  vec_foreach (sr, c->sub_rules)
208  {
209  void **d;
210  r = vec_elt_at_index (cm->parse_rules, sr->rule_index);
211  vec_add2 (cm->parse_rule_data, d, 1);
212  vec_reset_length (d[0]);
213  if (r->data_size)
214  d[0] = _vec_resize (d[0],
215  /* length increment */ 1,
216  r->data_size,
217  /* header_bytes */ 0,
218  /* data align */ sizeof (uword));
219  if (unformat_user (i, r->unformat_function, vm, d[0]))
220  {
221  *result = vec_elt_at_index (cm->commands, sr->command_index);
222  return 1;
223  }
224  }
225  }
226 
227  match_bitmap = vlib_cli_sub_command_match (c, i);
228  is_unique = clib_bitmap_count_set_bits (match_bitmap) == 1;
229  index = ~0;
230  if (is_unique)
231  {
232  index = clib_bitmap_first_set (match_bitmap);
233  *result = get_sub_command (cm, c, index);
234  }
235  clib_bitmap_free (match_bitmap);
236 
237  return is_unique;
238 }
239 
240 static int
241 vlib_cli_cmp_strings (void *a1, void *a2)
242 {
243  u8 *c1 = *(u8 **) a1;
244  u8 *c2 = *(u8 **) a2;
245 
246  return vec_cmp (c1, c2);
247 }
248 
249 u8 **
251 {
254  vlib_main_t *vm = vlib_get_main ();
255  vlib_cli_main_t *vcm = &vm->cli_main;
256  uword *match_bitmap = 0;
257  uword index, is_unique, help_next_level;
258  u8 **result = 0;
259  unformat_input_t input;
260  unformat_init_vector (&input, vec_dup (str));
261  c = vec_elt_at_index (vcm->commands, 0);
262 
263  /* remove trailing whitespace, except for one of them */
264  while (vec_len (input.buffer) >= 2 &&
265  isspace (input.buffer[vec_len (input.buffer) - 1]) &&
266  isspace (input.buffer[vec_len (input.buffer) - 2]))
267  {
268  vec_del1 (input.buffer, vec_len (input.buffer) - 1);
269  }
270 
271  /* if input is empty, directly return list of root commands */
272  if (vec_len (input.buffer) == 0 ||
273  (vec_len (input.buffer) == 1 && isspace (input.buffer[0])))
274  {
275  vec_foreach (sc, c->sub_commands)
276  {
277  vec_add1 (result, (u8 *) sc->name);
278  }
279  goto done;
280  }
281 
282  /* add a trailing '?' so that vlib_cli_sub_command_match can find
283  * all commands starting with the input string */
284  vec_add1 (input.buffer, '?');
285 
286  while (1)
287  {
288  match_bitmap = vlib_cli_sub_command_match (c, &input);
289  /* no match: return no result */
290  if (match_bitmap == 0)
291  {
292  goto done;
293  }
294  is_unique = clib_bitmap_count_set_bits (match_bitmap) == 1;
295  /* unique match: try to step one subcommand level further */
296  if (is_unique)
297  {
298  /* stop if no more input */
299  if (input.index >= vec_len (input.buffer) - 1)
300  {
301  break;
302  }
303 
304  index = clib_bitmap_first_set (match_bitmap);
305  c = get_sub_command (vcm, c, index);
306  clib_bitmap_free (match_bitmap);
307  continue;
308  }
309  /* multiple matches: stop here, return all matches */
310  break;
311  }
312 
313  /* remove trailing '?' */
314  vec_del1 (input.buffer, vec_len (input.buffer) - 1);
315 
316  /* if we have a space at the end of input, and a unique match,
317  * autocomplete the next level of subcommands */
318  help_next_level = (vec_len (str) == 0) || isspace (str[vec_len (str) - 1]);
319  /* *INDENT-OFF* */
320  clib_bitmap_foreach(index, match_bitmap, {
321  if (help_next_level && is_unique) {
322  c = get_sub_command (vcm, c, index);
323  vec_foreach (sc, c->sub_commands) {
324  vec_add1 (result, (u8*) sc->name);
325  }
326  goto done; /* break doesn't work in this macro-loop */
327  }
328  sc = &c->sub_commands[index];
329  vec_add1(result, (u8*) sc->name);
330  });
331  /* *INDENT-ON* */
332 
333 done:
334  clib_bitmap_free (match_bitmap);
335  unformat_free (&input);
336 
337  if (result)
339  return result;
340 }
341 
342 static u8 *
343 format_vlib_cli_command_help (u8 * s, va_list * args)
344 {
345  vlib_cli_command_t *c = va_arg (*args, vlib_cli_command_t *);
346  int is_long = va_arg (*args, int);
347  if (is_long && c->long_help)
348  s = format (s, "%s", c->long_help);
349  else if (c->short_help)
350  s = format (s, "%s", c->short_help);
351  else
352  s = format (s, "%v commands", c->path);
353  return s;
354 }
355 
356 static u8 *
357 format_vlib_cli_parse_rule_name (u8 * s, va_list * args)
358 {
359  vlib_cli_parse_rule_t *r = va_arg (*args, vlib_cli_parse_rule_t *);
360  return format (s, "<%U>", format_c_identifier, r->name);
361 }
362 
363 static u8 *
364 format_vlib_cli_path (u8 * s, va_list * args)
365 {
366  u8 *path = va_arg (*args, u8 *);
367  int i, in_rule;
368  in_rule = 0;
369  for (i = 0; i < vec_len (path); i++)
370  {
371  switch (path[i])
372  {
373  case '%':
374  in_rule = 1;
375  vec_add1 (s, '<'); /* start of <RULE> */
376  break;
377 
378  case '_':
379  /* _ -> space in rules. */
380  vec_add1 (s, in_rule ? ' ' : '_');
381  break;
382 
383  case ' ':
384  if (in_rule)
385  {
386  vec_add1 (s, '>'); /* end of <RULE> */
387  in_rule = 0;
388  }
389  vec_add1 (s, ' ');
390  break;
391 
392  default:
393  vec_add1 (s, path[i]);
394  break;
395  }
396  }
397 
398  if (in_rule)
399  vec_add1 (s, '>'); /* terminate <RULE> */
400 
401  return s;
402 }
403 
404 static vlib_cli_command_t *
405 all_subs (vlib_cli_main_t * cm, vlib_cli_command_t * subs, u32 command_index)
406 {
407  vlib_cli_command_t *c = vec_elt_at_index (cm->commands, command_index);
410 
411  if (c->function)
412  vec_add1 (subs, c[0]);
413 
414  vec_foreach (sr, c->sub_rules)
415  subs = all_subs (cm, subs, sr->command_index);
416  vec_foreach (sc, c->sub_commands) subs = all_subs (cm, subs, sc->index);
417 
418  return subs;
419 }
420 
421 static int
422 vlib_cli_cmp_rule (void *a1, void *a2)
423 {
424  vlib_cli_sub_rule_t *r1 = a1;
425  vlib_cli_sub_rule_t *r2 = a2;
426 
427  return vec_cmp (r1->name, r2->name);
428 }
429 
430 static int
431 vlib_cli_cmp_command (void *a1, void *a2)
432 {
433  vlib_cli_command_t *c1 = a1;
434  vlib_cli_command_t *c2 = a2;
435 
436  return vec_cmp (c1->path, c2->path);
437 }
438 
439 static clib_error_t *
441  vlib_cli_main_t * cm,
442  unformat_input_t * input,
443  uword parent_command_index)
444 {
445  vlib_cli_command_t *parent, *c;
446  clib_error_t *error = 0;
447  unformat_input_t sub_input;
448  u8 *string;
449  uword is_main_dispatch = cm == &vm->cli_main;
450 
451  parent = vec_elt_at_index (cm->commands, parent_command_index);
452  if (is_main_dispatch && unformat (input, "help"))
453  {
454  uword help_at_end_of_line, i;
455 
456  help_at_end_of_line =
458  while (1)
459  {
460  c = parent;
461  if (unformat_user
462  (input, unformat_vlib_cli_sub_command, vm, c, &parent))
463  ;
464 
465  else if (!(unformat_check_input (input) == UNFORMAT_END_OF_INPUT))
466  goto unknown;
467 
468  else
469  break;
470  }
471 
472  /* help SUB-COMMAND => long format help.
473  "help" at end of line: show all commands. */
474  if (!help_at_end_of_line)
476  /* is_long */ 1);
477 
478  else if (vec_len (c->sub_commands) + vec_len (c->sub_rules) == 0)
479  vlib_cli_output (vm, "%v: no sub-commands", c->path);
480 
481  else
482  {
484  vlib_cli_sub_rule_t *sr, *subs;
485 
486  subs = vec_dup (c->sub_rules);
487 
488  /* Add in rules if any. */
489  vec_foreach (sc, c->sub_commands)
490  {
491  vec_add2 (subs, sr, 1);
492  sr->name = sc->name;
493  sr->command_index = sc->index;
494  sr->rule_index = ~0;
495  }
496 
498 
499  for (i = 0; i < vec_len (subs); i++)
500  {
503 
504  d = vec_elt_at_index (cm->commands, subs[i].command_index);
505  r =
506  subs[i].rule_index != ~0 ? vec_elt_at_index (cm->parse_rules,
507  subs
508  [i].rule_index) :
509  0;
510 
511  if (r)
513  (vm, " %-30U %U",
515  format_vlib_cli_command_help, d, /* is_long */ 0);
516  else
518  (vm, " %-30v %U",
519  subs[i].name,
520  format_vlib_cli_command_help, d, /* is_long */ 0);
521  }
522 
523  vec_free (subs);
524  }
525  }
526 
527  else if (is_main_dispatch
528  && (unformat (input, "choices") || unformat (input, "?")))
529  {
530  vlib_cli_command_t *sub, *subs;
531 
532  subs = all_subs (cm, 0, parent_command_index);
534  vec_foreach (sub, subs)
535  vlib_cli_output (vm, " %-40U %U",
537  format_vlib_cli_command_help, sub, /* is_long */ 0);
538  vec_free (subs);
539  }
540 
541  else if (unformat (input, "comment %v", &string))
542  {
543  vec_free (string);
544  }
545 
546  else if (unformat (input, "uncomment %U",
547  unformat_vlib_cli_sub_input, &sub_input))
548  {
549  error =
550  vlib_cli_dispatch_sub_commands (vm, cm, &sub_input,
551  parent_command_index);
552  unformat_free (&sub_input);
553  }
554 
555  else
556  if (unformat_user (input, unformat_vlib_cli_sub_command, vm, parent, &c))
557  {
558  unformat_input_t *si;
559  uword has_sub_commands =
560  vec_len (c->sub_commands) + vec_len (c->sub_rules) > 0;
561 
562  si = input;
563  if (unformat_user (input, unformat_vlib_cli_sub_input, &sub_input))
564  si = &sub_input;
565 
566  if (has_sub_commands)
567  error = vlib_cli_dispatch_sub_commands (vm, cm, si, c - cm->commands);
568 
569  if (has_sub_commands && !error)
570  /* Found valid sub-command. */ ;
571 
572  else if (c->function)
573  {
574  clib_error_t *c_error;
575 
576  /* Skip white space for benefit of called function. */
578 
579  if (unformat (si, "?"))
580  {
581  vlib_cli_output (vm, " %-40U %U", format_vlib_cli_path, c->path, format_vlib_cli_command_help, c, /* is_long */
582  0);
583  }
584  else
585  {
586  if (!c->is_mp_safe)
588 
589  c_error = c->function (vm, si, c);
590 
591  if (!c->is_mp_safe)
593 
594  if (c_error)
595  {
596  error =
597  clib_error_return (0, "%v: %v", c->path, c_error->what);
598  clib_error_free (c_error);
599  /* Free sub input. */
600  if (si != input)
601  unformat_free (si);
602 
603  return error;
604  }
605  }
606 
607  /* Free any previous error. */
608  clib_error_free (error);
609  }
610 
611  else if (!error)
612  error = clib_error_return (0, "%v: no sub-commands", c->path);
613 
614  /* Free sub input. */
615  if (si != input)
616  unformat_free (si);
617  }
618 
619  else
620  goto unknown;
621 
622  return error;
623 
624 unknown:
625  if (parent->path)
626  return clib_error_return (0, "%v: unknown input `%U'", parent->path,
627  format_unformat_error, input);
628  else
629  return clib_error_return (0, "unknown input `%U'", format_unformat_error,
630  input);
631 }
632 
633 
635  __attribute__ ((weak));
636 
637 void
639 {
640 }
641 
642 /* Process CLI input. */
643 void
645  unformat_input_t * input,
646  vlib_cli_output_function_t * function, uword function_arg)
647 {
649  vlib_cli_main_t *cm = &vm->cli_main;
650  clib_error_t *error;
651  vlib_cli_output_function_t *save_function;
652  uword save_function_arg;
653 
654  save_function = cp->output_function;
655  save_function_arg = cp->output_function_arg;
656 
657  cp->output_function = function;
658  cp->output_function_arg = function_arg;
659 
660  do
661  {
663  error = vlib_cli_dispatch_sub_commands (vm, &vm->cli_main, input, /* parent */
664  0);
665  }
666  while (!error && !unformat (input, "%U", unformat_eof));
667 
668  if (error)
669  {
670  vlib_cli_output (vm, "%v", error->what);
671  vlib_unix_error_report (vm, error);
672  clib_error_free (error);
673  }
674 
675  cp->output_function = save_function;
676  cp->output_function_arg = save_function_arg;
677 }
678 
679 /* Output to current CLI connection. */
680 void
681 vlib_cli_output (vlib_main_t * vm, char *fmt, ...)
682 {
684  va_list va;
685  u8 *s;
686 
687  va_start (va, fmt);
688  s = va_format (0, fmt, &va);
689  va_end (va);
690 
691  /* Terminate with \n if not present. */
692  if (vec_len (s) > 0 && s[vec_len (s) - 1] != '\n')
693  vec_add1 (s, '\n');
694 
695  if ((!cp) || (!cp->output_function))
696  fformat (stdout, "%v", s);
697  else
698  cp->output_function (cp->output_function_arg, s, vec_len (s));
699 
700  vec_free (s);
701 }
702 
703 void *vl_msg_push_heap (void) __attribute__ ((weak));
704 void vl_msg_pop_heap (void *oldheap) __attribute__ ((weak));
705 
706 static clib_error_t *
708  unformat_input_t * input, vlib_cli_command_t * cmd)
709 {
710  int verbose = 0, api_segment = 0;
711  clib_error_t *error;
712  u32 index = 0;
713 
715  {
716  if (unformat (input, "verbose"))
717  verbose = 1;
718  else if (unformat (input, "api-segment"))
719  api_segment = 1;
720  else
721  {
722  error = clib_error_return (0, "unknown input `%U'",
723  format_unformat_error, input);
724  return error;
725  }
726  }
727 
728  if (api_segment)
729  {
730  void *oldheap = vl_msg_push_heap ();
731  u8 *s_in_svm =
732  format (0, "%U\n", format_mheap, clib_mem_get_heap (), 1);
733  vl_msg_pop_heap (oldheap);
734  u8 *s = vec_dup (s_in_svm);
735 
736  oldheap = vl_msg_push_heap ();
737  vec_free (s_in_svm);
738  vl_msg_pop_heap (oldheap);
739  vlib_cli_output (vm, "API segment start:");
740  vlib_cli_output (vm, "%v", s);
741  vlib_cli_output (vm, "API segment end:");
742  vec_free (s);
743  }
744 
745  /* *INDENT-OFF* */
747  ({
749  vlib_cli_output (vm, "%sThread %d %v\n", index ? "\n":"", index,
750  vlib_worker_threads[index].name);
753  h->vm_alloc_size);
754  vlib_cli_output (vm, " %U\n", format_mheap, clib_per_cpu_mheaps[index], verbose);
755  index++;
756  }));
757  /* *INDENT-ON* */
758  return 0;
759 }
760 
761 /* *INDENT-OFF* */
762 VLIB_CLI_COMMAND (show_memory_usage_command, static) = {
763  .path = "show memory",
764  .short_help = "[verbose | api-segment] Show current memory usage",
765  .function = show_memory_usage,
766 };
767 /* *INDENT-ON* */
768 
769 static clib_error_t *
771  vlib_cli_command_t * cmd)
772 {
773 #define _(a,b,c) vlib_cli_output (vm, "%-25s " b, a ":", c);
774  _("Model name", "%U", format_cpu_model_name);
775  _("Microarchitecture", "%U", format_cpu_uarch);
776  _("Flags", "%U", format_cpu_flags);
777  _("Base frequency", "%.2f GHz",
778  ((f64) vm->clib_time.clocks_per_second) * 1e-9);
779 #undef _
780  return 0;
781 }
782 
783 /*?
784  * Displays various information about the CPU.
785  *
786  * @cliexpar
787  * @cliexstart{show cpu}
788  * Model name: Intel(R) Xeon(R) CPU E5-2667 v4 @ 3.20GHz
789  * Microarchitecture: Broadwell (Broadwell-EP/EX)
790  * Flags: sse3 ssse3 sse41 sse42 avx avx2 aes
791  * Base Frequency: 3.20 GHz
792  * @cliexend
793 ?*/
794 /* *INDENT-OFF* */
795 VLIB_CLI_COMMAND (show_cpu_command, static) = {
796  .path = "show cpu",
797  .short_help = "Show cpu information",
798  .function = show_cpu,
799 };
800 
801 /* *INDENT-ON* */
802 
803 static clib_error_t *
805  unformat_input_t * input,
806  vlib_cli_command_t * cmd)
807 {
808  unformat_input_t _line_input, *line_input = &_line_input;
809  int enable;
810  int api_segment = 0;
811  void *oldheap;
812 
813 
814  if (!unformat_user (input, unformat_line_input, line_input))
815  return 0;
816 
817  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
818  {
819  if (unformat (line_input, "%U", unformat_vlib_enable_disable, &enable))
820  ;
821  else if (unformat (line_input, "api-segment"))
822  api_segment = 1;
823  else
824  {
825  unformat_free (line_input);
826  return clib_error_return (0, "invalid input");
827  }
828  }
829  unformat_free (line_input);
830 
831  if (api_segment)
832  oldheap = vl_msg_push_heap ();
833  clib_mem_trace (enable);
834  if (api_segment)
835  vl_msg_pop_heap (oldheap);
836 
837  return 0;
838 }
839 
840 /* *INDENT-OFF* */
841 VLIB_CLI_COMMAND (enable_disable_memory_trace_command, static) = {
842  .path = "memory-trace",
843  .short_help = "on|off [api-segment] Enable/disable memory allocation trace",
844  .function = enable_disable_memory_trace,
845 };
846 /* *INDENT-ON* */
847 
848 
849 static clib_error_t *
851  vlib_cli_command_t * cmd)
852 {
853  clib_error_t *error = 0;
854  void *heap;
855  mheap_t *mheap;
856 
857  if (unformat (input, "on"))
858  {
859  /* *INDENT-OFF* */
861  heap = clib_per_cpu_mheaps[this_vlib_main->thread_index];
862  mheap = mheap_header(heap);
863  mheap->flags |= MHEAP_FLAG_VALIDATE;
864  // Turn off small object cache because it delays detection of errors
866  });
867  /* *INDENT-ON* */
868 
869  }
870  else if (unformat (input, "off"))
871  {
872  /* *INDENT-OFF* */
874  heap = clib_per_cpu_mheaps[this_vlib_main->thread_index];
875  mheap = mheap_header(heap);
876  mheap->flags &= ~MHEAP_FLAG_VALIDATE;
878  });
879  /* *INDENT-ON* */
880  }
881  else if (unformat (input, "now"))
882  {
883  /* *INDENT-OFF* */
885  heap = clib_per_cpu_mheaps[this_vlib_main->thread_index];
886  mheap = mheap_header(heap);
887  mheap_validate(heap);
888  });
889  /* *INDENT-ON* */
890  vlib_cli_output (vm, "heap validation complete");
891 
892  }
893  else
894  {
895  return clib_error_return (0, "unknown input `%U'",
896  format_unformat_error, input);
897  }
898 
899  return error;
900 }
901 
902 /* *INDENT-OFF* */
903 VLIB_CLI_COMMAND (cmd_test_heap_validate,static) = {
904  .path = "test heap-validate",
905  .short_help = "<on/off/now> validate heap on future allocs/frees or right now",
906  .function = test_heap_validate,
907 };
908 /* *INDENT-ON* */
909 
910 static clib_error_t *
912  vlib_cli_command_t * cmd)
913 {
915  clib_file_t *f;
916 
917  /* environ(7) does not indicate a header for this */
918  extern char **environ;
919 
920  /* Close all known open files */
921  /* *INDENT-OFF* */
922  pool_foreach(f, fm->file_pool,
923  ({
924  if (f->file_descriptor > 2)
925  close(f->file_descriptor);
926  }));
927  /* *INDENT-ON* */
928 
929  /* Exec ourself */
930  execve (vm->name, (char **) vm->argv, environ);
931 
932  return 0;
933 }
934 
935 /* *INDENT-OFF* */
936 VLIB_CLI_COMMAND (restart_cmd,static) = {
937  .path = "restart",
938  .short_help = "restart process",
939  .function = restart_cmd_fn,
940 };
941 /* *INDENT-ON* */
942 
943 #ifdef TEST_CODE
944 /*
945  * A trivial test harness to verify the per-process output_function
946  * is working correcty.
947  */
948 
949 static clib_error_t *
950 sleep_ten_seconds (vlib_main_t * vm,
951  unformat_input_t * input, vlib_cli_command_t * cmd)
952 {
953  u16 i;
954  u16 my_id = rand ();
955 
956  vlib_cli_output (vm, "Starting 10 seconds sleep with id %u\n", my_id);
957 
958  for (i = 0; i < 10; i++)
959  {
961  vlib_cli_output (vm, "Iteration number %u, my id: %u\n", i, my_id);
962  }
963  vlib_cli_output (vm, "Done with sleep with id %u\n", my_id);
964  return 0;
965 }
966 
967 /* *INDENT-OFF* */
968 VLIB_CLI_COMMAND (ping_command, static) = {
969  .path = "test sleep",
970  .function = sleep_ten_seconds,
971  .short_help = "Sleep for 10 seconds",
972 };
973 /* *INDENT-ON* */
974 #endif /* ifdef TEST_CODE */
975 
976 static uword
977 vlib_cli_normalize_path (char *input, char **result)
978 {
979  char *i = input;
980  char *s = 0;
981  uword l = 0;
982  uword index_of_last_space = ~0;
983 
984  while (*i != 0)
985  {
986  u8 c = *i++;
987  /* Multiple white space -> single space. */
988  switch (c)
989  {
990  case ' ':
991  case '\t':
992  case '\n':
993  case '\r':
994  if (l > 0 && s[l - 1] != ' ')
995  {
996  vec_add1 (s, ' ');
997  l++;
998  }
999  break;
1000 
1001  default:
1002  if (l > 0 && s[l - 1] == ' ')
1003  index_of_last_space = vec_len (s);
1004  vec_add1 (s, c);
1005  l++;
1006  break;
1007  }
1008  }
1009 
1010  /* Remove any extra space at end. */
1011  if (l > 0 && s[l - 1] == ' ')
1012  _vec_len (s) -= 1;
1013 
1014  *result = s;
1015  return index_of_last_space;
1016 }
1017 
1019 parent_path_len (char *path)
1020 {
1021  word i;
1022  for (i = vec_len (path) - 1; i >= 0; i--)
1023  {
1024  if (path[i] == ' ')
1025  return i;
1026  }
1027  return ~0;
1028 }
1029 
1030 static void
1031 add_sub_command (vlib_cli_main_t * cm, uword parent_index, uword child_index)
1032 {
1033  vlib_cli_command_t *p, *c;
1034  vlib_cli_sub_command_t *sub_c;
1035  u8 *sub_name;
1036  word i, l;
1037 
1038  p = vec_elt_at_index (cm->commands, parent_index);
1039  c = vec_elt_at_index (cm->commands, child_index);
1040 
1041  l = parent_path_len (c->path);
1042  if (l == ~0)
1043  sub_name = vec_dup ((u8 *) c->path);
1044  else
1045  {
1046  ASSERT (l + 1 < vec_len (c->path));
1047  sub_name = 0;
1048  vec_add (sub_name, c->path + l + 1, vec_len (c->path) - (l + 1));
1049  }
1050 
1051  if (sub_name[0] == '%')
1052  {
1053  uword *q;
1054  vlib_cli_sub_rule_t *sr;
1055 
1056  /* Remove %. */
1057  vec_delete (sub_name, 1, 0);
1058 
1059  if (!p->sub_rule_index_by_name)
1060  p->sub_rule_index_by_name = hash_create_vec ( /* initial length */ 32,
1061  sizeof (sub_name[0]),
1062  sizeof (uword));
1063  q = hash_get_mem (p->sub_rule_index_by_name, sub_name);
1064  if (q)
1065  {
1066  sr = vec_elt_at_index (p->sub_rules, q[0]);
1067  ASSERT (sr->command_index == child_index);
1068  return;
1069  }
1070 
1071  q = hash_get_mem (cm->parse_rule_index_by_name, sub_name);
1072  if (!q)
1073  {
1074  clib_error ("reference to unknown rule `%%%v' in path `%v'",
1075  sub_name, c->path);
1076  return;
1077  }
1078 
1079  hash_set_mem (p->sub_rule_index_by_name, sub_name,
1080  vec_len (p->sub_rules));
1081  vec_add2 (p->sub_rules, sr, 1);
1082  sr->name = sub_name;
1083  sr->rule_index = q[0];
1084  sr->command_index = child_index;
1085  return;
1086  }
1087 
1088  if (!p->sub_command_index_by_name)
1089  p->sub_command_index_by_name = hash_create_vec ( /* initial length */ 32,
1090  sizeof (c->path[0]),
1091  sizeof (uword));
1092 
1093  /* Check if sub-command has already been created. */
1094  if (hash_get_mem (p->sub_command_index_by_name, sub_name))
1095  {
1096  vec_free (sub_name);
1097  return;
1098  }
1099 
1100  vec_add2 (p->sub_commands, sub_c, 1);
1101  sub_c->index = child_index;
1102  sub_c->name = sub_name;
1104  sub_c - p->sub_commands);
1105 
1106  vec_validate (p->sub_command_positions, vec_len (sub_c->name) - 1);
1107  for (i = 0; i < vec_len (sub_c->name); i++)
1108  {
1109  int n;
1111 
1113 
1114  if (!pos->bitmaps)
1115  pos->min_char = sub_c->name[i];
1116 
1117  n = sub_c->name[i] - pos->min_char;
1118  if (n < 0)
1119  {
1120  pos->min_char = sub_c->name[i];
1121  vec_insert (pos->bitmaps, -n, 0);
1122  n = 0;
1123  }
1124 
1125  vec_validate (pos->bitmaps, n);
1126  pos->bitmaps[n] =
1127  clib_bitmap_ori (pos->bitmaps[n], sub_c - p->sub_commands);
1128  }
1129 }
1130 
1131 static void
1133 {
1134  uword p_len, pi, *p;
1135  char *p_path;
1136  vlib_cli_command_t *c, *parent;
1137 
1138  /* Root command (index 0) should have already been added. */
1139  ASSERT (vec_len (cm->commands) > 0);
1140 
1141  c = vec_elt_at_index (cm->commands, ci);
1142  p_len = parent_path_len (c->path);
1143 
1144  /* No space? Parent is root command. */
1145  if (p_len == ~0)
1146  {
1147  add_sub_command (cm, 0, ci);
1148  return;
1149  }
1150 
1151  p_path = 0;
1152  vec_add (p_path, c->path, p_len);
1153 
1154  p = hash_get_mem (cm->command_index_by_path, p_path);
1155 
1156  /* Parent exists? */
1157  if (!p)
1158  {
1159  /* Parent does not exist; create it. */
1160  vec_add2 (cm->commands, parent, 1);
1161  parent->path = p_path;
1162  hash_set_mem (cm->command_index_by_path, parent->path,
1163  parent - cm->commands);
1164  pi = parent - cm->commands;
1165  }
1166  else
1167  {
1168  pi = p[0];
1169  vec_free (p_path);
1170  }
1171 
1172  add_sub_command (cm, pi, ci);
1173 
1174  /* Create parent's parent. */
1175  if (!p)
1176  vlib_cli_make_parent (cm, pi);
1177 }
1178 
1181 {
1182  return (c->long_help == 0 && c->short_help == 0 && c->function == 0);
1183 }
1184 
1185 clib_error_t *
1187 {
1188  vlib_cli_main_t *cm = &vm->cli_main;
1189  clib_error_t *error = 0;
1190  uword ci, *p;
1191  char *normalized_path;
1192 
1193  if ((error = vlib_call_init_function (vm, vlib_cli_init)))
1194  return error;
1195 
1196  (void) vlib_cli_normalize_path (c->path, &normalized_path);
1197 
1198  if (!cm->command_index_by_path)
1199  cm->command_index_by_path = hash_create_vec ( /* initial length */ 32,
1200  sizeof (c->path[0]),
1201  sizeof (uword));
1202 
1203  /* See if command already exists with given path. */
1204  p = hash_get_mem (cm->command_index_by_path, normalized_path);
1205  if (p)
1206  {
1207  vlib_cli_command_t *d;
1208 
1209  ci = p[0];
1210  d = vec_elt_at_index (cm->commands, ci);
1211 
1212  /* If existing command was created via vlib_cli_make_parent
1213  replaced it with callers data. */
1214  if (vlib_cli_command_is_empty (d))
1215  {
1216  vlib_cli_command_t save = d[0];
1217 
1219 
1220  /* Copy callers fields. */
1221  d[0] = c[0];
1222 
1223  /* Save internal fields. */
1224  d->path = save.path;
1225  d->sub_commands = save.sub_commands;
1228  d->sub_rules = save.sub_rules;
1229  }
1230  else
1231  error =
1232  clib_error_return (0, "duplicate command name with path %v",
1233  normalized_path);
1234 
1235  vec_free (normalized_path);
1236  if (error)
1237  return error;
1238  }
1239  else
1240  {
1241  /* Command does not exist: create it. */
1242 
1243  /* Add root command (index 0). */
1244  if (vec_len (cm->commands) == 0)
1245  {
1246  /* Create command with index 0; path is empty string. */
1247  vec_resize (cm->commands, 1);
1248  }
1249 
1250  ci = vec_len (cm->commands);
1251  hash_set_mem (cm->command_index_by_path, normalized_path, ci);
1252  vec_add1 (cm->commands, c[0]);
1253 
1254  c = vec_elt_at_index (cm->commands, ci);
1255  c->path = normalized_path;
1256 
1257  /* Don't inherit from registration. */
1258  c->sub_commands = 0;
1260  c->sub_command_positions = 0;
1261  }
1262 
1263  vlib_cli_make_parent (cm, ci);
1264  return 0;
1265 }
1266 
1267 clib_error_t *
1269 {
1270  vlib_cli_main_t *cm = &vm->cli_main;
1272  clib_error_t *error = 0;
1273  u8 *r_name;
1274  uword *p;
1275 
1276  if (!cm->parse_rule_index_by_name)
1277  cm->parse_rule_index_by_name = hash_create_vec ( /* initial length */ 32,
1278  sizeof (r->name[0]),
1279  sizeof (uword));
1280 
1281  /* Make vector copy of name. */
1282  r_name = format (0, "%s", r_reg->name);
1283 
1284  if ((p = hash_get_mem (cm->parse_rule_index_by_name, r_name)))
1285  {
1286  vec_free (r_name);
1287  return clib_error_return (0, "duplicate parse rule name `%s'",
1288  r_reg->name);
1289  }
1290 
1291  vec_add2 (cm->parse_rules, r, 1);
1292  r[0] = r_reg[0];
1293  r->name = (char *) r_name;
1295 
1296  return error;
1297 }
1298 
1299 #if 0
1300 /* $$$ turn back on again someday, maybe */
1301 static clib_error_t *vlib_cli_register_parse_rules (vlib_main_t * vm,
1303  lo,
1305  hi)
1306  __attribute__ ((unused))
1307 {
1308  clib_error_t *error = 0;
1310 
1311  for (r = lo; r < hi; r = clib_elf_section_data_next (r, 0))
1312  {
1313  if (!r->name || strlen (r->name) == 0)
1314  {
1315  error = clib_error_return (0, "parse rule with no name");
1316  goto done;
1317  }
1318 
1319  error = vlib_cli_register_parse_rule (vm, r);
1320  if (error)
1321  goto done;
1322  }
1323 
1324 done:
1325  return error;
1326 }
1327 #endif
1328 
1329 static int
1330 cli_path_compare (void *a1, void *a2)
1331 {
1332  u8 **s1 = a1;
1333  u8 **s2 = a2;
1334 
1335  if ((vec_len (*s1) < vec_len (*s2)) &&
1336  memcmp ((char *) *s1, (char *) *s2, vec_len (*s1)) == 0)
1337  return -1;
1338 
1339 
1340  if ((vec_len (*s1) > vec_len (*s2)) &&
1341  memcmp ((char *) *s1, (char *) *s2, vec_len (*s2)) == 0)
1342  return 1;
1343 
1344  return vec_cmp (*s1, *s2);
1345 }
1346 
1347 static clib_error_t *
1349  vlib_cli_command_t * cmd)
1350 {
1351  vlib_cli_main_t *cm = &vm->cli_main;
1352  vlib_cli_command_t *cli;
1353  u8 **paths = 0, **s;
1354 
1355  /* *INDENT-OFF* */
1356  vec_foreach (cli, cm->commands)
1357  if (vec_len (cli->path) > 0)
1358  vec_add1 (paths, (u8 *) cli->path);
1359 
1361 
1362  vec_foreach (s, paths)
1363  vlib_cli_output (vm, "%v", *s);
1364  /* *INDENT-ON* */
1365 
1366  vec_free (paths);
1367  return 0;
1368 }
1369 
1370 /* *INDENT-OFF* */
1371 VLIB_CLI_COMMAND (show_cli_command, static) = {
1372  .path = "show cli",
1373  .short_help = "Show cli commands",
1374  .function = show_cli_cmd_fn,
1375 };
1376 /* *INDENT-ON* */
1377 
1378 static clib_error_t *
1380 {
1381  vlib_cli_main_t *cm = &vm->cli_main;
1382  clib_error_t *error = 0;
1383  vlib_cli_command_t *cmd;
1384 
1385  cmd = cm->cli_command_registrations;
1386 
1387  while (cmd)
1388  {
1389  error = vlib_cli_register (vm, cmd);
1390  if (error)
1391  return error;
1392  cmd = cmd->next_cli_command;
1393  }
1394  return error;
1395 }
1396 
1398 
1399 /*
1400  * fd.io coding-style-patch-verification: ON
1401  *
1402  * Local Variables:
1403  * eval: (c-set-style "gnu")
1404  * End:
1405  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:437
uword output_function_arg
Definition: node.h:589
vmrglw vmrglh hi
unformat_function_t * unformat_function
Definition: cli.h:80
void * clib_per_cpu_mheaps[CLIB_MAX_MHEAPS]
Definition: mem_mheap.c:46
static clib_error_t * show_cpu(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:770
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
Definition: node_funcs.h:699
void vlib_cli_input(vlib_main_t *vm, unformat_input_t *input, vlib_cli_output_function_t *function, uword function_arg)
Definition: cli.c:644
uword data_size
Definition: cli.h:78
uword vm_alloc_offset_from_header
unformat_function_t unformat_eof
Definition: format.h:292
static u8 * format_vlib_cli_parse_rule_name(u8 *s, va_list *args)
Definition: cli.c:357
static uword unformat_get_input(unformat_input_t *input)
Definition: format.h:191
#define clib_error(format, args...)
Definition: error.h:62
vlib_cli_command_t * commands
Definition: cli.h:136
f64 clocks_per_second
Definition: time.h:53
format_function_t format_cpu_flags
Definition: cpu.h:195
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:523
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:562
int i
static uword parent_path_len(char *path)
Definition: cli.c:1019
static mheap_t * mheap_header(u8 *v)
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:983
uword * sub_rule_index_by_name
Definition: cli.h:121
#define hash_set_mem(h, key, value)
Definition: hash.h:275
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
u8 * va_format(u8 *s, const char *fmt, va_list *va)
Definition: format.c:387
clib_time_t clib_time
Definition: main.h:63
vlib_cli_main_t cli_main
Definition: main.h:138
static vlib_cli_command_t * all_subs(vlib_cli_main_t *cm, vlib_cli_command_t *subs, u32 command_index)
Definition: cli.c:405
unsigned char u8
Definition: types.h:56
u8 * format_mheap(u8 *s, va_list *va)
Definition: mheap.c:1178
#define clib_bitmap_dup(v)
Duplicate a bitmap.
Definition: bitmap.h:87
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
double f64
Definition: types.h:142
#define vlib_worker_thread_barrier_sync(X)
Definition: threads.h:212
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
Definition: vec.h:600
clib_file_t * file_pool
Definition: file.h:88
static clib_error_t * test_heap_validate(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:850
i64 word
Definition: types.h:111
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:443
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:156
#define always_inline
Definition: clib.h:92
static uword clib_bitmap_is_zero(uword *ai)
predicate function; is an entire bitmap empty?
Definition: bitmap.h:57
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
u8 * format_page_map(u8 *s, va_list *args)
Definition: unix-formats.c:959
#define clib_error_return(e, args...)
Definition: error.h:99
void * vl_msg_push_heap(void)
Definition: api_shared.c:959
uword * command_index_by_path
Definition: cli.h:139
clib_file_main_t file_main
Definition: main.c:63
u32 command_index
Definition: cli.h:68
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V...
Definition: vec.h:240
unsigned int u32
Definition: types.h:88
#define vlib_call_init_function(vm, x)
Definition: init.h:227
static void add_sub_command(vlib_cli_main_t *cm, uword parent_index, uword child_index)
Definition: cli.c:1031
static uword unformat_vlib_cli_sub_command(unformat_input_t *i, va_list *args)
Definition: cli.c:196
static int vlib_cli_cmp_strings(void *a1, void *a2)
Definition: cli.c:241
static int vlib_cli_cmp_rule(void *a1, void *a2)
Definition: cli.c:422
unformat_function_t unformat_line_input
Definition: format.h:282
u8 * format_c_identifier(u8 *s, va_list *va)
Definition: std-formats.c:258
char * name
Definition: main.h:104
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:35
vlib_cli_parse_rule_t * parse_rules
Definition: cli.h:142
static clib_error_t * enable_disable_memory_trace(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:804
#define clib_bitmap_foreach(i, ai, body)
Macro to iterate across set bits in a bitmap.
Definition: bitmap.h:361
static vlib_cli_command_t * get_sub_command(vlib_cli_main_t *cm, vlib_cli_command_t *parent, u32 si)
Definition: cli.c:189
#define vec_insert(V, N, M)
Insert N vector elements starting at element M, initialize new elements to zero (no header...
Definition: vec.h:687
vlib_cli_command_function_t * function
Definition: cli.h:102
static uword clib_bitmap_first_set(uword *ai)
Return the lowest numbered set bit in a bitmap.
Definition: bitmap.h:385
clib_error_t * vlib_cli_register_parse_rule(vlib_main_t *vm, vlib_cli_parse_rule_t *r_reg)
Definition: cli.c:1268
u8 ** vlib_cli_get_possible_completions(u8 *str)
Definition: cli.c:250
vlib_cli_sub_rule_t * sub_rules
Definition: cli.h:124
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
static int cli_path_compare(void *a1, void *a2)
Definition: cli.c:1330
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:373
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:806
static void unformat_put_input(unformat_input_t *input)
Definition: format.h:204
void vl_msg_pop_heap(void *oldheap)
Definition: api_shared.c:967
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:440
#define foreach_vlib_main(body)
Definition: threads.h:244
word fformat(FILE *f, char *fmt,...)
Definition: format.c:453
void unformat_init_vector(unformat_input_t *input, u8 *vector_string)
Definition: unformat.c:1031
vlib_cli_sub_command_t * sub_commands
Definition: cli.h:111
u8 ** argv
Definition: main.h:194
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
svmdb_client_t * c
static vlib_process_t * vlib_get_current_process(vlib_main_t *vm)
Definition: node_funcs.h:417
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:339
static uword * clib_bitmap_andnot(uword *ai, uword *bi)
Logical operator across two bitmaps.
uword ** bitmaps
Definition: cli.h:52
static u8 * format_vlib_cli_command_help(u8 *s, va_list *args)
Definition: cli.c:343
static uword * vlib_cli_sub_command_match(vlib_cli_command_t *c, unformat_input_t *input)
Definition: cli.c:80
static uword vlib_cli_command_is_empty(vlib_cli_command_t *c)
Definition: cli.c:1180
static void * clib_mem_get_heap(void)
Definition: mem.h:220
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
static int vlib_cli_cmp_command(void *a1, void *a2)
Definition: cli.c:431
#define clib_elf_section_data_next(a, extra)
Definition: elf_clib.h:57
static void vlib_cli_make_parent(vlib_cli_main_t *cm, uword ci)
Definition: cli.c:1132
#define ASSERT(truth)
static clib_error_t * vlib_cli_init(vlib_main_t *vm)
Definition: cli.c:1379
#define vec_delete(V, N, M)
Delete N elements starting at element M.
Definition: vec.h:786
uword * parse_rule_index_by_name
Definition: cli.h:145
void( vlib_cli_output_function_t)(uword arg, u8 *buffer, uword buffer_bytes)
Definition: cli.h:131
uword vm_alloc_size
char * long_help
Definition: cli.h:99
uword is_mp_safe
Definition: cli.h:108
#define MHEAP_FLAG_VALIDATE
char * path
Definition: cli.h:95
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
uword * sub_command_index_by_name
Definition: cli.h:114
#define vec_cmp(v1, v2)
Compare two vectors (only applicable to vectors of signed numbers).
Definition: vec.h:921
static uword pointer_to_uword(const void *p)
Definition: types.h:131
static clib_error_t * show_memory_usage(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:707
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
#define MHEAP_FLAG_SMALL_OBJECT_CACHE
static uword clib_bitmap_count_set_bits(uword *ai)
Return the number of set bits in a bitmap.
Definition: bitmap.h:462
struct vlib_cli_command_t * next_cli_command
Definition: cli.h:127
#define hash_create_vec(elts, key_bytes, value_bytes)
Definition: hash.h:668
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
uword unformat_vlib_enable_disable(unformat_input_t *input, va_list *args)
Definition: format.c:116
uword unformat_vlib_cli_sub_input(unformat_input_t *i, va_list *args)
Definition: cli.c:153
u64 uword
Definition: types.h:112
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:982
static void unformat_free(unformat_input_t *i)
Definition: format.h:162
void ** parse_rule_data
Definition: cli.h:148
format_function_t format_cpu_uarch
Definition: cpu.h:193
#define clib_error_free(e)
Definition: error.h:86
#define hash_get_mem(h, key)
Definition: hash.h:269
clib_error_t * vlib_cli_register(vlib_main_t *vm, vlib_cli_command_t *c)
Definition: cli.c:1186
vlib_cli_command_t * cli_command_registrations
Definition: cli.h:151
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
void vlib_unix_error_report(vlib_main_t *, clib_error_t *)
Definition: cli.c:638
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1545
void mheap_validate(void *v)
Definition: mheap.c:1355
static clib_error_t * restart_cmd_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:911
#define vec_foreach(var, vec)
Vector iterator.
Definition: file.h:51
vlib_cli_parse_position_t * sub_command_positions
Definition: cli.h:118
static uword vlib_cli_normalize_path(char *input, char **result)
Definition: cli.c:977
vlib_cli_output_function_t * output_function
Definition: node.h:588
void clib_mem_trace(int enable)
Definition: mem_mheap.c:154
static clib_error_t * show_cli_cmd_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:1348
char * short_help
Definition: cli.h:98
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:681
uword unformat_skip_white_space(unformat_input_t *input)
Definition: unformat.c:815
format_function_t format_cpu_model_name
Definition: cpu.h:194
static uword * clib_bitmap_and(uword *ai, uword *bi)
Logical operator across two bitmaps.
static u8 * format_vlib_cli_path(u8 *s, va_list *args)
Definition: cli.c:364
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
u32 rule_index
Definition: cli.h:66
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170