Imported Upstream version 16.04
[deb_dpdk.git] / lib / librte_table / rte_table_lpm.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef __INCLUDE_RTE_TABLE_LPM_H__
35 #define __INCLUDE_RTE_TABLE_LPM_H__
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /**
42  * @file
43  * RTE Table LPM for IPv4
44  *
45  * This table uses the Longest Prefix Match (LPM) algorithm to uniquely
46  * associate data to lookup keys.
47  *
48  * Use-case: IP routing table. Routes that are added to the table associate a
49  * next hop to an IP prefix. The IP prefix is specified as IP address and depth
50  * and cover for a multitude of lookup keys (i.e. destination IP addresses)
51  * that all share the same data (i.e. next hop). The next hop information
52  * typically contains the output interface ID, the IP address of the next hop
53  * station (which is part of the same IP network the output interface is
54  * connected to) and other flags and counters.
55  *
56  * The LPM primitive only allows associating an 8-bit number (next hop ID) to
57  * an IP prefix, while a routing table can potentially contain thousands of
58  * routes or even more. This means that the same next hop ID (and next hop
59  * information) has to be shared by multiple routes, which makes sense, as
60  * multiple remote networks could be reached through the same next hop.
61  * Therefore, when a route is added or updated, the LPM table has to check
62  * whether the same next hop is already in use before using a new next hop ID
63  * for this route.
64  *
65  * The comparison between different next hops is done for the first
66  * “entry_unique_size” bytes of the next hop information (configurable
67  * parameter), which have to uniquely identify the next hop, therefore the user
68  * has to carefully manage the format of the LPM table entry (i.e.  the next
69  * hop information) so that any next hop data that changes value during
70  * run-time (e.g. counters) is placed outside of this area.
71  *
72  ***/
73
74 #include <stdint.h>
75
76 #include "rte_table.h"
77
78 /** LPM table parameters */
79 struct rte_table_lpm_params {
80         /** Table name */
81         const char *name;
82
83         /** Maximum number of LPM rules (i.e. IP routes) */
84         uint32_t n_rules;
85
86         /**< Number of tbl8s to allocate. */
87         uint32_t number_tbl8s;
88
89         /**< This field is currently unused. */
90         int flags;
91
92         /** Number of bytes at the start of the table entry that uniquely
93         identify the entry. Cannot be bigger than table entry size. */
94         uint32_t entry_unique_size;
95
96         /** Byte offset within input packet meta-data where lookup key (i.e.
97         the destination IP address) is located. */
98         uint32_t offset;
99 };
100
101 /** LPM table rule (i.e. route), specified as IP prefix. While the key used by
102 the lookup operation is the destination IP address (read from the input packet
103 meta-data), the entry add and entry delete operations work with LPM rules, with
104 each rule covering for a multitude of lookup keys (destination IP addresses)
105 that share the same data (next hop). */
106 struct rte_table_lpm_key {
107         /** IP address */
108         uint32_t ip;
109
110         /** IP address depth. The most significant "depth" bits of the IP
111         address specify the network part of the IP address, while the rest of
112         the bits specify the host part of the address and are ignored for the
113         purpose of route specification. */
114         uint8_t depth;
115 };
116
117 /** LPM table operations */
118 extern struct rte_table_ops rte_table_lpm_ops;
119
120 #ifdef __cplusplus
121 }
122 #endif
123
124 #endif