DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] How to update the sequence number in TCP packets using DPDK-pktgen?
@ 2017-10-09 13:42 Shailja Pandey
  2017-10-09 17:12 ` Wiles, Keith
  2017-10-10 23:00 ` Stephen Hemminger
  0 siblings, 2 replies; 4+ messages in thread
From: Shailja Pandey @ 2017-10-09 13:42 UTC (permalink / raw)
  To: dev

Hi,

In the DPDK application, I am maintaining some state and due to that I 
need to generate the packets with monotonically increasing sequence 
numbers. As shown in the code below,

/tip->tcp.seq        = htonl(DEFAULT_PKT_NUMBER);/

DPDK is putting some default number as a sequence number in the TCP 
packet and not using as defined by TCP protocol. I tried various 
workarounds but due to multi-threaded nature of the pktgen application, 
I am facing some issues and unable to put sequence numbers in increasing 
order. I tried thread_local and pthread_mutex_lock etc to generate 
packets with increasing sequence number.

I am not very sure what am I missing, Please help me in this matter.

_Function:_

void
pktgen_tcp_hdr_ctor(pkt_seq_t *pkt, tcpip_t *tip, int type __rte_unused)
{
         uint16_t tlen;

         /* Zero out the header space */
         memset((char *)tip, 0, sizeof(tcpip_t));

         /* Create the TCP header */
         tip->ip.src         = htonl(pkt->ip_src_addr.addr.ipv4.s_addr);
         tip->ip.dst         = htonl(pkt->ip_dst_addr.addr.ipv4.s_addr);
         tlen                = pkt->pktSize -
                 (pkt->ether_hdr_size + sizeof(ipHdr_t));

         tip->ip.len         = htons(tlen);
         tip->ip.proto       = pkt->ipProto;

         tip->tcp.sport      = htons(pkt->sport);
         tip->tcp.dport      = htons(pkt->dport);

*tip->tcp.seq        = htonl(DEFAULT_PKT_NUMBER);*

         tip->tcp.ack        = htonl(DEFAULT_ACK_NUMBER);
         tip->tcp.offset     = ((sizeof(tcpHdr_t) / sizeof(uint32_t)) << 
4);     /* Offset in words */
         tip->tcp.flags      = 
ACK_FLAG;                                         /* ACK */
         tip->tcp.window     = htons(DEFAULT_WND_SIZE);
         tip->tcp.urgent     = 0;

         tlen                = pkt->pktSize - pkt->ether_hdr_size;

         tip->tcp.cksum      = cksum(tip, tlen, 0);
}

-- 

Thanks,
Shailja

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] How to update the sequence number in TCP packets using DPDK-pktgen?
  2017-10-09 13:42 [dpdk-dev] How to update the sequence number in TCP packets using DPDK-pktgen? Shailja Pandey
@ 2017-10-09 17:12 ` Wiles, Keith
  2017-10-10 23:00 ` Stephen Hemminger
  1 sibling, 0 replies; 4+ messages in thread
From: Wiles, Keith @ 2017-10-09 17:12 UTC (permalink / raw)
  To: Shailja Pandey; +Cc: dev



> On Oct 9, 2017, at 8:42 AM, Shailja Pandey <csz168117@iitd.ac.in> wrote:
> 
> Hi,
> 
> In the DPDK application, I am maintaining some state and due to that I need to generate the packets with monotonically increasing sequence numbers. As shown in the code below,
> 
> /tip->tcp.seq        = htonl(DEFAULT_PKT_NUMBER);/
> 
> DPDK is putting some default number as a sequence number in the TCP packet and not using as defined by TCP protocol. I tried various workarounds but due to multi-threaded nature of the pktgen application, I am facing some issues and unable to put sequence numbers in increasing order. I tried thread_local and pthread_mutex_lock etc to generate packets with increasing sequence number.
> 
> I am not very sure what am I missing, Please help me in this matter.

The way pktgen was written was for performance, which means I setup the mbufs at start time and do not touch them again till another start command. This causes packets to be sent out of order as I do not know when mbufs are returned to the free pool.

The only way to send a given sequence is to modified each packet as it is sent, which will impact performance. The random mode does just this type of packet mods and it would be a good model to look at if you want to modify the code.

