[P4-dev] reading egress port from register

Roshan Se roshan.sedar at student.uclouvain.be
Thu Aug 3 05:57:49 EDT 2017


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


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?


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170803/54f9a1e6/attachment-0002.html>


More information about the P4-dev mailing list