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

adopted and modified P4-14 description on parser value set to P4-16 #602

Merged
merged 7 commits into from
May 17, 2018

Conversation

hanw
Copy link
Contributor

@hanw hanw commented Mar 26, 2018

P4-14 spec has a section about parser value set that is still applicable to P4-16 with some modifications. I added that section in this PR

set name may be referenced in parse state transition conditions (the value list
in a case entry).

Parser Value Sets contain values only, no header types or state transition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this paragraph is no longer necessary; the way you use value sets would allow combinations which make this statement untrue.

Value sets are declared locally within a parser. They should be declared before
being referenced in parser `keysetExpression`.

Given a type `T` for the type parameter of the value set, the type of the value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this in the description of the select expression.

`keysetExpression` in the same `select` expression. If there is a mismatch, the
compiler must raise an error.

Parser Value Sets support a `size` annotation to provide hints to the compiler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You just changed this in another proposal, so it is best to describe here the argument.

to reserve hardware resource to implement the value set. The semantics of the
size annotation is TBD.

The run time API for updating parser value sets must allow value and mask pairs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably here a bit less specific: we can just say that the value set is populated by the control-plane by a method specified in the other spec - the control-plane API.

Copy link
Contributor

@mihaibudiu mihaibudiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also please include a complete code example in the spec?

runtime, one could write:

~ Begin P4Example
value_set<bit<16>>(4) pvs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definition is still not enough to generate a good API, because there is no way to name the fields, the values for which are going to be passed when value_set entries are going to be populated. This is especially important in case value_set is used to match against a tuple. Neither it is clear whether the values passed should be single or value/mask pair, range or anything else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this example there is just one field.
We can allow a value_set take a struct type, and in that case the fields can be named like the struct fields.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vgurevich : this spec does not specify anything about the control-plane API. The way values are specified should be part of that other document.

Copy link
Contributor

@mihaibudiu mihaibudiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to support struct types for the type of the value set.

runtime, one could write:

~ Begin P4Example
value_set<bit<16>>(4) pvs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this example there is just one field.
We can allow a value_set take a struct type, and in that case the fields can be named like the struct fields.

runtime, one could write:

~ Begin P4Example
value_set<bit<16>>(4) pvs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vgurevich : this spec does not specify anything about the control-plane API. The way values are specified should be part of that other document.

@vgurevich
Copy link
Contributor

@mbudiu-vmw ,

We can allow a value_set take a struct type, and in that case the fields can be named like the struct fields.

This is not a bad approach as long as the struct is flat. For more complicated structs it might be a little too much.

@vgurevich
Copy link
Contributor

@mbudiu-vmw

this spec does not specify anything about the control-plane API. The way values are specified should be part of that other document.

I believe that one of the goals of P4 is the ability to generate control plane APIs for all the objects, specified in the program. While it is true that the spec does not have to describe the APIs, we need to ensure that the object description in P4 contains all the information required for such API generation. If it does not, then the other spec cannot be written correctly anyways.

In this particular case, the match type is required to properly generate the APIs, but is missing (in my opinion). The same can be said about the field names unless we converge on the struct or some other approach.

@mihaibudiu
Copy link
Contributor

mihaibudiu commented Apr 16, 2018

I think that the match_type is really very target-specific; as a proof, v1model.p4 contains the definition of match_type range. Probably this should really be an annotation:

@implement(ternary)
value_set<S>(10) set;

@vgurevich
Copy link
Contributor

@mbudiu-bfn ,

I think that the significance of match_type in value_sets is no different than the one in tables and thus we need to use a very similar mechanism. It should be a part of the language, IMHO.

@jafingerhut
Copy link
Collaborator

Regarding match_kind for value sets, do you think for multi-field value sets, e.g. that match on a struct, that it should be possible to specify a different match_kind for each field, like you can in a table?

If so, it seems we are inching our way towards a value set specified much like a P4 table, except with no list of actions.

@hanw
Copy link
Contributor Author

hanw commented Apr 16, 2018

Attempted to write down what Vlad is saying,

header data_h {
  bit<32> da;
  bit<32> db;
}
struct my_packet {
  data_h data;
}
struct my_metadata {
  data_h[2] data;
}
parser MyParser(packet_in b, out my_packet p, inout my_metadata m, inout standard_metadata_t s) {
    value_set pvs {
        key = { p.data.da : exact; }
    }
    state start {
        b.extract(p.data);
        transition select(p.data.da) {
            pvs: accept;
            0x810: foo;
        }
    }
    state foo {
        transition accept;
    }
}

@hanw
Copy link
Contributor Author

hanw commented Apr 16, 2018

Here is a link to the solution that the P4runtime working group came up to solve the naming problem for field list which is not part of P4-16.
https://github.com/p4lang/PI/blob/master/proto/docs/p4runtime_type_serialization.md

The associated proto file for p4types.
https://github.com/p4lang/PI/blob/master/proto/p4/p4types.proto

To summarize, the issue with naming the field in value_set is not unique to value_set, it is also an issue with digest. The solution proposed by the P4 runtime work group should work for both primitives. The current implementation for value_set follows the guideline provided by the p4runtime working group.

@vgurevich
Copy link
Contributor

@hanw This might work, but will limit the ability to use the same value_set in multiple parser states. I would suggest using names that are not bound to anything, more like formal parameters for a function.

@vgurevich
Copy link
Contributor

@hanw ,

Here is a link to the solution that the P4runtime working group came up to solve the naming problem for field list which is not part of P4-16. https://github.com/p4lang/PI/blob/master/proto/docs/p4runtime_type_serialization.md

