feature: add descriptive cli command output for 'set interface feature'
[vpp.git] / src / vnet / feature / feature.c
index f1afa37..0f0bfeb 100644 (file)
  */
 
 #include <vnet/feature/feature.h>
-#include <vnet/adj/adj.h>
+
 
 vnet_feature_main_t feature_main;
 
+typedef struct vnet_feature_upd_registration_t_
+{
+  vnet_feature_update_cb_t cb;
+  void *data;
+} vnet_feature_upd_registration_t;
+
+static vnet_feature_upd_registration_t *regs;
+
+void
+vnet_feature_register (vnet_feature_update_cb_t cb, void *data)
+{
+  vnet_feature_upd_registration_t *reg;
+
+  vec_add2 (regs, reg, 1);
+
+  reg->cb = cb;
+  reg->data = data;
+}
+
+static void
+vent_feature_reg_invoke (u32 sw_if_index, u8 arc_index, u8 is_enable)
+{
+  vnet_feature_upd_registration_t *reg;
+
+  vec_foreach (reg, regs)
+    reg->cb (sw_if_index, arc_index, is_enable, reg->data);
+}
+
+
 static clib_error_t *
 vnet_feature_init (vlib_main_t * vm)
 {
@@ -122,6 +151,7 @@ vnet_feature_init (vlib_main_t * vm)
       vcm = &cm->config_main;
       if ((error = vnet_feature_arc_init
           (vm, vcm, areg->start_nodes, areg->n_start_nodes,
+           areg->last_in_arc,
            fm->next_feature_by_arc[arc_index],
            fm->next_constraint_by_arc[arc_index],
            &fm->feature_nodes[arc_index])))
@@ -132,7 +162,7 @@ vnet_feature_init (vlib_main_t * vm)
 
       features_in_order = fm->feature_nodes[arc_index];
 
-      /* If specificed, verify that the last node in the arc is actually last */
+      /* If specified, verify that the last node in the arc is actually last */
       if (areg->last_in_arc && vec_len (features_in_order) > 0)
        {
          last_feature = features_in_order[vec_len (features_in_order) - 1];
@@ -264,7 +294,7 @@ vnet_feature_enable_disable_with_index (u8 arc_index, u32 feature_index,
   fm->sw_if_index_has_features[arc_index] =
     clib_bitmap_set (fm->sw_if_index_has_features[arc_index], sw_if_index,
                     (feature_count > 0));
-  adj_feature_update (sw_if_index, arc_index, (feature_count > 0));
+  vent_feature_reg_invoke (sw_if_index, arc_index, (feature_count > 0));
 
   fm->feature_count_by_sw_if_index[arc_index][sw_if_index] = feature_count;
   return 0;
@@ -366,7 +396,7 @@ show_features_command_fn (vlib_main_t * vm,
 /* *INDENT-OFF* */
 VLIB_CLI_COMMAND (show_features_command, static) = {
   .path = "show features",
-  .short_help = "show features",
+  .short_help = "show features [verbose]",
   .function = show_features_command_fn,
 };
 /* *INDENT-ON* */
@@ -460,21 +490,22 @@ set_interface_features_command_fn (vlib_main_t * vm,
   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
     {
       if (unformat
-         (line_input, "%U %v", unformat_vnet_sw_interface, vnm, &sw_if_index,
-          &feature_name))
-       ;
-      else if (unformat (line_input, "arc %v", &arc_name))
+         (line_input, "%U %s arc %s", unformat_vnet_sw_interface, vnm,
+          &sw_if_index, &feature_name, &arc_name))
        ;
       else if (unformat (line_input, "disable"))
        enable = 0;
       else
        {
-         if (feature_name && arc_name)
-           break;
          error = unformat_parse_error (line_input);
          goto done;
        }
     }
+  if (!feature_name || !arc_name)
+    {
+      error = clib_error_return (0, "Both feature name and arc required...");
+      goto done;
+    }
 
   if (sw_if_index == ~0)
     {
@@ -485,13 +516,28 @@ set_interface_features_command_fn (vlib_main_t * vm,
   vec_add1 (arc_name, 0);
   vec_add1 (feature_name, 0);
 
+  u8 arc_index;
+
+  arc_index = vnet_get_feature_arc_index ((const char *) arc_name);
+
+  if (arc_index == (u8) ~ 0)
+    {
+      error =
+       clib_error_return (0, "Unknown arc name (%s)... ",
+                          (const char *) arc_name);
+      goto done;
+    }
+
   vnet_feature_registration_t *reg;
   reg =
     vnet_get_feature_reg ((const char *) arc_name,
                          (const char *) feature_name);
   if (reg == 0)
     {
-      error = clib_error_return (0, "Unknown feature...");
+      error =
+       clib_error_return (0,
+                          "Feature (%s) not registered to arc (%s)... See 'show features verbose' for valid feature/arc combinations. ",
+                          feature_name, arc_name);
       goto done;
     }
   if (reg->enable_disable_cb)