[P4-dev] p4_parse_states and branch_on with HLIR

hemant at mnkcg.com hemant at mnkcg.com
Thu Dec 8 21:19:42 EST 2016



Ok, that is it.   My question was why does not Python code not check if the list has one element, the code prints branch_on[0] rather than a single object reference?   Seeing the design in p4_headers.py, it is fine to keep the code as is.  If a user wants, the user can check the size of the list and if the size is 1, use the branch_on[0].


I also figured out branch_on[0] by adding this print to p4_parser.py:  print self.branch_on[0].  This is why I also got the string full name before I sent my email. 



hemant at ubuntu:~/p4-hlir$ ./bin/p4-shell ~/simple.p4 

WARNING: No error rule is defined for exclusive state 'pragma'

parsing successful

semantic checking successful

Header type standard_metadata_t not byte-aligned, adding padding



TABLE:  routing

HLIR successfully constructed, access with variable 'h'

Python 2.7.10 (default, Oct 14 2015, 16:09:02) 

[GCC 5.2.1 20151010] on linux2

Type "help", "copyright", "credits" or "license" for more information.



Thanks, I am all set.




From: Antonin Bas [mailto:antonin at barefootnetworks.com] 
Sent: Thursday, December 08, 2016 7:47 PM
To: hemant at mnkcg.com
Cc: p4-dev at lists.p4.org
Subject: Re: [P4-dev] p4_parse_states and branch_on with HLIR




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])


>>> print h.p4_parse_states["parse_ethernet"].branch_on[0]



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).






On Thu, Dec 8, 2016 at 4:07 PM, <hemant at mnkcg.com <mailto: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 {


    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>]






P4-dev mailing list
P4-dev at lists.p4.org <mailto:P4-dev at lists.p4.org> 




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

More information about the P4-dev mailing list