doc: add Meson coding style to contributors guide
[dpdk.git] / lib / librte_fib / rte_fib6.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Vladimir Medvedkin <medvedkinv@gmail.com>
3  * Copyright(c) 2019 Intel Corporation
4  */
5
6 #ifndef _RTE_FIB6_H_
7 #define _RTE_FIB6_H_
8
9 /**
10  * @file
11  *
12  * RTE FIB6 library.
13  *
14  * @warning
15  * @b EXPERIMENTAL:
16  * All functions in this file may be changed or removed without prior notice.
17  *
18  * FIB (Forwarding information base) implementation
19  * for IPv6 Longest Prefix Match
20  */
21
22 #include <stdint.h>
23
24 #include <rte_compat.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #define RTE_FIB6_IPV6_ADDR_SIZE         16
31 /** Maximum depth value possible for IPv6 FIB. */
32 #define RTE_FIB6_MAXDEPTH       128
33
34 struct rte_fib6;
35 struct rte_rib6;
36
37 /** Type of FIB struct */
38 enum rte_fib6_type {
39         RTE_FIB6_DUMMY,         /**< RIB6 tree based FIB */
40         RTE_FIB6_TRIE           /**< TRIE based fib  */
41 };
42
43 /** Modify FIB function */
44 typedef int (*rte_fib6_modify_fn_t)(struct rte_fib6 *fib,
45         const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE], uint8_t depth,
46         uint64_t next_hop, int op);
47 /** FIB bulk lookup function */
48 typedef void (*rte_fib6_lookup_fn_t)(void *fib,
49         uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE],
50         uint64_t *next_hops, const unsigned int n);
51
52 enum rte_fib6_op {
53         RTE_FIB6_ADD,
54         RTE_FIB6_DEL,
55 };
56
57 /** Size of nexthop (1 << nh_sz) bits for TRIE based FIB */
58 enum rte_fib_trie_nh_sz {
59         RTE_FIB6_TRIE_2B = 1,
60         RTE_FIB6_TRIE_4B,
61         RTE_FIB6_TRIE_8B
62 };
63
64 /** Type of lookup function implementation */
65 enum rte_fib6_lookup_type {
66         RTE_FIB6_LOOKUP_DEFAULT,
67         /**< Selects the best implementation based on the max simd bitwidth */
68         RTE_FIB6_LOOKUP_TRIE_SCALAR, /**< Scalar lookup function implementation*/
69         RTE_FIB6_LOOKUP_TRIE_VECTOR_AVX512 /**< Vector implementation using AVX512 */
70 };
71
72 /** FIB configuration structure */
73 struct rte_fib6_conf {
74         enum rte_fib6_type type; /**< Type of FIB struct */
75         /** Default value returned on lookup if there is no route */
76         uint64_t default_nh;
77         int     max_routes;
78         union {
79                 struct {
80                         enum rte_fib_trie_nh_sz nh_sz;
81                         uint32_t        num_tbl8;
82                 } trie;
83         };
84 };
85
86 /**
87  * Create FIB
88  *
89  * @param name
90  *  FIB name
91  * @param socket_id
92  *  NUMA socket ID for FIB table memory allocation
93  * @param conf
94  *  Structure containing the configuration
95  * @return
96  *  Handle to FIB object on success
97  *  NULL otherwise with rte_errno set to an appropriate values.
98  */
99 __rte_experimental
100 struct rte_fib6 *
101 rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf);
102
103 /**
104  * Find an existing FIB object and return a pointer to it.
105  *
106  * @param name
107  *  Name of the fib object as passed to rte_fib6_create()
108  * @return
109  *  Pointer to fib object or NULL if object not found with rte_errno
110  *  set appropriately. Possible rte_errno values include:
111  *   - ENOENT - required entry not available to return.
112  */
113 __rte_experimental
114 struct rte_fib6 *
115 rte_fib6_find_existing(const char *name);
116
117 /**
118  * Free an FIB object.
119  *
120  * @param fib
121  *   FIB object handle
122  * @return
123  *   None
124  */
125 __rte_experimental
126 void
127 rte_fib6_free(struct rte_fib6 *fib);
128
129 /**
130  * Add a route to the FIB.
131  *
132  * @param fib
133  *   FIB object handle
134  * @param ip
135  *   IPv6 prefix address to be added to the FIB
136  * @param depth
137  *   Prefix length
138  * @param next_hop
139  *   Next hop to be added to the FIB
140  * @return
141  *   0 on success, negative value otherwise
142  */
143 __rte_experimental
144 int
145 rte_fib6_add(struct rte_fib6 *fib, const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE],
146         uint8_t depth, uint64_t next_hop);
147
148 /**
149  * Delete a rule from the FIB.
150  *
151  * @param fib
152  *   FIB object handle
153  * @param ip
154  *   IPv6 prefix address to be deleted from the FIB
155  * @param depth
156  *   Prefix length
157  * @return
158  *   0 on success, negative value otherwise
159  */
160 __rte_experimental
161 int
162 rte_fib6_delete(struct rte_fib6 *fib,
163         const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE], uint8_t depth);
164
165 /**
166  * Lookup multiple IP addresses in the FIB.
167  *
168  * @param fib
169  *   FIB object handle
170  * @param ips
171  *   Array of IPv6s to be looked up in the FIB
172  * @param next_hops
173  *   Next hop of the most specific rule found for IP.
174  *   This is an array of eight byte values.
175  *   If the lookup for the given IP failed, then corresponding element would
176  *   contain default nexthop value configured for a FIB.
177  * @param n
178  *   Number of elements in ips (and next_hops) array to lookup.
179  *  @return
180  *   -EINVAL for incorrect arguments, otherwise 0
181  */
182 __rte_experimental
183 int
184 rte_fib6_lookup_bulk(struct rte_fib6 *fib,
185         uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE],
186         uint64_t *next_hops, int n);
187
188 /**
189  * Get pointer to the dataplane specific struct
190  *
191  * @param fib
192  *   FIB6 object handle
193  * @return
194  *   Pointer on the dataplane struct on success
195  *   NULL othervise
196  */
197 __rte_experimental
198 void *
199 rte_fib6_get_dp(struct rte_fib6 *fib);
200
201 /**
202  * Get pointer to the RIB6
203  *
204  * @param fib
205  *   FIB object handle
206  * @return
207  *   Pointer on the RIB6 on success
208  *   NULL othervise
209  */
210 __rte_experimental
211 struct rte_rib6 *
212 rte_fib6_get_rib(struct rte_fib6 *fib);
213
214 /**
215  * Set lookup function based on type
216  *
217  * @param fib
218  *   FIB object handle
219  * @param type
220  *   type of lookup function
221  *
222  * @return
223  *   0 on success
224  *   -EINVAL on failure
225  */
226 __rte_experimental
227 int
228 rte_fib6_select_lookup(struct rte_fib6 *fib, enum rte_fib6_lookup_type type);
229
230 #ifdef __cplusplus
231 }
232 #endif
233
234 #endif /* _RTE_FIB6_H_ */