6fc74a368bd7f1c471d0b741b9224cdb156facce
[vpp.git] / src / vnet / mfib / ip4_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 __IP4_MFIB_H__
26 #define __IP4_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 ip4_mfib_table_lookup(const ip4_mfib_t *fib,
34                                               const ip4_address_t *src,
35                                               const ip4_address_t *grp,
36                                               u32 len);
37 extern fib_node_index_t ip4_mfib_table_lookup_exact_match(const ip4_mfib_t *fib,
38                                                           const ip4_address_t *grp,
39                                                           const ip4_address_t *src,
40                                                           u32 len);
41
42 extern void ip4_mfib_table_entry_remove(ip4_mfib_t *fib,
43                                         const ip4_address_t *grp,
44                                         const ip4_address_t *src,
45                                         u32 len);
46
47 extern void ip4_mfib_table_entry_insert(ip4_mfib_t *fib,
48                                         const ip4_address_t *grp,
49                                         const ip4_address_t *src,
50                                         u32 len,
51                                         fib_node_index_t fib_entry_index);
52 extern void ip4_mfib_table_destroy(ip4_mfib_t *fib);
53
54 /**
55  * @brief Get the FIB at the given index
56  */
57 static inline ip4_mfib_t *
58 ip4_mfib_get (u32 index)
59 {
60     return (&(pool_elt_at_index(ip4_main.mfibs, index)->v4));
61 }
62
63 /**
64  * @brief Get or create an IPv4 fib.
65  *
66  * Get or create an IPv4 fib with the provided table ID.
67  *
68  * @param table_id
69  *      When set to \c ~0, an arbitrary and unused fib ID is picked
70  *      and can be retrieved with \c ret->table_id.
71  *      Otherwise, the fib ID to be used to retrieve or create the desired fib.
72  * @returns A pointer to the retrieved or created fib.
73  *
74  */
75 extern u32 ip4_mfib_table_find_or_create_and_lock(u32 table_id);
76 extern u32 ip4_mfib_table_create_and_lock(void);
77
78 static inline
79 u32 ip4_mfib_index_from_table_id (u32 table_id)
80 {
81   ip4_main_t * im = &ip4_main;
82   uword * p;
83
84   p = hash_get (im->mfib_index_by_table_id, table_id);
85   if (!p)
86     return ~0;
87
88   return p[0];
89 }
90
91 extern u32 ip4_mfib_table_get_index_for_sw_if_index(u32 sw_if_index);
92
93
94 #endif
95