[P4-dev] p4_parse_states and branch_on with HLIR

Antonin Bas antonin at barefootnetworks.com
Thu Dec 8 19:46:30 EST 2016


Hi,

I'm not sure I understand the question.
I can do the following:
>>> h.p4_parse_states["parse_ethernet"].branch_on
[<p4_hlir.hlir.p4_headers.p4_field object at 0x7f453a804dd0>]
>>> h.p4_parse_states["parse_ethernet"].branch_on[0]
<p4_hlir.hlir.p4_headers.p4_field object at 0x7f453a804dd0>
>>> str(h.p4_parse_states["parse_ethernet"].branch_on[0])
'ethernet.etherType'
>>> print h.p4_parse_states["parse_ethernet"].branch_on[0]
ethernet.etherType

Not sure what you were expecting instead.
In your case, you are asking the Python shell to evaluate an expression
which is a list containing a single object reference, which is what you
get. If I retrieve the first (and only) element in the list and I invoke
its __str__() method, then I get the full name of the field, because this
is how we implemented this method in the HLIR (
https://github.com/p4lang/p4-hlir/blob/master/p4_hlir/hlir/p4_headers.py#L42
).

Best,

Antonin

On Thu, Dec 8, 2016 at 4:07 PM, <hemant at mnkcg.com> wrote:

> This is the P4 code being tested in the p4-shell with the HLIR.
>
>
>
> header_type ethernet_t {
>
>     fields {
>
>         dstAddr : 48;
>
>         srcAddr : 48;
>
>         etherType : 16;
>
>     }
>
> }
>
>
>
> header ethernet_t ethernet;
>
>
>
> parser parse_ethernet {
>
>     extract(ethernet);
>
>     return select(latest.etherType) {
>
>         0x800 : parse_ipv4;
>
>         default: ingress;
>
>     }
>
> }
>
>
>
>
>
> I see the code in p4_hlir/hlir/p4_parser.py related to branch_on.
>
>
>
> For a parse_ethernet, I see the field_ref in the p4_parser.py code as
> ethernet.etherType.   Why can’t we make this field_ref available to the
> HLIR user?  When I used the following in the p4-shell, I get a reference
> value which gives me no clue that I have Ethernet.etherType.
>
>
>
> >>> h.p4_parse_states.items()[1][1].branch_on
>
> [<p4_hlir.hlir.p4_headers.p4_field object at 0x7f998d2854d0>]
>
>
>
> Thanks,
>
>
>
> Hemant
>
>
>
> _______________________________________________
> 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/20161208/0e9eea42/attachment-0002.html>


More information about the P4-dev mailing list