From ed822ddf54a3a44cdc8d2fa02eae9152ed64a1f2 Mon Sep 17 00:00:00 2001 From: Usha Gupta Date: Fri, 20 Jan 2023 05:50:52 +0000 Subject: [PATCH 1/2] Fix LNot handling in LOr and LAnd --- backends/dpdk/dpdkArch.h | 15 +- .../pna-example-logical-operations.p4 | 142 ++++++++++++++++++ .../pna-example-Logical-operations-first.p4 | 90 +++++++++++ ...pna-example-Logical-operations-frontend.p4 | 87 +++++++++++ .../pna-example-Logical-operations-midend.p4 | 113 ++++++++++++++ .../pna-example-Logical-operations.p4 | 90 +++++++++++ .../pna-example-Logical-operations.p4-error | 0 .../pna-example-Logical-operations.p4-stderr | 0 ...na-example-Logical-operations.p4.bfrt.json | 5 + .../pna-example-Logical-operations.p4.spec | 66 ++++++++ .../pna-example-logical-operations-first.p4 | 91 +++++++++++ ...pna-example-logical-operations-frontend.p4 | 88 +++++++++++ .../pna-example-logical-operations-midend.p4 | 114 ++++++++++++++ .../pna-example-logical-operations.p4 | 91 +++++++++++ .../pna-example-logical-operations.p4-error | 0 .../pna-example-logical-operations.p4-stderr | 0 ...na-example-logical-operations.p4.bfrt.json | 5 + .../pna-example-logical-operations.p4.spec | 69 +++++++++ 18 files changed, 1060 insertions(+), 6 deletions(-) create mode 100644 testdata/p4_16_samples/pna-example-logical-operations.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-example-Logical-operations-first.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-example-Logical-operations-frontend.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-example-Logical-operations-midend.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4-error create mode 100644 testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4-stderr create mode 100644 testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4.bfrt.json create mode 100644 testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4.spec create mode 100644 testdata/p4_16_samples_outputs/pna-example-logical-operations-first.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-example-logical-operations-frontend.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-example-logical-operations-midend.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-example-logical-operations.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-example-logical-operations.p4-error create mode 100644 testdata/p4_16_samples_outputs/pna-example-logical-operations.p4-stderr create mode 100644 testdata/p4_16_samples_outputs/pna-example-logical-operations.p4.bfrt.json create mode 100644 testdata/p4_16_samples_outputs/pna-example-logical-operations.p4.spec diff --git a/backends/dpdk/dpdkArch.h b/backends/dpdk/dpdkArch.h index 49ede3d66d3..7f16121159e 100644 --- a/backends/dpdk/dpdkArch.h +++ b/backends/dpdk/dpdkArch.h @@ -408,7 +408,7 @@ class LogicalExpressionUnroll : public Inspector { static bool is_logical(const IR::Operation_Binary *bin) { if (bin->is() || bin->is() || bin->is() || bin->is() || bin->is() || bin->is() || bin->is() || bin->is() || - bin->is()) + bin->is() || bin->is()) return true; else return false; @@ -702,7 +702,8 @@ class BreakLogicalExpressionParenthesis : public Transform { } else if (!land->left->is() && !land->left->is() && !land->left->is() && !land->left->is() && !land->left->is() && !land->left->is() && - !land->left->is() && !land->left->is() && + !land->left->is() && !land->left->is() && + !land->left->is() && !land->left->is() && !land->left->is()) { BUG("Logical Expression Unroll pass failed"); } @@ -712,9 +713,10 @@ class BreakLogicalExpressionParenthesis : public Transform { if (auto lor2 = lor->left->to()) { auto sub = new IR::LOr(lor2->right, lor->right); return new IR::LOr(lor2->left, sub); - } else if (!lor->left->is() && !lor->left->is() && + } else if (!lor->left->is() && !lor->left->is() && !lor->left->is() && !lor->left->is() && - !lor->left->is() && !lor->left->is() && + !lor->left->is() && !lor->left->is() && + !lor->left->is() && !lor->left->is() && !lor->left->is()) { BUG("Logical Expression Unroll pass failed"); } @@ -729,8 +731,9 @@ class BreakLogicalExpressionParenthesis : public Transform { class SwapSimpleExpressionToFrontOfLogicalExpression : public Transform { bool is_simple(const IR::Node *n) { if (n->is() || n->is() || n->is() || n->is() || - n->is() || n->is() || n->is() || - n->is() || n->is()) { + n->is() || n->is() || n->is() || + n->is() || n->is() || + n->is()) { return true; } else if (!n->is() && !n->is()) { BUG("Logical Expression Unroll pass failed"); diff --git a/testdata/p4_16_samples/pna-example-logical-operations.p4 b/testdata/p4_16_samples/pna-example-logical-operations.p4 new file mode 100644 index 00000000000..92b9f11fc02 --- /dev/null +++ b/testdata/p4_16_samples/pna-example-logical-operations.p4 @@ -0,0 +1,142 @@ +/* +Copyright 2022 Intel 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 "pna.p4" + + +typedef bit<48> EthernetAddress; + +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + bit<32> srcAddr; + bit<32> dstAddr; +} + +header udp_t { + bit<16> src_port; + bit<16> dst_port; + bit<16> length; + bit<16> checksum; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { + bool flag; + // empty for this skeleton +} + +// User-defined struct containing all of those headers parsed in the +// main parser. +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; + udp_t udp; +} + +control PreControlImpl( + in headers_t hdr, + inout main_metadata_t meta, + in pna_pre_input_metadata_t istd, + inout pna_pre_output_metadata_t ostd) +{ + apply { + } +} + +parser MainParserImpl( + packet_in pkt, + out headers_t hdr, + inout main_metadata_t main_meta, + in pna_main_parser_input_metadata_t istd) +{ + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 0x0800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + transition parse_udp; + } + state parse_udp { + pkt.extract(hdr.udp); + transition accept; + } +} + +control MainControlImpl( + inout headers_t hdr, // from main parser + inout main_metadata_t user_meta, // from main parser, to "next block" + in pna_main_input_metadata_t istd, + inout pna_main_output_metadata_t ostd) +{ + apply { + if (hdr.ipv4.isValid() || !user_meta.flag) { + hdr.ipv4.ttl = hdr.ipv4.ttl + 1; + recirculate(); + } + if (!hdr.udp.isValid() && user_meta.flag) { + hdr.udp.setValid(); + hdr.udp.src_port = hdr.udp.src_port + 1; + recirculate(); + } + } +} + +control MainDeparserImpl( + packet_out pkt, + in headers_t hdr, // from main control + in main_metadata_t user_meta, // from main control + in pna_main_output_metadata_t ostd) +{ + apply { + pkt.emit(hdr.ethernet); + pkt.emit(hdr.ipv4); + pkt.emit(hdr.udp); + } +} + +// BEGIN:Package_Instantiation_Example +PNA_NIC( + MainParserImpl(), + PreControlImpl(), + MainControlImpl(), + MainDeparserImpl() + // Hoping to make this optional parameter later, but not supported + // by p4c yet. + //, PreParserImpl() + ) main; +// END:Package_Instantiation_Example diff --git a/testdata/p4_16_samples_outputs/pna-example-Logical-operations-first.p4 b/testdata/p4_16_samples_outputs/pna-example-Logical-operations-first.p4 new file mode 100644 index 00000000000..7a2ea51275b --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-example-Logical-operations-first.p4 @@ -0,0 +1,90 @@ +#include +#include + +typedef bit<48> EthernetAddress; +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + bit<32> srcAddr; + bit<32> dstAddr; +} + +header udp_t { + bit<16> src_port; + bit<16> dst_port; + bit<16> length; + bit<16> checksum; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; + udp_t udp; +} + +control PreControlImpl(in headers_t hdr, inout main_metadata_t meta, in pna_pre_input_metadata_t istd, inout pna_pre_output_metadata_t ostd) { + apply { + } +} + +parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + transition parse_udp; + } + state parse_udp { + pkt.extract(hdr.udp); + transition accept; + } +} + +control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in pna_main_input_metadata_t istd, inout pna_main_output_metadata_t ostd) { + apply { + if (hdr.ipv4.isValid() || istd.pass != (PassNumber_t)3w0) { + hdr.ipv4.ttl = hdr.ipv4.ttl + 8w1; + recirculate(); + } + if (!hdr.udp.isValid() && istd.pass == (PassNumber_t)3w4) { + hdr.udp.setValid(); + hdr.udp.src_port = hdr.udp.src_port + 16w1; + recirculate(); + } + } +} + +control MainDeparserImpl(packet_out pkt, in headers_t hdr, in main_metadata_t user_meta, in pna_main_output_metadata_t ostd) { + apply { + pkt.emit(hdr.ethernet); + pkt.emit(hdr.ipv4); + pkt.emit(hdr.udp); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; diff --git a/testdata/p4_16_samples_outputs/pna-example-Logical-operations-frontend.p4 b/testdata/p4_16_samples_outputs/pna-example-Logical-operations-frontend.p4 new file mode 100644 index 00000000000..bf2dbd615f7 --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-example-Logical-operations-frontend.p4 @@ -0,0 +1,87 @@ +#include +#include + +typedef bit<48> EthernetAddress; +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + bit<32> srcAddr; + bit<32> dstAddr; +} + +header udp_t { + bit<16> src_port; + bit<16> dst_port; + bit<16> length; + bit<16> checksum; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; + udp_t udp; +} + +control PreControlImpl(in headers_t hdr, inout main_metadata_t meta, in pna_pre_input_metadata_t istd, inout pna_pre_output_metadata_t ostd) { + apply { + } +} + +parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + pkt.extract(hdr.udp); + transition accept; + } +} + +control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in pna_main_input_metadata_t istd, inout pna_main_output_metadata_t ostd) { + apply { + if (hdr.ipv4.isValid() || istd.pass != (PassNumber_t)3w0) { + hdr.ipv4.ttl = hdr.ipv4.ttl + 8w1; + recirculate(); + } + if (!hdr.udp.isValid() && istd.pass == (PassNumber_t)3w4) { + hdr.udp.setValid(); + hdr.udp.src_port = hdr.udp.src_port + 16w1; + recirculate(); + } + } +} + +control MainDeparserImpl(packet_out pkt, in headers_t hdr, in main_metadata_t user_meta, in pna_main_output_metadata_t ostd) { + apply { + pkt.emit(hdr.ethernet); + pkt.emit(hdr.ipv4); + pkt.emit(hdr.udp); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; diff --git a/testdata/p4_16_samples_outputs/pna-example-Logical-operations-midend.p4 b/testdata/p4_16_samples_outputs/pna-example-Logical-operations-midend.p4 new file mode 100644 index 00000000000..aba39890639 --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-example-Logical-operations-midend.p4 @@ -0,0 +1,113 @@ +#include +#include + +header ethernet_t { + bit<48> dstAddr; + bit<48> srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + bit<32> srcAddr; + bit<32> dstAddr; +} + +header udp_t { + bit<16> src_port; + bit<16> dst_port; + bit<16> length; + bit<16> checksum; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; + udp_t udp; +} + +control PreControlImpl(in headers_t hdr, inout main_metadata_t meta, in pna_pre_input_metadata_t istd, inout pna_pre_output_metadata_t ostd) { + apply { + } +} + +parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + pkt.extract(hdr.udp); + transition accept; + } +} + +control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in pna_main_input_metadata_t istd, inout pna_main_output_metadata_t ostd) { + @hidden action pnaexampleLogicaloperations107() { + hdr.ipv4.ttl = hdr.ipv4.ttl + 8w1; + recirculate(); + } + @hidden action pnaexampleLogicaloperations111() { + hdr.udp.setValid(); + hdr.udp.src_port = hdr.udp.src_port + 16w1; + recirculate(); + } + @hidden table tbl_pnaexampleLogicaloperations107 { + actions = { + pnaexampleLogicaloperations107(); + } + const default_action = pnaexampleLogicaloperations107(); + } + @hidden table tbl_pnaexampleLogicaloperations111 { + actions = { + pnaexampleLogicaloperations111(); + } + const default_action = pnaexampleLogicaloperations111(); + } + apply { + if (hdr.ipv4.isValid() || istd.pass != 3w0) { + tbl_pnaexampleLogicaloperations107.apply(); + } + if (!hdr.udp.isValid() && istd.pass == 3w4) { + tbl_pnaexampleLogicaloperations111.apply(); + } + } +} + +control MainDeparserImpl(packet_out pkt, in headers_t hdr, in main_metadata_t user_meta, in pna_main_output_metadata_t ostd) { + @hidden action pnaexampleLogicaloperations125() { + pkt.emit(hdr.ethernet); + pkt.emit(hdr.ipv4); + pkt.emit(hdr.udp); + } + @hidden table tbl_pnaexampleLogicaloperations125 { + actions = { + pnaexampleLogicaloperations125(); + } + const default_action = pnaexampleLogicaloperations125(); + } + apply { + tbl_pnaexampleLogicaloperations125.apply(); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; diff --git a/testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4 b/testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4 new file mode 100644 index 00000000000..7c2479e9ccc --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4 @@ -0,0 +1,90 @@ +#include +#include + +typedef bit<48> EthernetAddress; +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + bit<32> srcAddr; + bit<32> dstAddr; +} + +header udp_t { + bit<16> src_port; + bit<16> dst_port; + bit<16> length; + bit<16> checksum; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; + udp_t udp; +} + +control PreControlImpl(in headers_t hdr, inout main_metadata_t meta, in pna_pre_input_metadata_t istd, inout pna_pre_output_metadata_t ostd) { + apply { + } +} + +parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + transition parse_udp; + } + state parse_udp { + pkt.extract(hdr.udp); + transition accept; + } +} + +control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in pna_main_input_metadata_t istd, inout pna_main_output_metadata_t ostd) { + apply { + if (hdr.ipv4.isValid() || !(istd.pass == (PassNumber_t)0)) { + hdr.ipv4.ttl = hdr.ipv4.ttl + 1; + recirculate(); + } + if (!hdr.udp.isValid() && istd.pass == (PassNumber_t)4) { + hdr.udp.setValid(); + hdr.udp.src_port = hdr.udp.src_port + 1; + recirculate(); + } + } +} + +control MainDeparserImpl(packet_out pkt, in headers_t hdr, in main_metadata_t user_meta, in pna_main_output_metadata_t ostd) { + apply { + pkt.emit(hdr.ethernet); + pkt.emit(hdr.ipv4); + pkt.emit(hdr.udp); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; diff --git a/testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4-error b/testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4-error new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4-stderr b/testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4-stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4.bfrt.json b/testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4.bfrt.json new file mode 100644 index 00000000000..b6d66a630db --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4.bfrt.json @@ -0,0 +1,5 @@ +{ + "schema_version" : "1.0.0", + "tables" : [], + "learn_filters" : [] +} \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4.spec b/testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4.spec new file mode 100644 index 00000000000..aa96f61fafe --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-example-Logical-operations.p4.spec @@ -0,0 +1,66 @@ + +struct ethernet_t { + bit<48> dstAddr + bit<48> srcAddr + bit<16> etherType +} + +struct ipv4_t { + bit<8> version_ihl + bit<8> diffserv + bit<16> totalLen + bit<16> identification + bit<16> flags_fragOffset + bit<8> ttl + bit<8> protocol + bit<16> hdrChecksum + bit<32> srcAddr + bit<32> dstAddr +} + +struct udp_t { + bit<16> src_port + bit<16> dst_port + bit<16> length + bit<16> checksum +} + +struct main_metadata_t { + bit<32> pna_main_input_metadata_pass + bit<32> pna_main_input_metadata_input_port + bit<32> pna_main_output_metadata_output_port +} +metadata instanceof main_metadata_t + +header ethernet instanceof ethernet_t +header ipv4 instanceof ipv4_t +header udp instanceof udp_t + +regarray direction size 0x100 initval 0 + +apply { + rx m.pna_main_input_metadata_input_port + extract h.ethernet + jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType 0x800 + jmp MAINPARSERIMPL_ACCEPT + MAINPARSERIMPL_PARSE_IPV4 : extract h.ipv4 + extract h.udp + MAINPARSERIMPL_ACCEPT : jmpv LABEL_TRUE h.ipv4 + recircid m.pna_main_input_metadata_pass + jmpneq LABEL_TRUE m.pna_main_input_metadata_pass 0x0 + jmp LABEL_END + LABEL_TRUE : add h.ipv4.ttl 0x1 + recirculate + LABEL_END : jmpv LABEL_END_0 h.udp + recircid m.pna_main_input_metadata_pass + jmpneq LABEL_END_0 m.pna_main_input_metadata_pass 0x4 + validate h.udp + add h.udp.src_port 0x1 + recirculate + LABEL_END_0 : emit h.ethernet + emit h.ipv4 + emit h.udp + tx m.pna_main_output_metadata_output_port +} + + diff --git a/testdata/p4_16_samples_outputs/pna-example-logical-operations-first.p4 b/testdata/p4_16_samples_outputs/pna-example-logical-operations-first.p4 new file mode 100644 index 00000000000..b6ee6ffe652 --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-example-logical-operations-first.p4 @@ -0,0 +1,91 @@ +#include +#include + +typedef bit<48> EthernetAddress; +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + bit<32> srcAddr; + bit<32> dstAddr; +} + +header udp_t { + bit<16> src_port; + bit<16> dst_port; + bit<16> length; + bit<16> checksum; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { + bool flag; +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; + udp_t udp; +} + +control PreControlImpl(in headers_t hdr, inout main_metadata_t meta, in pna_pre_input_metadata_t istd, inout pna_pre_output_metadata_t ostd) { + apply { + } +} + +parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + transition parse_udp; + } + state parse_udp { + pkt.extract(hdr.udp); + transition accept; + } +} + +control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in pna_main_input_metadata_t istd, inout pna_main_output_metadata_t ostd) { + apply { + if (hdr.ipv4.isValid() || !user_meta.flag) { + hdr.ipv4.ttl = hdr.ipv4.ttl + 8w1; + recirculate(); + } + if (!hdr.udp.isValid() && user_meta.flag) { + hdr.udp.setValid(); + hdr.udp.src_port = hdr.udp.src_port + 16w1; + recirculate(); + } + } +} + +control MainDeparserImpl(packet_out pkt, in headers_t hdr, in main_metadata_t user_meta, in pna_main_output_metadata_t ostd) { + apply { + pkt.emit(hdr.ethernet); + pkt.emit(hdr.ipv4); + pkt.emit(hdr.udp); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; diff --git a/testdata/p4_16_samples_outputs/pna-example-logical-operations-frontend.p4 b/testdata/p4_16_samples_outputs/pna-example-logical-operations-frontend.p4 new file mode 100644 index 00000000000..3a00cadcae7 --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-example-logical-operations-frontend.p4 @@ -0,0 +1,88 @@ +#include +#include + +typedef bit<48> EthernetAddress; +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + bit<32> srcAddr; + bit<32> dstAddr; +} + +header udp_t { + bit<16> src_port; + bit<16> dst_port; + bit<16> length; + bit<16> checksum; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { + bool flag; +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; + udp_t udp; +} + +control PreControlImpl(in headers_t hdr, inout main_metadata_t meta, in pna_pre_input_metadata_t istd, inout pna_pre_output_metadata_t ostd) { + apply { + } +} + +parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + pkt.extract(hdr.udp); + transition accept; + } +} + +control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in pna_main_input_metadata_t istd, inout pna_main_output_metadata_t ostd) { + apply { + if (hdr.ipv4.isValid() || !user_meta.flag) { + hdr.ipv4.ttl = hdr.ipv4.ttl + 8w1; + recirculate(); + } + if (!hdr.udp.isValid() && user_meta.flag) { + hdr.udp.setValid(); + hdr.udp.src_port = hdr.udp.src_port + 16w1; + recirculate(); + } + } +} + +control MainDeparserImpl(packet_out pkt, in headers_t hdr, in main_metadata_t user_meta, in pna_main_output_metadata_t ostd) { + apply { + pkt.emit(hdr.ethernet); + pkt.emit(hdr.ipv4); + pkt.emit(hdr.udp); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; diff --git a/testdata/p4_16_samples_outputs/pna-example-logical-operations-midend.p4 b/testdata/p4_16_samples_outputs/pna-example-logical-operations-midend.p4 new file mode 100644 index 00000000000..01f86721654 --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-example-logical-operations-midend.p4 @@ -0,0 +1,114 @@ +#include +#include + +header ethernet_t { + bit<48> dstAddr; + bit<48> srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + bit<32> srcAddr; + bit<32> dstAddr; +} + +header udp_t { + bit<16> src_port; + bit<16> dst_port; + bit<16> length; + bit<16> checksum; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { + bool flag; +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; + udp_t udp; +} + +control PreControlImpl(in headers_t hdr, inout main_metadata_t meta, in pna_pre_input_metadata_t istd, inout pna_pre_output_metadata_t ostd) { + apply { + } +} + +parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + pkt.extract(hdr.udp); + transition accept; + } +} + +control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in pna_main_input_metadata_t istd, inout pna_main_output_metadata_t ostd) { + @hidden action pnaexamplelogicaloperations108() { + hdr.ipv4.ttl = hdr.ipv4.ttl + 8w1; + recirculate(); + } + @hidden action pnaexamplelogicaloperations112() { + hdr.udp.setValid(); + hdr.udp.src_port = hdr.udp.src_port + 16w1; + recirculate(); + } + @hidden table tbl_pnaexamplelogicaloperations108 { + actions = { + pnaexamplelogicaloperations108(); + } + const default_action = pnaexamplelogicaloperations108(); + } + @hidden table tbl_pnaexamplelogicaloperations112 { + actions = { + pnaexamplelogicaloperations112(); + } + const default_action = pnaexamplelogicaloperations112(); + } + apply { + if (hdr.ipv4.isValid() || !user_meta.flag) { + tbl_pnaexamplelogicaloperations108.apply(); + } + if (!hdr.udp.isValid() && user_meta.flag) { + tbl_pnaexamplelogicaloperations112.apply(); + } + } +} + +control MainDeparserImpl(packet_out pkt, in headers_t hdr, in main_metadata_t user_meta, in pna_main_output_metadata_t ostd) { + @hidden action pnaexamplelogicaloperations126() { + pkt.emit(hdr.ethernet); + pkt.emit(hdr.ipv4); + pkt.emit(hdr.udp); + } + @hidden table tbl_pnaexamplelogicaloperations126 { + actions = { + pnaexamplelogicaloperations126(); + } + const default_action = pnaexamplelogicaloperations126(); + } + apply { + tbl_pnaexamplelogicaloperations126.apply(); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; diff --git a/testdata/p4_16_samples_outputs/pna-example-logical-operations.p4 b/testdata/p4_16_samples_outputs/pna-example-logical-operations.p4 new file mode 100644 index 00000000000..ec8e089fad5 --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-example-logical-operations.p4 @@ -0,0 +1,91 @@ +#include +#include + +typedef bit<48> EthernetAddress; +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + bit<32> srcAddr; + bit<32> dstAddr; +} + +header udp_t { + bit<16> src_port; + bit<16> dst_port; + bit<16> length; + bit<16> checksum; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { + bool flag; +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; + udp_t udp; +} + +control PreControlImpl(in headers_t hdr, inout main_metadata_t meta, in pna_pre_input_metadata_t istd, inout pna_pre_output_metadata_t ostd) { + apply { + } +} + +parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + transition parse_udp; + } + state parse_udp { + pkt.extract(hdr.udp); + transition accept; + } +} + +control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in pna_main_input_metadata_t istd, inout pna_main_output_metadata_t ostd) { + apply { + if (hdr.ipv4.isValid() || !user_meta.flag) { + hdr.ipv4.ttl = hdr.ipv4.ttl + 1; + recirculate(); + } + if (!hdr.udp.isValid() && user_meta.flag) { + hdr.udp.setValid(); + hdr.udp.src_port = hdr.udp.src_port + 1; + recirculate(); + } + } +} + +control MainDeparserImpl(packet_out pkt, in headers_t hdr, in main_metadata_t user_meta, in pna_main_output_metadata_t ostd) { + apply { + pkt.emit(hdr.ethernet); + pkt.emit(hdr.ipv4); + pkt.emit(hdr.udp); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; diff --git a/testdata/p4_16_samples_outputs/pna-example-logical-operations.p4-error b/testdata/p4_16_samples_outputs/pna-example-logical-operations.p4-error new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/pna-example-logical-operations.p4-stderr b/testdata/p4_16_samples_outputs/pna-example-logical-operations.p4-stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/pna-example-logical-operations.p4.bfrt.json b/testdata/p4_16_samples_outputs/pna-example-logical-operations.p4.bfrt.json new file mode 100644 index 00000000000..b6d66a630db --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-example-logical-operations.p4.bfrt.json @@ -0,0 +1,5 @@ +{ + "schema_version" : "1.0.0", + "tables" : [], + "learn_filters" : [] +} \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-logical-operations.p4.spec b/testdata/p4_16_samples_outputs/pna-example-logical-operations.p4.spec new file mode 100644 index 00000000000..69b90e6d90b --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-example-logical-operations.p4.spec @@ -0,0 +1,69 @@ + +struct ethernet_t { + bit<48> dstAddr + bit<48> srcAddr + bit<16> etherType +} + +struct ipv4_t { + bit<8> version_ihl + bit<8> diffserv + bit<16> totalLen + bit<16> identification + bit<16> flags_fragOffset + bit<8> ttl + bit<8> protocol + bit<16> hdrChecksum + bit<32> srcAddr + bit<32> dstAddr +} + +struct udp_t { + bit<16> src_port + bit<16> dst_port + bit<16> length + bit<16> checksum +} + +struct main_metadata_t { + bit<32> pna_main_input_metadata_input_port + bit<8> local_metadata_flag + bit<32> pna_main_output_metadata_output_port + bit<8> MainControlT_tmp +} +metadata instanceof main_metadata_t + +header ethernet instanceof ethernet_t +header ipv4 instanceof ipv4_t +header udp instanceof udp_t + +regarray direction size 0x100 initval 0 + +apply { + rx m.pna_main_input_metadata_input_port + extract h.ethernet + jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType 0x800 + jmp MAINPARSERIMPL_ACCEPT + MAINPARSERIMPL_PARSE_IPV4 : extract h.ipv4 + extract h.udp + MAINPARSERIMPL_ACCEPT : jmpeq LABEL_TRUE m.local_metadata_flag 0x0 + mov m.MainControlT_tmp 0x0 + jmp LABEL_END + LABEL_TRUE : mov m.MainControlT_tmp 0x1 + LABEL_END : jmpv LABEL_TRUE_0 h.ipv4 + jmpeq LABEL_TRUE_0 m.MainControlT_tmp 0x1 + jmp LABEL_END_0 + LABEL_TRUE_0 : add h.ipv4.ttl 0x1 + recirculate + LABEL_END_0 : jmpv LABEL_END_1 h.udp + jmpneq LABEL_END_1 m.local_metadata_flag 0x1 + validate h.udp + add h.udp.src_port 0x1 + recirculate + LABEL_END_1 : emit h.ethernet + emit h.ipv4 + emit h.udp + tx m.pna_main_output_metadata_output_port +} + + From 419302bd4bbda8f84c1f372cbc99712a1ca72a56 Mon Sep 17 00:00:00 2001 From: Usha Gupta Date: Mon, 23 Jan 2023 15:01:42 +0000 Subject: [PATCH 2/2] Attempt to fix clang sanitizer build --- backends/dpdk/dpdkArch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backends/dpdk/dpdkArch.h b/backends/dpdk/dpdkArch.h index 7f16121159e..a60c8cbd982 100644 --- a/backends/dpdk/dpdkArch.h +++ b/backends/dpdk/dpdkArch.h @@ -408,7 +408,7 @@ class LogicalExpressionUnroll : public Inspector { static bool is_logical(const IR::Operation_Binary *bin) { if (bin->is() || bin->is() || bin->is() || bin->is() || bin->is() || bin->is() || bin->is() || bin->is() || - bin->is() || bin->is()) + bin->is()) return true; else return false;