[P4-dev] (P4-16) About header_union behavior

Rui Miguel rmiguel at lasige.di.fc.ul.pt
Thu Apr 20 14:00:43 EDT 2017


(I've recently tested the latest version of the compiler and found that extracting or emitting individual header fields is no longer acceptable. The compiler demands the parameter for extract() to be header, stack or union. I assumed unions were really being implemented into the language, so I snooped the project files and found the header_union construct.)

How closely does header_union resemble C unions? Suppose I defined:

 header A_h {
	bit<8> fixedField;
	varbit<8> varField;

 header B_h {
	bit<8> fixedF;
	varbit<16> varField;

 header_union U_hu {
	A_h a;
	B_h b;

Let's say I extract into a. If I then read/write to b.fixedF, can I expect it to yield equivalent results as if I were reading/writing to a.fixedField? This behavior would be extremely desirable for my purposes.

Also, will header_union have an isValid() method? (currently they don't seem to have one)

~ Rui Miguel

More information about the P4-dev mailing list