Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSA: Using virtual functions to specify action chosen in action_selector #446

Open
jafingerhut opened this issue Oct 20, 2017 · 5 comments

Comments

@jafingerhut
Copy link
Contributor

commented Oct 20, 2017

The comments below are copied from another issue regarding action selectors in the PSA spec. I wanted to preserve these comments in an open issue, since it is more difficult to remember where they are if they only exist in closed PRs or issues.

@jafingerhut

This comment has been minimized.

Copy link
Contributor Author

commented Oct 20, 2017

Copied from this comment by @antoninbas: #445 (comment)

Here is the proposal I wrote up a while ago for action selectors using abstract functions to define the hash algorithm:

struct H { };
struct M {
    bit<32> hash1;
    bit<32> hash2;
}

// my proposal
extern action_selector_psa<T> {
    action_selector_psa(bit<32> size);
    abstract T my_hash();
}

control IngressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) {

    action drop() { smeta.drop = 1; }

    // an example instantiation
    action_selector_psa<bit<16> > (32w1024) as = {
        bit<16> my_hash() {
            bit<16> res;
            // meta is in scope, which is what we need
            hash(res, HashAlgorithm.crc16, 16w0, {meta.hash1, meta.hash2}, 16w65535);
            return res;
            // ideally return hash(...)
        }
    };

    table indirect_ws {
        key = { }
        actions = { drop; NoAction; }
        const default_action = NoAction();
        implementation = as;
    }

    apply {
        indirect_ws.apply();
    }

};
@jafingerhut

This comment has been minimized.

Copy link
Contributor Author

commented Oct 20, 2017

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.
It probably should be considered for inclusion in P4-XX for XX > 16.

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.

@jafingerhut

This comment has been minimized.

Copy link
Contributor Author

commented Oct 21, 2017

Note that this idea may require some extension to the P4_16 language spec as well.

@jafingerhut

This comment has been minimized.

Copy link
Contributor Author

commented Apr 11, 2018

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 in or inout parameters of a virtual function that uses variables from the environment -- the values are read at the same time the table's search key field values are read.

Another approach would be to make these parameters explicit in the apply() call, between the parentheses after the apply. They would become parameters in the table definition explicitly.

@mbudiu-vmw

This comment has been minimized.

Copy link
Contributor

commented Apr 11, 2018

P4 does not have a notion of action selectors. If we standardize action selectors and describe in the spec when they are executed and how then we can also describe when the virtual function gets called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.