FIB: correctly report IPv6 FIB Unicast and Multicast memory usage (VPP-1578)"

and document scaling

Change-Id: I65d8999e65616d77e525963c770d91e9b0d5e593
Signed-off-by: Neale Ranns <nranns@cisco.com>
diff --git a/src/vnet/fib/fib_node.c b/src/vnet/fib/fib_node.c
index d2e3f04..3e99007 100644
--- a/src/vnet/fib/fib_node.c
+++ b/src/vnet/fib/fib_node.c
@@ -237,7 +237,7 @@
 
     vlib_cli_output (vm, "FIB memory");
     vlib_cli_output (vm, "  Tables:");
-    vlib_cli_output (vm, "%=30s %=6s %=8s", "SAFI", "Number", "Bytes");
+    vlib_cli_output (vm, "%=30s %=6s %=12s", "SAFI", "Number", "Bytes");
     vlib_cli_output (vm, "%U", format_fib_table_memory);
     vlib_cli_output (vm, "%U", format_mfib_table_memory);
     vlib_cli_output (vm, "  Nodes:");
diff --git a/src/vnet/fib/ip4_fib.c b/src/vnet/fib/ip4_fib.c
index 57fc23b..8944637 100644
--- a/src/vnet/fib/ip4_fib.c
+++ b/src/vnet/fib/ip4_fib.c
@@ -566,12 +566,12 @@
 format_ip4_fib_table_memory (u8 * s, va_list * args)
 {
 #if USE_DLMALLOC == 0
-    s = format(s, "%=30s %=6d %=8ld\n",
+    s = format(s, "%=30s %=6d %=12ld\n",
                "IPv4 unicast",
                pool_elts(ip4_main.fibs),
                mheap_bytes(ip4_main.mtrie_mheap));
 #else
-    s = format(s, "%=30s %=6d %=8ld\n",
+    s = format(s, "%=30s %=6d %=12ld\n",
                "IPv4 unicast",
                pool_elts(ip4_main.fibs),
                mspace_footprint(ip4_main.mtrie_mheap));
diff --git a/src/vnet/fib/ip6_fib.c b/src/vnet/fib/ip6_fib.c
index 60d1365..ba90c5f 100644
--- a/src/vnet/fib/ip6_fib.c
+++ b/src/vnet/fib/ip6_fib.c
@@ -573,16 +573,10 @@
 {
     uword bytes_inuse;
 
-    bytes_inuse = 
-        alloc_arena_next 
-        (&(ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash))
-        - alloc_arena (&(ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash));
+    bytes_inuse = (alloc_arena_next(&(ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash)) +
+                   alloc_arena_next(&(ip6_main.ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash)));
 
-    bytes_inuse += 
-        alloc_arena_next(&(ip6_main.ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash))
-        - alloc_arena(&(ip6_main.ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash));
-
-    s = format(s, "%=30s %=6d %=8ld\n",
+    s = format(s, "%=30s %=6d %=12ld\n",
                "IPv6 unicast",
                pool_elts(ip6_main.fibs),
                bytes_inuse);
@@ -623,6 +617,7 @@
     u32 mask_len  = 128;
     int table_id = -1, fib_index = ~0;
     int detail = 0;
+    int hash = 0;
 
     verbose = 1;
     matching = 0;
@@ -638,6 +633,11 @@
                  unformat (input, "det"))
 	    detail = 1;
 
+	else if (unformat (input, "hash") ||
+                 unformat (input, "mem") ||
+                 unformat (input, "memory"))
+	    hash = 1;
+
 	else if (unformat (input, "%U/%d",
 			   unformat_ip6_address, &matching_address, &mask_len))
 	    matching = 1;
@@ -653,6 +653,19 @@
 	    break;
     }
 
+    if (hash)
+    {
+        vlib_cli_output (vm, "IPv6 Non-Forwarding Hash Table:\n%U\n",
+                         BV (format_bihash),
+                         &im6->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
+                         detail);
+        vlib_cli_output (vm, "IPv6 Forwarding Hash Table:\n%U\n",
+                         BV (format_bihash),
+                         &im6->ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash,
+                         detail);
+        return (NULL);
+    }
+
     pool_foreach (fib_table, im6->fibs,
     ({
         fib_source_t source;
diff --git a/src/vnet/fib/mpls_fib.c b/src/vnet/fib/mpls_fib.c
index 6670c99..6440689 100644
--- a/src/vnet/fib/mpls_fib.c
+++ b/src/vnet/fib/mpls_fib.c
@@ -366,7 +366,7 @@
 
     n_tables = pool_elts(mpls_main.fibs);
     mem = n_tables * sizeof(mpls_fib_t);
-    s = format(s, "%=30s %=6ld %=8ld\n", "MPLS", n_tables, mem);
+    s = format(s, "%=30s %=6ld %=12ld\n", "MPLS", n_tables, mem);
 
     return (s);
 }