[P4-dev] [bmv2] Why does the <H> headers struct forbit nested structs?

hemant at mnkcg.com hemant at mnkcg.com
Fri Feb 1 13:00:25 EST 2019

To get away from the old tutorials, what you could do is the following:


1.	Just download p4c and build it.
2.	See several bit-vector nested structs examples in p4c/testdata/p4_16_samples/*bvec*.p4.  Also see the issue383-bmv2.p4 program in the same directory. 
3.	Just use this example command to compile a P4 program:  p4c/build/$./p4c-bm2-ss –std p4-16 ../testdata/ p4_16_samples/issue383-bmv2.p4




From: Kamila Součková <kamila at ksp.sk> 
Sent: Friday, February 01, 2019 12:41 PM
To: hemant at mnkcg.com
Cc: p4-dev at lists.p4.org
Subject: Re: [P4-dev] [bmv2] Why does the <H> headers struct forbit nested structs?


Thank you, that makes sense! I am attempting to update the toolchain now (I am using the tutorials VM, which presumably does not checkout the commits which include this).


Presumably the answer is yes, but a clarifying question: if I put the structs inside headers, they are going to be packed, not aligned, correct?


Thanks again for your help, I really appreciate it.





On Fri, Feb 1, 2019 at 6:12 PM <hemant at mnkcg.com <mailto:hemant at mnkcg.com> > wrote:



Please see in line below.


From: Kamila Součková <kamila at ksp.sk <mailto:kamila at ksp.sk> > 
Sent: Friday, February 01, 2019 12:03 PM
To: hemant at mnkcg.com <mailto:hemant at mnkcg.com> 
Cc: p4-dev at lists.p4.org <mailto:p4-dev at lists.p4.org> 

Subject: Re: [P4-dev] [bmv2] Why does the <H> headers struct forbit nested structs?


> Since around January 7th, 2019, p4c supports a nested bit-vector struct inside a P4 header. However, since the p4c bmv2 backend does not support nested structs, a midend pass flattens the header. See the spec changes that are being made to p4c regarding the code that was checked in.

Ah, okay, so this is a general problem with nested structs, rather than a specific problem with the `headers_t` struct, correct? 




> https://github.com/p4lang/p4-spec/pull/719/files


Is this change already implemented in bmv2, or is it a future thing? 


No.  Please see my comment above which says ‘”the bmv2 backend does not support any nested structs and thus a midend pass flattens any nested structs found inside a header.  Thus, you could still use the bmv2 backend. 


Does it mean that I could change the design to use a "struct > header > struct"-like wrapping (instead of my current "struct > struct > header")?


Correct.  Now p4c supports nested bit-vector struct inside a P4 header.   For a long time, P4 has supported struct inside struct.   If you are using emit(), then the members of the struct are restricted to only emittable types which are types that can be serialized.  Thus a nested struct contains only Type_Bits, Type_SerEnum, Type_Bool.  You code below looks fine.   Use p4test or p4c-bm2-ss to compile your test program. 



For the record, the code I am trying to compile is something along the lines of:


header scion_isdas_h {
    bit<12>   isd;
    bit<20>    as;

struct scion_addr_header_t {
    scion_isdas_h dst_isdas;

    // more header-type fields...



struct scion_header_t {
    scion_common_h      common;
    scion_addr_header_t addr;

    // more struct-type fields...



> Off hand, I don’t know of an alternative target that supports nested structs. 


Thanks for the info.

Thanks a lot!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20190201/668f17e6/attachment-0001.html>

More information about the P4-dev mailing list