VPP-81: Print interface name after creating an interface with CLI 24/1224/2
authorPierre Pfister <ppfister@cisco.com>
Mon, 23 May 2016 11:51:54 +0000 (12:51 +0100)
committerChris Luke <chris_luke@cable.comcast.com>
Mon, 23 May 2016 14:46:13 +0000 (14:46 +0000)
When the CLI is used to create an interface, and whend the operation
succeeds, the newly created interface name is printed-out.

The patch includes the following interfaces types:
- AF_PACKET
- Vhost User
- Netmap
- GRE
- L2TP
- MPLS-GRE
- Loopback

Change-Id: Id518c139ec63a261eae81d2ed95c4cd1f10b5157
Signed-off-by: Pierre Pfister <ppfister@cisco.com>
17 files changed:
vnet/vnet/devices/af_packet/af_packet.c
vnet/vnet/devices/af_packet/af_packet.h
vnet/vnet/devices/af_packet/cli.c
vnet/vnet/devices/dpdk/vhost_user.c
vnet/vnet/devices/netmap/cli.c
vnet/vnet/devices/netmap/netmap.c
vnet/vnet/devices/netmap/netmap.h
vnet/vnet/devices/virtio/vhost-user.c
vnet/vnet/ethernet/interface.c
vnet/vnet/gre/interface.c
vnet/vnet/interface_cli.c
vnet/vnet/l2tp/l2tp.c
vnet/vnet/mpls-gre/interface.c
vnet/vnet/unix/tapcli.c
vnet/vnet/vxlan-gpe/vxlan_gpe.c
vnet/vnet/vxlan/vxlan.c
vpp/api/api.c

index 20c6129..b41eaf3 100644 (file)
@@ -162,7 +162,7 @@ error:
 }
 
 int
-af_packet_create_if(vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set)
+af_packet_create_if(vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set, u32 *sw_if_index)
 {
   af_packet_main_t * apm = &af_packet_main;
   int ret, fd = -1;
@@ -258,7 +258,8 @@ af_packet_create_if(vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set)
                               VNET_HW_INTERFACE_FLAG_LINK_UP);
 
   mhash_set_mem (&apm->if_index_by_host_if_name, host_if_name, &if_index, 0);
-
+  if (sw_if_index)
+    *sw_if_index = apif->sw_if_index;
   return 0;
 
 error:
index 21f41c7..258700b 100644 (file)
@@ -54,5 +54,5 @@ af_packet_main_t af_packet_main;
 extern vnet_device_class_t af_packet_device_class;
 extern vlib_node_registration_t af_packet_input_node;
 
-int af_packet_create_if(vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set);
+int af_packet_create_if(vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set, u32 *sw_if_index);
 int af_packet_delete_if(vlib_main_t * vm, u8 * host_if_name);
index 4ac51cb..3153efe 100644 (file)
@@ -40,6 +40,7 @@ af_packet_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
   u8 * host_if_name = NULL;
   u8 hwaddr [6];
   u8 * hw_addr_ptr = 0;
+  u32 sw_if_index;
   int r;
 
   /* Get a line of input. */
@@ -60,7 +61,7 @@ af_packet_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
   if (host_if_name == NULL)
       return clib_error_return (0, "missing host interface name");
 
-  r = af_packet_create_if(vm, host_if_name, hw_addr_ptr);
+  r = af_packet_create_if(vm, host_if_name, hw_addr_ptr, &sw_if_index);
 
   if (r == VNET_API_ERROR_SYSCALL_ERROR_1)
     return clib_error_return(0, "%s (errno %d)", strerror (errno), errno);
@@ -71,6 +72,7 @@ af_packet_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
   if (r == VNET_API_ERROR_SUBIF_ALREADY_EXISTS)
     return clib_error_return(0, "Interface elready exists");
 
+  vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
   return 0;
 }
 
index 9bf7674..a461d39 100644 (file)
@@ -1702,6 +1702,7 @@ dpdk_vhost_user_connect_command_fn (vlib_main_t * vm,
                             renumber, custom_dev_instance, hw);
 
   vec_free(sock_filename);
+  vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
   return 0;
 }
 
index 584d680..5bf80e7 100644 (file)
@@ -36,6 +36,7 @@ netmap_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
   int r;
   u8 is_pipe = 0;
   u8 is_master = 0;
+  u32 sw_if_index = ~0;
 
   /* Get a line of input. */
   if (! unformat_user (input, unformat_line_input, line_input))
@@ -61,7 +62,7 @@ netmap_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
   if (host_if_name == NULL)
       return clib_error_return (0, "missing host interface name");
 
