[P4-dev] Doubts Regarding use of Register

Antonin Bas antonin at barefootnetworks.com
Wed Aug 5 17:29:07 EDT 2015


Hi Swaroop,

Thanks for your interest. I will give more details inline. However the
basic answer to all your questions is that P4 registers are almost not
supported at all (yet) in the behavioral model software switch. Some
stateful operations are supported, but differe from what is in the spec.

On Wed, Aug 5, 2015 at 12:08 PM, Swaroop Thool <swaroopthool1991 at outlook.com
> wrote:

> Hi all ,
>
> Thanks for the answers. Few more questions:
> If I write-
>        register r {
>             width : 9;
>             static : table_which_invokes_register;
>             instance_count : 500;
>             attributes : saturating; }
>
> 1) If I create register array of 500(cells) as above, is it like 1-D array
> whose location can be read/write? How to access that because I am getting
> syntax error when I used modify_field(). What is the proper syntax if I
> want to put some value at run-time generated location of array, say 50?
>

You can do this, just not with modify_field(). You need to use
register_read() and register_write(), which are described here:
https://github.com/barefootnetworks/p4-hlir/blob/master/p4_hlir/frontend/primitives.json#L61
Something like this should work in an action:
register_read(*my_field*, r, 50);
add_to_field(*my_field*, 0xaba);
register_write(r, 50, *my_field*);
As you can see you can read / write a register, and once the value is in a
field, you can do arithmetic on it. However you cannot operate directly on
the register (for now).


>
> 2) Further extension to above,How can I store value 1 at location say, 50
> in register array of 500 created above and later increment value 1 to 2
> when same location is encountered and maintain those values?
>

I guess the above answers your question?


>
> 3)What is layout declaration(instead of width declaration) means which
> require header_type_name?
>

It is a convenient way of accessing register values using field names, no
more. Let's say I have the following code:

header_type my_header_type {
  fields {
    fA: 16;
    fB: 32;
    fC: 16;
  }
}

register r2 {
  layout: my_header_type;
  instance_count: 100;
}

Then each cell in your register would be 64-bit wide. You would be able to
write things like this: r2[50].fB
So it is just a way to give "meaning" to the bits in a register cell.
However this is NOT supported in the p4lang software switch.


>
> 4) If I create metadata for a packet to copy some value into its field,
> will value get updated with new one for another packet when same metadata
> is used for example : modify_field (metadata, somevalue) ?If yes, then
> how to maintain value of individual packets as I dont want to loose that
> values ?
>

registers will let you maintain state, the value of metadata will be
overwritten with each new packet


>
> 5)OR should I use add_field() in above. What is the difference between
> both?
>

I don't see how this relates to 4)


Also since you are using it in your code, I need to point out that
attributes (e.g. saturating) are not supported in the switch yet.

Best,

Antonin


>
>
> Thanks,
> Swaroop
>
> _______________________________________________
> P4-dev mailing list
> P4-dev at p4.org
> Listinfo - http://mail.p4.org/mailman/listinfo/p4-dev_p4.org
> Archives - http://mail.p4.org/pipermail/p4-dev_p4.org/
>



-- 
Antonin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20150805/7ce63d17/attachment-0001.html>


More information about the P4-dev mailing list