tutorials
tutorials copied to clipboard
match-action table do not support negative number
Hi,
I want to achieve a one-to-one mapping in P4.
So I use a match-action table.
I hope assign values to a variable based on different keys
for example, when key==1, variable=2
when key==2, varibale=-4

so I hope I can use the negative number as the action parameter I populate the table entries like this { "table": "assign", "match": { "meta.Count": 2 }, "action_name": "set_to", "action_params": { "quantized_value": -4 } } It looks like the match action table only support the positive number, when the action parameter is less than 0, it just can consider the action parameter as 0.
So is there any way to use the negative number as the action parameter? Thanks
Perhaps you could share a complete program that exhibits the bug?
And if you're running on Bmv2, a full trace of the log would be useful.
It's hard to help with only partial snippets of code.
I was awake for an hour in the middle of the night last night, and tried quickly hacking up the basic exercise in the tutorials to add one table like in the original comment of this issue, and a single entry with a negative action parameter value. It crashed in the Python code within the tutorials repo while trying to write the entry with the negative value, because some of that Python code was not written to support writing negative integers. I can create a small PR later today with those changes for the person reporting this issue to try out.
Here is a proposed PR that worked in a tiny example I tried: https://github.com/p4lang/tutorials/pull/483
It would be great if @529669517 could try these changes out before that PR is merged in, to give better confidence that they are good changes, but if someone else thinks it is good in code review, it appears to be a safe change to make in that it should never change the behavior of the code when only non-negative action parameter values are used.