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_LIB_ARP_H__
18 #define __INCLUDE_LIB_ARP_H__
20 #include <rte_pipeline.h>
21 #include "rte_ether.h"
25 #define ND_IPV6_ADDR_SIZE 16 /**< 16 Byte of IPv6 Address. */
26 #define ND_IPV6_TIMER_EXPIRY 300 /**< in Seconds, Timer for ND IPv6 Expiry */
27 #define ARP_TIMER_EXPIRY 1800 /**< in Seconds, TIMER for ARP Expiry */
28 #define TIMER_MILLISECOND 1
29 #define RTE_LOGTYPE_LIBARP RTE_LOGTYPE_USER1
30 #define MAX_ND_RT_ENTRY 32
31 #define MAX_ARP_RT_ENTRY 32
34 * A structure for Route table entries of IPv4
37 struct lib_arp_route_table_entry {
38 uint32_t ip; /**< Ipv4 address*/
39 uint32_t mask; /**< mask */
40 uint32_t port; /**< Physical port */
41 uint32_t nh; /**< next hop */
45 * A structure for Route table entires of IPv6
48 struct lib_nd_route_table_entry {
49 uint8_t ipv6[16]; /**< Ipv6 address */
50 uint8_t depth; /**< Depth */
51 uint32_t port; /**< Port */
52 uint8_t nhipv6[16]; /**< next hop Ipv6 */
55 extern struct lib_nd_route_table_entry lib_nd_route_table[MAX_ND_RT_ENTRY];
56 extern struct lib_arp_route_table_entry lib_arp_route_table[MAX_ARP_RT_ENTRY];
70 uint32_t ip; /**< IP address */
71 uint8_t port_id; /**< Port id */
72 uint8_t filler1; /**< filler 1, for better hash key */
73 uint8_t filler2; /**< filler 2, for better hash key */
74 uint8_t filler3; /**< filler 3, for better hash key */
81 uint8_t ipv6[ND_IPV6_ADDR_SIZE]; /**< 128 Bit of IPv6 Address*/
82 uint8_t port_id; /**< Port id */
92 enum arp_key_type type;
94 struct arp_key_ipv4 ipv4;
95 } key; /**< Key of type arp key Ipv4 */
99 * call back function parameter pair remove nd entry
103 struct nd_timer_key {
104 uint8_t ipv6[ND_IPV6_ADDR_SIZE]; /**< IPv6 address */
105 uint8_t port_id; /**< Port id */
106 } __rte_cache_aligned;
109 * call back function parameter remove arp entry
112 struct arp_timer_key {
113 uint32_t ip; /**< Ip address */
114 uint8_t port_id; /**< Port id */
115 } __rte_cache_aligned;
117 extern uint32_t ARPICMP_DEBUG;
119 #define COMPLETE 1 /**< ARP entry populated and echo reply recieved. */
120 #define INCOMPLETE 0 /**< ARP entry populated and either awaiting echo reply or stale entry. */
122 extern uint32_t NDIPV6_DEBUG; /**< ND IPv6 */
124 #define ICMPv6_COMPLETE 1 /**< ICMPv6 entry populated and echo reply recieved. */
125 #define ICMPv6_INCOMPLETE 0 /**< ICMPv6 entry populated and either awaiting echo reply or stale entry. */
126 #define STATIC_ARP 1 /**< Static ARP Entry. */
127 #define DYNAMIC_ARP 0 /**< Dynamic ARP Entry. */
128 #define STATIC_ND 1 /**< Static ND Entry. */
129 #define DYNAMIC_ND 0 /**< Dynamic ND Entry. */
132 * A structure is used to defined the ARP entry data
133 * This structure is used as a input parameters for entry of ARP data
136 struct arp_entry_data {
137 struct ether_addr eth_addr; /**< ethernet address */
138 uint32_t ip; /**< IP address */
139 uint8_t port; /**< Port */
140 uint8_t status; /**< Status of entry */
141 uint8_t mode; /**< Mode */
142 uint8_t retry_count; /**< retry count for ARP*/
143 struct rte_timer *timer; /**< Timer Associated with ARP*/
144 struct arp_timer_key *timer_key;
145 } __attribute__ ((packed));
148 * A structure is used to defined the table for arp entry data
149 * This structure is used to maintain the arp entry data
152 struct table_arp_entry_data {
153 uint8_t eth_addr[6]; /**< Ethernet address */
154 uint8_t port; /**< port */
155 uint8_t status; /**< status of entry */
156 uint32_t ip; /**< Ip address */
157 } __attribute__ ((packed));
160 * A structure is used to define the ND entry data for IPV6
161 * This structure is used as a input parameters for ND entry data
164 struct nd_entry_data {
165 struct ether_addr eth_addr; /**< Ethernet address */
166 uint8_t port; /**< port */
167 uint8_t status; /**< statusof the entry */
168 uint8_t mode; /**< Mode */
169 uint8_t ipv6[ND_IPV6_ADDR_SIZE]; /**< Ipv6 address */
170 struct rte_timer *timer; /**< Timer */
171 } __attribute__ ((packed));
174 * A structure is used to define the table for ND entry data
175 * This structure is used to maintain ND entry data
179 struct table_nd_entry_data {
180 uint8_t eth_addr[6]; /**< Ethernet address */
181 uint8_t port; /**< Port */
182 uint8_t status; /**< status of Entry */
183 uint8_t ipv6[ND_IPV6_ADDR_SIZE]; /**< IPv6 address */
184 struct rte_timer *timer; /**< Timer */
185 } __attribute__ ((packed));
188 * To get the destination MAC address andnext hop for the ip address and outgoing port
190 * IP address for which MAC address is needed.
194 * pointer to the ether_addr, This gets update with valid MAC addresss
196 * Gets the next hop IP by Ip address and physical port
198 * 0 if failure, and 1 if success
201 int get_dest_mac_address(const uint32_t ipaddr, uint32_t *phy_port,
202 struct ether_addr *hw_addr, uint32_t *nhip);
204 * To get the destination MAC address andnext hop for the ip address and outgoing port
206 * IP address for which MAC address is needed.
210 * pointer to the ether_addr, This gets update with valid MAC addresss
212 * Gets the next hop IP by Ip address and physical port
214 * 0 if failure, and 1 if success
216 int get_dest_mac_addr_port(const uint32_t ipaddr,
217 uint32_t *phy_port, struct ether_addr *hw_addr);
220 * To get the destination mac address for IPv4 address
222 * IP address which need the destination mac address
226 * pointer to the ether_addr, This gets update with valid mac address
228 * 0 if failure, 1 if success
230 int get_dest_mac_addr(const uint32_t ipaddr, uint32_t *phy_port,
231 struct ether_addr *hw_addr);
234 * To get the destination mac address for IPV6 address
236 * IPv6 address which need the destination mac adress
240 * pointer to the ether_address, This gets update with valid mac address
242 * Gets the next hop ipv6 address by ipv6 address and physical port
244 * 0 if failure, 1 ifsuccess
246 int get_dest_mac_address_ipv6(uint8_t ipv6addr[], uint32_t *phy_port,
247 struct ether_addr *hw_addr, uint8_t nhipv6[]);
249 * To get the destination mac address for IPV6 address
251 * IPv6 address which need the destination mac adress
255 * pointer to the ether_address, This gets update with valid mac address
257 * Gets the next hop ipv6 address by ipv6 address and physical port
259 * 0 if failure, 1 ifsuccess
262 int get_dest_mac_address_ipv6_port(uint8_t ipv6addr[], uint32_t *phy_port,
263 struct ether_addr *hw_addr,
267 * To get hardware link address
272 struct ether_addr *get_link_hw_addr(uint8_t out_port);
275 * This prints the Arp Table
279 void print_arp_table(void);
282 * This prints the ND table
286 void print_nd_table(void);
289 * This removes arp entry from Table
295 void remove_arp_entry(uint32_t ipaddr, uint8_t portid, void *arg);
298 * Removes ND entry from Nd Table
305 void remove_nd_entry_ipv6(uint8_t ipv6addr[], uint8_t portid);
308 * Populate arp entry in arp Table
318 void populate_arp_entry(const struct ether_addr *hw_addr, uint32_t ipaddr,
319 uint8_t portid, uint8_t mode);
322 * Populate ND entry in ND Table
333 void populate_nd_entry(const struct ether_addr *hw_addr, uint8_t ip[],
334 uint8_t portid, uint8_t mode);
337 * To send ARp request
344 void request_arp(uint8_t port_id, uint32_t ip);
347 * TO send echo request
353 struct rte_mbuf *request_echo(uint32_t port_id, uint32_t ip);
356 * To send icmpv6 echo request
362 struct rte_mbuf *request_icmpv6_echo(uint8_t ipv6[], l2_phy_interface_t *port);
371 struct rte_mbuf *request_nd(uint8_t ipv6[], l2_phy_interface_t *port);
374 * To process te ARP and ICMP packets
376 * Packets to be processed
382 void process_arpicmp_pkt(struct rte_mbuf *pkt, l2_phy_interface_t *port);
386 * Validate if key-value pair already exists in the hash table for given key - IPv4
388 * Arp key to validate entry
390 struct arp_entry_data *retrieve_arp_entry(const struct arp_key_ipv4 arp_key);
394 * Validate if key-value pair already exists in the hash table for given key - ND IPv6
396 * Nd key to validate Nd entry
399 struct nd_entry_data *retrieve_nd_entry(struct nd_key_ipv6 nd_key);
402 * Setsup Arp Initilization
404 //void lib_arp_init(void);
405 void lib_arp_init(struct pipeline_params *params, struct app_params *app);
407 void set_port_to_loadb_map(uint8_t pipeline_num);
410 * Acts on port_to_loadb_map
412 uint8_t get_port_to_loadb_map(uint8_t phy_port_id);
414 void set_phy_inport_map(uint8_t pipeline_num, uint8_t *map);
415 void set_phy_outport_map(uint8_t pipeline_num, uint8_t *map);
418 * Acts on lb_outport_id
421 uint8_t get_loadb_outport_id(uint8_t actual_phy_port);
422 uint8_t get_vnf_set_num(uint8_t pipeline_num);
424 void pipelines_port_info(void);
425 void pipelines_map_info(void);
428 * A callback for arp Timer
434 void arp_timer_callback(struct rte_timer *, void *arg);
437 * A callback for ND timer
443 void nd_timer_callback(struct rte_timer *timer, void *arg);
446 * To create Arp Table
449 void create_arp_table(void);
454 void create_nd_table(void);
457 * To parse and process the Arp and icmp packets
467 void process_arpicmp_pkt_parse(struct rte_mbuf **pkt, uint16_t pkt_num,
468 uint64_t pkt_mask, l2_phy_interface_t *port);
475 void send_gratuitous_arp(l2_phy_interface_t *port);
481 void set_arpdebug(int flag);
483 * To set timer for arp entry
485 * timer val for arp entry
487 void set_arptimeout(uint32_t timeout_val);
489 * To get nexthop for ipv4
495 uint32_t get_nh(uint32_t, uint32_t *);
497 * To get nexthop for ipv6
505 void get_nh_ipv6(uint8_t ipv6[], uint32_t *port, uint8_t nhipv6[]);