cfbbe617e300ee491118eedf7ab3017ec2175c05
[samplevnf.git] / common / VIL / pipeline_arpicmp / pipeline_arpicmp_be.h
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
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
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 */
16
17 #ifndef __INCLUDE_PIPELINE_ARPICMP_BE_H__
18 #define __INCLUDE_PIPELINE_ARPICMP_BE_H__
19
20 #include "pipeline_common_be.h"
21 #define PIPELINE_ARPICMP_KEY_PORT_IN_AH(f_ah, f_pkt_work, f_pkt4_work)  \
22 static int                                                              \
23 f_ah(                                                                   \
24         __rte_unused struct rte_pipeline *rte_p,                        \
25         struct rte_mbuf **pkts,                                         \
26         uint32_t n_pkts,                                                \
27         void *arg)                                                      \
28 {                                                                       \
29         uint32_t i, j;                                                  \
30                                                                         \
31         for (j = 0; j < n_pkts; j++)                                    \
32                 rte_prefetch0(pkts[j]);                                 \
33                                                                         \
34         for (i = 0; i < (n_pkts & (~0x3LLU)); i += 4)                   \
35                 f_pkt4_work(&pkts[i], i, arg);                          \
36                                                                         \
37         for ( ; i < n_pkts; i++)                                        \
38                 f_pkt_work(pkts[i], i, arg);                            \
39                                                                         \
40                                                                         \
41         return 0;                                                       \
42 }
43
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);
47 #ifdef VNF_ACL
48
49 #include <rte_pipeline.h>
50 #include "rte_ether.h"
51 #include "app.h"
52
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)
58 #else
59 #define CHECK_ENDIAN_16(x) (x)
60 #define CHECK_ENDIAN_32(x) (x)
61 #endif
62
63
64 #define MAX_ARP_RT_ENTRY 32
65 #define MAX_ND_RT_ENTRY 32
66
67 #define ND_IPV6_ADDR_SIZE 16    /* 16 Byte of IPv6 Address */
68
69 enum {
70 ARP_FOUND,
71 ARP_NOT_FOUND,
72 NH_NOT_FOUND,
73 };
74
75 enum arp_key_type {
76         ARP_IPV4,
77         /* ND IPv6 */
78         ND_IPV6,
79 };
80
81 struct arp_key_ipv4 {
82         uint32_t ip;
83         uint8_t port_id;
84         uint8_t filler1;
85         uint8_t filler2;
86         uint8_t filler3;
87 };
88
89 /* ND IPv6 */
90 struct nd_key_ipv6 {
91         /*128 Bit of IPv6 Address */
92         /*<48bit Network> <16bit Subnet> <64bit Interface> */
93         uint8_t ipv6[ND_IPV6_ADDR_SIZE];
94         uint8_t port_id;
95         uint8_t filler1;
96         uint8_t filler2;
97         uint8_t filler3;
98 };
99
100 struct arp_key {
101         enum arp_key_type type;
102         union {
103                 struct arp_key_ipv4 ipv4;
104         } key;
105 };
106
107 struct lib_arp_route_table_entry {
108         uint32_t ip;
109         uint32_t mask;
110         uint32_t port;
111         uint32_t nh;
112 };
113
114 struct lib_nd_route_table_entry {
115         uint8_t ipv6[16];
116         uint8_t depth;
117         uint32_t port;
118         uint8_t nhipv6[16];
119 };
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];
122
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[]);
128
129 extern uint32_t ARPICMP_DEBUG;
130
131
132 /* ARP entry populated and echo reply recieved */
133 #define COMPLETE   1
134 /* ARP entry populated and either awaiting echo reply or stale entry */
135 #define INCOMPLETE 0
136
137 /* ND IPv6 */
138 extern uint32_t NDIPV6_DEBUG;
139
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
144
145 struct arp_entry_data {
146         struct ether_addr eth_addr;
147         uint8_t port;
148         uint8_t status;
149         uint32_t ip;
150 } __attribute__ ((__packed__));
151
152 /*ND IPv6*/
153 struct nd_entry_data {
154         struct ether_addr eth_addr;
155         uint8_t port;
156         uint8_t status;
157         uint8_t ipv6[ND_IPV6_ADDR_SIZE];
158 } __attribute__ ((__packed__));
159
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);
164
165 int get_dest_mac_address_ipv6(uint8_t ipv6addr[], uint32_t phy_port,
166                                                 struct ether_addr *hw_addr, uint8_t nhipv6[]);
167
168 void lib_arp_request_arp(
169         const uint32_t ipaddr,
170         const uint32_t phy_port,
171         struct rte_pipeline *rte_p);
172
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,
178                         uint8_t portid);
179 /*ND IPv6*/
180 int populate_nd_entry(const struct ether_addr *hw_addr, uint8_t ip[],
181                                         uint8_t portid);
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);
185
186 void process_arpicmp_pkt(struct rte_mbuf *pkt, uint32_t out_port,
187                          uint32_t pkt_num);
188
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);
191
192 struct nd_entry_data *retrieve_nd_entry(struct nd_key_ipv6 nd_key);
193
194 void lib_nd_init(/*struct pipeline_params *params, */ struct app_params *app);
195 void print_pkt1(struct rte_mbuf *pkt);
196
197 #endif
198
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];
205
206 #if 0
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];
212 #endif
213
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 */
217
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);
220
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);
226
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];
233
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);
240
241 /*
242  * Messages
243  */
244 enum pipeline_arpicmp_msg_req_type {
245         PIPELINE_ARPICMP_MSG_REQ_ENTRY_DBG,
246         PIPELINE_ARPICMP_MSG_REQS
247 };
248
249 /*
250  * MSG ENTRY DBG
251  */
252 struct pipeline_arpicmp_entry_dbg_msg_req {
253         enum pipeline_msg_req_type type;
254         enum pipeline_arpicmp_msg_req_type subtype;
255
256         /* data */
257         uint8_t data[2];
258 };
259
260 /*
261  * ARPICMP Entry
262  */
263
264 struct pipeline_arpicmp_in_port_h_arg {
265         struct pipeline_arpicmp *p;
266         uint8_t in_port_id;
267 };
268
269 struct pipeline_arpicmp_entry_dbg_msg_rsp {
270         int status;
271 };
272
273 #ifdef VNF_ACL
274
275  /* ICMPv6 Header */
276 struct icmpv6_hdr {
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__));
281
282  /**
283   * ICMPV6 Info Header
284   */
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__));
289
290  /**
291   * ICMPV6 ND Header
292   */
293 struct icmpv6_nd_hdr {
294          /*ND Advertisement flags */
295          uint32_t icmpv6_reserved;
296          /* bit31-Router, bit30-Solicited, bit29-Override, bit28-bit0 unused */
297
298          uint8_t target_ipv6[16];  /**< target IPv6 address */
299  /*ICMPv6 Option*/
300          uint8_t type;
301          uint8_t length;
302          struct ether_addr link_layer_address;
303 } __attribute__ ((__packed__));
304
305  /* Icmpv6 types */
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
312
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,
317          e_Link_Layer_Address
318 };
319
320 uint8_t is_multicast_ipv6_addr(uint8_t ipv6[]);
321 struct icmpv6_port_address {
322          uint32_t ipv6[16];
323          uint64_t mac_addr;
324 };
325
326 struct icmpv6_port_address icmpv6_port_addresses[RTE_MAX_ETHPORTS];
327
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);
334 void
335 process_icmpv6_pkt(struct rte_mbuf *pkt, uint32_t out_port, uint32_t pkt_num);
336
337 int get_dest_mac_addr_port(const uint32_t ipaddr,
338         uint32_t *phy_port, struct ether_addr *hw_addr);
339
340 int get_dest_mac_address_ipv6_port(uint8_t ipv6addr[], uint32_t *phy_port,
341         struct ether_addr *hw_addr, uint8_t nhipv6[]);
342 #endif
343 #endif