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
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2010-2016 Intel Corporation
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <sys/types.h>
#include <string.h>
#include <sys/queue.h>
#include <stdarg.h>
#include <errno.h>
#include <getopt.h>
#include <rte_common.h>
#include <rte_byteorder.h>
#include <rte_log.h>
#include <rte_memory.h>
#include <rte_memcpy.h>
#include <rte_eal.h>
#include <rte_per_lcore.h>
#include <rte_launch.h>
#include <rte_atomic.h>
#include <rte_cycles.h>
#include <rte_prefetch.h>
#include <rte_lcore.h>
#include <rte_branch_prediction.h>
#include <rte_interrupts.h>
#include <rte_pci.h>
#include <rte_random.h>
#include <rte_debug.h>
#include <rte_ether.h>
#include <rte_ethdev.h>
#include <rte_mempool.h>
#include <rte_mbuf.h>
#include <rte_ip.h>
#include <rte_tcp.h>
#include <rte_lpm.h>
#include <rte_lpm6.h>
#include <rte_string_fns.h>
#include "main.h"
struct app_params app;
static const char usage[] = "\n";
void
app_print_usage(void)
{
printf(usage);
}
static int
app_parse_port_mask(const char *arg)
{
char *end = NULL;
uint64_t port_mask;
uint32_t i;
if (arg[0] == '\0')
return -1;
port_mask = strtoul(arg, &end, 16);
if ((end == NULL) || (*end != '\0'))
return -2;
if (port_mask == 0)
return -3;
app.n_ports = 0;
for (i = 0; i < 64; i++) {
if ((port_mask & (1LLU << i)) == 0)
continue;
if (app.n_ports >= APP_MAX_PORTS)
return -4;
app.ports[app.n_ports] = i;
app.n_ports++;
}
if (!rte_is_power_of_2(app.n_ports))
return -5;
return 0;
}
struct {
const char *name;
uint32_t value;
} app_args_table[] = {
{"none", e_APP_PIPELINE_NONE},
{"stub", e_APP_PIPELINE_STUB},
{"hash-8-ext", e_APP_PIPELINE_HASH_KEY8_EXT},
{"hash-8-lru", e_APP_PIPELINE_HASH_KEY8_LRU},
{"hash-16-ext", e_APP_PIPELINE_HASH_KEY16_EXT},
{"hash-16-lru", e_APP_PIPELINE_HASH_KEY16_LRU},
{"hash-32-ext", e_APP_PIPELINE_HASH_KEY32_EXT},
{"hash-32-lru", e_APP_PIPELINE_HASH_KEY32_LRU},
{"hash-spec-8-ext", e_APP_PIPELINE_HASH_SPEC_KEY8_EXT},
{"hash-spec-8-lru", e_APP_PIPELINE_HASH_SPEC_KEY8_LRU},
{"hash-spec-16-ext", e_APP_PIPELINE_HASH_SPEC_KEY16_EXT},
{"hash-spec-16-lru", e_APP_PIPELINE_HASH_SPEC_KEY16_LRU},
{"hash-spec-32-ext", e_APP_PIPELINE_HASH_SPEC_KEY32_EXT},
{"hash-spec-32-lru", e_APP_PIPELINE_HASH_SPEC_KEY32_LRU},
{"acl", e_APP_PIPELINE_ACL},
{"lpm", e_APP_PIPELINE_LPM},
{"lpm-ipv6", e_APP_PIPELINE_LPM_IPV6},
{"hash-cuckoo-8", e_APP_PIPELINE_HASH_CUCKOO_KEY8},
{"hash-cuckoo-16", e_APP_PIPELINE_HASH_CUCKOO_KEY16},
{"hash-cuckoo-32", e_APP_PIPELINE_HASH_CUCKOO_KEY32},
{"hash-cuckoo-48", e_APP_PIPELINE_HASH_CUCKOO_KEY48},
{"hash-cuckoo-64", e_APP_PIPELINE_HASH_CUCKOO_KEY64},
{"hash-cuckoo-80", e_APP_PIPELINE_HASH_CUCKOO_KEY80},
{"hash-cuckoo-96", e_APP_PIPELINE_HASH_CUCKOO_KEY96},
{"hash-cuckoo-112", e_APP_PIPELINE_HASH_CUCKOO_KEY112},
{"hash-cuckoo-128", e_APP_PIPELINE_HASH_CUCKOO_KEY128},
};
int
app_parse_args(int argc, char **argv)
{
int opt, ret;
char **argvopt;
int option_index;
char *prgname = argv[0];
static struct option lgopts[] = {
{"none", 0, 0, 0},
{"stub", 0, 0, 0},
{"hash-8-ext", 0, 0, 0},
{"hash-8-lru", 0, 0, 0},
{"hash-16-ext", 0, 0, 0},
{"hash-16-lru", 0, 0, 0},
{"hash-32-ext", 0, 0, 0},
{"hash-32-lru", 0, 0, 0},
{"hash-spec-8-ext", 0, 0, 0},
{"hash-spec-8-lru", 0, 0, 0},
{"hash-spec-16-ext", 0, 0, 0},
{"hash-spec-16-lru", 0, 0, 0},
{"hash-spec-32-ext", 0, 0, 0},
{"hash-spec-32-lru", 0, 0, 0},
{"acl", 0, 0, 0},
{"lpm", 0, 0, 0},
{"lpm-ipv6", 0, 0, 0},
{"hash-cuckoo-8", 0, 0, 0},
{"hash-cuckoo-16", 0, 0, 0},
{"hash-cuckoo-32", 0, 0, 0},
{"hash-cuckoo-48", 0, 0, 0},
{"hash-cuckoo-64", 0, 0, 0},
{"hash-cuckoo-80", 0, 0, 0},
{"hash-cuckoo-96", 0, 0, 0},
{"hash-cuckoo-112", 0, 0, 0},
{"hash-cuckoo-128", 0, 0, 0},
{NULL, 0, 0, 0}
};
uint32_t lcores[3], n_lcores, lcore_id, pipeline_type_provided;
/* EAL args */
n_lcores = 0;
for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
if (rte_lcore_is_enabled(lcore_id) == 0)
continue;
if (n_lcores >= 3) {
RTE_LOG(ERR, USER1, "Number of cores must be 3\n");
app_print_usage();
return -1;
}
lcores[n_lcores] = lcore_id;
n_lcores++;
}
if (n_lcores != 3) {
RTE_LOG(ERR, USER1, "Number of cores must be 3\n");
app_print_usage();
return -1;
}
app.core_rx = lcores[0];
app.core_worker = lcores[1];
app.core_tx = lcores[2];
/* Non-EAL args */
argvopt = argv;
app.pipeline_type = e_APP_PIPELINE_HASH_KEY16_LRU;
pipeline_type_provided = 0;
while ((opt = getopt_long(argc, argvopt, "p:",
lgopts, &option_index)) != EOF) {
switch (opt) {
case 'p':
if (app_parse_port_mask(optarg) < 0) {
app_print_usage();
return -1;
}
break;
case 0: /* long options */
if (!pipeline_type_provided) {
uint32_t i;
for (i = 0; i < e_APP_PIPELINES; i++) {
if (!strcmp(lgopts[option_index].name,
app_args_table[i].name)) {
app.pipeline_type =
app_args_table[i].value;
pipeline_type_provided = 1;
break;
}
}
break;
}
app_print_usage();
return -1;
default:
return -1;
}
}
if (optind >= 0)
argv[optind - 1] = prgname;
ret = optind - 1;
optind = 1; /* reset getopt lib */
return ret;
}
|