* Copyright(c) 2010-2016 Intel Corporation
*/
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <errno.h>
#include <getopt.h>
+#include <sched.h>
#include <rte_common.h>
#include <rte_vect.h>
uint16_t port_dst;
uint16_t port_src;
uint8_t proto;
-} __attribute__((__packed__));
+} __rte_packed;
union ipv4_5tuple_host {
struct {
uint16_t port_dst;
uint16_t port_src;
uint8_t proto;
-} __attribute__((__packed__));
+} __rte_packed;
union ipv6_5tuple_host {
struct {
struct thread_tx_conf {
struct thread_conf conf;
- uint16_t tx_queue_id[RTE_MAX_LCORE];
- struct mbuf_table tx_mbufs[RTE_MAX_LCORE];
+ uint16_t tx_queue_id[RTE_MAX_ETHPORTS];
+ struct mbuf_table tx_mbufs[RTE_MAX_ETHPORTS];
struct rte_ring *ring;
struct lthread_cond **ready;
#endif
static inline void l3fwd_simple_forward(struct rte_mbuf *m, uint16_t portid)
- __attribute__((unused));
+ __rte_unused;
#if ((APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH) && \
(ENABLE_MULTI_BUFFER_OPTIMIZE == 1))
struct rte_ether_hdr *eth_hdr[8];
union ipv6_5tuple_host key[8];
- __attribute__((unused)) struct rte_ipv6_hdr *ipv6_hdr[8];
+ __rte_unused struct rte_ipv6_hdr *ipv6_hdr[8];
eth_hdr[0] = rte_pktmbuf_mtod(m[0], struct rte_ether_hdr *);
eth_hdr[1] = rte_pktmbuf_mtod(m[1], struct rte_ether_hdr *);
/*
* CPU-load stats collector
*/
-static int __attribute__((noreturn))
+static int __rte_noreturn
cpu_load_collector(__rte_unused void *arg) {
unsigned i, j, k;
uint64_t hits;
/*
* Start scheduler with initial lthread on lcore
*
- * This lthread loop spawns all rx and tx lthreads on master lcore
+ * This lthread loop spawns all rx and tx lthreads on main lcore
*/
static void *
}
/*
- * Start master scheduler with initial lthread spawning rx and tx lthreads
- * (main_lthread_master).
+ * Start main scheduler with initial lthread spawning rx and tx lthreads
+ * (main_lthread_main).
*/
static int
-lthread_master_spawner(__rte_unused void *arg) {
+lthread_main_spawner(__rte_unused void *arg) {
struct lthread *lt;
int lcore_id = rte_lcore_id();
}
/* main processing loop */
-static int __attribute__((noreturn))
+static int __rte_noreturn
pthread_tx(void *dummy)
{
struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
/* parse hexadecimal string */
pm = strtoul(portmask, &end, 16);
if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
- return -1;
-
- if (pm == 0)
- return -1;
+ return 0;
return pm;
}
*(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];
}
-#define CMD_LINE_OPT_RX_CONFIG "rx"
-#define CMD_LINE_OPT_TX_CONFIG "tx"
-#define CMD_LINE_OPT_STAT_LCORE "stat-lcore"
-#define CMD_LINE_OPT_ETH_DEST "eth-dest"
-#define CMD_LINE_OPT_NO_NUMA "no-numa"
-#define CMD_LINE_OPT_IPV6 "ipv6"
-#define CMD_LINE_OPT_ENABLE_JUMBO "enable-jumbo"
-#define CMD_LINE_OPT_HASH_ENTRY_NUM "hash-entry-num"
-#define CMD_LINE_OPT_NO_LTHREADS "no-lthreads"
-#define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype"
+enum {
+#define OPT_RX_CONFIG "rx"
+ OPT_RX_CONFIG_NUM = 256,
+#define OPT_TX_CONFIG "tx"
+ OPT_TX_CONFIG_NUM,
+#define OPT_STAT_LCORE "stat-lcore"
+ OPT_STAT_LCORE_NUM,
+#define OPT_ETH_DEST "eth-dest"
+ OPT_ETH_DEST_NUM,
+#define OPT_NO_NUMA "no-numa"
+ OPT_NO_NUMA_NUM,
+#define OPT_IPV6 "ipv6"
+ OPT_IPV6_NUM,
+#define OPT_ENABLE_JUMBO "enable-jumbo"
+ OPT_ENABLE_JUMBO_NUM,
+#define OPT_HASH_ENTRY_NUM "hash-entry-num"
+ OPT_HASH_ENTRY_NUM_NUM,
+#define OPT_NO_LTHREADS "no-lthreads"
+ OPT_NO_LTHREADS_NUM,
+#define OPT_PARSE_PTYPE "parse-ptype"
+ OPT_PARSE_PTYPE_NUM,
+};
/* Parse the argument given in the command line of the application */
static int
int option_index;
char *prgname = argv[0];
static struct option lgopts[] = {
- {CMD_LINE_OPT_RX_CONFIG, 1, 0, 0},
- {CMD_LINE_OPT_TX_CONFIG, 1, 0, 0},
- {CMD_LINE_OPT_STAT_LCORE, 1, 0, 0},
- {CMD_LINE_OPT_ETH_DEST, 1, 0, 0},
- {CMD_LINE_OPT_NO_NUMA, 0, 0, 0},
- {CMD_LINE_OPT_IPV6, 0, 0, 0},
- {CMD_LINE_OPT_ENABLE_JUMBO, 0, 0, 0},
- {CMD_LINE_OPT_HASH_ENTRY_NUM, 1, 0, 0},
- {CMD_LINE_OPT_NO_LTHREADS, 0, 0, 0},
- {CMD_LINE_OPT_PARSE_PTYPE, 0, 0, 0},
- {NULL, 0, 0, 0}
+ {OPT_RX_CONFIG, 1, NULL, OPT_RX_CONFIG_NUM },
+ {OPT_TX_CONFIG, 1, NULL, OPT_TX_CONFIG_NUM },
+ {OPT_STAT_LCORE, 1, NULL, OPT_STAT_LCORE_NUM },
+ {OPT_ETH_DEST, 1, NULL, OPT_ETH_DEST_NUM },
+ {OPT_NO_NUMA, 0, NULL, OPT_NO_NUMA_NUM },
+ {OPT_IPV6, 0, NULL, OPT_IPV6_NUM },
+ {OPT_ENABLE_JUMBO, 0, NULL, OPT_ENABLE_JUMBO_NUM },
+ {OPT_HASH_ENTRY_NUM, 1, NULL, OPT_HASH_ENTRY_NUM_NUM },
+ {OPT_NO_LTHREADS, 0, NULL, OPT_NO_LTHREADS_NUM },
+ {OPT_PARSE_PTYPE, 0, NULL, OPT_PARSE_PTYPE_NUM },
+ {NULL, 0, 0, 0 }
};
argvopt = argv;
return -1;
}
break;
+
case 'P':
printf("Promiscuous mode selected\n");
promiscuous_on = 1;
break;
/* long options */
- case 0:
- if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_RX_CONFIG,
- sizeof(CMD_LINE_OPT_RX_CONFIG))) {
- ret = parse_rx_config(optarg);
- if (ret) {
- printf("invalid rx-config\n");
- print_usage(prgname);
- return -1;
- }
+ case OPT_RX_CONFIG_NUM:
+ ret = parse_rx_config(optarg);
+ if (ret) {
+ printf("invalid rx-config\n");
+ print_usage(prgname);
+ return -1;
}
+ break;
- if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_TX_CONFIG,
- sizeof(CMD_LINE_OPT_TX_CONFIG))) {
- ret = parse_tx_config(optarg);
- if (ret) {
- printf("invalid tx-config\n");
- print_usage(prgname);
- return -1;
- }
+ case OPT_TX_CONFIG_NUM:
+ ret = parse_tx_config(optarg);
+ if (ret) {
+ printf("invalid tx-config\n");
+ print_usage(prgname);
+ return -1;
}
+ break;
#if (APP_CPU_LOAD > 0)
- if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_STAT_LCORE,
- sizeof(CMD_LINE_OPT_STAT_LCORE))) {
- cpu_load_lcore_id = parse_stat_lcore(optarg);
- }
+ case OPT_STAT_LCORE_NUM:
+ cpu_load_lcore_id = parse_stat_lcore(optarg);
+ break;
#endif
- if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_ETH_DEST,
- sizeof(CMD_LINE_OPT_ETH_DEST)))
- parse_eth_dest(optarg);
+ case OPT_ETH_DEST_NUM:
+ parse_eth_dest(optarg);
+ break;
- if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_NO_NUMA,
- sizeof(CMD_LINE_OPT_NO_NUMA))) {
- printf("numa is disabled\n");
- numa_on = 0;
- }
+ case OPT_NO_NUMA_NUM:
+ printf("numa is disabled\n");
+ numa_on = 0;
+ break;
#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
- if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_IPV6,
- sizeof(CMD_LINE_OPT_IPV6))) {
- printf("ipv6 is specified\n");
- ipv6 = 1;
- }
+ case OPT_IPV6_NUM:
+ printf("ipv6 is specified\n");
+ ipv6 = 1;
+ break;
#endif
- if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_NO_LTHREADS,
- sizeof(CMD_LINE_OPT_NO_LTHREADS))) {
- printf("l-threads model is disabled\n");
- lthreads_on = 0;
- }
+ case OPT_NO_LTHREADS_NUM:
+ printf("l-threads model is disabled\n");
+ lthreads_on = 0;
+ break;
- if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_PARSE_PTYPE,
- sizeof(CMD_LINE_OPT_PARSE_PTYPE))) {
- printf("software packet type parsing enabled\n");
- parse_ptype_on = 1;
- }
+ case OPT_PARSE_PTYPE_NUM:
+ printf("software packet type parsing enabled\n");
+ parse_ptype_on = 1;
+ break;
- if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_ENABLE_JUMBO,
- sizeof(CMD_LINE_OPT_ENABLE_JUMBO))) {
- struct option lenopts = {"max-pkt-len", required_argument, 0,
- 0};
-
- printf("jumbo frame is enabled - disabling simple TX path\n");
- port_conf.rxmode.offloads |=
- DEV_RX_OFFLOAD_JUMBO_FRAME;
- port_conf.txmode.offloads |=
- DEV_TX_OFFLOAD_MULTI_SEGS;
-
- /* if no max-pkt-len set, use the default value
- * RTE_ETHER_MAX_LEN
- */
- if (0 == getopt_long(argc, argvopt, "", &lenopts,
- &option_index)) {
-
- ret = parse_max_pkt_len(optarg);
- if ((ret < 64) || (ret > MAX_JUMBO_PKT_LEN)) {
- printf("invalid packet length\n");
- print_usage(prgname);
- return -1;
- }
- port_conf.rxmode.max_rx_pkt_len = ret;
- }
- printf("set jumbo frame max packet length to %u\n",
- (unsigned int)port_conf.rxmode.max_rx_pkt_len);
- }
-#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
- if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_HASH_ENTRY_NUM,
- sizeof(CMD_LINE_OPT_HASH_ENTRY_NUM))) {
- ret = parse_hash_entry_number(optarg);
- if ((ret > 0) && (ret <= L3FWD_HASH_ENTRIES)) {
- hash_entry_number = ret;
- } else {
- printf("invalid hash entry number\n");
+ case OPT_ENABLE_JUMBO_NUM:
+ {
+ struct option lenopts = {"max-pkt-len",
+ required_argument, 0, 0};
+
+ printf("jumbo frame is enabled - disabling simple TX path\n");
+ port_conf.rxmode.offloads |=
+ DEV_RX_OFFLOAD_JUMBO_FRAME;
+ port_conf.txmode.offloads |=
+ DEV_TX_OFFLOAD_MULTI_SEGS;
+
+ /* if no max-pkt-len set, use the default value
+ * RTE_ETHER_MAX_LEN
+ */
+ if (getopt_long(argc, argvopt, "", &lenopts,
+ &option_index) == 0) {
+
+ ret = parse_max_pkt_len(optarg);
+ if ((ret < 64) || (ret > MAX_JUMBO_PKT_LEN)) {
+ printf("invalid packet length\n");
print_usage(prgname);
return -1;
}
+ port_conf.rxmode.max_rx_pkt_len = ret;
+ }
+ printf("set jumbo frame max packet length to %u\n",
+ (unsigned int)port_conf.rxmode.max_rx_pkt_len);
+ break;
+ }
+#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
+ case OPT_HASH_ENTRY_NUM_NUM:
+ ret = parse_hash_entry_number(optarg);
+ if ((ret > 0) && (ret <= L3FWD_HASH_ENTRIES)) {
+ hash_entry_number = ret;
+ } else {
+ printf("invalid hash entry number\n");
+ print_usage(prgname);
+ return -1;
}
-#endif
break;
+#endif
default:
print_usage(prgname);
uint8_t count, all_ports_up, print_flag = 0;
struct rte_eth_link link;
int ret;
+ char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
printf("\nChecking link status");
fflush(stdout);
}
/* print link status if flag set */
if (print_flag == 1) {
- if (link.link_status)
- printf(
- "Port%d Link Up. Speed %u Mbps - %s\n",
- portid, link.link_speed,
- (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
- ("full-duplex") : ("half-duplex\n"));
- else
- printf("Port %d Link Down\n", portid);
+ rte_eth_link_to_str(link_status_text,
+ sizeof(link_status_text), &link);
+ printf("Port %d %s\n", portid,
+ link_status_text);
continue;
}
/* clear all_ports_up flag if any link down */
#endif
lthread_num_schedulers_set(nb_lcores);
- rte_eal_mp_remote_launch(sched_spawner, NULL, SKIP_MASTER);
- lthread_master_spawner(NULL);
+ rte_eal_mp_remote_launch(sched_spawner, NULL, SKIP_MAIN);
+ lthread_main_spawner(NULL);
} else {
printf("Starting P-Threading Model\n");
/* launch per-lcore init on every lcore */
- rte_eal_mp_remote_launch(pthread_run, NULL, CALL_MASTER);
- RTE_LCORE_FOREACH_SLAVE(lcore_id) {
+ rte_eal_mp_remote_launch(pthread_run, NULL, CALL_MAIN);
+ RTE_LCORE_FOREACH_WORKER(lcore_id) {
if (rte_eal_wait_lcore(lcore_id) < 0)
return -1;
}
}
+ /* clean up the EAL */
+ rte_eal_cleanup();
+
return 0;
}