/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * node_cli.c: node CLI
 *
 * Copyright (c) 2008 Eliot Dresselhaus
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <vlib/vlib.h>
#include <vlib/threads.h>
#include <math.h>

static int
node_cmp (void *a1, void *a2)
{
  vlib_node_t **n1 = a1;
  vlib_node_t **n2 = a2;

  return vec_cmp (n1[0]->name, n2[0]->name);
}

static clib_error_t *
show_node_graph (vlib_main_t * vm,
		 unformat_input_t * input, vlib_cli_command_t * cmd)
{
  vlib_node_main_t *nm = &vm->node_main;
  vlib_node_t *n;
  u32 node_index;

  vlib_cli_output (vm, "%U\n", format_vlib_node_graph, nm, 0);

  if (unformat (input, "%U", unformat_vlib_node, vm, &node_index))
    {
      n = vlib_get_node (vm, node_index);
      vlib_cli_output (vm, "%U\n", format_vlib_node_graph, nm, n);
    }
  else
    {
      vlib_node_t **nodes = vec_dup (nm->nodes);
      uword i;

      vec_sort_with_function (nodes, node_cmp);

      for (i = 0; i < vec_len (nodes); i++)
	vlib_cli_output (vm, "%U\n\n", format_vlib_node_graph, nm, nodes[i]);

      vec_free (nodes);
    }

  return 0;
}

/* *INDENT-OFF* */
VLIB_CLI_COMMAND (show_node_graph_command, static) = {
  .path = "show vlib graph",
  .short_help = "Show packet processing node graph",
  .function = show_node_graph,
};
/* *INDENT-ON* */