I might be wrong but I do not see a solution for naming individual members of an unnamed field list there. If these are just numbers, this is not a good API solution for value_sets.

@hanw
Copy link
Contributor Author

hanw commented May 7, 2018

I updated p4c frontend to allow struct type for the value set p4lang/p4c#1271
to address the issue of the naming objects in the value set in runtime API.

We (Vlad, Calin and I) had an offline discussion on the PR. To summarize the discussion, the proposal for value_set must satisfy the following constraints:

  1. it must have a ‘size’.
  2. it must have a ‘name’.
  3. it must support simple datatypes, such as BitType and TupleType.
  4. it must be able to generate meaningful API.
  5. it must support more complex datatype, such as StructType(to be able to name the fields)
  6. it must support sharing between parser states.
  7. it must support multiple match_kind: exact, ternary, range.

The current proposal of

value_set<T> name (size);

satisfies all 7 requirements, but needs an annotation on the value_set instance to specify the match_kind. An option was proposed to integrate the match_kind in the struct as:

struct vsk_t {
    bit<16> field : ternary;
}

But the discussion on this new syntax for struct should happen in a different thread as part of the modularity discussion.

We suggest the working group to accept this PR.

@mihaibudiu
Copy link
Contributor

You should then use annotations on struct fields:

struct vsk_t {
    @match(ternary)
    bit<16> field;
}

@hanw
Copy link
Contributor Author

hanw commented May 9, 2018

@mbudiu-vmw can we merge this PR?

a type `T` for the type parameter of the value set, the type of the value set
is `set<T>`. The type of the value set must match to the type of all other
`keysetExpression` in the same `select` expression. If there is a mismatch, the
compiler must raise an error. A parser value set accepts bit type, tuple type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of the values in the set must be one of bit<>, tuple or struct

functionality, P4 supports the notion of a Parser Value Set. This is a named
set of values with a run time API to add and remove values from the set.

Value sets are declared locally within a parser. They should be declared before
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and can be used as a label in a select expression.

Value sets are declared locally within a parser. They should be declared before
being referenced in parser `keysetExpression`.

Parser Value Sets support a `size` argument to provide hints to the compiler to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can either cross-reference the previous section or give another example here.

@mihaibudiu
Copy link
Contributor

I would appreciate if @vgurevich and @jafingerhut would take a look as well.

@hanw hanw force-pushed the description-on-value-set branch from 6cd50a4 to df27eb7 Compare May 9, 2018 21:13

~ Begin P4Example
struct vsk_t {
@match(ternary)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be a problem for the compiler, and/or the language definition, if this annotation name were 'match_kind' instead of 'match', so it was the same as 'match_kind' used elsewhere in P4_16? This is a low priority issue, in my mind. 'match' is fine if there are any problems using 'match_kind' as an annotation name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match_kind is a keyword used to declare new match kinds. We may be able to tweak the grammar to make it work, but it may be confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use match_kind triggers a frontend error. I will use match for now.

syntax error, unexpected MATCH_KIND
  @match_kind
   ^^^^^^^^^^
error: 1 errors encountered, aborting compilation```

}
~ End P4Example

The above example allows the runtime API to populate upto 4 different
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend "up to" instead of "upto" for English prose.

~ Begin P4Example
struct vsk_t {
@match(ternary)
bit<16> port;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there is no @match annotation on a field?

Two possibilites I can think of:
(a) It is an error
(b) It defaults to @match(exact)

(b) seems reasonable to me, but whatever the choice, it would be good to say in the spec.

Is this syntax expected to be allowed? value_set<@match(ternary) bit<16>>(4) pvs; Or should we simply say that if you want a single non-exact field, you must put that field into a struct by itself, with the desired @match annotation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified the text to specify default is match(exact) and single non-exact field must be in a struct by itself.

compiler must raise an error. The type of the values in the set must be one of
bit<>, tuple, and struct.

For example, to allow control plane API to specify TCP reserved ports at
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend adding "the" here: "to allow the control plane API"

@jafingerhut
Copy link
Collaborator

@mbudiu-vmw I have added my review comments.

@jafingerhut
Copy link
Collaborator

@hanw It would also be good to edit Appendix D "Restrictions on compile time and run time calls" to mention value_set's and their proposed restrictions, everywhere that a P4 table is mentioned already. value_set's might not have identical restrictions to tables, but they are a new stateful element that is very similar to them, and people might look to that section for ideas on where they need to support it, vs. need not.

@mihaibudiu
Copy link
Contributor

@hanw : I think we are close to merging this; @jafingerhut makes some good points that maybe you can address.

@hanw
Copy link
Contributor Author

hanw commented May 17, 2018

I modified Appendix D to specify the restrictions on value-set, please take a look and verify the text is accurate.

@@ -6680,6 +6752,7 @@ e.g. `bit<32> x = rand.get();`.
| control | no | yes | no | no | no |
| extern | yes | yes | yes | yes | no |
| table | no | yes | no | no | no |
| value-set | no | no | no | no | no |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be reasonable to put a "yes" in the "parser state" column for the value-set row, if you also say above after the sentence:

"Calling a parser, control, or table means invoking its apply() method."

something like this:

"Calling a value-set means using it in a select expression."

@hanw
Copy link
Contributor Author

hanw commented May 17, 2018

make sense, I fixed that column.

@jafingerhut
Copy link
Collaborator

@hanw @mbudiu-vmw Newest changes all look good to me.

@hanw hanw merged commit a0a9f4d into master May 17, 2018
@hanw hanw deleted the description-on-value-set branch May 17, 2018 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants