ip: Move the IP6 fib into ip6_[m]fib.c
[vpp.git] / src / vnet / fib / ip6_fib.h
index e460e2f..706bebb 100644 (file)
 #include <vnet/ip/format.h>
 #include <vnet/fib/fib_entry.h>
 #include <vnet/fib/fib_table.h>
-#include <vnet/fib/fib_urpf_list.h>
 #include <vnet/ip/lookup.h>
 #include <vnet/dpo/load_balance.h>
+#include <vppinfra/bihash_24_8.h>
+#include <vppinfra/bihash_template.h>
+
+/*
+ * Default size of the ip6 fib hash table
+ */
+#define IP6_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
+#define IP6_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20)
+
+/**
+ * Enumeration of the FIB table instance types
+ */
+typedef enum ip6_fib_table_instance_type_t_
+{
+    /**
+     * This table stores the routes that are used to forward traffic.
+     * The key is the prefix, the result the adjacency to forward on.
+     */
+  IP6_FIB_TABLE_FWDING,
+    /**
+     * The table that stores ALL routes learned by the DP.
+     * Some of these routes may not be ready to install in forwarding
+     * at a given time.
+     * The key in this table is the prefix, the result is the fib_entry_t
+     */
+  IP6_FIB_TABLE_NON_FWDING,
+} ip6_fib_table_instance_type_t;
+
+#define IP6_FIB_NUM_TABLES (IP6_FIB_TABLE_NON_FWDING+1)
+
+/**
+ * A representation of a single IP6 table
+ */
+typedef struct ip6_fib_table_instance_t_
+{
+  /* The hash table */
+  clib_bihash_24_8_t ip6_hash;
+
+  /* bitmap / refcounts / vector of mask widths to search */
+  uword *non_empty_dst_address_length_bitmap;
+  u8 *prefix_lengths_in_search_order;
+  i32 dst_address_length_refcounts[129];
+} ip6_fib_table_instance_t;
+
+/**
+ * The two FIB tables; fwding and non-fwding
+ */
+extern ip6_fib_table_instance_t ip6_fib_table[IP6_FIB_NUM_TABLES];
 
 extern fib_node_index_t ip6_fib_table_lookup(u32 fib_index,
                                             const ip6_address_t *addr,
@@ -54,9 +101,6 @@ extern void ip6_fib_table_fwding_dpo_remove(u32 fib_index,
 u32 ip6_fib_table_fwding_lookup_with_if_index(ip6_main_t * im,
                                              u32 sw_if_index,
                                              const ip6_address_t * dst);
-u32 ip6_fib_table_fwding_lookup(ip6_main_t * im,
-                               u32 fib_index,
-                               const ip6_address_t * dst);
 
 /**
  * @brief Walk all entries in a FIB table
@@ -67,27 +111,54 @@ extern void ip6_fib_table_walk(u32 fib_index,
                                fib_table_walk_fn_t fn,
                                void *ctx);
 
-/**
- * @brief returns number of links on which src is reachable.
- */
-always_inline int
-ip6_urpf_loose_check (ip6_main_t * im,
-                     vlib_buffer_t * b,
-                     ip6_header_t * i)
+always_inline u32
+ip6_fib_table_fwding_lookup (u32 fib_index,
+                             const ip6_address_t * dst)
 {
-    const load_balance_t *lb0;
-    index_t lbi;
+    ip6_fib_table_instance_t *table;
+    clib_bihash_kv_24_8_t kv, value;
+    int i, len;
+    int rv;
+    u64 fib;
 
-    lbi = ip6_fib_table_fwding_lookup_with_if_index(
-              im,
-              vnet_buffer (b)->sw_if_index[VLIB_RX],
-              &i->src_address);
+    table = &ip6_fib_table[IP6_FIB_TABLE_FWDING];
+    len = vec_len (table->prefix_lengths_in_search_order);
 
-    lb0 = load_balance_get(lbi);
+    kv.key[0] = dst->as_u64[0];
+    kv.key[1] = dst->as_u64[1];
+    fib = ((u64)((fib_index))<<32);
+
+    for (i = 0; i < len; i++)
+    {
+       int dst_address_length = table->prefix_lengths_in_search_order[i];
+       ip6_address_t * mask = &ip6_main.fib_masks[dst_address_length];
+
+       ASSERT(dst_address_length >= 0 && dst_address_length <= 128);
+       //As lengths are decreasing, masks are increasingly specific.
+       kv.key[0] &= mask->as_u64[0];
+       kv.key[1] &= mask->as_u64[1];
+       kv.key[2] = fib | dst_address_length;
+
+       rv = clib_bihash_search_inline_2_24_8(&table->ip6_hash, &kv, &value);
+       if (rv == 0)
+           return value.value;
+    }
 
-    return (fib_urpf_check_size (lb0->lb_urpf));
+    /* default route is always present */
+    ASSERT(0);
+    return 0;
 }
 
+/**
+ * @brief Walk all entries in a sub-tree of the FIB table
+ * N.B: This is NOT safe to deletes. If you need to delete walk the whole
+ * table and store elements in a vector, then delete the elements
+ */
+extern void ip6_fib_table_sub_tree_walk(u32 fib_index,
+                                        const fib_prefix_t *root,
+                                        fib_table_walk_fn_t fn,
+                                        void *ctx);
+
 /**
  * @brief return the DPO that the LB stacks on.
  */
@@ -130,14 +201,19 @@ ip6_src_lookup_for_packet (ip6_main_t * im,
  * \returns A pointer to the retrieved or created fib.
  *
  */
-extern u32 ip6_fib_table_find_or_create_and_lock(u32 table_id);
-extern u32 ip6_fib_table_create_and_lock(void);
+extern u32 ip6_fib_table_find_or_create_and_lock(u32 table_id,
+                                                 fib_source_t src);
+extern u32 ip6_fib_table_create_and_lock(fib_source_t src,
+                                         fib_table_flags_t flags,
+                                         u8* desc);
+
+extern u8 *format_ip6_fib_table_memory(u8 * s, va_list * args);
 
 static inline ip6_fib_t *
 ip6_fib_get (fib_node_index_t index)
 {
     ASSERT(!pool_is_free_index(ip6_main.fibs, index));
-    return (&pool_elt_at_index (ip6_main.fibs, index)->v6);
+    return (pool_elt_at_index (ip6_main.v6_fibs, index));
 }
 
 static inline 
@@ -155,7 +231,5 @@ u32 ip6_fib_index_from_table_id (u32 table_id)
 
 extern u32 ip6_fib_table_get_index_for_sw_if_index(u32 sw_if_index);
 
-extern flow_hash_config_t ip6_fib_table_get_flow_hash_config(u32 fib_index);
-
 #endif