[P4-dev] Doubts Regarding use of Register

Antonin Bas antonin at barefootnetworks.com
Thu Aug 13 09:59:53 EDT 2015


Hi Swaroop,

Please see inline

On Wed, Aug 12, 2015 at 9:10 AM, Swaroop Thool <swaroopthool1991 at outlook.com
> wrote:

> Hi Antonin,
>
> Thank you for your reply.
>
> 1) Furthermore, few basic operations implemented in many languages making
> it difficult to implement in P4.
>
> Is there way in P4 where I can keep record of values for particular
> flow/input.
> For example, I have stored 3 values of 1st input(like 1st IP address) in 3
> different register arrays(one in each) through metadata field transfer. And
> again stored 3 values of 2nd input(like another IP address) in those 3
> different register arrays but at different locations. Again for next 3rd
> input and so on.
> Issue here is that ALL those values are in 3 register arrays and now I
> want to pick only that 3 values of 1st input. As metadata values are
> overwritten with latest values which cant rescue me. How to collect this 3
> values of each input when register array almost becomes full or when inputs
> are stopped? If this is not the way, can I create run-time instances of
> metadatas for each new input which will hold values of that particular
> input/flow? But again here how can I refer to 1st flow metadatas after few
> flows?
>

I am sorry but it is very difficult for me to understand what you are
trying to achieve here. I don't understand how you are filling your
register arrays (like a queue?), what you are putting there, how you want
to use it later...? If you can give some pseudo-code, I may be able to help
you better.


>
> 2)Is there any print statement in P4?
>

That would not mean much, given that a) P4 is not a purely imperative
language b) it is targeted at many kinds of target switches, including
hardware ones.
a) Where would you be able to print exactly? Only in actions, control flow,
some parts of the parse states?
b) Where would your message go?
Also, user strings are not supported in P4, which kind of makes it
difficult.
In a nutshell, I don't think this belongs into standard P4. If you are
writing P4 programs specifically for a software switch, you may be able to
extend the P4 language with print statements that will be interpreted by
your backend. But that would require modifying the frontend of the compiler
(parser, hlir).

We are working on a P4 debugger which will interact with the p4lang
software switch. This debugger would let you step through a P4 program and
print information about fields / metadata as you go. It will not be ready
to be released for a while though.


>
> 3)Are there any comparison statement among values (e.g  max, min) ?
>

I think it is in the works.


Best,

Antonin


>
>
> Thanks,
> Swaroop
>
>
>
> ------------------------------
> Date: Mon, 10 Aug 2015 08:31:32 -0700
>
> Subject: Re: [P4-dev] Doubts Regarding use of Register
> From: antonin at barefootnetworks.com
> To: swaroopthool1991 at outlook.com
> CC: p4-dev at p4.org
>
> Hi Swaroop,
>
> Sorry I sent you the wrong link, here is the correct one:
> https://github.com/p4lang/p4-hlir/blob/master/p4_hlir/frontend/primitives.json#L61
>
> As for your questions:
>
> 1) *myfield* is independent of the register, it should be a (any) header
> field / metadata field. Using the register name here will result in an
> error.
>
> 2) Please submit an issue here:
> https://github.com/p4lang/p4c-behavioral/issues for the Python error you
> are seeing. You can just avoid using 'static' in your P4 program for now. I
> am pretty sure this attribute is ignored by the behavioral-model anyway.
>
> Thanks,
>
> Antonin
>
> On Mon, Aug 10, 2015 at 8:07 AM, Swaroop Thool <
> swaroopthool1991 at outlook.com> wrote:
>
> Hi Antonin,
>
> Thanks for the reply.
> When I used the lines mentioned by you:
>
> register_read(*myfield*, r, runTimeValueofOtherMetadata);
> add_to_field(*myfield*, 0x01);
> register_write(r, runTimeValueofOtherMetadata, *myfield*);
>
> Which *"*
>
> *myfield" actually here related to register r ? Can I use different field
> reference(e.g. some metadata field ref) instead of it?*
> I was not getting compile error at start.It compiled for few lines
> however, later I got error stated as follows:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> */home/swaroop/p4-other/p4factory/submodules/p4c-behavioral/p4c_bm/shell.py
> p4src/sample.p4
> --gen-dir=/home/swaroop/p4-other/p4factory/targets/sample/build//bm/
> --thrift
> --public-inc-path=/home/swaroop/p4-other/p4factory/targets/sample/build//inc/p4_sim
> --p4-prefix=sampleWARNING: No error rule is defined for exclusive state
> 'pragma'WARNING: Token 'DIVIDE' defined, but not usedWARNING: Token
> 'PPHASH' defined, but not usedWARNING: Token 'MOD' defined, but not
> usedWARNING: There are 3 unused tokensparsing successfulSemantic warning:
> action 'no_op' is not reachable and will be removedsemantic checking
> successfulHeader type standard_metadata_t not byte-aligned, adding
> paddingvalidating:  Truevalidating:  Truevalidating:  Truevalidating:
> TrueGenerating files in directory
> /home/swaroop/p4-other/p4factory/targets/sample/build/bmtotal phv length
> (in bytes): 124Traceback (most recent call last):  File
> "/home/swaroop/p4-other/p4factory/submodules/p4c-behavioral/p4c_bm/shell.py",
> line 130, in <module>    main()  File
> "/home/swaroop/p4-other/p4factory/submodules/p4c-behavioral/p4c_bm/shell.py",
> line 124, in main    dump_yaml = args.dump_yaml)  File
> "/home/swaroop/p4-other/p4factory/submodules/p4c-behavioral/p4c_bm/smart.py",
> line 1141, in render_dict_create
> render_dict_populate_registers(render_dict, hlir)  File
> "/home/swaroop/p4-other/p4factory/submodules/p4c-behavioral/p4c_bm/smart.py",
> line 1076, in render_dict_populate_registers    r_info["binding"] =
> ("static", table)UnboundLocalError: local variable 'table' referenced
> before assignmentmake: ***
> [/home/swaroop/p4-other/p4factory/targets/sample/build//inc/p4_sim/rmt.h]
> Error 1P.S: Repository by the Link is not accessible *
>
> <https://github.com/barefootnetworks/p4-hlir/blob/master/p4_hlir/frontend/primitives.json#L61>
> https://github.com/barefootnetworks/p4-hlir/blob/master/p4_hlir/frontend/primitives.json#L61
>
>
> Thanks,
> Swaroop
>
> ------------------------------
> Date: Wed, 5 Aug 2015 14:29:07 -0700
> Subject: Re: [P4-dev] Doubts Regarding use of Register
> From: antonin at barefootnetworks.com
> To: swaroopthool1991 at outlook.com
> CC: p4-dev at p4.org
>
>
> 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
>
>
>
>
> --
> Antonin
>



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


More information about the P4-dev mailing list