Discussion:
[dpdk-dev] About the data payload of rte_mbuf?
bai bakari
2018-12-06 03:45:22 UTC
Permalink
Hi,


Now, I want to get the data payload of rte_mbuf, and i wrote the following code:


struct ipv4_hdr *ipv4_hdr;
struct tcp_hdr *tcp_hdr;
uint32_t payload_len, ip_len;
uint8_t *payload = NULL;



ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, sizeof(struct ether_hdr));
ip_len = ntohs(ipv4_hdr->total_length);



if (ipv4_hdr->next_proto_id == IPPROTO_TCP) {
tcp_hdr = (struct tcp_hdr *)((uint8_t *)ipv4_hdr + ((ipv4_hdr->version_ihl & 0xf) << 2));
payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off << 2);
payload_len = ip_len - (payload - (uint8_t *)ipv4_hdr);

}


when i send packets using dpdk-pktgen, i found:
ip_len = 46
ip_header_len = 20
but the tcp_header_len=(tcp_hdr->data_off << 2)=0,
and (payload - (uint8_t *)ipv4_hdr) = 340 > ip_len.


I'm confused, is there any errors about the code to compute the payload_len of rte_mbuf?
I think maybe the dpdk-pktgen cannot send the packets with payload?


I'm a beginner, anyone can help me how to compute the payload_len of rte_mbuf and test it?


Thank you
Varghese, Vipin
2018-12-06 04:20:05 UTC
Permalink
Hi,

A quick query from your email

Snipped
Post by bai bakari
ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, sizeof(struct ether_hdr));
Questions:
1. Should not be sizeof(struct ipv4_hdr) since you are passing second argument as ipv4_hdr?
2. you are getting packets which starts from ether or ipv4? If it is ethernet header would not you checking if ether type is ipv4 first? You can get arp, vlan, mpls right?

ip_len = ntohs(ipv4_hdr->total_length);
Post by bai bakari
if (ipv4_hdr->next_proto_id == IPPROTO_TCP) {
tcp_hdr = (struct tcp_hdr *)((uint8_t *)ipv4_hdr + ((ipv4_hdr->version_ihl &
0xf) << 2));
payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off << 2);
payload_len = ip_len - (payload - (uint8_t *)ipv4_hdr);
}
ip_len = 46
ip_header_len = 20
but the tcp_header_len=(tcp_hdr->data_off << 2)=0, and (payload - (uint8_t
*)ipv4_hdr) = 340 > ip_len.
I'm confused, is there any errors about the code to compute the payload_len of rte_mbuf?
I think maybe the dpdk-pktgen cannot send the packets with payload?
I'm a beginner, anyone can help me how to compute the payload_len of rte_mbuf and test it?
Thank you in advance!
bai bakari
2018-12-06 04:59:54 UTC
Permalink
Hi,


Thank your reply.


For your two question,
1. I think it's right, because the definition of "rte_pktmbuf_mtod_offset" is:
#define rte_pktmbuf_mtod_offset(m, t, o) \
((t)((char *)(m)->buf_addr + (m)->data_off + (o)))



2. I set the packet type is IPv4 when i use dpdk-pktgen, that if can promise its type is IPv4?


------------------ Original ------------------
From: "Varghese, Vipin"<***@intel.com>;
Date: Thu, Dec 6, 2018 12:20 PM
To: "bai bakari"<***@qq.com>;"dev"<***@dpdk.org>;

Subject: RE: [dpdk-dev] About the data payload of rte_mbuf?



Hi,

A quick query from your email

Snipped
Post by bai bakari
ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, sizeof(struct ether_hdr));
Questions:
1. Should not be sizeof(struct ipv4_hdr) since you are passing second argument as ipv4_hdr?
2. you are getting packets which starts from ether or ipv4? If it is ethernet header would not you checking if ether type is ipv4 first? You can get arp, vlan, mpls right?

ip_len = ntohs(ipv4_hdr->total_length);
Post by bai bakari
if (ipv4_hdr->next_proto_id == IPPROTO_TCP) {
tcp_hdr = (struct tcp_hdr *)((uint8_t *)ipv4_hdr + ((ipv4_hdr->version_ihl &
0xf) << 2));
payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off << 2);
payload_len = ip_len - (payload - (uint8_t *)ipv4_hdr);
}
ip_len = 46
ip_header_len = 20
but the tcp_header_len=(tcp_hdr->data_off << 2)=0, and (payload - (uint8_t
*)ipv4_hdr) = 340 > ip_len.
I'm confused, is there any errors about the code to compute the payload_len of rte_mbuf?
I think maybe the dpdk-pktgen cannot send the packets with payload?
I'm a beginner, anyone can help me how to compute the payload_len of
rte_mbuf
Varghese, Vipin
2018-12-06 05:41:56 UTC
Permalink
Hi,

