lib: remind experimental status in headers
[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  *
12  * RTE FIB 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 IPv4 Longest Prefix Match
20  */
21
22 #include <rte_compat.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 struct rte_fib;
29 struct rte_rib;
30
31 /** Maximum depth value possible for IPv4 FIB. */
32 #define RTE_FIB_MAXDEPTH        32
33
34 /** Type of FIB struct */
35 enum rte_fib_type {
36         RTE_FIB_DUMMY,          /**< RIB tree based FIB */
37         RTE_FIB_DIR24_8,        /**< DIR24_8 based FIB */
38         RTE_FIB_TYPE_MAX
39 };
40
41 /** Modify FIB function */
42 typedef int (*rte_fib_modify_fn_t)(struct rte_fib *fib, uint32_t ip,
43         uint8_t depth, uint64_t next_hop, int op);
44 /** FIB bulk lookup function */
45 typedef void (*rte_fib_lookup_fn_t)(void *fib, const uint32_t *ips,
46         uint64_t *next_hops, const unsigned int n);
47
48 enum rte_fib_op {
49         RTE_FIB_ADD,
50         RTE_FIB_DEL,
51 };
52
53 /** Size of nexthop (1 << nh_sz) bits for DIR24_8 based FIB */
54 enum rte_fib_dir24_8_nh_sz {
55         RTE_FIB_DIR24_8_1B,
56         RTE_FIB_DIR24_8_2B,
57         RTE_FIB_DIR24_8_4B,
58         RTE_FIB_DIR24_8_8B
59 };
60
61 /** FIB configuration structure */
62 struct rte_fib_conf {
63         enum rte_fib_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_dir24_8_nh_sz nh_sz;
70                         uint32_t        num_tbl8;
71                 } dir24_8;
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 the FIB object on success
86  *  NULL otherwise with rte_errno set to an appropriate values.
87  */
88 __rte_experimental
89 struct rte_fib *
90 rte_fib_create(const char *name, int socket_id, struct rte_fib_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_fib_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_fib *
104 rte_fib_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_fib_free(struct rte_fib *fib);
117
118 /**
119  * Add a route to the FIB.
120  *
121  * @param fib
122  *   FIB object handle
123  * @param ip
124  *   IPv4 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_fib_add(struct rte_fib *fib, uint32_t ip, uint8_t depth, uint64_t next_hop);
135
136 /**
137  * Delete a rule from the FIB.
138  *
139  * @param fib
140  *   FIB object handle
141  * @param ip
142  *   IPv4 prefix address to be deleted from the FIB
143  * @param depth
144  *   Prefix length
145  * @return
146  *   0 on success, negative value otherwise
147  */
148 __rte_experimental
149 int
150 rte_fib_delete(struct rte_fib *fib, uint32_t ip, uint8_t depth);
151
152 /**
153  * Lookup multiple IP addresses in the FIB.
154  *
155  * @param fib
156  *   FIB object handle
157  * @param ips
158  *   Array of IPs to be looked up in the FIB
159  * @param next_hops
160  *   Next hop of the most specific rule found for IP.
161  *   This is an array of eight byte values.
162  *   If the lookup for the given IP failed, then corresponding element would
163  *   contain default nexthop value configured for a FIB.
164  * @param n
165  *   Number of elements in ips (and next_hops) array to lookup.
166  *  @return
167  *   -EINVAL for incorrect arguments, otherwise 0
168  */
169 __rte_experimental
170 int
171 rte_fib_lookup_bulk(struct rte_fib *fib, uint32_t *ips,
172                 uint64_t *next_hops, int n);
173 /**
174  * Get pointer to the dataplane specific struct
175  *
176  * @param fib
177  *   FIB object handle
178  * @return
179  *   Pointer on the dataplane struct on success
180  *   NULL othervise
181  */
182 __rte_experimental
183 void *
184 rte_fib_get_dp(struct rte_fib *fib);
185
186 /**
187  * Get pointer to the RIB
188  *
189  * @param fib
190  *   FIB object handle
191  * @return
192  *   Pointer on the RIB on success
193  *   NULL othervise
194  */
195 __rte_experimental
196 struct rte_rib *
197 rte_fib_get_rib(struct rte_fib *fib);
198
199 #ifdef __cplusplus
200 }
201 #endif
202
203 #endif /* _RTE_FIB_H_ */