IP6-MFIB: replace the radix tree with bihash (VPP-1526)
[vpp.git] / src / vnet / mfib / ip6_mfib.h
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * @brief The IPv4 Multicast-FIB
17  *
18  * FIXME
19  *
20  * This IPv4 FIB is used by the protocol independent FIB. So directly using
21  * this APIs in client code is not encouraged. However, this IPv4 FIB can be
22  * used if all the client wants is an IPv4 prefix data-base
23  */
24
25 #ifndef __IP6_MFIB_H__
26 #define __IP6_MFIB_H__
27
28 #include <vlib/vlib.h>
29 #include <vnet/ip/ip.h>
30
31 #include <vnet/mfib/mfib_table.h>
32
33 extern fib_node_index_t ip6_mfib_table_lookup(const ip6_mfib_t *fib,
34                                               const ip6_address_t *src,
35                                               const ip6_address_t *grp,
36                                               u32 len);
37 extern fib_node_index_t ip6_mfib_table_fwd_lookup(const ip6_mfib_t *fib,
38                                                   const ip6_address_t *src,
39                                                   const ip6_address_t *grp);
40 extern fib_node_index_t ip6_mfib_table_lookup_exact_match(const ip6_mfib_t *fib,
41                                                           const ip6_address_t *grp,
42                                                           const ip6_address_t *src,
43                                                           u32 len);
44
45 extern void ip6_mfib_table_entry_remove(ip6_mfib_t *fib,
46                                         const ip6_address_t *grp,
47                                         const ip6_address_t *src,
48                                         u32 len);
49
50 extern void ip6_mfib_table_entry_insert(ip6_mfib_t *fib,
51                                         const ip6_address_t *grp,
52                                         const ip6_address_t *src,
53                                         u32 len,
54                                         fib_node_index_t fib_entry_index);
55 extern void ip6_mfib_table_destroy(ip6_mfib_t *fib);
56
57 /**
58  * @brief
59  *  Add/remove the interface from the accepting list of the special MFIB entries
60  */
61 extern void ip6_mfib_interface_enable_disable(u32 sw_if_index,
62                                               int is_enable);
63
64 /**
65  * @brief Get the FIB at the given index
66  */
67 static inline ip6_mfib_t *
68 ip6_mfib_get (u32 index)
69 {
70     return (&(pool_elt_at_index(ip6_main.mfibs, index)->v6));
71 }
72
73 /**
74  * @brief Get or create an IPv4 fib.
75  *
76  * Get or create an IPv4 fib with the provided table ID.
77  *
78  * @param table_id
79  *      When set to \c ~0, an arbitrary and unused fib ID is picked
80  *      and can be retrieved with \c ret->table_id.
81  *      Otherwise, the fib ID to be used to retrieve or create the desired fib.
82  * @returns A pointer to the retrieved or created fib.
83  *
84  */
85 extern u32 ip6_mfib_table_find_or_create_and_lock(u32 table_id,
86                                                   mfib_source_t src);
87 extern u32 ip6_mfib_table_create_and_lock(mfib_source_t src);
88
89
90 static inline
91 u32 ip6_mfib_index_from_table_id (u32 table_id)
92 {
93   ip6_main_t * im = &ip6_main;
94   uword * p;
95
96   p = hash_get (im->mfib_index_by_table_id, table_id);
97   if (!p)
98     return ~0;
99
100   return p[0];
101 }
102
103 extern u32 ip6_mfib_table_get_index_for_sw_if_index(u32 sw_if_index);
104
105 /**
106  * @brief Data-plane lookup function
107  */
108 extern fib_node_index_t ip6_mfib_table_lookup2(const ip6_mfib_t *mfib,
109                                                const ip6_address_t *src,
110                                                const ip6_address_t *grp);
111
112 /**
113  * @brief Walk the IP6 mfib table.
114  *
115  * @param mfib the table to walk
116  * @param fn The function to invoke on each entry visited
117  * @param ctx A context passed in the visit function
118  */
119 extern void ip6_mfib_table_walk (ip6_mfib_t *mfib,
120                                  mfib_table_walk_fn_t fn,
121                                  void *ctx);
122
123 /**
124  * @brief format (display) ipv6 MFIB mempry usage
125  */
126 extern u8 *format_ip6_mfib_table_memory(u8 * s, va_list * args);
127
128 #endif
129