-  r = netmap_create_if(vm, host_if_name, hw_addr_ptr, is_pipe, is_master);
+  r = netmap_create_if(vm, host_if_name, hw_addr_ptr, is_pipe, is_master, &sw_if_index);
 
   if (r == VNET_API_ERROR_SYSCALL_ERROR_1)
     return clib_error_return(0, "%s (errno %d)", strerror (errno), errno);
@@ -72,6 +73,7 @@ netmap_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
   if (r == VNET_API_ERROR_SUBIF_ALREADY_EXISTS)
     return clib_error_return(0, "Interface already exists");
 
+  vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
   return 0;
 }
 
index 2f3233a..df3b2be 100644 (file)
@@ -80,7 +80,7 @@ close_netmap_if(netmap_main_t * nm, netmap_if_t * nif)
 
 int
 netmap_create_if(vlib_main_t * vm, u8 * if_name, u8 * hw_addr_set,
-                u8 is_pipe, u8 is_master)
+                u8 is_pipe, u8 is_master, u32 *sw_if_index)
 {
   netmap_main_t * nm = &netmap_main;
   int ret = 0;
@@ -194,6 +194,9 @@ netmap_create_if(vlib_main_t * vm, u8 * if_name, u8 * hw_addr_set,
 
   mhash_set_mem (&nm->if_index_by_host_if_name, if_name, &nif->if_index, 0);
 
+  if (sw_if_index)
+    *sw_if_index = nif->sw_if_index;
+
   return 0;
 
 error:
index c5b3dfb..6f7791c 100644 (file)
@@ -90,7 +90,8 @@ netmap_main_t netmap_main;
 extern vnet_device_class_t netmap_device_class;
 extern vlib_node_registration_t netmap_input_node;
 
-int netmap_create_if(vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set, u8 is_pipe, u8 is_master);
+int netmap_create_if(vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
+                     u8 is_pipe, u8 is_master, u32 *sw_if_index);
 int netmap_delete_if(vlib_main_t * vm, u8 * host_if_name);
 
 
index ef4993f..4ed45e3 100644 (file)
@@ -1791,7 +1791,7 @@ vhost_user_connect_command_fn (vlib_main_t * vm,
                        renumber, custom_dev_instance, hw);
 
   vec_free(sock_filename);
-
+  vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
   return 0;
 }
 
index 833ee30..fd64030 100644 (file)
@@ -431,6 +431,7 @@ create_simulated_ethernet_interfaces (vlib_main_t * vm,
   if (rv)
     return clib_error_return (0, "vnet_create_loopback_interface failed");
 
+  vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
   return 0;
 }
 
index 1e442bc..ae59b24 100644 (file)
@@ -159,6 +159,7 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
   int rv;
   u32 num_m_args = 0;
   u8 is_add = 1;
+  u32 sw_if_index;
 
   /* Get a line of input. */
   if (! unformat_user (input, unformat_line_input, line_input))
@@ -191,11 +192,12 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
   clib_memcpy(&a->src, &src, sizeof(src));
   clib_memcpy(&a->dst, &dst, sizeof(dst));
 
-  rv = vnet_gre_add_del_tunnel (a, 0);
+  rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
 
   switch(rv)
     {
     case 0:
+      vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
       break;
     case VNET_API_ERROR_INVALID_VALUE:
       return clib_error_return (0, "GRE tunnel already exists...");
index 13a7d8c..d0d7515 100644 (file)
@@ -608,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)
index d359a50..7dfbe15 100644 (file)
@@ -466,6 +466,7 @@ create_l2tpv3_tunnel_command_fn (vlib_main_t * vm,
   switch(rv)
     {
     case 0:
+      vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
       break;
     case VNET_API_ERROR_INVALID_VALUE:
       return clib_error_return (0, "session already exists...");
index 75cd022..5b78072 100644 (file)
@@ -1083,6 +1083,8 @@ create_mpls_gre_tunnel_command_fn (vlib_main_t * vm,
   switch (rv) 
     {
     case 0:
+      if (!is_del)
+        vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), tunnel_intfc_sw_if_index);
       break;
 
     case VNET_API_ERROR_NO_SUCH_INNER_FIB:
@@ -1521,6 +1523,7 @@ create_mpls_ethernet_tunnel_command_fn (vlib_main_t * vm,
   u8 is_del = 0;
   u8 l2_only = 0;
   u32 tx_sw_if_index;
+  u32 sw_if_index = ~0;
   
   /* Get a line of input. */
   if (! unformat_user (input, unformat_line_input, line_input))
@@ -1560,11 +1563,15 @@ create_mpls_ethernet_tunnel_command_fn (vlib_main_t * vm,
 
   rv = vnet_mpls_ethernet_add_del_tunnel (dst, &intfc, mask_width, 
                                           inner_fib_id, tx_sw_if_index, 
-                                          0 /* tunnel sw_if_index */, 
+                                          &sw_if_index,
                                           l2_only, !is_del);
 
   switch (rv) 
     {
+    case 0:
+      if (!is_del)
+        vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
+      break;
     case VNET_API_ERROR_NO_SUCH_FIB:
       return clib_error_return (0, "rx fib ID %d doesn't exist\n",
                                 inner_fib_id);
@@ -1582,6 +1589,7 @@ create_mpls_ethernet_tunnel_command_fn (vlib_main_t * vm,
       break;
       
     default:
+      return clib_error_return (0, "vnet_mpls_ethernet_add_del_tunnel returned %d", rv);
       break;
     }
   return 0;
@@ -1902,6 +1910,10 @@ create_mpls_ethernet_policy_tunnel_command_fn (vlib_main_t * vm,
                                                  l2_only, !is_del);
   switch (rv) 
     {
+    case 0:
+      if (!is_del)
+        vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), new_tunnel_index);
+      break;
     case VNET_API_ERROR_NO_SUCH_FIB:
       return clib_error_return (0, "rx fib ID %d doesn't exist\n",
                                 inner_fib_id);
@@ -1919,12 +1931,10 @@ create_mpls_ethernet_policy_tunnel_command_fn (vlib_main_t * vm,
       break;
       
     default:
+      return clib_error_return (0, "vnet_mpls_ethernet_add_del_policy_tunnel returned %d", rv);
       break;
     }
 
-  if (!is_del)
-    vlib_cli_output (vm, "tunnel index %d", new_tunnel_index);
-
   return 0;
 }
 
index a299936..1d5beba 100644 (file)
@@ -1090,12 +1090,8 @@ tap_connect_command_fn (vlib_main_t * vm,
     return 0;
   }
 
-  vlib_cli_output (vm, "Created %U for Linux tap '%s'",
-                  format_vnet_sw_if_index_name, tm->vnet_main, 
-                  sw_if_index, intfc_name);
-                   
+  vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
   return 0;
-
   }
 
 VLIB_CLI_COMMAND (tap_connect_command, static) = {
index bee6e7c..76cba05 100644 (file)
@@ -326,6 +326,7 @@ vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm,
   int rv;
   u32 tmp;
   vnet_vxlan_gpe_add_del_tunnel_args_t _a, * a = &_a;
+  u32 sw_if_index;
   
   /* Get a line of input. */
   if (! unformat_user (input, unformat_line_input, line_input))
@@ -389,11 +390,12 @@ vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm,
   foreach_gpe_copy_field;
 #undef _
 
-  rv = vnet_vxlan_gpe_add_del_tunnel (a, 0 /* hw_if_indexp */);
+  rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
 
   switch(rv)
     {
     case 0:
+      vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
       break;
     case VNET_API_ERROR_INVALID_DECAP_NEXT:
       return clib_error_return (0, "invalid decap-next...");
index 89e56e7..9e0d0a5 100644 (file)
@@ -419,6 +419,7 @@ vxlan_add_del_tunnel_command_fn (vlib_main_t * vm,
   u32 tmp;
   int rv;
   vnet_vxlan_add_del_tunnel_args_t _a, * a = &_a;
+  u32 sw_if_index;
   
   /* Get a line of input. */
   if (! unformat_user (input, unformat_line_input, line_input))
@@ -504,11 +505,13 @@ vxlan_add_del_tunnel_command_fn (vlib_main_t * vm,
   else          foreach_copy_ipv6
 #undef _
   
-  rv = vnet_vxlan_add_del_tunnel (a, 0 /* hw_if_indexp */);
+  rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
 
   switch(rv)
     {
     case 0:
+      if (is_add)
+        vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
       break;
     case VNET_API_ERROR_INVALID_DECAP_NEXT:
       return clib_error_return (0, "invalid decap-next...");
index 3b56d1c..3bf2ed4 100644 (file)
@@ -5930,7 +5930,7 @@ vl_api_af_packet_create_t_handler
     vec_add1 (host_if_name, 0);
 
     rv = af_packet_create_if(vm, host_if_name,
-                             mp->use_random_hw_addr ? 0 : mp->hw_addr);
+                             mp->use_random_hw_addr ? 0 : mp->hw_addr, 0);
 
     vec_free(host_if_name);
 
@@ -6077,7 +6077,7 @@ vl_api_netmap_create_t_handler
     vec_add1 (if_name, 0);
 
     rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
-                          mp->is_pipe, mp->is_master);
+                          mp->is_pipe, mp->is_master, 0);
 
     vec_free(if_name);