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

edgar costa molero edgarcosta at hotmail.es
Wed Oct 18 15:06:54 EDT 2017


Hi all,

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

table.apply();
table.apply();

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){
        tableA.apply();
    }
    else {
       //first call to table B
       tableB.apply();
          
       // MORE CODE X
   }

else {
    //second call to table B
    tableB.apply();
  
    //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,
Edgar


More information about the P4-dev mailing list