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

Kamila Součková kamila at ksp.sk
Fri Feb 1 14:37:57 EST 2019


Hi,

I do need the changes, as I want to structure my headers (in order to be
able to create modular sub-parsers, which I want to do because I want my
code to be usable as a library in other projects). The latest version of
the compiler works for me.

Thanks a lot!

Best,
Kamila

On Fri, 1 Feb 2019, 20:15 Andy Fingerhut, <andy.fingerhut at gmail.com> wrote:

> Kamila:
>
> I may be missing the mark in what you are asking for, but if you want some
> collection of headers that do not contain structs (only bit<W>, int<W>, and
> varbit<W> type fields inside of headers), and also some user-defined
> metadata that contain fields of any types at all, including other structs,
> then I believe that worked before any of Hemant's recent changes, as long
> as the user-defined metadata was put into type <M> in v1model, outside of
> type <H>.  There is no help that I can see trying to put a user-defined
> metadata structs inside of type <H> rather than <M>.
>
> If you do actually want to embed structs inside of headers, then yes you
> need Hemant's changes.
>
> Andy
>
> On Fri, Feb 1, 2019 at 10:01 AM <hemant at mnkcg.com> wrote:
>
>> 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
>>
>>
>>
>> Hemant
>>
>>
>>
>> *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.
>>
>>
>>
>> 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
>>
>> _______________________________________________
>> P4-dev mailing list
>> P4-dev at lists.p4.org
>> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20190201/db2d3305/attachment.html>


More information about the P4-dev mailing list