From aea22bef942358aa8eb623811c9c0e569bf55fc4 Mon Sep 17 00:00:00 2001 From: Chris Dodd Date: Tue, 20 Feb 2024 10:57:17 +1300 Subject: [PATCH] Don't apply defaultArguments in table action lists (#4434) Co-authored-by: Chris Dodd --- frontends/p4/defaultArguments.h | 5 ++ .../p4_16_samples/default-action-arg-bmv2.p4 | 40 ++++++++++ .../p4_16_samples/default-action-arg-bmv2.stf | 17 +++++ .../default-action-arg-bmv2-first.p4 | 73 ++++++++++++++++++ .../default-action-arg-bmv2-frontend.p4 | 66 ++++++++++++++++ .../default-action-arg-bmv2-midend.p4 | 75 +++++++++++++++++++ .../default-action-arg-bmv2.p4 | 73 ++++++++++++++++++ .../default-action-arg-bmv2.p4-stderr | 0 .../default-action-arg-bmv2.p4.entries.txtpb | 3 + .../default-action-arg-bmv2.p4.p4info.txtpb | 43 +++++++++++ 10 files changed, 395 insertions(+) create mode 100644 testdata/p4_16_samples/default-action-arg-bmv2.p4 create mode 100644 testdata/p4_16_samples/default-action-arg-bmv2.stf create mode 100644 testdata/p4_16_samples_outputs/default-action-arg-bmv2-first.p4 create mode 100644 testdata/p4_16_samples_outputs/default-action-arg-bmv2-frontend.p4 create mode 100644 testdata/p4_16_samples_outputs/default-action-arg-bmv2-midend.p4 create mode 100644 testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4 create mode 100644 testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4-stderr create mode 100644 testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4.entries.txtpb create mode 100644 testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4.p4info.txtpb diff --git a/frontends/p4/defaultArguments.h b/frontends/p4/defaultArguments.h index 32b82378d4..0fbc3ef475 100644 --- a/frontends/p4/defaultArguments.h +++ b/frontends/p4/defaultArguments.h @@ -47,6 +47,11 @@ class DoDefaultArguments : public Transform { const IR::Node *postorder(IR::MethodCallExpression *expression) override; const IR::Node *postorder(IR::Declaration_Instance *inst) override; const IR::Node *postorder(IR::ConstructorCallExpression *ccc) override; + const IR::Node *preorder(IR::ActionList *al) override { + // don't modify the action lists in tables + prune(); + return al; + } }; class DefaultArguments : public PassManager { diff --git a/testdata/p4_16_samples/default-action-arg-bmv2.p4 b/testdata/p4_16_samples/default-action-arg-bmv2.p4 new file mode 100644 index 0000000000..797674225e --- /dev/null +++ b/testdata/p4_16_samples/default-action-arg-bmv2.p4 @@ -0,0 +1,40 @@ +/* +Copyright 2013-present Barefoot Networks, Inc. +Copyright 2024 NVIDIA CORPORATION. + +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 +#include + +header hdr { + bit<16> key; + bit<32> a; + bit<32> b; +} + +control compute(inout hdr h) { + action add(bit<32> va, bit<32> vb = 0) { + h.a = h.a + va; + h.b = h.b + vb; + } + table t { + key = { h.key : exact; } + actions = { add; } + const default_action = add(10, 0); + } + apply { t.apply(); } +} + +#include "arith-inline-skeleton.p4" diff --git a/testdata/p4_16_samples/default-action-arg-bmv2.stf b/testdata/p4_16_samples/default-action-arg-bmv2.stf new file mode 100644 index 0000000000..a5f71fb959 --- /dev/null +++ b/testdata/p4_16_samples/default-action-arg-bmv2.stf @@ -0,0 +1,17 @@ +# bit<16> key bit<32> A bit<32> B +# In the output A = (A + 10), B = (B + 0) + +packet 0 0000 00000000 ABCDEF01 +expect 0 0000 0000000A ABCDEF01 + +packet 0 0000 00000001 00000000 +expect 0 0000 0000000B 00000000 + +packet 0 0000 00000001 00000000 +expect 0 0000 0000000B 00000000 + +packet 0 0000 00000011 00000000 +expect 0 0000 0000001B 00000000 + +packet 0 0000 FFFFFFFF 00000000 +expect 0 0000 00000009 00000000 diff --git a/testdata/p4_16_samples_outputs/default-action-arg-bmv2-first.p4 b/testdata/p4_16_samples_outputs/default-action-arg-bmv2-first.p4 new file mode 100644 index 0000000000..20e672df86 --- /dev/null +++ b/testdata/p4_16_samples_outputs/default-action-arg-bmv2-first.p4 @@ -0,0 +1,73 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +header hdr { + bit<16> key; + bit<32> a; + bit<32> b; +} + +control compute(inout hdr h) { + action add(bit<32> va, bit<32> vb=0) { + h.a = h.a + va; + h.b = h.b + vb; + } + table t { + key = { + h.key: exact @name("h.key"); + } + actions = { + add(); + } + const default_action = add(32w10, 32w0); + } + apply { + t.apply(); + } +} + +struct Headers { + hdr h; +} + +struct Meta { +} + +parser p(packet_in b, out Headers h, inout Meta m, inout standard_metadata_t sm) { + state start { + b.extract(h.h); + transition accept; + } +} + +control vrfy(inout Headers h, inout Meta m) { + apply { + } +} + +control update(inout Headers h, inout Meta m) { + apply { + } +} + +control egress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { + apply { + } +} + +control deparser(packet_out b, in Headers h) { + apply { + b.emit(h.h); + } +} + +control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { + compute() c; + apply { + c.apply(h.h); + sm.egress_spec = 9w0; + } +} + +V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main; diff --git a/testdata/p4_16_samples_outputs/default-action-arg-bmv2-frontend.p4 b/testdata/p4_16_samples_outputs/default-action-arg-bmv2-frontend.p4 new file mode 100644 index 0000000000..534106df08 --- /dev/null +++ b/testdata/p4_16_samples_outputs/default-action-arg-bmv2-frontend.p4 @@ -0,0 +1,66 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +header hdr { + bit<16> key; + bit<32> a; + bit<32> b; +} + +struct Headers { + hdr h; +} + +struct Meta { +} + +parser p(packet_in b, out Headers h, inout Meta m, inout standard_metadata_t sm) { + state start { + b.extract(h.h); + transition accept; + } +} + +control vrfy(inout Headers h, inout Meta m) { + apply { + } +} + +control update(inout Headers h, inout Meta m) { + apply { + } +} + +control egress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { + apply { + } +} + +control deparser(packet_out b, in Headers h) { + apply { + b.emit(h.h); + } +} + +control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { + @name("ingress.c.add") action c_add_0(@name("va") bit<32> va, @name("vb") bit<32> vb=0) { + h.h.a = h.h.a + va; + h.h.b = h.h.b + vb; + } + @name("ingress.c.t") table c_t { + key = { + h.h.key: exact @name("h.key"); + } + actions = { + c_add_0(); + } + const default_action = c_add_0(32w10, 32w0); + } + apply { + c_t.apply(); + sm.egress_spec = 9w0; + } +} + +V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main; diff --git a/testdata/p4_16_samples_outputs/default-action-arg-bmv2-midend.p4 b/testdata/p4_16_samples_outputs/default-action-arg-bmv2-midend.p4 new file mode 100644 index 0000000000..85dcdb57ac --- /dev/null +++ b/testdata/p4_16_samples_outputs/default-action-arg-bmv2-midend.p4 @@ -0,0 +1,75 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +header hdr { + bit<16> key; + bit<32> a; + bit<32> b; +} + +struct Headers { + hdr h; +} + +struct Meta { +} + +parser p(packet_in b, out Headers h, inout Meta m, inout standard_metadata_t sm) { + state start { + b.extract(h.h); + transition accept; + } +} + +control vrfy(inout Headers h, inout Meta m) { + apply { + } +} + +control update(inout Headers h, inout Meta m) { + apply { + } +} + +control egress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { + apply { + } +} + +control deparser(packet_out b, in Headers h) { + apply { + b.emit(h.h); + } +} + +control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { + @name("ingress.c.add") action c_add_0(@name("va") bit<32> va, @name("vb") bit<32> vb=0) { + h.h.a = h.h.a + va; + h.h.b = h.h.b + vb; + } + @name("ingress.c.t") table c_t { + key = { + h.h.key: exact @name("h.key"); + } + actions = { + c_add_0(); + } + const default_action = c_add_0(32w10, 32w0); + } + @hidden action arithinlineskeleton51() { + sm.egress_spec = 9w0; + } + @hidden table tbl_arithinlineskeleton51 { + actions = { + arithinlineskeleton51(); + } + const default_action = arithinlineskeleton51(); + } + apply { + c_t.apply(); + tbl_arithinlineskeleton51.apply(); + } +} + +V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main; diff --git a/testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4 b/testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4 new file mode 100644 index 0000000000..1393ff8e7c --- /dev/null +++ b/testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4 @@ -0,0 +1,73 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +header hdr { + bit<16> key; + bit<32> a; + bit<32> b; +} + +control compute(inout hdr h) { + action add(bit<32> va, bit<32> vb=0) { + h.a = h.a + va; + h.b = h.b + vb; + } + table t { + key = { + h.key: exact; + } + actions = { + add; + } + const default_action = add(10, 0); + } + apply { + t.apply(); + } +} + +struct Headers { + hdr h; +} + +struct Meta { +} + +parser p(packet_in b, out Headers h, inout Meta m, inout standard_metadata_t sm) { + state start { + b.extract(h.h); + transition accept; + } +} + +control vrfy(inout Headers h, inout Meta m) { + apply { + } +} + +control update(inout Headers h, inout Meta m) { + apply { + } +} + +control egress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { + apply { + } +} + +control deparser(packet_out b, in Headers h) { + apply { + b.emit(h.h); + } +} + +control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { + compute() c; + apply { + c.apply(h.h); + sm.egress_spec = 0; + } +} + +V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main; diff --git a/testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4-stderr b/testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4-stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4.entries.txtpb b/testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4.entries.txtpb new file mode 100644 index 0000000000..5cb9652623 --- /dev/null +++ b/testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4.entries.txtpb @@ -0,0 +1,3 @@ +# proto-file: p4/v1/p4runtime.proto +# proto-message: p4.v1.WriteRequest + diff --git a/testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4.p4info.txtpb b/testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4.p4info.txtpb new file mode 100644 index 0000000000..60ec69e011 --- /dev/null +++ b/testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4.p4info.txtpb @@ -0,0 +1,43 @@ +# proto-file: p4/config/v1/p4info.proto +# proto-message: p4.config.v1.P4Info + +pkg_info { + arch: "v1model" +} +tables { + preamble { + id: 43577110 + name: "ingress.c.t" + alias: "t" + } + match_fields { + id: 1 + name: "h.key" + bitwidth: 16 + match_type: EXACT + } + action_refs { + id: 29022044 + } + const_default_action_id: 29022044 + size: 1024 +} +actions { + preamble { + id: 29022044 + name: "ingress.c.add" + alias: "add" + } + params { + id: 1 + name: "va" + bitwidth: 32 + } + params { + id: 2 + name: "vb" + bitwidth: 32 + } +} +type_info { +}