[P4-dev] Any examples of "register" ?

David Gatting gattingd at gmail.com
Fri Sep 30 19:04:06 EDT 2016


On Sat, Sep 17, 2016 at 1:49 PM, Antonin Bas <antonin at barefootnetworks.com>

> Hi David,
> 1) Registers with a "layout" attribute (as opposed to a "width" attribute)
> are not supported. I believe that a new version of the P4 spec is going to
> be released, which will not mention the "layout" attribute.
> I was not able to reproduce this statement: "When I tried the same with
> *layout* & *instance_count*, I didn't get any error." I always get the
> CRITICAL error message whenever I use the "layout" attribute. If you could
> provide a P4 program that supports your statement, that would be great; I
> would be able to fix the compiler so that it always rejects "layout".

[Sarat] Will try this out one more time and see if I hit it again. Any
particular reason to not support "layout" ? Seems like a very useful
construct to have to keep all the state pertaining to a given entity
together in one place. Is this due to compiler complexity ?

I tried out rest of the suggestions below and it worked out fine, although
had to define bunch of register arrays that could have been made more
convenient with "layout" support.


> 2) As for a register example, there is one (along with a small demo) here:
> https://github.com/p4lang/tutorials/tree/master/examples/register
> Since only the "width" attribute is supported, if you need to store
> multiple fields in a register entry, you actually need to instantiate
> multiple register arrays in P4 (one per field).

> 3) You can use the register_write and register_read primitive:
> *register_write(<register array>, <index>, <value>)*
> *register_read(<field destination>, <register array>, <index>)*
> These primitives are not described in the spec right now, but they will be
> in the next P4v1 spec version that I mentioned earlier.

> Let us know if you need help with the register example.
> Best,
> Antonin
> On Fri, Sep 16, 2016 at 9:12 PM, David Gatting <gattingd at gmail.com> wrote:
>> Hi,
>> Are there any examples of "register" usage ?
>> 1) I tried out register with *layout* & *direct* keywords and got an
>> error (shown below) while compiling the p4 file.
>> *CRITICAL:gen_json:registers with layout not supported*
>> When I tried the same with *layout* & *instance_count*, I didn't get any
>> error. Is this only partially supported ?
>> 2) How do I use runtime_CLI.py to do register write and read ? especially
>> if register with layout where there could be multiple fields. I tried
>> "register_write <register_name> <index> <val>" (on a register with width
>> and instance_count, however write failed, complaining that index in
>> invalid).
>> 3) While processing the packet, I would like to modify few fields of a
>> register entry as part of one of the actions.
>> Is there any working example showing all this ?
>> Thanks,
>> D.
>> _______________________________________________
>> P4-dev mailing list
>> P4-dev at lists.p4.org
>> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
> --
> Antonin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20160930/1562cac5/attachment-0002.html>

More information about the P4-dev mailing list