vlib: refactor node function variants
[vpp.git] / src / vlib / node_cli.c
index bf18702..1c07805 100644 (file)
@@ -442,11 +442,12 @@ show_node_runtime (vlib_main_t * vm,
          dt = time_now - nm->time_last_runtime_stats_clear;
          vlib_cli_output
            (vm,
-            "Time %.1f, %f sec internal node vector rate %.2f \n"
+            "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);
 
@@ -549,9 +550,10 @@ show_node (vlib_main_t * vm, unformat_input_t * input,
   vlib_node_main_t *nm = &vm->node_main;
   vlib_node_t *n;
   u8 *s = 0, *s2 = 0;
-  u32 i, node_index = ~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;
@@ -560,6 +562,8 @@ show_node (vlib_main_t * vm, unformat_input_t * 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;
@@ -614,13 +618,15 @@ show_node (vlib_main_t * vm, unformat_input_t * input,
   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",
-                       "Name", "Priority", "Active");
-         s = format (s, "\n    %-15s  %=8u  %=6s", fnr->name, fnr->priority,
-                     fnr->function == n->function ? "yes" : "");
+           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;
        }
     }
@@ -641,7 +647,7 @@ show_node (vlib_main_t * vm, unformat_input_t * input,
        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],
+      s = format (s, "\n    %=10u  %=10u  %=30v %=8llu", i, n->next_nodes[i],
                  pn->name, vec_elt (n->n_vectors_by_next_node, i));
     }
 
@@ -654,24 +660,46 @@ show_node (vlib_main_t * vm, unformat_input_t * input,
     {
       int j = 0;
       /* *INDENT-OFF* */
-      clib_bitmap_foreach (i, n->prev_node_bitmap, ({
+      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 < vec_len (vlib_mains); i++)
+    {
+      n = vlib_get_node (vlib_mains[i], node_index);
+      vlib_node_sync_stats (vlib_mains[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);
-  vec_free (s2);
   return 0;
 }
 
@@ -686,11 +714,9 @@ 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;
+  u32 node_index, march_variant;
   vlib_node_t *n;
   clib_error_t *err = 0;
-  vlib_node_fn_registration_t *fnr;
-  u8 *variant = 0;
 
   if (!unformat_user (input, unformat_line_input, line_input))
     return 0;
@@ -701,9 +727,9 @@ set_node_fn(vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd
       goto done;
     }
 
-  if (!unformat (line_input, "%s", &variant))
+  if (!unformat (line_input, "%U", unformat_vlib_node_variant, &march_variant))
     {
-      err = clib_error_return (0, "please specify node functional variant");
+      err = clib_error_return (0, "please specify node function variant");
       goto done;
     }
 
@@ -711,36 +737,21 @@ set_node_fn(vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd
 
   if (n->node_fn_registrations == 0)
     {
-      err = clib_error_return (0, "node doesn't have functional variants");
+      err = clib_error_return (0, "node doesn't have function variants");
       goto done;
     }
 
-  fnr = n->node_fn_registrations;
-  vec_add1 (variant, 0);
-
-  while (fnr)
+  if (vlib_node_set_march_variant (vm, node_index, march_variant))
     {
-      if (!strncmp (fnr->name, (char *) variant, vec_len (variant) - 1))
-       {
-         int i;
-
-         n->function = fnr->function;
-
-         for (i = 0; i < vec_len (vlib_mains); i++)
-           {
-             vlib_node_runtime_t *nrt;
-             nrt = vlib_node_get_runtime (vlib_mains[i], n->index);
-             nrt->function = fnr->function;
-           }
-         goto done;
-       }
-      fnr = fnr->next_registration;
+      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;
     }
 
-  err = clib_error_return (0, "node functional variant '%s' not found", variant);
 
 done:
-  vec_free (variant);
   unformat_free (line_input);
   return err;
 }