[P4-dev] Variable-length header problem

yunchen chang y2924uki at gmail.com
Wed May 3 06:46:53 EDT 2017


Hello everyone :

I have a question in parse tcp header.
Because tcp header sometimes have option data, the length is variable.
Therefore I parse tcp header like below :

parser parse_tcp {
    extract(tcp_header);
    set_metadata( intrinsic_metadata.tcp_hdr_len, tcp_header.dataOffset * 4
);
    return ingress ;
}

header_type tcp_header_t {
    fields {
        srcPort : 16;
        dstPort : 16;
        seqNo : 32;
        ackNo : 32;
        dataOffset : 4;
        res : 3;
        ecn : 3;
        ctrl : 6;
        window : 16;
        checksum : 16;
        urgentPtr : 16;
        options: *;
    }

    length : 4 * dataOffset ;
    max_length : 512;
}

But sometimes it will fail.
I changed the bm_sim/parser.cpp code(
https://github.com/p4lang/behavioral-model/blob/master/src/bm_sim/parser.cpp
,235~262)
to show some information that I need.
( document I attached )

The log file is below :

[18:31:09.106] [bmv2] [D] [thread 97342] [30.0] [cxt 0] Extracting header
'tcp_header'
[18:31:09.106] [bmv2] [D] [thread 97342] check :
[18:31:09.106] [bmv2] [D] [thread 97342] 74
[18:31:09.106] [bmv2] [D] [thread 97342] 34
[18:31:09.106] [bmv2] [D] [thread 97342] 32 // the header size is
[18:31:09.106] [bmv2] [D] [thread 97342] after check the header size is
[18:31:09.106] [bmv2] [D] [thread 97342] 32
[18:31:09.106] [bmv2] [D] [thread 97342] after extract the header size is
[18:31:09.106] [bmv2] [D] [thread 97342] 40
[18:31:09.106] [bmv2] [D] [thread 97342] bytes_parsed add done the header
size is
[18:31:09.106] [bmv2] [D] [thread 97342] 40
[18:31:09.106] [bmv2] [D] [thread 97342] [30.0] [cxt 0] Parser set: setting
field 'intrinsic_metadata.tcp_hdr_len' from expression, new value is 40

###### works fine, but why the size will change ( the header size is 40
bytes )

[18:31:09.108] [bmv2] [D] [thread 97342] [31.0] [cxt 0] Extracting header
'tcp_header'
[18:31:09.108] [bmv2] [D] [thread 97342] check :
[18:31:09.108] [bmv2] [D] [thread 97342] 54
[18:31:09.108] [bmv2] [D] [thread 97342] 34
[18:31:09.108] [bmv2] [D] [thread 97342] 40 // the header size
[18:31:09.108] [bmv2] [E] [thread 97342] [31.0] [cxt 0] Exception while
parsing: PacketTooShort

###### works fail, and the header size is 20 bytes not 40 bytes

I also sent the pcap file.

Thanks.

Best regards,
Abbie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170503/08176273/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: abbie_whatapp.pcap
Type: application/octet-stream
Size: 568 bytes
Desc: not available
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170503/08176273/attachment.pcap>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: parser_modify.cpp
Type: text/x-c++src
Size: 1526 bytes
Desc: not available
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170503/08176273/attachment.cpp>


More information about the P4-dev mailing list