Standard_metadata value always zero

there are always some problems when i tried to read the hdr.tcp.syn and also some variables from standard_metadata.
When i used scapy to create a SYN packet (pkt=IP(dst=“”)/TCP(flags=“S”)) and sent it from h1 to h2 through p4 switch s1, the syn value and some standard_metadata variables were awalys 0 according to s1.log.

Is there any definition errors about my registers or my struct metadata?

I attached my complete p4 program with mu current s1.log with github link to help you understand my question better.
complete programm with p4utils and mininet

Thank you very much!!!
I expect for your suggestions!

Best regard,


One thing I noticed quickly about your program is that your parser extracts and Ethernet header, and if the ethertype field is 0x800 it then extracts an IPv4 header, but it does not then check the value of the protocol field in the IPv4 header, and if it is 6, extract a tcp header. If you do not extract the tcp header of the packet, then the variable hdr.tcp will always be invalid, and its fields will be uninitialized garbage, which simple_switch always fills in with 0 for you.

Another unusual thing about your program that I do not understand what you are trying to achieve is that the beginning of the apply block of your ingress control starts with these statements:, 0);
        direction.apply();, 0);, 0);, 0);, 0);

The line, 0); will read the register named reg_syn_value at address 0 (the 2nd parameter), and whatever value is stored there, it will modify hdr.tcp_t.syn to become that value stored at that address inside of reg_syn_value. Initially simple_switch initializes all entries of a register with 0, so that will change hdr.tcp_t.syn to 0 for the first packet.

Similarly for your later read calls shown in the code snippet above. I do not think that is what you intended to do, but that is what those statements will do, according to the definition of the read method, which you can find some documentation for it inside of the v1model.p4 include file here: p4c/v1model.p4 at main · p4lang/p4c · GitHub

I have not looked further in your program yet, because those two things look like you should definitely change them, in order for your program to have a chance of doing what you intend (which is not yet clear to me).

Thank you very much!
Noe i solved my problem with your attention.
And the statements at the begining of apply block is to debugging. I just wanted to know, whether there are current variables after parsering, however, i ignored reg_read will be initilized when there is no actual value to be written. So that the values are always zero as your mentioned. I changed the way to debug now.

Thank you very much!

Best regard,


simple_switch implements a function called log_msg() that is useful for debugging, too. See the v1model.p4 include file that I linked in my earlier message.