Imported Upstream version 16.04
[deb_dpdk.git] / lib / librte_table / rte_table_lpm_ipv6.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_IPV6_H__
35 #define __INCLUDE_RTE_TABLE_LPM_IPV6_H__
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /**
42  * @file
43  * RTE Table LPM for IPv6
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 #define RTE_LPM_IPV6_ADDR_SIZE 16
79
80 /** LPM table parameters */
81 struct rte_table_lpm_ipv6_params {
82         /** Table name */
83         const char *name;
84
85         /** Maximum number of LPM rules (i.e. IP routes) */
86         uint32_t n_rules;
87
88         uint32_t number_tbl8s;
89
90         /** Number of bytes at the start of the table entry that uniquely
91         identify the entry. Cannot be bigger than table entry size. */
92         uint32_t entry_unique_size;
93
94         /** Byte offset within input packet meta-data where lookup key (i.e.
95         the destination IP address) is located. */
96         uint32_t offset;
97 };
98
99 /** LPM table rule (i.e. route), specified as IP prefix. While the key used by
100 the lookup operation is the destination IP address (read from the input packet
101 meta-data), the entry add and entry delete operations work with LPM rules, with
102 each rule covering for a multitude of lookup keys (destination IP addresses)
103 that share the same data (next hop). */
104 struct rte_table_lpm_ipv6_key {
105         /** IP address */
106         uint8_t ip[RTE_LPM_IPV6_ADDR_SIZE];
107
108         /** IP address depth. The most significant "depth" bits of the IP
109         address specify the network part of the IP address, while the rest of
110         the bits specify the host part of the address and are ignored for the
111         purpose of route specification. */
112         uint8_t depth;
113 };
114
115 /** LPM table operations */
116 extern struct rte_table_ops rte_table_lpm_ipv6_ops;
117
118 #ifdef __cplusplus
119 }
120 #endif
121
122 #endif