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