#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/queue.h>
#include <setjmp.h>
#include <stdarg.h>
#include <ctype.h>
#include <errno.h>
#include <getopt.h>
#include <signal.h>
#include <stdbool.h>
#include <rte_net.h>
#include "common.h"
static int use_template_api = 1;
static volatile bool force_quit;
static uint16_t port_id;
static uint16_t nr_queues = 5;
struct rte_flow *flow;
#define MAX_QUEUE_SIZE 256
static inline void
print_ether_addr(const char *what, struct rte_ether_addr *eth_addr)
{
char buf[RTE_ETHER_ADDR_FMT_SIZE];
printf("%s%s", what, buf);
}
static int
main_loop(void)
{
uint16_t nb_rx;
uint16_t i;
uint16_t j;
int ret;
while (!force_quit) {
for (i = 0; i < nr_queues; i++) {
i, mbufs, 32);
if (nb_rx) {
for (j = 0; j < nb_rx; j++) {
print_ether_addr("src=",
print_ether_addr(" - dst=",
printf(" - queue=0x%x",
(unsigned int)i);
printf("\n");
}
}
}
}
if (ret < 0)
printf("Failed to stop port %u: %s",
return ret;
}
#define CHECK_INTERVAL 1000
#define MAX_REPEAT_TIMES 90
static void
assert_link_status(void)
{
uint8_t rep_cnt = MAX_REPEAT_TIMES;
int link_get_err = -EINVAL;
memset(&link, 0, sizeof(link));
do {
break;
} while (--rep_cnt);
if (link_get_err < 0)
rte_exit(EXIT_FAILURE,
":: error: link get is failing: %s\n",
rte_exit(EXIT_FAILURE,
":: error: link is still down\n");
}
static void
configure_port_template(uint16_t port_id)
{
int ret;
uint16_t std_queue;
for (std_queue = 0; std_queue < RTE_MAX_LCORE; std_queue++) {
queue_attr[std_queue].size = MAX_QUEUE_SIZE;
attr_list[std_queue] = &queue_attr[std_queue];
}
1, attr_list, &error);
if (ret != 0)
"rte_flow_configure:err=%d, port=%u\n",
ret, port_id);
printf(":: Configuring template port [%d] Done ..\n", port_id);
}
static void
init_port(void)
{
int ret;
uint16_t i;
RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
RTE_ETH_TX_OFFLOAD_TCP_TSO,
},
};
if (ret != 0)
"Error during getting device (port %u) info: %s\n",
port_id, strerror(-ret));
printf(":: initializing port: %d\n", port_id);
nr_queues, nr_queues, &port_conf);
if (ret < 0) {
":: cannot configure device: err=%d, port=%u\n",
ret, port_id);
}
rxq_conf = dev_info.default_rxconf;
for (i = 0; i < nr_queues; i++) {
&rxq_conf,
mbuf_pool);
if (ret < 0) {
":: Rx queue setup failed: err=%d, port=%u\n",
ret, port_id);
}
}
txq_conf = dev_info.default_txconf;
for (i = 0; i < nr_queues; i++) {
&txq_conf);
if (ret < 0) {
":: Tx queue setup failed: err=%d, port=%u\n",
ret, port_id);
}
}
if (ret != 0)
":: promiscuous mode enable failed: err=%s, port=%u\n",
if (ret < 0) {
"rte_eth_dev_start:err=%d, port=%u\n",
ret, port_id);
}
assert_link_status();
printf(":: initializing port: %d done\n", port_id);
if (use_template_api == 0)
return;
if (ret < 0)
"rte_eth_dev_stop:err=%d, port=%u\n",
ret, port_id);
configure_port_template(port_id);
if (ret < 0)
"rte_eth_dev_start:err=%d, port=%u\n",
ret, port_id);
}
static void
signal_handler(int signum)
{
if (signum == SIGINT || signum == SIGTERM) {
printf("\n\nSignal %d received, preparing to exit...\n",
signum);
force_quit = true;
}
}
static int
flow_filtering_parse_args(int argc, char **argv)
{
.usage = "[EAL options] -- [optional parameters]",
.descriptor = NULL,
.epilog = NULL,
.exit_on_error = false,
.callback = NULL,
.opaque = NULL,
.args = {
{ "--template", NULL, "Enable template API flow",
&use_template_api, (void *)1,
},
{ "--non-template", NULL, "Enable non template API flow",
&use_template_api, (void *)0,
},
ARGPARSE_ARG_END(),
},
};
}
int
main(int argc, char **argv)
{
int ret;
uint16_t nr_ports;
if (ret < 0)
rte_exit(EXIT_FAILURE,
":: invalid EAL arguments\n");
argc -= ret;
argv += ret;
force_quit = false;
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
ret = flow_filtering_parse_args(argc, argv);
if (ret < 0)
rte_exit(EXIT_FAILURE,
"Invalid flow filtering arguments\n");
if (nr_ports == 0)
rte_exit(EXIT_FAILURE,
":: no Ethernet ports found\n");
port_id = 0;
if (nr_ports != 1) {
printf(":: warn: %d ports detected, but we use only one: port %u\n",
nr_ports, port_id);
}
RTE_MBUF_DEFAULT_BUF_SIZE,
if (mbuf_pool == NULL)
rte_exit(EXIT_FAILURE,
"Cannot init mbuf pool\n");
init_port();
flow = generate_flow_skeleton(port_id, &error, use_template_api);
if (!flow) {
printf("Flow can't be created %d message: %s\n",
error.type,
error.message ? error.message : "(no stated reason)");
rte_exit(EXIT_FAILURE,
"error in creating flow");
}
printf("Flow created!!:\n");
ret = main_loop();
return ret;
}
#define RTE_ARGPARSE_ARG_VALUE_INT
#define RTE_ARGPARSE_ARG_NO_VALUE
__rte_experimental int rte_argparse_parse(struct rte_argparse *obj, int argc, char **argv)
__rte_noreturn void rte_exit(int exit_code, const char *format,...) __rte_format_printf(2
static void rte_delay_ms(unsigned ms)
int rte_eal_init(int argc, char **argv)
int rte_eal_cleanup(void)
const char * rte_strerror(int errnum)
int rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_queue, uint16_t nb_tx_queue, const struct rte_eth_conf *eth_conf)
#define RTE_ETH_TX_OFFLOAD_VLAN_INSERT
#define RTE_ETH_LINK_DOWN
int rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id, uint16_t nb_rx_desc, unsigned int socket_id, const struct rte_eth_rxconf *rx_conf, struct rte_mempool *mb_pool)
static uint16_t rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id, struct rte_mbuf **rx_pkts, const uint16_t nb_pkts)
int rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info) __rte_warn_unused_result
int rte_eth_promiscuous_enable(uint16_t port_id)
int rte_eth_dev_stop(uint16_t port_id)
int rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id, uint16_t nb_tx_desc, unsigned int socket_id, const struct rte_eth_txconf *tx_conf)
uint16_t rte_eth_dev_count_avail(void)
int rte_eth_link_get(uint16_t port_id, struct rte_eth_link *link) __rte_warn_unused_result
int rte_eth_dev_close(uint16_t port_id)
int rte_eth_dev_socket_id(uint16_t port_id)
int rte_eth_dev_start(uint16_t port_id)
void rte_ether_format_addr(char *buf, uint16_t size, const struct rte_ether_addr *eth_addr)
int rte_flow_flush(uint16_t port_id, struct rte_flow_error *error)
__rte_experimental int rte_flow_configure(uint16_t port_id, const struct rte_flow_port_attr *port_attr, uint16_t nb_queue, const struct rte_flow_queue_attr *queue_attr[], struct rte_flow_error *error)
unsigned int rte_socket_id(void)
static void rte_pktmbuf_free(struct rte_mbuf *m)
struct rte_mempool * rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id)
#define rte_pktmbuf_mtod(m, t)
struct rte_eth_txmode txmode
struct rte_eth_rxmode rxmode
struct rte_ether_addr src_addr
struct rte_ether_addr dst_addr