Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
PSA: Using virtual functions to specify action chosen in action_selector #446
Here is the proposal I wrote up a while ago for action selectors using abstract functions to define the hash algorithm:
Some follow-up comments to the sample code above copied from this PR: #445
@mbudiu-vmw Abstract extern methods are an experimental feature that is already supported by the compiler.
Using variables available in the context, however, should not be supported.
@jafingerhut By "variables available in the context", I am guessing you mean by that, in the sample code that @antoninbas published, the use of meta.hash1 and meta.hash2 inside of the function my_hash?
If so, how would you propose to write code with equivalent behavior that avoided doing this?
@mbudiu-vmw If you need to capture variables from the environment they have to be passed explicitly as arguments. The problem is that we don't know when the virtual method is going to be called.
Regarding Mihai Budiu's comment that "we do not know when the virtual function is going to be called".
A possible response:
How does a compile know when to "read" the values of the table's search key fields? I think the answer to this is: The P4_16 language spec defines those values to be read at the same time in the execution as the table_name.apply(); call is made. That apply() call does not take those search key fields as parameters explicitly at the place in the source code where the apply() call occurs. It is understood by the compiler and P4 programmers that the search key fields will be read at that time.
The same could be defined for direction
Another approach would be to make these parameters explicit in the apply() call, between the parentheses after the