summaryrefslogtreecommitdiffstats
path: root/common/VIL/pipeline_arpicmp/pipeline_arpicmp_be.h
blob: 2c7fce2e660face7acc43e8b2c710cb42a03aff2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
// Copyright (c) 2017 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/

#ifndef __INCLUDE_PIPELINE_ARPICMP_BE_H__
#define __INCLUDE_PIPELINE_ARPICMP_BE_H__

#include "pipeline_common_be.h"
#define PIPELINE_ARPICMP_KEY_PORT_IN_AH(f_ah, f_pkt_work, f_pkt4_work)  \
static int                                                              \
f_ah(                                                                   \
	__rte_unused struct rte_pipeline *rte_p,                        \
	struct rte_mbuf **pkts,                                         \
	uint32_t n_pkts,                                                \
	void *arg)                                                      \
{                                                                       \
	uint32_t i, j;                                                  \
									\
	for (j = 0; j < n_pkts; j++)                                    \
		rte_prefetch0(pkts[j]);                                 \
									\
	for (i = 0; i < (n_pkts & (~0x3LLU)); i += 4)                   \
		f_pkt4_work(&pkts[i], i, arg);                          \
									\
	for ( ; i < n_pkts; i++)                                        \
		f_pkt_work(pkts[i], i, arg);                            \
									\
									\
	return 0;                                                       \
}

extern struct app_params *myApp;
void print_pkt1(struct rte_mbuf *pkt);
struct ether_addr *get_link_hw_addr(uint8_t out_port);
#ifdef VNF_ACL

#include <rte_pipeline.h>
#include "rte_ether.h"
#include "app.h"

#if (RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN)
// x86 == little endian
// network  == big endian
#define CHECK_ENDIAN_16(x) rte_be_to_cpu_16(x)
#define CHECK_ENDIAN_32(x) rte_be_to_cpu_32(x)
#else
#define CHECK_ENDIAN_16(x) (x)
#define CHECK_ENDIAN_32(x) (x)
#endif


#define MAX_ARP_RT_ENTRY 16
#define MAX_ND_RT_ENTRY 16

#define ND_IPV6_ADDR_SIZE 16	/* 16 Byte of IPv6 Address */

enum {
ARP_FOUND,
ARP_NOT_FOUND,
NH_NOT_FOUND,
};

enum arp_key_type {
	ARP_IPV4,
	/* ND IPv6 */
	ND_IPV6,
};

struct arp_key_ipv4 {
	uint32_t ip;
	uint8_t port_id;
	uint8_t filler1;
	uint8_t filler2;
	uint8_t filler3;
};

/* ND IPv6 */
struct nd_key_ipv6 {
	/*128 Bit of IPv6 Address */
	/*<48bit Network> <16bit Subnet> <64bit Interface> */
	uint8_t ipv6[ND_IPV6_ADDR_SIZE];
	uint8_t port_id;
	uint8_t filler1;
	uint8_t filler2;
	uint8_t filler3;
};

struct arp_key {
	enum arp_key_type type;
	union {
		struct arp_key_ipv4 ipv4;
	} key;
};

struct lib_arp_route_table_entry {
	uint32_t ip;
	uint32_t mask;
	uint32_t port;
	uint32_t nh;
};

struct lib_nd_route_table_entry {
	uint8_t ipv6[16];
	uint8_t depth;
	uint32_t port;
	uint8_t nhipv6[16];
};
extern struct lib_arp_route_table_entry lib_arp_route_table[MAX_ARP_RT_ENTRY];
extern struct lib_nd_route_table_entry  lib_nd_route_table[MAX_ND_RT_ENTRY];

extern uint8_t prv_in_port_a[PIPELINE_MAX_PORT_IN];
extern void convert_prefixlen_to_netmask_ipv6(uint32_t depth,
								uint8_t netmask_ipv6[]);
uint32_t get_nh(uint32_t, uint32_t*);
void get_nh_ipv6(uint8_t ipv6[], uint32_t *port, uint8_t nhipv6[]);

extern uint32_t ARPICMP_DEBUG;


/* ARP entry populated and echo reply recieved */
#define COMPLETE   1
/* ARP entry populated and either awaiting echo reply or stale entry */
#define INCOMPLETE 0

/* ND IPv6 */
extern uint32_t NDIPV6_DEBUG;

