'dpdk - can't receive packets

i'm new at networking and dpdk, i tryed a little program to recieve and print packets using dpdk that the host receives, but it appears the nic binded to dpdk is clueless about those packets. How can i read the packets ? In other words, eno1 and eno2 are interfaces binded to dpdk. enp1s0 is the interface using kernel driver. I wish to read packets flowing through enp1s0 with dpdk. I used tcpreplay, and netcat to send packet to the host. I know the host receives the packets, but the dpdk application is utterly clueless about it. Could you give me any suggestions ? Here's the little code

#define RING_SIZE 4096
#define n 16383              //n = 2^12 - 1. Optimized according API
#define MEMPOOL_CACHE_SIZE 256 // n%MEMPOOL_CACHE_SIZE = 0. Optimized according API
//#define DATA_ROOM_SIZE 256
#define NB_DESC 1024
#define BURST_SIZE 32


static int ragequit = 0;
struct rte_mempool *buff;

static struct rte_eth_conf port_conf_default = {
    .rxmode = {
        .mq_mode = RTE_ETH_MQ_RX_RSS,
    },
    .txmode = {
        .mq_mode = RTE_ETH_MQ_TX_NONE,
    },
};

static void handler(int sig_num)
{
    if (sig_num == SIGINT)
        ragequit = 1;
    printf(" packets capture over\n");
}

int main(int argc, char *argv[])
{
    int ret, pack; 
    uint16_t port_id;
    struct rte_ring *ring_rx;
    struct rte_eth_conf port_conf = port_conf_default;

    signal(SIGINT, handler);

    //body
    //EAL initialization
    ret = rte_eal_init(argc, argv);
    if (ret < 0)
        rte_exit(EXIT_FAILURE, "\nEAL can not start");
    //ports available
    int nbports = rte_eth_dev_count_avail();
    if (nbports < 1)
        rte_exit(EXIT_FAILURE, "no ethernet ports found");
    
    buff = rte_pktmbuf_pool_create("buff_pool", n, MEMPOOL_CACHE_SIZE, 0, 
    RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
    if (buff == NULL)
        rte_exit(EXIT_FAILURE, "\nCannot create pool buffer | %s\n", rte_strerror(rte_errno));
    printf("pool buffer created\n");

    RTE_ETH_FOREACH_DEV(port_id) {  //iterate over all enabled and ownerless ports
        ret = rte_eth_dev_configure(port_id, 1, 1, &port_conf);
        if (ret < 0)
            rte_exit(EXIT_FAILURE, "\nCannot configure ethernet device");
        ret = rte_eth_rx_queue_setup(port_id, 0, NB_DESC, rte_eth_dev_socket_id(port_id), NULL, buff);
        if (ret < 0)
            rte_exit(EXIT_FAILURE, "\nCannot setup rx queue");
        ret = rte_eth_tx_queue_setup(port_id, 0, NB_DESC, rte_eth_dev_socket_id(port_id), NULL);
        if (ret < 0)
            rte_exit(EXIT_FAILURE, "\nCannot setup tx queue");
        ret = rte_eth_dev_start(port_id);
        if (ret < 0)
            rte_exit(EXIT_FAILURE, "\nCannot start ethernet service");
    }

    ring_rx = rte_ring_create("RX", RING_SIZE, rte_socket_id(), RING_F_SP_ENQ); //single producer
    if (ring_rx == NULL)
        rte_exit(EXIT_FAILURE, "\nCannot create RX ring");

    struct rte_mbuf *mbuff[BURST_SIZE];
    unsigned char *msg = NULL;
    while (ragequit == 0)
    {
        RTE_ETH_FOREACH_DEV(port_id)
        {
            pack = rte_eth_rx_burst(port_id, 0, mbuff, BURST_SIZE);
            if (pack == 0)
            {
                //sleep(1);
                continue;
            }
            rte_ring_enqueue_burst(ring_rx, (void *) mbuff, pack, NULL);
            for (int i = 0; i < pack; i++)
            {
                msg = rte_pktmbuf_mtod(mbuff[i], unsigned char *);
                for (int octet = 1; octet < 96; octet++)
                {
                printf("%02x ", msg[octet-1]);
                if (octet%8 == 0)
                {
                    if (octet%32 == 0)
                        printf("\n");
                    else
                        printf("    ");
                }     
                }
                printf("--------------------------------------------------------------    --------------------------------------------------------------\n");
            }
        }
    }
    printf("\nEndgame\n");
    rte_eal_cleanup();
    return 0;
}

i execute this with ./test3 -l 0-1 -n 4 -- -p 0xfff Thanks for reading. Best regards



Solution 1:[1]

@Frederic based on the information shared, there is a configuration issue. Let me explain

  1. eno1 and eno2 are interfaces binded to dpdk
  2. enp1s0 is the interface using kernel driver
  3. I wish to read packets flowing through enp1s0 with dpdk

your current code interacts with the NIC bonded with DPDK such as en01 and en02. But there is no provision added to support kernel Driver NIC enp1s0.

How to solve the problem: I wish to read packets flowing through enp1s0 with dpdk

  1. PCAP PMD to read and write packets from the kernel interface using --vdev=net_pcap0,iface=[kernel nic interface instance enp1s0]
  2. TAP PMD and add route rules to redirect desired packets with --vdev=net_tap0,iface=[desired nic name]
  3. AF_XDP PMD to load XDP eBPF to redirect all or desired packet to XDP socket in DPDK.

Hence to solve your current issue, please make sure to use right virtual device by passing to EAL args

Solution 2:[2]

You're using conditionals so using if is better than while. Anyway, your problem is that in the second condition check, the condition is interpreted as DNA[-3:len(DNA)] != "TAA")or"TAG"or"TGA". So, you can do if DNA[-3:len(DNA)] not in ("TAA", "TAG", "TGA"):. For your second question, I'll assume that you want to take input again if the input is not valid. This is easily achievable with an infinite loop with a break condition. Here's an example.

valid = False
while !valid:
    DNA_text = raw_input("Please enter a DNA sequanece that is a valid ORF\n")
    DNA = Seq(DNA_text)
    print("You have entered the following DNA sequence: " + DNA)
    if DNA[0:3] != "ATG":
        print ("Sequence does not include a valid start codon")
    
    elif DNA[-3:len(DNA)] not in ("TAA","TAG","TGA"):
        print ("Sequence does not include a valid stop codon")

    elif len(DNA) %3 != 0:
        print ("Sequence is not a valid reading frame")

    else:
        valid = True

#rest of your code here

Solution 3:[3]

First things first you need a condition for every or operator used.
while DNA[-3:len(DNA)] != "TAA"or"TAG"or"TGA":
Should be
while DNA[-3:len(DNA)] != "TAA"or DNA[-3:len(DNA)] != "TAG"or DNA[-3:len(DNA)] !="TGA":
A cleaner way of doing this would be
while DNA[-3:len(DNA)] not in ("TAA","TAG","TGA"):

Also you are not using while loops properly. It seems like you are trying to use them like if statements which would simply be:
if DNA[-3:len(DNA)] not in ("TAA","TAG","TGA"):

If you would like to return to the beginning of the input you're going to want to wrap all this code in a while loop with a flag that tells your program whether or not to re-run the code. For example:
flagToReturnToBeginning= true
while(flagToReturnToBeginning):
And inside of the while loop you will set flagToReturnToBeginning to false when the necessary condition is met and you no longer want to continue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vipin Varghese
Solution 2 Abdur Rakib
Solution 3 qTzz