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 #include <cmdline_parse.h>
18 #include <cmdline_parse_num.h>
19 #include <cmdline_parse_string.h>
20 #include <cmdline_parse_ipaddr.h>
21 #include <cmdline_parse_etheraddr.h>
24 #include "pipeline_common_fe.h"
25 #include "pipeline_loadb.h"
26 #include "vnf_common.h"
27 //#include "lib_arp.h"
28 #include "pipeline_arpicmp_be.h"
29 //#include "lib_arp.h"
30 //#include "interface.h"
32 app_pipeline_loadb_entry_dbg(struct app_params *app,
33 uint32_t pipeline_id, uint8_t *msg)
35 struct pipeline_loadb_entry_dbg_msg_req *req;
36 struct pipeline_loadb_entry_dbg_msg_rsp *rsp;
38 /* Check input arguments */
42 /* Allocate and write request */
43 req = app_msg_alloc(app);
47 req->type = PIPELINE_MSG_REQ_CUSTOM;
48 req->subtype = PIPELINE_LOADB_MSG_REQ_ENTRY_DBG;
49 req->data[0] = msg[0];
50 req->data[1] = msg[1];
52 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
58 app_msg_free(app, rsp);
59 printf("Error rsp->status %d\n", rsp->status);
64 app_msg_free(app, rsp);
73 struct cmd_entry_dbg_result {
74 cmdline_fixed_string_t p_string;
76 cmdline_fixed_string_t entry_string;
77 cmdline_fixed_string_t dbg_string;
83 cmd_entry_dbg_parsed(void *parsed_result,
84 __rte_unused struct cmdline *cl, void *data)
86 struct cmd_entry_dbg_result *params = parsed_result;
87 struct app_params *app = data;
93 status = app_pipeline_loadb_entry_dbg(app, params->p, msg);
96 printf("Dbg Command failed\n");
101 static cmdline_parse_token_string_t lb_cmd_entry_dbg_p_string =
102 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, p_string, "p");
104 static cmdline_parse_token_num_t lb_cmd_entry_dbg_p =
105 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, p, UINT32);
107 static cmdline_parse_token_string_t lb_cmd_entry_dbg_entry_string =
108 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result,
109 entry_string, "lbentry");
111 static cmdline_parse_token_string_t lb_cmd_entry_dbg_dbg_string =
112 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, dbg_string,
115 static cmdline_parse_token_num_t lb_cmd_entry_dbg_cmd =
116 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, cmd, UINT8);
118 static cmdline_parse_token_num_t lb_cmd_entry_dbg_d1 =
119 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, d1, UINT8);
121 static cmdline_parse_inst_t lb_cmd_entry_dbg = {
122 .f = cmd_entry_dbg_parsed,
124 .help_str = "LOADB dbg cmd",
126 (void *)&lb_cmd_entry_dbg_p_string,
127 (void *)&lb_cmd_entry_dbg_p,
128 (void *)&lb_cmd_entry_dbg_entry_string,
129 (void *)&lb_cmd_entry_dbg_dbg_string,
130 (void *)&lb_cmd_entry_dbg_cmd,
131 (void *)&lb_cmd_entry_dbg_d1,
137 /*print_arp_entry(const struct app_pipeline_arp_icmp_arp_entry *entry)*/
139 /* printf("(Port = %" PRIu32 ", IP = %" PRIu32 ".%" PRIu32*/
140 /* ".%" PRIu32 ".%" PRIu32 ") => "*/
141 /* "HWaddress = %02" PRIx32 ":%02" PRIx32 ":%02" PRIx32*/
142 /* ":%02" PRIx32 ":%02" PRIx32 ":%02" PRIx32 "\n",*/
143 /* entry->key.key.ipv4.port_id,*/
144 /* (entry->key.key.ipv4.ip >> 24) & 0xFF,*/
145 /* (entry->key.key.ipv4.ip >> 16) & 0xFF,*/
146 /* (entry->key.key.ipv4.ip >> 8) & 0xFF,*/
147 /* entry->key.key.ipv4.ip & 0xFF,*/
149 /* entry->macaddr.addr_bytes[0],*/
150 /* entry->macaddr.addr_bytes[1],*/
151 /* entry->macaddr.addr_bytes[2],*/
152 /* entry->macaddr.addr_bytes[3],*/
153 /* entry->macaddr.addr_bytes[4],*/
154 /* entry->macaddr.addr_bytes[5]);*/
162 struct cmd_arp_add_result {
163 cmdline_fixed_string_t p_string;
165 cmdline_fixed_string_t arpadd_string;
168 struct ether_addr macaddr;
173 cmd_arp_add_parsed(void *parsed_result,
174 __rte_unused struct cmdline *cl, __rte_unused void *data)
176 struct cmd_arp_add_result *params = parsed_result;
179 /* struct pipeline_arp_icmp_arp_key key;*/
180 /* key.type = PIPELINE_ARP_ICMP_ARP_IPV4;*/
181 /* key.key.ipv4.port_id = params->port_id;*/
182 /* key.key.ipv4.ip = rte_cpu_to_be_32(params->ip.addr.ipv4.s_addr);*/
183 /* populate_arp_entry(&req->macaddr, rte_bswap32(req->key.key.ipv4.ip),
184 * req->key.key.ipv4.port_id);
186 if (params->ip.family == AF_INET) {
187 populate_arp_entry(¶ms->macaddr,
188 rte_cpu_to_be_32(params->ip.addr.
190 params->port_id, STATIC_ARP);
192 memcpy(ipv6, params->ip.addr.ipv6.s6_addr, 16);
193 populate_nd_entry(¶ms->macaddr, ipv6, params->port_id, STATIC_ND);
197 static cmdline_parse_token_string_t cmd_arp_add_p_string =
198 TOKEN_STRING_INITIALIZER(struct cmd_arp_add_result, p_string,
201 static cmdline_parse_token_num_t cmd_arp_add_p =
202 TOKEN_NUM_INITIALIZER(struct cmd_arp_add_result, p, UINT32);
204 static cmdline_parse_token_string_t cmd_arp_add_arp_string =
205 TOKEN_STRING_INITIALIZER(struct cmd_arp_add_result, arpadd_string, "arpadd");
207 static cmdline_parse_token_num_t cmd_arp_add_port_id =
208 TOKEN_NUM_INITIALIZER(struct cmd_arp_add_result, port_id, UINT32);
210 static cmdline_parse_token_ipaddr_t cmd_arp_add_ip =
211 TOKEN_IPADDR_INITIALIZER(struct cmd_arp_add_result, ip);
213 static cmdline_parse_token_etheraddr_t cmd_arp_add_macaddr =
214 TOKEN_ETHERADDR_INITIALIZER(struct cmd_arp_add_result, macaddr);
216 static cmdline_parse_inst_t cmd_arp_add = {
217 .f = cmd_arp_add_parsed,
219 .help_str = "ARP add",
221 (void *)&cmd_arp_add_p_string,
222 (void *)&cmd_arp_add_p,
223 (void *)&cmd_arp_add_arp_string,
224 (void *)&cmd_arp_add_port_id,
225 (void *)&cmd_arp_add_ip,
226 (void *)&cmd_arp_add_macaddr,
235 struct cmd_arp_del_result {
236 cmdline_fixed_string_t p_string;
238 cmdline_fixed_string_t arp_string;
244 cmd_arp_del_parsed(void *parsed_result,
245 __rte_unused struct cmdline *cl, __rte_unused void *data)
247 struct cmd_arp_del_result *params = parsed_result;
250 /* struct pipeline_arp_icmp_arp_key key;*/
251 /* key.type = PIPELINE_ARP_ICMP_ARP_IPV4;*/
252 /* key.key.ipv4.ip = rte_cpu_to_be_32(params->ip.addr.ipv4.s_addr);*/
253 /* key.key.ipv4.port_id = params->port_id;*/
254 /* remove_arp_entry(rte_bswap32(req->key.key.ipv4.ip),
255 * req->key.key.ipv4.port_id);
257 if (params->ip.family == AF_INET) {
258 remove_arp_entry(rte_cpu_to_be_32(params->ip.addr.ipv4.s_addr),
259 params->port_id, NULL);
261 memcpy(ipv6, params->ip.addr.ipv6.s6_addr, 16);
262 remove_nd_entry_ipv6(ipv6, params->port_id);
266 static cmdline_parse_token_string_t cmd_arp_del_p_string =
267 TOKEN_STRING_INITIALIZER(struct cmd_arp_del_result, p_string,
270 static cmdline_parse_token_num_t cmd_arp_del_p =
271 TOKEN_NUM_INITIALIZER(struct cmd_arp_del_result, p, UINT32);
273 static cmdline_parse_token_string_t cmd_arp_del_arp_string =
274 TOKEN_STRING_INITIALIZER(struct cmd_arp_del_result, arp_string, "arpdel");
276 static cmdline_parse_token_num_t cmd_arp_del_port_id =
277 TOKEN_NUM_INITIALIZER(struct cmd_arp_del_result, port_id, UINT32);
279 static cmdline_parse_token_ipaddr_t cmd_arp_del_ip =
280 TOKEN_IPADDR_INITIALIZER(struct cmd_arp_del_result, ip);
282 static cmdline_parse_inst_t cmd_arp_del = {
283 .f = cmd_arp_del_parsed,
285 .help_str = "ARP delete",
287 (void *)&cmd_arp_del_p_string,
288 (void *)&cmd_arp_del_p,
289 (void *)&cmd_arp_del_arp_string,
290 (void *)&cmd_arp_del_port_id,
291 (void *)&cmd_arp_del_ip,
300 /*Re-uses delete structures*/
303 cmd_arp_req_parsed(void *parsed_result,
304 __rte_unused struct cmdline *cl, __rte_unused void *data)
306 struct cmd_arp_del_result *params = parsed_result;
307 /*struct app_params *app = data;*/
309 struct arp_key_ipv4 key;
312 /* key.type = ARP_IPV4;*/
313 /* key.key.ipv4.ip = rte_cpu_to_be_32(params->ip.addr.ipv4.s_addr);*/
314 /* key.key.ipv4.port_id = params->port_id;*/
315 key.ip = rte_cpu_to_be_32(params->ip.addr.ipv4.s_addr);
316 key.port_id = params->port_id;
321 struct arp_entry_data *arp_data = retrieve_arp_entry(key, STATIC_ARP);
325 printf("ARP entry exists for ip 0x%x, port %d\n",
326 params->ip.addr.ipv4.s_addr, params->port_id);
329 /* else request an arp*/
331 printf("ARP - requesting arp for ip 0x%x, port %d\n",
332 params->ip.addr.ipv4.s_addr, params->port_id);
333 request_arp(params->port_id, params->ip.addr.ipv4.s_addr);
334 /*give pipeline number too*/
337 static cmdline_parse_token_string_t cmd_arp_req_string =
338 TOKEN_STRING_INITIALIZER(struct cmd_arp_del_result, arp_string, "arpreq");
340 static cmdline_parse_inst_t cmd_arp_req = {
341 .f = cmd_arp_req_parsed,
343 .help_str = "ARP request",
345 (void *)&cmd_arp_del_p_string,
346 (void *)&cmd_arp_del_p,
347 (void *)&cmd_arp_req_string,
348 (void *)&cmd_arp_del_port_id,
349 (void *)&cmd_arp_del_ip,
358 /*Re-uses delete structures*/
361 cmd_icmp_echo_req_parsed(void *parsed_result,
362 __rte_unused struct cmdline *cl,
363 __rte_unused void *data)
365 struct cmd_arp_del_result *params = parsed_result;
366 struct rte_mbuf *pkt;
367 l2_phy_interface_t *port = (l2_phy_interface_t *) ifm_get_port((uint8_t)params->port_id);
370 printf("Echo Req Handler ip %x, port %d\n",
371 params->ip.addr.ipv4.s_addr, params->port_id);
373 pkt = request_echo(params->port_id, params->ip.addr.ipv4.s_addr);
374 port->transmit_single_pkt(port, pkt);
377 static cmdline_parse_token_string_t cmd_icmp_echo_req_string =
378 TOKEN_STRING_INITIALIZER(struct cmd_arp_del_result, arp_string, "icmpecho");
380 static cmdline_parse_inst_t cmd_icmp_echo_req = {
381 .f = cmd_icmp_echo_req_parsed,
383 .help_str = "ICMP echo request",
385 (void *)&cmd_arp_del_p_string,
386 (void *)&cmd_arp_del_p,
387 (void *)&cmd_icmp_echo_req_string,
388 (void *)&cmd_arp_del_port_id,
389 (void *)&cmd_arp_del_ip,
398 struct cmd_arp_ls_result {
399 cmdline_fixed_string_t p_string;
401 cmdline_fixed_string_t arp_string;
406 cmd_arp_ls_parsed(void *parsed_result,
407 __rte_unused struct cmdline *cl, __rte_unused void *data)
409 struct cmd_arp_ls_result *params = parsed_result;
411 if (!params->ip_type) {
412 printf("\nARP table ...\n");
413 printf("-------------\n");
416 printf("\nND IPv6 table:\n");
417 printf("--------------\n");
422 static cmdline_parse_token_string_t cmd_arp_ls_p_string =
423 TOKEN_STRING_INITIALIZER(struct cmd_arp_ls_result, p_string,
426 static cmdline_parse_token_num_t cmd_arp_ls_p =
427 TOKEN_NUM_INITIALIZER(struct cmd_arp_ls_result, p, UINT32);
429 static cmdline_parse_token_string_t cmd_arp_ls_arp_string =
430 TOKEN_STRING_INITIALIZER(struct cmd_arp_ls_result, arp_string,
433 static cmdline_parse_token_num_t cmd_arp_ls_ip_type =
434 TOKEN_NUM_INITIALIZER(struct cmd_arp_ls_result, ip_type, UINT32);
436 static cmdline_parse_inst_t cmd_arp_ls = {
437 .f = cmd_arp_ls_parsed,
439 .help_str = "ARP list",
441 (void *)&cmd_arp_ls_p_string,
442 (void *)&cmd_arp_ls_p,
443 (void *)&cmd_arp_ls_arp_string,
444 (void *)&cmd_arp_ls_ip_type,
453 struct cmd_show_ports_info_result {
454 cmdline_fixed_string_t p_string;
456 cmdline_fixed_string_t arp_string;
460 cmd_show_ports_info_parsed(__rte_unused void *parsed_result,
461 __rte_unused struct cmdline *cl,
462 __rte_unused void *data)
467 static cmdline_parse_token_string_t cmd_show_ports_info_string =
468 TOKEN_STRING_INITIALIZER(struct cmd_arp_ls_result, arp_string,
471 static cmdline_parse_inst_t cmd_show_ports_info = {
472 .f = cmd_show_ports_info_parsed,
474 .help_str = "show ports info",
476 (void *)&cmd_arp_ls_p_string,
477 (void *)&cmd_arp_ls_p,
478 (void *)&cmd_show_ports_info_string,
484 static cmdline_parse_ctx_t pipeline_cmds[] = {
485 (cmdline_parse_inst_t *) &lb_cmd_entry_dbg,
489 static struct pipeline_fe_ops pipeline_loadb_fe_ops = {
492 .cmds = pipeline_cmds,
495 struct pipeline_type pipeline_loadb = {
497 .be_ops = &pipeline_loadb_be_ops,
498 .fe_ops = &pipeline_loadb_fe_ops,