static clib_error_t *
show_node_graphviz (vlib_main_t * vm,
		    unformat_input_t * input, vlib_cli_command_t * cmd)
{
  clib_error_t *error = 0;
  vlib_node_main_t *nm = &vm->node_main;
  vlib_node_t **nodes = nm->nodes;
  u8 *chroot_filename = 0;
  int fd;
  uword *active = 0;
  u32 i, j;
  unformat_input_t _line_input, *line_input = &_line_input;
  u8 filter = 0, calls_filter = 0, vectors_filter = 0, both = 0;

  fd = -1;
  /* Get a line of input. */
  if (unformat_user (input, unformat_line_input, line_input))
    {
      while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
	{
	  if (unformat (line_input, "filter"))
	    filter = 1;
	  else if (unformat (line_input, "calls") && filter)
	    calls_filter = 1;
	  else if (unformat (line_input, "vectors") && filter)
	    vectors_filter = 1;
	  else if (unformat (line_input, "file %U", unformat_vlib_tmpfile,
			     &chroot_filename))
	    {
	      fd = open ((char *) chroot_filename,
			 O_CREAT | O_TRUNC | O_WRONLY, 0664);
	    }
	  else
	    return clib_error_return (0, "unknown input `%U'",
				      format_unformat_error, input);
	}
      unformat_free (line_input);
    }

  /*both is set to true if calls_filter and vectors_filter are, or neither */
  both = filter & (!(calls_filter ^ vectors_filter));

#define format__(vm__, fd__, ...) \
  if ((fd) < 0) \
    { \
      vlib_cli_output((vm__), ## __VA_ARGS__); \
    } \
  else \
    { \
      fdformat((fd__), ## __VA_ARGS__); \
    }

  format__ (vm, fd, "%s", "digraph {\n");

  clib_bitmap_alloc (active, vec_len (nodes));
  clib_bitmap_set_region (active, 0, 1, vec_len (nodes));
  if (filter)
    {
      /*Adding the legend to the dot file*/
      format__ (vm, fd, "%s",
		"  rankdir=\"LR\"\n  nodesep=2\n  subgraph cluster_legend {\n "
		"   label=\"Legend\"\n    style=\"solid\"\n    labelloc = b\n "
		"   subgraph cluster_colors {\n      label=\"Packets/Call\"\n "
		"     style=\"solid\"\n      labelloc = b\n");
      format__ (vm, fd, "%s",
		"      0 [label=\"No packet\", fixedsize=true shape=circle "
		"width=2 fontsize=17]\n"
		"      1 [label=\"1-32\", fillcolor=1 style=filled "
		"colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
		"fontsize=17]\n"
		"      2 [label=\"33-64\", fillcolor=2 style=filled "
		"colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
		"fontsize=17]\n"
		"      3 [label=\"65-96\", fillcolor=3 style=filled "
		"colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
		"fontsize=17]\n"
		"      4 [label=\"97-128\", fillcolor=4 style=filled "
		"colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
		"fontsize=17]\n"
		"      5 [label=\"129-160\", fillcolor=5 style=filled "
		"colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
		"fontsize=17]\n"
		"      6 [label=\"161-192\", fillcolor=6 style=filled "
		"colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
		"fontsize=17]\n"
		"      7 [label=\"193-224\", fillcolor=7 style=filled "
		"colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
		"fontsize=17]\n"
		"      8 [label=\"224+\", fillcolor=8 style=filled "
		"colorscheme=ylorrd8 fixedsize=true shape=circle width=2 "
		"fontsize=17]\n");
      format__ (vm, fd, "%s",
		"      0 -> 1 -> 2 -> 3 -> 4 [style=\"invis\",weight =100]\n  "
		"    5 -> 6 -> 7 -> 8 [style=\"invis\",weight =100]\n    }\n  "
		"  subgraph cluster_size {\n      label=\"Cycles/Packet\"\n   "
		"   style=\"solid\"\n      labelloc = b\n");
      format__ (
	vm, fd, "%s",
	"      a[label=\"0\",fixedsize=true shape=circle width=1] \n"
	"      b[label=\"10\",fixedsize=true shape=circle width=2 "
	"fontsize=17]\n"
	"      c[label=\"100\",fixedsize=true shape=circle width=3 "
	"fontsize=20]\n"
	"      d[label=\"1000\",fixedsize=true shape=circle width=4 "
	"fontsize=23]\n"
	"      a -> b -> c -> d  [style=\"invis\",weight =100]\n    }\n  }\n");

      vlib_worker_thread_barrier_sync (vm);
      for (j = 0; j < vec_len (nm->nodes); j++)
	{
	  vlib_node_t *n;
	  n = nm->nodes[j];
	  vlib_node_sync_stats (vm, n);
	}

      /* Updating the stats for multithreaded use cases.
       * We need to dup the nodes to sum the stats from all threads.*/
      nodes = vec_dup (nm->nodes);
      for (i = 1; i < vlib_get_n_threads (); i++)
	{
	  vlib_node_main_t *nm_clone;
	  vlib_main_t *vm_clone;
	  vlib_node_runtime_t *rt;
	  vlib_node_t *n;

	  vm_clone = vlib_get_main_by_index (i);
	  nm_clone = &vm_clone->node_main;

	  for (j = 0; j < vec_len (nm_clone->nodes); j++)
	    {
	      n = nm_clone->nodes[j];

	      rt = vlib_node_get_runtime (vm_clone, n->index);
	      /* Sync the stats directly in the duplicated node.*/
	      vlib_node_runtime_sync_stats_node (nodes[j], rt, 0, 0, 0);
	    }
	}
      vlib_worker_thread_barrier_release (vm);

      for (i = 0; i < vec_len (nodes); i++)
	{
	  u64 p, c, l;
	  c = nodes[i]->stats_total.calls - nodes[i]->stats_last_clear.calls;
	  p =
	    nodes[i]->stats_total.vectors - nodes[i]->stats_last_clear.vectors;
	  l = nodes[i]->stats_total.clocks - nodes[i]->stats_last_clear.clocks;

	  if ((both && c > 0 && p > 0) || (calls_filter && c > 0) ||
	      (vectors_filter && p > 0))
	    {
	      format__ (vm, fd, "  \"%v\" [shape=circle", nodes[i]->name);
	      /*Changing the size and the font of nodes that receive packets*/
	      if (p > 0)
		{
		  f64 x = (f64) l / (f64) p;
		  f64 size_ratio = (1 + log10 (x + 1));
		  format__ (vm, fd, " width=%.2f fontsize=%.2f fixedsize=true",
			    size_ratio, 11 + 3 * size_ratio);
		  /*Coloring nodes that are indeed called*/
		  if (c > 0)
		    {
		      u64 color = ((p - 1) / (32 * c)) + 1;
		      color = clib_min (color, 8);
		      format__ (
			vm, fd,
			" fillcolor=%u style=filled colorscheme=ylorrd8",
			color);
		    }
		}
	      format__ (vm, fd, "]\n");
	    }
	  else
	    {
	      clib_bitmap_set (active, i, 0);
	    }
	}
    }

  clib_bitmap_foreach (i, active)
    {
      for (j = 0; j < vec_len (nodes[i]->next_nodes); j++)
	{
	  if (nodes[i]->next_nodes[j] == VLIB_INVALID_NODE_INDEX)
	    continue;

	  if (!filter || clib_bitmap_get (active, nodes[i]->next_nodes[j]))
	    {
	      format__ (vm, fd, "  \"%v\" -> \"%v\"\n", nodes[i]->name,
			nodes[nodes[i]->next_nodes[j]]->name);
	    }
	}
    }

  format__ (vm, fd, "}\n");

  if (fd >= 0)
    {
      /*Dumping all the nodes saturates dot capacities to render a directed
       * graph. In this case, prefer using he fdp command to generate an
       * undirected graph. */
      const char *soft = filter ? "dot" : "fdp";
      vlib_cli_output (
	vm, "vlib graph dumped into `%s'. Run eg. `%s -Tsvg -O %s'.",
	chroot_filename, soft, chroot_filename);
    }

  clib_bitmap_free (active);
  vec_free (chroot_filename);
  if (filter)
    vec_free (nodes);
  if (fd >= 0)
    close (fd);
  return error;
}

/*?
 * Dump dot files data to draw a graph of all the nodes.
 * If the argument 'filter' is provided, only the active nodes (since the last
 * "clear run" command) are selected and they are scaled and colored according
 * to their utilization. You can choose to filter nodes that are called,
 * nodes that receive vectors or both (default).
 * The 'file' option allows to save data in a temp file.
 *
 * @cliexpar
 * @clistart
 * show vlib graphviz
 * show vlib graphviz filter file tmpfile
 * show vlib graphviz filter calls file tmpfile
 * @cliend
 * @cliexcmd{show vlib graphviz [filter][calls][vectors][file <filename>]}
?*/
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (show_node_graphviz_command, static) = {
  .path = "show vlib graphviz",
  .short_help = "Dump packet processing node graph as a graphviz dotfile",
  .function = show_node_graphviz,
  .is_mp_safe = 1,
};
/* *INDENT-ON* */

static u8 *
format_vlib_node_state (u8 * s, va_list * va)
{
  vlib_main_t *vm = va_arg (*va, vlib_main_t *);
  vlib_node_t *n = va_arg (*va, vlib_node_t *);
  char *state;

  state = "active";
  if (n->type == VLIB_NODE_TYPE_PROCESS)
    {
      vlib_process_t *p = vlib_get_process_from_node (vm, n);

      switch (p->flags & (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK
			  | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT))
	{
	default:
	  if (!(p->flags & VLIB_PROCESS_IS_RUNNING))
	    state = "done";
	  break;

	case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK:
	  state = "time wait";
	  break;

	case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT:
	  state = "event wait";
	  break;

	case (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK):
	  state =
	    "any wait";
	  break;
	}
    }
  else if (n->type != VLIB_NODE_TYPE_INTERNAL)
    {
      state = "polling";
      if (n->state == VLIB_NODE_STATE_DISABLED)
	state = "disabled";
      else if (n->state == VLIB_NODE_STATE_INTERRUPT)
	state = "interrupt wait";
    }

  return format (s, "%s", state);
}

static u8 *
format_vlib_node_stats (u8 * s, va_list * va)
{
  vlib_main_t *vm = va_arg (*va, vlib_main_t *);
  vlib_node_t *n = va_arg (*va, vlib_node_t *);
  int max = va_arg (*va, int);
  f64 v;
  u8 *ns;
  u8 *misc_info = 0;
  u64 c, p, l, d;
  f64 x;
  f64 maxc, maxcn;
  u32 maxn;
  u32 indent;

  if (!n)
    {
      if (max)
	s = format (s,
		    "%=30s%=17s%=16s%=16s%=16s%=16s",
		    "Name", "Max Node Clocks", "Vectors at Max",
		    "Max Clocks", "Avg Clocks", "Avg Vectors/Call");
      else
	s = format (s,
		    "%=30s%=12s%=16s%=16s%=16s%=16s%=16s",
		    "Name", "State", "Calls", "Vectors", "Suspends",
		    "Clocks", "Vectors/Call");
      return s;
    }

  indent = format_get_indent (s);

  l = n->stats_total.clocks - n->stats_last_clear.clocks;
  c = n->stats_total.calls - n->stats_last_clear.calls;
  p = n->stats_total.vectors - n->stats_last_clear.vectors;
  d = n->stats_total.suspends - n->stats_last_clear.suspends;
  maxc = (f64) n->stats_total.max_clock;
  maxn = n->stats_total.max_clock_n;
  if (n->stats_total.max_clock_n)
    maxcn = (f64) n->stats_total.max_clock / (f64) maxn;
  else
    maxcn = 0.0;

  /* Clocks per packet, per call or per suspend. */
  x = 0;
  if (p > 0)
    x = (f64) l / (f64) p;
  else if (c > 0)
    x = (f64) l / (f64) c;
  else if (d > 0)
    x = (f64) l / (f64) d;

  if (c > 0)
    v = (double) p / (double) c;
  else
    v = 0;

  if (n->type == VLIB_NODE_TYPE_PROCESS)
    {
      vlib_process_t *p = vlib_get_process_from_node (vm, n);

      /* Show processes with events pending.  This helps spot bugs where events are not
         being handled. */
      if (!clib_bitmap_is_zero (p->non_empty_event_type_bitmap))
	misc_info = format (misc_info, "events pending, ");
    }
  ns = n->name;

  if (max)
    s = format (s, "%-30v%=17.2e%=16d%=16.2e%=16.2e%=16.2e",
		ns, maxc, maxn, maxcn, x, v);
  else
    s = format (s, "%-30v%=12U%16Ld%16Ld%16Ld%16.2e%16.2f", ns,
		format_vlib_node_state, vm, n, c, p, d, x, v);

  if (ns != n->name)
    vec_free (ns);

  if (misc_info)
    {
      s = format (s, "\n%U%v", format_white_space, indent + 4, misc_info);
      vec_free (misc_info);
    }

  return s;
}

f64 vlib_get_stat_segment_update_rate (void) __attribute__ ((weak));
f64
vlib_get_stat_segment_update_rate (void)
{
  return 1e70;
}

static clib_error_t *
show_node_runtime (vlib_main_t * vm,
		   unformat_input_t * input, vlib_cli_command_t * cmd)
{
  vlib_node_main_t *nm = &vm->node_main;
  vlib_node_t *n;
  f64 time_now;
  u32 node_index;
  vlib_node_t ***node_dups = 0;
  f64 *internal_node_vector_rates = 0;

  time_now = vlib_time_now (vm);

  if (unformat (input, "%U", unformat_vlib_node, vm, &node_index))
    {
      n = vlib_get_node (vm, node_index);
      vlib_node_sync_stats (vm, n);
      vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, 0, 0);
      vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, n, 0);
    }
  else
    {
      vlib_node_t **nodes;
      uword i, j;
      f64 dt;
      u64 n_input, n_output, n_drop, n_punt;
      u64 n_internal_vectors, n_internal_calls;
      u64 n_clocks, l, v, c, d;
      int brief = 1;
      int summary = 0;
      int max = 0;
      vlib_main_t **stat_vms = 0, *stat_vm;

      /* Suppress nodes with zero calls since last clear */
      if (unformat (input, "brief") || unformat (input, "b"))
	brief = 1;
      if (unformat (input, "verbose") || unformat (input, "v"))
	brief = 0;
      if (unformat (input, "max") || unformat (input, "m"))
	max = 1;
      if (unformat (input, "summary") || unformat (input, "sum")
	  || unformat (input, "su"))
	summary = 1;

      for (i = 0; i < vlib_get_n_threads (); i++)
	{
	  stat_vm = vlib_get_main_by_index (i);
	  if (stat_vm)
	    vec_add1 (stat_vms, stat_vm);
	}

      /*
       * Barrier sync across stats scraping.
       * Otherwise, the counts will be grossly inaccurate.
       */
      vlib_worker_thread_barrier_sync (vm);

      for (j = 0; j < vec_len (stat_vms); j++)
	{
	  stat_vm = stat_vms[j];
	  nm = &stat_vm->node_main;

	  for (i = 0; i < vec_len (nm->nodes); i++)
	    {
	      n = nm->nodes[i];
	      vlib_node_sync_stats (stat_vm, n);
	    }

	  nodes = vec_dup (nm->nodes);

	  vec_add1 (node_dups, nodes);
	  vec_add1 (internal_node_vector_rates,
		    vlib_internal_node_vector_rate (stat_vm));
	}
      vlib_worker_thread_barrier_release (vm);


      for (j = 0; j < vec_len (stat_vms); j++)
	{
	  stat_vm = stat_vms[j];
	  nodes = node_dups[j];

	  vec_sort_with_function (nodes, node_cmp);

	  n_input = n_output = n_drop = n_punt = n_clocks = 0;
	  n_internal_vectors = n_internal_calls = 0;
	  for (i = 0; i < vec_len (nodes); i++)
	    {
	      n = nodes[i];

	      l = n->stats_total.clocks - n->stats_last_clear.clocks;
	      n_clocks += l;

	      v = n->stats_total.vectors - n->stats_last_clear.vectors;
	      c = n->stats_total.calls - n->stats_last_clear.calls;

	      switch (n->type)
		{
		default:
		  continue;

		case VLIB_NODE_TYPE_INTERNAL:
		  n_output += (n->flags & VLIB_NODE_FLAG_IS_OUTPUT) ? v : 0;
		  n_drop += (n->flags & VLIB_NODE_FLAG_IS_DROP) ? v : 0;
		  n_punt += (n->flags & VLIB_NODE_FLAG_IS_PUNT) ? v : 0;
		  if (!(n->flags & VLIB_NODE_FLAG_IS_OUTPUT))
		    {
		      n_internal_vectors += v;
		      n_internal_calls += c;
		    }
		  if (n->flags & VLIB_NODE_FLAG_IS_HANDOFF)
		    n_input += v;
		  break;

		case VLIB_NODE_TYPE_INPUT:
		  n_input += v;
		  break;
		}
	    }

	  if (vlib_get_n_threads () > 1)
	    {
	      vlib_worker_thread_t *w = vlib_worker_threads + j;
	      if (j > 0)
		vlib_cli_output (vm, "---------------");

	      if (w->cpu_id > -1)
		vlib_cli_output (vm, "Thread %d %s (lcore %u)", j, w->name,
				 w->cpu_id);
	      else
		vlib_cli_output (vm, "Thread %d %s", j, w->name);
	    }

	  dt = time_now - nm->time_last_runtime_stats_clear;
	  vlib_cli_output
	    (vm,
	     "Time %.1f, %f sec internal node vector rate %.2f loops/sec %.2f\n"
	     "  vector rates in %.4e, out %.4e, drop %.4e, punt %.4e",
	     dt,
	     vlib_get_stat_segment_update_rate (),
	     internal_node_vector_rates[j],
	     stat_vm->loops_per_second,
	     (f64) n_input / dt,
	     (f64) n_output / dt, (f64) n_drop / dt, (f64) n_punt / dt);

	  if (summary == 0)
	    {
	      vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm,
			       0, max);
	      for (i = 0; i < vec_len (nodes); i++)
		{
		  c =
		    nodes[i]->stats_total.calls -
		    nodes[i]->stats_last_clear.calls;
		  d =
		    nodes[i]->stats_total.suspends -
		    nodes[i]->stats_last_clear.suspends;
		  if (c || d || !brief)
		    {
		      vlib_cli_output (vm, "%U", format_vlib_node_stats,
				       stat_vm, nodes[i], max);
		    }
		}
	    }
	  vec_free (nodes);
	}
      vec_free (stat_vms);
      vec_free (node_dups);
      vec_free (internal_node_vector_rates);
    }

  return 0;
}

