ip: Protocol Independent IP Neighbors
[vpp.git] / src / vnet / fib / ip6_fib.c
index 60d1365..784f52c 100644 (file)
@@ -151,11 +151,15 @@ ip6_fib_table_destroy (u32 fib_index)
     fib_table_t *fib_table = fib_table_get(fib_index, FIB_PROTOCOL_IP6);
     fib_source_t source;
 
-     /*
+    /*
      * validate no more routes.
      */
-    ASSERT(0 == fib_table->ft_total_route_counts);
-    FOR_EACH_FIB_SOURCE(source)
+#ifdef CLIB_DEBUG
+    if (0 != fib_table->ft_total_route_counts)
+        fib_table_assert_empty(fib_table);
+#endif
+
+    vec_foreach_index(source, fib_table->ft_src_route_counts)
     {
        ASSERT(0 == fib_table->ft_src_route_counts[source]);
     }
@@ -164,6 +168,7 @@ ip6_fib_table_destroy (u32 fib_index)
     {
        hash_unset (ip6_main.fib_index_by_table_id, fib_table->ft_table_id);
     }
+    vec_free(fib_table->ft_src_route_counts);
     pool_put_index(ip6_main.v6_fibs, fib_table->ft_index);
     pool_put(ip6_main.fibs, fib_table);
 }
@@ -319,7 +324,7 @@ u32 ip6_fib_table_fwding_lookup_with_if_index (ip6_main_t * im,
                                               const ip6_address_t * dst)
 {
     u32 fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index);
-    return ip6_fib_table_fwding_lookup(im, fib_index, dst);
+    return ip6_fib_table_fwding_lookup(fib_index, dst);
 }
 
 u32
@@ -573,16 +578,10 @@ format_ip6_fib_table_memory (u8 * s, va_list * args)
 {
     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_FWDING].ip6_hash))
-        - alloc_arena(&(ip6_main.ip6_table[IP6_FIB_TABLE_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)));
 
-    s = format(s, "%=30s %=6d %=8ld\n",
+    s = format(s, "%=30s %=6d %=12ld\n",
                "IPv6 unicast",
                pool_elts(ip6_main.fibs),
                bytes_inuse);
@@ -594,7 +593,7 @@ typedef struct {
   u64 count_by_prefix_length[129];
 } count_routes_in_fib_at_prefix_length_arg_t;
 
-static void
+static int
 count_routes_in_fib_at_prefix_length (clib_bihash_kv_24_8_t * kvp,
                                       void *arg)
 {
@@ -602,11 +601,13 @@ count_routes_in_fib_at_prefix_length (clib_bihash_kv_24_8_t * kvp,
   int mask_width;
 
   if ((kvp->key[2]>>32) != ap->fib_index)
-    return;
+      return (BIHASH_WALK_CONTINUE);
 
   mask_width = kvp->key[2] & 0xFF;
 
   ap->count_by_prefix_length[mask_width]++;
+
+  return (BIHASH_WALK_CONTINUE);
 }
 
 static clib_error_t *
@@ -623,6 +624,7 @@ ip6_show_fib (vlib_main_t * vm,
     u32 mask_len  = 128;
     int table_id = -1, fib_index = ~0;
     int detail = 0;
+    int hash = 0;
 
     verbose = 1;
     matching = 0;
@@ -638,6 +640,11 @@ ip6_show_fib (vlib_main_t * vm,
                  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 +660,19 @@ ip6_show_fib (vlib_main_t * vm,
            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;
@@ -666,13 +686,16 @@ ip6_show_fib (vlib_main_t * vm,
         if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL)
             continue;
 
-       s = format(s, "%U, fib_index:%d, flow hash:[%U] locks:[",
+       s = format(s, "%U, fib_index:%d, flow hash:[%U] epoch:%d flags:%U locks:[",
                    format_fib_table_name, fib->index,
                    FIB_PROTOCOL_IP6,
                    fib->index,
                    format_ip_flow_hash_config,
-                   fib_table->ft_flow_hash_config);
-       FOR_EACH_FIB_SOURCE(source)
+                   fib_table->ft_flow_hash_config,
+                   fib_table->ft_epoch,
+                   format_fib_table_flags, fib_table->ft_flags);
+
+        vec_foreach_index(source, fib_table->ft_locks)
         {
             if (0 != fib_table->ft_locks[source])
             {