Add a name to the creation of an IP and MPLS table

Change-Id: I4b4648831551519b2ffb6f93255d28a4b8726c22
Signed-off-by: Neale Ranns <nranns@cisco.com>
diff --git a/src/vnet/ip/ip.api b/src/vnet/ip/ip.api
index e57c2fe..f26d794 100644
--- a/src/vnet/ip/ip.api
+++ b/src/vnet/ip/ip.api
@@ -27,6 +27,9 @@
     @param table_id - table ID associated with the route
                       This table ID will apply to both the unicats
 		      and mlticast FIBs
+    @param name - A client provided name/tag for the table. If this is
+                  not set by the client, then VPP will generate something
+		  meaningfull.
 */
 autoreply define ip_table_add_del
 {
@@ -35,6 +38,7 @@
   u32 table_id;
   u8 is_ipv6;
   u8 is_add;
+  u8 name[64];
 };
 
 /** \brief Dump IP fib table
@@ -83,6 +87,7 @@
 {
   u32 context;
   u32 table_id;
+  u8  table_name[64];
   u8  address_length;
   u8  address[4];
   u32 count;
@@ -98,10 +103,10 @@
   u32 context;
 };
 
-/** \brief IP6 FIB table response
+/** \brief IP6 FIB table entry response
     @param table_id - IP6 fib table id
-    @address_length - mask length
-    @address - ip6 prefix
+    @param address_length - mask length
+    @param address - ip6 prefix
     @param count - the number of fib_path in path
     @param path  - array of of fib_path structures
 */
@@ -109,6 +114,7 @@
 {
   u32 context;
   u32 table_id;
+  u8  table_name[64];
   u8  address_length;
   u8  address[16];
   u32 count;
diff --git a/src/vnet/ip/ip.h b/src/vnet/ip/ip.h
index 7880786..7e26bc6 100644
--- a/src/vnet/ip/ip.h
+++ b/src/vnet/ip/ip.h
@@ -184,7 +184,8 @@
 extern vlib_node_registration_t ip4_inacl_node;
 extern vlib_node_registration_t ip6_inacl_node;
 
-void ip_table_create (fib_protocol_t fproto, u32 table_id, u8 is_api);
+void ip_table_create (fib_protocol_t fproto, u32 table_id, u8 is_api,
+		      const u8 * name);
 
 void ip_table_delete (fib_protocol_t fproto, u32 table_id, u8 is_api);
 
diff --git a/src/vnet/ip/ip_api.c b/src/vnet/ip/ip_api.c
index 384ec3e..bb29e0b 100644
--- a/src/vnet/ip/ip_api.c
+++ b/src/vnet/ip/ip_api.c
@@ -180,7 +180,8 @@
 static void
 send_ip_fib_details (vpe_api_main_t * am,
 		     unix_shared_memory_queue_t * q,
-		     u32 table_id, fib_prefix_t * pfx,
+		     const fib_table_t * table,
+		     const fib_prefix_t * pfx,
 		     fib_route_path_encode_t * api_rpaths, u32 context)
 {
   vl_api_ip_fib_details_t *mp;
@@ -196,7 +197,9 @@
   mp->_vl_msg_id = ntohs (VL_API_IP_FIB_DETAILS);
   mp->context = context;
 
-  mp->table_id = htonl (table_id);
+  mp->table_id = htonl (table->ft_table_id);
+  memcpy (mp->table_name, table->ft_desc,
+	  clib_min (vec_len (table->ft_desc), sizeof (mp->table_name)));
   mp->address_length = pfx->fp_len;
   memcpy (mp->address, &pfx->fp_addr.ip4, sizeof (pfx->fp_addr.ip4));
 
@@ -295,9 +298,7 @@
     fib_table = fib_table_get (fib_index, pfx.fp_proto);
     api_rpaths = NULL;
     fib_entry_encode (*lfeip, &api_rpaths);
-    send_ip_fib_details (am, q,
-			 fib_table->ft_table_id, &pfx, api_rpaths,
-			 mp->context);
+    send_ip_fib_details (am, q, fib_table, &pfx, api_rpaths, mp->context);
     vec_free (api_rpaths);
   }
 
@@ -744,7 +745,7 @@
 
   if (mp->is_add)
     {
-      ip_table_create (fproto, table_id, 1);
+      ip_table_create (fproto, table_id, 1, mp->name);
     }
   else
     {
@@ -1124,7 +1125,8 @@
 }
 
 void
-ip_table_create (fib_protocol_t fproto, u32 table_id, u8 is_api)
+ip_table_create (fib_protocol_t fproto,
+		 u32 table_id, u8 is_api, const u8 * name)
 {
   u32 fib_index, mfib_index;
 
@@ -1147,17 +1149,17 @@
 
       if (~0 == fib_index)
 	{
-	  fib_table_find_or_create_and_lock (fproto, table_id,
-					     (is_api ?
-					      FIB_SOURCE_API :
-					      FIB_SOURCE_CLI));
+	  fib_table_find_or_create_and_lock_w_name (fproto, table_id,
+						    (is_api ?
+						     FIB_SOURCE_API :
+						     FIB_SOURCE_CLI), name);
 	}
       if (~0 == mfib_index)
 	{
-	  mfib_table_find_or_create_and_lock (fproto, table_id,
-					      (is_api ?
-					       MFIB_SOURCE_API :
-					       MFIB_SOURCE_CLI));
+	  mfib_table_find_or_create_and_lock_w_name (fproto, table_id,
+						     (is_api ?
+						      MFIB_SOURCE_API :
+						      MFIB_SOURCE_CLI), name);
 	}
     }
 }
diff --git a/src/vnet/ip/lookup.c b/src/vnet/ip/lookup.c
index 667c679..d9922f4 100755
--- a/src/vnet/ip/lookup.c
+++ b/src/vnet/ip/lookup.c
@@ -695,6 +695,7 @@
   unformat_input_t _line_input, *line_input = &_line_input;
   clib_error_t *error = NULL;
   u32 table_id, is_add;
+  u8 *name = NULL;
 
   is_add = 1;
   table_id = ~0;
@@ -711,6 +712,8 @@
 	is_add = 0;
       else if (unformat (line_input, "add"))
 	is_add = 1;
+      else if (unformat (line_input, "name %s", &name))
+	;
       else
 	{
 	  error = unformat_parse_error (line_input);
@@ -732,7 +735,7 @@
     {
       if (is_add)
 	{
-	  ip_table_create (fproto, table_id, 0);
+	  ip_table_create (fproto, table_id, 0, name);
 	}
       else
 	{