4 * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/queue.h>
36 #include <sys/socket.h>
50 #include <rte_common.h>
52 #include <rte_memory.h>
53 #include <rte_memcpy.h>
54 #include <rte_memzone.h>
56 #include <rte_per_lcore.h>
57 #include <rte_launch.h>
58 #include <rte_atomic.h>
59 #include <rte_cycles.h>
60 #include <rte_prefetch.h>
61 #include <rte_lcore.h>
62 #include <rte_per_lcore.h>
63 #include <rte_branch_prediction.h>
64 #include <rte_interrupts.h>
66 #include <rte_random.h>
67 #include <rte_debug.h>
68 #include <rte_ether.h>
69 #include <rte_ethdev.h>
72 #include <rte_mempool.h>
74 #include <rte_memcpy.h>
78 #include <rte_spinlock.h>
80 #include <cmdline_rdline.h>
81 #include <cmdline_parse.h>
82 #include <cmdline_parse_num.h>
83 #include <cmdline_parse_string.h>
84 #include <cmdline_parse_ipaddr.h>
85 #include <cmdline_parse_etheraddr.h>
86 #include <cmdline_socket.h>
91 #include <rte_devargs.h>
94 #include "rte_byteorder.h"
95 #include "rte_cpuflags.h"
96 #include "rte_eth_bond.h"
98 #define RTE_LOGTYPE_DCB RTE_LOGTYPE_USER1
100 #define NB_MBUF (1024*8)
102 #define MAX_PKT_BURST 32
103 #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */
104 #define BURST_RX_INTERVAL_NS (10) /* RX poll interval ~100ns */
107 * RX and TX Prefetch, Host, and Write-back threshold values should be
108 * carefully set for optimal performance. Consult the network
109 * controller's datasheet and supporting DPDK documentation for guidance
110 * on how these parameters should be set.
112 #define RX_PTHRESH 8 /**< Default values of RX prefetch threshold reg. */
113 #define RX_HTHRESH 8 /**< Default values of RX host threshold reg. */
114 #define RX_WTHRESH 4 /**< Default values of RX write-back threshold reg. */
115 #define RX_FTHRESH (MAX_PKT_BURST * 2)/**< Default values of RX free threshold reg. */
118 * These default values are optimized for use with the Intel(R) 82599 10 GbE
119 * Controller and the DPDK ixgbe PMD. Consider using other values for other
120 * network controllers and/or network drivers.
122 #define TX_PTHRESH 36 /**< Default values of TX prefetch threshold reg. */
123 #define TX_HTHRESH 0 /**< Default values of TX host threshold reg. */
124 #define TX_WTHRESH 0 /**< Default values of TX write-back threshold reg. */
127 * Configurable number of RX/TX ring descriptors
129 #define RTE_RX_DESC_DEFAULT 128
130 #define RTE_TX_DESC_DEFAULT 512
137 /* not defined under linux */
139 #define NIPQUAD_FMT "%u.%u.%u.%u"
143 #define PRINT_MAC(addr) printf("%02"PRIx8":%02"PRIx8":%02"PRIx8 \
144 ":%02"PRIx8":%02"PRIx8":%02"PRIx8, \
145 addr.addr_bytes[0], addr.addr_bytes[1], addr.addr_bytes[2], \
146 addr.addr_bytes[3], addr.addr_bytes[4], addr.addr_bytes[5])
148 uint8_t slaves[RTE_MAX_ETHPORTS];
149 uint8_t slaves_count;
151 static uint8_t BOND_PORT = 0xff;
153 static struct rte_mempool *mbuf_pool;
155 static struct rte_eth_conf port_conf = {
157 .mq_mode = ETH_MQ_RX_NONE,
158 .max_rx_pkt_len = ETHER_MAX_LEN,
160 .header_split = 0, /**< Header Split disabled */
161 .hw_ip_checksum = 0, /**< IP checksum offload enabled */
162 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
163 .jumbo_frame = 0, /**< Jumbo Frame Support disabled */
164 .hw_strip_crc = 0, /**< CRC stripped by hardware */
169 .rss_hf = ETH_RSS_IP,
173 .mq_mode = ETH_MQ_TX_NONE,
178 slave_port_init(uint8_t portid, struct rte_mempool *mbuf_pool)
182 if (portid >= rte_eth_dev_count())
183 rte_exit(EXIT_FAILURE, "Invalid port\n");
185 retval = rte_eth_dev_configure(portid, 1, 1, &port_conf);
187 rte_exit(EXIT_FAILURE, "port %u: configuration failed (res=%d)\n",
191 retval = rte_eth_rx_queue_setup(portid, 0, RTE_RX_DESC_DEFAULT,
192 rte_eth_dev_socket_id(portid), NULL,
195 rte_exit(retval, " port %u: RX queue 0 setup failed (res=%d)",
199 retval = rte_eth_tx_queue_setup(portid, 0, RTE_TX_DESC_DEFAULT,
200 rte_eth_dev_socket_id(portid), NULL);
203 rte_exit(retval, "port %u: TX queue 0 setup failed (res=%d)",
206 retval = rte_eth_dev_start(portid);
209 "Start port %d failed (res=%d)",
212 struct ether_addr addr;
214 rte_eth_macaddr_get(portid, &addr);
215 printf("Port %u MAC: ", (unsigned)portid);
221 bond_port_init(struct rte_mempool *mbuf_pool)
226 retval = rte_eth_bond_create("bond0", BONDING_MODE_ALB,
227 0 /*SOCKET_ID_ANY*/);
229 rte_exit(EXIT_FAILURE,
230 "Faled to create bond port\n");
232 BOND_PORT = (uint8_t)retval;
234 retval = rte_eth_dev_configure(BOND_PORT, 1, 1, &port_conf);
236 rte_exit(EXIT_FAILURE, "port %u: configuration failed (res=%d)\n",
240 retval = rte_eth_rx_queue_setup(BOND_PORT, 0, RTE_RX_DESC_DEFAULT,
241 rte_eth_dev_socket_id(BOND_PORT), NULL,
244 rte_exit(retval, " port %u: RX queue 0 setup failed (res=%d)",
248 retval = rte_eth_tx_queue_setup(BOND_PORT, 0, RTE_TX_DESC_DEFAULT,
249 rte_eth_dev_socket_id(BOND_PORT), NULL);
252 rte_exit(retval, "port %u: TX queue 0 setup failed (res=%d)",
255 for (i = 0; i < slaves_count; i++) {
256 if (rte_eth_bond_slave_add(BOND_PORT, slaves[i]) == -1)
257 rte_exit(-1, "Oooops! adding slave (%u) to bond (%u) failed!\n",
258 slaves[i], BOND_PORT);
262 retval = rte_eth_dev_start(BOND_PORT);
264 rte_exit(retval, "Start port %d failed (res=%d)", BOND_PORT, retval);
266 rte_eth_promiscuous_enable(BOND_PORT);
268 struct ether_addr addr;
270 rte_eth_macaddr_get(BOND_PORT, &addr);
271 printf("Port %u MAC: ", (unsigned)BOND_PORT);
277 get_vlan_offset(struct ether_hdr *eth_hdr, uint16_t *proto)
279 size_t vlan_offset = 0;
281 if (rte_cpu_to_be_16(ETHER_TYPE_VLAN) == *proto) {
282 struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
284 vlan_offset = sizeof(struct vlan_hdr);
285 *proto = vlan_hdr->eth_proto;
287 if (rte_cpu_to_be_16(ETHER_TYPE_VLAN) == *proto) {
288 vlan_hdr = vlan_hdr + 1;
290 *proto = vlan_hdr->eth_proto;
291 vlan_offset += sizeof(struct vlan_hdr);
297 struct global_flag_stru_t {
298 int LcoreMainIsRunning;
300 uint32_t port_packets[4];
303 struct global_flag_stru_t global_flag_stru;
304 struct global_flag_stru_t *global_flag_stru_p = &global_flag_stru;
307 * Main thread that does the work, reading from INPUT_PORT
308 * and writing to OUTPUT_PORT
310 static int lcore_main(__attribute__((unused)) void *arg1)
312 struct rte_mbuf *pkts[MAX_PKT_BURST] __rte_cache_aligned;
313 struct ether_addr d_addr;
315 struct ether_hdr *eth_hdr;
316 struct arp_hdr *arp_hdr;
317 struct ipv4_hdr *ipv4_hdr;
318 uint16_t ether_type, offset;
325 bond_ip = BOND_IP_1 | (BOND_IP_2 << 8) |
326 (BOND_IP_3 << 16) | (BOND_IP_4 << 24);
328 rte_spinlock_trylock(&global_flag_stru_p->lock);
330 while (global_flag_stru_p->LcoreMainIsRunning) {
331 rte_spinlock_unlock(&global_flag_stru_p->lock);
332 rx_cnt = rte_eth_rx_burst(BOND_PORT, 0, pkts, MAX_PKT_BURST);
335 /* If didn't receive any packets, wait and go to next iteration */
341 /* Search incoming data for ARP packets and prepare response */
342 for (i = 0; i < rx_cnt; i++) {
343 if (rte_spinlock_trylock(&global_flag_stru_p->lock) == 1) {
344 global_flag_stru_p->port_packets[0]++;
345 rte_spinlock_unlock(&global_flag_stru_p->lock);
347 eth_hdr = rte_pktmbuf_mtod(pkts[i], struct ether_hdr *);
348 ether_type = eth_hdr->ether_type;
349 if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_VLAN))
350 printf("VLAN taged frame, offset:");
351 offset = get_vlan_offset(eth_hdr, ðer_type);
353 printf("%d\n", offset);
354 if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_ARP)) {
355 if (rte_spinlock_trylock(&global_flag_stru_p->lock) == 1) {
356 global_flag_stru_p->port_packets[1]++;
357 rte_spinlock_unlock(&global_flag_stru_p->lock);
359 arp_hdr = (struct arp_hdr *)((char *)(eth_hdr + 1) + offset);
360 if (arp_hdr->arp_data.arp_tip == bond_ip) {
361 if (arp_hdr->arp_op == rte_cpu_to_be_16(ARP_OP_REQUEST)) {
362 arp_hdr->arp_op = rte_cpu_to_be_16(ARP_OP_REPLY);
363 /* Switch src and dst data and set bonding MAC */
364 ether_addr_copy(ð_hdr->s_addr, ð_hdr->d_addr);
365 rte_eth_macaddr_get(BOND_PORT, ð_hdr->s_addr);
366 ether_addr_copy(&arp_hdr->arp_data.arp_sha, &arp_hdr->arp_data.arp_tha);
367 arp_hdr->arp_data.arp_tip = arp_hdr->arp_data.arp_sip;
368 rte_eth_macaddr_get(BOND_PORT, &d_addr);
369 ether_addr_copy(&d_addr, &arp_hdr->arp_data.arp_sha);
370 arp_hdr->arp_data.arp_sip = bond_ip;
371 rte_eth_tx_burst(BOND_PORT, 0, &pkts[i], 1);
374 rte_eth_tx_burst(BOND_PORT, 0, NULL, 0);
377 } else if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
378 if (rte_spinlock_trylock(&global_flag_stru_p->lock) == 1) {
379 global_flag_stru_p->port_packets[2]++;
380 rte_spinlock_unlock(&global_flag_stru_p->lock);
382 ipv4_hdr = (struct ipv4_hdr *)((char *)(eth_hdr + 1) + offset);
383 if (ipv4_hdr->dst_addr == bond_ip) {
384 ether_addr_copy(ð_hdr->s_addr, ð_hdr->d_addr);
385 rte_eth_macaddr_get(BOND_PORT, ð_hdr->s_addr);
386 ipv4_hdr->dst_addr = ipv4_hdr->src_addr;
387 ipv4_hdr->src_addr = bond_ip;
388 rte_eth_tx_burst(BOND_PORT, 0, &pkts[i], 1);
393 /* Free processed packets */
395 rte_pktmbuf_free(pkts[i]);
397 rte_spinlock_trylock(&global_flag_stru_p->lock);
399 rte_spinlock_unlock(&global_flag_stru_p->lock);
400 printf("BYE lcore_main\n");
404 struct cmd_obj_send_result {
405 cmdline_fixed_string_t action;
408 static inline void get_string(struct cmd_obj_send_result *res, char *buf, uint8_t size)
410 snprintf(buf, size, NIPQUAD_FMT,
411 ((unsigned)((unsigned char *)&(res->ip.addr.ipv4))[0]),
412 ((unsigned)((unsigned char *)&(res->ip.addr.ipv4))[1]),
413 ((unsigned)((unsigned char *)&(res->ip.addr.ipv4))[2]),
414 ((unsigned)((unsigned char *)&(res->ip.addr.ipv4))[3])
417 static void cmd_obj_send_parsed(void *parsed_result,
418 __attribute__((unused)) struct cmdline *cl,
419 __attribute__((unused)) void *data)
422 struct cmd_obj_send_result *res = parsed_result;
423 char ip_str[INET6_ADDRSTRLEN];
425 struct rte_mbuf *created_pkt;
426 struct ether_hdr *eth_hdr;
427 struct arp_hdr *arp_hdr;
432 if (res->ip.family == AF_INET)
433 get_string(res, ip_str, INET_ADDRSTRLEN);
435 cmdline_printf(cl, "Wrong IP format. Only IPv4 is supported\n");
437 bond_ip = BOND_IP_1 | (BOND_IP_2 << 8) |
438 (BOND_IP_3 << 16) | (BOND_IP_4 << 24);
440 created_pkt = rte_pktmbuf_alloc(mbuf_pool);
441 pkt_size = sizeof(struct ether_hdr) + sizeof(struct arp_hdr);
442 created_pkt->data_len = pkt_size;
443 created_pkt->pkt_len = pkt_size;
445 eth_hdr = rte_pktmbuf_mtod(created_pkt, struct ether_hdr *);
446 rte_eth_macaddr_get(BOND_PORT, ð_hdr->s_addr);
447 memset(ð_hdr->d_addr, 0xFF, ETHER_ADDR_LEN);
448 eth_hdr->ether_type = rte_cpu_to_be_16(ETHER_TYPE_ARP);
450 arp_hdr = (struct arp_hdr *)((char *)eth_hdr + sizeof(struct ether_hdr));
451 arp_hdr->arp_hrd = rte_cpu_to_be_16(ARP_HRD_ETHER);
452 arp_hdr->arp_pro = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
453 arp_hdr->arp_hln = ETHER_ADDR_LEN;
454 arp_hdr->arp_pln = sizeof(uint32_t);
455 arp_hdr->arp_op = rte_cpu_to_be_16(ARP_OP_REQUEST);
457 rte_eth_macaddr_get(BOND_PORT, &arp_hdr->arp_data.arp_sha);
458 arp_hdr->arp_data.arp_sip = bond_ip;
459 memset(&arp_hdr->arp_data.arp_tha, 0, ETHER_ADDR_LEN);
460 arp_hdr->arp_data.arp_tip =
461 ((unsigned char *)&res->ip.addr.ipv4)[0] |
462 (((unsigned char *)&res->ip.addr.ipv4)[1] << 8) |
463 (((unsigned char *)&res->ip.addr.ipv4)[2] << 16) |
464 (((unsigned char *)&res->ip.addr.ipv4)[3] << 24);
465 rte_eth_tx_burst(BOND_PORT, 0, &created_pkt, 1);
468 cmdline_printf(cl, "\n");
471 cmdline_parse_token_string_t cmd_obj_action_send =
472 TOKEN_STRING_INITIALIZER(struct cmd_obj_send_result, action, "send");
473 cmdline_parse_token_ipaddr_t cmd_obj_ip =
474 TOKEN_IPV4_INITIALIZER(struct cmd_obj_send_result, ip);
476 cmdline_parse_inst_t cmd_obj_send = {
477 .f = cmd_obj_send_parsed, /* function to call */
478 .data = NULL, /* 2nd arg of func */
479 .help_str = "send client_ip",
480 .tokens = { /* token list, NULL terminated */
481 (void *)&cmd_obj_action_send,
487 struct cmd_start_result {
488 cmdline_fixed_string_t start;
491 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
493 __attribute__((unused)) void *data)
495 int slave_core_id = rte_lcore_id();
497 rte_spinlock_trylock(&global_flag_stru_p->lock);
498 if (global_flag_stru_p->LcoreMainIsRunning == 0) {
499 if (lcore_config[global_flag_stru_p->LcoreMainCore].state != WAIT) {
500 rte_spinlock_unlock(&global_flag_stru_p->lock);
503 rte_spinlock_unlock(&global_flag_stru_p->lock);
505 cmdline_printf(cl, "lcore_main already running on core:%d\n",
506 global_flag_stru_p->LcoreMainCore);
507 rte_spinlock_unlock(&global_flag_stru_p->lock);
511 /* start lcore main on core != master_core - ARP response thread */
512 slave_core_id = rte_get_next_lcore(rte_lcore_id(), 1, 0);
513 if ((slave_core_id >= RTE_MAX_LCORE) || (slave_core_id == 0))
516 rte_spinlock_trylock(&global_flag_stru_p->lock);
517 global_flag_stru_p->LcoreMainIsRunning = 1;
518 rte_spinlock_unlock(&global_flag_stru_p->lock);
520 "Starting lcore_main on core %d:%d "
521 "Our IP:%d.%d.%d.%d\n",
523 rte_eal_remote_launch(lcore_main, NULL, slave_core_id),
531 cmdline_parse_token_string_t cmd_start_start =
532 TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
534 cmdline_parse_inst_t cmd_start = {
535 .f = cmd_start_parsed, /* function to call */
536 .data = NULL, /* 2nd arg of func */
537 .help_str = "starts listening if not started at startup",
538 .tokens = { /* token list, NULL terminated */
539 (void *)&cmd_start_start,
544 struct cmd_help_result {
545 cmdline_fixed_string_t help;
548 static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
550 __attribute__((unused)) void *data)
553 "ALB - link bonding mode 6 example\n"
554 "send IP - sends one ARPrequest thru bonding for IP.\n"
555 "start - starts listening ARPs.\n"
556 "stop - stops lcore_main.\n"
557 "show - shows some bond info: ex. active slaves etc.\n"
558 "help - prints help.\n"
559 "quit - terminate all threads and quit.\n"
563 cmdline_parse_token_string_t cmd_help_help =
564 TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");
566 cmdline_parse_inst_t cmd_help = {
567 .f = cmd_help_parsed, /* function to call */
568 .data = NULL, /* 2nd arg of func */
569 .help_str = "show help",
570 .tokens = { /* token list, NULL terminated */
571 (void *)&cmd_help_help,
576 struct cmd_stop_result {
577 cmdline_fixed_string_t stop;
580 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
582 __attribute__((unused)) void *data)
584 rte_spinlock_trylock(&global_flag_stru_p->lock);
585 if (global_flag_stru_p->LcoreMainIsRunning == 0) {
587 "lcore_main not running on core:%d\n",
588 global_flag_stru_p->LcoreMainCore);
589 rte_spinlock_unlock(&global_flag_stru_p->lock);
592 global_flag_stru_p->LcoreMainIsRunning = 0;
593 rte_eal_wait_lcore(global_flag_stru_p->LcoreMainCore);
595 "lcore_main stopped on core:%d\n",
596 global_flag_stru_p->LcoreMainCore);
597 rte_spinlock_unlock(&global_flag_stru_p->lock);
600 cmdline_parse_token_string_t cmd_stop_stop =
601 TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
603 cmdline_parse_inst_t cmd_stop = {
604 .f = cmd_stop_parsed, /* function to call */
605 .data = NULL, /* 2nd arg of func */
606 .help_str = "this command do not handle any arguments",
607 .tokens = { /* token list, NULL terminated */
608 (void *)&cmd_stop_stop,
613 struct cmd_quit_result {
614 cmdline_fixed_string_t quit;
617 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
619 __attribute__((unused)) void *data)
621 rte_spinlock_trylock(&global_flag_stru_p->lock);
622 if (global_flag_stru_p->LcoreMainIsRunning == 0) {
624 "lcore_main not running on core:%d\n",
625 global_flag_stru_p->LcoreMainCore);
626 rte_spinlock_unlock(&global_flag_stru_p->lock);
630 global_flag_stru_p->LcoreMainIsRunning = 0;
631 rte_eal_wait_lcore(global_flag_stru_p->LcoreMainCore);
633 "lcore_main stopped on core:%d\n",
634 global_flag_stru_p->LcoreMainCore);
635 rte_spinlock_unlock(&global_flag_stru_p->lock);
639 cmdline_parse_token_string_t cmd_quit_quit =
640 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
642 cmdline_parse_inst_t cmd_quit = {
643 .f = cmd_quit_parsed, /* function to call */
644 .data = NULL, /* 2nd arg of func */
645 .help_str = "this command do not handle any arguments",
646 .tokens = { /* token list, NULL terminated */
647 (void *)&cmd_quit_quit,
652 struct cmd_show_result {
653 cmdline_fixed_string_t show;
656 static void cmd_show_parsed(__attribute__((unused)) void *parsed_result,
658 __attribute__((unused)) void *data)
660 uint8_t slaves[16] = {0};
662 struct ether_addr addr;
665 while (i < slaves_count) {
666 rte_eth_macaddr_get(i, &addr);
672 rte_spinlock_trylock(&global_flag_stru_p->lock);
675 "packets received:Tot:%d Arp:%d IPv4:%d\n",
676 rte_eth_bond_active_slaves_get(BOND_PORT, slaves, len),
677 global_flag_stru_p->port_packets[0],
678 global_flag_stru_p->port_packets[1],
679 global_flag_stru_p->port_packets[2]);
680 rte_spinlock_unlock(&global_flag_stru_p->lock);
683 cmdline_parse_token_string_t cmd_show_show =
684 TOKEN_STRING_INITIALIZER(struct cmd_show_result, show, "show");
686 cmdline_parse_inst_t cmd_show = {
687 .f = cmd_show_parsed, /* function to call */
688 .data = NULL, /* 2nd arg of func */
689 .help_str = "this command do not handle any arguments",
690 .tokens = { /* token list, NULL terminated */
691 (void *)&cmd_show_show,
696 /****** CONTEXT (list of instruction) */
698 cmdline_parse_ctx_t main_ctx[] = {
699 (cmdline_parse_inst_t *)&cmd_start,
700 (cmdline_parse_inst_t *)&cmd_obj_send,
701 (cmdline_parse_inst_t *)&cmd_stop,
702 (cmdline_parse_inst_t *)&cmd_show,
703 (cmdline_parse_inst_t *)&cmd_quit,
704 (cmdline_parse_inst_t *)&cmd_help,
708 /* prompt function, called from main on MASTER lcore */
709 static void prompt(__attribute__((unused)) void *arg1)
713 cl = cmdline_stdin_new(main_ctx, "bond6>");
715 cmdline_interact(cl);
716 cmdline_stdin_exit(cl);
720 /* Main function, does initialisation and calls the per-lcore functions */
722 main(int argc, char *argv[])
728 ret = rte_eal_init(argc, argv);
729 rte_eal_devargs_dump(stdout);
731 rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");
735 nb_ports = rte_eth_dev_count();
737 rte_exit(EXIT_FAILURE, "Give at least one port\n");
738 else if (nb_ports > MAX_PORTS)
739 rte_exit(EXIT_FAILURE, "You can have max 4 ports\n");
741 mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NB_MBUF, 32,
742 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
743 if (mbuf_pool == NULL)
744 rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
746 /* initialize all ports */
747 slaves_count = nb_ports;
748 for (i = 0; i < nb_ports; i++) {
749 slave_port_init(i, mbuf_pool);
753 bond_port_init(mbuf_pool);
755 rte_spinlock_init(&global_flag_stru_p->lock);
756 int slave_core_id = rte_lcore_id();
758 /* check state of lcores */
759 RTE_LCORE_FOREACH_SLAVE(slave_core_id) {
760 if (lcore_config[slave_core_id].state != WAIT)
763 /* start lcore main on core != master_core - ARP response thread */
764 slave_core_id = rte_get_next_lcore(rte_lcore_id(), 1, 0);
765 if ((slave_core_id >= RTE_MAX_LCORE) || (slave_core_id == 0))
768 global_flag_stru_p->LcoreMainIsRunning = 1;
769 global_flag_stru_p->LcoreMainCore = slave_core_id;
770 printf("Starting lcore_main on core %d:%d Our IP:%d.%d.%d.%d\n",
772 rte_eal_remote_launch((lcore_function_t *)lcore_main,
781 /* Start prompt for user interact */