1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
3 */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <stdint.h>
8 #include <inttypes.h>
9 #include <sys/types.h>
10 #include <string.h>
11 #include <sys/queue.h>
12 #include <stdarg.h>
13 #include <errno.h>
14 #include <getopt.h>
15
16 #include <rte_common.h>
17 #include <rte_byteorder.h>
18 #include <rte_log.h>
19 #include <rte_memory.h>
20 #include <rte_memcpy.h>
21 #include <rte_eal.h>
22 #include <rte_per_lcore.h>
23 #include <rte_launch.h>
24 #include <rte_atomic.h>
25 #include <rte_cycles.h>
26 #include <rte_prefetch.h>
27 #include <rte_lcore.h>
28 #include <rte_branch_prediction.h>
29 #include <rte_interrupts.h>
30 #include <rte_pci.h>
31 #include <rte_random.h>
32 #include <rte_debug.h>
33 #include <rte_ether.h>
34 #include <rte_ethdev.h>
35 #include <rte_mempool.h>
36 #include <rte_mbuf.h>
37 #include <rte_ip.h>
38 #include <rte_tcp.h>
39 #include <rte_lpm.h>
40 #include <rte_lpm6.h>
41 #include <rte_string_fns.h>
42
43 #include "main.h"
44
45 static const char usage[] = "\n";
46
47 void
app_print_usage(void)48 app_print_usage(void)
49 {
50 printf(usage);
51 }
52
53 static int
app_parse_port_mask(const char * arg)54 app_parse_port_mask(const char *arg)
55 {
56 char *end = NULL;
57 uint64_t port_mask;
58 uint32_t i;
59
60 if (arg[0] == '\0')
61 return -1;
62
63 port_mask = strtoul(arg, &end, 16);
64 if ((end == NULL) || (*end != '\0'))
65 return -2;
66
67 if (port_mask == 0)
68 return -3;
69
70 app.n_ports = 0;
71 for (i = 0; i < 64; i++) {
72 if ((port_mask & (1LLU << i)) == 0)
73 continue;
74
75 if (app.n_ports >= APP_MAX_PORTS)
76 return -4;
77
78 app.ports[app.n_ports] = i;
79 app.n_ports++;
80 }
81
82 if (!rte_is_power_of_2(app.n_ports))
83 return -5;
84
85 return 0;
86 }
87
88 struct {
89 const char *name;
90 uint32_t value;
91 } app_args_table[] = {
92 {"none", e_APP_PIPELINE_NONE},
93 {"stub", e_APP_PIPELINE_STUB},
94 {"hash-8-ext", e_APP_PIPELINE_HASH_KEY8_EXT},
95 {"hash-8-lru", e_APP_PIPELINE_HASH_KEY8_LRU},
96 {"hash-16-ext", e_APP_PIPELINE_HASH_KEY16_EXT},
97 {"hash-16-lru", e_APP_PIPELINE_HASH_KEY16_LRU},
98 {"hash-32-ext", e_APP_PIPELINE_HASH_KEY32_EXT},
99 {"hash-32-lru", e_APP_PIPELINE_HASH_KEY32_LRU},
100 {"hash-spec-8-ext", e_APP_PIPELINE_HASH_SPEC_KEY8_EXT},
101 {"hash-spec-8-lru", e_APP_PIPELINE_HASH_SPEC_KEY8_LRU},
102 {"hash-spec-16-ext", e_APP_PIPELINE_HASH_SPEC_KEY16_EXT},
103 {"hash-spec-16-lru", e_APP_PIPELINE_HASH_SPEC_KEY16_LRU},
104 {"hash-spec-32-ext", e_APP_PIPELINE_HASH_SPEC_KEY32_EXT},
105 {"hash-spec-32-lru", e_APP_PIPELINE_HASH_SPEC_KEY32_LRU},
106 {"acl", e_APP_PIPELINE_ACL},
107 {"lpm", e_APP_PIPELINE_LPM},
108 {"lpm-ipv6", e_APP_PIPELINE_LPM_IPV6},
109 {"hash-cuckoo-8", e_APP_PIPELINE_HASH_CUCKOO_KEY8},
110 {"hash-cuckoo-16", e_APP_PIPELINE_HASH_CUCKOO_KEY16},
111 {"hash-cuckoo-32", e_APP_PIPELINE_HASH_CUCKOO_KEY32},
112 {"hash-cuckoo-48", e_APP_PIPELINE_HASH_CUCKOO_KEY48},
113 {"hash-cuckoo-64", e_APP_PIPELINE_HASH_CUCKOO_KEY64},
114 {"hash-cuckoo-80", e_APP_PIPELINE_HASH_CUCKOO_KEY80},
115 {"hash-cuckoo-96", e_APP_PIPELINE_HASH_CUCKOO_KEY96},
116 {"hash-cuckoo-112", e_APP_PIPELINE_HASH_CUCKOO_KEY112},
117 {"hash-cuckoo-128", e_APP_PIPELINE_HASH_CUCKOO_KEY128},
118 };
119
120 int
app_parse_args(int argc,char ** argv)121 app_parse_args(int argc, char **argv)
122 {
123 int opt, ret;
124 char **argvopt;
125 int option_index;
126 char *prgname = argv[0];
127 static struct option lgopts[] = {
128 {"none", 0, 0, 0},
129 {"stub", 0, 0, 0},
130 {"hash-8-ext", 0, 0, 0},
131 {"hash-8-lru", 0, 0, 0},
132 {"hash-16-ext", 0, 0, 0},
133 {"hash-16-lru", 0, 0, 0},
134 {"hash-32-ext", 0, 0, 0},
135 {"hash-32-lru", 0, 0, 0},
136 {"hash-spec-8-ext", 0, 0, 0},
137 {"hash-spec-8-lru", 0, 0, 0},
138 {"hash-spec-16-ext", 0, 0, 0},
139 {"hash-spec-16-lru", 0, 0, 0},
140 {"hash-spec-32-ext", 0, 0, 0},
141 {"hash-spec-32-lru", 0, 0, 0},
142 {"acl", 0, 0, 0},
143 {"lpm", 0, 0, 0},
144 {"lpm-ipv6", 0, 0, 0},
145 {"hash-cuckoo-8", 0, 0, 0},
146 {"hash-cuckoo-16", 0, 0, 0},
147 {"hash-cuckoo-32", 0, 0, 0},
148 {"hash-cuckoo-48", 0, 0, 0},
149 {"hash-cuckoo-64", 0, 0, 0},
150 {"hash-cuckoo-80", 0, 0, 0},
151 {"hash-cuckoo-96", 0, 0, 0},
152 {"hash-cuckoo-112", 0, 0, 0},
153 {"hash-cuckoo-128", 0, 0, 0},
154 {NULL, 0, 0, 0}
155 };
156 uint32_t lcores[3], n_lcores, lcore_id, pipeline_type_provided;
157
158 /* EAL args */
159 n_lcores = 0;
160 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
161 if (rte_lcore_is_enabled(lcore_id) == 0)
162 continue;
163
164 if (n_lcores >= 3) {
165 RTE_LOG(ERR, USER1, "Number of cores must be 3\n");
166 app_print_usage();
167 return -1;
168 }
169
170 lcores[n_lcores] = lcore_id;
171 n_lcores++;
172 }
173
174 if (n_lcores != 3) {
175 RTE_LOG(ERR, USER1, "Number of cores must be 3\n");
176 app_print_usage();
177 return -1;
178 }
179
180 app.core_rx = lcores[0];
181 app.core_worker = lcores[1];
182 app.core_tx = lcores[2];
183
184 /* Non-EAL args */
185 argvopt = argv;
186
187 app.pipeline_type = e_APP_PIPELINE_HASH_KEY16_LRU;
188 pipeline_type_provided = 0;
189
190 while ((opt = getopt_long(argc, argvopt, "p:",
191 lgopts, &option_index)) != EOF) {
192 switch (opt) {
193 case 'p':
194 if (app_parse_port_mask(optarg) < 0) {
195 app_print_usage();
196 return -1;
197 }
198 break;
199
200 case 0: /* long options */
201 if (!pipeline_type_provided) {
202 uint32_t i;
203
204 for (i = 0; i < e_APP_PIPELINES; i++) {
205 if (!strcmp(lgopts[option_index].name,
206 app_args_table[i].name)) {
207 app.pipeline_type =
208 app_args_table[i].value;
209 pipeline_type_provided = 1;
210 break;
211 }
212 }
213
214 break;
215 }
216
217 app_print_usage();
218 return -1;
219
220 default:
221 return -1;
222 }
223 }
224
225 if (optind >= 0)
226 argv[optind - 1] = prgname;
227
228 ret = optind - 1;
229 optind = 1; /* reset getopt lib */
230 return ret;
231 }
232