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