xref: /dpdk/lib/table/rte_table_lpm_ipv6.h (revision e1a06e391ba74f9c4d46a6ecef6d8ee084f4229e)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef __INCLUDE_RTE_TABLE_LPM_IPV6_H__
699a2dd95SBruce Richardson #define __INCLUDE_RTE_TABLE_LPM_IPV6_H__
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file
1099a2dd95SBruce Richardson  * RTE Table LPM for IPv6
1199a2dd95SBruce Richardson  *
1299a2dd95SBruce Richardson  * This table uses the Longest Prefix Match (LPM) algorithm to uniquely
1399a2dd95SBruce Richardson  * associate data to lookup keys.
1499a2dd95SBruce Richardson  *
1599a2dd95SBruce Richardson  * Use-case: IP routing table. Routes that are added to the table associate a
1699a2dd95SBruce Richardson  * next hop to an IP prefix. The IP prefix is specified as IP address and depth
1799a2dd95SBruce Richardson  * and cover for a multitude of lookup keys (i.e. destination IP addresses)
1899a2dd95SBruce Richardson  * that all share the same data (i.e. next hop). The next hop information
1999a2dd95SBruce Richardson  * typically contains the output interface ID, the IP address of the next hop
2099a2dd95SBruce Richardson  * station (which is part of the same IP network the output interface is
2199a2dd95SBruce Richardson  * connected to) and other flags and counters.
2299a2dd95SBruce Richardson  *
2399a2dd95SBruce Richardson  * The LPM primitive only allows associating an 8-bit number (next hop ID) to
2499a2dd95SBruce Richardson  * an IP prefix, while a routing table can potentially contain thousands of
2599a2dd95SBruce Richardson  * routes or even more. This means that the same next hop ID (and next hop
2699a2dd95SBruce Richardson  * information) has to be shared by multiple routes, which makes sense, as
2799a2dd95SBruce Richardson  * multiple remote networks could be reached through the same next hop.
2899a2dd95SBruce Richardson  * Therefore, when a route is added or updated, the LPM table has to check
2999a2dd95SBruce Richardson  * whether the same next hop is already in use before using a new next hop ID
3099a2dd95SBruce Richardson  * for this route.
3199a2dd95SBruce Richardson  *
3299a2dd95SBruce Richardson  * The comparison between different next hops is done for the first
3399a2dd95SBruce Richardson  * “entry_unique_size” bytes of the next hop information (configurable
3499a2dd95SBruce Richardson  * parameter), which have to uniquely identify the next hop, therefore the user
3599a2dd95SBruce Richardson  * has to carefully manage the format of the LPM table entry (i.e.  the next
3699a2dd95SBruce Richardson  * hop information) so that any next hop data that changes value during
3799a2dd95SBruce Richardson  * run-time (e.g. counters) is placed outside of this area.
383e4c5be9SThomas Monjalon  */
3999a2dd95SBruce Richardson 
4099a2dd95SBruce Richardson #include <stdint.h>
4199a2dd95SBruce Richardson 
42*e1a06e39SRobin Jarry #include <rte_common.h>
43*e1a06e39SRobin Jarry #include <rte_ip6.h>
44*e1a06e39SRobin Jarry 
4599a2dd95SBruce Richardson #include "rte_table.h"
4699a2dd95SBruce Richardson 
47719834a6SMattias Rönnblom #ifdef __cplusplus
48719834a6SMattias Rönnblom extern "C" {
49719834a6SMattias Rönnblom #endif
50719834a6SMattias Rönnblom 
51*e1a06e39SRobin Jarry #define RTE_LPM_IPV6_ADDR_SIZE (RTE_DEPRECATED(RTE_LPM_IPV6_ADDR_SIZE) RTE_IPV6_ADDR_SIZE)
5299a2dd95SBruce Richardson 
5399a2dd95SBruce Richardson /** LPM table parameters */
5499a2dd95SBruce Richardson struct rte_table_lpm_ipv6_params {
5599a2dd95SBruce Richardson 	/** Table name */
5699a2dd95SBruce Richardson 	const char *name;
5799a2dd95SBruce Richardson 
5899a2dd95SBruce Richardson 	/** Maximum number of LPM rules (i.e. IP routes) */
5999a2dd95SBruce Richardson 	uint32_t n_rules;
6099a2dd95SBruce Richardson 
6199a2dd95SBruce Richardson 	uint32_t number_tbl8s;
6299a2dd95SBruce Richardson 
6399a2dd95SBruce Richardson 	/** Number of bytes at the start of the table entry that uniquely
6499a2dd95SBruce Richardson 	identify the entry. Cannot be bigger than table entry size. */
6599a2dd95SBruce Richardson 	uint32_t entry_unique_size;
6699a2dd95SBruce Richardson 
6799a2dd95SBruce Richardson 	/** Byte offset within input packet meta-data where lookup key (i.e.
6899a2dd95SBruce Richardson 	the destination IP address) is located. */
6999a2dd95SBruce Richardson 	uint32_t offset;
7099a2dd95SBruce Richardson };
7199a2dd95SBruce Richardson 
7299a2dd95SBruce Richardson /** LPM table rule (i.e. route), specified as IP prefix. While the key used by
7399a2dd95SBruce Richardson the lookup operation is the destination IP address (read from the input packet
7499a2dd95SBruce Richardson meta-data), the entry add and entry delete operations work with LPM rules, with
7599a2dd95SBruce Richardson each rule covering for a multitude of lookup keys (destination IP addresses)
7699a2dd95SBruce Richardson that share the same data (next hop). */
7799a2dd95SBruce Richardson struct rte_table_lpm_ipv6_key {
7899a2dd95SBruce Richardson 	/** IP address */
79*e1a06e39SRobin Jarry 	struct rte_ipv6_addr ip;
8099a2dd95SBruce Richardson 
8199a2dd95SBruce Richardson 	/** IP address depth. The most significant "depth" bits of the IP
8299a2dd95SBruce Richardson 	address specify the network part of the IP address, while the rest of
8399a2dd95SBruce Richardson 	the bits specify the host part of the address and are ignored for the
8499a2dd95SBruce Richardson 	purpose of route specification. */
8599a2dd95SBruce Richardson 	uint8_t depth;
8699a2dd95SBruce Richardson };
8799a2dd95SBruce Richardson 
8899a2dd95SBruce Richardson /** LPM table operations */
8999a2dd95SBruce Richardson extern struct rte_table_ops rte_table_lpm_ipv6_ops;
9099a2dd95SBruce Richardson 
9199a2dd95SBruce Richardson #ifdef __cplusplus
9299a2dd95SBruce Richardson }
9399a2dd95SBruce Richardson #endif
9499a2dd95SBruce Richardson 
9599a2dd95SBruce Richardson #endif
96