[P4-dev] apply() a table more than once in different branches of a conditional

Mihai Budiu mbudiu at vmware.com
Wed Oct 18 16:00:01 EDT 2017

This is a restriction of a particular P4 compiler back-end; it models limitations of the behavioral model, which in turn models restrictions on some kinds of pipelined hardware architectures.

If you are saying that you found a program that at runtime does something different than the spec says it should do, then this is a compiler bug; please give us more details so we can reproduce this bug.


-----Original Message-----
From: P4-dev [mailto:p4-dev-bounces at lists.p4.org] On Behalf Of edgar costa molero
Sent: Wednesday, October 18, 2017 12:07 PM
To: p4-dev at lists.p4.org
Subject: [P4-dev] apply() a table more than once in different branches of a conditional

Hi all,

If you apply the same table in a sequential way i.e: 



The compiler complains: it says that the program requires a cycle containing table.

However, if you place the calls to apply() in different if branches such that only one can be executed, the compiler does not complain….but weird things start happening. If we consider the following code:

if (condition 1){

    if (condition 2){



    else {

       //first call to table B



       // MORE CODE X


else {

    //second call to table B



    //MORE CODE Y    


In the code snippet above we can see that tableB can be called if (condition 1 and not condition 2), and the second call if (not condition 1). You can see also that after this calls there is some code that is different: code x and code y. So far, so good. But when you send a packet to the switch that will trigger the call to the first tableB.apply() (I verified checking the switch’s log), Code Y is executed instead of Code X. 

I understand that for some hardware limitations you don’t allow calls to the same table twice. But then, why is the compiler not complaining in the scenario above ? And why  is the apply() function returning/jumping to “CODE Y” ?

Kind regards,

P4-dev mailing list
P4-dev at lists.p4.org

More information about the P4-dev mailing list