//pmd 0 s a #include #include #include #include _Bool received_sigint = false; struct rte_eth_conf port_conf = { .rxmode = { .mq_mode = RTE_ETH_MQ_RX_NONE, }, .txmode = { .mq_mode = RTE_ETH_MQ_TX_NONE, }, }; static void SIGINT_signal_handler( const int signal ) { fprintf( stderr, "\b\bReceived Interrupt Signal SIGINT (%d). Exiting...\n", signal ); received_sigint = true; } int main( int argc, char **argv ) { uint16_t pkt_count, num_of_pkts_rcvd; struct rte_eth_dev_info dev_info; if( signal( SIGINT, SIGINT_signal_handler ) == SIG_ERR ) { fprintf( stderr, "%s %d SIGINT signal handling failed\n", __func__, __LINE__ ); exit( 1 ); } const int ret = rte_eal_init( argc, argv ); if( ret < 0 ) rte_exit( EXIT_FAILURE, "Error with EAL initialization\n" ); argc -= ret; argv += ret; const int port_id = atoi( argv[1] ); const char send_recv = argv[2][0]; if( rte_eth_dev_info_get( port_id, &dev_info ) != 0 ) rte_exit( EXIT_FAILURE, "%s %d rte_eth_dev_info_get\n", __func__, __LINE__ ); const int sock = rte_eth_dev_socket_id( port_id ); if( sock == -1 ) rte_exit( EXIT_FAILURE, "%s %d rte_eth_dev_socket_id port id: %u", __func__, __LINE__, port_id ); // if( rte_eth_promiscuous_enable( port_id ) != 0 ) // rte_exit( EXIT_FAILURE, "%s %d rte_eth_promiscuous_enable port id: %u", __func__, __LINE__, port_id ); char mem_pool_name[20]; sprintf( mem_pool_name, "pool_%u_%c", port_id, send_recv ); const uint32_t num_of_pkts_per_queue = 4096; struct rte_mbuf *mbuf[num_of_pkts_per_queue]; char *packet_buffer[num_of_pkts_per_queue]; fprintf( stderr, "%s %d port id: %d num_of_pkts_per_queue: %u\n", __func__, __LINE__, port_id, num_of_pkts_per_queue ); struct rte_mempool *mem_pool = rte_pktmbuf_pool_create( mem_pool_name, num_of_pkts_per_queue, RTE_MEMPOOL_CACHE_MAX_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, sock ); if( mem_pool == NULL ) { fprintf( stderr, "%d %s\n", rte_errno, rte_strerror(rte_errno) ); rte_exit( EXIT_FAILURE, "%s %d rte_pktmbuf_pool_create port id: %u\n", __func__, __LINE__, port_id ); } for( pkt_count=0; pkt_countpkt_len = mbuf[pkt_count]->data_len = dev_info.max_mtu; } } else if( send_recv == 'r' ) { if( rte_eth_dev_configure( port_id, 1, 0, &port_conf ) != 0 ) rte_exit( EXIT_FAILURE, "%s %d rte_eth_dev_configure port id: %u", __func__, __LINE__, port_id ); if( rte_eth_rx_queue_setup( port_id, 0, num_of_pkts_per_queue, (unsigned int)sock, NULL, mem_pool ) < 0 ) rte_exit( EXIT_FAILURE, "%s %d rte_eth_rx_queue_setup port id: %u", __func__, __LINE__, port_id ); } else { rte_exit( EXIT_FAILURE, "%s %d Invalid param %c port id: %u", __func__, __LINE__, send_recv, port_id ); } if( rte_eth_dev_start( port_id ) < 0 ) rte_exit( EXIT_FAILURE, "%s %d rte_eth_dev_start port id: %u", __func__, __LINE__, port_id ); while( received_sigint == false ) { if( send_recv == 's' ) { if( rte_eth_tx_burst( port_id, 0, mbuf, num_of_pkts_per_queue ) != num_of_pkts_per_queue ) { fprintf( stderr, "%d %s\n", rte_errno, rte_strerror(rte_errno) ); rte_exit( EXIT_FAILURE, "%s %d rte_eth_tx_burst port id: %u\n", __func__, __LINE__, port_id ); } fprintf( stderr, "%s %d port: %u packet: %c sent %u packets\n", __func__, __LINE__, port_id, argv[3][0], num_of_pkts_per_queue ); } else if( send_recv == 'r' ) { fprintf( stderr, "port: %u rte_eth_rx_burst\n", port_id ); num_of_pkts_rcvd = rte_eth_rx_burst( port_id, 0, mbuf, num_of_pkts_per_queue ); for( pkt_count=0; pkt_countpkt_len != mbuf[pkt_count]->data_len ) rte_exit( EXIT_FAILURE, "%s %d mbuf[pkt_count]->pkt_len(%u) != mbuf[pkt_count]->data_len(%u) port id: %u", __func__, __LINE__, mbuf[pkt_count]->pkt_len, mbuf[pkt_count]->data_len, port_id ); if( mbuf[pkt_count]->pkt_len > 40 ) mbuf[pkt_count]->pkt_len = 40; fprintf( stderr, "port: %u pkt count: %u\t", port_id, pkt_count ); for( uint8_t i=0; ipkt_len; i++ ) fprintf( stderr, "%02X ", packet_buffer[pkt_count][i] ); fprintf( stderr, "\n" ); } } } for( pkt_count=0; pkt_count