2 // Copyright (c) 2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
19 * L3fwd lpm6 header file is for IPv6 specific declarations
29 #include <sys/types.h>
31 #include <sys/queue.h>
37 #include <rte_debug.h>
38 #include <rte_ether.h>
39 #include <rte_ethdev.h>
41 #include <rte_mempool.h>
42 #include <rte_cycles.h>
49 #include <rte_table_lpm_ipv6.h>
50 #include "l3fwd_common.h"
51 #include "l3fwd_lpm4.h"
52 #include "interface.h"
55 * Define all RTE MBUF offset size
58 #define MBUF_HDR_ROOM 256 /**< MBUF HEADER ROOM OFFSET */
60 #define IP_HDR_SIZE_IPV6 40 /**< IPv6 HEADER OFFSET */
61 #define IP_HDR_SRC_ADR_OFST_IPV6 8 /**< IPv6 HEADER SRC IP ADDRESS OFFSET */
62 #define IP_HDR_DST_ADR_OFST_IPV6 24 /**< IPv6 HEADER DST IP ADDRESS OFFSET */
64 /* IPV6 Rules and Tables8s */
65 #define IPV6_L3FWD_LPM_MAX_RULES 1024 /**< Number of LPM6 Rules*/
66 #define IPV6_L3FWD_LPM_NUMBER_TBL8S (1 << 16) /**< Number of Table 8 for LPM6 */
68 #define MAX_FIB_PATHS 8 /**< MAX FIB PATH, If ECMP feature is enabled */
71 * A structure used to define the routing information for IPv6
72 * This structure is used as input parameters for route ADD
74 struct ipv6_routing_info {
75 uint8_t dst_ipv6[RTE_LPM_IPV6_ADDR_SIZE]; /**< DST IPv6 Address */
76 uint8_t depth; /**< Depth */
77 uint32_t metric; /**< Metrics */
78 uint32_t fib_nh_size; /**< num of fib paths, greater than if Multipath(ECMP) feature is supported*/
79 uint8_t nh_ipv6[MAX_FIB_PATHS][RTE_LPM_IPV6_ADDR_SIZE]; /**< NextHop IP Address */
80 uint8_t out_port[MAX_FIB_PATHS]; /**< OUTGOING PORT */
81 } __rte_cache_aligned; /**< RTE CACHE ALIGNED */
84 * A structure used to define the fib path for Destination IPv6 Address
85 * This fib path is shared accross different fib_info.
87 struct ipv6_fib_path {
88 uint8_t nh_ipv6[RTE_LPM_IPV6_ADDR_SIZE]; /**< Next hop IP address (only valid for remote routes) */
89 uint32_t refcount; /**< Refcount, greater then 1 if multiple fib_info has same fib_path*/
90 uint8_t out_port; /**< Output port */
91 struct l2_adj_ipv6_entry *l2_adj_ipv6_ptr;/**< Address of the L2 ADJ table entry */
92 } __rte_cache_aligned; /**< RTE CACHE ALIGNED */
95 * A structure used to define the fib info (Route info)
96 * This fib info structure can have multiple fib paths.
98 struct ipv6_fib_info {
99 uint8_t dst_ipv6[RTE_LPM_IPV6_ADDR_SIZE]; /**< DST IPv6 Address */
100 uint8_t depth; /**< Depth */
101 uint32_t metric; /**< Metric */
102 uint32_t fib_nh_size; /**< num of fib paths, greater than if Multipath(ECMP) feature is supported*/
103 struct ipv6_fib_path *path[MAX_FIB_PATHS]; /**< Array of pointers to the fib_path */
104 } __rte_cache_aligned; /**< RTE CACHE ALIGNED */
107 * A structure used to define the L2 Adjacency table
109 struct l2_adj_ipv6_entry {
110 struct ether_addr eth_addr; /**< Ether address */
111 uint8_t out_port_id; /**< Outgoing port */
112 uint8_t nh_ipv6[RTE_LPM_IPV6_ADDR_SIZE]; /**< Next hop IP address (only valid for remote routes) */
113 uint32_t refcount; /**< Refcount, greater then 1 if multiple fib_path has same L2_adj_entry*/
114 uint8_t l2_string[256]; /**< L2 string, to rewrite the packet before transmission */
115 l2_phy_interface_t *phy_port; /**< Address of the L2 physical interface structure */
116 uint8_t flags; /**< flags for marking this entry as resolved or unresolved. */
117 } __rte_cache_aligned; /**< RTE CACHE ALIGNED */
120 * A structure used to define the L2 Adjacency table
122 struct l2_adj_key_ipv6 {
123 /*128 Bit of IPv6 Address */
124 /*<48bit Network> <16bit Subnet> <64bit Interface> */
125 uint8_t nh_ipv6[RTE_LPM_IPV6_ADDR_SIZE]; /**< Next hop IPv6 address */
126 uint8_t out_port_id; /**< Outgoing port */
127 uint8_t filler1; /**< Filler 1, for better hash key */
128 uint8_t filler2; /**< Filler2, for better hash key*/
129 uint8_t filler3; /**< Filler3, for better hash Key */
133 * A structure used to define the fib path key for hash table
135 struct fib_path_key_ipv6 {
136 /*128 Bit of IPv6 Address */
137 /*<48bit Network> <16bit Subnet> <64bit Interface> */
138 uint8_t nh_ipv6[RTE_LPM_IPV6_ADDR_SIZE]; /**< Next hop IPv6 address */
139 uint8_t out_port; /**< Outgoing port */
140 uint8_t filler1; /**< Filler 1, for better hash key */
141 uint8_t filler2; /**< Filler2, for better hash key*/
142 uint8_t filler3; /**< Filler3, for better hash Key */
145 struct ipv6_protocol_type {
146 uint8_t protocol_type; /**< Protocol Type */
147 void (*func) (struct rte_mbuf **, uint16_t, uint64_t,
148 l2_phy_interface_t *);
149 } __rte_cache_aligned;
151 /* Function Declarations */
153 * To creare LPM6 table, Cuckoo hash table for fib_path and l2_adj_entry tables
155 * 0 for failure, 1 for success
160 * To add a route in LPM6 table by populating fib_path and L2 Adjacency.
162 * To add the route based on ipv6_routing_info stucture.
164 * 0 for failure, 1 for success
166 int lpm6_table_route_add(struct ipv6_routing_info *data);
169 * To Delete the IP route and corresponding fib_path and L2 Adjacency entries.
171 * Destionation IPv6 for which the route need to deleted
173 * netmask for the Destination IP
175 * 0 for failure, 1 for success
177 int lpm6_table_route_delete(uint8_t dst_ipv6[RTE_LPM_IPV6_ADDR_SIZE],
181 * To perform a LPM6 table lookup
183 * Burst of packets that needs to be lookup in LPM6 table
185 * Number of valid L3 packets
187 * number of valid pkts mask that needs to be lookup in LPM6 table
189 * 0 for failure, 1 for success
191 int lpm6_table_lookup(struct rte_mbuf **pkts_burst, uint16_t nb_pkts,
193 l2_phy_interface_t *port_ptr[RTE_PORT_IN_BURST_SIZE_MAX],
197 * To forward the valid L3 packets for LMP6 table lookup and forward ICMP Pkts to ICMP module
199 * packet burst of type rte_mbuf
201 * Number of valid L3 packets
202 * @param valid_pkts_mask
203 * Valid IPv6 packets mask that needs to be processed
205 * IPv6 Pkt received form the input port.
209 void l3fwd_rx_ipv6_packets(struct rte_mbuf **m, uint16_t nb_pkts,
210 uint64_t valid_pkts_mask,
211 l2_phy_interface_t *in_port);
214 * To populate the fib_path for the nexthop IPv6 and outgoing port
216 * NextHop Ip Address for which L2_adj_entry needs to be populated
220 * NULL if lookup fails, Address of the type ipv6_fib_path if lookup success
222 struct ipv6_fib_path *populate_ipv6_fib_path(uint8_t
223 nh_ipv6[RTE_LPM_IPV6_ADDR_SIZE],
227 * To retrieve the fib_path entry for the nexthop IP and outgoing port
228 * This queries with cuckoo hash table based on the fib_path_key_ipv4
230 * Key which is required for Cuckook hash table lookup
232 * NULL if lookup fails, Address of type ipv6_fib_path if lookup success
234 struct ipv6_fib_path *retrieve_ipv6_fib_path_entry(struct fib_path_key_ipv6
238 * To retrieve the l2_adj_entry for the nexthop IP and outgoing port
239 * This queries with cuckoo hash table based on the l2_adj_key_ipv6
241 * Key which is required for Cuckook hash table lookup
243 * NULL if lookup fails, Address of type l2_adj_ipv6_entry if lookup success
245 struct l2_adj_ipv6_entry *retrieve_ipv6_l2_adj_entry(struct l2_adj_key_ipv6
249 * To populate the l2_adj_entry for the nexthop IP and outgoing port
251 * NextHop Ip Address for which L2_adj_entry needs to be populated
255 * NULL if lookup fails, Address of the L2_adj_ipv6_entry if lookup success
257 struct l2_adj_ipv6_entry *populate_ipv6_l2_adj(uint8_t
258 nh_ip[RTE_LPM_IPV6_ADDR_SIZE],
262 * To get the destination MAC Address for the nexthop IP and outgoing port
264 * Next HOP IP Address for which MAC address is needed
265 * @param out_phy_port
266 * Outgoing physical port
268 * pointet to the ether_add, This gets update with valid MAC address based on nh_ip and out port
270 * 0 if failure, 1 if success
272 int get_dest_mac_for_nexthop_ipv6(uint8_t nh_ipv6[RTE_LPM_IPV6_ADDR_SIZE],
273 uint32_t out_phy_port,
274 struct ether_addr *hw_addr);
277 * To delete the ipv6 fib path and l2 adjacency entry from the cuckoo hash table
281 void remove_ipv6_fib_l2_adj_entry(void *entry);
284 ipv6_l3_protocol_type_add(uint8_t protocol_type,
285 void (*func) (struct rte_mbuf **, uint16_t, uint64_t,
286 l2_phy_interface_t *));
289 ipv6_local_deliver(struct rte_mbuf **, uint16_t, uint64_t,
290 l2_phy_interface_t *);
293 ipv6_forward_deliver(struct rte_mbuf **, uint16_t, uint64_t,
294 l2_phy_interface_t *);
296 int is_valid_ipv6_pkt(struct ipv6_hdr *pkt, uint32_t link_len);
297 uint8_t ipv6_hash_load_balance(struct rte_mbuf *mbuf);
300 * To resolve l2_adj_entry based on nexthop IP, outgoing port and ether hw address.
302 * NextHop Ip Address for which L2_adj_entry needs to be resolved
306 * Ethernet hardware address for the above nexthop IP and out port ID.
311 void resolve_ipv6_l2_adj(uint8_t nh_ip[RTE_LPM_IPV6_ADDR_SIZE], uint8_t portid,
312 struct ether_addr *hw_addr);
314 void ipv6_iterate__hash_table(void);
315 #endif /* L3FWD_LPM_H */