mempool: fix slow allocation of large mempools
[dpdk.git] / lib / librte_fib / rte_fib.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_FIB_H_
7 #define _RTE_FIB_H_
8
9 /**
10  * @file
11  * FIB (Forwarding information base) implementation
12  * for IPv4 Longest Prefix Match
13  */
14
15 #include <rte_compat.h>
16
17 struct rte_fib;
18 struct rte_rib;
19
20 /** Maximum depth value possible for IPv4 FIB. */
21 #define RTE_FIB_MAXDEPTH        32
22
23 /** Type of FIB struct */
24 enum rte_fib_type {
25         RTE_FIB_DUMMY,          /**< RIB tree based FIB */
26         RTE_FIB_DIR24_8,        /**< DIR24_8 based FIB */
27         RTE_FIB_TYPE_MAX
28 };
29
30 /** Modify FIB function */
31 typedef int (*rte_fib_modify_fn_t)(struct rte_fib *fib, uint32_t ip,
32         uint8_t depth, uint64_t next_hop, int op);
33 /** FIB bulk lookup function */
34 typedef void (*rte_fib_lookup_fn_t)(void *fib, const uint32_t *ips,
35         uint64_t *next_hops, const unsigned int n);
36
37 enum rte_fib_op {
38         RTE_FIB_ADD,
39         RTE_FIB_DEL,
40 };
41
42 /** Size of nexthop (1 << nh_sz) bits for DIR24_8 based FIB */
43 enum rte_fib_dir24_8_nh_sz {
44         RTE_FIB_DIR24_8_1B,
45         RTE_FIB_DIR24_8_2B,
46         RTE_FIB_DIR24_8_4B,
47         RTE_FIB_DIR24_8_8B
48 };
49
50 /** FIB configuration structure */
51 struct rte_fib_conf {
52         enum rte_fib_type type; /**< Type of FIB struct */
53         /** Default value returned on lookup if there is no route */
54         uint64_t default_nh;
55         int     max_routes;
56         union {
57                 struct {
58                         enum rte_fib_dir24_8_nh_sz nh_sz;
59                         uint32_t        num_tbl8;
60                 } dir24_8;
61         };
62 };
63
64 /**
65  * Create FIB
66  *
67  * @param name
68  *  FIB name
69  * @param socket_id
70  *  NUMA socket ID for FIB table memory allocation
71  * @param conf
72  *  Structure containing the configuration
73  * @return
74  *  Handle to the FIB object on success
75  *  NULL otherwise with rte_errno set to an appropriate values.
76  */
77 __rte_experimental
78 struct rte_fib *
79 rte_fib_create(const char *name, int socket_id, struct rte_fib_conf *conf);
80
81 /**
82  * Find an existing FIB object and return a pointer to it.
83  *
84  * @param name
85  *  Name of the fib object as passed to rte_fib_create()
86  * @return
87  *  Pointer to fib object or NULL if object not found with rte_errno
88  *  set appropriately. Possible rte_errno values include:
89  *   - ENOENT - required entry not available to return.
90  */
91 __rte_experimental
92 struct rte_fib *
93 rte_fib_find_existing(const char *name);
94
95 /**
96  * Free an FIB object.
97  *
98  * @param fib
99  *   FIB object handle
100  * @return
101  *   None
102  */
103 __rte_experimental
104 void
105 rte_fib_free(struct rte_fib *fib);
106
107 /**
108  * Add a route to the FIB.
109  *
110  * @param fib
111  *   FIB object handle
112  * @param ip
113  *   IPv4 prefix address to be added to the FIB
114  * @param depth
115  *   Prefix length
116  * @param next_hop
117  *   Next hop to be added to the FIB
118  * @return
119  *   0 on success, negative value otherwise
120  */
121 __rte_experimental
122 int
123 rte_fib_add(struct rte_fib *fib, uint32_t ip, uint8_t depth, uint64_t next_hop);
124
125 /**
126  * Delete a rule from the FIB.
127  *
128  * @param fib
129  *   FIB object handle
130  * @param ip
131  *   IPv4 prefix address to be deleted from the FIB
132  * @param depth
133  *   Prefix length
134  * @return
135  *   0 on success, negative value otherwise
136  */
137 __rte_experimental
138 int
139 rte_fib_delete(struct rte_fib *fib, uint32_t ip, uint8_t depth);
140
141 /**
142  * Lookup multiple IP addresses in the FIB.
143  *
144  * @param fib
145  *   FIB object handle
146  * @param ips
147  *   Array of IPs to be looked up in the FIB
148  * @param next_hops
149  *   Next hop of the most specific rule found for IP.
150  *   This is an array of eight byte values.
151  *   If the lookup for the given IP failed, then corresponding element would
152  *   contain default nexthop value configured for a FIB.
153  * @param n
154  *   Number of elements in ips (and next_hops) array to lookup.
155  *  @return
156  *   -EINVAL for incorrect arguments, otherwise 0
157  */
158 __rte_experimental
159 int
160 rte_fib_lookup_bulk(struct rte_fib *fib, uint32_t *ips,
161                 uint64_t *next_hops, int n);
162 /**
163  * Get pointer to the dataplane specific struct
164  *
165  * @param fib
166  *   FIB object handle
167  * @return
168  *   Pointer on the dataplane struct on success
169  *   NULL othervise
170  */
171 __rte_experimental
172 void *
173 rte_fib_get_dp(struct rte_fib *fib);
174
175 /**
176  * Get pointer to the RIB
177  *
178  * @param fib
179  *   FIB object handle
180  * @return
181  *   Pointer on the RIB on success
182  *   NULL othervise
183  */
184 __rte_experimental
185 struct rte_rib *
186 rte_fib_get_rib(struct rte_fib *fib);
187
188 #endif /* _RTE_FIB_H_ */