/* *INDENT-OFF* */
VLIB_CLI_COMMAND (show_node_runtime_command, static) = {
  .path = "show runtime",
  .short_help = "Show packet processing runtime",
  .function = show_node_runtime,
  .is_mp_safe = 1,
};
/* *INDENT-ON* */

static clib_error_t *
clear_node_runtime (vlib_main_t * vm,
		    unformat_input_t * input, vlib_cli_command_t * cmd)
{
  vlib_node_main_t *nm;
  vlib_node_t *n;
  int i, j;
  vlib_main_t **stat_vms = 0, *stat_vm;
  vlib_node_runtime_t *r;

  for (i = 0; i < vlib_get_n_threads (); i++)
    {
      stat_vm = vlib_get_main_by_index (i);
      if (stat_vm)
	vec_add1 (stat_vms, stat_vm);
    }

  vlib_worker_thread_barrier_sync (vm);

  for (j = 0; j < vec_len (stat_vms); j++)
    {
      stat_vm = stat_vms[j];
      nm = &stat_vm->node_main;

      for (i = 0; i < vec_len (nm->nodes); i++)
	{
	  n = nm->nodes[i];
	  vlib_node_sync_stats (stat_vm, n);
	  n->stats_last_clear = n->stats_total;

	  r = vlib_node_get_runtime (stat_vm, n->index);
	  r->max_clock = 0;
	}
      /* Note: input/output rates computed using vlib_global_main */
      nm->time_last_runtime_stats_clear = vlib_time_now (vm);
    }

  vlib_worker_thread_barrier_release (vm);

  vec_free (stat_vms);

  return 0;
}

