P4c compiler returns error when I use header stack's next

Hi,
when I want to parse header stack, I compare the header field value with the [ .lastIndex ]value of header stack, It returns [Use of uninitialized parser value] error ,I could not solve this, could you please help me?

I use the same parser logic as ng-sdn tutorial, I don’t know why it was wrong, my code is as follows

state parser_srv6_list{
    pkt.extract(hdr.srh_segment_list.next);
    bool next_segment = (bit<32>)hdr.srh.segment_left - 1 == (bit<32>)hdr.srh_segment_list.lastIndex;
    transition select(next_segment){
        true:accept_state;
    }
}

the compiler returns

error: Use of uninitialized parser value  [ ingress::parse_ipv4 : (bit<1>)(0 ++ ingress::hdr.srh.segment_left + 4294967295 == ingress::hdr.srh_segment_list.lastIndex); (bit<1>)(0 ++ hdr.srh/srh.segment_left + 4294967295 == hdr.srh_segment_list.lastIndex); ]
Number of errors exceeded set maximum of 1

Hi!

I think that if you need help with any Tofino-related topic, Intel has a very friendly forum that can help you with this particular issue. Here: Intel Connectivity Research Program . :slight_smile:

Cheers,

What I want to ask is P4 itself, not a specific target, is there a solution to this? Thanks a lot.

The P4 compiler for some target devices in some cases accept different subsets of the P4 language features. I do not know if that is the case here, but if you want to know if the code you have written can be accepted by the most general P4 compiler, you can try the open source p4test command on your program, which is part of the open source p4c compiler. If you do not already have it installed on a system accessible to you, probably the fastest way to try it out is to install a fresh Ubuntu 20.04 Linux system, e.g. in a VM, and run the install-p4dev-v5.sh script on it (takes about 3 minutes if your Internet connection is not too slow – only downloads about 250 MBytes in the install process), documented here: p4-guide/README-install-troubleshooting.md at master · jafingerhut/p4-guide · GitHub

@aoiland – if you just want to check if the program is a formally valid P4 code, you can always use p4test backend that comes as a part of p4c. For TNA the verification would be done like this:

p4test -I <path-to-tna-include-files> -D__TARGET_TOFINO__=1 my_program.p4

Having said that, each target backend has the right to reject any P4 program if it can’t be compiled for that target, irrespective of whether it is syntactically valid or not. Therefore, if you want your P4 program to work on a certain target, you need to follow it’s rules and constraints, which I’ll be happy to discuss in the appropriate forum.

Happy hacking,
Vladimir

Ok,I got it. Thanks a lot.

I’’ try latter,the p4 program in Tofino is the same as v1model, but it compiles wrong.

Okay, I’ll check it out. I know the difference between different targets