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

can't use verify in parser #141

Closed
jnfoster opened this issue Nov 8, 2016 · 9 comments
Closed

can't use verify in parser #141

jnfoster opened this issue Nov 8, 2016 · 9 comments
Assignees
Labels
fixed This topic is considered to be fixed.

Comments

@jnfoster
Copy link
Contributor

jnfoster commented Nov 8, 2016

If I try to invoke verify (a built-in function whose type is currently defined in core.p4), in the parser using the bmv2 backend,

#include <v1model.p4>

struct h { }

struct m { }

parser MyParser(packet_in b, out h hdr, inout m meta, inout standard_metadata_t std) {
  state start {
    verify(true, error.NoError);
    transition accept;
  }
}

control MyVerifyChecksum(in h hdr, inout m meta) {
  apply {}
}
control MyIngress(inout h hdr, inout m meta, inout standard_metadata_t std) {
  apply { }
}
control MyEgress(inout h hdr, inout m meta, inout standard_metadata_t std) {
  apply { }
}

control MyComputeChecksum(inout h hdr, inout m meta) {
  apply {}
}
control MyDeparser(packet_out b, in h hdr) {
  apply { }
}

V1Switch(MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser()) main;

I get an error in the JSON converter:

vagrant@vagrant-ubuntu-trusty-64:~$ p4c-bm2-ss --p4-16 min.p4
min.p4(9): error: MethodCallStatement: not supported in parser on this target
    verify(true, error.NoError);
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^

The culprit seems to be that the implementation of JsonConverter::convertParserStatement is incomplete:
https://github.com/p4lang/p4c/blob/master/backends/bmv2/jsonconverter.cpp#L2111

@mihaibudiu
Copy link
Contributor

As far as I know the behavioral simulator does not support implementing a verify function.
In particular, there is no way to specify errors in the user program.

@mihaibudiu
Copy link
Contributor

mihaibudiu commented Nov 9, 2016

Actually, since the error is invisible anywhere in v1model.p4, we can probably implement verify by just a conditional transition to reject.

@jnfoster
Copy link
Contributor Author

jnfoster commented Nov 9, 2016

At lunch today, Chris suggested that verify would be compiled down into
TCAM matches and then special handing for the transition to reject. Is this
what you mean?

-N

On Tue, Nov 8, 2016 at 4:56 PM, Mihai Budiu notifications@github.com
wrote:

Actually, since the error is invisible anywhere, we can probably implement
verify by just a conditional transition to reject.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#141 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABwi0hE0FUcNqVQ1INdywSHeLdRwmNW7ks5q8RpPgaJpZM4Ks13M
.

@jnfoster
Copy link
Contributor Author

I'm getting a confusing warning message:

warning: SelectCase: unreachable case

The generated JSON looks like this:

{
  "program" : "141.p4",
  "header_types" : [
    {
      "name" : "standard_metadata_t",
      "id" : 1,
      "fields" : [
        ["ingress_port", 9, false],
        ["egress_spec", 9, false],
        ["egress_port", 9, false],
        ["clone_spec", 32, false],
        ["instance_type", 32, false],
        ["drop", 1, false],
        ["recirculate_port", 16, false],
        ["packet_length", 32, false],
        ["_padding", 4, false]
      ]
    }
  ],
  "headers" : [
    {
      "name" : "standard_metadata",
      "id" : 0,
      "header_type" : "standard_metadata_t",
      "metadata" : true
    }
  ],
  "header_stacks" : [],
  "field_lists" : [],
  "parsers" : [
    {
      "name" : "parser",
      "id" : 0,
      "init_state" : "start",
      "parse_states" : [
        {
          "name" : "start",
          "id" : 0,
          "parser_ops" : [],
          "transitions" : [
            {
              "value" : "default",
              "mask" : null,
              "next_state" : "start_join"
            }
          ],
          "transition_key" : []
        },
        {
          "name" : "start_join",
          "id" : 1,
          "parser_ops" : [],
          "transitions" : [
            {
              "value" : "default",
              "mask" : null,
              "next_state" : null
            }
          ],
          "transition_key" : []
        }
      ]
    }
  ],
  "deparsers" : [
    {
      "name" : "deparser",
      "id" : 0,
      "order" : []
    }
  ],
  "meter_arrays" : [],
  "counter_arrays" : [],
  "register_arrays" : [],
  "calculations" : [],
  "learn_lists" : [],
  "actions" : [
    {
      "name" : ".drop",
      "id" : 0,
      "runtime_data" : [],
      "primitives" : [
        {
          "op" : "drop",
          "parameters" : []
        }
      ]
    }
  ],
  "pipelines" : [
    {
      "name" : "ingress",
      "id" : 0,
      "init_table" : "MyIngress.exit",
      "tables" : [
        {
          "name" : "MyIngress.exit",
          "id" : 0,
          "key" : [
            {
              "match_type" : "exact",
              "target" : ["standard_metadata", "drop"]
            }
          ],
          "match_type" : "exact",
          "type" : "simple",
          "max_size" : 1,
          "with_counters" : false,
          "support_timeout" : false,
          "direct_meters" : null,
          "actions" : [".drop"],
          "action_ids" : [0],
          "next_tables" : {
            ".drop" : null
          }
        }
      ],
      "conditionals" : []
    },
    {
      "name" : "egress",
      "id" : 1,
      "init_table" : "MyEgress.exit",
      "tables" : [
        {
          "name" : "MyEgress.exit",
          "id" : 1,
          "key" : [
            {
              "match_type" : "exact",
              "target" : ["standard_metadata", "drop"]
            }
          ],
          "match_type" : "exact",
          "type" : "simple",
          "max_size" : 1,
          "with_counters" : false,
          "support_timeout" : false,
          "direct_meters" : null,
          "actions" : [".drop"],
          "action_ids" : [0],
          "next_tables" : {
            ".drop" : null
          }
        }
      ],
      "conditionals" : []
    }
  ],
  "checksums" : [],
  "force_arith" : [
    ["standard_metadata", "ingress_port"],
    ["standard_metadata", "egress_spec"],
    ["standard_metadata", "egress_port"],
    ["standard_metadata", "clone_spec"],
    ["standard_metadata", "instance_type"],
    ["standard_metadata", "drop"],
    ["standard_metadata", "recirculate_port"],
    ["standard_metadata", "packet_length"]
  ]
}

@mihaibudiu
Copy link
Contributor

Yes, we should remove the warning.
This happens because the verify compiles into a select statement where the 'false' label is unreachable.

@mihaibudiu
Copy link
Contributor

BTW: to see what this compiles into you can use the --top4 flag supplying a pass name.
To see all pass names run it first with -v.

@jnfoster
Copy link
Contributor Author

Right. What's confusing is that my program didn't contain any select statements, and the parser in the generated JSON doesn't have it either. So it's purely an intermediate construct that is later compiled down...

  "parsers" : [
    {
      "name" : "parser",
      "id" : 0,
      "init_state" : "start",
      "parse_states" : [
        {
          "name" : "start",
          "id" : 0,
          "parser_ops" : [],
          "transitions" : [
            {
              "value" : "default",
              "mask" : null,
              "next_state" : "start_join"
            }
          ],
          "transition_key" : []
        },
        {
          "name" : "start_join",
          "id" : 1,
          "parser_ops" : [],
          "transitions" : [
            {
              "value" : "default",
              "mask" : null,
              "next_state" : null
            }
          ],
          "transition_key" : []
        }
      ]
    }
  ]

@mihaibudiu
Copy link
Contributor

I have just pushed a commit to remove this warning; it's now on top of the existing pull request.

@ChrisDodd ChrisDodd added the fixed This topic is considered to be fixed. label Dec 13, 2016
@jnfoster
Copy link
Contributor Author

Looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed This topic is considered to be fixed.
Projects
None yet
Development

No branches or pull requests

3 participants