-
Notifications
You must be signed in to change notification settings - Fork 334
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 expression of type as objectValue #835
Comments
The JSON file generated from new p4c bmv2 backend via this PR (p4lang/p4c#2118) is attached. Please also look for DEREFERENCE_STACK keyword in the JSON file. |
Attached files are a bit more convenient than multi-page text copy-and-paste for users of the content. You do have to rename them with a .txt suffix, or enclose them in a .zip file, for Github to take them as attachments. |
A smaller example would have helped as well. I doubt you need such a large program to demonstrate the issue.
|
BTW, I doubt that we need any changes to the supported JSON format or the P4Objects.cpp implementation. |
When Chris Dodd suggested the above format in ``["hdr", "ml", "idx"]` , you said, "Chris figured out the format quick" which made me think the format is correct. This is why I developed the JSON output in this format. I can change the format to a tuple. Also, let me prepare a shorter P4 program. |
A day or two back, github failed to attach a .txt file for me. This is why I gave up and had to add the contents of the file. |
Isn't the new JSON format such that the expression is a JsonObject? Then how does P4Objects.cpp handle the expression? |
In the PR (p4lang/p4c#2118) branch, I trimmed down the P4 test to test runtime array index and checked in code. Please see The above P4 code includes |
After trimming the P4 program, I generated new JSON and attached the JSON output in this Issue - thanks. I will look into change p4c code next to generate a tuple. |
Chris had the JSON structure right. It's fairly easy to figure out the exact syntax by looking at other generated JSON files and at the documentation.
I don't understand the question, but looking at your new JSON file, I can see that even the basic structure is wrong:
The second parameter must be an |
How do I store three entries in a array of size 2? What if the number of entries in the JSON Array is four? Please give an example for how four entries are stored in an array of size 2. Only thing I can think of is nesting, but how does nesting work with four entries? |
I didn't say that Chris was incorrect about the type being an expression. It's the three entries in the Json array of Chris' example that are not correct because today you said, the array can only have two entries. |
I changed code and generated new JSON which looks correct but has one extra type as expression - I will look into it. One type in the JSON is header because we have op as
|
@hesingh I am not sure if this "array of size 2" thing you are mentioning is the same thing that @antoninbas is describing. The header stack arrays can be any finite size, 2 or otherwise. The array size 2 limit that I think Antonin is mentioning is the list of strings like |
@jafingerhut The array size I am mentioning has got nothing to do with the header stack size. The P4 code is |
@hesingh You can choose to write names like |
Ah, got it - thanks! Now I need to find the implementation details in bmv2 to figure out how to setup my 2-entry JSON array. |
The JSON example you gave from behavioral-model does not have the P4 code I could find. Using P4 code and generating JSON, one gets the line of code as source_info to understand what code generated what JSON. I agree, some JSON code can still be understood without P4 source code. I did what you suggested and see the generated JSON using default p4c (does not have my code changes). The line of code is at the bottom of the log. The P4 code is
I have another JSON issue to fix for this code |
@antoninbas After more code changes, the right side of assignment statement has its val emitted in JSON as well. This is what Chris had also included. See the output json below. However, this JSON still fails behavioral-model testing with the following error:
|
@antoninbas If the comment on the following line is correct
Then why doesn't the line of code below also include and OR for arrayValue? |
So I had some more time to look into this issue. What I found is that bmv2 supports runtime indices for header stack access as long as the expression is used as a r-value and not a l-value. In other words:
For the r-value case, I verified support by following my own advice... I started with the following P4 program:
I generated the JSON for it the hand-modified it to implement the For reference, this is the original JSON: As for l-value support, this requires a big change to the bmv2 code. The "expression evaluation engine" currently only returns values, not references. I'll open an issue for this but I don't really have the time to look into it these days. |
BTW, here is the relevant part of the JSON file:
|
I opened a new Github issue for the non-supported case I described: #838 I will close this issue now. The title is not really helpful and it's important to make the difference between the case which is already supported and the case which is not. |
It's an enhancement for the behavioral-model to support an
Array Index
as an expression. The expression is a JsonObject and thus this repo's code needs to process the expression as anobjectValue
.If one would like to test new JSON generated by p4c bmv2 backend with an expression type described above, see this PR which has changed p4c.
p4lang/p4c#2118
The P4 program used to generate new JSON is available at this repo:
https://github.com/IETF-Hackathon/p4-ipv6-switch-ml/blob/master/ipv6-switch-ml-bmv2.p4
The text was updated successfully, but these errors were encountered: