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

writes out json boolean values for valid match keys. #536

Merged
merged 1 commit into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backends/bmv2/jsonconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ void JsonConverter::convertTableEntries(const IR::P4Table *table,
key->emplace("match_type", matchType);
if (matchType == "valid") {
if (k->is<IR::BoolLiteral>())
key->emplace("key", k->to<IR::BoolLiteral>()->toString());
key->emplace("key", k->to<IR::BoolLiteral>()->value);
else
::error("%1% invalid 'valid' key expression", k);
} else if (matchType == corelib.exactMatch.name) {
Expand Down
76 changes: 76 additions & 0 deletions testdata/p4_16_samples/table-entries-valid-bmv2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright 2013-present Barefoot Networks, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

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

header hdr {
bit<8> e;
bit<16> t;
bit<8> l;
bit<8> r;
bit<1> v;
}

struct Header_t {
hdr h;
}
struct Meta_t {}

parser p(packet_in b, out Header_t h, inout Meta_t m, inout standard_metadata_t sm) {
state start {
b.extract(h.h);
transition accept;
}
}

control vrfy(in Header_t h, inout Meta_t m) { apply {} }
control update(inout Header_t h, inout Meta_t m) { apply {} }
control egress(inout Header_t h, inout Meta_t m, inout standard_metadata_t sm) { apply {} }
control deparser(packet_out b, in Header_t h) { apply { b.emit(h.h); } }

control ingress(inout Header_t h, inout Meta_t m, inout standard_metadata_t standard_meta) {

action a() { standard_meta.egress_spec = 0; }
action a_with_control_params(bit<9> x) { standard_meta.egress_spec = x; }

table t_valid {

key = {
h.h.isValid() : exact;
h.h.e : exact;
}

actions = {
a;
a_with_control_params;
}

default_action = a;

const entries = {
(true, 0x01) : a_with_control_params(1);
(false, 0x02) : a_with_control_params(2);
}
}

apply {
t_valid.apply();
}
}


V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main;
77 changes: 77 additions & 0 deletions testdata/p4_16_samples_outputs/table-entries-valid-bmv2-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <core.p4>
#include <v1model.p4>

header hdr {
bit<8> e;
bit<16> t;
bit<8> l;
bit<8> r;
bit<1> v;
}

struct Header_t {
hdr h;
}

struct Meta_t {
}

parser p(packet_in b, out Header_t h, inout Meta_t m, inout standard_metadata_t sm) {
state start {
b.extract<hdr>(h.h);
transition accept;
}
}

control vrfy(in Header_t h, inout Meta_t m) {
apply {
}
}

control update(inout Header_t h, inout Meta_t m) {
apply {
}
}

control egress(inout Header_t h, inout Meta_t m, inout standard_metadata_t sm) {
apply {
}
}

control deparser(packet_out b, in Header_t h) {
apply {
b.emit<hdr>(h.h);
}
}

control ingress(inout Header_t h, inout Meta_t m, inout standard_metadata_t standard_meta) {
action a() {
standard_meta.egress_spec = 9w0;
}
action a_with_control_params(bit<9> x) {
standard_meta.egress_spec = x;
}
table t_valid {
key = {
h.h.isValid(): exact @name("h.h.isValid()") ;
h.h.e : exact @name("h.h.e") ;
}
actions = {
a();
a_with_control_params();
}
default_action = a();
const entries = {
(true, 8w0x1) : a_with_control_params(9w1);

(false, 8w0x2) : a_with_control_params(9w2);

}

}
apply {
t_valid.apply();
}
}

V1Switch<Header_t, Meta_t>(p(), vrfy(), ingress(), egress(), update(), deparser()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <core.p4>
#include <v1model.p4>

header hdr {
bit<8> e;
bit<16> t;
bit<8> l;
bit<8> r;
bit<1> v;
}

struct Header_t {
hdr h;
}

struct Meta_t {
}

parser p(packet_in b, out Header_t h, inout Meta_t m, inout standard_metadata_t sm) {
state start {
b.extract<hdr>(h.h);
transition accept;
}
}

control vrfy(in Header_t h, inout Meta_t m) {
apply {
}
}

control update(inout Header_t h, inout Meta_t m) {
apply {
}
}

control egress(inout Header_t h, inout Meta_t m, inout standard_metadata_t sm) {
apply {
}
}

control deparser(packet_out b, in Header_t h) {
apply {
b.emit<hdr>(h.h);
}
}

control ingress(inout Header_t h, inout Meta_t m, inout standard_metadata_t standard_meta) {
@name("a") action a_0() {
standard_meta.egress_spec = 9w0;
}
@name("a_with_control_params") action a_with_control_params_0(bit<9> x) {
standard_meta.egress_spec = x;
}
@name("t_valid") table t_valid_0 {
key = {
h.h.isValid(): exact @name("h.h.isValid()") ;
h.h.e : exact @name("h.h.e") ;
}
actions = {
a_0();
a_with_control_params_0();
}
default_action = a_0();
const entries = {
(true, 8w0x1) : a_with_control_params_0(9w1);

(false, 8w0x2) : a_with_control_params_0(9w2);

}

}
apply {
t_valid_0.apply();
}
}

V1Switch<Header_t, Meta_t>(p(), vrfy(), ingress(), egress(), update(), deparser()) main;
77 changes: 77 additions & 0 deletions testdata/p4_16_samples_outputs/table-entries-valid-bmv2-midend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <core.p4>
#include <v1model.p4>

header hdr {
bit<8> e;
bit<16> t;
bit<8> l;
bit<8> r;
bit<1> v;
}

struct Header_t {
hdr h;
}

struct Meta_t {
}

parser p(packet_in b, out Header_t h, inout Meta_t m, inout standard_metadata_t sm) {
state start {
b.extract<hdr>(h.h);
transition accept;
}
}

control vrfy(in Header_t h, inout Meta_t m) {
apply {
}
}

control update(inout Header_t h, inout Meta_t m) {
apply {
}
}

control egress(inout Header_t h, inout Meta_t m, inout standard_metadata_t sm) {
apply {
}
}

control deparser(packet_out b, in Header_t h) {
apply {
b.emit<hdr>(h.h);
}
}

control ingress(inout Header_t h, inout Meta_t m, inout standard_metadata_t standard_meta) {
@name("a") action a_0() {
standard_meta.egress_spec = 9w0;
}
@name("a_with_control_params") action a_with_control_params_0(bit<9> x) {
standard_meta.egress_spec = x;
}
@name("t_valid") table t_valid {
key = {
h.h.isValid(): exact @name("h.h.isValid()") ;
h.h.e : exact @name("h.h.e") ;
}
actions = {
a_0();
a_with_control_params_0();
}
default_action = a_0();
const entries = {
(true, 8w0x1) : a_with_control_params_0(9w1);

(false, 8w0x2) : a_with_control_params_0(9w2);

}

}
apply {
t_valid.apply();
}
}

V1Switch<Header_t, Meta_t>(p(), vrfy(), ingress(), egress(), update(), deparser()) main;
77 changes: 77 additions & 0 deletions testdata/p4_16_samples_outputs/table-entries-valid-bmv2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <core.p4>
#include <v1model.p4>

header hdr {
bit<8> e;
bit<16> t;
bit<8> l;
bit<8> r;
bit<1> v;
}

struct Header_t {
hdr h;
}

struct Meta_t {
}

parser p(packet_in b, out Header_t h, inout Meta_t m, inout standard_metadata_t sm) {
state start {
b.extract(h.h);
transition accept;
}
}

control vrfy(in Header_t h, inout Meta_t m) {
apply {
}
}

control update(inout Header_t h, inout Meta_t m) {
apply {
}
}

control egress(inout Header_t h, inout Meta_t m, inout standard_metadata_t sm) {
apply {
}
}

control deparser(packet_out b, in Header_t h) {
apply {
b.emit(h.h);
}
}

control ingress(inout Header_t h, inout Meta_t m, inout standard_metadata_t standard_meta) {
action a() {
standard_meta.egress_spec = 0;
}
action a_with_control_params(bit<9> x) {
standard_meta.egress_spec = x;
}
table t_valid {
key = {
h.h.isValid(): exact;
h.h.e : exact;
}
actions = {
a;
a_with_control_params;
}
default_action = a;
const entries = {
(true, 0x1) : a_with_control_params(1);

(false, 0x2) : a_with_control_params(2);

}

}
apply {
t_valid.apply();
}
}

V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main;
Empty file.