Skip to content
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

Question: Of what use are constants in BMv2 JSON field_lists? #704

Open
jafingerhut opened this issue Jan 20, 2019 · 2 comments
Open

Question: Of what use are constants in BMv2 JSON field_lists? #704

jafingerhut opened this issue Jan 20, 2019 · 2 comments

Comments

@jafingerhut
Copy link
Contributor

simple_switch can read without error arbitrary mixes of type "hexstr" and "field" inside of the "elements" list, as shown in the example below:

  "field_lists" : [
    {
      "id" : 1,
      "name" : "tuple_0",
      "source_info" : {
        "filename" : "resubmit-constant-prop-bug-p414.p4",
        "line" : 66,
        "column" : 0,
        "source_fragment" : "field_list resubmit_FL { ..."
      },
      "elements" : [
        {
          "type" : "hexstr",
          "value" : "0x0003"
        },
        {
          "type" : "field",
          "value" : ["scalars", "tmp"]
        },
        {
          "type" : "field",
          "value" : ["scalars", "tmp_0"]
        }
      ]
    }
  ],

I found the commit to behavioral-model where the capability to accept "hexstr" elements was added, but it wasn't clear to me from reading that why it was added.

Does P4_14 allow constants in a field_list definition?

It makes sense that P4_16 allows constants in a list of fields given as an arg to a call like a hash or checksum calculation. Was that the motivation?

Separate from that question, does it seem to you like it would always be a mistake of some kind if a field list used for recirculate, resubmit, or clone3 primitives of simple_switch contained an element with type "hexstr"? I cannot think of any reason why that would make sense. The current p4c can sometimes generate such a field_list, but I am guessing that it is always a sign of a bug in p4c when it does so.

@jafingerhut
Copy link
Contributor Author

Answering one of my own questions, which I should have looked up before asking: The P4_14 spec does allow constant values in field_list definitions. Probably primarily for the purpose of hash/checksum calculation input lists, would be my guess.

The other question about whether constant values make sense in a recirculate/resubmit/clone3 primitive is still open, in my mind.

@jafingerhut
Copy link
Contributor Author

I am pretty sure that the answer to the question: "Does it make sense for a recirculate/resubmit/clone primitive to contain constant values?" is "No, that is a sign of a bug in p4c bmv2 back end."

I have a Python program that can detect this and a few other similar problems in such field lists, written to see how prevalent this issue is in p4c: p4lang/p4c#1669

The Python program that reads BMv2 JSON files and looks for possible problems is here: https://github.com/p4pktgen/p4pktgen/blob/master/tools/bmv2-json-check.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant