I am running dpdk-stable-18.11.9
on Ubuntu 18.04
.I have external card that was generating UDP
packet continuously (rate:40Gbps) I want to
In order to access a received packet's ethernet payload use DPDK API rte_pktmbuf_mtod().
for (i = 0; i < nb_rx; i++) {
/* access payload of rcv'd pkt at ethernet header */
eth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
}
but if the intention is more than just ethernet header, you can refer to below sample code snippet for ipv4.
#include <linux/if_vlan.h>
In the main processing loop
uint16_t i, nb_rx, len;
uint16_t ether_type;
struct ether_hdr *eth_hdr;
struct vlan_hdr *vh;
uint16_t *proto;
struct ipv4_hdr *ip_hdr;
struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
/* rcv burst of pkts from interface, on success returns no. of pkts rcv'd */
nb_rx = rte_eth_rx_burst(port_id, queue_id, pkts_burst, MAX_PKT_BURST)
/* Loop through rcv'd pkts */
for (i = 0; i < nb_rx; i++) {
/* update len on each iteration to 0 */
len = 0;
/* access payload of rcv'd pkt at ethernet header */
eth_hdr = rte_pktmbuf_mtod(pkts_burst[i], struct ether_hdr *);
if (rte_cpu_to_be_16(ETHER_TYPE_VLAN) == eth_hdr->ether_type) {
len = sizeof(struct ether_hdr);
vh = (struct vlan_hdr *)(eth_hdr + 1);
proto = vh->eth_proto;
if (rte_cpu_to_be_16(ETHER_TYPE_VLAN) == *proto) {
len += sizeof(struct vlan_hdr);
proto = vh->eth_proto;
}
/* free up non ipv4 packets */
if (rte_cpu_to_be_16(ETHER_TYPE_IPv4) != *proto)
rte_pktmbuf_free(pkt);
}
/* access IP header of rcv'd pkt */
ip_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkts_burst[i], char *) + len);
/* process packets which are ipv4 */
}