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

P4-14 to P4-16 fails in getting parameters from extern instatiation #604

Closed
engjefersonsantiago opened this issue May 10, 2017 · 21 comments
Closed
Labels
fixed This topic is considered to be fixed.

Comments

@engjefersonsantiago
Copy link
Contributor

engjefersonsantiago commented May 10, 2017

The P4-14 to P4-16 conversion is not getting the correct instatiation parameters. E.g:

Following P4-14 code:

parser start { return ingress; }
extern_type extern_test {
    attribute att_test {
        type: int;
    }
    method my_extern_method ();
}
extern extern_test my_extern_inst {
  att_test: 0xab;
}
action a() { my_extern_inst.my_extern_method(); }
table t {
    actions { a; }
}
control ingress {
    apply(t);
}
control egress {}

Generates:

#include <core.p4>
#include <v1model.p4>

struct metadata {
}

struct headers {
}

extern extern_test {
    void my_extern_method();
    extern_test();
}

parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
    @name("start") state start {
        transition accept;
    }
}

control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
    apply {
    }
}

control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
    extern_test() my_extern_inst;
    @name(".a") action a() {
        my_extern_inst.my_extern_method();
    }
    @name("t") table t {
        actions = {
            a;
            @default_only NoAction;
        }
        default_action = NoAction();
    }
    apply {
        t.apply();
    }
}

control DeparserImpl(packet_out packet, in headers hdr) {
    apply {
    }
}

control verifyChecksum(in headers hdr, inout metadata meta) {
    apply {
    }
}

control computeChecksum(inout headers hdr, inout metadata meta) {
    apply {
    }
}

V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;

I believe there is an issue with the v1parser.ypp, but I feel a bit unconfortable to change it.

@sethfowler
Copy link
Contributor

I'll take a look.

@mihaibudiu
Copy link
Contributor

This is probably about converting properties; they have no equivalent in P4-16.
They should probably be converted to constructor parameter, but for backwards compatibility with some existing P4-14 programs which are not in the public test suite they seem to be converted also to IR properties, which do not really exist in P4-16.

@sethfowler
Copy link
Contributor

By the way @engjefersonsantiago, when you paste code, it will be formatted more nicely if you surround it with the appropriate markdown syntax, like this:

```p4
<code here>
```

(The p4 is not strictly necessary, but it tells Github to highlight the code using P4 syntax.)

@sethfowler
Copy link
Contributor

@mbudiu-vmw yeah, that makes sense. I don't know much about extern properties, so I may not be the best person to look at this, actually. (I saw mention of v1parser.ypp and thought that if it was a parser problem, I could probably fix it quickly.)

@mihaibudiu
Copy link
Contributor

Unfortunately externs were a P4 v1.1 extension, so they are not even in the P4-14 spec.
So it won't be easy to figure out what to do about them.
@ChrisDodd has written some code to read extern properties, but they are not converted to constructors, but to properties, which flow through the IR all the way to the back-end. They do not generate P4-16 source.
Frankly, P4 v1.1 is deprecated, and we should stop writing code in that dialect.

@ChrisDodd
Copy link
Contributor

ChrisDodd commented May 11, 2017 via email

@jnfoster
Copy link
Contributor

I lack a detailed understanding of v1.1, but could we simply pick a canonical encoding as P4-16 extern objects? For example, maybe each attribute generates a corresponding constructor parameter and a getter/setter method. Then we could eliminate them in the front-end instead of carrying them down. We could also annotate the IR nodes to indicate they were encoding a v1.1 extern so that back-ends that wanted to treat these particular objects in a special way could do so.

@ChrisDodd
Copy link
Contributor

The original plan was to transform extern attributes into construtor params. The problem is that this scale poorly for externs with many (mostly optional) attributes, and doesn't work at all for attributes that are expressions rather than constants -- those need to be transformed method arguments somehow, but there isn't really clean one-to-one mapping. You really need to redesign v1.1 externs that use general expression attributes to have methods instead.

@cc10512
Copy link
Contributor

cc10512 commented May 11, 2017

The resolution then is that extern attributes are not supported officially supported. They are part of the IR, so a particular backend can take advantage of them, but since they have no P4_16 equivalent, they will not be printed in P4_16. As @ChrisDodd points out, you should redesign the externs for P4_16 to use methods.

@cc10512 cc10512 closed this as completed May 11, 2017
@engjefersonsantiago
Copy link
Contributor Author

Ok then, it is not a problem to use P4-16. I am already using it. I opened the issue because I worked in a patch to support arbritrary externs in the bmv2 backend compiler and I faced this "problem".
However, I do believe we should throw an warning if the user tries to use extern attributes.

@jnfoster
Copy link
Contributor

jnfoster commented May 11, 2017 via email

@mihaibudiu
Copy link
Contributor

Talk to @ChrisDodd first; it looks like Barefoot is actually using this feature.
He introduced it in the compiler.

@jnfoster
Copy link
Contributor

It's safe to pass these attributes through as annotations on the IR nodes. A backend can do what it wants.

However, we should warn if we try to use a backend that doesn't support them (like Bmv2) or try to print them as P4 via the --top4 or --pp flags.

-N

@cc10512
Copy link
Contributor

cc10512 commented May 11, 2017

Sure, let's warn. @engjefersonsantiago would you mind submitting that patch for this issue?

@cc10512 cc10512 reopened this May 11, 2017
@engjefersonsantiago
Copy link
Contributor Author

Sure I can.
My suggestion is to insert this warnig in the parser.
So, I have an opened PR #591. Should I include the patch in the same PR?

@jnfoster
Copy link
Contributor

Rather than issuing warnings in the front-end, perhaps they should go in the pretty printer (when we would be silently and confusingly eliding these IR nodes) and/or in backends that cannot handle them.

@jnfoster
Copy link
Contributor

In general, we try to split up PRs into as small as is reaosnable. Since these warnings are an independent improvement to p4c, it'd be great to do it separately from your other PR.

If it'd be a burden to split it out you can do them together. But it's more work to review...

@engjefersonsantiago
Copy link
Contributor Author

@jnfoster, I feel that I have not such experience with the compiler code to progate this warning deeper in the code. I think that someone more experint should address this issue.

mihaibudiu pushed a commit to mihaibudiu/p4c-clone that referenced this issue May 15, 2017
mihaibudiu pushed a commit to mihaibudiu/p4c-clone that referenced this issue May 15, 2017
@mihaibudiu mihaibudiu added the fixed This topic is considered to be fixed. label May 15, 2017
mihaibudiu pushed a commit that referenced this issue May 23, 2017
Fix for issue #604
@ChrisDodd
Copy link
Contributor

We've added infrastructure to be able to add custom ExternConverters in the compiler to translate P4_14 extern attributes into something else in P4_16 (constructor params or type params or abstract functions or anything else that can be represented in P4_16). It is likely that the precise nature of the transform needed will depend on the purpose and use of the extern.

@mihaibudiu
Copy link
Contributor

So can this issue be closed?

@mihaibudiu
Copy link
Contributor

Since no one answered my question for a few months, I will assume that we can close.

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

6 participants