-
Notifications
You must be signed in to change notification settings - Fork 332
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
Support expressions as l-values for action primitives #838
Comments
A workaround for the header stack field case would be to introduce one or more new types for the "type value object" in the bmv2 JSON. For example, we could introduce |
@antoninbas thanks for all the debugging, narrowing down the problem and filing this issue. |
What is the bmv2 expression engine? Is it code in https://github.com/p4lang/p4c/blob/master/backends/bmv2/common/expression.h ? |
No, it's this: https://github.com/p4lang/behavioral-model/blob/master/include/bm/bm_sim/expressions.h. At the moment it only supports returning Edit: only the reference variant is needed for |
The bmv2 expression engine can now returns references to bmv2 primitive objects (Data, Header, ...) when the expression being evaluated is an lvalue. This means that we can now handle assignments to complex lvalue expressions which do not statically resolve to a field / header / union. One example would be an assignment to a header stack field accessed through a runtime index. Unit tests were added, although at the moment they do not support all the possible cases (e.g. expressions which evaluate to a header union). The JSON version number was bumped up to 2.23. Even though no additions were made to the format, we now support additional cases and the documentation now includes an example of a "complex" assignment statement. Fixes #838
I opened a patch for this. Probably not perfect but it covers the specific case we looked at (assignments to a header stack field accessed with a runtime index) and many others. I think the expression evaluation engine is now generic enough that a lot of the code can be simplified and many special cases can be removed. I added a few unit tests, but I also tested with the attached JSON file. which corresponds to the following program:
Sending the following packet with Scapy:
should lead to the following output packet in bmv2 log message:
From a syntax perspective, nothing changed in the bmv2 JSON format. But of course, some work is required in the bmv2 compiler backend to leverage this new "feature" and support a P4 program like the one above. |
Thanks so much! |
I have a PR open to make changes to p4c bmv2 backend. I can look into your changes from today and see what I have to change in the backend - thanks. |
@antoninbas Out of curiosity, what happens if the run-time index is out of bounds of the size of the header stack array? A 32-bit index for a header stack ... :-) |
I suppose the behavioral-model should add a check For a switching asic, the asic tends to include an ALU for arithmetic operations. The ALU bus (assume 32 bits wide) won't allow numbers greater than 32 bits. |
@jafingerhut at this time, you should get a nice uncaught C++ |
Thanks for the info. A process crash seems reasonable to me. At least it will not be a quietly wrong answer. |
The bmv2 expression engine can now returns references to bmv2 primitive objects (Data, Header, ...) when the expression being evaluated is an lvalue. This means that we can now handle assignments to complex lvalue expressions which do not statically resolve to a field / header / union. One example would be an assignment to a header stack field accessed through a runtime index. Unit tests were added, although at the moment they do not support all the possible cases (e.g. expressions which evaluate to a header union). The JSON version number was bumped up to 2.23. Even though no additions were made to the format, we now support additional cases and the documentation now includes an example of a "complex" assignment statement. Fixes #838
See #835 (comment)
The bmv2 expression engine currently only supports returning
Data
objects, and notData &
references. This means that expressions cannot be used as l-values for theassign
action primitive. See https://github.com/p4lang/behavioral-model/blob/master/include/bm/bm_sim/actions.h#L278.This makes it difficult to support assignments to a header stack field accessed with a runtime index (
<hs>[<index expression>].<field> = X
in P4). If one tries to hand-generate a JSON for such an assignment (using an expression involving theaccess_field
anddereference_header_stack
operations on the left-hand side), one will run into this assertion: https://github.com/p4lang/behavioral-model/blob/master/include/bm/bm_sim/actions.h#L294The text was updated successfully, but these errors were encountered: