Skip to content

Commit

Permalink
Don't apply defaultArguments in table action lists (#4434)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Dodd <[email protected]>
  • Loading branch information
ChrisDodd and ChrisDodd authored Feb 19, 2024
1 parent a733780 commit aea22be
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 0 deletions.
5 changes: 5 additions & 0 deletions frontends/p4/defaultArguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
40 changes: 40 additions & 0 deletions testdata/p4_16_samples/default-action-arg-bmv2.p4
Original file line number Diff line number Diff line change
@@ -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 <core.p4>
#include <v1model.p4>

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"
17 changes: 17 additions & 0 deletions testdata/p4_16_samples/default-action-arg-bmv2.stf
Original file line number Diff line number Diff line change
@@ -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
73 changes: 73 additions & 0 deletions testdata/p4_16_samples_outputs/default-action-arg-bmv2-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <core.p4>
#define V1MODEL_VERSION 20180101
#include <v1model.p4>

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<hdr>(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<hdr>(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<Headers, Meta>(p(), vrfy(), ingress(), egress(), update(), deparser()) main;
66 changes: 66 additions & 0 deletions testdata/p4_16_samples_outputs/default-action-arg-bmv2-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <core.p4>
#define V1MODEL_VERSION 20180101
#include <v1model.p4>

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<hdr>(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<hdr>(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<Headers, Meta>(p(), vrfy(), ingress(), egress(), update(), deparser()) main;
75 changes: 75 additions & 0 deletions testdata/p4_16_samples_outputs/default-action-arg-bmv2-midend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <core.p4>
#define V1MODEL_VERSION 20180101
#include <v1model.p4>

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<hdr>(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<hdr>(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<Headers, Meta>(p(), vrfy(), ingress(), egress(), update(), deparser()) main;
73 changes: 73 additions & 0 deletions testdata/p4_16_samples_outputs/default-action-arg-bmv2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <core.p4>
#define V1MODEL_VERSION 20180101
#include <v1model.p4>

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;
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# proto-file: p4/v1/p4runtime.proto
# proto-message: p4.v1.WriteRequest

Loading

0 comments on commit aea22be

Please sign in to comment.