/* ICMPv6 entry populated and echo reply recieved */
#define ICMPv6_COMPLETE   1
/* ICMPv6 entry populated and either awaiting echo reply or stale entry */
#define ICMPv6_INCOMPLETE 0

struct arp_entry_data {
	struct ether_addr eth_addr;
	uint8_t port;
	uint8_t status;
	uint32_t ip;
} __attribute__ ((__packed__));

/*ND IPv6*/
struct nd_entry_data {
	struct ether_addr eth_addr;
	uint8_t port;
	uint8_t status;
	uint8_t ipv6[ND_IPV6_ADDR_SIZE];
} __attribute__ ((__packed__));

int get_dest_mac_address(const uint32_t ipaddr, const uint32_t phy_port,
			 struct ether_addr *hw_addr, uint32_t *nhip);
int get_dest_mac_addr(const uint32_t ipaddr, const uint32_t phy_port,
					struct ether_addr *hw_addr);

int get_dest_mac_address_ipv6(uint8_t ipv6addr[], uint32_t phy_port,
						struct ether_addr *hw_addr, uint8_t nhipv6[]);

void lib_arp_request_arp(
	const uint32_t ipaddr,
	const uint32_t phy_port,
	struct rte_pipeline *rte_p);

void print_arp_table(void);
void print_nd_table(void);
void remove_arp_entry(uint32_t ipaddr, uint8_t portid);
void remove_nd_entry_ipv6(uint8_t ipv6addr[], uint8_t portid);
void populate_arp_entry(const struct ether_addr *hw_addr, uint32_t ipaddr,
			uint8_t portid);
/*ND IPv6*/
int populate_nd_entry(const struct ether_addr *hw_addr, uint8_t ip[],
					uint8_t portid);
void request_arp(uint8_t port_id, uint32_t ip, struct rte_pipeline *rte_p);
void request_arp_wrap(uint8_t port_id, uint32_t ip);
void request_echo(unsigned int port_id, uint32_t ip);

void process_arpicmp_pkt(struct rte_mbuf *pkt, uint32_t out_port,
			 uint32_t pkt_num);

struct arp_entry_data *retrieve_arp_entry(const struct arp_key_ipv4 arp_key);
struct nd_entry_data *retrieve_nd_entry(struct nd_key_ipv6 nd_key);

struct nd_entry_data *retrieve_nd_entry(struct nd_key_ipv6 nd_key);

void lib_nd_init(/*struct pipeline_params *params, */ struct app_params *app);
void print_pkt1(struct rte_mbuf *pkt);

#endif

uint8_t lb_outport_id[PIPELINE_MAX_PORT_IN];
struct pipeline *loadb_pipeline[PIPELINE_MAX_PORT_IN];
struct pipeline *all_pipeline[PIPELINE_MAX_PORT_IN];
uint8_t vnf_to_loadb_map[PIPELINE_MAX_PORT_IN];
uint8_t port_to_loadb_map[PIPELINE_MAX_PORT_IN];
uint8_t loadb_pipeline_nums[PIPELINE_MAX_PORT_IN];

#if 0
uint8_t lb_outport_id[PIPELINE_MAX_PORT_IN];
struct pipeline *arp_pipeline[PIPELINE_MAX_PORT_IN];
uint8_t vnf_to_arp_map[PIPELINE_MAX_PORT_IN];
uint8_t port_to_arp_map[PIPELINE_MAX_PORT_IN];
uint8_t arp_pipeline_nums[PIPELINE_MAX_PORT_IN];
#endif

void set_port_to_loadb_map(uint8_t pipeline_num);
uint8_t get_port_to_loadb_map(uint8_t phy_port_id);
/* acts on port_to_loadb_map */

void set_phy_inport_map(uint8_t pipeline_num, uint8_t *map);
void set_phy_outport_map(uint8_t pipeline_num, uint8_t *map);

void set_outport_id(uint8_t pipeline_num, struct pipeline *p, uint8_t *map);
/* acts on lb_outport_id */
uint8_t get_loadb_outport_id(uint8_t actual_phy_port);
/* acts on lb_outport_id */
uint8_t get_vnf_set_num(uint8_t pipeline_num);

void pipelines_port_info(void);
void pipelines_map_info(void);
void register_loadb_to_arp(uint8_t pipeline_num, struct pipeline *p,
				 __rte_unused struct app_params *app);
/* vnf_to_loadb_map[]  and loadb_pipelines[] */
uint8_t SWQ_to_Port_map[128];

extern struct pipeline_be_ops pipeline_arpicmp_be_ops;
void register_pipeline_Qs(uint8_t pipeline_num, struct pipeline *p);
void set_link_map(uint8_t pipeline_num, struct pipeline *p, uint8_t *map);
void set_outport_id(uint8_t pipeline_num, struct pipeline *p, uint8_t *map);
void set_phy_outport_id(uint8_t pipeline_num, struct pipeline *p, uint8_t *map);
void set_phy_inport_id(uint8_t pipeline_num, struct pipeline *p, uint8_t *map);

/*
 * Messages
 */
enum pipeline_arpicmp_msg_req_type {
	PIPELINE_ARPICMP_MSG_REQ_ENTRY_DBG,
	PIPELINE_ARPICMP_MSG_REQS
};

/*
 * MSG ENTRY DBG
 */
struct pipeline_arpicmp_entry_dbg_msg_req {
	enum pipeline_msg_req_type type;
	enum pipeline_arpicmp_msg_req_type subtype;

	/* data */
	uint8_t data[2];
};

/*
 * ARPICMP Entry
 */

struct pipeline_arpicmp_in_port_h_arg {
	struct pipeline_arpicmp *p;
	uint8_t in_port_id;
};

struct pipeline_arpicmp_entry_dbg_msg_rsp {
	int status;
};

#ifdef VNF_ACL

 /* ICMPv6 Header */
struct icmpv6_hdr {
	 uint8_t icmpv6_type;    /* ICMPV6 packet type. */
	 uint8_t icmpv6_code;    /* ICMPV6 packet code. */
	 uint16_t icmpv6_cksum;  /* ICMPV6 packet checksum. */
} __attribute__ ((__packed__));

 /**
  * ICMPV6 Info Header
  */
struct icmpv6_info_hdr {
	 uint16_t icmpv6_ident;  /* ICMPV6 packet identifier. */
	 uint16_t icmpv6_seq_nb; /* ICMPV6 packet sequence number. */
} __attribute__ ((__packed__));

 /**
  * ICMPV6 ND Header
  */
struct icmpv6_nd_hdr {
	 /*ND Advertisement flags */
	 uint32_t icmpv6_reserved;
	 /* bit31-Router, bit30-Solicited, bit29-Override, bit28-bit0 unused */

	 uint8_t target_ipv6[16];  /**< target IPv6 address */
 /*ICMPv6 Option*/
	 uint8_t type;
	 uint8_t length;
	 struct ether_addr link_layer_address;
} __attribute__ ((__packed__));

 /* Icmpv6 types */
 #define ICMPV6_PROTOCOL_ID 58
 #define ICMPV6_ECHO_REQUEST 0x0080
 #define ICMPV6_ECHO_REPLY 0x0081
 #define ICMPV6_NEIGHBOR_SOLICITATION 0x0087
  #define ICMPV6_NEIGHBOR_ADVERTISEMENT 0x0088
 #define IPV6_MULTICAST 0xFF02

 #define NEIGHBOR_SOLICITATION_SET 0x40000000
enum icmpv6_link_layer_Address_type {
	 e_Source_Link_Layer_Address = 1,
	 e_Target_Link_Layer_Address,
	 e_Link_Layer_Address
};

uint8_t is_multicast_ipv6_addr(uint8_t ipv6[]);
struct icmpv6_port_address {
	 uint32_t ipv6[16];
	 uint64_t mac_addr;
};

struct icmpv6_port_address icmpv6_port_addresses[RTE_MAX_ETHPORTS];

 #define MAX_NUM_ICMPv6_ENTRIES 64
 //struct rte_pipeline *myicmpP;
struct rte_mbuf *lib_icmpv6_pkt;
void request_icmpv6_echo(uint32_t port_id, uint8_t ipv6[]);
void request_icmpv6_echo_message(uint16_t port_id, uint8_t ipv6[],
					 struct ether_addr *gw_addr);
void
process_icmpv6_pkt(struct rte_mbuf *pkt, uint32_t out_port, uint32_t pkt_num);

int get_dest_mac_addr_port(const uint32_t ipaddr,
	uint32_t *phy_port, struct ether_addr *hw_addr);

int get_dest_mac_address_ipv6_port(uint8_t ipv6addr[], uint32_t *phy_port,
	struct ether_addr *hw_addr, uint8_t nhipv6[]);
#endif
#endif