* [dpdk-dev] About the data payload of rte_mbuf?
@ 2018-12-06 3:45 bai bakari
2018-12-06 4:20 ` Varghese, Vipin
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: bai bakari @ 2018-12-06 3:45 UTC (permalink / raw)
To: dev
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 in advance!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] About the data payload of rte_mbuf?
2018-12-06 3:45 [dpdk-dev] About the data payload of rte_mbuf? bai bakari
@ 2018-12-06 4:20 ` Varghese, Vipin
2018-12-06 4:59 ` bai bakari
2018-12-06 5:48 ` Shyam Shrivastav
2018-12-06 7:09 ` [dpdk-dev] About the data payload of rte_mbuf? Stephen Hemminger
2 siblings, 1 reply; 10+ messages in thread
From: Varghese, Vipin @ 2018-12-06 4:20 UTC (permalink / raw)
To: bai bakari, dev
Hi,
A quick query from your email
Snipped
> 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);
>
>
>
> 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 in advance!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] About the data payload of rte_mbuf?
2018-12-06 4:20 ` Varghese, Vipin
@ 2018-12-06 4:59 ` bai bakari
2018-12-06 5:41 ` Varghese, Vipin
0 siblings, 1 reply; 10+ messages in thread
From: bai bakari @ 2018-12-06 4:59 UTC (permalink / raw)
To: Varghese, Vipin; +Cc: dev
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"<vipin.varghese@intel.com>;
Date: Thu, Dec 6, 2018 12:20 PM
To: "bai bakari"<912873551@qq.com>;"dev"<dev@dpdk.org>;
Subject: RE: [dpdk-dev] About the data payload of rte_mbuf?
Hi,
A quick query from your email
Snipped
> 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);
>
>
>
> 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 in advance!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] About the data payload of rte_mbuf?
2018-12-06 4:59 ` bai bakari
@ 2018-12-06 5:41 ` Varghese, Vipin
0 siblings, 0 replies; 10+ messages in thread
From: Varghese, Vipin @ 2018-12-06 5:41 UTC (permalink / raw)
To: bai bakari; +Cc: dev
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"<vipin.varghese@intel.com<mailto:vipin.varghese@intel.com>>;
Date: Thu, Dec 6, 2018 12:20 PM
To: "bai bakari"<912873551@qq.com<mailto:912873551@qq.com>>;"dev"<dev@dpdk.org<mailto:dev@dpdk.org>>;
Subject: RE: [dpdk-dev] About the data payload of rte_mbuf?
Hi,
A quick query from your email
Snipped
> 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);
>
>
>
> 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 in advance!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] About the data payload of rte_mbuf?
2018-12-06 3:45 [dpdk-dev] About the data payload of rte_mbuf? bai bakari
2018-12-06 4:20 ` Varghese, Vipin
@ 2018-12-06 5:48 ` Shyam Shrivastav
2018-12-06 5:52 ` Shyam Shrivastav
2018-12-06 7:09 ` [dpdk-dev] About the data payload of rte_mbuf? Stephen Hemminger
2 siblings, 1 reply; 10+ messages in thread
From: Shyam Shrivastav @ 2018-12-06 5:48 UTC (permalink / raw)
To: 912873551; +Cc: dev
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 <912873551@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?
>
>
> Thank you in advance!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] About the data payload of rte_mbuf?
2018-12-06 5:48 ` Shyam Shrivastav
@ 2018-12-06 5:52 ` Shyam Shrivastav
2018-12-06 6:19 ` [dpdk-dev] =?gb18030?b?u9i4tKO6ICBBYm91dCB0aGUgZGF0YSBwYXlsb2Fk?= =?gb18030?q?_of_rte=5Fmbuf=3F?= =?gb18030?B?YmFpIGJha2FyaQ==?=
0 siblings, 1 reply; 10+ messages in thread
From: Shyam Shrivastav @ 2018-12-06 5:52 UTC (permalink / raw)
To: 912873551; +Cc: dev
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 <shrivastav.shyam@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 <912873551@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?
>>
>>
>> Thank you in advance!
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [dpdk-dev] =?gb18030?b?u9i4tKO6ICBBYm91dCB0aGUgZGF0YSBwYXlsb2Fk?= =?gb18030?q?_of_rte=5Fmbuf=3F?=
2018-12-06 5:52 ` Shyam Shrivastav
@ 2018-12-06 6:19 ` =?gb18030?B?YmFpIGJha2FyaQ==?=
0 siblings, 0 replies; 10+ messages in thread
From: =?gb18030?B?YmFpIGJha2FyaQ==?= @ 2018-12-06 6:19 UTC (permalink / raw)
To: =?gb18030?B?U2h5YW0gU2hyaXZhc3Rhdg==?=,
=?gb18030?B?VmFyZ2hlc2UsIFZpcGlu?=
Cc: =?gb18030?B?ZGV2?=
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb18030", Size: 2018 bytes --]
Thank your answers, that helped me out.
------------------ ÔʼÓʼþ ------------------
·¢¼þÈË: "Shyam Shrivastav"<shrivastav.shyam@gmail.com>;
·¢ËÍʱ¼ä: 2018Äê12ÔÂ6ÈÕ(ÐÇÆÚËÄ) ÏÂÎç2:22
ÊÕ¼þÈË: "bai bakari"<912873551@qq.com>;
³ËÍ: "dev"<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 <shrivastav.shyam@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 <912873551@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?
Thank you in advance!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] About the data payload of rte_mbuf?
2018-12-06 3:45 [dpdk-dev] About the data payload of rte_mbuf? bai bakari
2018-12-06 4:20 ` Varghese, Vipin
2018-12-06 5:48 ` Shyam Shrivastav
@ 2018-12-06 7:09 ` Stephen Hemminger
2018-12-06 15:17 ` Wiles, Keith
2 siblings, 1 reply; 10+ messages in thread
From: Stephen Hemminger @ 2018-12-06 7:09 UTC (permalink / raw)
To: bai bakari; +Cc: dev
On Thu, 6 Dec 2018 11:45:22 +0800
"bai bakari" <912873551@qq.com> wrote:
> 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.
dpdk pktgen sends UDP not TCP.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] About the data payload of rte_mbuf?
2018-12-06 7:09 ` [dpdk-dev] About the data payload of rte_mbuf? Stephen Hemminger
@ 2018-12-06 15:17 ` Wiles, Keith
2018-12-06 17:22 ` Stephen Hemminger
0 siblings, 1 reply; 10+ messages in thread
From: Wiles, Keith @ 2018-12-06 15:17 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: bai bakari, dev
> On Dec 6, 2018, at 12:09 AM, Stephen Hemminger <stephen@networkplumber.org> wrote:
>
> On Thu, 6 Dec 2018 11:45:22 +0800
> "bai bakari" <912873551@qq.com> wrote:
>
>> 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.
>
>
> 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] About the data payload of rte_mbuf?
2018-12-06 15:17 ` Wiles, Keith
@ 2018-12-06 17:22 ` Stephen Hemminger
0 siblings, 0 replies; 10+ messages in thread
From: Stephen Hemminger @ 2018-12-06 17:22 UTC (permalink / raw)
To: Wiles, Keith; +Cc: bai bakari, dev
On Thu, 6 Dec 2018 15:17:19 +0000
"Wiles, Keith" <keith.wiles@intel.com> wrote:
> > On Dec 6, 2018, at 12:09 AM, Stephen Hemminger <stephen@networkplumber.org> wrote:
> >
> > On Thu, 6 Dec 2018 11:45:22 +0800
> > "bai bakari" <912873551@qq.com> wrote:
> >
> >> 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.
> >
> >
> > 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>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2018-12-06 17:22 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-06 3:45 [dpdk-dev] About the data payload of rte_mbuf? bai bakari
2018-12-06 4:20 ` Varghese, Vipin
2018-12-06 4:59 ` bai bakari
2018-12-06 5:41 ` Varghese, Vipin
2018-12-06 5:48 ` Shyam Shrivastav
2018-12-06 5:52 ` Shyam Shrivastav
2018-12-06 6:19 ` [dpdk-dev] =?gb18030?b?u9i4tKO6ICBBYm91dCB0aGUgZGF0YSBwYXlsb2Fk?= =?gb18030?q?_of_rte=5Fmbuf=3F?= =?gb18030?B?YmFpIGJha2FyaQ==?=
2018-12-06 7:09 ` [dpdk-dev] About the data payload of rte_mbuf? Stephen Hemminger
2018-12-06 15:17 ` Wiles, Keith
2018-12-06 17:22 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).