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