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