p4lang / behavioral-model

The reference P4 software switch
Apache License 2.0
541 stars 329 forks source link

Simple switch - Invalid packet data #978

Closed fruffy closed 3 years ago

fruffy commented 3 years ago

This is related to #976. I have a program with fairly diverse and complex headers. When trying to feed this program into simple_switch, I get the following error message:

fruffy@fruffy /s/P/p4_tv (master) [1]> python p4c/backends/bmv2/run-bmv2-test.py p4c -v -b -bd p4c/build/  /storage/Projekte/p4_tv/tests/tmp/gauntlet_various_ops-bmv2.p4                                                                                      
Matplotlib created a temporary config/cache directory at /home/fruffy/.config/matplotlib because the default path (/tmp/matplotlib-i463udat) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.                                                                                                                  
Writing temporary files into  ./tmpnqi47t2u                                                                          
Executing  p4c/build//p4c-bm2-ss -o ./tmpnqi47t2u/gauntlet_various_ops-bmv2.json /storage/Projekte/p4_tv/tests/tmp/gauntlet_various_ops-bmv2.p4
Exit code  0
Check for  /storage/Projekte/p4_tv/tests/tmp/gauntlet_various_ops-bmv2.stf
Running model
Running simple_switch --log-file switch.log --log-flush --use-files 0 --thrift-port 9170 --device-id 80 -i 0@pcap0 .././tmpnqi47t2u/gauntlet_various_ops-bmv2.json
Calling target program-options parser
Adding interface pcap0 as port 0 (files)
Running simple_switch_CLI --thrift-port 9170
STF Command: packet 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0
*** Invalid packet data 0000000000000000000000000000000000000000000000000000000000000000000000000000000
STF Command: expect 0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF 03 00 03 00 71 3E 30 0F 00 00 02 00 01 11 11 01 01 01 00 00 00 02 FE 10 0
Obtaining JSON from switch...
Done
Control utility for runtime P4 table manipulation
RuntimeCmd: 
simple_switch exit code -15
Execution completed
Comparing outputs
*** Expected 1 packets on port 0 got 0
*** Full list of 1 expected packets on port 0:
***     packet # 1: 0000000000000000000000000000FF03000300713E300F0000020001111101010100000002FE100
*** Full list of 0 received packets on port 0:
Log file:
[13:03:58.176] [bmv2] [D] [thread 40356] Set default default entry for table 'tbl_gauntlet_various_opsbmv2l100': gauntlet_various_opsbmv2l100 - 
[13:03:58.176] [bmv2] [D] [thread 40356] Adding interface pcap0 as port 0
[13:03:58.177] [bmv2] [I] [thread 40356] Starting Thrift server on port 9170
[13:03:58.177] [bmv2] [I] [thread 40356] Thrift server was started
[13:03:58.177] [bmv2] [D] [thread 40360] Pcap reader: starting PcapFilesReader 1
[13:03:58.287] [bmv2] [D] [thread 40360] Pcap reader: end of all input files
[13:03:58.356] [bmv2] [T] [thread 40372] bm_get_config

*** Test failed

What could be the reason for this? One thing I can think of is that I am using bools, ints, and uneven bit values in the header.

gauntlet_various_ops-bmv2.p4.txt gauntlet_various_ops-bmv2.stf.txt

fruffy commented 3 years ago
header BOOL {
    bool a;
    bit<7> padding;
}

struct Headers {
    ethernet_t eth_hdr;
    BOOL b;
}

struct Meta {}

parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t sm) {
    state start {
        transition parse_hdrs;
    }
    state parse_hdrs {
        pkt.extract(hdr.eth_hdr);
        pkt.extract(hdr.b);
        transition accept;
    }
}

control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
    apply {
        // bool evaluation
        h.b.a = 1 == 1;
    }
}

Reducing the program to this snippet causes the same error. So bools and uneven bits are not supported?

antoninbas commented 3 years ago

The Invalid packet data error message is output by the STF framework, not bmv2: https://github.com/p4lang/p4c/blob/eab654a4e06c823e1876ef52e4a0dd70cf5763cc/backends/bmv2/bmv2stf.py#L425. The error is produced when the packet cannot be sent on the veth. It does seem that there is something fishy with your input packet: you are missing half a byte (... 00 00 0).