dpdk l2fwd(2)

dpdk l2fwd (2)

回到l2fwd的main函数中

int

MAIN(int argc, char **argv) {

struct lcore_queue_conf *qconf; struct rte_eth_dev_info dev_info; int ret;

uint8_t nb_ports;

uint8_t nb_ports_available; uint8_t portid, last_port;

unsigned lcore_id, rx_lcore_id; unsigned nb_ports_in_mask = 0;

/* init EAL */

ret = rte_eal_init(argc, argv); if (ret < 0)

rte_exit(EXIT_FAILURE, \ argc -= ret; argv += ret;

/* parse application arguments (after the EAL ones) */ ret = l2fwd_parse_args(argc, argv); if (ret < 0)

rte_exit(EXIT_FAILURE, \

/* create the mbuf pool */ l2fwd_pktmbuf_pool =

rte_mempool_create(\ MBUF_SIZE, 32,

sizeof(struct rte_pktmbuf_pool_private), rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, NULL, rte_socket_id(), 0); if (l2fwd_pktmbuf_pool == NULL)

rte_exit(EXIT_FAILURE, \

/* init driver(s) */

if (rte_pmd_init_all() < 0)

rte_exit(EXIT_FAILURE, \

if (rte_eal_pci_probe() < 0)

rte_exit(EXIT_FAILURE, \

nb_ports = rte_eth_dev_count(); if (nb_ports == 0)

rte_exit(EXIT_FAILURE, \

if (nb_ports > RTE_MAX_ETHPORTS) nb_ports = RTE_MAX_ETHPORTS;

/* reset l2fwd_dst_ports */

for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) l2fwd_dst_ports[portid] = 0; last_port = 0;

/* port0发给port1, port1发给port0. 两个端口为一对,互相发包 */ /*

* Each logical core is assigned a dedicated TX queue on each port. */

for (portid = 0; portid < nb_ports; portid++) { /* skip ports that are not enabled */

if ((l2fwd_enabled_port_mask & (1 << portid)) == 0) continue;

if (nb_ports_in_mask % 2) {

l2fwd_dst_ports[portid] = last_port; l2fwd_dst_ports[last_port] = portid; } else

last_port = portid;

nb_ports_in_mask++;

rte_eth_dev_info_get(portid, &dev_info);

}

if (nb_ports_in_mask % 2) {

printf(\ l2fwd_dst_ports[last_port] = last_port; }

rx_lcore_id = 0; qconf = NULL;

/* 每个core负责收l2fwd_rx_queue_per_lcore个端口, 每个端口(其实应该是QUEUE,因为这里一个port只有一个QUEUE)只能由一个lcore进行收包 */ /* Initialize the port/queue configuration of each logical core */ for (portid = 0; portid < nb_ports; portid++) { /* skip ports that are not enabled */

if ((l2fwd_enabled_port_mask & (1 << portid)) == 0) continue;

/* get the lcore_id for this port */

while (rte_lcore_is_enabled(rx_lcore_id) == 0 || lcore_queue_conf[rx_lcore_id].n_rx_port == l2fwd_rx_queue_per_lcore) {

rx_lcore_id++;

if (rx_lcore_id >= RTE_MAX_LCORE)

rte_exit(EXIT_FAILURE, \ }

if (qconf != &lcore_queue_conf[rx_lcore_id])

/* Assigned a new logical core in the loop above. */ qconf = &lcore_queue_conf[rx_lcore_id];

qconf->rx_port_list[qconf->n_rx_port] = portid;

qconf->n_rx_port++;

printf(\portid); }

nb_ports_available = nb_ports;

/* 每个port收发包队列的初始化 */

/* Initialise each port */

for (portid = 0; portid < nb_ports; portid++) { /* skip ports that are not enabled */

if ((l2fwd_enabled_port_mask & (1 << portid)) == 0) {

printf(\ nb_ports_available--; continue; }

/* init port */

printf(\ fflush(stdout);

ret = rte_eth_dev_configure(portid, 1, 1, &port_conf); if (ret < 0)

rte_exit(EXIT_FAILURE, \port=%u\\n\

ret, (unsigned) portid);

rte_eth_macaddr_get(portid,&l2fwd_ports_eth_addr[portid]);

/* init one RX queue */ fflush(stdout);

ret = rte_eth_rx_queue_setup(portid, 0, nb_rxd,

rte_eth_dev_socket_id(portid), &rx_conf, l2fwd_pktmbuf_pool); if (ret < 0)

rte_exit(EXIT_FAILURE, \port=%u\\n\

ret, (unsigned) portid);

/* init one TX queue on each port */ fflush(stdout);

ret = rte_eth_tx_queue_setup(portid, 0, nb_txd, rte_eth_dev_socket_id(portid), &tx_conf); if (ret < 0)

rte_exit(EXIT_FAILURE, \port=%u\\n\

ret, (unsigned) portid);

/* Start device */

联系客服:779662525#qq.com(#替换为@)