[P4-dev] reading egress port from register

Roshan Se roshan.sedar at student.uclouvain.be
Sun Aug 6 12:01:32 EDT 2017


Thank Antonin.

Yes, I used p4-validate to check the code. yes, p4c-bmv2 works with no 
errors.

Regards,
Roshan.

On 2017-08-03 18:54, Antonin Bas wrote:
> Please see inline
>
> On Thu, Aug 3, 2017 at 2:57 AM, Roshan Se 
> <roshan.sedar at student.uclouvain.be 
> <mailto:roshan.sedar at student.uclouvain.be>> wrote:
>
>     Thanks Antonin.
>
>     But I am getting the following error when I use "
>     modify_field_rng_uniform" :
>
>     Semantic error: Invalid reference to modify_field_rng_uniform in
>     file /home/vagrant/p4src/test.p4: object was not defined
>     1 errors during semantic checking
>     Interrupting compilation
>
>
> It would be nice if you had included the command you used. 
> Nevertheless I can try to guess. modify_field_rng_uniform is specific 
> to bmv2. As a result, it it not know to p4-validate unless you provide 
> it the path to this file 
> (https://github.com/p4lang/p4c-bm/blob/master/p4c_bm/primitives.json) 
> using the --primitives command line option. If you use p4c-bmv2 
> directly instead of p4-validate, you will not see that error.
>
>
>
>     My piece of code:
>
>     header_type ingress_metadata_t {
>         fields {
>             port_metadata: 32;
>             reg_index: 32;
>         }
>     }
>
>     metadata ingress_metadata_t m;
>
>     register port_list_reg {
>        width: 32;
>        instance_count: 32;
>     }
>
>
>     action find_port() {
>          modify_field_rng_uniform(m.reg_index, 0, 32);
>          register_read(m.port_metadata, port_list_reg, m.reg_index);
>          modify_field(standard_metadata.egress_spec, m.port_metadata);
>      }
>
>
>     "How can I match this metadata value using a table?"
>
>     The table:
>
>     table route_pkt {
>         reads {
>            standard_metadata.ingress_port: exact;
>            //m.port_metadata: exact;
>            }
>         actions {
>             _drop;
>             find_port;
>         }
>         size: 3;
>     }
>
>     My question was in the table I should match
>     "standard_metadata.ingress_port: exact;" or
>
>     "m.port_metadata: exact;"  OR both?
>
>
> Still don't understand. One indicates the ingress port and the other 
> one you use to store the egress port. They're different. Match on 
> standard_metadata.ingress_port if you need to match on the ingress 
> port, match on m.port_metadata if you need to match on the egress 
> port, and match on both if you need to match on both to implement your 
> forwarding logic...
>
>
>
>     Thanks in advance,
>     Regards,
>     Roshan.
>
>
>     On 2017-08-01 20:47, Antonin Bas wrote:
>>     Hi,
>>
>>     It is pretty simple IMO:
>>     1) compute a random index for your register lookup. You can
>>     either use modify_field_with_hash_based_offset if the
>>     "randomness" comes from computing a hash over a list of fields
>>     (header fields or metadata fields), or modify_field_rng_uniform
>>     if you want a truly random number. Both of these primitives will
>>     let you get a value in the range of your choice, i.e. [0,
>>     register_size[.
>>     2) use register_read to read the value stored at the index
>>     computed in 1) in the register array. When calling register_read,
>>     you can either copy the value directly into
>>     standard_metadata.egress_spec or into one of your user-defined
>>     metadata field (and copy this value to
>>     standard_metadata.egress_spec later in the pipeline).
>>
>>     I am not sure what you mean by "How can I match this metadata
>>     value using a table?". There is no real difference between
>>     matching on a header field or a metadata field (except for
>>     validity considerations).
>>
>>     On Tue, Aug 1, 2017 at 4:05 AM, Roshan Se
>>     <roshan.sedar at student.uclouvain.be
>>     <mailto:roshan.sedar at student.uclouvain.be>> wrote:
>>
>>         Hi,
>>
>>         I am trying to pick the outgoing (a random fashion) from a
>>         register, where I have stored all the available outgoing
>>         ports in the register in advance. What I tried to do so far
>>         is that reading the register value into a metadata field and
>>         copy (modify_field) to egress_spec. I am not sure whether
>>         this is the right way to do.
>>
>>         How can I match this metadata value using a table? how can I
>>         do mod operation on the register value set?
>>
>>
>>         any help would be great. thanks in advance,
>>
>>         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>
>>
>>
>>
>>
>>     -- 
>>     Antonin
>
>
>
>
> -- 
> Antonin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170806/4c7e0405/attachment-0002.html>


More information about the P4-dev mailing list