/* *INDENT-OFF* */
VLIB_CLI_COMMAND (clear_node_runtime_command, static) = {
  .path = "clear runtime",
  .short_help = "Clear packet processing runtime statistics",
  .function = clear_node_runtime,
};
/* *INDENT-ON* */

static clib_error_t *
show_node (vlib_main_t * vm, unformat_input_t * input,
	   vlib_cli_command_t * cmd)
{
  unformat_input_t _line_input, *line_input = &_line_input;
  clib_error_t *error = 0;
  vlib_node_main_t *nm = &vm->node_main;
  vlib_node_t *n;
  u8 *s = 0, *s2 = 0;
  u32 i, node_index = ~0, verbose = 0;
  char *type_str;
  u8 valid_node_name = 0;
  u64 cl, ca, v;

  if (!unformat_user (input, unformat_line_input, line_input))
    return 0;

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "index %u", &node_index))
	;
      else if (unformat (line_input, "verbose"))
	verbose = 1;
      else
	if (unformat (line_input, "%U", unformat_vlib_node, vm, &node_index))
	valid_node_name = 1;
      else if (!valid_node_name)
	error = clib_error_return (0, "unknown node name: '%U'",
				   format_unformat_error, line_input);
      else
	error = clib_error_return (0, "unknown input '%U'",
				   format_unformat_error, line_input);

      if (error)
	break;
    }

  unformat_free (line_input);

  if (error)
    return error;

  if (node_index >= vec_len (vm->node_main.nodes))
    return clib_error_return (0, "please specify valid node");

  n = vlib_get_node (vm, node_index);
  vlib_node_sync_stats (vm, n);

  switch (n->type)
    {
    case VLIB_NODE_TYPE_INTERNAL:
      type_str = "internal";
      break;
    case VLIB_NODE_TYPE_INPUT:
      type_str = "input";
      break;
    case VLIB_NODE_TYPE_PRE_INPUT:
      type_str = "pre-input";
      break;
    case VLIB_NODE_TYPE_PROCESS:
      type_str = "process";
      break;
    default:
      type_str = "unknown";
    }

  if (n->sibling_of)
    s = format (s, ", sibling-of %s", n->sibling_of);

  vlib_cli_output (vm, "node %v, type %s, state %U, index %d%v\n",
		   n->name, type_str, format_vlib_node_state, vm, n,
		   n->index, s);
  vec_reset_length (s);

  if (n->node_fn_registrations)
    {
      vlib_node_fn_registration_t *fnr = n->node_fn_registrations;
      vlib_node_fn_variant_t *v;
      while (fnr)
	{
	  v = vec_elt_at_index (vm->node_main.variants, fnr->march_variant);
	  if (vec_len (s) == 0)
	    s = format (s, "\n    %-15s  %=8s  %6s  %s", "Name", "Priority",
			"Active", "Description");
	  s = format (s, "\n    %-15s  %8d  %=6s  %s", v->suffix, v->priority,
		      fnr->function == n->function ? "yes" : "", v->desc);
	  fnr = fnr->next_registration;
	}
    }
  else
    s = format (s, "\n    default only");
  vlib_cli_output (vm, "  node function variants:%v\n", s);
  vec_reset_length (s);

  for (i = 0; i < vec_len (n->next_nodes); i++)
    {
      vlib_node_t *pn;
      if (n->next_nodes[i] == VLIB_INVALID_NODE_INDEX)
	continue;

      pn = vec_elt (nm->nodes, n->next_nodes[i]);

      if (vec_len (s) == 0)
	s = format (s, "\n    %10s  %10s  %=30s %8s",
		    "next-index", "node-index", "Node", "Vectors");

      s = format (s, "\n    %=10u  %=10u  %=30v %=8llu", i, n->next_nodes[i],
		  pn->name, vec_elt (n->n_vectors_by_next_node, i));
    }

  if (vec_len (s) == 0)
    s = format (s, "\n    none");
  vlib_cli_output (vm, "\n  next nodes:%v\n", s);
  vec_reset_length (s);

  if (n->type == VLIB_NODE_TYPE_INTERNAL)
    {
      int j = 0;
      /* *INDENT-OFF* */
      clib_bitmap_foreach (i, n->prev_node_bitmap)  {
	    vlib_node_t *pn = vlib_get_node (vm, i);
	    if (j++ % 3 == 0)
	      s = format (s, "\n    ");
	    s2 = format (s2, "%v (%u)", pn->name, i);
	    s = format (s, "%-35v", s2);
	    vec_reset_length (s2);
	  }
      /* *INDENT-ON* */

      if (vec_len (s) == 0)
	s = format (s, "\n    none");
      vlib_cli_output (vm, "\n  known previous nodes:%v\n", s);
      vec_reset_length (s);
      vec_free (s2);
    }

  if (!verbose)
    goto done;

  s = format (s, "\n%8s %=12s %=12s %=12s %=12s %=12s\n", "Thread", "Calls",
	      "Clocks", "Vectors", "Max Clock", "Max Vectors");
  for (i = 0; i < vlib_get_n_threads (); i++)
    {
      n = vlib_get_node (vlib_get_main_by_index (i), node_index);
      vlib_node_sync_stats (vlib_get_main_by_index (i), n);

      cl = n->stats_total.clocks - n->stats_last_clear.clocks;
      ca = n->stats_total.calls - n->stats_last_clear.calls;
      v = n->stats_total.vectors - n->stats_last_clear.vectors;

      s = format (s, "%=8u %=12lu %=12lu %=12lu %=12u %=12u\n", i, ca, cl, v,
		  n->stats_total.max_clock, n->stats_total.max_clock_n);
    }

  vlib_cli_output (vm, "%v", s);

