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