tutorials icon indicating copy to clipboard operation
tutorials copied to clipboard

match-action table do not support negative number

Open KaiyiZhang-uo opened this issue 3 years ago • 3 comments

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 1664674226869

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

KaiyiZhang-uo avatar Oct 02 '22 01:10 KaiyiZhang-uo

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.

jnfoster avatar Oct 03 '22 12:10 jnfoster

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.

jfingerh avatar Oct 03 '22 16:10 jfingerh

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.

jafingerhut avatar Oct 03 '22 16:10 jafingerhut