done:

  vec_free (s);
  return 0;
}

/* *INDENT-OFF* */
VLIB_CLI_COMMAND (show_node_command, static) = {
  .path = "show node",
  .short_help = "show node [index] <node-name | node-index>",
  .function = show_node,
};

static clib_error_t *
set_node_fn(vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
{
  unformat_input_t _line_input, *line_input = &_line_input;
  u32 node_index, march_variant;
  vlib_node_t *n;
  clib_error_t *err = 0;

  if (!unformat_user (input, unformat_line_input, line_input))
    return 0;

  if (!unformat (line_input, "%U", unformat_vlib_node, vm, &node_index))
    {
      err = clib_error_return (0, "please specify valid node name");
      goto done;
    }

  if (!unformat (line_input, "%U", unformat_vlib_node_variant, &march_variant))
    {
      err = clib_error_return (0, "please specify node function variant");
      goto done;
    }

  n = vlib_get_node (vm, node_index);

  if (n->node_fn_registrations == 0)
    {
      err = clib_error_return (0, "node doesn't have function variants");
      goto done;
    }

  if (vlib_node_set_march_variant (vm, node_index, march_variant))
    {
      vlib_node_fn_variant_t *v;
      v = vec_elt_at_index (vm->node_main.variants, march_variant);
      err = clib_error_return (0, "node function variant '%s' not found",
			       v->suffix);
      goto done;
    }


done:
  unformat_free (line_input);
  return err;
}

/* *INDENT-OFF* */
VLIB_CLI_COMMAND (set_node_fn_command, static) = {
  .path = "set node function",
  .short_help = "set node function <node-name> <variant-name>",
  .function = set_node_fn,
};
/* *INDENT-ON* */

/* Dummy function to get us linked in. */
void
vlib_node_cli_reference (void)
{
}

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
