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.
17 #ifndef __INCLUDE_PIPELINE_ARPICMP_BE_H__
18 #define __INCLUDE_PIPELINE_ARPICMP_BE_H__
20 #include "pipeline_common_be.h"
21 #define PIPELINE_ARPICMP_KEY_PORT_IN_AH(f_ah, f_pkt_work, f_pkt4_work) \
24 __rte_unused struct rte_pipeline *rte_p, \
25 struct rte_mbuf **pkts, \
31 for (j = 0; j < n_pkts; j++) \
32 rte_prefetch0(pkts[j]); \
34 for (i = 0; i < (n_pkts & (~0x3LLU)); i += 4) \
35 f_pkt4_work(&pkts[i], i, arg); \
37 for ( ; i < n_pkts; i++) \
38 f_pkt_work(pkts[i], i, arg); \
44 extern struct app_params *myApp;
45 void print_pkt1(struct rte_mbuf *pkt);
46 struct ether_addr *get_link_hw_addr(uint8_t out_port);
49 #include <rte_pipeline.h>
50 #include "rte_ether.h"
53 #if (RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN)
54 // x86 == little endian
55 // network == big endian
56 #define CHECK_ENDIAN_16(x) rte_be_to_cpu_16(x)
57 #define CHECK_ENDIAN_32(x) rte_be_to_cpu_32(x)
59 #define CHECK_ENDIAN_16(x) (x)
60 #define CHECK_ENDIAN_32(x) (x)
64 #define MAX_ARP_RT_ENTRY 32
65 #define MAX_ND_RT_ENTRY 32
67 #define ND_IPV6_ADDR_SIZE 16 /* 16 Byte of IPv6 Address */
91 /*128 Bit of IPv6 Address */
92 /*<48bit Network> <16bit Subnet> <64bit Interface> */
93 uint8_t ipv6[ND_IPV6_ADDR_SIZE];
101 enum arp_key_type type;
103 struct arp_key_ipv4 ipv4;
107 struct lib_arp_route_table_entry {
114 struct lib_nd_route_table_entry {
120 extern struct lib_arp_route_table_entry lib_arp_route_table[MAX_ARP_RT_ENTRY];
121 extern struct lib_nd_route_table_entry lib_nd_route_table[MAX_ND_RT_ENTRY];
123 extern uint8_t prv_in_port_a[PIPELINE_MAX_PORT_IN];
124 extern void convert_prefixlen_to_netmask_ipv6(uint32_t depth,
125 uint8_t netmask_ipv6[]);
126 uint32_t get_nh(uint32_t, uint32_t*);
127 void get_nh_ipv6(uint8_t ipv6[], uint32_t *port, uint8_t nhipv6[]);
129 extern uint32_t ARPICMP_DEBUG;
132 /* ARP entry populated and echo reply recieved */
134 /* ARP entry populated and either awaiting echo reply or stale entry */
138 extern uint32_t NDIPV6_DEBUG;
140 /* ICMPv6 entry populated and echo reply recieved */
141 #define ICMPv6_COMPLETE 1
142 /* ICMPv6 entry populated and either awaiting echo reply or stale entry */
143 #define ICMPv6_INCOMPLETE 0
145 struct arp_entry_data {
146 struct ether_addr eth_addr;
150 } __attribute__ ((__packed__));
153 struct nd_entry_data {
154 struct ether_addr eth_addr;
157 uint8_t ipv6[ND_IPV6_ADDR_SIZE];
158 } __attribute__ ((__packed__));
160 int get_dest_mac_address(const uint32_t ipaddr, const uint32_t phy_port,
161 struct ether_addr *hw_addr, uint32_t *nhip);
162 int get_dest_mac_addr(const uint32_t ipaddr, const uint32_t phy_port,
163 struct ether_addr *hw_addr);
165 int get_dest_mac_address_ipv6(uint8_t ipv6addr[], uint32_t phy_port,
166 struct ether_addr *hw_addr, uint8_t nhipv6[]);
168 void lib_arp_request_arp(
169 const uint32_t ipaddr,
170 const uint32_t phy_port,
171 struct rte_pipeline *rte_p);
173 void print_arp_table(void);
174 void print_nd_table(void);
175 void remove_arp_entry(uint32_t ipaddr, uint8_t portid);
176 void remove_nd_entry_ipv6(uint8_t ipv6addr[], uint8_t portid);
177 void populate_arp_entry(const struct ether_addr *hw_addr, uint32_t ipaddr,
180 int populate_nd_entry(const struct ether_addr *hw_addr, uint8_t ip[],
182 void request_arp(uint8_t port_id, uint32_t ip, struct rte_pipeline *rte_p);
183 void request_arp_wrap(uint8_t port_id, uint32_t ip);
184 void request_echo(unsigned int port_id, uint32_t ip);
186 void process_arpicmp_pkt(struct rte_mbuf *pkt, uint32_t out_port,
189 struct arp_entry_data *retrieve_arp_entry(const struct arp_key_ipv4 arp_key);
190 struct nd_entry_data *retrieve_nd_entry(struct nd_key_ipv6 nd_key);
192 struct nd_entry_data *retrieve_nd_entry(struct nd_key_ipv6 nd_key);
194 void lib_nd_init(/*struct pipeline_params *params, */ struct app_params *app);
195 void print_pkt1(struct rte_mbuf *pkt);
199 uint8_t lb_outport_id[PIPELINE_MAX_PORT_IN];
200 struct pipeline *loadb_pipeline[PIPELINE_MAX_PORT_IN];
201 struct pipeline *all_pipeline[PIPELINE_MAX_PORT_IN];
202 uint8_t vnf_to_loadb_map[PIPELINE_MAX_PORT_IN];
203 uint8_t port_to_loadb_map[PIPELINE_MAX_PORT_IN];
204 uint8_t loadb_pipeline_nums[PIPELINE_MAX_PORT_IN];
207 uint8_t lb_outport_id[PIPELINE_MAX_PORT_IN];
208 struct pipeline *arp_pipeline[PIPELINE_MAX_PORT_IN];
209 uint8_t vnf_to_arp_map[PIPELINE_MAX_PORT_IN];
210 uint8_t port_to_arp_map[PIPELINE_MAX_PORT_IN];
211 uint8_t arp_pipeline_nums[PIPELINE_MAX_PORT_IN];
214 void set_port_to_loadb_map(uint8_t pipeline_num);
215 uint8_t get_port_to_loadb_map(uint8_t phy_port_id);
216 /* acts on port_to_loadb_map */
218 void set_phy_inport_map(uint8_t pipeline_num, uint8_t *map);
219 void set_phy_outport_map(uint8_t pipeline_num, uint8_t *map);
221 void set_outport_id(uint8_t pipeline_num, struct pipeline *p, uint8_t *map);
222 /* acts on lb_outport_id */
223 uint8_t get_loadb_outport_id(uint8_t actual_phy_port);
224 /* acts on lb_outport_id */
225 uint8_t get_vnf_set_num(uint8_t pipeline_num);
227 void pipelines_port_info(void);
228 void pipelines_map_info(void);
229 void register_loadb_to_arp(uint8_t pipeline_num, struct pipeline *p,
230 __rte_unused struct app_params *app);
231 /* vnf_to_loadb_map[] and loadb_pipelines[] */
232 uint8_t SWQ_to_Port_map[128];
234 extern struct pipeline_be_ops pipeline_arpicmp_be_ops;
235 void register_pipeline_Qs(uint8_t pipeline_num, struct pipeline *p);
236 void set_link_map(uint8_t pipeline_num, struct pipeline *p, uint8_t *map);
237 void set_outport_id(uint8_t pipeline_num, struct pipeline *p, uint8_t *map);
238 void set_phy_outport_id(uint8_t pipeline_num, struct pipeline *p, uint8_t *map);
239 void set_phy_inport_id(uint8_t pipeline_num, struct pipeline *p, uint8_t *map);
244 enum pipeline_arpicmp_msg_req_type {
245 PIPELINE_ARPICMP_MSG_REQ_ENTRY_DBG,
246 PIPELINE_ARPICMP_MSG_REQS
252 struct pipeline_arpicmp_entry_dbg_msg_req {
253 enum pipeline_msg_req_type type;
254 enum pipeline_arpicmp_msg_req_type subtype;
264 struct pipeline_arpicmp_in_port_h_arg {
265 struct pipeline_arpicmp *p;
269 struct pipeline_arpicmp_entry_dbg_msg_rsp {
277 uint8_t icmpv6_type; /* ICMPV6 packet type. */
278 uint8_t icmpv6_code; /* ICMPV6 packet code. */
279 uint16_t icmpv6_cksum; /* ICMPV6 packet checksum. */
280 } __attribute__ ((__packed__));
285 struct icmpv6_info_hdr {
286 uint16_t icmpv6_ident; /* ICMPV6 packet identifier. */
287 uint16_t icmpv6_seq_nb; /* ICMPV6 packet sequence number. */
288 } __attribute__ ((__packed__));
293 struct icmpv6_nd_hdr {
294 /*ND Advertisement flags */
295 uint32_t icmpv6_reserved;
296 /* bit31-Router, bit30-Solicited, bit29-Override, bit28-bit0 unused */
298 uint8_t target_ipv6[16]; /**< target IPv6 address */
302 struct ether_addr link_layer_address;
303 } __attribute__ ((__packed__));
306 #define ICMPV6_PROTOCOL_ID 58
307 #define ICMPV6_ECHO_REQUEST 0x0080
308 #define ICMPV6_ECHO_REPLY 0x0081
309 #define ICMPV6_NEIGHBOR_SOLICITATION 0x0087
310 #define ICMPV6_NEIGHBOR_ADVERTISEMENT 0x0088
311 #define IPV6_MULTICAST 0xFF02
313 #define NEIGHBOR_SOLICITATION_SET 0x40000000
314 enum icmpv6_link_layer_Address_type {
315 e_Source_Link_Layer_Address = 1,
316 e_Target_Link_Layer_Address,
320 uint8_t is_multicast_ipv6_addr(uint8_t ipv6[]);
321 struct icmpv6_port_address {
326 struct icmpv6_port_address icmpv6_port_addresses[RTE_MAX_ETHPORTS];
328 #define MAX_NUM_ICMPv6_ENTRIES 64
329 //struct rte_pipeline *myicmpP;
330 struct rte_mbuf *lib_icmpv6_pkt;
331 void request_icmpv6_echo(uint32_t port_id, uint8_t ipv6[]);
332 void request_icmpv6_echo_message(uint16_t port_id, uint8_t ipv6[],
333 struct ether_addr *gw_addr);
335 process_icmpv6_pkt(struct rte_mbuf *pkt, uint32_t out_port, uint32_t pkt_num);
337 int get_dest_mac_addr_port(const uint32_t ipaddr,
338 uint32_t *phy_port, struct ether_addr *hw_addr);
340 int get_dest_mac_address_ipv6_port(uint8_t ipv6addr[], uint32_t *phy_port,
341 struct ether_addr *hw_addr, uint8_t nhipv6[]);