[dpdk-dev] How to update the sequence number in TCP packets using DPDK-pktgen?

Shailja Pandey csz168117 at iitd.ac.in
Mon Oct 9 15:42:49 CEST 2017


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



More information about the dev mailing list