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