Reformat output of lisp eid-table show command.
[vpp.git] / vnet / vnet / interface_cli.c
index 8d98652..d0d7515 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <vnet/vnet.h>
 #include <vnet/ip/ip.h>
+#include <vppinfra/bitmap.h>
 
 static int compare_interface_names (void *a1, void *a2)
 {
@@ -58,21 +59,21 @@ show_or_clear_hw_interfaces (vlib_main_t * vm,
   vnet_interface_main_t * im = &vnm->interface_main;
   vnet_hw_interface_t * hi;
   u32 hw_if_index, * hw_if_indices = 0;
-  int i, verbose = 1, is_show;
+  int i, verbose = -1, is_show, show_bond = 0;
 
   is_show = strstr (cmd->path, "show") != 0;
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
       /* See if user wants to show a specific interface. */
       if (unformat (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
-       {
          vec_add1 (hw_if_indices, hw_if_index);
-         /* Implies verbose. */
-         verbose = 1;
-       }
+
+      /* See if user wants to show an interface with a specific hw_if_index. */
+      else if (unformat (input, "%u", &hw_if_index))
+         vec_add1 (hw_if_indices, hw_if_index);
 
       else if (unformat (input, "verbose"))
-       verbose = 1;
+         verbose = 1; /* this is also the default */
 
       else if (unformat (input, "detail"))
        verbose = 2;
@@ -80,6 +81,12 @@ show_or_clear_hw_interfaces (vlib_main_t * vm,
       else if (unformat (input, "brief"))
        verbose = 0;
 
+      else if (unformat (input, "bond"))
+      {
+       show_bond = 1;
+       if (verbose < 0) verbose = 0; /* default to brief for link bonding */
+      }
+
       else
        {
          error = clib_error_return (0, "unknown input `%U'",
@@ -93,6 +100,8 @@ show_or_clear_hw_interfaces (vlib_main_t * vm,
     pool_foreach (hi, im->hw_interfaces,
                  vec_add1 (hw_if_indices, hi - im->hw_interfaces));
 
+  if (verbose < 0) verbose = 1; /* default to verbose (except bond) */
+
   if (is_show)
     {
       /* Sort by name. */
@@ -102,7 +111,23 @@ show_or_clear_hw_interfaces (vlib_main_t * vm,
       for (i = 0; i < vec_len (hw_if_indices); i++)
        {
          hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
-         vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, hi, verbose);
+         if (show_bond == 0) /* show all interfaces */
+             vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 
+                              hi, verbose);
+         else if ((hi->bond_info) && 
+                  (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
+           { /* show only bonded interface and all its slave interfaces */
+             int hw_idx;
+             vnet_hw_interface_t * shi;
+             vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 
+                              hi, verbose);
+             clib_bitmap_foreach (hw_idx, hi->bond_info,
+               ({
+                 shi = vnet_get_hw_interface(vnm, hw_idx);
+                 vlib_cli_output (vm, "%U\n", 
+                                  format_vnet_hw_interface, vnm, shi, verbose);
+               }));
+           }
        }
     }
   else
@@ -126,7 +151,7 @@ show_or_clear_hw_interfaces (vlib_main_t * vm,
 
 VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
   .path = "show hardware-interfaces",
-  .short_help = "show hardware-interfaces [verbose|brief]  [<if-name1> <if-name2> ...]",
+  .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] [<if-name1> <if-name2> ...]",
   .function = show_or_clear_hw_interfaces,
 };
 
@@ -549,6 +574,13 @@ create_sub_interfaces (vlib_main_t * vm,
   */
 
   hi = vnet_get_hw_interface (vnm, hw_if_index);
+
+  if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
+    error = clib_error_return (
+       0, "not allowed as %v belong to a BondEthernet interface", hi->name);
+    goto done;
+  }
+
   for (id = id_min; id <= id_max; id++)
     {
       uword * p;
@@ -576,6 +608,7 @@ create_sub_interfaces (vlib_main_t * vm,
       if (error) goto done;
       hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
       hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
+      vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
     }
 
   if (error)
@@ -767,3 +800,82 @@ VLIB_CLI_COMMAND (renumber_interface_command, static) = {
   .function = renumber_interface_command_fn,
 };
 
+static clib_error_t *
+promiscuous_cmd (vlib_main_t * vm,
+                 unformat_input_t * input,
+                 vlib_cli_command_t * cmd)
+{
+  vnet_main_t * vnm = vnet_get_main();
+  u32 hw_if_index;
+  u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
+  ethernet_main_t * em = &ethernet_main;
+  ethernet_interface_t * eif;
+
+  if (unformat (input, "on %U",
+                unformat_vnet_hw_interface, vnm, &hw_if_index))
+    ;
+  else if (unformat (input, "off %U",
+                     unformat_ethernet_interface, vnm, &hw_if_index))
+    flags = 0;
+  else
+    return clib_error_return (0, "unknown input `%U'",
+                              format_unformat_error, input);
+
+  eif = ethernet_get_interface (em, hw_if_index);
+  if (!eif)
+    return clib_error_return (0, "not supported");
+
+  ethernet_set_flags (vnm, hw_if_index, flags);
+  return 0;
+}
+
+VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
+  .path = "set interface promiscuous",
+  .short_help = "set interface promiscuous [on | off] <intfc>",
+  .function = promiscuous_cmd,
+};
+
+static clib_error_t *
+mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
+{
+  vnet_main_t * vnm = vnet_get_main();
+  u32 hw_if_index, mtu;
+  u32 flags = ETHERNET_INTERFACE_FLAG_MTU;
+  ethernet_main_t * em = &ethernet_main;
+
+  if (unformat (input, "%d %U", &mtu,
+                unformat_vnet_hw_interface, vnm, &hw_if_index))
+    {
+      vnet_hw_interface_t * hi = vnet_get_hw_interface (vnm, hw_if_index);
+      ethernet_interface_t * eif = ethernet_get_interface (em, hw_if_index);
+
+      if (!eif)
+        return clib_error_return (0, "not supported");
+
+      if (mtu < hi->min_supported_packet_bytes)
+       return clib_error_return (0, "Invalid mtu (%d): "
+                                 "must be >= min pkt bytes (%d)", mtu,
+                                 hi->min_supported_packet_bytes);
+
+      if (mtu > hi->max_supported_packet_bytes)
+       return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
+                                  hi->max_supported_packet_bytes);
+
+      if (hi->max_packet_bytes != mtu)
+       {
+         hi->max_packet_bytes = mtu;
+         ethernet_set_flags (vnm, hw_if_index, flags);
+       }
+    }
+  else
+    return clib_error_return (0, "unknown input `%U'",
+                              format_unformat_error, input);
+  return 0;
+}
+
+VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
+  .path = "set interface mtu",
+  .short_help = "set interface mtu <value> <intfc>",
+  .function = mtu_cmd,
+};
+