Fixes for 'make UNATTENDED=yes CC=clang CXX=clang verify'
[vpp.git] / src / vnet / ip / ip4_mtrie.c
index adc9512..5aa9b92 100644 (file)
@@ -176,9 +176,12 @@ ply_create (ip4_fib_mtrie_t * m,
            u32 leaf_prefix_len, u32 ply_base_len)
 {
   ip4_fib_mtrie_8_ply_t *p;
-
+  void *old_heap;
   /* Get cache aligned ply. */
+
+  old_heap = clib_mem_set_heap (ip4_main.mtrie_mheap);
   pool_get_aligned (ip4_ply_pool, p, CLIB_CACHE_LINE_BYTES);
+  clib_mem_set_heap (old_heap);
 
   ply_8_init (p, init_leaf, leaf_prefix_len, ply_base_len);
   return ip4_fib_mtrie_leaf_set_next_ply_index (p - ip4_ply_pool);
@@ -271,7 +274,7 @@ set_leaf (ip4_fib_mtrie_t * m,
 
   old_ply = pool_elt_at_index (ip4_ply_pool, old_ply_index);
 
-  ASSERT (a->dst_address_length >= 0 && a->dst_address_length <= 32);
+  ASSERT (a->dst_address_length <= 32);
   ASSERT (dst_address_byte_index < ARRAY_LEN (a->dst_address.as_u8));
 
   /* how many bits of the destination address are in the next PLY */
@@ -284,7 +287,8 @@ set_leaf (ip4_fib_mtrie_t * m,
   if (n_dst_bits_next_plies <= 0)
     {
       /* The mask length of the address to insert maps to this ply */
-      uword i, n_dst_bits_this_ply, old_leaf_is_terminal;
+      uword old_leaf_is_terminal;
+      u32 i, n_dst_bits_this_ply;
 
       /* The number of bits, and hence slots/buckets, we will fill */
       n_dst_bits_this_ply = clib_min (8, -n_dst_bits_next_plies);
@@ -401,7 +405,7 @@ set_root_leaf (ip4_fib_mtrie_t * m,
 
   old_ply = &m->root_ply;
 
-  ASSERT (a->dst_address_length >= 0 && a->dst_address_length <= 32);
+  ASSERT (a->dst_address_length <= 32);
 
   /* how many bits of the destination address are in the next PLY */
   n_dst_bits_next_plies = a->dst_address_length - BITS (u16);
@@ -412,7 +416,8 @@ set_root_leaf (ip4_fib_mtrie_t * m,
   if (n_dst_bits_next_plies <= 0)
     {
       /* The mask length of the address to insert maps to this ply */
-      uword i, n_dst_bits_this_ply, old_leaf_is_terminal;
+      uword old_leaf_is_terminal;
+      u32 i, n_dst_bits_this_ply;
 
       /* The number of bits, and hence slots/buckets, we will fill */
       n_dst_bits_this_ply = 16 - a->dst_address_length;
@@ -515,7 +520,7 @@ unset_leaf (ip4_fib_mtrie_t * m,
   i32 i, n_dst_bits_this_ply, old_leaf_is_terminal;
   u8 dst_byte;
 
-  ASSERT (a->dst_address_length >= 0 && a->dst_address_length <= 32);
+  ASSERT (a->dst_address_length <= 32);
   ASSERT (dst_address_byte_index < ARRAY_LEN (a->dst_address.as_u8));
 
   n_dst_bits_next_plies =
@@ -588,7 +593,7 @@ unset_root_leaf (ip4_fib_mtrie_t * m,
   u16 dst_byte;
   ip4_fib_mtrie_16_ply_t *old_ply;
 
-  ASSERT (a->dst_address_length >= 0 && a->dst_address_length <= 32);
+  ASSERT (a->dst_address_length <= 32);
 
   old_ply = &m->root_ply;
   n_dst_bits_next_plies = a->dst_address_length - BITS (u16);
@@ -681,8 +686,8 @@ mtrie_ply_memory_usage (ip4_fib_mtrie_t * m, ip4_fib_mtrie_8_ply_t * p)
 }
 
 /* Returns number of bytes of memory used by mtrie. */
-static uword
-mtrie_memory_usage (ip4_fib_mtrie_t * m)
+uword
+ip4_fib_mtrie_memory_usage (ip4_fib_mtrie_t * m)
 {
   uword bytes, i;
 
@@ -738,7 +743,7 @@ format_ip4_fib_mtrie_ply (u8 * s, va_list * va)
   u32 base_address = va_arg (*va, u32);
   u32 ply_index = va_arg (*va, u32);
   ip4_fib_mtrie_8_ply_t *p;
-  uword indent;
+  u32 indent;
   int i;
 
   p = pool_elt_at_index (ip4_ply_pool, ply_index);
@@ -750,8 +755,8 @@ format_ip4_fib_mtrie_ply (u8 * s, va_list * va)
     {
       if (ip4_fib_mtrie_leaf_is_non_empty (p, i))
        {
-         FORMAT_PLY (s, p, i, base_address,
-                     p->dst_address_bits_base + 8, indent);
+         s = FORMAT_PLY (s, p, i, base_address,
+                         p->dst_address_bits_base + 8, indent);
        }
     }
 
@@ -762,40 +767,59 @@ u8 *
 format_ip4_fib_mtrie (u8 * s, va_list * va)
 {
   ip4_fib_mtrie_t *m = va_arg (*va, ip4_fib_mtrie_t *);
+  int verbose = va_arg (*va, int);
   ip4_fib_mtrie_16_ply_t *p;
   u32 base_address = 0;
   int i;
 
   s = format (s, "%d plies, memory usage %U\n",
              pool_elts (ip4_ply_pool),
-             format_memory_size, mtrie_memory_usage (m));
+             format_memory_size, ip4_fib_mtrie_memory_usage (m));
   s = format (s, "root-ply");
   p = &m->root_ply;
 
-  for (i = 0; i < ARRAY_LEN (p->leaves); i++)
+  if (verbose)
     {
-      u16 slot;
-
-      slot = clib_host_to_net_u16 (i);
+      s = format (s, "root-ply");
+      p = &m->root_ply;
 
-      if (p->dst_address_bits_of_leaves[slot] > 0)
+      for (i = 0; i < ARRAY_LEN (p->leaves); i++)
        {
-         FORMAT_PLY (s, p, slot, base_address, 16, 2);
+         u16 slot;
+
+         slot = clib_host_to_net_u16 (i);
+
+         if (p->dst_address_bits_of_leaves[slot] > 0)
+           {
+             s = FORMAT_PLY (s, p, slot, base_address, 16, 2);
+           }
        }
     }
 
   return s;
 }
 
+/** Default heap size for the IPv4 mtries */
+#define IP4_FIB_DEFAULT_MTRIE_HEAP_SIZE (32<<20)
+
 static clib_error_t *
 ip4_mtrie_module_init (vlib_main_t * vm)
 {
-  /* Burn one ply so index 0 is taken */
   CLIB_UNUSED (ip4_fib_mtrie_8_ply_t * p);
+  ip4_main_t *im = &ip4_main;
+  clib_error_t *error = NULL;
+  uword *old_heap;
 
+  if (0 == im->mtrie_heap_size)
+    im->mtrie_heap_size = IP4_FIB_DEFAULT_MTRIE_HEAP_SIZE;
+  im->mtrie_mheap = mheap_alloc (0, im->mtrie_heap_size);
+
+  /* Burn one ply so index 0 is taken */
+  old_heap = clib_mem_set_heap (ip4_main.mtrie_mheap);
   pool_get (ip4_ply_pool, p);
+  clib_mem_set_heap (old_heap);
 
-  return (NULL);
+  return (error);
 }
 
 VLIB_INIT_FUNCTION (ip4_mtrie_module_init);