[P4-dev] A variable in the header

Roshan sedar at oasis.uclouvain.be
Mon Nov 27 12:01:24 EST 2017


Hi,

A follow up question:

I am trying to store two state variables per switch in a header stack 
and doing the following. Seems it does not work. I am trying this on 
bmv2. No compilation errors. Is this the correct way to do what I am 
trying to do?

header_type state_var_t{

     fields {

          field_1: 8;

          field_2: 8;

    }

}

header state_var_t state[8]; // 8-node topology

parser start {
     extract(state[2]); //for example
     set_metadata(my_meta.field_1, state[2].field_1);
     set_metadata(my_meta.field_2, state[2].field_2);
      return ingress;
}

Any help would be great.

Thanks.
Roshan.


On 2017-11-21 22:55, Andy Fingerhut wrote:
> P4_14 and P4_16 languages have the notion of a header stack, which is 
> close to the idea of an array in other languages.
>
> As long as you can pick a maximum value for 'n' in your example that 
> you can live with, and compile with that maximum allowed value into 
> your program, the P4 language can implement that.
>
> There are several examples of using P4 for Inband Network Telemetry 
> (INT) that have a similar header, with not only a switch id recorded 
> in the header at each switch, but also statistics like the current 
> queue depth of the queue that the packet went through, or a timestamp 
> when the packet arrived at or left that device.  You should be able to 
> find some examples of this in the repository 
> https://github.com/p4lang/tutorials, but I don't have a recommendation 
> of which particular program to look at first in there, although pick 
> the most recent ones if you are interested in P4_16 source code, or 
> somewhat older ones if you are interested in P4_14.
>
> Andy
>
> On Tue, Nov 21, 2017 at 7:03 AM, Roshan <sedar at oasis.uclouvain.be 
> <mailto:sedar at oasis.uclouvain.be>> wrote:
>
>     Hi,
>
>     I am trying the following to keep a variable in packet header per
>     switch. I just want to know which way is the best way to do this.
>     This could grow the header largely as it appears.
>
>
>     header_type {
>
>           fields {
>
>                 switch_1: 8;
>
>                  switch_2: 8;
>
>                 ............
>
>                  switch_n: 8;
>
>         }
>
>     }
>
>
>     Thanks!
>
>
>     Regards,
>
>     Roshan.
>
>
>     _______________________________________________
>     P4-dev mailing list
>     P4-dev at lists.p4.org <mailto:P4-dev at lists.p4.org>
>     http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
>     <http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org>
>
>
>
>
> _______________________________________________
> 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/20171127/c9980097/attachment-0002.html>


More information about the P4-dev mailing list