[P4-dev] P4 variable fields

shubham bhardwaj bhardwajshubham2011 at gmail.com
Wed Jul 19 09:05:05 EDT 2017

Hello Andy,

Thanks for your reply, its really helpful. But i am facing another issue in
initializing the variable length. I am able to initialize variable length
of the field options for IPv4, as already explained by Antonin. However, I
am not able to do the same for Profinet RT header, which is a low-level
protocol. I am not sure if i am doing something wrong or is there any other

//Ethernet header
header_type ethernet_t {
    fields {
        dstAddr: 48;
        srcAddr: 48;
        etherType: 16;

//Profinet header
header_type Profinet_RT_t {
    fields {
frameID: 16;
        profinetcyclic: *;
length: frameID * 20;
max_length: 512;

On Tue, Jul 18, 2017 at 4:57 PM, Andy Fingerhut <andy.fingerhut at gmail.com>

> The only ways I know of in P4 programs to fill in the values of
> variable-length fields of headers is to extract() them from a packet being
> parsed.  From there, they can be copied (without any modifications) to
> other instances of the same type of header, by copy_header() in P4_14, or
> in P4_16 simply assigning the value of one header to another of the same
> type.
> I believe it would be nice if P4_16 were extended to include ways to copy
> parts of varbit fields and copy them into fixed-width fields/variables, or
> vice versa, and I have suggested such a language addition on this Github
> issue: https://github.com/p4lang/p4-spec/issues/264   It will probably be
> some time before significant-sized changes will be made to the P4_16 spec,
> and there is no consensus yet on whether such a change is of interest to a
> wider audience.
> Andy
> On Tue, Jul 18, 2017 at 6:07 AM, shubham bhardwaj <
> bhardwajshubham2011 at gmail.com> wrote:
>> Dear All,
>> I am working on a case where a single field in a header can vary in
>> length. In that case, is it possible to initialize it using variable fields.
>> --
>> Thanks & Regards
>> Shubham Bhardwaj
>> *Technical University of Darmstadt*
>> +49 17643686394 <+49%20176%2043686394>
>> _______________________________________________
>> P4-dev mailing list
>> P4-dev at lists.p4.org
>> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org

Thanks & Regards
Shubham Bhardwaj
*Technical University of Darmstadt*
+49 17643686394
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170719/9c46369f/attachment-0002.html>

More information about the P4-dev mailing list