snipped
For your two question,
1. I think it's right, because the definition of "rte_pktmbuf_mtod_offset" is:
#define rte_pktmbuf_mtod_offset(m, t, o) \
((t)((char *)(m)->buf_addr + (m)->data_off + (o)))

You are passing ' ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, sizeof(struct ether_hdr)); ' So you are expecting the start of packet is ipv4 rather than ethernet header.

Can you capture the packet and cross check the content in mbuf using 'pdump' tool


2. I set the packet type is IPv4 when i use dpdk-pktgen, that if can promise its type is IPv4?
Capture the packet, I am sure it will have ethernet header + ipv4 header + payload and not ipv4 header + payload.


------------------ Original ------------------
From: "Varghese, Vipin"<***@intel.com<mailto:***@intel.com>>;
Date: Thu, Dec 6, 2018 12:20 PM
To: "bai bakari"<***@qq.com<mailto:***@qq.com>>;"dev"<***@dpdk.org<mailto:***@dpdk.org>>;
Subject: RE: [dpdk-dev] About the data payload of rte_mbuf?

Hi,

A quick query from your email

Snipped
Post by bai bakari
ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, sizeof(struct ether_hdr));
Questions:
1. Should not be sizeof(struct ipv4_hdr) since you are passing second argument as ipv4_hdr?
2. you are getting packets which starts from ether or ipv4? If it is ethernet header would not you checking if ether type is ipv4 first? You can get arp, vlan, mpls right?

ip_len = ntohs(ipv4_hdr->total_length);
Post by bai bakari
if (ipv4_hdr->next_proto_id == IPPROTO_TCP) {
tcp_hdr = (struct tcp_hdr *)((uint8_t *)ipv4_hdr + ((ipv4_hdr->version_ihl &
0xf) << 2));
payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off << 2);
payload_len = ip_len - (payload - (uint8_t *)ipv4_hdr);
}
ip_len = 46
ip_header_len = 20
but the tcp_header_len=(tcp_hdr->data_off << 2)=0, and (payload - (uint8_t
*)ipv4_hdr) = 340 > ip_len.
I'm confused, is there any errors about the code to compute the payload_len of rte_mbuf?
I think maybe the dpdk-pktgen cannot send the packets with payload?
I'm a beginner, anyone can help me how to compute the payload_len of rte_mbuf and test it?
Thank you in advance!
Shyam Shrivastav
2018-12-06 05:48:49 UTC
Permalink
As per my understanding

payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off << 2);

should be

payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off >> 4) << 2);

Note that data offset is 4 most significant bits of the byte, refer tcp
header
Post by bai bakari
Hi,
struct ipv4_hdr *ipv4_hdr;
struct tcp_hdr *tcp_hdr;
uint32_t payload_len, ip_len;
uint8_t *payload = NULL;
ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, sizeof(struct ether_hdr));
ip_len = ntohs(ipv4_hdr->total_length);
if (ipv4_hdr->next_proto_id == IPPROTO_TCP) {
tcp_hdr = (struct tcp_hdr *)((uint8_t *)ipv4_hdr +
((ipv4_hdr->version_ihl & 0xf) << 2));
payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off << 2);
payload_len = ip_len - (payload - (uint8_t *)ipv4_hdr);
}
ip_len = 46
ip_header_len = 20
but the tcp_header_len=(tcp_hdr->data_off << 2)=0,
and (payload - (uint8_t *)ipv4_hdr) = 340 > ip_len.
I'm confused, is there any errors about the code to compute the payload_len of rte_mbuf?
I think maybe the dpdk-pktgen cannot send the packets with payload?
I'm a beginner, anyone can help me how to compute the payload_len of rte_mbuf and test it?
Thank you in advance!
Shyam Shrivastav
2018-12-06 05:52:15 UTC
Permalink
And if just payload length is required one can get by subtracting
(ip-hdr-len + tcp-offset) from total length in ip header ...
Post by Shyam Shrivastav
As per my understanding
payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off << 2);
should be
payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off >> 4) << 2);
Note that data offset is 4 most significant bits of the byte, refer tcp
header
Post by bai bakari
Hi,
struct ipv4_hdr *ipv4_hdr;
struct tcp_hdr *tcp_hdr;
uint32_t payload_len, ip_len;
uint8_t *payload = NULL;
ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, sizeof(struct ether_hdr));
ip_len = ntohs(ipv4_hdr->total_length);
if (ipv4_hdr->next_proto_id == IPPROTO_TCP) {
tcp_hdr = (struct tcp_hdr *)((uint8_t *)ipv4_hdr +
((ipv4_hdr->version_ihl & 0xf) << 2));
payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off << 2);
payload_len = ip_len - (payload - (uint8_t *)ipv4_hdr);
}
ip_len = 46
ip_header_len = 20
but the tcp_header_len=(tcp_hdr->data_off << 2)=0,
and (payload - (uint8_t *)ipv4_hdr) = 340 > ip_len.
I'm confused, is there any errors about the code to compute the payload_len of rte_mbuf?
I think maybe the dpdk-pktgen cannot send the packets with payload?
I'm a beginner, anyone can help me how to compute the payload_len of
rte_mbuf and test it?
Thank you in advance!
bai bakari
2018-12-06 06:19:50 UTC
Permalink
Thank your answers, that helped me out.




