Incorrect checksums on generated packets

526 views
Skip to first unread message

Rauf Babayev

unread,
May 23, 2016, 8:19:33 PM5/23/16
to TRex Traffic Generator
Hi T-Rex team,

T-Rex is not recalculating checksums after replacing src and destination ips and macs.
I've tried both with v1.99 and v2.02.
For example here is wrong_ip.pcap:
 
reading from file ./cap2/wrong_ip.pcap, link-type EN10MB (Ethernet)
192.168.56.102.1039 > nld-net-ip.as51430.net.http: Flags [S], cksum 0x7103 (correct), seq 4101411529, win 64240, options [mss 1460,nop,nop,sackOK], length 0
17:11:58.223198 IP (tos 0x0, ttl 57, id 38819, offset 0, flags [DF], proto TCP (6), length 48)
    nld-net-ip.as51430.net.http > 192.168.56.102.1039: Flags [S.], cksum 0x2146 (correct), seq 1218249673, ack 4101411530, win 65535, options [mss 1260,sackOK,eol], length 0


And this is what I'm capturing on ubuntu machine while running t-rex with wrong_ip.yaml:


tcpdump: listening on enp4s0f0, link-type EN10MB (Ethernet), capture size 262144 bytes
17:11:12.818144 90:e2:ba:7f:4b:3a (oui Unknown) > 90:e2:ba:a5:eb:aa (oui Unknown), ethertype IPv4 (0x0800), length 62: (tos 0x0, ttl 128, id 1935, offset 0, flags [DF], proto TCP (6), length 48)
    17.0.1.0.1024 > 49.0.0.128.http: Flags [S], cksum 0x7103 (incorrect -> 0xb91e), seq 4101411529, win 64240, options [mss 1460,nop,nop,sackOK], length 0
17:11:12.828176 90:e2:ba:a5:eb:aa (oui Unknown) > 90:e2:ba:7f:4b:3a (oui Unknown), ethertype IPv4 (0x0800), length 62: (tos 0x0, ttl 56, id 38819, offset 0, flags [DF], proto TCP (6), length 48)
    49.0.0.128.http > 17.0.1.0.1024: Flags [S.], cksum 0x2146 (incorrect -> 0x6961), seq 1218249673, ack 4101411530, win 65535, options [mss 1260,sackOK,eol], length 0

The same true also for http_simple.yaml

Is there way to force t-rex to recalculate checksums?

hanoh haim

unread,
May 24, 2016, 12:42:33 AM5/24/16
to Rauf Babayev, TRex Traffic Generator
Hi Rauf,
for both Stateless and Stateful TCP/UDP cs is not fixed only IPv4 header.
The reason is performance. Routers/Switch/L7 features don't care about this TCP/UDP CS.
There is a hardware accelerators in most of the NIC but it is limited to a few types of packets.

Thanks,
Hanoh
--
You received this message because you are subscribed to the Google Groups "TRex Traffic Generator" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trex-tgn+u...@googlegroups.com.
To post to this group, send email to trex...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trex-tgn/df5c0772-5350-4c23-a5e1-18f01b508356%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Hanoh
Sent from my iPhone

Rauf Babayev

unread,
May 25, 2016, 6:46:33 PM5/25/16
to TRex Traffic Generator, ra...@babayev.com
Thanks Hanoh,

Is it possible to add this as an additional command line argument?
Or if you could give some clue about  where in the sources I can add that functionality.
I would like to fork the repo and add that functionality to my own copy.

Regards,
Rauf
To unsubscribe from this group and stop receiving emails from it, send an email to trex-tgn+unsubscribe@googlegroups.com.

To post to this group, send email to trex...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trex-tgn/df5c0772-5350-4c23-a5e1-18f01b508356%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hanoh haim

unread,
May 26, 2016, 11:43:39 AM5/26/16
to Rauf Babayev, TRex Traffic Generator
Hi, 
I can give some pointers. 
How would like to start 
Stateful or Stateless?

Thanks
Hanoh
To unsubscribe from this group and stop receiving emails from it, send an email to trex-tgn+u...@googlegroups.com.

To post to this group, send email to trex...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trex-tgn/df5c0772-5350-4c23-a5e1-18f01b508356%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Hanoh
Sent from my iPhone

