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

Add struct with emit to bmv2 backend #1659

Open
hesingh opened this Issue Jan 11, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@hesingh
Copy link
Contributor

hesingh commented Jan 11, 2019

The bmv2 backend implementation should be as close to the P4-16 specification as possible. The specification supports emit for a struct, but the bmv2 backend does not. We should add the support to the bmv2 backend.

See p4c/backends/bmv2/common/deparser.cpp and this code:

} else {
    ::error("%1%: emit only supports header and stack arguments, not %2%",
               arg, type);
}
@mbudiu-vmw

This comment has been minimized.

Copy link
Collaborator

mbudiu-vmw commented Jan 11, 2019

Have you tested the program?
Structs containing headers are dismantled by another compiler pass.

@hesingh

This comment has been minimized.

Copy link
Contributor Author

hesingh commented Jan 11, 2019

Here is a short test program that fails. The failure log is included first, followed by the test P4 program.

hemant@ubuntu:~/p4c-1/build$ ./p4c-bm2-ss --std p4-16 foo.p4
foo.p4(64): error: b.emit: argument must be a header, stack or union, or a struct or tuple of such types
        b.emit(h.bvh0.row);
        ^^^^^^^^^^^^^^^^^^
foo.p4(64): error: b.emit: argument must be a header, stack or union, or a struct or tuple of such types
        b.emit(h.bvh0.row);
        ^^^^^^^^^^^^^^^^^^
foo.p4(64): error: b.emit: argument must be a header, stack or union, or a struct or tuple of such types
        b.emit(h.bvh0.row);
        ^^^^^^^^^^^^^^^^^^
foo.p4(64): error: b.emit: argument must be a header, stack or union, or a struct or tuple of such types
        b.emit(h.bvh0.row);
        ^^^^^^^^^^^^^^^^^^
hemant@ubuntu:~/p4c-1/build$ 
#include <v1model.p4>

struct alt_t {
    bit<1> valid;
    bit<7> port;
};

struct row_t {
    alt_t alt0;
    alt_t alt1;
};

header bitvec_hdr {
    row_t row;
}

struct local_metadata_t {
    bit<8> row0;
};

struct parsed_packet_t {
    bitvec_hdr bvh0;
    bitvec_hdr bvh1;
};

parser parse(packet_in pk, out parsed_packet_t h, inout local_metadata_t local_metadata,
             inout standard_metadata_t standard_metadata) {
    state start {
	transition accept;
    }
}

control ingress(inout parsed_packet_t h, inout local_metadata_t local_metadata,
                inout standard_metadata_t standard_metadata) {
    apply {
        clone3(CloneType.I2E, 0, h);
    }
}

control egress(inout parsed_packet_t hdr, inout local_metadata_t local_metadata,
               inout standard_metadata_t standard_metadata) {
    apply { }
}

control deparser(packet_out b, in parsed_packet_t h) {
    apply {
        b.emit(h.bvh0.row);
    }
}

control verify_checksum(inout parsed_packet_t hdr,
inout local_metadata_t local_metadata) {
    apply { }
}

control compute_checksum(inout parsed_packet_t hdr,
                         inout local_metadata_t local_metadata) {
    apply { }
}

V1Switch(parse(), verify_checksum(), ingress(), egress(),
compute_checksum(), deparser()) main;
@mbudiu-vmw

This comment has been minimized.

Copy link
Collaborator

mbudiu-vmw commented Jan 11, 2019

This error is provided by the front-end and is in conformance with the Section 15 of the language spec.
It has nothing to do with the bmv2 back-end.

@hesingh

This comment has been minimized.

Copy link
Contributor Author

hesingh commented Jan 11, 2019

In a private workspace few weeks back, I had changed the frontend code, also the midend ExpandEmit pass, and then the bmv2 deparser gave me the error. When I get a chance during the next few days, I'd be happy to ressurect that code changes and add a log.

@hesingh

This comment has been minimized.

Copy link
Contributor Author

hesingh commented Jan 12, 2019

I created this workspace to add code changes to create the bmv2 failure for emit with struct.

https://github.com/hesingh/emit-struct

In the workspace, the shorter test P4 program is included in path

testdata/p4_16_samples/emit-struct.p4

creates the problem. Please see test log below.

hemant@ubuntu:~/emit-struct/build$ ./p4c-bm2-ss --std p4-16 ../testdata/p4_16_samples/emit-struct.p4
../testdata/p4_16_samples/emit-struct.p4(16): [--Wwarn=uninitialized_out_param] warning: out parameter h may be uninitialized when parse terminates
parser parse(packet_in pk, out parsed_packet_t h, inout local_metadata_t local_metadata,
                                               ^
../testdata/p4_16_samples/emit-struct.p4(16)
parser parse(packet_in pk, out parsed_packet_t h, inout local_metadata_t local_metadata,
       ^^^^^
../testdata/p4_16_samples/emit-struct.p4(37): error: bmv2 , StructInitializerExpression: emit only supports header and stack arguments, not struct row_t
        b.emit(h.row);
               ^^^^^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment