#include <rte_memcpy.h>
#include <rte_eal.h>
#include <rte_launch.h>
-#include <rte_atomic.h>
#include <rte_cycles.h>
#include <rte_prefetch.h>
#include <rte_lcore.h>
#include <rte_string_fns.h>
#include <rte_acl.h>
+#include <cmdline_parse.h>
+#include <cmdline_parse_etheraddr.h>
+
#if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
#define L3FWDACL_DEBUG
#endif
static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
-/* ethernet addresses of ports */
-static struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
-
/* mask of enabled ports */
static uint32_t enabled_port_mask;
static int promiscuous_on; /**< Ports set in promiscuous mode off by default. */
static struct rte_mempool *pktmbuf_pool[NB_SOCKETS];
+/* ethernet addresses of ports */
+static struct rte_ether_hdr port_l2hdr[RTE_MAX_ETHPORTS];
+
+static const struct {
+ const char *name;
+ enum rte_acl_classify_alg alg;
+} acl_alg[] = {
+ {
+ .name = "scalar",
+ .alg = RTE_ACL_CLASSIFY_SCALAR,
+ },
+ {
+ .name = "sse",
+ .alg = RTE_ACL_CLASSIFY_SSE,
+ },
+ {
+ .name = "avx2",
+ .alg = RTE_ACL_CLASSIFY_AVX2,
+ },
+ {
+ .name = "neon",
+ .alg = RTE_ACL_CLASSIFY_NEON,
+ },
+ {
+ .name = "altivec",
+ .alg = RTE_ACL_CLASSIFY_ALTIVEC,
+ },
+ {
+ .name = "avx512x16",
+ .alg = RTE_ACL_CLASSIFY_AVX512X16,
+ },
+ {
+ .name = "avx512x32",
+ .alg = RTE_ACL_CLASSIFY_AVX512X32,
+ },
+};
+
/***********************start of ACL part******************************/
#ifdef DO_RFC_1812_CHECKS
static inline int
#define ACL_LEAD_CHAR ('@')
#define ROUTE_LEAD_CHAR ('R')
#define COMMENT_LEAD_CHAR ('#')
-#define OPTION_CONFIG "config"
-#define OPTION_NONUMA "no-numa"
-#define OPTION_ENBJMO "enable-jumbo"
-#define OPTION_RULE_IPV4 "rule_ipv4"
-#define OPTION_RULE_IPV6 "rule_ipv6"
-#define OPTION_SCALAR "scalar"
+
+enum {
+#define OPT_CONFIG "config"
+ OPT_CONFIG_NUM = 256,
+#define OPT_NONUMA "no-numa"
+ OPT_NONUMA_NUM,
+#define OPT_ENBJMO "enable-jumbo"
+ OPT_ENBJMO_NUM,
+#define OPT_RULE_IPV4 "rule_ipv4"
+ OPT_RULE_IPV4_NUM,
+#define OPT_RULE_IPV6 "rule_ipv6"
+ OPT_RULE_IPV6_NUM,
+#define OPT_ALG "alg"
+ OPT_ALG_NUM,
+#define OPT_ETH_DEST "eth-dest"
+ OPT_ETH_DEST_NUM,
+};
+
#define ACL_DENY_SIGNATURE 0xf0000000
#define RTE_LOGTYPE_L3FWDACL RTE_LOGTYPE_USER3
#define acl_log(format, ...) RTE_LOG(ERR, L3FWDACL, format, ##__VA_ARGS__)
static struct{
const char *rule_ipv4_name;
const char *rule_ipv6_name;
- int scalar;
+ enum rte_acl_classify_alg alg;
} parm_config;
const char cb_port_delim[] = ":";
return 0;
}
+static int
+usage_acl_alg(char *buf, size_t sz)
+{
+ uint32_t i, n, rc, tn;
+
+ n = 0;
+ tn = 0;
+ for (i = 0; i < RTE_DIM(acl_alg); i++) {
+ rc = snprintf(buf + n, sz - n,
+ i == RTE_DIM(acl_alg) - 1 ? "%s" : "%s|",
+ acl_alg[i].name);
+ tn += rc;
+ if (rc < sz - n)
+ n += rc;
+ }
+
+ return tn;
+}
+
+static const char *
+str_acl_alg(enum rte_acl_classify_alg alg)
+{
+ uint32_t i;
+
+ for (i = 0; i != RTE_DIM(acl_alg); i++) {
+ if (alg == acl_alg[i].alg)
+ return acl_alg[i].name;
+ }
+
+ return "default";
+}
+
+static enum rte_acl_classify_alg
+parse_acl_alg(const char *alg)
+{
+ uint32_t i;
+
+ for (i = 0; i != RTE_DIM(acl_alg); i++) {
+ if (strcmp(alg, acl_alg[i].name) == 0)
+ return acl_alg[i].alg;
+ }
+
+ return RTE_ACL_CLASSIFY_DEFAULT;
+}
+
static void
dump_acl_config(void)
{
printf("ACL option are:\n");
- printf(OPTION_RULE_IPV4": %s\n", parm_config.rule_ipv4_name);
- printf(OPTION_RULE_IPV6": %s\n", parm_config.rule_ipv6_name);
- printf(OPTION_SCALAR": %d\n", parm_config.scalar);
+ printf(OPT_RULE_IPV4": %s\n", parm_config.rule_ipv4_name);
+ printf(OPT_RULE_IPV6": %s\n", parm_config.rule_ipv6_name);
+ printf(OPT_ALG": %s\n", str_acl_alg(parm_config.alg));
}
static int
if ((context = rte_acl_create(&acl_param)) == NULL)
rte_exit(EXIT_FAILURE, "Failed to create ACL context\n");
- if (parm_config.scalar && rte_acl_set_ctx_classify(context,
- RTE_ACL_CLASSIFY_SCALAR) != 0)
+ if (parm_config.alg != RTE_ACL_CLASSIFY_DEFAULT &&
+ rte_acl_set_ctx_classify(context, parm_config.alg) != 0)
rte_exit(EXIT_FAILURE,
"Failed to setup classify method for ACL context\n");
{
uint32_t lcore_id;
struct lcore_conf *qconf;
+ struct rte_ether_hdr *eh;
lcore_id = rte_lcore_id();
+ /* update src and dst mac*/
+ eh = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
+ memcpy(eh, &port_l2hdr[port],
+ sizeof(eh->dst_addr) + sizeof(eh->src_addr));
+
qconf = &lcore_conf[lcore_id];
rte_eth_tx_buffer(port, qconf->tx_queue_id[port],
qconf->tx_buffer[port], m);
static void
print_usage(const char *prgname)
{
+ char alg[PATH_MAX];
+
+ usage_acl_alg(alg, sizeof(alg));
printf("%s [EAL options] -- -p PORTMASK -P"
- "--"OPTION_RULE_IPV4"=FILE"
- "--"OPTION_RULE_IPV6"=FILE"
- " [--"OPTION_CONFIG" (port,queue,lcore)[,(port,queue,lcore]]"
- " [--"OPTION_ENBJMO" [--max-pkt-len PKTLEN]]\n"
+ "--"OPT_RULE_IPV4"=FILE"
+ "--"OPT_RULE_IPV6"=FILE"
+ " [--"OPT_CONFIG" (port,queue,lcore)[,(port,queue,lcore]]"
+ " [--"OPT_ENBJMO" [--max-pkt-len PKTLEN]]\n"
" -p PORTMASK: hexadecimal bitmask of ports to configure\n"
" -P : enable promiscuous mode\n"
- " --"OPTION_CONFIG": (port,queue,lcore): "
+ " --"OPT_CONFIG": (port,queue,lcore): "
"rx queues configuration\n"
- " --"OPTION_NONUMA": optional, disable numa awareness\n"
- " --"OPTION_ENBJMO": enable jumbo frame"
+ " --"OPT_NONUMA": optional, disable numa awareness\n"
+ " --"OPT_ENBJMO": enable jumbo frame"
" which max packet len is PKTLEN in decimal (64-9600)\n"
- " --"OPTION_RULE_IPV4"=FILE: specify the ipv4 rules entries "
+ " --"OPT_RULE_IPV4"=FILE: specify the ipv4 rules entries "
"file. "
"Each rule occupy one line. "
"2 kinds of rules are supported. "
"One is ACL entry at while line leads with character '%c', "
"another is route entry at while line leads with "
"character '%c'.\n"
- " --"OPTION_RULE_IPV6"=FILE: specify the ipv6 rules "
+ " --"OPT_RULE_IPV6"=FILE: specify the ipv6 rules "
"entries file.\n"
- " --"OPTION_SCALAR": Use scalar function to do lookup\n",
- prgname, ACL_LEAD_CHAR, ROUTE_LEAD_CHAR);
+ " --"OPT_ALG": ACL classify method to use, one of: %s\n",
+ prgname, ACL_LEAD_CHAR, ROUTE_LEAD_CHAR, alg);
}
static int
return 0;
}
+static const char *
+parse_eth_dest(const char *optarg)
+{
+ unsigned long portid;
+ char *port_end;
+
+ errno = 0;
+ portid = strtoul(optarg, &port_end, 0);
+ if (errno != 0 || port_end == optarg || *port_end++ != ',')
+ return "Invalid format";
+ else if (portid >= RTE_MAX_ETHPORTS)
+ return "port value exceeds RTE_MAX_ETHPORTS("
+ RTE_STR(RTE_MAX_ETHPORTS) ")";
+
+ if (cmdline_parse_etheraddr(NULL, port_end,
+ &port_l2hdr[portid].dst_addr,
+ sizeof(port_l2hdr[portid].dst_addr)) < 0)
+ return "Invalid ethernet address";
+ return NULL;
+}
+
/* Parse the argument given in the command line of the application */
static int
parse_args(int argc, char **argv)
int option_index;
char *prgname = argv[0];
static struct option lgopts[] = {
- {OPTION_CONFIG, 1, 0, 0},
- {OPTION_NONUMA, 0, 0, 0},
- {OPTION_ENBJMO, 0, 0, 0},
- {OPTION_RULE_IPV4, 1, 0, 0},
- {OPTION_RULE_IPV6, 1, 0, 0},
- {OPTION_SCALAR, 0, 0, 0},
- {NULL, 0, 0, 0}
+ {OPT_CONFIG, 1, NULL, OPT_CONFIG_NUM },
+ {OPT_NONUMA, 0, NULL, OPT_NONUMA_NUM },
+ {OPT_ENBJMO, 0, NULL, OPT_ENBJMO_NUM },
+ {OPT_RULE_IPV4, 1, NULL, OPT_RULE_IPV4_NUM },
+ {OPT_RULE_IPV6, 1, NULL, OPT_RULE_IPV6_NUM },
+ {OPT_ALG, 1, NULL, OPT_ALG_NUM },
+ {OPT_ETH_DEST, 1, NULL, OPT_ETH_DEST_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,
- OPTION_CONFIG,
- sizeof(OPTION_CONFIG))) {
- ret = parse_config(optarg);
- if (ret) {
- printf("invalid config\n");
- print_usage(prgname);
- return -1;
- }
+ case OPT_CONFIG_NUM:
+ ret = parse_config(optarg);
+ if (ret) {
+ printf("invalid config\n");
+ print_usage(prgname);
+ return -1;
}
+ break;
- if (!strncmp(lgopts[option_index].name,
- OPTION_NONUMA,
- sizeof(OPTION_NONUMA))) {
- printf("numa is disabled\n");
- numa_on = 0;
- }
+ case OPT_NONUMA_NUM:
+ printf("numa is disabled\n");
+ numa_on = 0;
+ break;
- if (!strncmp(lgopts[option_index].name,
- OPTION_ENBJMO, sizeof(OPTION_ENBJMO))) {
- struct option lenopts = {
- "max-pkt-len",
- required_argument,
- 0,
- 0
- };
-
- printf("jumbo frame is enabled\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, then 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;
+ case OPT_ENBJMO_NUM:
+ {
+ struct option lenopts = {
+ "max-pkt-len",
+ required_argument,
+ 0,
+ 0
+ };
+
+ printf("jumbo frame is enabled\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, then 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;
}
- printf("set jumbo frame max packet length "
- "to %u\n",
- (unsigned int)
- port_conf.rxmode.max_rx_pkt_len);
+ 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;
+ }
+ case OPT_RULE_IPV4_NUM:
+ parm_config.rule_ipv4_name = optarg;
+ break;
- if (!strncmp(lgopts[option_index].name,
- OPTION_RULE_IPV4,
- sizeof(OPTION_RULE_IPV4)))
- parm_config.rule_ipv4_name = optarg;
+ case OPT_RULE_IPV6_NUM:
+ parm_config.rule_ipv6_name = optarg;
+ break;
- if (!strncmp(lgopts[option_index].name,
- OPTION_RULE_IPV6,
- sizeof(OPTION_RULE_IPV6))) {
- parm_config.rule_ipv6_name = optarg;
+ case OPT_ALG_NUM:
+ parm_config.alg = parse_acl_alg(optarg);
+ if (parm_config.alg ==
+ RTE_ACL_CLASSIFY_DEFAULT) {
+ printf("unknown %s value:\"%s\"\n",
+ OPT_ALG, optarg);
+ print_usage(prgname);
+ return -1;
}
-
- if (!strncmp(lgopts[option_index].name,
- OPTION_SCALAR, sizeof(OPTION_SCALAR)))
- parm_config.scalar = 1;
-
-
break;
+ case OPT_ETH_DEST_NUM:
+ {
+ const char *serr = parse_eth_dest(optarg);
+ if (serr != NULL) {
+ printf("invalid %s value:\"%s\": %s\n",
+ OPT_ETH_DEST, optarg, serr);
+ print_usage(prgname);
+ return -1;
+ }
+ break;
+ }
default:
print_usage(prgname);
return -1;
}
}
+/*
+ * build-up default vaues for dest MACs.
+ */
+static void
+set_default_dest_mac(void)
+{
+ uint32_t i;
+
+ for (i = 0; i != RTE_DIM(port_l2hdr); i++) {
+ port_l2hdr[i].dst_addr.addr_bytes[0] =
+ RTE_ETHER_LOCAL_ADMIN_ADDR;
+ port_l2hdr[i].dst_addr.addr_bytes[5] = i;
+ }
+}
+
int
main(int argc, char **argv)
{
argc -= ret;
argv += ret;
+ set_default_dest_mac();
+
/* parse application arguments (after the EAL ones) */
ret = parse_args(argc, argv);
if (ret < 0)
"rte_eth_dev_adjust_nb_rx_tx_desc: err=%d, port=%d\n",
ret, portid);
- ret = rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
+ ret = rte_eth_macaddr_get(portid, &port_l2hdr[portid].src_addr);
if (ret < 0)
rte_exit(EXIT_FAILURE,
"rte_eth_macaddr_get: err=%d, port=%d\n",
ret, portid);
- print_ethaddr(" Address:", &ports_eth_addr[portid]);
+ print_ethaddr("Dst MAC:", &port_l2hdr[portid].dst_addr);
+ print_ethaddr(", Src MAC:", &port_l2hdr[portid].src_addr);
printf(", ");
/* init memory */
check_all_ports_link_status(enabled_port_mask);
/* launch per-lcore init on every lcore */
- rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER);
- RTE_LCORE_FOREACH_SLAVE(lcore_id) {
+ rte_eal_mp_remote_launch(main_loop, 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;
}