1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Vladimir Medvedkin <medvedkinv@gmail.com>
3 * Copyright(c) 2019 Intel Corporation
14 * FIB (Forwarding information base) implementation
15 * for IPv4 Longest Prefix Match
20 #include <rte_compat.h>
29 /** Maximum depth value possible for IPv4 FIB. */
30 #define RTE_FIB_MAXDEPTH 32
32 /** Type of FIB struct */
34 RTE_FIB_DUMMY, /**< RIB tree based FIB */
35 RTE_FIB_DIR24_8 /**< DIR24_8 based FIB */
38 /** Modify FIB function */
39 typedef int (*rte_fib_modify_fn_t)(struct rte_fib *fib, uint32_t ip,
40 uint8_t depth, uint64_t next_hop, int op);
41 /** FIB bulk lookup function */
42 typedef void (*rte_fib_lookup_fn_t)(void *fib, const uint32_t *ips,
43 uint64_t *next_hops, const unsigned int n);
50 /** Size of nexthop (1 << nh_sz) bits for DIR24_8 based FIB */
51 enum rte_fib_dir24_8_nh_sz {
58 /** Type of lookup function implementation */
59 enum rte_fib_lookup_type {
60 RTE_FIB_LOOKUP_DEFAULT,
61 /**< Selects the best implementation based on the max simd bitwidth */
62 RTE_FIB_LOOKUP_DIR24_8_SCALAR_MACRO,
63 /**< Macro based lookup function */
64 RTE_FIB_LOOKUP_DIR24_8_SCALAR_INLINE,
66 * Lookup implementation using inlined functions
67 * for different next hop sizes
69 RTE_FIB_LOOKUP_DIR24_8_SCALAR_UNI,
71 * Unified lookup function for all next hop sizes
73 RTE_FIB_LOOKUP_DIR24_8_VECTOR_AVX512
74 /**< Vector implementation using AVX512 */
77 /** FIB configuration structure */
79 enum rte_fib_type type; /**< Type of FIB struct */
80 /** Default value returned on lookup if there is no route */
83 /** Size of the node extension in the internal RIB struct */
84 unsigned int rib_ext_sz;
87 enum rte_fib_dir24_8_nh_sz nh_sz;
99 * NUMA socket ID for FIB table memory allocation
101 * Structure containing the configuration
103 * Handle to the FIB object on success
104 * NULL otherwise with rte_errno set to an appropriate values.
107 rte_fib_create(const char *name, int socket_id, struct rte_fib_conf *conf);
110 * Find an existing FIB object and return a pointer to it.
113 * Name of the fib object as passed to rte_fib_create()
115 * Pointer to fib object or NULL if object not found with rte_errno
116 * set appropriately. Possible rte_errno values include:
117 * - ENOENT - required entry not available to return.
120 rte_fib_find_existing(const char *name);
123 * Free an FIB object.
131 rte_fib_free(struct rte_fib *fib);
134 * Add a route to the FIB.
139 * IPv4 prefix address to be added to the FIB
143 * Next hop to be added to the FIB
145 * 0 on success, negative value otherwise
148 rte_fib_add(struct rte_fib *fib, uint32_t ip, uint8_t depth, uint64_t next_hop);
151 * Delete a rule from the FIB.
156 * IPv4 prefix address to be deleted from the FIB
160 * 0 on success, negative value otherwise
163 rte_fib_delete(struct rte_fib *fib, uint32_t ip, uint8_t depth);
166 * Lookup multiple IP addresses in the FIB.
171 * Array of IPs to be looked up in the FIB
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.
178 * Number of elements in ips (and next_hops) array to lookup.
180 * -EINVAL for incorrect arguments, otherwise 0
183 rte_fib_lookup_bulk(struct rte_fib *fib, uint32_t *ips,
184 uint64_t *next_hops, int n);
186 * Get pointer to the dataplane specific struct
191 * Pointer on the dataplane struct on success
195 rte_fib_get_dp(struct rte_fib *fib);
198 * Get pointer to the RIB
203 * Pointer on the RIB on success
207 rte_fib_get_rib(struct rte_fib *fib);
210 * Set lookup function based on type
215 * type of lookup function
222 rte_fib_select_lookup(struct rte_fib *fib, enum rte_fib_lookup_type type);
228 #endif /* _RTE_FIB_H_ */