------------------ 原始邮件 ------------------
发件人: "Shyam Shrivastav"<***@gmail.com>;
发送时间: 2018年12月6日(星期四) 下午2:22
收件人: "bai bakari"<***@qq.com>;
抄送: "dev"<***@dpdk.org>;
主题: Re: [dpdk-dev] About the data payload of rte_mbuf?



And if just payload length is required one can get by subtracting (ip-hdr-len + tcp-offset) from total length in ip header ...



On Thu, Dec 6, 2018 at 11:18 AM Shyam Shrivastav <***@gmail.com> wrote:



As per my understanding

payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off << 2);

should be

payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off >> 4) << 2);

Note that data offset is 4 most significant bits of the byte, refer tcp header






On Thu, Dec 6, 2018 at 9:15 AM bai bakari <***@qq.com> wrote:

Hi,


Now, I want to get the data payload of rte_mbuf, and i wrote the following code:


struct ipv4_hdr *ipv4_hdr;
struct tcp_hdr *tcp_hdr;
uint32_t payload_len, ip_len;
uint8_t *payload = NULL;



ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, sizeof(struct ether_hdr));
ip_len = ntohs(ipv4_hdr->total_length);



if (ipv4_hdr->next_proto_id == IPPROTO_TCP) {
tcp_hdr = (struct tcp_hdr *)((uint8_t *)ipv4_hdr + ((ipv4_hdr->version_ihl & 0xf) << 2));
payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off << 2);
payload_len = ip_len - (payload - (uint8_t *)ipv4_hdr);

}


when i send packets using dpdk-pktgen, i found:
ip_len = 46
ip_header_len = 20
but the tcp_header_len=(tcp_hdr->data_off << 2)=0,
and (payload - (uint8_t *)ipv4_hdr) = 340 > ip_len.


I'm confused, is there any errors about the code to compute the payload_len of rte_mbuf?
I think maybe the dpdk-pktgen cannot send the packets with payload?


I'm a beginner, anyone can help me how to compute the payload_len of rte_mbuf and test it?


T
Stephen Hemminger
2018-12-06 07:09:14 UTC
Permalink
On Thu, 6 Dec 2018 11:45:22 +0800
Post by bai bakari
ip_len = 46
ip_header_len = 20
but the tcp_header_len=(tcp_hdr->data_off << 2)=0,
and (payload - (uint8_t *)ipv4_hdr) = 340 > ip_len.
dpdk pktgen sends UDP not TCP.
Wiles, Keith
2018-12-06 15:17:19 UTC
Permalink
Post by Stephen Hemminger
On Thu, 6 Dec 2018 11:45:22 +0800
Post by bai bakari
ip_len = 46
ip_header_len = 20
but the tcp_header_len=(tcp_hdr->data_off << 2)=0,
and (payload - (uint8_t *)ipv4_hdr) = 340 > ip_len.
dpdk pktgen sends UDP not TCP.
Not sure I understand this statement Pktgen can send UDP or TCP, it depends on the configuration. Does your statement mean Pktgen has a bug or what ?

Regards,
Keith
Stephen Hemminger
2018-12-06 17:22:25 UTC
Permalink
On Thu, 6 Dec 2018 15:17:19 +0000
Post by Wiles, Keith
Post by Stephen Hemminger
On Thu, 6 Dec 2018 11:45:22 +0800
Post by bai bakari
ip_len = 46
ip_header_len = 20
but the tcp_header_len=(tcp_hdr->data_off << 2)=0,
and (payload - (uint8_t *)ipv4_hdr) = 340 > ip_len.
dpdk pktgen sends UDP not TCP.
Not sure I understand this statement Pktgen can send UDP or TCP, it depends on the configuration. Does your statement mean Pktgen has a bug or what ?
Regards,
Keith
I just wanted to make sure that user had configured TCP, and not UDP>
Loading...