--
You received this message because you are subscribed to the Google Groups "TRex Traffic Generator" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trex-tgn+u...@googlegroups.com.

To post to this group, send email to trex...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Rauf Babayev

unread,
May 26, 2016, 7:23:16 PM5/26/16
to TRex Traffic Generator, ra...@babayev.com
Hi Hanoh,

I would like to start with stateful.

Thanks
Rauf
To unsubscribe from this group and stop receiving emails from it, send an email to trex-tgn+unsubscribe@googlegroups.com.

To post to this group, send email to trex...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trex-tgn/df5c0772-5350-4c23-a5e1-18f01b508356%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Hanoh
Sent from my iPhone

--
You received this message because you are subscribed to the Google Groups "TRex Traffic Generator" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trex-tgn+unsubscribe@googlegroups.com.

To post to this group, send email to trex...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trex-tgn/8888bdee-0f7c-49ef-9b89-7e97db8728eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hanoh haim

unread,
May 27, 2016, 10:20:58 AM5/27/16
to Rauf Babayev, TRex Traffic Generator
Hi Rauf, 

There are a few paths in the code, let enhance first the simple path for one flow template. 

- Start with a simple use case 'cap2/simple_http.yaml' and see that TCP CS is fixed
- The code that needs to be changed is this "if"

inline void CFlowPktInfo::update_pkt_info(char *p,
                                   CGenNode * node){
..

        ipv4->updateCheckSum();
    }


    /* replace port base on TCP/UDP */
    if ( m_pkt_indication.m_desc.IsTcp() ) {
        TCPHeader * m_tcp = (TCPHeader *)(p +m_pkt_indication.getFastTcpOffset());
        BP_ASSERT(m_tcp);
        /* replace port */
        if ( port_dir ==  CLIENT_SIDE ) {
            m_tcp->setSourcePort(src_port);
        }else{
            m_tcp->setDestPort(src_port);
        }

      <<<< update_TCP_CS
      
- To update the TCP CS you should calculate the CS of the original fields that are expected to be changed 
(src_ip,dst_ip,src_port,dst_port,ttl) offline and save the results in the descriptor 
And then do the diff between the new fields and old pseudo CS
You can use those functions 
// checksum and csToSubtract are two uint16_t cs fields AS THEY APPEAR INSIDE A PACKET !
uint16_t pkt_SubtractInetChecksum(uint16_t checksum, uint16_t csToSubtract);

// checksum and csToAdd are two uint16_t cs fields AS THEY APPEAR INSIDE A PACKET !
uint16_t pkt_AddInetChecksum(uint16_t checksum, uint16_t csToAdd);

- follow the descriptor 
  m_pkt_indication.m_desc.IsUdp() 

- I suspect that doing this operation won't be CPU intensive and we can add it in default.
 We could consider enabling/disable using follow this example of --learn 
 
        if ( unlikely ( CGlobalInfo::is_learn_mode()  ) ){               <<===


- To test your code, I suggest to use the simulator and not TRex 
to build the simulator do this 

build
$cd $root/linux
$./b configure 
$./b build

to run it 

from $root

$./bp-sim-64-debug -f cap2/http_simple.yaml -o a.pcap
 a.pcap should have fixed TCP CS of this template 
you can gdb using

gdb --args /bp-sim-64-debug -f cap2/http_simple.yaml -o a.pcap

b $function


thanks
Hanoh

Hanoh
To unsubscribe from this group and stop receiving emails from it, send an email to trex-tgn+u...@googlegroups.com.

To post to this group, send email to trex...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trex-tgn/df5c0772-5350-4c23-a5e1-18f01b508356%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Hanoh
Sent from my iPhone

--
You received this message because you are subscribed to the Google Groups "TRex Traffic Generator" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trex-tgn+u...@googlegroups.com.

To post to this group, send email to trex...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trex-tgn/8888bdee-0f7c-49ef-9b89-7e97db8728eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Hanoh
Sent from my iPhone

--
You received this message because you are subscribed to the Google Groups "TRex Traffic Generator" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trex-tgn+u...@googlegroups.com.

To post to this group, send email to trex...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages