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

Mihai Budiu mbudiu at vmware.com
Fri Feb 1 12:44:14 EST 2019


P4 does not do any field alignment or padding.
I am not very familiar with the tutorials VM, but I believe the code isn’t updated too frequently. That can be a good thing, since we occasionally introduce regressions in the compiler, but it may mean that you may not have all the latest features.

Mihai

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

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<mailto:hemant at mnkcg.com>> wrote:
Kamila,

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?

Yes.

> 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%7Ceb25ff66b14c46aca04708d6886c9033%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636846397203497217&sdata=QyNDLTrupmWU9ljpstw8AqiUhjx77Rt6lZb5%2Fe%2FIG0s%3D&reserved=0>

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/398b48b6/attachment-0001.html>


More information about the P4-dev mailing list