#include <stdint.h>
#include <sys/queue.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <signal.h>
#include <stdarg.h>
#include <inttypes.h>
#include <getopt.h>
#define NUM_QUEUES 128
#define NUM_MBUFS 64*1024
#define MBUF_CACHE_SIZE 64
#define INVALID_PORT_ID 0xFF
static uint32_t enabled_port_mask = 0;
.split_hdr_size = 0,
.header_split = 0,
.hw_ip_checksum = 0,
.hw_vlan_filter = 0,
.jumbo_frame = 0,
},
.txmode = {
},
.rx_adv_conf = {
.vmdq_dcb_conf = {
.enable_default_pool = 0,
.default_pool = 0,
.nb_pool_maps = 0,
.pool_map = {{0, 0},},
.dcb_tc = {0},
},
},
};
static uint8_t ports[RTE_MAX_ETHPORTS];
static unsigned num_ports = 0;
volatile unsigned long rxPackets[ NUM_QUEUES ] = {0};
const uint16_t vlan_tags[] = {
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31
};
static inline int
{
unsigned i;
conf.enable_default_pool = 0;
conf.default_pool = 0;
conf.nb_pool_maps = sizeof( vlan_tags )/sizeof( vlan_tags[ 0 ]);
for (i = 0; i < conf.nb_pool_maps; i++){
conf.pool_map[i].vlan_id = vlan_tags[ i ];
conf.pool_map[i].pools = 1 << (i % num_pools);
}
conf.dcb_tc[i] = (uint8_t)(i % (NUM_QUEUES/num_pools));
}
(void)(
rte_memcpy(eth_conf, &vmdq_dcb_conf_default,
sizeof(*eth_conf)));
return 0;
}
static inline int
{
const uint16_t rxRingSize = 128, txRingSize = 512;
int retval;
uint16_t q;
retval = get_eth_conf(&port_conf, num_pools);
if (retval < 0)
return retval;
if (retval != 0)
return retval;
for (q = 0; q < rxRings; q ++) {
rte_eth_dev_socket_id(port),
NULL,
mbuf_pool);
if (retval < 0)
return retval;
}
for (q = 0; q < txRings; q ++) {
rte_eth_dev_socket_id(port),
NULL);
if (retval < 0)
return retval;
}
if (retval < 0)
return retval;
printf("Port %u MAC: %02"PRIx8" %02"PRIx8" %02"PRIx8
" %02"PRIx8" %02"PRIx8" %02"PRIx8"\n",
(unsigned)port,
addr.addr_bytes[0], addr.addr_bytes[1], addr.addr_bytes[2],
addr.addr_bytes[3], addr.addr_bytes[4], addr.addr_bytes[5]);
return 0;
}
static int
vmdq_parse_num_pools(const char *q_arg)
{
char *end = NULL;
int n;
n = strtol(q_arg, &end, 10);
if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0'))
return -1;
if (n != 16 && n != 32)
return -1;
if (n == 16)
else
return 0;
}
static int
parse_portmask(const char *portmask)
{
char *end = NULL;
unsigned long pm;
pm = strtoul(portmask, &end, 16);
if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
return -1;
if (pm == 0)
return -1;
return pm;
}
static void
vmdq_usage(const char *prgname)
{
printf("%s [EAL options] -- -p PORTMASK]\n"
" --nb-pools NP: number of pools (16 default, 32)\n",
prgname);
}
static int
vmdq_parse_args(int argc, char **argv)
{
int opt;
int option_index;
unsigned i;
const char *prgname = argv[0];
static struct option long_option[] = {
{"nb-pools", required_argument, NULL, 0},
{NULL, 0, 0, 0}
};
while ((opt = getopt_long(argc, argv, "p:",long_option,&option_index)) != EOF) {
switch (opt) {
case 'p':
enabled_port_mask = parse_portmask(optarg);
if (enabled_port_mask == 0) {
printf("invalid portmask\n");
vmdq_usage(prgname);
return -1;
}
break;
case 0:
if (vmdq_parse_num_pools(optarg) == -1){
printf("invalid number of pools\n");
vmdq_usage(prgname);
return -1;
}
break;
default:
vmdq_usage(prgname);
return -1;
}
}
for(i = 0; i < RTE_MAX_ETHPORTS; i++)
{
if (enabled_port_mask & (1 << i))
ports[num_ports++] = (uint8_t)i;
}
if (num_ports < 2 || num_ports % 2) {
printf("Current enabled port number is %u,"
"but it should be even and at least 2\n",num_ports);
return -1;
}
return 0;
}
static void
sighup_handler(int signum)
{
unsigned q;
for (q = 0; q < NUM_QUEUES; q ++) {
if (q % (NUM_QUEUES/num_pools) == 0)
printf("\nPool %u: ", q/(NUM_QUEUES/num_pools));
printf("%lu ", rxPackets[ q ]);
}
printf("\nFinished handling signal %d\n", signum);
}
static __attribute__((noreturn)) int
lcore_main(void *arg)
{
const uintptr_t core_num = (uintptr_t)arg;
uint16_t startQueue = (uint16_t)(core_num * (NUM_QUEUES/num_cores));
uint16_t endQueue = (uint16_t)(startQueue + (NUM_QUEUES/num_cores));
uint16_t q, i, p;
printf("Core %u(lcore %u) reading queues %i-%i\n", (unsigned)core_num,
for (;;) {
const uint16_t buf_size = sizeof(buf) / sizeof(buf[0]);
for (p = 0; p < num_ports; p++) {
const uint8_t src = ports[p];
const uint8_t dst = ports[p ^ 1];
if ((src == INVALID_PORT_ID) || (dst == INVALID_PORT_ID))
continue;
for (q = startQueue; q < endQueue; q++) {
q, buf, buf_size);
if (rxCount == 0)
continue;
rxPackets[q] += rxCount;
(uint16_t)core_num, buf, rxCount);
if (txCount != rxCount) {
for (i = txCount; i < rxCount; i++)
}
}
}
}
}
static unsigned check_ports_num(unsigned nb_ports)
{
unsigned valid_num_ports = num_ports;
unsigned portid;
if (num_ports > nb_ports) {
printf("\nSpecified port number(%u) exceeds total system port number(%u)\n",
num_ports, nb_ports);
num_ports = nb_ports;
}
for (portid = 0; portid < num_ports; portid ++) {
if (ports[portid] >= nb_ports) {
printf("\nSpecified port ID(%u) exceeds max system port ID(%u)\n",
ports[portid], (nb_ports - 1));
ports[portid] = INVALID_PORT_ID;
valid_num_ports --;
}
}
return valid_num_ports;
}
int
main(int argc, char *argv[])
{
unsigned cores;
unsigned lcore_id;
uintptr_t i;
int ret;
unsigned nb_ports, valid_num_ports;
uint8_t portid;
signal(SIGHUP, sighup_handler);
if (ret < 0)
rte_exit(EXIT_FAILURE,
"Error with EAL initialization\n");
argc -= ret;
argv += ret;
ret = vmdq_parse_args(argc, argv);
if (ret < 0)
rte_exit(EXIT_FAILURE,
"Invalid VMDQ argument\n");
if ((cores & (cores - 1)) != 0 || cores > 128) {
rte_exit(EXIT_FAILURE,
"This program can only run on an even"
"number of cores(1-128)\n\n");
}
if (nb_ports > RTE_MAX_ETHPORTS)
nb_ports = RTE_MAX_ETHPORTS;
valid_num_ports = check_ports_num(nb_ports);
if (valid_num_ports < 2 || valid_num_ports % 2) {
printf("Current valid ports number is %u\n", valid_num_ports);
rte_exit(EXIT_FAILURE,
"Error with valid ports number is not even or less than 2\n");
}
if (mbuf_pool == NULL)
rte_exit(EXIT_FAILURE,
"Cannot create mbuf pool\n");
for (portid = 0; portid < nb_ports; portid++) {
if ((enabled_port_mask & (1 << portid)) == 0) {
printf("\nSkipping disabled port %d\n", portid);
continue;
}
if (port_init(portid, mbuf_pool) != 0)
rte_exit(EXIT_FAILURE,
"Cannot initialize network ports\n");
}
i = 0;
}
(void) lcore_main((void*)i);
return 0;
}