Skip to content

Commit

Permalink
Additional tests and bug-fixes for varbits
Browse files Browse the repository at this point in the history
  • Loading branch information
mbudiu-vmw committed May 16, 2017
1 parent 78696d4 commit 2a32b34
Show file tree
Hide file tree
Showing 30 changed files with 1,145 additions and 4 deletions.
6 changes: 4 additions & 2 deletions backends/bmv2/header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ Visitor::profile_t ConvertHeaders::init_apply(const IR::Node* node) {
auto type = typeMap->getType(v, true);
if (auto st = type->to<IR::Type_StructLike>()) {
auto metadata_type = extVisibleName(st);
json->add_metadata(metadata_type, v->name);
if (type->is<IR::Type_Header>())
json->add_header(metadata_type, v->name);
else
json->add_metadata(metadata_type, v->name);
// only create header type only
if (visitedHeaders.find(st->getName()) != visitedHeaders.end())
continue; // already seen
Expand Down Expand Up @@ -255,7 +258,6 @@ void ConvertHeaders::end_apply(UNUSED const IR::Node* node) {
}
}


/**
* Generate json for header from IR::Block's constructor parameters
*
Expand Down
19 changes: 17 additions & 2 deletions backends/bmv2/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,28 @@ Util::IJson* Parser::convertParserStatement(const IR::StatOrDecl* stat) {
auto params = mkArrayField(result, "parameters");
if (stat->is<IR::AssignmentStatement>()) {
auto assign = stat->to<IR::AssignmentStatement>();
result->emplace("op", "set");
auto l = conv->convertLeftValue(assign->left);
auto type = typeMap->getType(assign->left, true);
cstring operation;
if (type->is<IR::Type_StructLike>())
operation = "assign_header";
else
operation = "set";
result->emplace("op", operation);
auto l = conv->convertLeftValue(assign->left);
bool convertBool = type->is<IR::Type_Boolean>();
auto r = conv->convert(assign->right, true, true, convertBool);
params->append(l);
params->append(r);

if (operation == "assign_header") {
// must wrap into another outer object
auto wrap = new Util::JsonObject();
wrap->emplace("op", "primitive");
auto params = mkParameters(wrap);
params->append(result);
result = wrap;
}

return result;
} else if (stat->is<IR::MethodCallStatement>()) {
auto mce = stat->to<IR::MethodCallStatement>()->methodCall;
Expand Down
51 changes: 51 additions & 0 deletions testdata/p4_16_samples/issue447-1-bmv2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <core.p4>
#include <v1model.p4>

header H {
varbit<32> var;
}

struct Parsed_packet {
H h1;
H h2;
}

struct Metadata {
}

control DeparserI(packet_out packet, in Parsed_packet hdr) {
apply {
packet.emit(hdr.h2);
packet.emit(hdr.h1);
}
}

parser parserI(packet_in pkt, out Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract<H>(hdr.h1, 32w16);
pkt.extract<H>(hdr.h2, 32w16);
transition accept;
}
}

control ingress(inout Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control egress(inout Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control vc(in Parsed_packet hdr, inout Metadata meta) {
apply {
}
}

control uc(inout Parsed_packet hdr, inout Metadata meta) {
apply {
}
}

V1Switch<Parsed_packet, Metadata>(parserI(), vc(), ingress(), egress(), uc(), DeparserI()) main;
2 changes: 2 additions & 0 deletions testdata/p4_16_samples/issue447-1-bmv2.stf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packet 0 12 34 56 78 90
expect 0 56 78 12 34 90
55 changes: 55 additions & 0 deletions testdata/p4_16_samples/issue447-2-bmv2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <core.p4>
#include <v1model.p4>

header S {
bit<32> size;
}

header H {
varbit<32> var;
}

struct Parsed_packet {
S s;
H h;
}

struct Metadata {
}

parser parserI(packet_in pkt, out Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract(hdr.s);
bit<32> size = hdr.s.size;
pkt.extract(hdr.h, size);
transition accept;
}
}

control DeparserI(packet_out packet, in Parsed_packet hdr) {
apply {
packet.emit(hdr.h);
}
}

control ingress(inout Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control egress(inout Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control vc(in Parsed_packet hdr, inout Metadata meta) {
apply {
}
}

control uc(inout Parsed_packet hdr, inout Metadata meta) {
apply {
}
}

V1Switch<Parsed_packet, Metadata>(parserI(), vc(), ingress(), egress(), uc(), DeparserI()) main;
5 changes: 5 additions & 0 deletions testdata/p4_16_samples/issue447-2-bmv2.stf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# size
packet 0 00000008 12 34 56 78 90
expect 0 12 34 56 78 90
packet 0 00000010 12 34 56 78 90
expect 0 12 34 56 78 90
57 changes: 57 additions & 0 deletions testdata/p4_16_samples/issue447-3-bmv2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <core.p4>
#include <v1model.p4>

header S {
bit<32> size;
}

header H {
varbit<32> var;
}

struct Parsed_packet {
S s1;
H h;
S s2;
}

struct Metadata {
}

parser parserI(packet_in pkt, out Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract(hdr.s1);
bit<32> size = hdr.s1.size;
pkt.extract(hdr.h, size);
pkt.extract(hdr.s2);
transition accept;
}
}

control DeparserI(packet_out packet, in Parsed_packet hdr) {
apply {
packet.emit(hdr.s2);
}
}

control ingress(inout Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control egress(inout Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control vc(in Parsed_packet hdr, inout Metadata meta) {
apply {
}
}

control uc(inout Parsed_packet hdr, inout Metadata meta) {
apply {
}
}

V1Switch<Parsed_packet, Metadata>(parserI(), vc(), ingress(), egress(), uc(), DeparserI()) main;
5 changes: 5 additions & 0 deletions testdata/p4_16_samples/issue447-3-bmv2.stf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# size
packet 0 00000008 12 34 56 78 90
expect 0 34 56 78 90
packet 0 00000010 12 34 56 78 90
expect 0 56 78 90
56 changes: 56 additions & 0 deletions testdata/p4_16_samples/issue447-4-bmv2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <core.p4>
#include <v1model.p4>

header S {
bit<32> size;
}

header H {
varbit<32> var;
}

struct Parsed_packet {
S s1;
H h;
S s2;
}

struct Metadata {
}

parser parserI(packet_in pkt, out Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract(hdr.s1);
pkt.extract(hdr.h, hdr.s1.size);
pkt.extract(hdr.s2);
transition accept;
}
}

control DeparserI(packet_out packet, in Parsed_packet hdr) {
apply {
packet.emit(hdr.s2);
}
}

control ingress(inout Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control egress(inout Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control vc(in Parsed_packet hdr, inout Metadata meta) {
apply {
}
}

control uc(inout Parsed_packet hdr, inout Metadata meta) {
apply {
}
}

V1Switch<Parsed_packet, Metadata>(parserI(), vc(), ingress(), egress(), uc(), DeparserI()) main;
5 changes: 5 additions & 0 deletions testdata/p4_16_samples/issue447-4-bmv2.stf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# size
packet 0 00000008 12 34 56 78 90
expect 0 34 56 78 90
packet 0 00000010 12 34 56 78 90
expect 0 56 78 90
51 changes: 51 additions & 0 deletions testdata/p4_16_samples_outputs/issue447-1-bmv2-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <core.p4>
#include <v1model.p4>

header H {
varbit<32> var;
}

struct Parsed_packet {
H h1;
H h2;
}

struct Metadata {
}

control DeparserI(packet_out packet, in Parsed_packet hdr) {
apply {
packet.emit<H>(hdr.h2);
packet.emit<H>(hdr.h1);
}
}

parser parserI(packet_in pkt, out Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract<H>(hdr.h1, 32w16);
pkt.extract<H>(hdr.h2, 32w16);
transition accept;
}
}

control ingress(inout Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control egress(inout Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control vc(in Parsed_packet hdr, inout Metadata meta) {
apply {
}
}

control uc(inout Parsed_packet hdr, inout Metadata meta) {
apply {
}
}

V1Switch<Parsed_packet, Metadata>(parserI(), vc(), ingress(), egress(), uc(), DeparserI()) main;
51 changes: 51 additions & 0 deletions testdata/p4_16_samples_outputs/issue447-1-bmv2-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <core.p4>
#include <v1model.p4>

header H {
varbit<32> var;
}

struct Parsed_packet {
H h1;
H h2;
}

struct Metadata {
}

control DeparserI(packet_out packet, in Parsed_packet hdr) {
apply {
packet.emit<H>(hdr.h2);
packet.emit<H>(hdr.h1);
}
}

parser parserI(packet_in pkt, out Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract<H>(hdr.h1, 32w16);
pkt.extract<H>(hdr.h2, 32w16);
transition accept;
}
}

control ingress(inout Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control egress(inout Parsed_packet hdr, inout Metadata meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control vc(in Parsed_packet hdr, inout Metadata meta) {
apply {
}
}

control uc(inout Parsed_packet hdr, inout Metadata meta) {
apply {
}
}

V1Switch<Parsed_packet, Metadata>(parserI(), vc(), ingress(), egress(), uc(), DeparserI()) main;
Loading

0 comments on commit 2a32b34

Please sign in to comment.