hs-test: fix TCP with loss test
[vpp.git] / src / vlib / cli.c
index 223a3b7..98d57c6 100644 (file)
@@ -38,6 +38,7 @@
  */
 
 #include <vlib/vlib.h>
+#include <vlib/stats/stats.h>
 #include <vlib/unix/unix.h>
 #include <vppinfra/callback.h>
 #include <vppinfra/cpu.h>
@@ -54,36 +55,28 @@ int vl_api_get_elog_trace_api_messages (void);
 static void *current_traced_heap;
 
 /* Root of all show commands. */
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (vlib_cli_show_command, static) = {
   .path = "show",
   .short_help = "Show commands",
 };
-/* *INDENT-ON* */
 
 /* Root of all clear commands. */
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (vlib_cli_clear_command, static) = {
   .path = "clear",
   .short_help = "Clear commands",
 };
-/* *INDENT-ON* */
 
 /* Root of all set commands. */
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (vlib_cli_set_command, static) = {
   .path = "set",
   .short_help = "Set commands",
 };
-/* *INDENT-ON* */
 
 /* Root of all test commands. */
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (vlib_cli_test_command, static) = {
   .path = "test",
   .short_help = "Test commands",
 };
-/* *INDENT-ON* */
 
 /* Returns bitmap of commands which match key. */
 static uword *
@@ -158,6 +151,64 @@ done:
   return match;
 }
 
+uword
+unformat_vlib_cli_line (unformat_input_t *i, va_list *va)
+{
+  unformat_input_t *result = va_arg (*va, unformat_input_t *);
+  u8 *line = 0;
+  uword c;
+  int skip;
+
+next_line:
+  skip = 0;
+
+  /* skip leading whitespace if any */
+  unformat_skip_white_space (i);
+
+  if (unformat_is_eof (i))
+    return 0;
+
+  while ((c = unformat_get_input (i)) != UNFORMAT_END_OF_INPUT)
+    {
+      if (c == '\\')
+       {
+         c = unformat_get_input (i);
+
+         if (c == '\n')
+           {
+             if (!skip)
+               vec_add1 (line, '\n');
+             skip = 0;
+             continue;
+           }
+
+         if (!skip)
+           vec_add1 (line, '\\');
+
+         if (c == UNFORMAT_END_OF_INPUT)
+           break;
+
+         if (!skip)
+           vec_add1 (line, c);
+         continue;
+       }
+
+      if (c == '#')
+       skip = 1;
+      else if (c == '\n')
+       break;
+
+      if (!skip)
+       vec_add1 (line, c);
+    }
+
+  if (line == 0)
+    goto next_line;
+
+  unformat_init_vector (result, line);
+  return 1;
+}
+
 /* Looks for string based sub-input formatted { SUB-INPUT }. */
 uword
 unformat_vlib_cli_sub_input (unformat_input_t * i, va_list * args)
