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

Mihai Budiu mbudiu at vmware.com
Fri Feb 1 12:17:54 EST 2019

If you use a relatively recent version of the compiler it should support nested structs.


From: P4-dev <p4-dev-bounces at lists.p4.org> On Behalf Of Kamila Soucková
Sent: Friday, February 1, 2019 9:03 AM
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?

> https://github.com/p4lang/p4-spec/pull/719/files<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fp4lang%2Fp4-spec%2Fpull%2F719%2Ffiles&data=02%7C01%7Cmbudiu%40vmware.com%7Caaa8a4fe4b9e4d46a0cf08d68867341b%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636846374176460385&sdata=ZI%2BQ6iJNq8ibUk8xZB2pkscCVO5P0YrjHO9897v%2FCQk%3D&reserved=0>

Is this change already implemented in bmv2, or is it a future thing? Does it mean that I could change the design to use a "struct > header > struct"-like wrapping (instead of my current "struct > struct > header")?

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/ea86ee13/attachment.html>

More information about the P4-dev mailing list