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

Table collision on valid P4 when instantiating control twice #8

Closed
Tracked by #6
rcgoodfellow opened this issue Sep 7, 2022 · 0 comments · Fixed by #11
Closed
Tracked by #6

Table collision on valid P4 when instantiating control twice #8

rcgoodfellow opened this issue Sep 7, 2022 · 0 comments · Fixed by #11
Assignees

Comments

@rcgoodfellow
Copy link
Collaborator

rcgoodfellow commented Sep 7, 2022

The following P4 generates bad rust output.

What's happening here is the same control resolver is instantiated multiple times, once from the foo control and once from the bar control. Because generated rust names for tables are based entirely on the name of control they are a part of and the name of the table e.g. $control_table_$table this means that multiple instantiations will cause collisions. The code generated from the P4 below at time of writing is recorded in this gist.

One possible solution is to make the generated names more specific. Another arguably much better solution would be to not have control objects be implicitly global, but rather have them be local to the scope in which they're created. This is a pretty major change and will require a lot of rework, but is probably a better path forward.

#include <p4/examples/codegen/core.p4>
#include <p4/examples/codegen/softnpu.p4>

SoftNPU(
    parse(),
    ingress()
) main;

struct headers_t { }

parser parse(
    packet_in pkt,
    out headers_t headers,
    inout IngressMetadata ingress,
){
    state start { transition accept; }
}

control resolver(
    in bit<32> x,
    out bool resolved,
) {
    action resolve() {
        resolved = true;
    }
    table arp {
        key = { x: exact; }
        actions = { resolve; }
        default_action = NoAction;
    }
    apply { arp.apply(); }
}

control foo() {
    resolver() resolver;
    apply {
        resolver.apply(32w47);
    }
}

control bar() {
    resolver() resolver;
    apply { resolver.apply(32w1701); }
}

control ingress(
    inout headers_t hdr,
    inout IngressMetadata ingress,
    inout EgressMetadata egress,
) {
    foo() foo;
    bar() bar;

    apply {
        bar.apply();
        foo.apply();
    }
}
@rcgoodfellow rcgoodfellow self-assigned this Sep 7, 2022
@rcgoodfellow rcgoodfellow mentioned this issue Sep 7, 2022
15 tasks
rcgoodfellow added a commit that referenced this issue Sep 8, 2022
- codegen/rust: consistent bit/int literal byte order
- p4rs: consistent bitvec dumps
- checker: basic assignment type checking
- add double instantiation example from issue #8
- boundary services e2e NAT working with sidecar-lite
- update examples based on consistent byte order literals
rcgoodfellow added a commit that referenced this issue Nov 9, 2022
rcgoodfellow added a commit that referenced this issue Nov 9, 2022
rcgoodfellow added a commit that referenced this issue Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant