xref: /dpdk/lib/table/rte_table_lpm.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 
5 #ifndef __INCLUDE_RTE_TABLE_LPM_H__
6 #define __INCLUDE_RTE_TABLE_LPM_H__
7 
8 /**
9  * @file
10  * RTE Table LPM for IPv4
11  *
12  * This table uses the Longest Prefix Match (LPM) algorithm to uniquely
13  * associate data to lookup keys.
14  *
15  * Use-case: IP routing table. Routes that are added to the table associate a
16  * next hop to an IP prefix. The IP prefix is specified as IP address and depth
17  * and cover for a multitude of lookup keys (i.e. destination IP addresses)
18  * that all share the same data (i.e. next hop). The next hop information
19  * typically contains the output interface ID, the IP address of the next hop
20  * station (which is part of the same IP network the output interface is
21  * connected to) and other flags and counters.
22  *
23  * The LPM primitive only allows associating an 8-bit number (next hop ID) to
24  * an IP prefix, while a routing table can potentially contain thousands of
25  * routes or even more. This means that the same next hop ID (and next hop
26  * information) has to be shared by multiple routes, which makes sense, as
27  * multiple remote networks could be reached through the same next hop.
28  * Therefore, when a route is added or updated, the LPM table has to check
29  * whether the same next hop is already in use before using a new next hop ID
30  * for this route.
31  *
32  * The comparison between different next hops is done for the first
33  * “entry_unique_size” bytes of the next hop information (configurable
34  * parameter), which have to uniquely identify the next hop, therefore the user
35  * has to carefully manage the format of the LPM table entry (i.e.  the next
36  * hop information) so that any next hop data that changes value during
37  * run-time (e.g. counters) is placed outside of this area.
38  */
39 
40 #include <stdint.h>
41 
42 #include "rte_table.h"
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /** LPM table parameters */
49 struct rte_table_lpm_params {
50 	/** Table name */
51 	const char *name;
52 
53 	/** Maximum number of LPM rules (i.e. IP routes) */
54 	uint32_t n_rules;
55 
56 	/**< Number of tbl8s to allocate. */
57 	uint32_t number_tbl8s;
58 
59 	/**< This field is currently unused. */
60 	int flags;
61 
62 	/** Number of bytes at the start of the table entry that uniquely
63 	identify the entry. Cannot be bigger than table entry size. */
64 	uint32_t entry_unique_size;
65 
66 	/** Byte offset within input packet meta-data where lookup key (i.e.
67 	the destination IP address) is located. */
68 	uint32_t offset;
69 };
70 
71 /** LPM table rule (i.e. route), specified as IP prefix. While the key used by
72 the lookup operation is the destination IP address (read from the input packet
73 meta-data), the entry add and entry delete operations work with LPM rules, with
74 each rule covering for a multitude of lookup keys (destination IP addresses)
75 that share the same data (next hop). */
76 struct rte_table_lpm_key {
77 	/** IP address */
78 	uint32_t ip;
79 
80 	/** IP address depth. The most significant "depth" bits of the IP
81 	address specify the network part of the IP address, while the rest of
82 	the bits specify the host part of the address and are ignored for the
83 	purpose of route specification. */
84 	uint8_t depth;
85 };
86 
87 /** LPM table operations */
88 extern struct rte_table_ops rte_table_lpm_ops;
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif
95