[P4-dev] applying the same table multiple times

Andy Fingerhut andy.fingerhut at gmail.com
Fri Nov 23 15:23:16 EST 2018

One more quick thought I forgot while typing the previous reply:

You could create the two (or more) tables via copy and paste, but with
P4_16 you can also create a control with a table defined inside of it, and
then instantiate that control multiple times inside your ingress control,
and call each instantiation one time.  That causes the P4_16 compiler to
effectively do the code duplication for you, and the implementations of
each table will always remain identical to each other, if you ever make
changes to its one definition in the source code.


On Fri, Nov 23, 2018 at 11:44 AM Andy Fingerhut <andy.fingerhut at gmail.com>

> If you don't mind just making two tables with similar names and are
> otherwise the same in all ways, e.g. including the control plane making the
> same updates to both, that is a workaround for this limitation.
> In some high speed ASIC implementations, that is the only way to do it,
> and it seems that bmv2 and the p4c bmv2 backend inherited that limitation.
> See https://github.com/p4lang/p4c/issues/457 for some discussion.  The
> compiler _could_ of course be modified to duplicate the table for you, but
> it doesn't right now -- you can do it manually as suggested above.
> Andy
> On Fri, Nov 23, 2018 at 8:09 AM cs.lev <cs.lev at gmx.com> wrote:
>> Dear All,
>> I have run into a simple problem.
>> I have simple application that parses different header types, e.g.,
>> For specific TCP packets I want to some special forwarding, which
>> contains some conditions, i.e., as conditions cannot be defined in
>> actions, I need to implement my conditions in the Ingress control's
>> apply {} part.
>> Such condition would be a state of a bit, e.g., if SYN then forward, if
>> ACK then drop (for simplicity! of course this does not make sense :)).
>> On the other hand, to provide working communications, I need to handle
>> ICMP and ARP packets as well.
>> So, what I am doing is that I have a switch with 2 ports, and a
>> port_forward table, which forwards packets from port 0 to port 1 and
>> vice versa.
>> And in the Ingress control's apply part, I have conditions for the
>> types of the packets, but in essence I would like to apply port_forward
>> table mulitple times, as I need to pass ARP,ICMP and even the modified
>> TCP packets as well from one port to the other, however the following
>> code snippet does not work:
>> if(hdr.ethernet.isValid())
>>         {
>>             if(hdr.arp.isValid())
>>             {
>>                 port_forward.apply();
>>             }
>>             else if(hdr.ipv4.isValid())
>>             {
>>                 if(hdr.ipv4.protocol == IP_PROTO_ICMP)
>>                 {
>>                     port_forward.apply();
>>                 }
>>                 if(hdr.ipv4.protocol == IP_PROTO_TCP &&
>> hdr.tcp.isValid())
>>                 {
>>                         //do the mumbojumbo with the packets (or this
>> part could also
>> be done in a separate action)
>>                         port_forward.apply();
>>                 }
>>         ...
>> compiler raises the following error:
>> Program is not supported by this target, because table
>> MyIngress.port_forward has multiple successors
>>   table port_forward
>> This means for me that one table can only be applied once, however not
>> just my stupid example would require to 'recirculate packets to already
>> visited table'.
>> Is there any way to resolve my issue? Can I call apply a table several
>> times if I jump from ingress to egress back-and-forth (I don't know
>> whether this would even work for jumping back only once).
>> Or can I call somehow an action without applying a table (but of course
>> matching on the input port (for instance in my case) would be known)?
>> So far, as a workaround I created the same tables over and over with
>> different names (e.g., port_forward, arp_forward, icmp_forward) but
>> fundamentally with the same look (match-action table). At least the
>> actions can be reused in the tables, so they don't need to be redefined
>> in a similar way.
>> Thanks,
>> cs.lev
>> _______________________________________________
>> P4-dev mailing list
>> P4-dev at lists.p4.org
>> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20181123/f82039d5/attachment.html>

More information about the P4-dev mailing list