@@ -205,10 +256,11 @@ get_sub_command (vlib_cli_main_t * cm, vlib_cli_command_t * parent, u32 si)
 static uword
 unformat_vlib_cli_sub_command (unformat_input_t * i, va_list * args)
 {
-  vlib_main_t *vm = va_arg (*args, vlib_main_t *);
+  vlib_main_t __clib_unused *vm = va_arg (*args, vlib_main_t *);
+  vlib_global_main_t *vgm = vlib_get_global_main ();
   vlib_cli_command_t *c = va_arg (*args, vlib_cli_command_t *);
   vlib_cli_command_t **result = va_arg (*args, vlib_cli_command_t **);
-  vlib_cli_main_t *cm = &vm->cli_main;
+  vlib_cli_main_t *cm = &vgm->cli_main;
   uword *match_bitmap, is_unique, index;
 
   match_bitmap = vlib_cli_sub_command_match (c, i);
@@ -238,8 +290,8 @@ vlib_cli_get_possible_completions (u8 * str)
 {
   vlib_cli_command_t *c;
   vlib_cli_sub_command_t *sc;
-  vlib_main_t *vm = vlib_get_main ();
-  vlib_cli_main_t *vcm = &vm->cli_main;
+  vlib_global_main_t *vgm = vlib_get_global_main ();
+  vlib_cli_main_t *vcm = &vgm->cli_main;
   uword *match_bitmap = 0;
   uword index, is_unique, help_next_level;
   u8 **result = 0;
@@ -303,8 +355,7 @@ vlib_cli_get_possible_completions (u8 * str)
   /* if we have a space at the end of input, and a unique match,
    * autocomplete the next level of subcommands */
   help_next_level = (vec_len (str) == 0) || isspace (str[vec_len (str) - 1]);
-  /* *INDENT-OFF* */
-  clib_bitmap_foreach(index, match_bitmap, {
+  clib_bitmap_foreach (index, match_bitmap) {
     if (help_next_level && is_unique) {
        c = get_sub_command (vcm, c, index);
        vec_foreach (sc, c->sub_commands) {
@@ -314,8 +365,7 @@ vlib_cli_get_possible_completions (u8 * str)
     }
     sc = &c->sub_commands[index];
     vec_add1(result, (u8*) sc->name);
-  });
-  /* *INDENT-ON* */
+  }
 
 done:
   clib_bitmap_free (match_bitmap);
@@ -388,11 +438,12 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
                                unformat_input_t * input,
                                uword parent_command_index)
 {
+  vlib_global_main_t *vgm = vlib_get_global_main ();
   vlib_cli_command_t *parent, *c;
   clib_error_t *error = 0;
   unformat_input_t sub_input;
   u8 *string;
-  uword is_main_dispatch = cm == &vm->cli_main;
+  uword is_main_dispatch = cm == &vgm->cli_main;
 
   parent = vec_elt_at_index (cm->commands, parent_command_index);
   if (is_main_dispatch && unformat (input, "help"))
@@ -472,6 +523,23 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
       vec_free (string);
     }
 
+  else if (unformat (input, "vpplog %v", &string))
+    {
+      int i;
+      /*
+       * Delete leading whitespace, so "vpplog { this and that }"
+       * and "vpplog this" line up nicely.
+       */
+      for (i = 0; i < vec_len (string); i++)
+       if (string[i] != ' ')
+         break;
+      if (i > 0)
+       vec_delete (string, i, 0);
+
+      vlib_log_notice (cm->log, "CLI: %v", string);
+      vec_free (string);
+    }
+
   else if (unformat (input, "uncomment %U",
                     unformat_vlib_cli_sub_input, &sub_input))
     {
@@ -507,7 +575,7 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
        }
 
       (void) clib_mem_trace_enable_disable (0);
-      leak_report = format (0, "%U", format_mheap, clib_mem_get_heap (),
+      leak_report = format (0, "%U", format_clib_mem_heap, 0,
                            1 /* verbose, i.e. print leaks */ );
       clib_mem_trace (0);
       vlib_cli_output (vm, "%v", leak_report);
@@ -547,19 +615,17 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
            {
              if (PREDICT_FALSE (vm->elog_trace_cli_commands))
                {
-                  /* *INDENT-OFF* */
                   ELOG_TYPE_DECLARE (e) =
                     {
                       .format = "cli-cmd: %s",
                       .format_args = "T4",
                     };
-                  /* *INDENT-ON* */
                  struct
                  {
                    u32 c;
                  } *ed;
-                 ed = ELOG_DATA (&vm->elog_main, e);
-                 ed->c = elog_string (&vm->elog_main, "%v", c->path);
+                 ed = ELOG_DATA (vlib_get_elog_main (), e);
+                 ed->c = elog_string (vlib_get_elog_main (), "%v", c->path);
                }
 
              if (!c->is_mp_safe)
@@ -579,28 +645,26 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
 
              if (PREDICT_FALSE (vm->elog_trace_cli_commands))
                {
-                  /* *INDENT-OFF* */
                   ELOG_TYPE_DECLARE (e) =
                     {
                       .format = "cli-cmd: %s %s",
                       .format_args = "T4T4",
                     };
-                  /* *INDENT-ON* */
                  struct
                  {
                    u32 c, err;
                  } *ed;
-                 ed = ELOG_DATA (&vm->elog_main, e);
-                 ed->c = elog_string (&vm->elog_main, "%v", c->path);
+                 ed = ELOG_DATA (vlib_get_elog_main (), e);
+                 ed->c = elog_string (vlib_get_elog_main (), "%v", c->path);
                  if (c_error)
                    {
                      vec_add1 (c_error->what, 0);
-                     ed->err =
-                       elog_string (&vm->elog_main, (char *) c_error->what);
-                     _vec_len (c_error->what) -= 1;
+                     ed->err = elog_string (vlib_get_elog_main (),
+                                            (char *) c_error->what);
+                     vec_dec_len (c_error->what, 1);
                    }
                  else
-                   ed->err = elog_string (&vm->elog_main, "OK");
+                   ed->err = elog_string (vlib_get_elog_main (), "OK");
                }
 
              if (c_error)
@@ -657,6 +721,7 @@ vlib_cli_input (vlib_main_t * vm,
                unformat_input_t * input,
                vlib_cli_output_function_t * function, uword function_arg)
 {
+  vlib_global_main_t *vgm = vlib_get_global_main ();
   vlib_process_t *cp = vlib_get_current_process (vm);
   clib_error_t *error;
   vlib_cli_output_function_t *save_function;
@@ -671,7 +736,7 @@ vlib_cli_input (vlib_main_t * vm,
 
   do
     {
-      error = vlib_cli_dispatch_sub_commands (vm, &vm->cli_main, input,
+      error = vlib_cli_dispatch_sub_commands (vm, &vgm->cli_main, input,
                                              /* parent */ 0);
     }
   while (!error && !unformat (input, "%U", unformat_eof));
@@ -703,6 +768,11 @@ vlib_cli_output (vlib_main_t * vm, char *fmt, ...)
   s = va_format (0, fmt, &va);
   va_end (va);
 
+  /* some format functions might return 0
+   * e.g. show int addr */
+  if (NULL == s)
+    return;
+
   /* Terminate with \n if not present. */
   if (vec_len (s) > 0 && s[vec_len (s) - 1] != '\n')
     vec_add1 (s, '\n');
@@ -728,13 +798,6 @@ vl_msg_pop_heap (void *oldheap)
 {
 }
 
-void *vlib_stats_push_heap (void *) __attribute__ ((weak));
-void *
-vlib_stats_push_heap (void *notused)
-{
-  return 0;
-}
-
 static clib_error_t *
 show_memory_usage (vlib_main_t * vm,
                   unformat_input_t * input, vlib_cli_command_t * cmd)
@@ -781,8 +844,7 @@ show_memory_usage (vlib_main_t * vm,
     {
       void *oldheap = vl_msg_push_heap ();
       was_enabled = clib_mem_trace_enable_disable (0);
-      u8 *s_in_svm =
-       format (0, "%U\n", format_mheap, clib_mem_get_heap (), 1);
+      u8 *s_in_svm = format (0, "%U\n", format_clib_mem_heap, 0, 1);
       vl_msg_pop_heap (oldheap);
       u8 *s = vec_dup (s_in_svm);
 
@@ -796,15 +858,14 @@ show_memory_usage (vlib_main_t * vm,
     }
   if (stats_segment)
     {
-      void *oldheap = vlib_stats_push_heap (0);
+      void *oldheap = vlib_stats_set_heap ();
       was_enabled = clib_mem_trace_enable_disable (0);
-      u8 *s_in_svm =
-       format (0, "%U\n", format_mheap, clib_mem_get_heap (), 1);
+      u8 *s_in_svm = format (0, "%U\n", format_clib_mem_heap, 0, 1);
       if (oldheap)
        clib_mem_set_heap (oldheap);
       u8 *s = vec_dup (s_in_svm);
 
-      oldheap = vlib_stats_push_heap (0);
+      oldheap = vlib_stats_set_heap ();
       vec_free (s_in_svm);
       if (oldheap)
        {
@@ -826,34 +887,20 @@ show_memory_usage (vlib_main_t * vm,
         */
        was_enabled = clib_mem_trace_enable_disable (0);
 
-        /* *INDENT-OFF* */
-        foreach_vlib_main (
-        ({
-          struct dlmallinfo mi;
-          void *mspace;
-          mspace = mm->per_cpu_mheaps[index];
-
-          mi = mspace_mallinfo (mspace);
-          vlib_cli_output (vm, "%sThread %d %s\n", index ? "\n":"", index,
-                           vlib_worker_threads[index].name);
-          vlib_cli_output (vm, "  %U\n", format_page_map,
-                           pointer_to_uword (mspace_least_addr(mspace)),
-                           mi.arena);
-          vlib_cli_output (vm, "  %U\n", format_mheap,
-                           mm->per_cpu_mheaps[index],
-                           verbose);
-          index++;
-        }));
-        /* *INDENT-ON* */
+       foreach_vlib_main ()
+         {
+           vlib_cli_output (vm, "%sThread %d %s\n", index ? "\n" : "", index,
+                            vlib_worker_threads[index].name);
+           vlib_cli_output (vm, "  %U\n", format_clib_mem_heap,
+                            mm->per_cpu_mheaps[index], verbose);
+           index++;
+         }
 
        /* Restore the trace flag */
        clib_mem_trace_enable_disable (was_enabled);
       }
     if (numa_heaps)
       {
-       struct dlmallinfo mi;
-       void *mspace;
-
        for (i = 0; i < ARRAY_LEN (mm->per_numa_mheaps); i++)
          {
            if (mm->per_numa_mheaps[i] == 0)
@@ -864,14 +911,9 @@ show_memory_usage (vlib_main_t * vm,
                continue;
              }
            was_enabled = clib_mem_trace_enable_disable (0);
-           mspace = mm->per_numa_mheaps[i];
 
-           mi = mspace_mallinfo (mspace);
            vlib_cli_output (vm, "Numa %d:", i);
-           vlib_cli_output (vm, "  %U\n", format_page_map,
-                            pointer_to_uword (mspace_least_addr (mspace)),
-                            mi.arena);
-           vlib_cli_output (vm, "  %U\n", format_mheap,
+           vlib_cli_output (vm, "  %U\n", format_clib_mem_heap,
                             mm->per_numa_mheaps[index], verbose);
          }
       }
@@ -882,8 +924,8 @@ show_memory_usage (vlib_main_t * vm,
        u8 *s = 0;
        int numa = -1;
 
-       s = format (s, "\n%-16s%7s%7s%7s",
-                   "StartAddr", "size", "PageSz", "Pages");
+       s = format (s, "\n%-16s%7s%5s%7s%7s",
+                   "StartAddr", "size", "FD", "PageSz", "Pages");
        while ((numa = vlib_mem_get_next_numa_node (numa)) != -1)
          s = format (s, " Numa%u", numa);
        s = format (s, " NotMap");
@@ -896,9 +938,16 @@ show_memory_usage (vlib_main_t * vm,
            clib_mem_get_page_stats ((void *) hdr->base_addr,
                                     hdr->log2_page_sz, hdr->num_pages,
                                     &stats);
-           s = format (s, "%016lx%7U%7U%7lu",
+           s = format (s, "%016lx%7U",
                        hdr->base_addr, format_memory_size,
-                       hdr->num_pages << hdr->log2_page_sz,
+                       hdr->num_pages << hdr->log2_page_sz);
+
+           if (hdr->fd != -1)
+             s = format (s, "%5d", hdr->fd);
+           else
+             s = format (s, "%5s", " ");
+
+           s = format (s, "%7U%7lu",
                        format_log2_page_size, hdr->log2_page_sz,
                        hdr->num_pages);
            while ((numa = vlib_mem_get_next_numa_node (numa)) != -1)
@@ -914,14 +963,12 @@ show_memory_usage (vlib_main_t * vm,
   return 0;
 }
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (show_memory_usage_command, static) = {
   .path = "show memory",
   .short_help = "show memory [api-segment][stats-segment][verbose]\n"
-  "            [numa-heaps][map]",
+               "            [numa-heaps][map][main-heap]",
   .function = show_memory_usage,
 };
-/* *INDENT-ON* */
 
 static clib_error_t *
 show_cpu (vlib_main_t * vm, unformat_input_t * input,
@@ -948,13 +995,11 @@ show_cpu (vlib_main_t * vm, unformat_input_t * input,
  * Base Frequency:           3.20 GHz
  * @cliexend
 ?*/
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (show_cpu_command, static) = {
   .path = "show cpu",
   .short_help = "Show cpu information",
   .function = show_cpu,
 };
-/* *INDENT-ON* */
 
 static clib_error_t *
 enable_disable_memory_trace (vlib_main_t * vm,
@@ -1027,7 +1072,7 @@ enable_disable_memory_trace (vlib_main_t * vm,
   /* Stats segment */
   if (stats_segment)
     {
-      oldheap = vlib_stats_push_heap (0);
+      oldheap = vlib_stats_set_heap ();
       current_traced_heap = clib_mem_get_heap ();
       clib_mem_trace (stats_segment);
       /* We don't want to call vlib_stats_pop_heap... */
@@ -1062,19 +1107,18 @@ enable_disable_memory_trace (vlib_main_t * vm,
   return 0;
 }
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (enable_disable_memory_trace_command, static) = {
   .path = "memory-trace",
   .short_help = "memory-trace on|off [api-segment][stats-segment][main-heap]\n"
   "                   [numa-heap <numa-id>]\n",
   .function = enable_disable_memory_trace,
 };
-/* *INDENT-ON* */
 
 static clib_error_t *
 restart_cmd_fn (vlib_main_t * vm, unformat_input_t * input,
                vlib_cli_command_t * cmd)
 {
+  vlib_global_main_t *vgm = vlib_get_global_main ();
   clib_file_main_t *fm = &file_main;
   clib_file_t *f;
 
@@ -1082,27 +1126,23 @@ restart_cmd_fn (vlib_main_t * vm, unformat_input_t * input,
   extern char **environ;
 
   /* Close all known open files */
-  /* *INDENT-OFF* */
-  pool_foreach(f, fm->file_pool,
-    ({
+  pool_foreach (f, fm->file_pool)
+     {
       if (f->file_descriptor > 2)
         close(f->file_descriptor);
-    }));
-  /* *INDENT-ON* */
+    }
 
   /* Exec ourself */
-  execve (vm->name, (char **) vm->argv, environ);
+  execve (vgm->name, (char **) vgm->argv, environ);
 
   return 0;
 }
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (restart_cmd,static) = {
     .path = "restart",
     .short_help = "restart process",
     .function = restart_cmd_fn,
 };
-/* *INDENT-ON* */
 
 #ifdef TEST_CODE
 /*
@@ -1128,13 +1168,11 @@ sleep_ten_seconds (vlib_main_t * vm,
   return 0;
 }
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (ping_command, static) = {
   .path = "test sleep",
   .function = sleep_ten_seconds,
   .short_help = "Sleep for 10 seconds",
 };
-/* *INDENT-ON* */
 #endif /* ifdef TEST_CODE */
 
 static uword
@@ -1173,7 +1211,7 @@ vlib_cli_normalize_path (char *input, char **result)
 
   /* Remove any extra space at end. */
   if (l > 0 && s[l - 1] == ' ')
-    _vec_len (s) -= 1;
+    vec_dec_len (s, 1);
 
   *result = s;
   return index_of_last_space;
@@ -1212,6 +1250,9 @@ add_sub_command (vlib_cli_main_t * cm, uword parent_index, uword child_index)
       vec_add (sub_name, c->path + l + 1, vec_len (c->path) - (l + 1));
     }
 
+  /* "Can't happen," check mainly to shut up coverity */
+  ALWAYS_ASSERT (sub_name != 0);
+
   if (sub_name[0] == '%')
     {
       uword *q;
@@ -1341,7 +1382,8 @@ vlib_cli_command_is_empty (vlib_cli_command_t * c)
 clib_error_t *
 vlib_cli_register (vlib_main_t * vm, vlib_cli_command_t * c)
 {
-  vlib_cli_main_t *cm = &vm->cli_main;
+  vlib_global_main_t *vgm = vlib_get_global_main ();
+  vlib_cli_main_t *cm = &vgm->cli_main;
   clib_error_t *error = 0;
   uword ci, *p;
   char *normalized_path;
@@ -1483,8 +1525,9 @@ done:
 #endif
 
 static clib_error_t *
-elog_trace_command_fn (vlib_main_t * vm,
-                      unformat_input_t * input, vlib_cli_command_t * cmd)
+event_logger_trace_command_fn (vlib_main_t * vm,
+                              unformat_input_t * input,
+                              vlib_cli_command_t * cmd)
 {
   unformat_input_t _line_input, *line_input = &_line_input;
   int enable = 1;
@@ -1535,7 +1578,7 @@ elog_trace_command_fn (vlib_main_t * vm,
    */
   if (dispatch || circuit)
     {
-      elog_main_t *em = &vm->elog_main;
+      elog_main_t *em = &vlib_global_main.elog_main;
 
       em->n_total_events_disable_limit =
        em->n_total_events + vec_len (em->event_ring);
@@ -1573,23 +1616,20 @@ print_status:
  *
  * @cliexpar
  * @clistart
- * elog trace api cli barrier
- * elog trace api cli barrier disable
- * elog trace dispatch
- * elog trace circuit-node ethernet-input
- * elog trace
+ * event-logger trace api cli barrier
+ * event-logger trace api cli barrier disable
+ * event-logger trace dispatch
+ * event-logger trace circuit-node ethernet-input
  * @cliend
- * @cliexcmd{elog trace [api][cli][barrier][disable]}
+ * @cliexcmd{event-logger trace [api][cli][barrier][disable]}
 ?*/
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (elog_trace_command, static) =
+VLIB_CLI_COMMAND (event_logger_trace_command, static) =
 {
-  .path = "elog trace",
-  .short_help = "elog trace [api][cli][barrier][dispatch]\n"
+  .path = "event-logger trace",
+  .short_help = "event-logger trace [api][cli][barrier][dispatch]\n"
   "[circuit-node <name> e.g. ethernet-input][disable]",
-  .function = elog_trace_command_fn,
+  .function = event_logger_trace_command_fn,
 };
-/* *INDENT-ON* */
 
 static clib_error_t *
 suspend_command_fn (vlib_main_t * vm,
@@ -1599,7 +1639,6 @@ suspend_command_fn (vlib_main_t * vm,
   return 0;
 }
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (suspend_command, static) =
 {
   .path = "suspend",
@@ -1607,7 +1646,6 @@ VLIB_CLI_COMMAND (suspend_command, static) =
   .function = suspend_command_fn,
   .is_mp_safe = 1,
 };
-/* *INDENT-ON* */
 
 
 static int
@@ -1615,8 +1653,8 @@ sort_cmds_by_path (void *a1, void *a2)
 {
   u32 *index1 = a1;
   u32 *index2 = a2;
-  vlib_main_t *vm = vlib_get_main ();
-  vlib_cli_main_t *cm = &vm->cli_main;
+  vlib_global_main_t *vgm = vlib_get_global_main ();
+  vlib_cli_main_t *cm = &vgm->cli_main;
   vlib_cli_command_t *c1, *c2;
   int i, lmin;
 
@@ -1726,6 +1764,7 @@ static clib_error_t *
 show_cli_command_fn (vlib_main_t * vm,
                     unformat_input_t * input, vlib_cli_command_t * cmd)
 {
+  vlib_global_main_t *vgm = vlib_get_global_main ();
   int show_mp_safe = 0;
   int show_not_mp_safe = 0;
   int show_hit = 0;
@@ -1749,8 +1788,8 @@ show_cli_command_fn (vlib_main_t * vm,
   if (clear_hit == 0 && (show_mp_safe + show_not_mp_safe) == 0)
     show_mp_safe = show_not_mp_safe = 1;
 
-  vlib_cli_output (vm, "%U", format_mp_safe, &vm->cli_main,
-                  show_mp_safe, show_not_mp_safe, show_hit, clear_hit);
+  vlib_cli_output (vm, "%U", format_mp_safe, &vgm->cli_main, show_mp_safe,
+                  show_not_mp_safe, show_hit, clear_hit);
   if (clear_hit)
     vlib_cli_output (vm, "hit counters cleared...");
 
@@ -1797,7 +1836,6 @@ show_cli_command_fn (vlib_main_t * vm,
  * @cliexend
 ?*/
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (show_cli_command, static) =
 {
   .path = "show cli",
@@ -1805,12 +1843,12 @@ VLIB_CLI_COMMAND (show_cli_command, static) =
   .function = show_cli_command_fn,
   .is_mp_safe = 1,
 };
-/* *INDENT-ON* */
 
 static clib_error_t *
 vlib_cli_init (vlib_main_t * vm)
 {
-  vlib_cli_main_t *cm = &vm->cli_main;
+  vlib_global_main_t *vgm = vlib_get_global_main ();
+  vlib_cli_main_t *cm = &vgm->cli_main;
   clib_error_t *error = 0;
   vlib_cli_command_t *cmd;
 
@@ -1823,6 +1861,9 @@ vlib_cli_init (vlib_main_t * vm)
        return error;
       cmd = cmd->next_cli_command;
     }
+
+  cm->log = vlib_log_register_class_rate_limit (
+    "cli", "log", 0x7FFFFFFF /* aka no rate limit */);
   return error;
 }