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

Three minor changes #370

Merged
merged 5 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
15 changes: 9 additions & 6 deletions backends/bmv2/bmv2stf.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ def run(self):
reportError("Could not find a free port for Thrift")
return FAILURE
thriftPort = str(9090 + rand)
rv = SUCCESS

try:
runswitch = [FindExe("behavioral-model", "simple_switch"),
Expand Down Expand Up @@ -534,25 +535,27 @@ def run(self):
cli.stdin.close()
for interface, fp in self.interfaces.iteritems():
fp.close()
cli.wait()
if cli.returncode != 0:
reportError("CLI process failed with exit code", cli.returncode)
return FAILURE
# Give time to the model to execute
time.sleep(2)
cli.terminate()
sw.terminate()
sw.wait()
# This only works on Unix: negative returncode is
# minus the signal number that killed the process.
if sw.returncode != -15: # 15 is SIGTERM
if sw.returncode != 0 and sw.returncode != -15: # 15 is SIGTERM
reportError("simple_switch died with return code", sw.returncode);
rv = FAILURE
elif self.options.verbose:
print("simple_switch exit code", sw.returncode)
cli.wait()
if cli.returncode != 0 and cli.returncode != -15:
reportError("CLI process failed with exit code", cli.returncode)
rv = FAILURE
finally:
concurrent.release(rand)
if self.options.verbose:
print("Execution completed")
return SUCCESS
return rv
def comparePacket(self, expected, received):
received = ''.join(ByteToHex(str(received)).split()).upper()
expected = ''.join(expected.split()).upper()
Expand Down
4 changes: 4 additions & 0 deletions backends/bmv2/run-bmv2-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ def run_model(options, tmpdir, jsonfile):
testfile = dirname + "/" + base + ".stf"
print("Check for ", testfile)
if not os.path.isfile(testfile):
# If no stf file is present just use the empty file
testfile = dirname + "/empty.stf"
if not os.path.isfile(testfile):
# If no empty.stf present, don't try to run the model at all
return SUCCESS

bmv2 = RunBMV2(tmpdir, options, jsonfile)
Expand Down
2 changes: 1 addition & 1 deletion control-plane/PI
Submodule PI updated 66 files
+24 −31 CLI/table_common.c
+8 −8 CLI/table_dump.c
+1 −1 CLI/utils.c
+4 −6 examples/example_1.c
+5 −7 examples/example_2.c
+2 −2 frontends_extra/cpp/example/example.cpp
+13 −22 frontends_extra/cpp/src/tables.cpp
+16 −18 generators/fe_defines.c
+27 −7 generators/pd/gen_pd.py
+2 −1 generators/pd/templates/src/pd_tables.c
+3 −1 include/Makefile.am
+17 −0 include/PI/int/pi_int.h
+4 −9 include/PI/p4info.h
+1 −7 include/PI/p4info/actions.h
+56 −0 include/PI/p4info/field_list.h
+51 −0 include/PI/p4info/fields.h
+12 −27 include/PI/p4info/tables.h
+0 −3 include/PI/pi.h
+5 −2 include/PI/pi_base.h
+10 −12 include/PI/pi_value.h
+1 −1 proto/Makefile.am
+3 −0 proto/PI/proto/util.h
+0 −1 proto/configure.ac
+21 −3 proto/demo_grpc/Makefile.am
+0 −0 proto/demo_grpc/PI/proto/pi_server.h
+0 −0 proto/demo_grpc/pi_server.cpp
+7 −8 proto/demo_grpc/simple_router_mgr.cpp
+2 −2 proto/demo_grpc/test_perf.cpp
+0 −6 proto/frontend/Makefile.am
+8 −7 proto/frontend/src/device_mgr.cpp
+32 −0 proto/p4/config/p4info.proto
+78 −44 proto/p4info/p4info_to_and_from_proto.cpp
+0 −19 proto/server/Makefile.am
+6 −0 proto/src/util.cpp
+9 −5 proto/tests/test_proto_fe.cpp
+4 −0 src/Makefile.am
+120 −28 src/config_readers/bmv2_json_reader.c
+81 −21 src/config_readers/native_json_reader.c
+15 −21 src/frontends/generic/pi.c
+38 −33 src/p4info/actions.c
+160 −0 src/p4info/field_list.c
+46 −0 src/p4info/field_list_int.h
+129 −0 src/p4info/fields.c
+42 −0 src/p4info/fields_int.h
+16 −0 src/p4info/p4info.c
+0 −21 src/p4info/p4info_common.c
+0 −5 src/p4info/p4info_common.h
+2 −4 src/p4info/p4info_name_map.c
+2 −3 src/p4info/p4info_name_map.h
+2 −47 src/p4info/p4info_struct.c
+3 −2 src/p4info/p4info_struct.h
+38 −102 src/p4info/tables.c
+1 −2 src/p4info/tables_int.h
+3 −12 src/p4info_int.h
+29 −6 src/pi.c
+22 −30 src/pi_value.c
+2 −3 targets/bmv2/action_helpers.cpp
+1 −1 targets/bmv2/common.h
+22 −13 targets/bmv2/pi_learn_imp.cpp
+8 −10 targets/bmv2/pi_tables_imp.cpp
+1 −0 tests/Makefile.am
+13 −9 tests/frontends/generic/test.c
+40 −2 tests/test_bmv2_json_reader.c
+34 −39 tests/test_getnetv.c
+188 −107 tests/test_p4info.c
+62 −0 tests/testdata/pi_omit.json
6 changes: 3 additions & 3 deletions frontends/p4/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class FrontEndLast : public PassManager {
FrontEndLast() { setName("FrontEndLast"); }
};

const IR::P4Program*
FrontEnd::run(const CompilerOptions &options, const IR::P4Program* program) {
const IR::P4Program *FrontEnd::run(const CompilerOptions &options, const IR::P4Program* program,
bool skipSideEffectOrdering) {
if (program == nullptr)
return nullptr;

Expand Down Expand Up @@ -113,7 +113,7 @@ FrontEnd::run(const CompilerOptions &options, const IR::P4Program* program) {
new UniqueNames(&refMap), // Give each local declaration a unique internal name
new MoveDeclarations(), // Move all local declarations to the beginning
new MoveInitializers(),
new SideEffectOrdering(&refMap, &typeMap),
skipSideEffectOrdering ? nullptr : new SideEffectOrdering(&refMap, &typeMap),
new SimplifyControlFlow(&refMap, &typeMap),
new MoveDeclarations(), // Move all local declarations to the beginning
new SimplifyDefUse(&refMap, &typeMap),
Expand Down
3 changes: 2 additions & 1 deletion frontends/p4/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class FrontEnd {
FrontEnd() = default;
explicit FrontEnd(DebugHook hook) { hooks.push_back(hook); }
void addDebugHook(DebugHook hook) { hooks.push_back(hook); }
const IR::P4Program* run(const CompilerOptions& options, const IR::P4Program* program);
const IR::P4Program* run(const CompilerOptions& options, const IR::P4Program* program,
bool skipSideEffectOrdering = false);
};

} // namespace P4
Expand Down
136 changes: 136 additions & 0 deletions testdata/p4_14_samples/misc_prim.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
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.
*/

/* Sample P4 program */
header_type pkt_t {
fields {
field_a_32 : 32;
field_b_32 : 32 (signed);
field_c_32 : 32;
field_d_32 : 32;

field_e_16 : 16;
field_f_16 : 16;
field_g_16 : 16;
field_h_16 : 16;

field_i_8 : 8;
field_j_8 : 8;
field_k_8 : 8;
field_l_8 : 8;

field_x_32 : 32 (signed);
}
}

parser start {
return parse_ethernet;
}

header pkt_t pkt;

parser parse_ethernet {
extract(pkt);
return ingress;
}

action action_0(){
bit_nor(pkt.field_a_32, pkt.field_b_32, pkt.field_c_32);
}
action action_1(param0){
bit_nand(pkt.field_a_32, param0, pkt.field_c_32);
}
action action_2(param0){
bit_xnor(pkt.field_a_32, pkt.field_b_32, param0);
}
action action_3(){
bit_not(pkt.field_a_32, pkt.field_d_32);
}
action action_4(param0){
min(pkt.field_a_32, pkt.field_d_32, param0);
}
action action_5(param0){
max(pkt.field_a_32, param0, pkt.field_d_32);
}
action action_6(){
min(pkt.field_b_32, pkt.field_d_32, 7);
}
action action_7(param0){
max(pkt.field_b_32, param0, pkt.field_d_32);
}
action action_8(param0){
max(pkt.field_x_32, pkt.field_x_32, param0);
}
action action_9(){
shift_right(pkt.field_x_32, pkt.field_x_32, 7);
}

action action_10(param0){
//bit_andca(pkt.field_a_32, pkt.field_a_32, param0);
bit_andca(pkt.field_a_32, param0, pkt.field_a_32);
}

action action_11(param0){
//bit_andcb(pkt.field_a_32, pkt.field_a_32, param0);
bit_andcb(pkt.field_a_32, param0, pkt.field_a_32);
}

action action_12(param0){
//bit_orca(pkt.field_a_32, pkt.field_a_32, param0);
bit_orca(pkt.field_a_32, param0, pkt.field_a_32);
}

action action_13(param0){
//bit_orcb(pkt.field_a_32, pkt.field_a_32, param0);
bit_orcb(pkt.field_a_32, param0, pkt.field_a_32);
}

action do_nothing(){}

table table_0 {
reads {
pkt.field_a_32 : ternary;
pkt.field_b_32 : ternary;
pkt.field_c_32 : ternary;
pkt.field_d_32 : ternary;
pkt.field_g_16 : ternary;
pkt.field_h_16 : ternary;
}
actions {
action_0;
action_1;
action_2;
action_3;
action_4;
action_5;
action_6;
action_7;
action_8;
action_9;
action_10;
action_11;
action_12;
action_13;
do_nothing;
}
size : 512;
}

/* Main control flow */

control ingress {
apply(table_0);
}
139 changes: 139 additions & 0 deletions testdata/p4_14_samples_outputs/misc_prim-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include <core.p4>
#include <v1model.p4>

header pkt_t {
bit<32> field_a_32;
int<32> field_b_32;
bit<32> field_c_32;
bit<32> field_d_32;
bit<16> field_e_16;
bit<16> field_f_16;
bit<16> field_g_16;
bit<16> field_h_16;
bit<8> field_i_8;
bit<8> field_j_8;
bit<8> field_k_8;
bit<8> field_l_8;
int<32> field_x_32;
}

struct metadata {
}

struct headers {
@name("pkt")
pkt_t pkt;
}

parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
@name("parse_ethernet") state parse_ethernet {
packet.extract<pkt_t>(hdr.pkt);
transition accept;
}
@name("start") state start {
transition parse_ethernet;
}
}

control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
@name("action_0") action action_14() {
hdr.pkt.field_a_32 = (bit<32>)~(hdr.pkt.field_b_32 | (int<32>)hdr.pkt.field_c_32);
}
@name("action_1") action action_15(bit<32> param0) {
hdr.pkt.field_a_32 = ~(param0 & hdr.pkt.field_c_32);
}
@name("action_2") action action_16(bit<32> param0) {
hdr.pkt.field_a_32 = (bit<32>)~(hdr.pkt.field_b_32 ^ (int<32>)param0);
}
@name("action_3") action action_17() {
hdr.pkt.field_a_32 = ~hdr.pkt.field_d_32;
}
@name("action_4") action action_18(bit<32> param0) {
hdr.pkt.field_a_32 = (hdr.pkt.field_d_32 <= param0 ? hdr.pkt.field_d_32 : param0);
}
@name("action_5") action action_19(bit<32> param0) {
hdr.pkt.field_a_32 = (param0 >= hdr.pkt.field_d_32 ? param0 : hdr.pkt.field_d_32);
}
@name("action_6") action action_20() {
hdr.pkt.field_b_32 = (int<32>)(hdr.pkt.field_d_32 <= 32w7 ? hdr.pkt.field_d_32 : 32w7);
}
@name("action_7") action action_21(int<32> param0) {
hdr.pkt.field_b_32 = (param0 >= (int<32>)hdr.pkt.field_d_32 ? param0 : (int<32>)hdr.pkt.field_d_32);
}
@name("action_8") action action_22(int<32> param0) {
hdr.pkt.field_x_32 = (hdr.pkt.field_x_32 >= param0 ? hdr.pkt.field_x_32 : param0);
}
@name("action_9") action action_23() {
hdr.pkt.field_x_32 = hdr.pkt.field_x_32 >> 7;
}
@name("action_10") action action_24(bit<32> param0) {
hdr.pkt.field_a_32 = ~param0 & hdr.pkt.field_a_32;
}
@name("action_11") action action_25(bit<32> param0) {
hdr.pkt.field_a_32 = param0 & ~hdr.pkt.field_a_32;
}
@name("action_12") action action_26(bit<32> param0) {
hdr.pkt.field_a_32 = ~param0 | hdr.pkt.field_a_32;
}
@name("action_13") action action_27(bit<32> param0) {
hdr.pkt.field_a_32 = param0 | ~hdr.pkt.field_a_32;
}
@name("do_nothing") action do_nothing_0() {
}
@name("table_0") table table_1() {
actions = {
action_14();
action_15();
action_16();
action_17();
action_18();
action_19();
action_20();
action_21();
action_22();
action_23();
action_24();
action_25();
action_26();
action_27();
do_nothing_0();
@default_only NoAction();
}
key = {
hdr.pkt.field_a_32: ternary @name("hdr.pkt.field_a_32") ;
hdr.pkt.field_b_32: ternary @name("hdr.pkt.field_b_32") ;
hdr.pkt.field_c_32: ternary @name("hdr.pkt.field_c_32") ;
hdr.pkt.field_d_32: ternary @name("hdr.pkt.field_d_32") ;
hdr.pkt.field_g_16: ternary @name("hdr.pkt.field_g_16") ;
hdr.pkt.field_h_16: ternary @name("hdr.pkt.field_h_16") ;
}
size = 512;
default_action = NoAction();
}
apply {
table_1.apply();
}
}

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

control DeparserImpl(packet_out packet, in headers hdr) {
apply {
packet.emit<pkt_t>(hdr.pkt);
}
}

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

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

V1Switch<headers, metadata>(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;
Loading