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

Kamila Součková kamila at ksp.sk
Fri Feb 1 12:41:02 EST 2019


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.

Best,
Kamila

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

> Kamila,
>
>
>
> Please see in line below.
>
>
>
> *From:* Kamila Součková <kamila at ksp.sk>
> *Sent:* Friday, February 01, 2019 12:03 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?
>
>
>
> > 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?
>
>
>
> Yes.
>
>
>
> > 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.
>
>
>
> Hemant
>
>
>
> 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!
>
> Best,
> Kamila
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20190201/b94f4f12/attachment.html>


More information about the P4-dev mailing list