xref: /dpdk/lib/fib/rte_fib6.h (revision 6cb10a9bdb6d2d0253e4d022f230371d703d8ac2)
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_common.h>
21 #include <rte_ip6.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #define RTE_FIB6_IPV6_ADDR_SIZE (RTE_DEPRECATED(RTE_FIB6_IPV6_ADDR_SIZE) RTE_IPV6_ADDR_SIZE)
28 /** Maximum depth value possible for IPv6 FIB. */
29 #define RTE_FIB6_MAXDEPTH (RTE_DEPRECATED(RTE_FIB6_MAXDEPTH) RTE_IPV6_MAX_DEPTH)
30 
31 struct rte_fib6;
32 struct rte_rib6;
33 
34 /** Type of FIB struct */
35 enum rte_fib6_type {
36 	RTE_FIB6_DUMMY,		/**< RIB6 tree based FIB */
37 	RTE_FIB6_TRIE		/**< TRIE based fib  */
38 };
39 
40 /** Modify FIB function */
41 typedef int (*rte_fib6_modify_fn_t)(struct rte_fib6 *fib,
42 	const struct rte_ipv6_addr *ip, uint8_t depth,
43 	uint64_t next_hop, int op);
44 /** FIB bulk lookup function */
45 typedef void (*rte_fib6_lookup_fn_t)(void *fib,
46 	const struct rte_ipv6_addr *ips,
47 	uint64_t *next_hops, const unsigned int n);
48 
49 enum rte_fib6_op {
50 	RTE_FIB6_ADD,
51 	RTE_FIB6_DEL,
52 };
53 
54 /** Size of nexthop (1 << nh_sz) bits for TRIE based FIB */
55 enum rte_fib_trie_nh_sz {
56 	RTE_FIB6_TRIE_2B = 1,
57 	RTE_FIB6_TRIE_4B,
58 	RTE_FIB6_TRIE_8B
59 };
60 
61 /** Type of lookup function implementation */
62 enum rte_fib6_lookup_type {
63 	RTE_FIB6_LOOKUP_DEFAULT,
64 	/**< Selects the best implementation based on the max simd bitwidth */
65 	RTE_FIB6_LOOKUP_TRIE_SCALAR, /**< Scalar lookup function implementation*/
66 	RTE_FIB6_LOOKUP_TRIE_VECTOR_AVX512 /**< Vector implementation using AVX512 */
67 };
68 
69 /** FIB configuration structure */
70 struct rte_fib6_conf {
71 	enum rte_fib6_type type; /**< Type of FIB struct */
72 	/** Default value returned on lookup if there is no route */
73 	uint64_t default_nh;
74 	int	max_routes;
75 	/** Size of the node extension in the internal RIB struct */
76 	unsigned int rib_ext_sz;
77 	union {
78 		struct {
79 			enum rte_fib_trie_nh_sz nh_sz;
80 			uint32_t	num_tbl8;
81 		} trie;
82 	};
83 };
84 
85 /**
86  * Create FIB
87  *
88  * @param name
89  *  FIB name
90  * @param socket_id
91  *  NUMA socket ID for FIB table memory allocation
92  * @param conf
93  *  Structure containing the configuration
94  * @return
95  *  Handle to FIB object on success
96  *  NULL otherwise with rte_errno set to an appropriate values.
97  */
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 struct rte_fib6 *
112 rte_fib6_find_existing(const char *name);
113 
114 /**
115  * Free an FIB object.
116  *
117  * @param fib
118  *   FIB object handle created by rte_fib6_create().
119  *   If fib is NULL, no operation is performed.
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 struct rte_ipv6_addr *ip,
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 struct rte_ipv6_addr *ip, 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 	const struct rte_ipv6_addr *ips,
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_ */
224