[P4-dev] HLIR and p4_action

hemant at mnkcg.com hemant at mnkcg.com
Sat Nov 5 10:00:08 EDT 2016


Antonin,

 

A follow-up question.  I don’t see any build instructions/script to show how the HLIR is built.   What if a user is changing a .py file in the HLIR code and would like to rebuild the HLIR? 

 

Thanks,

 

Hemant

 

From: Antonin Bas [mailto:antonin at barefootnetworks.com] 
Sent: Thursday, November 03, 2016 12:35 PM
To: hemant at mnkcg.com
Cc: p4-dev at lists.p4.org
Subject: Re: [P4-dev] HLIR and p4_action

 

Hi Hemant,

There is no straightforward way of checking whether an action is user-defined or a primitive action. You can look at the call_sequence attribute of the p4_action object (h.p4_actions[action_name].call_sequence). If this is an empty list, then it is likely to be a primitive action -although in theory it can also be a user-defined action with an empty body.

Usually, we do not iterate over the p4_actions dictionary directly. Rather, we walk the table graph and for each table we look at the actions it is calling. For each of these actions, we then look at the flat_call_sequence attribute, which is the sequence of action primitives this action is calling (and these are guaranteed to be ALL action primitives as we have flattened the call sequence).

 

On Thu, Nov 3, 2016 at 5:05 AM, <hemant at mnkcg.com <mailto:hemant at mnkcg.com> > wrote:

I am playing with stateful.p4 included in the tests directory with the p4-hlir.  The stateful.p4 source code contains only two actions shown below.

 

action hop(ttl, egress_spec) {

    add_to_field(ttl, -1);

    modify_field(standard_metadata.egress_spec, egress_spec, 0xFFFFFFFF);

}

 

action hop_ipv4(egress_spec) {

    hop(ipv4.ttl, egress_spec);

}

 

I am using the p4-shell to inspect hlir info.   The h.p4_actions includes a kitchen sink of actions followed by the two actions implemented in the stateful.p4 source code.  What if a user of the HLIR would like to see his/her defined methods only?

 

>>> h.p4_actions.items()

[('subtract', p4_action.subtract), ('no_op', p4_action.no_op), ('remove_header', p4_action.remove_header), ('modify_field_with_hash_based_offset', p4_action.modify_field_with_hash_based_offset), ('add_header', p4_action.add_header), ('execute_meter', p4_action.execute_meter), ('bit_and', p4_action.bit_and), ('subtract_from_field', p4_action.subtract_from_field), ('register_write', p4_action.register_write), ('add', p4_action.add), ('modify_field', p4_action.modify_field), ('count', p4_action.count), ('truncate', p4_action.truncate), ('clone_egress_pkt_to_egress', p4_action.clone_egress_pkt_to_egress), ('bit_or', p4_action.bit_or), ('pop', p4_action.pop), ('register_read', p4_action.register_read), ('bit_xor', p4_action.bit_xor), ('recirculate', p4_action.recirculate), ('resubmit', p4_action.resubmit), ('add_to_field', p4_action.add_to_field), ('drop', p4_action.drop), ('copy_header', p4_action.copy_header), ('generate_digest', p4_action.generate_digest), ('push', p4_action.push), ('clone_ingress_pkt_to_egress', p4_action.clone_ingress_pkt_to_egress), ('hop', p4_action.hop), ('hop_ipv4', p4_action.hop_ipv4), ('drop_pkt', p4_action.drop_pkt)]

 

Thanks,

 

Hemant


_______________________________________________
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




-- 

Antonin

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


More information about the P4-dev mailing list