[P4-dev] Looping in P4, Apply table multiple times and Timers?

David Hancock dhancock at cs.utah.edu
Tue Jun 28 16:30:12 EDT 2016

Tu Dang,

These are the kinds of things I think about a lot.

"Looping within a compound action or the control flow in P4":  you 
cannot do this directly.  There are no explicit loop constructs in P4.  
This is a language design choice motivated by the types of high-speed 
packet processing hardware architectures that are among the target 
platforms for P4.  BUT you can still do a form of looping by using the 
resubmit (invoked in ingress, returns the packet to the parser) and 
recirculate (invoked in egress, returns the packet to the parser and 
ingress pipeline) primitives.  These primitives accept a field list 
parameter where you can specify those fields that should retain their 
values when the packet shows up at the parser again.  Note that this 
will incur a performance penalty.  If your program always resubmits 
packets N times, you can expect throughput to be cut by a factor of N, 
more or less.

"Apply a table multiple times": again, this is not normally allowed, 
except through the resubmit and recirculate primitives.  Another way 
around this limitation is to have functionally identical tables that are 
only different in name.  This costs memory but only for the table 
declarations and not for action declarations, because multiple tables 
can be associated with the same action(s).

"Timers to fire an action": I'm not sure exactly what you want to do, 
but the closest thing to this I can think of is to have a timer in the 
controller that triggers the controller to communicate with the switch 
in one of various ways* and cause the switch to execute the action.

*Ways include sending a table update via the control channel (e.g., the 
Thrift port used by a bmv2 sswitch), indicating that while the switch is 
processing the next packet it should take the desired action, or sending 
a special packet that your program recognizes as the signal to execute a 
certain action.


On 06/28/2016 02:02 PM, Huynhtu Dang wrote:
> Dear all,
> My goal is to get the values of a dynamic range of register elements. I’m facing with several obstacles that I wonder if someone has already experienced.
> - Looping within a compound action or the control flow in P4
> - Apply a table multiple times
> - Timers to fire an action
> Looking forward to your advices.
> Best,
> Tu Dang
> _______________________________________________
> P4-dev mailing list
> P4-dev at lists.p4.org
> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org

More information about the P4-dev mailing list