> 
> _Function:_
> 
> void
> pktgen_tcp_hdr_ctor(pkt_seq_t *pkt, tcpip_t *tip, int type __rte_unused)
> {
>         uint16_t tlen;
> 
>         /* Zero out the header space */
>         memset((char *)tip, 0, sizeof(tcpip_t));
> 
>         /* Create the TCP header */
>         tip->ip.src         = htonl(pkt->ip_src_addr.addr.ipv4.s_addr);
>         tip->ip.dst         = htonl(pkt->ip_dst_addr.addr.ipv4.s_addr);
>         tlen                = pkt->pktSize -
>                 (pkt->ether_hdr_size + sizeof(ipHdr_t));
> 
>         tip->ip.len         = htons(tlen);
>         tip->ip.proto       = pkt->ipProto;
> 
>         tip->tcp.sport      = htons(pkt->sport);
>         tip->tcp.dport      = htons(pkt->dport);
> 
> *tip->tcp.seq        = htonl(DEFAULT_PKT_NUMBER);*
> 
>         tip->tcp.ack        = htonl(DEFAULT_ACK_NUMBER);
>         tip->tcp.offset     = ((sizeof(tcpHdr_t) / sizeof(uint32_t)) << 4);     /* Offset in words */
>         tip->tcp.flags      = ACK_FLAG;                                         /* ACK */
>         tip->tcp.window     = htons(DEFAULT_WND_SIZE);
>         tip->tcp.urgent     = 0;
> 
>         tlen                = pkt->pktSize - pkt->ether_hdr_size;
> 
>         tip->tcp.cksum      = cksum(tip, tlen, 0);
> }
> 
> -- 
> 
> Thanks,
> Shailja
> 

Regards,
Keith

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] How to update the sequence number in TCP packets using DPDK-pktgen?
  2017-10-09 13:42 [dpdk-dev] How to update the sequence number in TCP packets using DPDK-pktgen? Shailja Pandey
  2017-10-09 17:12 ` Wiles, Keith
@ 2017-10-10 23:00 ` Stephen Hemminger
  2017-10-11  0:10   ` Wiles, Keith
  1 sibling, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2017-10-10 23:00 UTC (permalink / raw)
  To: Shailja Pandey; +Cc: dev

On Mon, 9 Oct 2017 19:12:49 +0530
Shailja Pandey <csz168117@iitd.ac.in> wrote:

> pktgen_tcp_hdr_ctor(pkt_seq_t *pkt, tcpip_t *tip, int type __rte_unused)
> {
>          uint16_t tlen;
> 
>          /* Zero out the header space */
>          memset((char *)tip, 0, sizeof(tcpip_t));
> 
>          /* Create the TCP header */
>          tip->ip.src         = htonl(pkt->

FYI memset is a performance hit. Gcc generates a rep string instruction
which slows down CPU.. Better to do either set all fields individually
or fill in the pad values by doing structure assignment.

	*tip = (tcpi_ip_t) {
		.ip.src = htonl(pkt->ip_src_addr.addr.ipv4_saddr),
	...
	};

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] How to update the sequence number in TCP packets using DPDK-pktgen?
  2017-10-10 23:00 ` Stephen Hemminger
@ 2017-10-11  0:10   ` Wiles, Keith
  0 siblings, 0 replies; 4+ messages in thread
From: Wiles, Keith @ 2017-10-11  0:10 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Shailja Pandey, dev



> On Oct 10, 2017, at 6:00 PM, Stephen Hemminger <stephen@networkplumber.org> wrote:
> 
> On Mon, 9 Oct 2017 19:12:49 +0530
> Shailja Pandey <csz168117@iitd.ac.in> wrote:
> 
>> pktgen_tcp_hdr_ctor(pkt_seq_t *pkt, tcpip_t *tip, int type __rte_unused)
>> {
>>         uint16_t tlen;
>> 
>>         /* Zero out the header space */
>>         memset((char *)tip, 0, sizeof(tcpip_t));
>> 
>>         /* Create the TCP header */
>>         tip->ip.src         = htonl(pkt->
> 
> FYI memset is a performance hit. Gcc generates a rep string instruction
> which slows down CPU.. Better to do either set all fields individually
> or fill in the pad values by doing structure assignment.

Thanks for the info, will try and find some time to update pktgen.

> 
> 	*tip = (tcpi_ip_t) {
> 		.ip.src = htonl(pkt->ip_src_addr.addr.ipv4_saddr),
> 	...
> 	};
> 

Regards,
Keith

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-10-11  0:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-09 13:42 [dpdk-dev] How to update the sequence number in TCP packets using DPDK-pktgen? Shailja Pandey
2017-10-09 17:12 ` Wiles, Keith
2017-10-10 23:00 ` Stephen Hemminger
2017-10-11  0:10   ` Wiles, Keith

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).