-
Notifications
You must be signed in to change notification settings - Fork 82
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
Conversation
p4-16/spec/P4-16-spec.mdk
Outdated
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 |
There was a problem hiding this comment.
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.
p4-16/spec/P4-16-spec.mdk
Outdated
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 |
There was a problem hiding this comment.
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.
p4-16/spec/P4-16-spec.mdk
Outdated
`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 |
There was a problem hiding this comment.
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.
p4-16/spec/P4-16-spec.mdk
Outdated
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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?
p4-16/spec/P4-16-spec.mdk
Outdated
runtime, one could write: | ||
|
||
~ Begin P4Example | ||
value_set<bit<16>>(4) pvs; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
p4-16/spec/P4-16-spec.mdk
Outdated
runtime, one could write: | ||
|
||
~ Begin P4Example | ||
value_set<bit<16>>(4) pvs; |
There was a problem hiding this comment.
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.
p4-16/spec/P4-16-spec.mdk
Outdated
runtime, one could write: | ||
|
||
~ Begin P4Example | ||
value_set<bit<16>>(4) pvs; |
There was a problem hiding this comment.
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.
@mbudiu-vmw ,
This is not a bad approach as long as the struct is flat. For more complicated structs it might be a little too much. |
@mbudiu-vmw
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. |
I think that the match_type is really very target-specific; as a proof, v1model.p4 contains the definition of
|
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. |
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. |
Attempted to write down what Vlad is saying,
|
Here is a link to the solution that the P4runtime working group came up to solve the naming problem for The associated proto file for p4types. 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. |
@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. |
@hanw ,
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. |
71615d9
to
278afae
Compare
I updated p4c frontend to allow struct type for the value set p4lang/p4c#1271 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:
The current proposal of
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:
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. |
You should then use annotations on struct fields:
|
@mbudiu-vmw can we merge this PR? |
p4-16/spec/P4-16-spec.mdk
Outdated
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
p4-16/spec/P4-16-spec.mdk
Outdated
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 |
There was a problem hiding this comment.
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.
I would appreciate if @vgurevich and @jafingerhut would take a look as well. |
6cd50a4
to
df27eb7
Compare
|
||
~ Begin P4Example | ||
struct vsk_t { | ||
@match(ternary) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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```
p4-16/spec/P4-16-spec.mdk
Outdated
} | ||
~ End P4Example | ||
|
||
The above example allows the runtime API to populate upto 4 different |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
p4-16/spec/P4-16-spec.mdk
Outdated
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 |
There was a problem hiding this comment.
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"
@mbudiu-vmw I have added my review comments. |
@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. |
@hanw : I think we are close to merging this; @jafingerhut makes some good points that maybe you can address. |
I modified Appendix D to specify the restrictions on value-set, please take a look and verify the text is accurate. |
p4-16/spec/P4-16-spec.mdk
Outdated
@@ -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 | |
There was a problem hiding this comment.
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."
make sense, I fixed that column. |
@hanw @mbudiu-vmw Newest changes all look good to me. |
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