1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2015 Intel Corporation
7 #include <sys/socket.h>
21 #include <rte_common.h>
23 #include <rte_memory.h>
24 #include <rte_memcpy.h>
26 #include <rte_launch.h>
27 #include <rte_atomic.h>
28 #include <rte_cycles.h>
29 #include <rte_prefetch.h>
30 #include <rte_lcore.h>
31 #include <rte_per_lcore.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_interrupts.h>
34 #include <rte_random.h>
35 #include <rte_debug.h>
36 #include <rte_ether.h>
37 #include <rte_ethdev.h>
38 #include <rte_mempool.h>
43 #include <rte_spinlock.h>
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
56 #include <rte_devargs.h>
59 #include "rte_byteorder.h"
60 #include "rte_cpuflags.h"
61 #include "rte_eth_bond.h"
63 #define RTE_LOGTYPE_DCB RTE_LOGTYPE_USER1
65 #define NB_MBUF (1024*8)
67 #define MAX_PKT_BURST 32
68 #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */
69 #define BURST_RX_INTERVAL_NS (10) /* RX poll interval ~100ns */
72 * RX and TX Prefetch, Host, and Write-back threshold values should be
73 * carefully set for optimal performance. Consult the network
74 * controller's datasheet and supporting DPDK documentation for guidance
75 * on how these parameters should be set.
77 #define RX_PTHRESH 8 /**< Default values of RX prefetch threshold reg. */
78 #define RX_HTHRESH 8 /**< Default values of RX host threshold reg. */
79 #define RX_WTHRESH 4 /**< Default values of RX write-back threshold reg. */
80 #define RX_FTHRESH (MAX_PKT_BURST * 2)/**< Default values of RX free threshold reg. */
83 * These default values are optimized for use with the Intel(R) 82599 10 GbE
84 * Controller and the DPDK ixgbe PMD. Consider using other values for other
85 * network controllers and/or network drivers.
87 #define TX_PTHRESH 36 /**< Default values of TX prefetch threshold reg. */
88 #define TX_HTHRESH 0 /**< Default values of TX host threshold reg. */
89 #define TX_WTHRESH 0 /**< Default values of TX write-back threshold reg. */
92 * Configurable number of RX/TX ring descriptors
94 #define RTE_RX_DESC_DEFAULT 1024
95 #define RTE_TX_DESC_DEFAULT 1024
102 /* not defined under linux */
104 #define NIPQUAD_FMT "%u.%u.%u.%u"
108 #define PRINT_MAC(addr) printf("%02"PRIx8":%02"PRIx8":%02"PRIx8 \
109 ":%02"PRIx8":%02"PRIx8":%02"PRIx8, \
110 addr.addr_bytes[0], addr.addr_bytes[1], addr.addr_bytes[2], \
111 addr.addr_bytes[3], addr.addr_bytes[4], addr.addr_bytes[5])
113 uint16_t slaves[RTE_MAX_ETHPORTS];
114 uint16_t slaves_count;
116 static uint16_t BOND_PORT = 0xffff;
118 static struct rte_mempool *mbuf_pool;
120 static struct rte_eth_conf port_conf = {
122 .mq_mode = ETH_MQ_RX_NONE,
123 .max_rx_pkt_len = ETHER_MAX_LEN,
125 .offloads = DEV_RX_OFFLOAD_CRC_STRIP,
130 .rss_hf = ETH_RSS_IP,
134 .mq_mode = ETH_MQ_TX_NONE,
139 slave_port_init(uint16_t portid, struct rte_mempool *mbuf_pool)
142 uint16_t nb_rxd = RTE_RX_DESC_DEFAULT;
143 uint16_t nb_txd = RTE_TX_DESC_DEFAULT;
144 struct rte_eth_dev_info dev_info;
145 struct rte_eth_rxconf rxq_conf;
146 struct rte_eth_txconf txq_conf;
147 struct rte_eth_conf local_port_conf = port_conf;
149 if (!rte_eth_dev_is_valid_port(portid))
150 rte_exit(EXIT_FAILURE, "Invalid port\n");
152 rte_eth_dev_info_get(portid, &dev_info);
153 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
154 local_port_conf.txmode.offloads |=
155 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
157 local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
158 dev_info.flow_type_rss_offloads;
159 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
160 port_conf.rx_adv_conf.rss_conf.rss_hf) {
161 printf("Port %u modified RSS hash function based on hardware support,"
162 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
164 port_conf.rx_adv_conf.rss_conf.rss_hf,
165 local_port_conf.rx_adv_conf.rss_conf.rss_hf);
168 retval = rte_eth_dev_configure(portid, 1, 1, &local_port_conf);
170 rte_exit(EXIT_FAILURE, "port %u: configuration failed (res=%d)\n",
173 retval = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd, &nb_txd);
175 rte_exit(EXIT_FAILURE, "port %u: rte_eth_dev_adjust_nb_rx_tx_desc "
176 "failed (res=%d)\n", portid, retval);
179 rxq_conf = dev_info.default_rxconf;
180 rxq_conf.offloads = local_port_conf.rxmode.offloads;
181 retval = rte_eth_rx_queue_setup(portid, 0, nb_rxd,
182 rte_eth_dev_socket_id(portid),
186 rte_exit(retval, " port %u: RX queue 0 setup failed (res=%d)",
190 txq_conf = dev_info.default_txconf;
191 txq_conf.offloads = local_port_conf.txmode.offloads;
192 retval = rte_eth_tx_queue_setup(portid, 0, nb_txd,
193 rte_eth_dev_socket_id(portid), &txq_conf);
196 rte_exit(retval, "port %u: TX queue 0 setup failed (res=%d)",
199 retval = rte_eth_dev_start(portid);
202 "Start port %d failed (res=%d)",
205 struct ether_addr addr;
207 rte_eth_macaddr_get(portid, &addr);
208 printf("Port %u MAC: ", portid);
214 bond_port_init(struct rte_mempool *mbuf_pool)
218 uint16_t nb_rxd = RTE_RX_DESC_DEFAULT;
219 uint16_t nb_txd = RTE_TX_DESC_DEFAULT;
220 struct rte_eth_dev_info dev_info;
221 struct rte_eth_rxconf rxq_conf;
222 struct rte_eth_txconf txq_conf;
223 struct rte_eth_conf local_port_conf = port_conf;
225 retval = rte_eth_bond_create("net_bonding0", BONDING_MODE_ALB,
226 0 /*SOCKET_ID_ANY*/);
228 rte_exit(EXIT_FAILURE,
229 "Faled to create bond port\n");
233 rte_eth_dev_info_get(BOND_PORT, &dev_info);
234 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
235 local_port_conf.txmode.offloads |=
236 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
237 retval = rte_eth_dev_configure(BOND_PORT, 1, 1, &local_port_conf);
239 rte_exit(EXIT_FAILURE, "port %u: configuration failed (res=%d)\n",
242 retval = rte_eth_dev_adjust_nb_rx_tx_desc(BOND_PORT, &nb_rxd, &nb_txd);
244 rte_exit(EXIT_FAILURE, "port %u: rte_eth_dev_adjust_nb_rx_tx_desc "
245 "failed (res=%d)\n", BOND_PORT, retval);
248 rxq_conf = dev_info.default_rxconf;
249 rxq_conf.offloads = local_port_conf.rxmode.offloads;
250 retval = rte_eth_rx_queue_setup(BOND_PORT, 0, nb_rxd,
251 rte_eth_dev_socket_id(BOND_PORT),
252 &rxq_conf, mbuf_pool);
254 rte_exit(retval, " port %u: RX queue 0 setup failed (res=%d)",
258 txq_conf = dev_info.default_txconf;
259 txq_conf.offloads = local_port_conf.txmode.offloads;
260 retval = rte_eth_tx_queue_setup(BOND_PORT, 0, nb_txd,
261 rte_eth_dev_socket_id(BOND_PORT), &txq_conf);
264 rte_exit(retval, "port %u: TX queue 0 setup failed (res=%d)",
267 for (i = 0; i < slaves_count; i++) {
268 if (rte_eth_bond_slave_add(BOND_PORT, slaves[i]) == -1)
269 rte_exit(-1, "Oooops! adding slave (%u) to bond (%u) failed!\n",
270 slaves[i], BOND_PORT);
274 retval = rte_eth_dev_start(BOND_PORT);
276 rte_exit(retval, "Start port %d failed (res=%d)", BOND_PORT, retval);
278 rte_eth_promiscuous_enable(BOND_PORT);
280 struct ether_addr addr;
282 rte_eth_macaddr_get(BOND_PORT, &addr);
283 printf("Port %u MAC: ", (unsigned)BOND_PORT);
289 get_vlan_offset(struct ether_hdr *eth_hdr, uint16_t *proto)
291 size_t vlan_offset = 0;
293 if (rte_cpu_to_be_16(ETHER_TYPE_VLAN) == *proto) {
294 struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
296 vlan_offset = sizeof(struct vlan_hdr);
297 *proto = vlan_hdr->eth_proto;
299 if (rte_cpu_to_be_16(ETHER_TYPE_VLAN) == *proto) {
300 vlan_hdr = vlan_hdr + 1;
302 *proto = vlan_hdr->eth_proto;
303 vlan_offset += sizeof(struct vlan_hdr);
309 struct global_flag_stru_t {
310 int LcoreMainIsRunning;
312 uint32_t port_packets[4];
315 struct global_flag_stru_t global_flag_stru;
316 struct global_flag_stru_t *global_flag_stru_p = &global_flag_stru;
319 * Main thread that does the work, reading from INPUT_PORT
320 * and writing to OUTPUT_PORT
322 static int lcore_main(__attribute__((unused)) void *arg1)
324 struct rte_mbuf *pkts[MAX_PKT_BURST] __rte_cache_aligned;
325 struct ether_addr d_addr;
327 struct ether_hdr *eth_hdr;
328 struct arp_hdr *arp_hdr;
329 struct ipv4_hdr *ipv4_hdr;
330 uint16_t ether_type, offset;
337 bond_ip = BOND_IP_1 | (BOND_IP_2 << 8) |
338 (BOND_IP_3 << 16) | (BOND_IP_4 << 24);
340 rte_spinlock_trylock(&global_flag_stru_p->lock);
342 while (global_flag_stru_p->LcoreMainIsRunning) {
343 rte_spinlock_unlock(&global_flag_stru_p->lock);
344 rx_cnt = rte_eth_rx_burst(BOND_PORT, 0, pkts, MAX_PKT_BURST);
347 /* If didn't receive any packets, wait and go to next iteration */
353 /* Search incoming data for ARP packets and prepare response */
354 for (i = 0; i < rx_cnt; i++) {
355 if (rte_spinlock_trylock(&global_flag_stru_p->lock) == 1) {
356 global_flag_stru_p->port_packets[0]++;
357 rte_spinlock_unlock(&global_flag_stru_p->lock);
359 eth_hdr = rte_pktmbuf_mtod(pkts[i], struct ether_hdr *);
360 ether_type = eth_hdr->ether_type;
361 if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_VLAN))
362 printf("VLAN taged frame, offset:");
363 offset = get_vlan_offset(eth_hdr, ðer_type);
365 printf("%d\n", offset);
366 if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_ARP)) {
367 if (rte_spinlock_trylock(&global_flag_stru_p->lock) == 1) {
368 global_flag_stru_p->port_packets[1]++;
369 rte_spinlock_unlock(&global_flag_stru_p->lock);
371 arp_hdr = (struct arp_hdr *)((char *)(eth_hdr + 1) + offset);
372 if (arp_hdr->arp_data.arp_tip == bond_ip) {
373 if (arp_hdr->arp_op == rte_cpu_to_be_16(ARP_OP_REQUEST)) {
374 arp_hdr->arp_op = rte_cpu_to_be_16(ARP_OP_REPLY);
375 /* Switch src and dst data and set bonding MAC */
376 ether_addr_copy(ð_hdr->s_addr, ð_hdr->d_addr);
377 rte_eth_macaddr_get(BOND_PORT, ð_hdr->s_addr);
378 ether_addr_copy(&arp_hdr->arp_data.arp_sha, &arp_hdr->arp_data.arp_tha);
379 arp_hdr->arp_data.arp_tip = arp_hdr->arp_data.arp_sip;
380 rte_eth_macaddr_get(BOND_PORT, &d_addr);
381 ether_addr_copy(&d_addr, &arp_hdr->arp_data.arp_sha);
382 arp_hdr->arp_data.arp_sip = bond_ip;
383 rte_eth_tx_burst(BOND_PORT, 0, &pkts[i], 1);
386 rte_eth_tx_burst(BOND_PORT, 0, NULL, 0);
389 } else if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
390 if (rte_spinlock_trylock(&global_flag_stru_p->lock) == 1) {
391 global_flag_stru_p->port_packets[2]++;
392 rte_spinlock_unlock(&global_flag_stru_p->lock);
394 ipv4_hdr = (struct ipv4_hdr *)((char *)(eth_hdr + 1) + offset);
395 if (ipv4_hdr->dst_addr == bond_ip) {
396 ether_addr_copy(ð_hdr->s_addr, ð_hdr->d_addr);
397 rte_eth_macaddr_get(BOND_PORT, ð_hdr->s_addr);
398 ipv4_hdr->dst_addr = ipv4_hdr->src_addr;
399 ipv4_hdr->src_addr = bond_ip;
400 rte_eth_tx_burst(BOND_PORT, 0, &pkts[i], 1);
405 /* Free processed packets */
407 rte_pktmbuf_free(pkts[i]);
409 rte_spinlock_trylock(&global_flag_stru_p->lock);
411 rte_spinlock_unlock(&global_flag_stru_p->lock);
412 printf("BYE lcore_main\n");
416 struct cmd_obj_send_result {
417 cmdline_fixed_string_t action;
420 static inline void get_string(struct cmd_obj_send_result *res, char *buf, uint8_t size)
422 snprintf(buf, size, NIPQUAD_FMT,
423 ((unsigned)((unsigned char *)&(res->ip.addr.ipv4))[0]),
424 ((unsigned)((unsigned char *)&(res->ip.addr.ipv4))[1]),
425 ((unsigned)((unsigned char *)&(res->ip.addr.ipv4))[2]),
426 ((unsigned)((unsigned char *)&(res->ip.addr.ipv4))[3])
429 static void cmd_obj_send_parsed(void *parsed_result,
430 __attribute__((unused)) struct cmdline *cl,
431 __attribute__((unused)) void *data)
434 struct cmd_obj_send_result *res = parsed_result;
435 char ip_str[INET6_ADDRSTRLEN];
437 struct rte_mbuf *created_pkt;
438 struct ether_hdr *eth_hdr;
439 struct arp_hdr *arp_hdr;
444 if (res->ip.family == AF_INET)
445 get_string(res, ip_str, INET_ADDRSTRLEN);
447 cmdline_printf(cl, "Wrong IP format. Only IPv4 is supported\n");
449 bond_ip = BOND_IP_1 | (BOND_IP_2 << 8) |
450 (BOND_IP_3 << 16) | (BOND_IP_4 << 24);
452 created_pkt = rte_pktmbuf_alloc(mbuf_pool);
453 if (created_pkt == NULL) {
454 cmdline_printf(cl, "Failed to allocate mbuf\n");
458 pkt_size = sizeof(struct ether_hdr) + sizeof(struct arp_hdr);
459 created_pkt->data_len = pkt_size;
460 created_pkt->pkt_len = pkt_size;
462 eth_hdr = rte_pktmbuf_mtod(created_pkt, struct ether_hdr *);
463 rte_eth_macaddr_get(BOND_PORT, ð_hdr->s_addr);
464 memset(ð_hdr->d_addr, 0xFF, ETHER_ADDR_LEN);
465 eth_hdr->ether_type = rte_cpu_to_be_16(ETHER_TYPE_ARP);
467 arp_hdr = (struct arp_hdr *)((char *)eth_hdr + sizeof(struct ether_hdr));
468 arp_hdr->arp_hrd = rte_cpu_to_be_16(ARP_HRD_ETHER);
469 arp_hdr->arp_pro = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
470 arp_hdr->arp_hln = ETHER_ADDR_LEN;
471 arp_hdr->arp_pln = sizeof(uint32_t);
472 arp_hdr->arp_op = rte_cpu_to_be_16(ARP_OP_REQUEST);
474 rte_eth_macaddr_get(BOND_PORT, &arp_hdr->arp_data.arp_sha);
475 arp_hdr->arp_data.arp_sip = bond_ip;
476 memset(&arp_hdr->arp_data.arp_tha, 0, ETHER_ADDR_LEN);
477 arp_hdr->arp_data.arp_tip =
478 ((unsigned char *)&res->ip.addr.ipv4)[0] |
479 (((unsigned char *)&res->ip.addr.ipv4)[1] << 8) |
480 (((unsigned char *)&res->ip.addr.ipv4)[2] << 16) |
481 (((unsigned char *)&res->ip.addr.ipv4)[3] << 24);
482 rte_eth_tx_burst(BOND_PORT, 0, &created_pkt, 1);
485 cmdline_printf(cl, "\n");
488 cmdline_parse_token_string_t cmd_obj_action_send =
489 TOKEN_STRING_INITIALIZER(struct cmd_obj_send_result, action, "send");
490 cmdline_parse_token_ipaddr_t cmd_obj_ip =
491 TOKEN_IPV4_INITIALIZER(struct cmd_obj_send_result, ip);
493 cmdline_parse_inst_t cmd_obj_send = {
494 .f = cmd_obj_send_parsed, /* function to call */
495 .data = NULL, /* 2nd arg of func */
496 .help_str = "send client_ip",
497 .tokens = { /* token list, NULL terminated */
498 (void *)&cmd_obj_action_send,
504 struct cmd_start_result {
505 cmdline_fixed_string_t start;
508 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
510 __attribute__((unused)) void *data)
512 int slave_core_id = rte_lcore_id();
514 rte_spinlock_trylock(&global_flag_stru_p->lock);
515 if (global_flag_stru_p->LcoreMainIsRunning == 0) {
516 if (lcore_config[global_flag_stru_p->LcoreMainCore].state != WAIT) {
517 rte_spinlock_unlock(&global_flag_stru_p->lock);
520 rte_spinlock_unlock(&global_flag_stru_p->lock);
522 cmdline_printf(cl, "lcore_main already running on core:%d\n",
523 global_flag_stru_p->LcoreMainCore);
524 rte_spinlock_unlock(&global_flag_stru_p->lock);
528 /* start lcore main on core != master_core - ARP response thread */
529 slave_core_id = rte_get_next_lcore(rte_lcore_id(), 1, 0);
530 if ((slave_core_id >= RTE_MAX_LCORE) || (slave_core_id == 0))
533 rte_spinlock_trylock(&global_flag_stru_p->lock);
534 global_flag_stru_p->LcoreMainIsRunning = 1;
535 rte_spinlock_unlock(&global_flag_stru_p->lock);
537 "Starting lcore_main on core %d:%d "
538 "Our IP:%d.%d.%d.%d\n",
540 rte_eal_remote_launch(lcore_main, NULL, slave_core_id),
548 cmdline_parse_token_string_t cmd_start_start =
549 TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
551 cmdline_parse_inst_t cmd_start = {
552 .f = cmd_start_parsed, /* function to call */
553 .data = NULL, /* 2nd arg of func */
554 .help_str = "starts listening if not started at startup",
555 .tokens = { /* token list, NULL terminated */
556 (void *)&cmd_start_start,
561 struct cmd_help_result {
562 cmdline_fixed_string_t help;
565 static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
567 __attribute__((unused)) void *data)
570 "ALB - link bonding mode 6 example\n"
571 "send IP - sends one ARPrequest through bonding for IP.\n"
572 "start - starts listening ARPs.\n"
573 "stop - stops lcore_main.\n"
574 "show - shows some bond info: ex. active slaves etc.\n"
575 "help - prints help.\n"
576 "quit - terminate all threads and quit.\n"
580 cmdline_parse_token_string_t cmd_help_help =
581 TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");
583 cmdline_parse_inst_t cmd_help = {
584 .f = cmd_help_parsed, /* function to call */
585 .data = NULL, /* 2nd arg of func */
586 .help_str = "show help",
587 .tokens = { /* token list, NULL terminated */
588 (void *)&cmd_help_help,
593 struct cmd_stop_result {
594 cmdline_fixed_string_t stop;
597 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
599 __attribute__((unused)) void *data)
601 rte_spinlock_trylock(&global_flag_stru_p->lock);
602 if (global_flag_stru_p->LcoreMainIsRunning == 0) {
604 "lcore_main not running on core:%d\n",
605 global_flag_stru_p->LcoreMainCore);
606 rte_spinlock_unlock(&global_flag_stru_p->lock);
609 global_flag_stru_p->LcoreMainIsRunning = 0;
610 if (rte_eal_wait_lcore(global_flag_stru_p->LcoreMainCore) < 0)
612 "error: lcore_main can not stop on core:%d\n",
613 global_flag_stru_p->LcoreMainCore);
616 "lcore_main stopped on core:%d\n",
617 global_flag_stru_p->LcoreMainCore);
618 rte_spinlock_unlock(&global_flag_stru_p->lock);
621 cmdline_parse_token_string_t cmd_stop_stop =
622 TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
624 cmdline_parse_inst_t cmd_stop = {
625 .f = cmd_stop_parsed, /* function to call */
626 .data = NULL, /* 2nd arg of func */
627 .help_str = "this command do not handle any arguments",
628 .tokens = { /* token list, NULL terminated */
629 (void *)&cmd_stop_stop,
634 struct cmd_quit_result {
635 cmdline_fixed_string_t quit;
638 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
640 __attribute__((unused)) void *data)
642 rte_spinlock_trylock(&global_flag_stru_p->lock);
643 if (global_flag_stru_p->LcoreMainIsRunning == 0) {
645 "lcore_main not running on core:%d\n",
646 global_flag_stru_p->LcoreMainCore);
647 rte_spinlock_unlock(&global_flag_stru_p->lock);
651 global_flag_stru_p->LcoreMainIsRunning = 0;
652 if (rte_eal_wait_lcore(global_flag_stru_p->LcoreMainCore) < 0)
654 "error: lcore_main can not stop on core:%d\n",
655 global_flag_stru_p->LcoreMainCore);
658 "lcore_main stopped on core:%d\n",
659 global_flag_stru_p->LcoreMainCore);
660 rte_spinlock_unlock(&global_flag_stru_p->lock);
664 cmdline_parse_token_string_t cmd_quit_quit =
665 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
667 cmdline_parse_inst_t cmd_quit = {
668 .f = cmd_quit_parsed, /* function to call */
669 .data = NULL, /* 2nd arg of func */
670 .help_str = "this command do not handle any arguments",
671 .tokens = { /* token list, NULL terminated */
672 (void *)&cmd_quit_quit,
677 struct cmd_show_result {
678 cmdline_fixed_string_t show;
681 static void cmd_show_parsed(__attribute__((unused)) void *parsed_result,
683 __attribute__((unused)) void *data)
685 uint16_t slaves[16] = {0};
687 struct ether_addr addr;
690 while (i < slaves_count) {
691 rte_eth_macaddr_get(i, &addr);
697 rte_spinlock_trylock(&global_flag_stru_p->lock);
700 "packets received:Tot:%d Arp:%d IPv4:%d\n",
701 rte_eth_bond_active_slaves_get(BOND_PORT, slaves, len),
702 global_flag_stru_p->port_packets[0],
703 global_flag_stru_p->port_packets[1],
704 global_flag_stru_p->port_packets[2]);
705 rte_spinlock_unlock(&global_flag_stru_p->lock);
708 cmdline_parse_token_string_t cmd_show_show =
709 TOKEN_STRING_INITIALIZER(struct cmd_show_result, show, "show");
711 cmdline_parse_inst_t cmd_show = {
712 .f = cmd_show_parsed, /* function to call */
713 .data = NULL, /* 2nd arg of func */
714 .help_str = "this command do not handle any arguments",
715 .tokens = { /* token list, NULL terminated */
716 (void *)&cmd_show_show,
721 /****** CONTEXT (list of instruction) */
723 cmdline_parse_ctx_t main_ctx[] = {
724 (cmdline_parse_inst_t *)&cmd_start,
725 (cmdline_parse_inst_t *)&cmd_obj_send,
726 (cmdline_parse_inst_t *)&cmd_stop,
727 (cmdline_parse_inst_t *)&cmd_show,
728 (cmdline_parse_inst_t *)&cmd_quit,
729 (cmdline_parse_inst_t *)&cmd_help,
733 /* prompt function, called from main on MASTER lcore */
734 static void prompt(__attribute__((unused)) void *arg1)
738 cl = cmdline_stdin_new(main_ctx, "bond6>");
740 cmdline_interact(cl);
741 cmdline_stdin_exit(cl);
745 /* Main function, does initialisation and calls the per-lcore functions */
747 main(int argc, char *argv[])
750 uint16_t nb_ports, i;
753 ret = rte_eal_init(argc, argv);
754 rte_devargs_dump(stdout);
756 rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");
760 nb_ports = rte_eth_dev_count_avail();
762 rte_exit(EXIT_FAILURE, "Give at least one port\n");
763 else if (nb_ports > MAX_PORTS)
764 rte_exit(EXIT_FAILURE, "You can have max 4 ports\n");
766 mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NB_MBUF, 32,
767 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
768 if (mbuf_pool == NULL)
769 rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
771 /* initialize all ports */
772 slaves_count = nb_ports;
773 RTE_ETH_FOREACH_DEV(i) {
774 slave_port_init(i, mbuf_pool);
778 bond_port_init(mbuf_pool);
780 rte_spinlock_init(&global_flag_stru_p->lock);
781 int slave_core_id = rte_lcore_id();
783 /* check state of lcores */
784 RTE_LCORE_FOREACH_SLAVE(slave_core_id) {
785 if (lcore_config[slave_core_id].state != WAIT)
788 /* start lcore main on core != master_core - ARP response thread */
789 slave_core_id = rte_get_next_lcore(rte_lcore_id(), 1, 0);
790 if ((slave_core_id >= RTE_MAX_LCORE) || (slave_core_id == 0))
793 global_flag_stru_p->LcoreMainIsRunning = 1;
794 global_flag_stru_p->LcoreMainCore = slave_core_id;
795 printf("Starting lcore_main on core %d:%d Our IP:%d.%d.%d.%d\n",
797 rte_eal_remote_launch((lcore_function_t *)lcore_main,
806 /* Start prompt for user interact */