From ce5c019c5a9b84197ae704282fb8ca6f79e5891b Mon Sep 17 00:00:00 2001 From: Kamlesh Kumar Date: Mon, 18 Apr 2022 00:29:55 -0800 Subject: [PATCH 1/6] [dpdk] Extract pna direction from input port --- backends/dpdk/DpdkXfail.cmake | 9 +- backends/dpdk/backend.cpp | 8 + backends/dpdk/dpdkAsmOpt.cpp | 123 ++++++++++-- backends/dpdk/dpdkAsmOpt.h | 45 ++++- backends/dpdk/dpdkUtils.cpp | 10 + backends/dpdk/dpdkUtils.h | 2 +- .../pna-direction-main-parser-err.p4 | 185 +++++++++++++++++ testdata/p4_16_samples/pna-direction.p4 | 188 ++++++++++++++++++ .../pna-action-selector.p4.spec | 2 + .../pna-add-on-miss.p4.spec | 2 + .../pna-direction-first.p4 | 104 ++++++++++ .../pna-direction-frontend.p4 | 103 ++++++++++ .../pna-direction-main-parser-err-first.p4 | 115 +++++++++++ .../pna-direction-main-parser-err-frontend.p4 | 112 +++++++++++ .../pna-direction-main-parser-err-midend.p4 | 162 +++++++++++++++ .../pna-direction-main-parser-err.p4 | 106 ++++++++++ .../pna-direction-main-parser-err.p4-stderr | 0 .../pna-direction-midend.p4 | 157 +++++++++++++++ .../p4_16_samples_outputs/pna-direction.p4 | 104 ++++++++++ .../pna-direction.p4-error | 0 .../pna-direction.p4-stderr | 0 .../pna-direction.p4.bfrt.json | 61 ++++++ .../pna-direction.p4.spec | 107 ++++++++++ .../pna-dpdk-parser-state-err.p4.spec | 2 + .../pna-dpdk-table-key-use-annon.p4.spec | 2 + .../pna-example-SelectByDirection.p4.spec | 9 + .../pna-example-SelectByDirection1.p4.spec | 9 + .../pna-example-SelectByDirection2.p4.spec | 9 + .../pna-example-dpdk-varbit.p4.spec | 2 + .../pna-example-mirror-packet.p4.spec | 2 + .../pna-example-template.p4.spec | 2 + .../pna-example-tunnel.p4.spec | 11 +- .../pna-extract-local-header.p4.spec | 2 + .../pna-issue3041.p4.spec | 2 + .../pna-lookahead-structure-bit-field.p4.spec | 2 + .../pna-lookahead-structure.p4.spec | 2 + .../pna-mux-dismantle.p4.spec | 2 + .../pna-subparser.p4.spec | 2 + 38 files changed, 1738 insertions(+), 27 deletions(-) create mode 100644 testdata/p4_16_samples/pna-direction-main-parser-err.p4 create mode 100644 testdata/p4_16_samples/pna-direction.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-direction-first.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-direction-frontend.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-direction-main-parser-err-first.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-direction-main-parser-err-frontend.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-direction-main-parser-err-midend.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4-stderr create mode 100644 testdata/p4_16_samples_outputs/pna-direction-midend.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-direction.p4 create mode 100644 testdata/p4_16_samples_outputs/pna-direction.p4-error create mode 100644 testdata/p4_16_samples_outputs/pna-direction.p4-stderr create mode 100644 testdata/p4_16_samples_outputs/pna-direction.p4.bfrt.json create mode 100644 testdata/p4_16_samples_outputs/pna-direction.p4.spec diff --git a/backends/dpdk/DpdkXfail.cmake b/backends/dpdk/DpdkXfail.cmake index d742873ed95..cf485f05491 100644 --- a/backends/dpdk/DpdkXfail.cmake +++ b/backends/dpdk/DpdkXfail.cmake @@ -71,10 +71,6 @@ p4c_add_xfail_reason("dpdk" testdata/p4_16_samples/psa-dpdk-lpm-match-err2.p4 ) -p4c_add_xfail_reason("dpdk" - "Non Type_Bits type bool for expression" - ) - p4c_add_xfail_reason("dpdk" "mirror_packet cannot be used in the" testdata/p4_16_samples/pna-example-mirror-packet-ctxt-error.p4 @@ -96,6 +92,11 @@ p4c_add_xfail_reason("dpdk" testdata/p4_16_samples/pna-example-mirror-packet-error3.p4 ) +p4c_add_xfail_reason("dpdk" + "declaration not found" + testdata/p4_16_samples/pna-direction-main-parser-err.p4 + ) + p4c_add_xfail_reason("dpdk" "All table keys together with holes in the underlying structure should fit in 64 bytes" testdata/p4_16_samples/psa-dpdk-table-key-error.p4 diff --git a/backends/dpdk/backend.cpp b/backends/dpdk/backend.cpp index a451b8878dd..592518106fc 100644 --- a/backends/dpdk/backend.cpp +++ b/backends/dpdk/backend.cpp @@ -122,6 +122,14 @@ void DpdkBackend::convert(const IR::ToplevelBlock *tlb) { dpdk_program = convertToDpdk->getDpdkProgram(); if (!dpdk_program) return; + if (structure.p4arch == "pna") { + PassManager post_code_gen = { + new DirectionToRegRead(), + new AddNewMetadataFields(), + }; + dpdk_program = dpdk_program->apply(post_code_gen)->to(); + } + PassManager post_code_gen = { new EliminateUnusedAction(), new DpdkAsmOptimization, diff --git a/backends/dpdk/dpdkAsmOpt.cpp b/backends/dpdk/dpdkAsmOpt.cpp index 054d4eabbde..87826319194 100644 --- a/backends/dpdk/dpdkAsmOpt.cpp +++ b/backends/dpdk/dpdkAsmOpt.cpp @@ -15,6 +15,7 @@ limitations under the License. */ #include "dpdkAsmOpt.h" +#include "dpdkUtils.h" namespace DPDK { // The assumption is compiler can only produce forward jumps. @@ -178,12 +179,8 @@ bool RemoveUnusedMetadataFields::isByteSizeField(const IR::Type *field_type) { const IR::Node* RemoveUnusedMetadataFields::preorder(IR::DpdkAsmProgram *p) { IR::IndexedVector usedStruct; - bool isMetadataStruct = false; for (auto st : p->structType) { - if (!isMetadataStruct) { - for (auto anno : st->annotations->annotations) { - if (anno->name == "__metadata__") { - isMetadataStruct = true; + if (isMetadataStruct(st)) { IR::IndexedVector usedMetadataFields; for (auto field : st->fields) { if (used_fields.count(field->name.name)) { @@ -198,11 +195,6 @@ const IR::Node* RemoveUnusedMetadataFields::preorder(IR::DpdkAsmProgram *p) { auto newSt = new IR::DpdkStructType(st->srcInfo, st->name, st->annotations, usedMetadataFields); usedStruct.push_back(newSt); - } - } - if (!isMetadataStruct) { - usedStruct.push_back(st); - } } else { usedStruct.push_back(st); } @@ -227,15 +219,6 @@ int ValidateTableKeys::getFieldSizeBits(const IR::Type *field_type) { return -1; } -bool ValidateTableKeys::isMetadataStruct(const IR::Type_Struct *st) { - for (auto anno : st->annotations->annotations) { - if (anno->name == "__metadata__") { - return true; - } - } - return false; -} - bool ValidateTableKeys::preorder(const IR::DpdkAsmProgram *p) { const IR::DpdkStructType *metaStruct = nullptr; for (auto st : p->structType) { @@ -256,7 +239,8 @@ bool ValidateTableKeys::preorder(const IR::DpdkAsmProgram *p) { "%1% is not a structure field", key); auto keyMem = key->expression->to(); auto type = keyMem->expr->type; - if (type->is() && isMetadataStruct(type->to())) { + if (type->is() + && isMetadataStruct(type->to())) { auto offset = metaStruct->getFieldBitOffset(keyMem->member.name); if (min == -1 || min > offset) min = offset; @@ -280,5 +264,104 @@ bool ValidateTableKeys::preorder(const IR::DpdkAsmProgram *p) { return false; } +const IR::Node* AddNewMetadataFields::preorder(IR::DpdkStructType *st) { + if (isMetadataStruct(st)) { + for (auto nf : newMetadataFields) { + st->fields.push_back(nf); + } + auto newSt = new IR::DpdkStructType(st->srcInfo, st->name, + st->annotations, st->fields); + newMetadataFields.clear(); + return newSt; + } + return st; +} + +const IR::Node* DirectionToRegRead::preorder(IR::DpdkAsmProgram *p) { + p->externDeclarations.push_back(addRegDeclInstance(registerInstanceName)); + return p; + } + +IR::DpdkExternDeclaration* DirectionToRegRead::addRegDeclInstance(cstring instanceName) { + auto typepath = new IR::Path("Register"); + auto type = new IR::Type_Name(typepath); + auto typeargs = new IR::Vector({IR::Type::Bits::get(32), + IR::Type::Bits::get(32)}); + auto spectype = new IR::Type_Specialized(type, typeargs); + auto args = new IR::Vector(); + args->push_back(new IR::Argument(new IR::Constant(IR::Type::Bits::get(32), 1))); + auto annot = IR::Annotations::empty; + annot->addAnnotationIfNew(IR::Annotation::nameAnnotation, + new IR::StringLiteral(instanceName)); + auto decl = new IR::DpdkExternDeclaration(instanceName, annot, spectype, args, + nullptr); + return decl; +} + +void DirectionToRegRead::addMetadataField(cstring fieldName) { + if (newFieldName.count(fieldName)) + return; + newMetadataFields.push_back(new IR::StructField(IR::ID(fieldName), + IR::Type::Bits::get(32))); + newFieldName.insert(fieldName); +} + +bool DirectionToRegRead::isDirection(const IR::Member *m) { + if (m == nullptr) + return false; + return m->member.name == "pna_main_input_metadata_direction" + || m->member.name == "pna_pre_input_metadata_direction" + || m->member.name == "pna_main_parser_input_metadata_direction"; +} + +const IR::Node *DirectionToRegRead::postorder(IR::DpdkListStatement *l) { + l->statements = replaceDirectionWithRegRead(l->statements); + newStmts.clear(); + return l; +} + +void DirectionToRegRead::replaceDirection(const IR::Member *m) { + addMetadataField(reg_read_tmp); + addMetadataField(left_shift_tmp); + auto reade = new IR::Member(new IR::PathExpression(IR::ID("m")), + IR::ID(reg_read_tmp)); + auto reads = new IR::DpdkRegisterReadStatement(reade, registerInstanceName, + new IR::Constant(IR::Type::Bits::get(32), + 0)); + auto shld = new IR::Member(new IR::PathExpression(IR::ID("m")), + IR::ID(left_shift_tmp)); + auto mov = new IR::DpdkMovStatement(shld, new IR::Constant(IR::Type::Bits::get(32), 1)); + auto shl = new IR::DpdkShlStatement(shld, shld, + new IR::Member(new IR::PathExpression(IR::ID("m")), + IR::ID(dirToInput[m->member.name]))); + auto mov1 = new IR::DpdkMovStatement(m, reade); + auto and0 = new IR::DpdkAndStatement(m, m, shld); + newStmts.push_back(reads); + newStmts.push_back(mov); + newStmts.push_back(shl); + newStmts.push_back(mov1); + newStmts.push_back(and0); +} + +IR::IndexedVector +DirectionToRegRead::replaceDirectionWithRegRead(IR::IndexedVector stmts) { + for (auto s : stmts) { + if (auto jc = s->to()) { + if (isDirection(jc->src1->to())) { + replaceDirection(jc->src1->to()); + } else if (isDirection(jc->src2->to())) { + replaceDirection(jc->src2->to()); + } + } else if (auto u = s->to()) { + if (isDirection(u->src->to())) { + replaceDirection(u->src->to()); + } + } + newStmts.push_back(s); + } + return newStmts; +} + size_t ShortenTokenLength::count = 0; +IR::IndexedVector AddNewMetadataFields::newMetadataFields = {}; } // namespace DPDK diff --git a/backends/dpdk/dpdkAsmOpt.h b/backends/dpdk/dpdkAsmOpt.h index c5268217f4d..11d56983321 100644 --- a/backends/dpdk/dpdkAsmOpt.h +++ b/backends/dpdk/dpdkAsmOpt.h @@ -169,7 +169,6 @@ class ValidateTableKeys : public Inspector { public: ValidateTableKeys() {} bool preorder(const IR::DpdkAsmProgram *p) override; - bool isMetadataStruct(const IR::Type_Struct *st); int getFieldSizeBits(const IR::Type *field_type); }; @@ -291,6 +290,50 @@ class ShortenTokenLength : public Transform { } }; +class AddNewMetadataFields : public Transform { + public: + static IR::IndexedVector newMetadataFields; + const IR::Node* preorder(IR::DpdkStructType *st) override; +}; + +class DirectionToRegRead : public Transform { + ordered_map dirToInput; + IR::IndexedVector newStmts; + IR::IndexedVector &newMetadataFields = AddNewMetadataFields::newMetadataFields; + ordered_set newFieldName; + cstring reg_read_tmp; + cstring left_shift_tmp; + cstring registerInstanceName; + + public: + DirectionToRegRead() { + reg_read_tmp = "reg_read_tmp"; + left_shift_tmp = "left_shift_tmp"; + registerInstanceName = "direction_port_mask"; + // direction to input metadata field name mapping + dirToInput.insert(std::make_pair(cstring("pna_main_input_metadata_direction"), + cstring("pna_main_input_metadata_input_port"))); + dirToInput.insert(std::make_pair(cstring("pna_pre_input_metadata_direction"), + cstring("pna_pre_input_metadata_input_port"))); + dirToInput.insert(std::make_pair(cstring("pna_main_parser_input_metadata_direction"), + cstring("pna_main_parser_input_metadata_input_port"))); + } + + const IR::Node* preorder(IR::DpdkAsmProgram *p) override; + + IR::DpdkExternDeclaration* + addRegDeclInstance(cstring instanceName); + void addMetadataField(cstring fieldName); + bool isDirection(const IR::Member *m); + + const IR::Node *postorder(IR::DpdkListStatement *l) override; + + void replaceDirection(const IR::Member *m); + IR::IndexedVector + replaceDirectionWithRegRead(IR::IndexedVector stmts); +}; + + // Instructions can only appear in actions and apply block of .spec file. // All these individual passes work on the actions and apply block of .spec file. class DpdkAsmOptimization : public PassRepeated { diff --git a/backends/dpdk/dpdkUtils.cpp b/backends/dpdk/dpdkUtils.cpp index 53879267686..5406d50a3fa 100644 --- a/backends/dpdk/dpdkUtils.cpp +++ b/backends/dpdk/dpdkUtils.cpp @@ -53,4 +53,14 @@ bool isStandardMetadata(cstring name) { name == "pna_main_parser_input_metadata_t"; return isStdMeta; } + +bool isMetadataStruct(const IR::Type_Struct *st) { + for (auto anno : st->annotations->annotations) { + if (anno->name == "__metadata__") { + return true; + } + } + return false; +} + } // namespace DPDK diff --git a/backends/dpdk/dpdkUtils.h b/backends/dpdk/dpdkUtils.h index cc7a244ef82..c644448bb64 100644 --- a/backends/dpdk/dpdkUtils.h +++ b/backends/dpdk/dpdkUtils.h @@ -23,6 +23,6 @@ bool isSimpleExpression(const IR::Expression *e); bool isNonConstantSimpleExpression(const IR::Expression *e); bool isCommutativeBinaryOperation(const IR::Operation_Binary *bin); bool isStandardMetadata(cstring name); +bool isMetadataStruct(const IR::Type_Struct *st); } // namespace DPDK - #endif /* BACKENDS_DPDK_DPDKUTILS_H_ */ diff --git a/testdata/p4_16_samples/pna-direction-main-parser-err.p4 b/testdata/p4_16_samples/pna-direction-main-parser-err.p4 new file mode 100644 index 00000000000..49db6d707be --- /dev/null +++ b/testdata/p4_16_samples/pna-direction-main-parser-err.p4 @@ -0,0 +1,185 @@ +/* +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; +} + +struct empty_metadata_t { +} + +////////////////////////////////////////////////////////////////////// +// Struct types for holding user-defined collections of headers and +// metadata in the P4 developer's program. +// +// Note: The names of these struct types are completely up to the P4 +// developer, as are their member fields, with the only restriction +// being that the structs intended to contain headers should only +// contain members whose types are header, header stack, or +// header_union. +////////////////////////////////////////////////////////////////////// + +struct main_metadata_t { + // empty for this skeleton + bit<32> tmpDir; +} + +// User-defined struct containing all of those headers parsed in the +// main parser. +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; +} + +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 { + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + meta.tmpDir = hdr.ipv4.srcAddr; + } else { + meta.tmpDir = hdr.ipv4.dstAddr; + } + + } + +} + +parser MainParserImpl( + packet_in pkt, + out headers_t hdr, + inout main_metadata_t main_meta, + in pna_main_parser_input_metadata_t istd) +{ + bit<32> tmpDir; + + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 0x0800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tmpDir = hdr.ipv4.srcAddr; + } else { + tmpDir = hdr.ipv4.dstAddr; + } + + transition accept; + } +} + +//Register, bit<16>>(1) direction_port_mask; +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) +{ + bit<32> tmpDir; +// This is to be inserted by the compiler for direction metadata + //Register, bit<16>>(1) direction_port_mask; + action next_hop(PortId_t vport) { + send_to_port(vport); + } + action default_route_drop() { + drop_packet(); + } + table ipv4_da_lpm { + key = { + tmpDir :lpm @name ("ipv4_addr"); + } + actions = { + next_hop; + default_route_drop; + } + const default_action = default_route_drop; + } + apply { + + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tmpDir = hdr.ipv4.srcAddr; + } else { + tmpDir = hdr.ipv4.dstAddr; + } +/* +// istd.direction should be replaced with "direction_port_mask.read(0) & (32w0x1 << istd.input_port" + if ((direction_port_mask.read(0) & (32w0x1 << istd.input_port)) != 0) { + tmpDir = hdr.ipv4.srcAddr; + } else { + tmpDir = hdr.ipv4.dstAddr; + } +*/ + if (hdr.ipv4.isValid()) { + ipv4_da_lpm.apply(); + } + } +} + +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); + } +} + +// 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/pna-direction.p4 b/testdata/p4_16_samples/pna-direction.p4 new file mode 100644 index 00000000000..80b76e09b99 --- /dev/null +++ b/testdata/p4_16_samples/pna-direction.p4 @@ -0,0 +1,188 @@ +/* +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; +} + +struct empty_metadata_t { +} + +////////////////////////////////////////////////////////////////////// +// Struct types for holding user-defined collections of headers and +// metadata in the P4 developer's program. +// +// Note: The names of these struct types are completely up to the P4 +// developer, as are their member fields, with the only restriction +// being that the structs intended to contain headers should only +// contain members whose types are header, header stack, or +// header_union. +////////////////////////////////////////////////////////////////////// + +struct main_metadata_t { + // empty for this skeleton + bit<32> tmpDir; +PNA_Direction_t t1; +bool b; +} + +// User-defined struct containing all of those headers parsed in the +// main parser. +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; +} + +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 { + meta.b = istd.direction != PNA_Direction_t.NET_TO_HOST; + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + meta.tmpDir = hdr.ipv4.srcAddr; + } else { + meta.tmpDir = hdr.ipv4.dstAddr; + } + + } + +} + +parser MainParserImpl( + packet_in pkt, + out headers_t hdr, + inout main_metadata_t main_meta, + in pna_main_parser_input_metadata_t istd) +{ + bit<32> tmpDir; + + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 0x0800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + /*if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tmpDir = hdr.ipv4.srcAddr; + } else { + tmpDir = hdr.ipv4.dstAddr; + }*/ + + transition accept; + } +} + +//Register, bit<16>>(1) direction_port_mask; +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) +{ + bit<32> tmpDir; +// This is to be inserted by the compiler for direction metadata + //Register, bit<16>>(1) direction_port_mask; + action next_hop(PortId_t vport) { + send_to_port(vport); + } + action default_route_drop() { + drop_packet(); + } + table ipv4_da_lpm { + key = { + tmpDir :lpm @name ("ipv4_addr"); + } + actions = { + next_hop; + default_route_drop; + } + const default_action = default_route_drop; + } + apply { + + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tmpDir = hdr.ipv4.srcAddr; + } else { + tmpDir = hdr.ipv4.dstAddr; + } +/* +// istd.direction should be replaced with "direction_port_mask.read(0) & (32w0x1 << istd.input_port" + if ((direction_port_mask.read(0) & (32w0x1 << istd.input_port)) != 0) { + tmpDir = hdr.ipv4.srcAddr; + } else { + tmpDir = hdr.ipv4.dstAddr; + } +*/ + if (hdr.ipv4.isValid()) { + ipv4_da_lpm.apply(); + } + } +} + +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); + } +} + +// 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-action-selector.p4.spec b/testdata/p4_16_samples_outputs/pna-action-selector.p4.spec index 441449c1c57..60c6e92751a 100644 --- a/testdata/p4_16_samples_outputs/pna-action-selector.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-action-selector.p4.spec @@ -43,6 +43,8 @@ metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t +regarray direction_port_mask size 0x1 initval 0 + action NoAction args none { return } diff --git a/testdata/p4_16_samples_outputs/pna-add-on-miss.p4.spec b/testdata/p4_16_samples_outputs/pna-add-on-miss.p4.spec index f46ef78808a..98e939a99cd 100644 --- a/testdata/p4_16_samples_outputs/pna-add-on-miss.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-add-on-miss.p4.spec @@ -39,6 +39,8 @@ metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t +regarray direction_port_mask size 0x1 initval 0 + action next_hop args instanceof next_hop_arg_t { mov m.pna_main_output_metadata_output_port t.vport return diff --git a/testdata/p4_16_samples_outputs/pna-direction-first.p4 b/testdata/p4_16_samples_outputs/pna-direction-first.p4 new file mode 100644 index 00000000000..0ec29deeffe --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-direction-first.p4 @@ -0,0 +1,104 @@ +#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; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { + bit<32> tmpDir; + PNA_Direction_t t1; + bool b; +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; +} + +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 { + meta.b = istd.direction != PNA_Direction_t.NET_TO_HOST; + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + meta.tmpDir = hdr.ipv4.srcAddr; + } else { + meta.tmpDir = hdr.ipv4.dstAddr; + } + } +} + +parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { + bit<32> tmpDir; + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + 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) { + bit<32> tmpDir; + action next_hop(PortId_t vport) { + send_to_port(vport); + } + action default_route_drop() { + drop_packet(); + } + table ipv4_da_lpm { + key = { + tmpDir: lpm @name("ipv4_addr") ; + } + actions = { + next_hop(); + default_route_drop(); + } + const default_action = default_route_drop(); + } + apply { + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tmpDir = hdr.ipv4.srcAddr; + } else { + tmpDir = hdr.ipv4.dstAddr; + } + if (hdr.ipv4.isValid()) { + ipv4_da_lpm.apply(); + } + } +} + +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); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; + diff --git a/testdata/p4_16_samples_outputs/pna-direction-frontend.p4 b/testdata/p4_16_samples_outputs/pna-direction-frontend.p4 new file mode 100644 index 00000000000..ae57c8603cd --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-direction-frontend.p4 @@ -0,0 +1,103 @@ +#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; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { + bit<32> tmpDir; + PNA_Direction_t t1; + bool b; +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; +} + +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 { + meta.b = istd.direction != PNA_Direction_t.NET_TO_HOST; + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + meta.tmpDir = hdr.ipv4.srcAddr; + } else { + meta.tmpDir = hdr.ipv4.dstAddr; + } + } +} + +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 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) { + @name("MainControlImpl.tmpDir") bit<32> tmpDir_0; + @name("MainControlImpl.next_hop") action next_hop(@name("vport") PortId_t vport) { + send_to_port(vport); + } + @name("MainControlImpl.default_route_drop") action default_route_drop() { + drop_packet(); + } + @name("MainControlImpl.ipv4_da_lpm") table ipv4_da_lpm_0 { + key = { + tmpDir_0: lpm @name("ipv4_addr") ; + } + actions = { + next_hop(); + default_route_drop(); + } + const default_action = default_route_drop(); + } + apply { + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tmpDir_0 = hdr.ipv4.srcAddr; + } else { + tmpDir_0 = hdr.ipv4.dstAddr; + } + if (hdr.ipv4.isValid()) { + ipv4_da_lpm_0.apply(); + } + } +} + +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); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; + diff --git a/testdata/p4_16_samples_outputs/pna-direction-main-parser-err-first.p4 b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err-first.p4 new file mode 100644 index 00000000000..e4f40565670 --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err-first.p4 @@ -0,0 +1,115 @@ +#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; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { + bit<32> tmpDir; +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; +} + +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 { + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + meta.tmpDir = hdr.ipv4.srcAddr; + } else { + meta.tmpDir = hdr.ipv4.dstAddr; + } + } +} + +parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { + @name("tmpDir") bit<32> tmpDir_0; + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + transition select(PNA_Direction_t.NET_TO_HOST == istd.direction) { + true: parse_ipv4_true; + false: parse_ipv4_false; + } + } + state parse_ipv4_true { + tmpDir_0 = hdr.ipv4.srcAddr; + transition parse_ipv4_join; + } + state parse_ipv4_false { + tmpDir_0 = hdr.ipv4.dstAddr; + transition parse_ipv4_join; + } + state parse_ipv4_join { + 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) { + @name("tmpDir") bit<32> tmpDir_1; + @name("next_hop") action next_hop_0(PortId_t vport) { + send_to_port(vport); + } + @name("default_route_drop") action default_route_drop_0() { + drop_packet(); + } + @name("ipv4_da_lpm") table ipv4_da_lpm_0 { + key = { + tmpDir_1: lpm @name("ipv4_addr") ; + } + actions = { + next_hop_0(); + default_route_drop_0(); + } + const default_action = default_route_drop_0(); + } + apply { + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tmpDir_1 = hdr.ipv4.srcAddr; + } else { + tmpDir_1 = hdr.ipv4.dstAddr; + } + if (hdr.ipv4.isValid()) { + ipv4_da_lpm_0.apply(); + } + } +} + +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); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; + diff --git a/testdata/p4_16_samples_outputs/pna-direction-main-parser-err-frontend.p4 b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err-frontend.p4 new file mode 100644 index 00000000000..540160830a3 --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err-frontend.p4 @@ -0,0 +1,112 @@ +#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; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { + bit<32> tmpDir; +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; +} + +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 { + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + meta.tmpDir = hdr.ipv4.srcAddr; + } else { + meta.tmpDir = hdr.ipv4.dstAddr; + } + } +} + +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 select(PNA_Direction_t.NET_TO_HOST == istd.direction) { + true: parse_ipv4_true; + false: parse_ipv4_false; + } + } + state parse_ipv4_true { + transition parse_ipv4_join; + } + state parse_ipv4_false { + transition parse_ipv4_join; + } + state parse_ipv4_join { + 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) { + @name("MainControlImpl.tmpDir") bit<32> tmpDir_1; + @name("MainControlImpl.next_hop") action next_hop_0(@name("vport") PortId_t vport) { + send_to_port(vport); + } + @name("MainControlImpl.default_route_drop") action default_route_drop_0() { + drop_packet(); + } + @name("MainControlImpl.ipv4_da_lpm") table ipv4_da_lpm { + key = { + tmpDir_1: lpm @name("ipv4_addr") ; + } + actions = { + next_hop_0(); + default_route_drop_0(); + } + const default_action = default_route_drop_0(); + } + apply { + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tmpDir_1 = hdr.ipv4.srcAddr; + } else { + tmpDir_1 = hdr.ipv4.dstAddr; + } + if (hdr.ipv4.isValid()) { + ipv4_da_lpm.apply(); + } + } +} + +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); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; + diff --git a/testdata/p4_16_samples_outputs/pna-direction-main-parser-err-midend.p4 b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err-midend.p4 new file mode 100644 index 00000000000..28434e06528 --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err-midend.p4 @@ -0,0 +1,162 @@ +#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; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { + bit<32> tmpDir; +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; +} + +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) { + @hidden action pnadirectionmainparsererr79() { + meta.tmpDir = hdr.ipv4.srcAddr; + } + @hidden action pnadirectionmainparsererr81() { + meta.tmpDir = hdr.ipv4.dstAddr; + } + @hidden table tbl_pnadirectionmainparsererr79 { + actions = { + pnadirectionmainparsererr79(); + } + const default_action = pnadirectionmainparsererr79(); + } + @hidden table tbl_pnadirectionmainparsererr81 { + actions = { + pnadirectionmainparsererr81(); + } + const default_action = pnadirectionmainparsererr81(); + } + apply { + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tbl_pnadirectionmainparsererr79.apply(); + } else { + tbl_pnadirectionmainparsererr81.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 select((bit<1>)(PNA_Direction_t.NET_TO_HOST == istd.direction)) { + 1w1: parse_ipv4_true; + 1w0: parse_ipv4_false; + default: noMatch; + } + } + state parse_ipv4_true { + transition parse_ipv4_join; + } + state parse_ipv4_false { + transition parse_ipv4_join; + } + state parse_ipv4_join { + transition accept; + } + state noMatch { + verify(false, error.NoMatch); + transition reject; + } +} + +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) { + @name("MainControlImpl.tmpDir") bit<32> tmpDir_1; + @name("MainControlImpl.next_hop") action next_hop_0(@name("vport") PortId_t vport) { + send_to_port(vport); + } + @name("MainControlImpl.default_route_drop") action default_route_drop_0() { + drop_packet(); + } + @name("MainControlImpl.ipv4_da_lpm") table ipv4_da_lpm { + key = { + tmpDir_1: lpm @name("ipv4_addr") ; + } + actions = { + next_hop_0(); + default_route_drop_0(); + } + const default_action = default_route_drop_0(); + } + @hidden action pnadirectionmainparsererr144() { + tmpDir_1 = hdr.ipv4.srcAddr; + } + @hidden action pnadirectionmainparsererr146() { + tmpDir_1 = hdr.ipv4.dstAddr; + } + @hidden table tbl_pnadirectionmainparsererr144 { + actions = { + pnadirectionmainparsererr144(); + } + const default_action = pnadirectionmainparsererr144(); + } + @hidden table tbl_pnadirectionmainparsererr146 { + actions = { + pnadirectionmainparsererr146(); + } + const default_action = pnadirectionmainparsererr146(); + } + apply { + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tbl_pnadirectionmainparsererr144.apply(); + } else { + tbl_pnadirectionmainparsererr146.apply(); + } + if (hdr.ipv4.isValid()) { + ipv4_da_lpm.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 pnadirectionmainparsererr169() { + pkt.emit(hdr.ethernet); + pkt.emit(hdr.ipv4); + } + @hidden table tbl_pnadirectionmainparsererr169 { + actions = { + pnadirectionmainparsererr169(); + } + const default_action = pnadirectionmainparsererr169(); + } + apply { + tbl_pnadirectionmainparsererr169.apply(); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; + diff --git a/testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4 b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4 new file mode 100644 index 00000000000..f3965fab658 --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4 @@ -0,0 +1,106 @@ +#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; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { + bit<32> tmpDir; +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; +} + +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 { + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + meta.tmpDir = hdr.ipv4.srcAddr; + } else { + meta.tmpDir = hdr.ipv4.dstAddr; + } + } +} + +parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { + bit<32> tmpDir; + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tmpDir = hdr.ipv4.srcAddr; + } else { + tmpDir = hdr.ipv4.dstAddr; + } + 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) { + bit<32> tmpDir; + action next_hop(PortId_t vport) { + send_to_port(vport); + } + action default_route_drop() { + drop_packet(); + } + table ipv4_da_lpm { + key = { + tmpDir: lpm @name("ipv4_addr") ; + } + actions = { + next_hop; + default_route_drop; + } + const default_action = default_route_drop; + } + apply { + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tmpDir = hdr.ipv4.srcAddr; + } else { + tmpDir = hdr.ipv4.dstAddr; + } + if (hdr.ipv4.isValid()) { + ipv4_da_lpm.apply(); + } + } +} + +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); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; + diff --git a/testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4-stderr b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4-stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/pna-direction-midend.p4 b/testdata/p4_16_samples_outputs/pna-direction-midend.p4 new file mode 100644 index 00000000000..2ea2f97dea2 --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-direction-midend.p4 @@ -0,0 +1,157 @@ +#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; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { + bit<32> tmpDir; + PNA_Direction_t t1; + bool b; +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; +} + +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) { + @hidden action pnadirection82() { + meta.tmpDir = hdr.ipv4.srcAddr; + } + @hidden action pnadirection84() { + meta.tmpDir = hdr.ipv4.dstAddr; + } + @hidden action pnadirection80() { + meta.b = istd.direction != PNA_Direction_t.NET_TO_HOST; + } + @hidden table tbl_pnadirection80 { + actions = { + pnadirection80(); + } + const default_action = pnadirection80(); + } + @hidden table tbl_pnadirection82 { + actions = { + pnadirection82(); + } + const default_action = pnadirection82(); + } + @hidden table tbl_pnadirection84 { + actions = { + pnadirection84(); + } + const default_action = pnadirection84(); + } + apply { + tbl_pnadirection80.apply(); + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tbl_pnadirection82.apply(); + } else { + tbl_pnadirection84.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 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) { + @name("MainControlImpl.tmpDir") bit<32> tmpDir_0; + @name("MainControlImpl.next_hop") action next_hop(@name("vport") PortId_t vport) { + send_to_port(vport); + } + @name("MainControlImpl.default_route_drop") action default_route_drop() { + drop_packet(); + } + @name("MainControlImpl.ipv4_da_lpm") table ipv4_da_lpm_0 { + key = { + tmpDir_0: lpm @name("ipv4_addr") ; + } + actions = { + next_hop(); + default_route_drop(); + } + const default_action = default_route_drop(); + } + @hidden action pnadirection147() { + tmpDir_0 = hdr.ipv4.srcAddr; + } + @hidden action pnadirection149() { + tmpDir_0 = hdr.ipv4.dstAddr; + } + @hidden table tbl_pnadirection147 { + actions = { + pnadirection147(); + } + const default_action = pnadirection147(); + } + @hidden table tbl_pnadirection149 { + actions = { + pnadirection149(); + } + const default_action = pnadirection149(); + } + apply { + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tbl_pnadirection147.apply(); + } else { + tbl_pnadirection149.apply(); + } + if (hdr.ipv4.isValid()) { + ipv4_da_lpm_0.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 pnadirection172() { + pkt.emit(hdr.ethernet); + pkt.emit(hdr.ipv4); + } + @hidden table tbl_pnadirection172 { + actions = { + pnadirection172(); + } + const default_action = pnadirection172(); + } + apply { + tbl_pnadirection172.apply(); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; + diff --git a/testdata/p4_16_samples_outputs/pna-direction.p4 b/testdata/p4_16_samples_outputs/pna-direction.p4 new file mode 100644 index 00000000000..216f72edb8c --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-direction.p4 @@ -0,0 +1,104 @@ +#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; +} + +struct empty_metadata_t { +} + +struct main_metadata_t { + bit<32> tmpDir; + PNA_Direction_t t1; + bool b; +} + +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; +} + +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 { + meta.b = istd.direction != PNA_Direction_t.NET_TO_HOST; + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + meta.tmpDir = hdr.ipv4.srcAddr; + } else { + meta.tmpDir = hdr.ipv4.dstAddr; + } + } +} + +parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { + bit<32> tmpDir; + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 0x800: parse_ipv4; + default: accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + 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) { + bit<32> tmpDir; + action next_hop(PortId_t vport) { + send_to_port(vport); + } + action default_route_drop() { + drop_packet(); + } + table ipv4_da_lpm { + key = { + tmpDir: lpm @name("ipv4_addr") ; + } + actions = { + next_hop; + default_route_drop; + } + const default_action = default_route_drop; + } + apply { + if (PNA_Direction_t.NET_TO_HOST == istd.direction) { + tmpDir = hdr.ipv4.srcAddr; + } else { + tmpDir = hdr.ipv4.dstAddr; + } + if (hdr.ipv4.isValid()) { + ipv4_da_lpm.apply(); + } + } +} + +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); + } +} + +PNA_NIC(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; + diff --git a/testdata/p4_16_samples_outputs/pna-direction.p4-error b/testdata/p4_16_samples_outputs/pna-direction.p4-error new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/pna-direction.p4-stderr b/testdata/p4_16_samples_outputs/pna-direction.p4-stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/pna-direction.p4.bfrt.json b/testdata/p4_16_samples_outputs/pna-direction.p4.bfrt.json new file mode 100644 index 00000000000..13b95e4a64b --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-direction.p4.bfrt.json @@ -0,0 +1,61 @@ +{ + "schema_version" : "1.0.0", + "tables" : [ + { + "name" : "pipe.MainControlImpl.ipv4_da_lpm", + "id" : 40097106, + "table_type" : "MatchAction_Direct", + "size" : 1024, + "annotations" : [], + "depends_on" : [], + "has_const_default_action" : true, + "key" : [ + { + "id" : 1, + "name" : "ipv4_addr", + "repeated" : false, + "annotations" : [], + "mandatory" : false, + "match_type" : "LPM", + "type" : { + "type" : "bytes", + "width" : 32 + } + } + ], + "action_specs" : [ + { + "id" : 25584005, + "name" : "MainControlImpl.next_hop", + "action_scope" : "TableAndDefault", + "annotations" : [], + "data" : [ + { + "id" : 1, + "name" : "vport", + "repeated" : false, + "mandatory" : true, + "read_only" : false, + "annotations" : [], + "type" : { + "type" : "bytes", + "width" : 32 + } + } + ] + }, + { + "id" : 19071441, + "name" : "MainControlImpl.default_route_drop", + "action_scope" : "TableAndDefault", + "annotations" : [], + "data" : [] + } + ], + "data" : [], + "supported_operations" : [], + "attributes" : ["EntryScope"] + } + ], + "learn_filters" : [] +} \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-direction.p4.spec b/testdata/p4_16_samples_outputs/pna-direction.p4.spec new file mode 100644 index 00000000000..97c55760b6d --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-direction.p4.spec @@ -0,0 +1,107 @@ + +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 next_hop_arg_t { + bit<32> vport +} + +struct main_metadata_t { + bit<32> pna_pre_input_metadata_input_port + bit<32> pna_pre_input_metadata_direction + bit<32> pna_main_input_metadata_direction + bit<32> pna_main_input_metadata_input_port + bit<32> local_metadata_tmpDir + bit<8> local_metadata_b + bit<32> pna_main_output_metadata_output_port + bit<32> MainControlT_tmpDir + bit<32> reg_read_tmp + bit<32> left_shift_tmp +} +metadata instanceof main_metadata_t + +header ethernet instanceof ethernet_t +header ipv4 instanceof ipv4_t + +regarray direction_port_mask size 0x1 initval 0 + +action next_hop args instanceof next_hop_arg_t { + mov m.pna_main_output_metadata_output_port t.vport + return +} + +action default_route_drop args none { + drop + return +} + +table ipv4_da_lpm { + key { + m.MainControlT_tmpDir lpm + } + actions { + next_hop + default_route_drop + } + default_action default_route_drop args none + size 0x10000 +} + + +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 + MAINPARSERIMPL_ACCEPT : regrd m.reg_read_tmp direction_port_mask 0x0 + mov m.left_shift_tmp 0x1 + shl m.left_shift_tmp m.pna_pre_input_metadata_input_port + mov m.pna_pre_input_metadata_direction m.reg_read_tmp + and m.pna_pre_input_metadata_direction m.left_shift_tmp + jmpneq LABEL_TRUE m.pna_pre_input_metadata_direction 0x0 + mov m.local_metadata_b 0x0 + jmp LABEL_END + LABEL_TRUE : mov m.local_metadata_b 0x1 + LABEL_END : regrd m.reg_read_tmp direction_port_mask 0x0 + mov m.left_shift_tmp 0x1 + shl m.left_shift_tmp m.pna_pre_input_metadata_input_port + mov m.pna_pre_input_metadata_direction m.reg_read_tmp + and m.pna_pre_input_metadata_direction m.left_shift_tmp + jmpneq LABEL_FALSE_0 0x0 m.pna_pre_input_metadata_direction + mov m.local_metadata_tmpDir h.ipv4.srcAddr + jmp LABEL_END_0 + LABEL_FALSE_0 : mov m.local_metadata_tmpDir h.ipv4.dstAddr + LABEL_END_0 : regrd m.reg_read_tmp direction_port_mask 0x0 + mov m.left_shift_tmp 0x1 + shl m.left_shift_tmp m.pna_main_input_metadata_input_port + mov m.pna_main_input_metadata_direction m.reg_read_tmp + and m.pna_main_input_metadata_direction m.left_shift_tmp + jmpneq LABEL_FALSE_1 0x0 m.pna_main_input_metadata_direction + mov m.MainControlT_tmpDir h.ipv4.srcAddr + jmp LABEL_END_1 + LABEL_FALSE_1 : mov m.MainControlT_tmpDir h.ipv4.dstAddr + LABEL_END_1 : jmpnv LABEL_END_2 h.ipv4 + table ipv4_da_lpm + LABEL_END_2 : emit h.ethernet + emit h.ipv4 + tx m.pna_main_output_metadata_output_port +} + + diff --git a/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4.spec b/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4.spec index 2351ef62513..6eb7b137d14 100644 --- a/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4.spec @@ -69,6 +69,8 @@ header ipv4 instanceof ipv4_t header tcp instanceof tcp_t header MainControlT_hdr_3_tcp instanceof tcp_t +regarray direction_port_mask size 0x1 initval 0 + action do_range_checks_1 args instanceof do_range_checks_1_arg_t { mov h.MainControlT_hdr_3_tcp h.tcp jmpgt LABEL_FALSE_2 t.min1 h.MainControlT_hdr_3_tcp.srcPort diff --git a/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4.spec b/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4.spec index 936ae0f967e..f028dcc2de0 100644 --- a/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4.spec @@ -40,6 +40,8 @@ metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t +regarray direction_port_mask size 0x1 initval 0 + action next_hop args instanceof next_hop_arg_t { mov m.pna_main_output_metadata_output_port t.vport return diff --git a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4.spec b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4.spec index 44d0d4baaa7..5988264d485 100644 --- a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4.spec @@ -27,12 +27,16 @@ struct main_metadata_t { bit<32> pna_main_input_metadata_input_port bit<32> pna_main_output_metadata_output_port bit<32> MainControlT_key + bit<32> reg_read_tmp + bit<32> left_shift_tmp } metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t +regarray direction_port_mask size 0x1 initval 0 + action next_hop args instanceof next_hop_arg_t { mov m.pna_main_output_metadata_output_port t.vport return @@ -63,6 +67,11 @@ apply { jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_IPV4 : extract h.ipv4 MAINPARSERIMPL_ACCEPT : jmpnv LABEL_END h.ipv4 + regrd m.reg_read_tmp direction_port_mask 0x0 + mov m.left_shift_tmp 0x1 + shl m.left_shift_tmp m.pna_main_input_metadata_input_port + mov m.pna_main_input_metadata_direction m.reg_read_tmp + and m.pna_main_input_metadata_direction m.left_shift_tmp jmpeq LABEL_TRUE_0 m.pna_main_input_metadata_direction 0x0 mov m.MainControlT_key h.ipv4.dstAddr jmp LABEL_END_0 diff --git a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4.spec b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4.spec index 52b18dacb7e..cc634aee4c9 100644 --- a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4.spec @@ -27,12 +27,16 @@ struct main_metadata_t { bit<32> pna_main_input_metadata_input_port bit<32> pna_main_output_metadata_output_port bit<32> MainControlT_tmp + bit<32> reg_read_tmp + bit<32> left_shift_tmp } metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t +regarray direction_port_mask size 0x1 initval 0 + action next_hop args instanceof next_hop_arg_t { mov m.pna_main_output_metadata_output_port t.vport return @@ -63,6 +67,11 @@ apply { jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_IPV4 : extract h.ipv4 MAINPARSERIMPL_ACCEPT : jmpnv LABEL_END h.ipv4 + regrd m.reg_read_tmp direction_port_mask 0x0 + mov m.left_shift_tmp 0x1 + shl m.left_shift_tmp m.pna_main_input_metadata_input_port + mov m.pna_main_input_metadata_direction m.reg_read_tmp + and m.pna_main_input_metadata_direction m.left_shift_tmp jmpeq LABEL_TRUE_0 m.pna_main_input_metadata_direction 0x0 mov m.MainControlT_tmp h.ipv4.dstAddr jmp LABEL_END_0 diff --git a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4.spec b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4.spec index f017818e68e..3507940a026 100644 --- a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4.spec @@ -28,12 +28,16 @@ struct main_metadata_t { bit<32> local_metadata_meta bit<32> pna_main_output_metadata_output_port bit<32> MainControlT_addr + bit<32> reg_read_tmp + bit<32> left_shift_tmp } metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t +regarray direction_port_mask size 0x1 initval 0 + action forward args instanceof forward_arg_t { mov m.local_metadata_meta t.addr return @@ -64,6 +68,11 @@ apply { jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_IPV4 : extract h.ipv4 MAINPARSERIMPL_ACCEPT : jmpnv LABEL_END h.ipv4 + regrd m.reg_read_tmp direction_port_mask 0x0 + mov m.left_shift_tmp 0x1 + shl m.left_shift_tmp m.pna_main_input_metadata_input_port + mov m.pna_main_input_metadata_direction m.reg_read_tmp + and m.pna_main_input_metadata_direction m.left_shift_tmp jmpeq LABEL_TRUE_0 m.pna_main_input_metadata_direction 0x0 mov m.MainControlT_addr h.ipv4.dstAddr jmp LABEL_END_0 diff --git a/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4.spec b/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4.spec index 8c5a9ca5ad6..a1945acdcc7 100644 --- a/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4.spec @@ -59,6 +59,8 @@ header MainParserT_parser_tmp_hdr instanceof option_t ;oldname:MainParserT_parser_lookahead_tmp header MainParserT_parser_lookahead_0 instanceof lookahead_tmp_hdr +regarray direction_port_mask size 0x1 initval 0 + action NoAction args none { return } diff --git a/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4.spec b/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4.spec index ce9d2b3c929..6c75fcb7fae 100644 --- a/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4.spec @@ -35,6 +35,8 @@ struct main_metadata_t { } metadata instanceof main_metadata_t +regarray direction_port_mask size 0x1 initval 0 + action NoAction args none { return } diff --git a/testdata/p4_16_samples_outputs/pna-example-template.p4.spec b/testdata/p4_16_samples_outputs/pna-example-template.p4.spec index da270a64826..c061ec237e0 100644 --- a/testdata/p4_16_samples_outputs/pna-example-template.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-template.p4.spec @@ -31,6 +31,8 @@ metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t +regarray direction_port_mask size 0x1 initval 0 + action next_hop args instanceof next_hop_arg_t { mov m.pna_main_output_metadata_output_port t.vport return diff --git a/testdata/p4_16_samples_outputs/pna-example-tunnel.p4.spec b/testdata/p4_16_samples_outputs/pna-example-tunnel.p4.spec index 61de18c83c2..abdd584976e 100644 --- a/testdata/p4_16_samples_outputs/pna-example-tunnel.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-tunnel.p4.spec @@ -43,9 +43,13 @@ struct local_metadata_t { bit<32> main_control_tunnel_decap_ipv4_tunnel_term_table_outer_ipv41 ;oldname:main_control_tunnel_decap_ipv4_tunnel_term_table_outer_ipv4_dst_addr bit<32> main_control_tunnel_decap_ipv4_tunnel_term_table_outer_ipv42 + bit<32> reg_read_tmp + bit<32> left_shift_tmp } metadata instanceof local_metadata_t +regarray direction_port_mask size 0x1 initval 0 + action NoAction args none { return } @@ -94,7 +98,12 @@ apply { jmpeq PACKET_PARSER_PARSE_IPV4_OTR h.outer_ethernet.ether_type 0x800 jmp PACKET_PARSER_ACCEPT PACKET_PARSER_PARSE_IPV4_OTR : extract h.outer_ipv4 - PACKET_PARSER_ACCEPT : jmpneq LABEL_FALSE m.pna_main_input_metadata_direction 0x0 + PACKET_PARSER_ACCEPT : regrd m.reg_read_tmp direction_port_mask 0x0 + mov m.left_shift_tmp 0x1 + shl m.left_shift_tmp m.pna_main_input_metadata_input_port + mov m.pna_main_input_metadata_direction m.reg_read_tmp + and m.pna_main_input_metadata_direction m.left_shift_tmp + jmpneq LABEL_FALSE m.pna_main_input_metadata_direction 0x0 mov m.main_control_tunnel_decap_ipv4_tunnel_term_table_outer_ipv41 h.outer_ipv4.src_addr mov m.main_control_tunnel_decap_ipv4_tunnel_term_table_outer_ipv42 h.outer_ipv4.dst_addr table tunnel_decap_ipv4_tunnel_term_table diff --git a/testdata/p4_16_samples_outputs/pna-extract-local-header.p4.spec b/testdata/p4_16_samples_outputs/pna-extract-local-header.p4.spec index 409fa9af2ae..7d86e2a1f5e 100644 --- a/testdata/p4_16_samples_outputs/pna-extract-local-header.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-extract-local-header.p4.spec @@ -15,6 +15,8 @@ header h1 instanceof my_header_t header h2 instanceof my_header_t header MainParserT_parser_local_hdr instanceof my_header_t +regarray direction_port_mask size 0x1 initval 0 + apply { rx m.pna_main_input_metadata_input_port invalidate h.MainParserT_parser_local_hdr diff --git a/testdata/p4_16_samples_outputs/pna-issue3041.p4.spec b/testdata/p4_16_samples_outputs/pna-issue3041.p4.spec index ff06c8762bc..76564c49527 100644 --- a/testdata/p4_16_samples_outputs/pna-issue3041.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-issue3041.p4.spec @@ -54,6 +54,8 @@ header ipv4_base instanceof ipv4_base_t header ipv4_option_timestamp instanceof ipv4_option_timestamp_t header option instanceof option_t +regarray direction_port_mask size 0x1 initval 0 + action NoAction args none { return } diff --git a/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4.spec b/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4.spec index 3e4924110ef..cd173576047 100644 --- a/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4.spec @@ -25,6 +25,8 @@ header h2 instanceof header2_t ;oldname:MainParserT_parser_lookahead_tmp header MainParserT_parser_lookahead_0 instanceof lookahead_tmp_hdr +regarray direction_port_mask size 0x1 initval 0 + apply { rx m.pna_main_input_metadata_input_port lookahead h.MainParserT_parser_lookahead_0 diff --git a/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4.spec b/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4.spec index 31f08717e1e..e0118b4d79d 100644 --- a/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4.spec @@ -34,6 +34,8 @@ header MainParserT_parser_lookahead_0 instanceof lookahead_tmp_hdr ;oldname:MainParserT_parser_lookahead_tmp_0 header MainParserT_parser_lookahead_1 instanceof lookahead_tmp_hdr_0 +regarray direction_port_mask size 0x1 initval 0 + apply { rx m.pna_main_input_metadata_input_port lookahead h.MainParserT_parser_lookahead_1 diff --git a/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4.spec b/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4.spec index c185b840d4a..536c8a05aa3 100644 --- a/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4.spec @@ -69,6 +69,8 @@ header ipv4 instanceof ipv4_t header tcp instanceof tcp_t header MainControlT_hdr_3_tcp instanceof tcp_t +regarray direction_port_mask size 0x1 initval 0 + action do_range_checks_1 args instanceof do_range_checks_1_arg_t { mov h.MainControlT_hdr_3_tcp h.tcp jmpgt LABEL_FALSE_1 t.min1 h.MainControlT_hdr_3_tcp.srcPort diff --git a/testdata/p4_16_samples_outputs/pna-subparser.p4.spec b/testdata/p4_16_samples_outputs/pna-subparser.p4.spec index 1c4c6bddc59..40dcddaea90 100644 --- a/testdata/p4_16_samples_outputs/pna-subparser.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-subparser.p4.spec @@ -27,6 +27,8 @@ metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t +regarray direction_port_mask size 0x1 initval 0 + apply { rx m.pna_main_input_metadata_input_port invalidate h.ethernet From a34c9b095ba7a270b5d7ebacc9f56b374fdb616a Mon Sep 17 00:00:00 2001 From: Kamlesh Kumar Date: Mon, 18 Apr 2022 21:14:45 -0800 Subject: [PATCH 2/6] Separate code in new file Consider statements in actions --- backends/dpdk/CMakeLists.txt | 2 + backends/dpdk/backend.cpp | 1 + backends/dpdk/dpdkAsmOpt.cpp | 99 -------------- backends/dpdk/dpdkAsmOpt.h | 44 ------ backends/dpdk/dpdkPnaDirection.cpp | 125 ++++++++++++++++++ backends/dpdk/dpdkPnaDirection.h | 71 ++++++++++ .../pna-direction-main-parser-err.p4 | 12 -- testdata/p4_16_samples/pna-direction.p4 | 21 +-- .../pna-action-selector.p4-error | 20 +++ .../pna-action-selector.p4.spec | 2 +- .../pna-add-on-miss.p4-error | 27 ++++ .../pna-add-on-miss.p4.spec | 2 +- .../pna-direction.p4-error | 41 ++++++ .../pna-direction.p4.spec | 8 +- .../pna-dpdk-parser-state-err.p4-error | 61 +++++++++ .../pna-dpdk-parser-state-err.p4.spec | 2 +- .../pna-dpdk-table-key-use-annon.p4-error | 27 ++++ .../pna-dpdk-table-key-use-annon.p4.spec | 2 +- .../pna-example-SelectByDirection.p4-error | 26 ++++ .../pna-example-SelectByDirection.p4.spec | 4 +- .../pna-example-SelectByDirection1.p4-error | 31 +++++ .../pna-example-SelectByDirection1.p4.spec | 4 +- .../pna-example-SelectByDirection2.p4-error | 39 ++++++ .../pna-example-SelectByDirection2.p4.spec | 4 +- .../pna-example-dpdk-varbit.p4-error | 30 +++++ .../pna-example-dpdk-varbit.p4.spec | 2 +- .../pna-example-mirror-packet.p4-error | 21 +++ .../pna-example-mirror-packet.p4.spec | 2 +- .../pna-example-template.p4-error | 20 +++ .../pna-example-template.p4.spec | 2 +- .../pna-example-tunnel.p4-error | 25 ++++ .../pna-example-tunnel.p4.spec | 4 +- .../pna-extract-local-header.p4-error | 27 ++++ .../pna-extract-local-header.p4.spec | 2 +- .../pna-issue3041.p4-error | 29 ++++ .../pna-issue3041.p4.spec | 2 +- ...pna-lookahead-structure-bit-field.p4-error | 15 +++ .../pna-lookahead-structure-bit-field.p4.spec | 2 +- .../pna-lookahead-structure.p4-error | 19 +++ .../pna-lookahead-structure.p4.spec | 2 +- .../pna-mux-dismantle.p4-error | 59 +++++++++ .../pna-mux-dismantle.p4.spec | 2 +- .../pna-subparser.p4-error | 14 ++ .../pna-subparser.p4.spec | 2 +- 44 files changed, 757 insertions(+), 199 deletions(-) create mode 100644 backends/dpdk/dpdkPnaDirection.cpp create mode 100644 backends/dpdk/dpdkPnaDirection.h diff --git a/backends/dpdk/CMakeLists.txt b/backends/dpdk/CMakeLists.txt index 726a82ff26c..a464935a2eb 100644 --- a/backends/dpdk/CMakeLists.txt +++ b/backends/dpdk/CMakeLists.txt @@ -58,6 +58,7 @@ set(P4C_DPDK_SOURCES dpdkArch.cpp dpdkContext.cpp dpdkAsmOpt.cpp + dpdkPnaDirection.cpp dpdkUtils.cpp options.cpp control-plane/bfruntime_ext.cpp @@ -74,6 +75,7 @@ set(P4C_DPDK_HEADERS dpdkContext.h constants.h dpdkAsmOpt.h + dpdkPnaDirection.h printUtils.h dpdkUtils.h dpdkProgramStructure.h diff --git a/backends/dpdk/backend.cpp b/backends/dpdk/backend.cpp index 592518106fc..15b94604dda 100644 --- a/backends/dpdk/backend.cpp +++ b/backends/dpdk/backend.cpp @@ -29,6 +29,7 @@ limitations under the License. #include "ir/ir.h" #include "lib/stringify.h" #include "../bmv2/common/lower.h" +#include "dpdkPnaDirection.h" namespace DPDK { diff --git a/backends/dpdk/dpdkAsmOpt.cpp b/backends/dpdk/dpdkAsmOpt.cpp index 87826319194..eaac710cf05 100644 --- a/backends/dpdk/dpdkAsmOpt.cpp +++ b/backends/dpdk/dpdkAsmOpt.cpp @@ -264,104 +264,5 @@ bool ValidateTableKeys::preorder(const IR::DpdkAsmProgram *p) { return false; } -const IR::Node* AddNewMetadataFields::preorder(IR::DpdkStructType *st) { - if (isMetadataStruct(st)) { - for (auto nf : newMetadataFields) { - st->fields.push_back(nf); - } - auto newSt = new IR::DpdkStructType(st->srcInfo, st->name, - st->annotations, st->fields); - newMetadataFields.clear(); - return newSt; - } - return st; -} - -const IR::Node* DirectionToRegRead::preorder(IR::DpdkAsmProgram *p) { - p->externDeclarations.push_back(addRegDeclInstance(registerInstanceName)); - return p; - } - -IR::DpdkExternDeclaration* DirectionToRegRead::addRegDeclInstance(cstring instanceName) { - auto typepath = new IR::Path("Register"); - auto type = new IR::Type_Name(typepath); - auto typeargs = new IR::Vector({IR::Type::Bits::get(32), - IR::Type::Bits::get(32)}); - auto spectype = new IR::Type_Specialized(type, typeargs); - auto args = new IR::Vector(); - args->push_back(new IR::Argument(new IR::Constant(IR::Type::Bits::get(32), 1))); - auto annot = IR::Annotations::empty; - annot->addAnnotationIfNew(IR::Annotation::nameAnnotation, - new IR::StringLiteral(instanceName)); - auto decl = new IR::DpdkExternDeclaration(instanceName, annot, spectype, args, - nullptr); - return decl; -} - -void DirectionToRegRead::addMetadataField(cstring fieldName) { - if (newFieldName.count(fieldName)) - return; - newMetadataFields.push_back(new IR::StructField(IR::ID(fieldName), - IR::Type::Bits::get(32))); - newFieldName.insert(fieldName); -} - -bool DirectionToRegRead::isDirection(const IR::Member *m) { - if (m == nullptr) - return false; - return m->member.name == "pna_main_input_metadata_direction" - || m->member.name == "pna_pre_input_metadata_direction" - || m->member.name == "pna_main_parser_input_metadata_direction"; -} - -const IR::Node *DirectionToRegRead::postorder(IR::DpdkListStatement *l) { - l->statements = replaceDirectionWithRegRead(l->statements); - newStmts.clear(); - return l; -} - -void DirectionToRegRead::replaceDirection(const IR::Member *m) { - addMetadataField(reg_read_tmp); - addMetadataField(left_shift_tmp); - auto reade = new IR::Member(new IR::PathExpression(IR::ID("m")), - IR::ID(reg_read_tmp)); - auto reads = new IR::DpdkRegisterReadStatement(reade, registerInstanceName, - new IR::Constant(IR::Type::Bits::get(32), - 0)); - auto shld = new IR::Member(new IR::PathExpression(IR::ID("m")), - IR::ID(left_shift_tmp)); - auto mov = new IR::DpdkMovStatement(shld, new IR::Constant(IR::Type::Bits::get(32), 1)); - auto shl = new IR::DpdkShlStatement(shld, shld, - new IR::Member(new IR::PathExpression(IR::ID("m")), - IR::ID(dirToInput[m->member.name]))); - auto mov1 = new IR::DpdkMovStatement(m, reade); - auto and0 = new IR::DpdkAndStatement(m, m, shld); - newStmts.push_back(reads); - newStmts.push_back(mov); - newStmts.push_back(shl); - newStmts.push_back(mov1); - newStmts.push_back(and0); -} - -IR::IndexedVector -DirectionToRegRead::replaceDirectionWithRegRead(IR::IndexedVector stmts) { - for (auto s : stmts) { - if (auto jc = s->to()) { - if (isDirection(jc->src1->to())) { - replaceDirection(jc->src1->to()); - } else if (isDirection(jc->src2->to())) { - replaceDirection(jc->src2->to()); - } - } else if (auto u = s->to()) { - if (isDirection(u->src->to())) { - replaceDirection(u->src->to()); - } - } - newStmts.push_back(s); - } - return newStmts; -} - size_t ShortenTokenLength::count = 0; -IR::IndexedVector AddNewMetadataFields::newMetadataFields = {}; } // namespace DPDK diff --git a/backends/dpdk/dpdkAsmOpt.h b/backends/dpdk/dpdkAsmOpt.h index 11d56983321..9a0c2038918 100644 --- a/backends/dpdk/dpdkAsmOpt.h +++ b/backends/dpdk/dpdkAsmOpt.h @@ -290,50 +290,6 @@ class ShortenTokenLength : public Transform { } }; -class AddNewMetadataFields : public Transform { - public: - static IR::IndexedVector newMetadataFields; - const IR::Node* preorder(IR::DpdkStructType *st) override; -}; - -class DirectionToRegRead : public Transform { - ordered_map dirToInput; - IR::IndexedVector newStmts; - IR::IndexedVector &newMetadataFields = AddNewMetadataFields::newMetadataFields; - ordered_set newFieldName; - cstring reg_read_tmp; - cstring left_shift_tmp; - cstring registerInstanceName; - - public: - DirectionToRegRead() { - reg_read_tmp = "reg_read_tmp"; - left_shift_tmp = "left_shift_tmp"; - registerInstanceName = "direction_port_mask"; - // direction to input metadata field name mapping - dirToInput.insert(std::make_pair(cstring("pna_main_input_metadata_direction"), - cstring("pna_main_input_metadata_input_port"))); - dirToInput.insert(std::make_pair(cstring("pna_pre_input_metadata_direction"), - cstring("pna_pre_input_metadata_input_port"))); - dirToInput.insert(std::make_pair(cstring("pna_main_parser_input_metadata_direction"), - cstring("pna_main_parser_input_metadata_input_port"))); - } - - const IR::Node* preorder(IR::DpdkAsmProgram *p) override; - - IR::DpdkExternDeclaration* - addRegDeclInstance(cstring instanceName); - void addMetadataField(cstring fieldName); - bool isDirection(const IR::Member *m); - - const IR::Node *postorder(IR::DpdkListStatement *l) override; - - void replaceDirection(const IR::Member *m); - IR::IndexedVector - replaceDirectionWithRegRead(IR::IndexedVector stmts); -}; - - // Instructions can only appear in actions and apply block of .spec file. // All these individual passes work on the actions and apply block of .spec file. class DpdkAsmOptimization : public PassRepeated { diff --git a/backends/dpdk/dpdkPnaDirection.cpp b/backends/dpdk/dpdkPnaDirection.cpp new file mode 100644 index 00000000000..6a6c97cf0da --- /dev/null +++ b/backends/dpdk/dpdkPnaDirection.cpp @@ -0,0 +1,125 @@ +/* +Copyright 2022 Intel Corp. + +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 "dpdkPnaDirection.h" +#include "dpdkUtils.h" + +namespace DPDK { +const IR::Node* AddNewMetadataFields::preorder(IR::DpdkStructType *st) { + if (isMetadataStruct(st)) { + for (auto nf : newMetadataFields) { + st->fields.push_back(nf); + } + auto newSt = new IR::DpdkStructType(st->srcInfo, st->name, + st->annotations, st->fields); + newMetadataFields.clear(); + return newSt; + } + return st; +} + +const IR::Node* DirectionToRegRead::preorder(IR::DpdkAsmProgram *p) { + p->externDeclarations.push_back(addRegDeclInstance(registerInstanceName)); + return p; +} + +IR::DpdkExternDeclaration* DirectionToRegRead::addRegDeclInstance(cstring instanceName) { + auto typepath = new IR::Path("Register"); + auto type = new IR::Type_Name(typepath); + auto typeargs = new IR::Vector({IR::Type::Bits::get(32), + IR::Type::Bits::get(32)}); + auto spectype = new IR::Type_Specialized(type, typeargs); + auto args = new IR::Vector(); + args->push_back(new IR::Argument(new IR::Constant(IR::Type::Bits::get(32), 1))); + auto annot = IR::Annotations::empty; + annot->addAnnotationIfNew(IR::Annotation::nameAnnotation, + new IR::StringLiteral(instanceName)); + auto decl = new IR::DpdkExternDeclaration(instanceName, annot, spectype, args, + nullptr); + return decl; +} + +void DirectionToRegRead::addMetadataField(cstring fieldName) { + if (newFieldName.count(fieldName)) + return; + newMetadataFields.push_back(new IR::StructField(IR::ID(fieldName), + IR::Type::Bits::get(32))); + newFieldName.insert(fieldName); +} + +bool DirectionToRegRead::isDirection(const IR::Member *m) { + if (m == nullptr) + return false; + return m->member.name == "pna_main_input_metadata_direction" + || m->member.name == "pna_pre_input_metadata_direction" + || m->member.name == "pna_main_parser_input_metadata_direction"; +} + +const IR::Node *DirectionToRegRead::postorder(IR::DpdkListStatement *l) { + l->statements = replaceDirectionWithRegRead(l->statements); + newStmts.clear(); + return l; +} + +const IR::Node *DirectionToRegRead::postorder(IR::DpdkAction *a) { + a->statements = replaceDirectionWithRegRead(a->statements); + newStmts.clear(); + return a; +} + +void DirectionToRegRead::replaceDirection(const IR::Member *m) { + addMetadataField(reg_read_tmp); + addMetadataField(left_shift_tmp); + auto reade = new IR::Member(new IR::PathExpression(IR::ID("m")), + IR::ID(reg_read_tmp)); + auto reads = new IR::DpdkRegisterReadStatement(reade, registerInstanceName, + new IR::Constant(IR::Type::Bits::get(32), + 0)); + auto shld = new IR::Member(new IR::PathExpression(IR::ID("m")), + IR::ID(left_shift_tmp)); + auto mov = new IR::DpdkMovStatement(shld, new IR::Constant(IR::Type::Bits::get(32), 1)); + auto shl = new IR::DpdkShlStatement(shld, shld, + new IR::Member(new IR::PathExpression(IR::ID("m")), + IR::ID(dirToInput[m->member.name]))); + auto mov1 = new IR::DpdkMovStatement(m, reade); + auto and0 = new IR::DpdkAndStatement(m, m, shld); + newStmts.push_back(reads); + newStmts.push_back(mov); + newStmts.push_back(shl); + newStmts.push_back(mov1); + newStmts.push_back(and0); +} + +IR::IndexedVector +DirectionToRegRead::replaceDirectionWithRegRead(IR::IndexedVector stmts) { + for (auto s : stmts) { + if (auto jc = s->to()) { + if (isDirection(jc->src1->to())) + replaceDirection(jc->src1->to()); + else if (isDirection(jc->src2->to())) + replaceDirection(jc->src2->to()); + } else if (auto u = s->to()) { + if (isDirection(u->src->to())) + replaceDirection(u->src->to()); + } + s->dbprint(std::cerr); + newStmts.push_back(s); + } + return newStmts; +} + +IR::IndexedVector AddNewMetadataFields::newMetadataFields = {}; +} // namespace DPDK diff --git a/backends/dpdk/dpdkPnaDirection.h b/backends/dpdk/dpdkPnaDirection.h new file mode 100644 index 00000000000..34f92d563a1 --- /dev/null +++ b/backends/dpdk/dpdkPnaDirection.h @@ -0,0 +1,71 @@ +/* +Copyright 2022 Intel Corp. + +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. +*/ + +#ifndef BACKENDS_DPDK_DPDKPNADIRECTION_H_ +#define BACKENDS_DPDK_DPDKPNADIRECTION_H_ + +#include "ir/ir.h" + +namespace DPDK { + +class AddNewMetadataFields : public Transform { + public: + static IR::IndexedVector newMetadataFields; + const IR::Node* preorder(IR::DpdkStructType *st) override; +}; + +class DirectionToRegRead : public Transform { + ordered_map dirToInput; + IR::IndexedVector newStmts; + IR::IndexedVector &newMetadataFields = AddNewMetadataFields::newMetadataFields; + ordered_set newFieldName; + cstring reg_read_tmp; + cstring left_shift_tmp; + cstring registerInstanceName; + + public: + DirectionToRegRead() { + reg_read_tmp = "reg_read_tmp"; + left_shift_tmp = "left_shift_tmp"; + registerInstanceName = "network_port_mask"; + // direction to input metadata field name mapping + dirToInput.insert(std::make_pair(cstring("pna_main_input_metadata_direction"), + cstring("pna_main_input_metadata_input_port"))); + dirToInput.insert(std::make_pair(cstring("pna_pre_input_metadata_direction"), + cstring("pna_pre_input_metadata_input_port"))); + dirToInput.insert(std::make_pair(cstring("pna_main_parser_input_metadata_direction"), + cstring("pna_main_parser_input_metadata_input_port"))); + } + + const IR::Node* preorder(IR::DpdkAsmProgram *p) override; + + // create and add register declaration instance to program + IR::DpdkExternDeclaration* + addRegDeclInstance(cstring instanceName); + // add new fields in metadata structure + void addMetadataField(cstring fieldName); + // check member expression using metadata direction field + bool isDirection(const IR::Member *m); + const IR::Node *postorder(IR::DpdkAction *a); + const IR::Node *postorder(IR::DpdkListStatement *l) override; + // replace direction field uses with register read + void replaceDirection(const IR::Member *m); + IR::IndexedVector + replaceDirectionWithRegRead(IR::IndexedVector stmts); +}; + +} // namespace DPDK +#endif // BACKENDS_DPDK_DPDKPNADIRECTION_H_ diff --git a/testdata/p4_16_samples/pna-direction-main-parser-err.p4 b/testdata/p4_16_samples/pna-direction-main-parser-err.p4 index 49db6d707be..b372fc05967 100644 --- a/testdata/p4_16_samples/pna-direction-main-parser-err.p4 +++ b/testdata/p4_16_samples/pna-direction-main-parser-err.p4 @@ -80,7 +80,6 @@ control PreControlImpl( } else { meta.tmpDir = hdr.ipv4.dstAddr; } - } } @@ -112,7 +111,6 @@ parser MainParserImpl( } } -//Register, bit<16>>(1) direction_port_mask; control MainControlImpl( inout headers_t hdr, // from main parser inout main_metadata_t user_meta, // from main parser, to "next block" @@ -120,8 +118,6 @@ control MainControlImpl( inout pna_main_output_metadata_t ostd) { bit<32> tmpDir; -// This is to be inserted by the compiler for direction metadata - //Register, bit<16>>(1) direction_port_mask; action next_hop(PortId_t vport) { send_to_port(vport); } @@ -145,14 +141,6 @@ control MainControlImpl( } else { tmpDir = hdr.ipv4.dstAddr; } -/* -// istd.direction should be replaced with "direction_port_mask.read(0) & (32w0x1 << istd.input_port" - if ((direction_port_mask.read(0) & (32w0x1 << istd.input_port)) != 0) { - tmpDir = hdr.ipv4.srcAddr; - } else { - tmpDir = hdr.ipv4.dstAddr; - } -*/ if (hdr.ipv4.isValid()) { ipv4_da_lpm.apply(); } diff --git a/testdata/p4_16_samples/pna-direction.p4 b/testdata/p4_16_samples/pna-direction.p4 index 80b76e09b99..68a55ce46cc 100644 --- a/testdata/p4_16_samples/pna-direction.p4 +++ b/testdata/p4_16_samples/pna-direction.p4 @@ -58,8 +58,8 @@ struct empty_metadata_t { struct main_metadata_t { // empty for this skeleton bit<32> tmpDir; -PNA_Direction_t t1; -bool b; + PNA_Direction_t t1; + bool b; } // User-defined struct containing all of those headers parsed in the @@ -105,17 +105,10 @@ parser MainParserImpl( } state parse_ipv4 { pkt.extract(hdr.ipv4); - /*if (PNA_Direction_t.NET_TO_HOST == istd.direction) { - tmpDir = hdr.ipv4.srcAddr; - } else { - tmpDir = hdr.ipv4.dstAddr; - }*/ - transition accept; } } -//Register, bit<16>>(1) direction_port_mask; control MainControlImpl( inout headers_t hdr, // from main parser inout main_metadata_t user_meta, // from main parser, to "next block" @@ -123,8 +116,6 @@ control MainControlImpl( inout pna_main_output_metadata_t ostd) { bit<32> tmpDir; -// This is to be inserted by the compiler for direction metadata - //Register, bit<16>>(1) direction_port_mask; action next_hop(PortId_t vport) { send_to_port(vport); } @@ -148,14 +139,6 @@ control MainControlImpl( } else { tmpDir = hdr.ipv4.dstAddr; } -/* -// istd.direction should be replaced with "direction_port_mask.read(0) & (32w0x1 << istd.input_port" - if ((direction_port_mask.read(0) & (32w0x1 << istd.input_port)) != 0) { - tmpDir = hdr.ipv4.srcAddr; - } else { - tmpDir = hdr.ipv4.dstAddr; - } -*/ if (hdr.ipv4.isValid()) { ipv4_da_lpm.apply(); } diff --git a/testdata/p4_16_samples_outputs/pna-action-selector.p4-error b/testdata/p4_16_samples_outputs/pna-action-selector.p4-error index e69de29bb2d..0bebce95fff 100644 --- a/testdata/p4_16_samples_outputs/pna-action-selector.p4-error +++ b/testdata/p4_16_samples_outputs/pna-action-selector.p4-error @@ -0,0 +1,20 @@ +mov h.ethernet.dstAddr; t.param; +mov h.ethernet.etherType; t.param; +mov m.MainControlT_as_group_id; t.group_id; +(390414)MAINPARSERIMPL_START +extract h.ethernet; +jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4 +extract h.ipv4; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +mov m.MainControlT_as_member_id; 0 +mov m.MainControlT_as_group_id; 0 +apply tbl +apply as_sel +apply as +emit h.ethernet; +emit h.ipv4; +(390420) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-action-selector.p4.spec b/testdata/p4_16_samples_outputs/pna-action-selector.p4.spec index 60c6e92751a..d6ede9f2167 100644 --- a/testdata/p4_16_samples_outputs/pna-action-selector.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-action-selector.p4.spec @@ -43,7 +43,7 @@ metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 action NoAction args none { return diff --git a/testdata/p4_16_samples_outputs/pna-add-on-miss.p4-error b/testdata/p4_16_samples_outputs/pna-add-on-miss.p4-error index e69de29bb2d..4bcec049c86 100644 --- a/testdata/p4_16_samples_outputs/pna-add-on-miss.p4-error +++ b/testdata/p4_16_samples_outputs/pna-add-on-miss.p4-error @@ -0,0 +1,27 @@ +mov m.pna_main_output_metadata_output_port; t.vport; +mov m.learnArg; 0 +learn next_hop +mov m.pna_main_output_metadata_output_port; t.vport; +mov h.ipv4.srcAddr; t.newAddr; +mov m.MainControlT_tmp; 0 +mov m.MainControlT_tmp_0; 1234 +learn next_hop +(433978)MAINPARSERIMPL_START +extract h.ethernet; +jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4 +extract h.ipv4; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +jmpnv LABEL_FALSE h.ipv4; +LABEL_TRUE +apply ipv4_da +apply ipv4_da2 +jmp LABEL_END +LABEL_FALSE +LABEL_END +emit h.ethernet; +emit h.ipv4; +(433984) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-add-on-miss.p4.spec b/testdata/p4_16_samples_outputs/pna-add-on-miss.p4.spec index 98e939a99cd..51ab47a2879 100644 --- a/testdata/p4_16_samples_outputs/pna-add-on-miss.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-add-on-miss.p4.spec @@ -39,7 +39,7 @@ metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 action next_hop args instanceof next_hop_arg_t { mov m.pna_main_output_metadata_output_port t.vport diff --git a/testdata/p4_16_samples_outputs/pna-direction.p4-error b/testdata/p4_16_samples_outputs/pna-direction.p4-error index e69de29bb2d..d2d029faca2 100644 --- a/testdata/p4_16_samples_outputs/pna-direction.p4-error +++ b/testdata/p4_16_samples_outputs/pna-direction.p4-error @@ -0,0 +1,41 @@ +mov m.pna_main_output_metadata_output_port; t.vport; +drop +(385797)MAINPARSERIMPL_START +extract h.ethernet; +jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4 +extract h.ipv4; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +jmpneq LABEL_TRUE m.pna_pre_input_metadata_direction; 0 +LABEL_FALSE +mov m.local_metadata_b; 0 +jmp LABEL_END +LABEL_TRUE +mov m.local_metadata_b; 1 +LABEL_END +jmpneq LABEL_FALSE_0 0 m.pna_pre_input_metadata_direction; +LABEL_TRUE_0 +mov m.local_metadata_tmpDir; h.ipv4.srcAddr; +jmp LABEL_END_0 +LABEL_FALSE_0 +mov m.local_metadata_tmpDir; h.ipv4.dstAddr; +LABEL_END_0 +jmpneq LABEL_FALSE_1 0 m.pna_main_input_metadata_direction; +LABEL_TRUE_1 +mov m.MainControlT_tmpDir; h.ipv4.srcAddr; +jmp LABEL_END_1 +LABEL_FALSE_1 +mov m.MainControlT_tmpDir; h.ipv4.dstAddr; +LABEL_END_1 +jmpnv LABEL_FALSE_2 h.ipv4; +LABEL_TRUE_2 +apply ipv4_da_lpm +jmp LABEL_END_2 +LABEL_FALSE_2 +LABEL_END_2 +emit h.ethernet; +emit h.ipv4; +(385803) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-direction.p4.spec b/testdata/p4_16_samples_outputs/pna-direction.p4.spec index 97c55760b6d..0725eac114d 100644 --- a/testdata/p4_16_samples_outputs/pna-direction.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-direction.p4.spec @@ -39,7 +39,7 @@ metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 action next_hop args instanceof next_hop_arg_t { mov m.pna_main_output_metadata_output_port t.vport @@ -70,7 +70,7 @@ apply { jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType 0x800 jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_IPV4 : extract h.ipv4 - MAINPARSERIMPL_ACCEPT : regrd m.reg_read_tmp direction_port_mask 0x0 + MAINPARSERIMPL_ACCEPT : regrd m.reg_read_tmp network_port_mask 0x0 mov m.left_shift_tmp 0x1 shl m.left_shift_tmp m.pna_pre_input_metadata_input_port mov m.pna_pre_input_metadata_direction m.reg_read_tmp @@ -79,7 +79,7 @@ apply { mov m.local_metadata_b 0x0 jmp LABEL_END LABEL_TRUE : mov m.local_metadata_b 0x1 - LABEL_END : regrd m.reg_read_tmp direction_port_mask 0x0 + LABEL_END : regrd m.reg_read_tmp network_port_mask 0x0 mov m.left_shift_tmp 0x1 shl m.left_shift_tmp m.pna_pre_input_metadata_input_port mov m.pna_pre_input_metadata_direction m.reg_read_tmp @@ -88,7 +88,7 @@ apply { mov m.local_metadata_tmpDir h.ipv4.srcAddr jmp LABEL_END_0 LABEL_FALSE_0 : mov m.local_metadata_tmpDir h.ipv4.dstAddr - LABEL_END_0 : regrd m.reg_read_tmp direction_port_mask 0x0 + LABEL_END_0 : regrd m.reg_read_tmp network_port_mask 0x0 mov m.left_shift_tmp 0x1 shl m.left_shift_tmp m.pna_main_input_metadata_input_port mov m.pna_main_input_metadata_direction m.reg_read_tmp diff --git a/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4-error b/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4-error index e69de29bb2d..345880e8685 100644 --- a/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4-error +++ b/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4-error @@ -0,0 +1,61 @@ +mov h.MainControlT_hdr_3_tcp; h.tcp; +(527393)(527394)jmp LABEL_TRUE_2 +LABEL_TRUE_2 +mov m.MainControlT_tmp_1; 1 +jmp LABEL_END_2 +LABEL_FALSE_2 +mov m.MainControlT_tmp_1; 0 +LABEL_END_2 +mov m.local_metadata_rng_result1; m.MainControlT_tmp_1; +mov m.pna_main_output_metadata_output_port; t.vport; +mov m.learnArg; 0 +learn next_hop +(527470)(527471)jmp LABEL_TRUE_3 +LABEL_TRUE_3 +mov m.MainControlT_tmp_2; 1 +jmp LABEL_END_3 +LABEL_FALSE_3 +mov m.MainControlT_tmp_2; 0 +LABEL_END_3 +mov m.local_metadata_rng_result1; m.MainControlT_tmp_2; +mov m.pna_main_output_metadata_output_port; t.vport; +mov h.ipv4.srcAddr; t.newAddr; +mov m.MainControlT_tmp; 0 +mov m.MainControlT_tmp_0; 1234 +learn next_hop +(527672)MAINPARSERIMPL_START +extract h.tcp; +(527183)(527184)jmp LABEL_TRUE +LABEL_TRUE +mov m.MainParserT_parser_tmp; 1 +jmp LABEL_END +LABEL_FALSE +mov m.MainParserT_parser_tmp; 0 +LABEL_END +mov m.local_metadata_rng_result1; m.MainParserT_parser_tmp; +extract h.ethernet; +jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4 +extract h.ipv4; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +(527312)(527313)jmp LABEL_TRUE_0 +LABEL_TRUE_0 +mov m.MainControlT_tmp_3; 1 +jmp LABEL_END_0 +LABEL_FALSE_0 +mov m.MainControlT_tmp_3; 0 +LABEL_END_0 +mov m.local_metadata_rng_result1; m.MainControlT_tmp_3; +jmpnv LABEL_FALSE_1 h.ipv4; +LABEL_TRUE_1 +apply ipv4_da +apply ipv4_da2 +jmp LABEL_END_1 +LABEL_FALSE_1 +LABEL_END_1 +emit h.ethernet; +emit h.ipv4; +(527678) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4.spec b/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4.spec index 6eb7b137d14..fe5df671ee3 100644 --- a/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4.spec @@ -69,7 +69,7 @@ header ipv4 instanceof ipv4_t header tcp instanceof tcp_t header MainControlT_hdr_3_tcp instanceof tcp_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 action do_range_checks_1 args instanceof do_range_checks_1_arg_t { mov h.MainControlT_hdr_3_tcp h.tcp diff --git a/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4-error b/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4-error index e69de29bb2d..45c02f89897 100644 --- a/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4-error +++ b/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4-error @@ -0,0 +1,27 @@ +mov m.pna_main_output_metadata_output_port; t.vport; +mov m.learnArg; 0 +learn next_hop +mov m.pna_main_output_metadata_output_port; t.vport; +mov h.ipv4.srcAddr; t.newAddr; +mov m.MainControlT_tmp; 0 +mov m.MainControlT_tmp_0; 1234 +learn next_hop +(434711)MAINPARSERIMPL_START +extract h.ethernet; +jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4 +extract h.ipv4; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +jmpnv LABEL_FALSE h.ipv4; +LABEL_TRUE +apply ipv4_da +apply ipv4_da2 +jmp LABEL_END +LABEL_FALSE +LABEL_END +emit h.ethernet; +emit h.ipv4; +(434717) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4.spec b/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4.spec index f028dcc2de0..da7d00e63f5 100644 --- a/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4.spec @@ -40,7 +40,7 @@ metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 action next_hop args instanceof next_hop_arg_t { mov m.pna_main_output_metadata_output_port t.vport diff --git a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4-error b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4-error index e69de29bb2d..0055272532c 100644 --- a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4-error +++ b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4-error @@ -0,0 +1,26 @@ +mov m.pna_main_output_metadata_output_port; t.vport; +drop +(384359)MAINPARSERIMPL_START +extract h.ethernet; +jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4 +extract h.ipv4; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +jmpnv LABEL_FALSE h.ipv4; +LABEL_TRUE +jmpeq LABEL_TRUE_0 m.pna_main_input_metadata_direction; 0 +mov m.MainControlT_key; h.ipv4.dstAddr; +jmp LABEL_END_0 +LABEL_TRUE_0 +mov m.MainControlT_key; h.ipv4.srcAddr; +LABEL_END_0 +apply ipv4_da_lpm +jmp LABEL_END +LABEL_FALSE +LABEL_END +emit h.ethernet; +emit h.ipv4; +(384365) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4.spec b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4.spec index 5988264d485..2f18d2b4286 100644 --- a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4.spec @@ -35,7 +35,7 @@ metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 action next_hop args instanceof next_hop_arg_t { mov m.pna_main_output_metadata_output_port t.vport @@ -67,7 +67,7 @@ apply { jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_IPV4 : extract h.ipv4 MAINPARSERIMPL_ACCEPT : jmpnv LABEL_END h.ipv4 - regrd m.reg_read_tmp direction_port_mask 0x0 + regrd m.reg_read_tmp network_port_mask 0x0 mov m.left_shift_tmp 0x1 shl m.left_shift_tmp m.pna_main_input_metadata_input_port mov m.pna_main_input_metadata_direction m.reg_read_tmp diff --git a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4-error b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4-error index e69de29bb2d..e17df3e26ea 100644 --- a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4-error +++ b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4-error @@ -0,0 +1,31 @@ +mov m.pna_main_output_metadata_output_port; t.vport; +drop +(387677)MAINPARSERIMPL_START +extract h.ethernet; +jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4 +extract h.ipv4; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +jmpnv LABEL_FALSE h.ipv4; +LABEL_TRUE +jmpeq LABEL_TRUE_0 m.pna_main_input_metadata_direction; 0 +mov m.MainControlT_tmp; h.ipv4.dstAddr; +jmp LABEL_END_0 +LABEL_TRUE_0 +mov m.MainControlT_tmp; h.ipv4.srcAddr; +LABEL_END_0 +jmpneq LABEL_FALSE_0 m.MainControlT_tmp; h.ipv4.dstAddr; +LABEL_TRUE_1 +apply ipv4_da_lpm +jmp LABEL_END_1 +LABEL_FALSE_0 +LABEL_END_1 +jmp LABEL_END +LABEL_FALSE +LABEL_END +emit h.ethernet; +emit h.ipv4; +(387683) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4.spec b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4.spec index cc634aee4c9..15956360c91 100644 --- a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4.spec @@ -35,7 +35,7 @@ metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 action next_hop args instanceof next_hop_arg_t { mov m.pna_main_output_metadata_output_port t.vport @@ -67,7 +67,7 @@ apply { jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_IPV4 : extract h.ipv4 MAINPARSERIMPL_ACCEPT : jmpnv LABEL_END h.ipv4 - regrd m.reg_read_tmp direction_port_mask 0x0 + regrd m.reg_read_tmp network_port_mask 0x0 mov m.left_shift_tmp 0x1 shl m.left_shift_tmp m.pna_main_input_metadata_input_port mov m.pna_main_input_metadata_direction m.reg_read_tmp diff --git a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4-error b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4-error index e69de29bb2d..0a89e5886db 100644 --- a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4-error +++ b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4-error @@ -0,0 +1,39 @@ +mov m.local_metadata_meta; t.addr; +jmpeq LABEL_TRUE_2 m.pna_main_input_metadata_direction; 0 +mov m.MainControlT_addr; h.ipv4.dstAddr; +jmp LABEL_END_2 +LABEL_TRUE_2 +mov m.MainControlT_addr; h.ipv4.srcAddr; +LABEL_END_2 +mov m.local_metadata_meta; m.MainControlT_addr; +drop +(384937)MAINPARSERIMPL_START +extract h.ethernet; +jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4 +extract h.ipv4; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +jmpnv LABEL_FALSE h.ipv4; +LABEL_TRUE +jmpeq LABEL_TRUE_0 m.pna_main_input_metadata_direction; 0 +mov m.MainControlT_addr; h.ipv4.dstAddr; +jmp LABEL_END_0 +LABEL_TRUE_0 +mov m.MainControlT_addr; h.ipv4.srcAddr; +LABEL_END_0 +mov m.local_metadata_meta; m.MainControlT_addr; +jmpneq LABEL_FALSE_0 m.local_metadata_meta; h.ipv4.dstAddr; +LABEL_TRUE_1 +apply ipv4_da_lpm +jmp LABEL_END_1 +LABEL_FALSE_0 +LABEL_END_1 +jmp LABEL_END +LABEL_FALSE +LABEL_END +emit h.ethernet; +emit h.ipv4; +(384943) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4.spec b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4.spec index 3507940a026..aa8234c1eb7 100644 --- a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4.spec @@ -36,7 +36,7 @@ metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 action forward args instanceof forward_arg_t { mov m.local_metadata_meta t.addr @@ -68,7 +68,7 @@ apply { jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_IPV4 : extract h.ipv4 MAINPARSERIMPL_ACCEPT : jmpnv LABEL_END h.ipv4 - regrd m.reg_read_tmp direction_port_mask 0x0 + regrd m.reg_read_tmp network_port_mask 0x0 mov m.left_shift_tmp 0x1 shl m.left_shift_tmp m.pna_main_input_metadata_input_port mov m.pna_main_input_metadata_direction m.reg_read_tmp diff --git a/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4-error b/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4-error index e69de29bb2d..fa4b1633a0b 100644 --- a/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4-error +++ b/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4-error @@ -0,0 +1,30 @@ +mov h.ethernet.dstAddr; t.param; +mov h.ethernet.etherType; t.param; +(434766)MAINPARSERIMPL_START +extract h.ethernet; +jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4 +extract h.ipv4_base; +jmpeq MAINPARSERIMPL_ACCEPT h.ipv4_base.version_ihl; 69 +jmp MAINPARSERIMPL_PARSE_IPV4_OPTIONS +MAINPARSERIMPL_PARSE_IPV4_OPTIONS +lookahead h.MainParserT_parser_lookahead_tmp; +mov m.MainParserT_parser_tmp_2; h.MainParserT_parser_lookahead_tmp.f; +jmpeq MAINPARSERIMPL_PARSE_IPV4_OPTION_TIMESTAMP m.MainParserT_parser_tmp_2; 68 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4_OPTION_TIMESTAMP +lookahead h.MainParserT_parser_tmp_hdr; +(434471)mov m.MainParserT_parser_tmp_0; m.MainParserT_parser_tmp; +(434473)mov m.MainParserT_parser_tmp_1; m.MainParserT_parser_tmp_0; +(434475)mov m.MainParserT_parser_tmp_1_extract_tmp; m.MainParserT_parser_tmp_1; +(434537)extract h.ipv4_option_timestamp;m.MainParserT_parser_tmp_1_extract_tmp; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +mov m.pna_main_output_metadata_output_port; 0 +apply tbl +apply tbl2 +emit h.ethernet; +emit h.ipv4_base; +(434772) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4.spec b/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4.spec index a1945acdcc7..32e5f3d9cbe 100644 --- a/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4.spec @@ -59,7 +59,7 @@ header MainParserT_parser_tmp_hdr instanceof option_t ;oldname:MainParserT_parser_lookahead_tmp header MainParserT_parser_lookahead_0 instanceof lookahead_tmp_hdr -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 action NoAction args none { return diff --git a/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4-error b/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4-error index e69de29bb2d..1caf71f792b 100644 --- a/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4-error +++ b/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4-error @@ -0,0 +1,21 @@ +mov m.pna_main_output_metadata_output_port; t.vport; +mov m.mirrorSlot; 3 +mov m.mirrorSession; 58 +mirror m.mirrorSlot; m.mirrorSession; +drop +mov m.mirrorSlot_0; 3 +mov m.mirrorSession_0; 62 +mirror m.mirrorSlot_0; m.mirrorSession_0; +(395031)MAINPARSERIMPL_START +extract h.ethernet; +jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4 +extract h.ipv4; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +apply flowTable +emit h.ethernet; +emit h.ipv4; +(395037) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4.spec b/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4.spec index 6c75fcb7fae..ae622c4c823 100644 --- a/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4.spec @@ -35,7 +35,7 @@ struct main_metadata_t { } metadata instanceof main_metadata_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 action NoAction args none { return diff --git a/testdata/p4_16_samples_outputs/pna-example-template.p4-error b/testdata/p4_16_samples_outputs/pna-example-template.p4-error index e69de29bb2d..e534d2a9f59 100644 --- a/testdata/p4_16_samples_outputs/pna-example-template.p4-error +++ b/testdata/p4_16_samples_outputs/pna-example-template.p4-error @@ -0,0 +1,20 @@ +mov m.pna_main_output_metadata_output_port; t.vport; +drop +(372111)MAINPARSERIMPL_START +extract h.ethernet; +jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4 +extract h.ipv4; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +jmpnv LABEL_FALSE h.ipv4; +LABEL_TRUE +apply ipv4_da_lpm +jmp LABEL_END +LABEL_FALSE +LABEL_END +emit h.ethernet; +emit h.ipv4; +(372117) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-template.p4.spec b/testdata/p4_16_samples_outputs/pna-example-template.p4.spec index c061ec237e0..955d3e5cc82 100644 --- a/testdata/p4_16_samples_outputs/pna-example-template.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-template.p4.spec @@ -31,7 +31,7 @@ metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 action next_hop args instanceof next_hop_arg_t { mov m.pna_main_output_metadata_output_port t.vport diff --git a/testdata/p4_16_samples_outputs/pna-example-tunnel.p4-error b/testdata/p4_16_samples_outputs/pna-example-tunnel.p4-error index 3ade61402b0..527adf86dee 100644 --- a/testdata/p4_16_samples_outputs/pna-example-tunnel.p4-error +++ b/testdata/p4_16_samples_outputs/pna-example-tunnel.p4-error @@ -1 +1,26 @@ [--Wwarn=mismatch] warning: Mismatched header/metadata struct for key elements in table tunnel_decap_ipv4_tunnel_term_table. Copying all match fields to metadata +mov m.local_metadata__tunnel_id1; t.tunnel_id; +mov m.local_metadata__outer_ipv4_dst0; t.dst_addr; +(502996)PACKET_PARSER_START +extract h.outer_ethernet; +jmpeq PACKET_PARSER_PARSE_IPV4_OTR h.outer_ethernet.ether_type; 2048 +jmp PACKET_PARSER_ACCEPT +PACKET_PARSER_PARSE_IPV4_OTR +extract h.outer_ipv4; +jmp PACKET_PARSER_ACCEPT +PACKET_PARSER_REJECT +PACKET_PARSER_ACCEPT +jmpneq LABEL_FALSE m.pna_main_input_metadata_direction; 0 +LABEL_TRUE +mov m.main_control_tunnel_decap_ipv4_tunnel_term_table_outer_ipv4_src_addr; h.outer_ipv4.src_addr; +mov m.main_control_tunnel_decap_ipv4_tunnel_term_table_outer_ipv4_dst_addr; h.outer_ipv4.dst_addr; +apply tunnel_decap_ipv4_tunnel_term_table +jmp LABEL_END +LABEL_FALSE +apply tunnel_encap_set_tunnel_encap +LABEL_END +emit h.outer_ethernet; +emit h.outer_ipv4; +emit h.ethernet; +emit h.ipv4; +(503002) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-tunnel.p4.spec b/testdata/p4_16_samples_outputs/pna-example-tunnel.p4.spec index abdd584976e..2b7a37ef8f1 100644 --- a/testdata/p4_16_samples_outputs/pna-example-tunnel.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-tunnel.p4.spec @@ -48,7 +48,7 @@ struct local_metadata_t { } metadata instanceof local_metadata_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 action NoAction args none { return @@ -98,7 +98,7 @@ apply { jmpeq PACKET_PARSER_PARSE_IPV4_OTR h.outer_ethernet.ether_type 0x800 jmp PACKET_PARSER_ACCEPT PACKET_PARSER_PARSE_IPV4_OTR : extract h.outer_ipv4 - PACKET_PARSER_ACCEPT : regrd m.reg_read_tmp direction_port_mask 0x0 + PACKET_PARSER_ACCEPT : regrd m.reg_read_tmp network_port_mask 0x0 mov m.left_shift_tmp 0x1 shl m.left_shift_tmp m.pna_main_input_metadata_input_port mov m.pna_main_input_metadata_direction m.reg_read_tmp diff --git a/testdata/p4_16_samples_outputs/pna-extract-local-header.p4-error b/testdata/p4_16_samples_outputs/pna-extract-local-header.p4-error index e69de29bb2d..f1905dd13ca 100644 --- a/testdata/p4_16_samples_outputs/pna-extract-local-header.p4-error +++ b/testdata/p4_16_samples_outputs/pna-extract-local-header.p4-error @@ -0,0 +1,27 @@ +(324519)MAINPARSERIMPL_START +invalidate h.MainParserT_parser_local_hdr; +extract h.MainParserT_parser_local_hdr; +jmpeq MAINPARSERIMPL_PARSE_H1 h.MainParserT_parser_local_hdr.type1; 4660 +jmpeq MAINPARSERIMPL_PARSE_H2 h.MainParserT_parser_local_hdr.type1; 22136 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_H2 +validate h.h2; +mov h.h2.type1; h.MainParserT_parser_local_hdr.type1; +mov h.h2.type2; h.MainParserT_parser_local_hdr.type2; +mov h.h2.value; h.MainParserT_parser_local_hdr.value; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_H1 +extract h.h1; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +jmpnv LABEL_FALSE h.h1; +jmpnv LABEL_FALSE h.h2; +jmp LABEL_TRUE +LABEL_TRUE +emit h.h1; +emit h.h2; +jmp LABEL_END +LABEL_FALSE +LABEL_END +(324525) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-extract-local-header.p4.spec b/testdata/p4_16_samples_outputs/pna-extract-local-header.p4.spec index 7d86e2a1f5e..8a3312ab24a 100644 --- a/testdata/p4_16_samples_outputs/pna-extract-local-header.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-extract-local-header.p4.spec @@ -15,7 +15,7 @@ header h1 instanceof my_header_t header h2 instanceof my_header_t header MainParserT_parser_local_hdr instanceof my_header_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 apply { rx m.pna_main_input_metadata_input_port diff --git a/testdata/p4_16_samples_outputs/pna-issue3041.p4-error b/testdata/p4_16_samples_outputs/pna-issue3041.p4-error index e69de29bb2d..08df934288b 100644 --- a/testdata/p4_16_samples_outputs/pna-issue3041.p4-error +++ b/testdata/p4_16_samples_outputs/pna-issue3041.p4-error @@ -0,0 +1,29 @@ +mov h.ethernet.dstAddr; t.param; +mov h.ethernet.etherType; t.param; +(420382)MAINPARSERIMPL_START +extract h.ethernet; +jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4 +extract h.ipv4_base; +mov m.MainParserT_parser_tmp; h.ipv4_base.version_ihl; +(420041)(420042)jmpeq MAINPARSERIMPL_ACCEPT m.MainParserT_parser_tmp_2; 5 +jmp MAINPARSERIMPL_PARSE_IPV4_OPTIONS +MAINPARSERIMPL_PARSE_IPV4_OPTIONS +lookahead h.option; +jmpeq MAINPARSERIMPL_PARSE_IPV4_OPTION_TIMESTAMP h.option.type; 68 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4_OPTION_TIMESTAMP +(420087)mov m.MainParserT_parser_tmp_1; m.MainParserT_parser_tmp_0; +(420089)mov m.MainParserT_parser_tmp_3; m.MainParserT_parser_tmp_1; +(420091)mov m.MainParserT_parser_tmp_3_extract_tmp; m.MainParserT_parser_tmp_3; +(420153)extract h.ipv4_option_timestamp;m.MainParserT_parser_tmp_3_extract_tmp; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +mov m.pna_main_output_metadata_output_port; 0 +apply tbl +apply tbl2 +emit h.ethernet; +emit h.ipv4_base; +(420388) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-issue3041.p4.spec b/testdata/p4_16_samples_outputs/pna-issue3041.p4.spec index 76564c49527..2f72bc7cbcd 100644 --- a/testdata/p4_16_samples_outputs/pna-issue3041.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-issue3041.p4.spec @@ -54,7 +54,7 @@ header ipv4_base instanceof ipv4_base_t header ipv4_option_timestamp instanceof ipv4_option_timestamp_t header option instanceof option_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 action NoAction args none { return diff --git a/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4-error b/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4-error index e69de29bb2d..dad11b57896 100644 --- a/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4-error +++ b/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4-error @@ -0,0 +1,15 @@ +(309500)MAINPARSERIMPL_START +lookahead h.MainParserT_parser_lookahead_tmp; +mov m.local_metadata_f1; h.MainParserT_parser_lookahead_tmp.f; +jmpeq MAINPARSERIMPL_PARSE_H1 m.local_metadata_f1; 1 +jmpeq MAINPARSERIMPL_PARSE_H2 m.local_metadata_f1; 2 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_H2 +extract h.h2; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_H1 +extract h.h1; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +(309506) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4.spec b/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4.spec index cd173576047..c2432fc152a 100644 --- a/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4.spec @@ -25,7 +25,7 @@ header h2 instanceof header2_t ;oldname:MainParserT_parser_lookahead_tmp header MainParserT_parser_lookahead_0 instanceof lookahead_tmp_hdr -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 apply { rx m.pna_main_input_metadata_input_port diff --git a/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4-error b/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4-error index e69de29bb2d..3798bb921e0 100644 --- a/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4-error +++ b/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4-error @@ -0,0 +1,19 @@ +(333961)MAINPARSERIMPL_START +lookahead h.MainParserT_parser_lookahead_tmp_0; +mov m.MainParserT_parser_tmp_3; h.MainParserT_parser_lookahead_tmp_0.f; +mov m.MainParserT_parser_tmp_0; m.MainParserT_parser_tmp_3; +(333779)(333780)jmpeq MAINPARSERIMPL_PARSE_H1 m.MainParserT_parser_tmp_2; 4660 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_H1 +extract h.h1; +lookahead h.MainParserT_parser_lookahead_tmp; +mov m.MainParserT_parser_tmp_4; h.MainParserT_parser_lookahead_tmp.f; +mov m.MainParserT_parser_tmp; m.MainParserT_parser_tmp_4; +(333869)(333870)(333872)(333874)jmpeq MAINPARSERIMPL_PARSE_H2 m.MainParserT_parser_tmp_1; 1 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_H2 +extract h.h2; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +(333967) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4.spec b/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4.spec index e0118b4d79d..e20d0b86526 100644 --- a/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4.spec @@ -34,7 +34,7 @@ header MainParserT_parser_lookahead_0 instanceof lookahead_tmp_hdr ;oldname:MainParserT_parser_lookahead_tmp_0 header MainParserT_parser_lookahead_1 instanceof lookahead_tmp_hdr_0 -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 apply { rx m.pna_main_input_metadata_input_port diff --git a/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4-error b/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4-error index e69de29bb2d..d95a8db393a 100644 --- a/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4-error +++ b/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4-error @@ -0,0 +1,59 @@ +mov h.MainControlT_hdr_3_tcp; h.tcp; +(530864)(530865)jmp LABEL_TRUE_1 +LABEL_TRUE_1 +mov m.MainControlT_tmp_3; 1 +jmp LABEL_END_1 +LABEL_FALSE_1 +mov m.MainControlT_tmp_3; 0 +LABEL_END_1 +mov m.local_metadata_rng_result1; m.MainControlT_tmp_3; +mov m.pna_main_output_metadata_output_port; t.vport; +mov m.learnArg; 0 +learn next_hop +(530941)(530942)jmp LABEL_TRUE_2 +LABEL_TRUE_2 +(530946)(530947)jmp LABEL_TRUE_3 +LABEL_TRUE_3 +mov m.MainControlT_tmp_2; m.local_metadata_val1; +jmp LABEL_END_3 +LABEL_FALSE_3 +mov m.MainControlT_tmp_2; m.local_metadata_val2; +LABEL_END_3 +mov m.MainControlT_tmp_1; m.MainControlT_tmp_2; +jmp LABEL_END_2 +LABEL_FALSE_2 +mov m.MainControlT_tmp_1; m.local_metadata_val1; +LABEL_END_2 +mov m.local_metadata_rng_result1; m.MainControlT_tmp_1; +mov m.pna_main_output_metadata_output_port; t.vport; +mov h.ipv4.srcAddr; t.newAddr; +mov m.MainControlT_tmp; 0 +mov m.MainControlT_tmp_0; 1234 +learn next_hop +(531153)MAINPARSERIMPL_START +extract h.ethernet; +jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_PARSE_IPV4 +extract h.ipv4; +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +(530783)(530784)jmp LABEL_TRUE +LABEL_TRUE +mov m.MainControlT_tmp_4; 1 +jmp LABEL_END +LABEL_FALSE +mov m.MainControlT_tmp_4; 0 +LABEL_END +mov m.local_metadata_rng_result1; m.MainControlT_tmp_4; +jmpnv LABEL_FALSE_0 h.ipv4; +LABEL_TRUE_0 +apply ipv4_da +apply ipv4_da2 +jmp LABEL_END_0 +LABEL_FALSE_0 +LABEL_END_0 +emit h.ethernet; +emit h.ipv4; +(531159) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4.spec b/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4.spec index 536c8a05aa3..5779a1af083 100644 --- a/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4.spec @@ -69,7 +69,7 @@ header ipv4 instanceof ipv4_t header tcp instanceof tcp_t header MainControlT_hdr_3_tcp instanceof tcp_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 action do_range_checks_1 args instanceof do_range_checks_1_arg_t { mov h.MainControlT_hdr_3_tcp h.tcp diff --git a/testdata/p4_16_samples_outputs/pna-subparser.p4-error b/testdata/p4_16_samples_outputs/pna-subparser.p4-error index e69de29bb2d..dab901cbf01 100644 --- a/testdata/p4_16_samples_outputs/pna-subparser.p4-error +++ b/testdata/p4_16_samples_outputs/pna-subparser.p4-error @@ -0,0 +1,14 @@ +(319476)MAINPARSERIMPL_START +invalidate h.ethernet; +invalidate h.ipv4; +extract h.ethernet; +jmpeq MAINPARSERIMPL_COMMONPARSER_PARSE_IPV4 h.ethernet.etherType; 2048 +jmp MAINPARSERIMPL_START_0 +MAINPARSERIMPL_COMMONPARSER_PARSE_IPV4 +extract h.ipv4; +jmp MAINPARSERIMPL_START_0 +MAINPARSERIMPL_START_0 +jmp MAINPARSERIMPL_ACCEPT +MAINPARSERIMPL_REJECT +MAINPARSERIMPL_ACCEPT +(319482) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-subparser.p4.spec b/testdata/p4_16_samples_outputs/pna-subparser.p4.spec index 40dcddaea90..bb1edb4864d 100644 --- a/testdata/p4_16_samples_outputs/pna-subparser.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-subparser.p4.spec @@ -27,7 +27,7 @@ metadata instanceof main_metadata_t header ethernet instanceof ethernet_t header ipv4 instanceof ipv4_t -regarray direction_port_mask size 0x1 initval 0 +regarray network_port_mask size 0x1 initval 0 apply { rx m.pna_main_input_metadata_input_port From aa40a40b42837e36ae3a27a0c9db5f3c7545e4e8 Mon Sep 17 00:00:00 2001 From: Kamlesh Kumar Date: Mon, 18 Apr 2022 21:27:34 -0800 Subject: [PATCH 3/6] Added code comments --- backends/dpdk/dpdkPnaDirection.cpp | 1 - backends/dpdk/dpdkPnaDirection.h | 3 +- .../pna-action-selector.p4-error | 20 ------ .../pna-add-on-miss.p4-error | 27 -------- .../pna-direction.p4-error | 41 ------------- .../pna-dpdk-parser-state-err.p4-error | 61 ------------------- .../pna-dpdk-table-key-use-annon.p4-error | 27 -------- .../pna-example-SelectByDirection.p4-error | 26 -------- .../pna-example-SelectByDirection1.p4-error | 31 ---------- .../pna-example-SelectByDirection2.p4-error | 39 ------------ .../pna-example-dpdk-varbit.p4-error | 30 --------- .../pna-example-mirror-packet.p4-error | 21 ------- .../pna-example-template.p4-error | 20 ------ .../pna-example-tunnel.p4-error | 25 -------- .../pna-extract-local-header.p4-error | 27 -------- .../pna-issue3041.p4-error | 29 --------- ...pna-lookahead-structure-bit-field.p4-error | 15 ----- .../pna-lookahead-structure.p4-error | 19 ------ .../pna-mux-dismantle.p4-error | 59 ------------------ .../pna-subparser.p4-error | 14 ----- 20 files changed, 2 insertions(+), 533 deletions(-) diff --git a/backends/dpdk/dpdkPnaDirection.cpp b/backends/dpdk/dpdkPnaDirection.cpp index 6a6c97cf0da..f030b603680 100644 --- a/backends/dpdk/dpdkPnaDirection.cpp +++ b/backends/dpdk/dpdkPnaDirection.cpp @@ -115,7 +115,6 @@ DirectionToRegRead::replaceDirectionWithRegRead(IR::IndexedVectorsrc->to())) replaceDirection(u->src->to()); } - s->dbprint(std::cerr); newStmts.push_back(s); } return newStmts; diff --git a/backends/dpdk/dpdkPnaDirection.h b/backends/dpdk/dpdkPnaDirection.h index 34f92d563a1..36a738df98b 100644 --- a/backends/dpdk/dpdkPnaDirection.h +++ b/backends/dpdk/dpdkPnaDirection.h @@ -61,7 +61,8 @@ class DirectionToRegRead : public Transform { bool isDirection(const IR::Member *m); const IR::Node *postorder(IR::DpdkAction *a); const IR::Node *postorder(IR::DpdkListStatement *l) override; - // replace direction field uses with register read + // replace direction field uses with register read i.e. + // istd.direction -> (direction_port_mask.read(0) & (32w0x1 << istd.input_port)) void replaceDirection(const IR::Member *m); IR::IndexedVector replaceDirectionWithRegRead(IR::IndexedVector stmts); diff --git a/testdata/p4_16_samples_outputs/pna-action-selector.p4-error b/testdata/p4_16_samples_outputs/pna-action-selector.p4-error index 0bebce95fff..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-action-selector.p4-error +++ b/testdata/p4_16_samples_outputs/pna-action-selector.p4-error @@ -1,20 +0,0 @@ -mov h.ethernet.dstAddr; t.param; -mov h.ethernet.etherType; t.param; -mov m.MainControlT_as_group_id; t.group_id; -(390414)MAINPARSERIMPL_START -extract h.ethernet; -jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4 -extract h.ipv4; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -mov m.MainControlT_as_member_id; 0 -mov m.MainControlT_as_group_id; 0 -apply tbl -apply as_sel -apply as -emit h.ethernet; -emit h.ipv4; -(390420) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-add-on-miss.p4-error b/testdata/p4_16_samples_outputs/pna-add-on-miss.p4-error index 4bcec049c86..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-add-on-miss.p4-error +++ b/testdata/p4_16_samples_outputs/pna-add-on-miss.p4-error @@ -1,27 +0,0 @@ -mov m.pna_main_output_metadata_output_port; t.vport; -mov m.learnArg; 0 -learn next_hop -mov m.pna_main_output_metadata_output_port; t.vport; -mov h.ipv4.srcAddr; t.newAddr; -mov m.MainControlT_tmp; 0 -mov m.MainControlT_tmp_0; 1234 -learn next_hop -(433978)MAINPARSERIMPL_START -extract h.ethernet; -jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4 -extract h.ipv4; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -jmpnv LABEL_FALSE h.ipv4; -LABEL_TRUE -apply ipv4_da -apply ipv4_da2 -jmp LABEL_END -LABEL_FALSE -LABEL_END -emit h.ethernet; -emit h.ipv4; -(433984) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-direction.p4-error b/testdata/p4_16_samples_outputs/pna-direction.p4-error index d2d029faca2..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-direction.p4-error +++ b/testdata/p4_16_samples_outputs/pna-direction.p4-error @@ -1,41 +0,0 @@ -mov m.pna_main_output_metadata_output_port; t.vport; -drop -(385797)MAINPARSERIMPL_START -extract h.ethernet; -jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4 -extract h.ipv4; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -jmpneq LABEL_TRUE m.pna_pre_input_metadata_direction; 0 -LABEL_FALSE -mov m.local_metadata_b; 0 -jmp LABEL_END -LABEL_TRUE -mov m.local_metadata_b; 1 -LABEL_END -jmpneq LABEL_FALSE_0 0 m.pna_pre_input_metadata_direction; -LABEL_TRUE_0 -mov m.local_metadata_tmpDir; h.ipv4.srcAddr; -jmp LABEL_END_0 -LABEL_FALSE_0 -mov m.local_metadata_tmpDir; h.ipv4.dstAddr; -LABEL_END_0 -jmpneq LABEL_FALSE_1 0 m.pna_main_input_metadata_direction; -LABEL_TRUE_1 -mov m.MainControlT_tmpDir; h.ipv4.srcAddr; -jmp LABEL_END_1 -LABEL_FALSE_1 -mov m.MainControlT_tmpDir; h.ipv4.dstAddr; -LABEL_END_1 -jmpnv LABEL_FALSE_2 h.ipv4; -LABEL_TRUE_2 -apply ipv4_da_lpm -jmp LABEL_END_2 -LABEL_FALSE_2 -LABEL_END_2 -emit h.ethernet; -emit h.ipv4; -(385803) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4-error b/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4-error index 345880e8685..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4-error +++ b/testdata/p4_16_samples_outputs/pna-dpdk-parser-state-err.p4-error @@ -1,61 +0,0 @@ -mov h.MainControlT_hdr_3_tcp; h.tcp; -(527393)(527394)jmp LABEL_TRUE_2 -LABEL_TRUE_2 -mov m.MainControlT_tmp_1; 1 -jmp LABEL_END_2 -LABEL_FALSE_2 -mov m.MainControlT_tmp_1; 0 -LABEL_END_2 -mov m.local_metadata_rng_result1; m.MainControlT_tmp_1; -mov m.pna_main_output_metadata_output_port; t.vport; -mov m.learnArg; 0 -learn next_hop -(527470)(527471)jmp LABEL_TRUE_3 -LABEL_TRUE_3 -mov m.MainControlT_tmp_2; 1 -jmp LABEL_END_3 -LABEL_FALSE_3 -mov m.MainControlT_tmp_2; 0 -LABEL_END_3 -mov m.local_metadata_rng_result1; m.MainControlT_tmp_2; -mov m.pna_main_output_metadata_output_port; t.vport; -mov h.ipv4.srcAddr; t.newAddr; -mov m.MainControlT_tmp; 0 -mov m.MainControlT_tmp_0; 1234 -learn next_hop -(527672)MAINPARSERIMPL_START -extract h.tcp; -(527183)(527184)jmp LABEL_TRUE -LABEL_TRUE -mov m.MainParserT_parser_tmp; 1 -jmp LABEL_END -LABEL_FALSE -mov m.MainParserT_parser_tmp; 0 -LABEL_END -mov m.local_metadata_rng_result1; m.MainParserT_parser_tmp; -extract h.ethernet; -jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4 -extract h.ipv4; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -(527312)(527313)jmp LABEL_TRUE_0 -LABEL_TRUE_0 -mov m.MainControlT_tmp_3; 1 -jmp LABEL_END_0 -LABEL_FALSE_0 -mov m.MainControlT_tmp_3; 0 -LABEL_END_0 -mov m.local_metadata_rng_result1; m.MainControlT_tmp_3; -jmpnv LABEL_FALSE_1 h.ipv4; -LABEL_TRUE_1 -apply ipv4_da -apply ipv4_da2 -jmp LABEL_END_1 -LABEL_FALSE_1 -LABEL_END_1 -emit h.ethernet; -emit h.ipv4; -(527678) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4-error b/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4-error index 45c02f89897..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4-error +++ b/testdata/p4_16_samples_outputs/pna-dpdk-table-key-use-annon.p4-error @@ -1,27 +0,0 @@ -mov m.pna_main_output_metadata_output_port; t.vport; -mov m.learnArg; 0 -learn next_hop -mov m.pna_main_output_metadata_output_port; t.vport; -mov h.ipv4.srcAddr; t.newAddr; -mov m.MainControlT_tmp; 0 -mov m.MainControlT_tmp_0; 1234 -learn next_hop -(434711)MAINPARSERIMPL_START -extract h.ethernet; -jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4 -extract h.ipv4; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -jmpnv LABEL_FALSE h.ipv4; -LABEL_TRUE -apply ipv4_da -apply ipv4_da2 -jmp LABEL_END -LABEL_FALSE -LABEL_END -emit h.ethernet; -emit h.ipv4; -(434717) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4-error b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4-error index 0055272532c..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4-error +++ b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection.p4-error @@ -1,26 +0,0 @@ -mov m.pna_main_output_metadata_output_port; t.vport; -drop -(384359)MAINPARSERIMPL_START -extract h.ethernet; -jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4 -extract h.ipv4; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -jmpnv LABEL_FALSE h.ipv4; -LABEL_TRUE -jmpeq LABEL_TRUE_0 m.pna_main_input_metadata_direction; 0 -mov m.MainControlT_key; h.ipv4.dstAddr; -jmp LABEL_END_0 -LABEL_TRUE_0 -mov m.MainControlT_key; h.ipv4.srcAddr; -LABEL_END_0 -apply ipv4_da_lpm -jmp LABEL_END -LABEL_FALSE -LABEL_END -emit h.ethernet; -emit h.ipv4; -(384365) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4-error b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4-error index e17df3e26ea..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4-error +++ b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection1.p4-error @@ -1,31 +0,0 @@ -mov m.pna_main_output_metadata_output_port; t.vport; -drop -(387677)MAINPARSERIMPL_START -extract h.ethernet; -jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4 -extract h.ipv4; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -jmpnv LABEL_FALSE h.ipv4; -LABEL_TRUE -jmpeq LABEL_TRUE_0 m.pna_main_input_metadata_direction; 0 -mov m.MainControlT_tmp; h.ipv4.dstAddr; -jmp LABEL_END_0 -LABEL_TRUE_0 -mov m.MainControlT_tmp; h.ipv4.srcAddr; -LABEL_END_0 -jmpneq LABEL_FALSE_0 m.MainControlT_tmp; h.ipv4.dstAddr; -LABEL_TRUE_1 -apply ipv4_da_lpm -jmp LABEL_END_1 -LABEL_FALSE_0 -LABEL_END_1 -jmp LABEL_END -LABEL_FALSE -LABEL_END -emit h.ethernet; -emit h.ipv4; -(387683) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4-error b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4-error index 0a89e5886db..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4-error +++ b/testdata/p4_16_samples_outputs/pna-example-SelectByDirection2.p4-error @@ -1,39 +0,0 @@ -mov m.local_metadata_meta; t.addr; -jmpeq LABEL_TRUE_2 m.pna_main_input_metadata_direction; 0 -mov m.MainControlT_addr; h.ipv4.dstAddr; -jmp LABEL_END_2 -LABEL_TRUE_2 -mov m.MainControlT_addr; h.ipv4.srcAddr; -LABEL_END_2 -mov m.local_metadata_meta; m.MainControlT_addr; -drop -(384937)MAINPARSERIMPL_START -extract h.ethernet; -jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4 -extract h.ipv4; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -jmpnv LABEL_FALSE h.ipv4; -LABEL_TRUE -jmpeq LABEL_TRUE_0 m.pna_main_input_metadata_direction; 0 -mov m.MainControlT_addr; h.ipv4.dstAddr; -jmp LABEL_END_0 -LABEL_TRUE_0 -mov m.MainControlT_addr; h.ipv4.srcAddr; -LABEL_END_0 -mov m.local_metadata_meta; m.MainControlT_addr; -jmpneq LABEL_FALSE_0 m.local_metadata_meta; h.ipv4.dstAddr; -LABEL_TRUE_1 -apply ipv4_da_lpm -jmp LABEL_END_1 -LABEL_FALSE_0 -LABEL_END_1 -jmp LABEL_END -LABEL_FALSE -LABEL_END -emit h.ethernet; -emit h.ipv4; -(384943) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4-error b/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4-error index fa4b1633a0b..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4-error +++ b/testdata/p4_16_samples_outputs/pna-example-dpdk-varbit.p4-error @@ -1,30 +0,0 @@ -mov h.ethernet.dstAddr; t.param; -mov h.ethernet.etherType; t.param; -(434766)MAINPARSERIMPL_START -extract h.ethernet; -jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4 -extract h.ipv4_base; -jmpeq MAINPARSERIMPL_ACCEPT h.ipv4_base.version_ihl; 69 -jmp MAINPARSERIMPL_PARSE_IPV4_OPTIONS -MAINPARSERIMPL_PARSE_IPV4_OPTIONS -lookahead h.MainParserT_parser_lookahead_tmp; -mov m.MainParserT_parser_tmp_2; h.MainParserT_parser_lookahead_tmp.f; -jmpeq MAINPARSERIMPL_PARSE_IPV4_OPTION_TIMESTAMP m.MainParserT_parser_tmp_2; 68 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4_OPTION_TIMESTAMP -lookahead h.MainParserT_parser_tmp_hdr; -(434471)mov m.MainParserT_parser_tmp_0; m.MainParserT_parser_tmp; -(434473)mov m.MainParserT_parser_tmp_1; m.MainParserT_parser_tmp_0; -(434475)mov m.MainParserT_parser_tmp_1_extract_tmp; m.MainParserT_parser_tmp_1; -(434537)extract h.ipv4_option_timestamp;m.MainParserT_parser_tmp_1_extract_tmp; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -mov m.pna_main_output_metadata_output_port; 0 -apply tbl -apply tbl2 -emit h.ethernet; -emit h.ipv4_base; -(434772) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4-error b/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4-error index 1caf71f792b..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4-error +++ b/testdata/p4_16_samples_outputs/pna-example-mirror-packet.p4-error @@ -1,21 +0,0 @@ -mov m.pna_main_output_metadata_output_port; t.vport; -mov m.mirrorSlot; 3 -mov m.mirrorSession; 58 -mirror m.mirrorSlot; m.mirrorSession; -drop -mov m.mirrorSlot_0; 3 -mov m.mirrorSession_0; 62 -mirror m.mirrorSlot_0; m.mirrorSession_0; -(395031)MAINPARSERIMPL_START -extract h.ethernet; -jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4 -extract h.ipv4; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -apply flowTable -emit h.ethernet; -emit h.ipv4; -(395037) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-template.p4-error b/testdata/p4_16_samples_outputs/pna-example-template.p4-error index e534d2a9f59..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-example-template.p4-error +++ b/testdata/p4_16_samples_outputs/pna-example-template.p4-error @@ -1,20 +0,0 @@ -mov m.pna_main_output_metadata_output_port; t.vport; -drop -(372111)MAINPARSERIMPL_START -extract h.ethernet; -jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4 -extract h.ipv4; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -jmpnv LABEL_FALSE h.ipv4; -LABEL_TRUE -apply ipv4_da_lpm -jmp LABEL_END -LABEL_FALSE -LABEL_END -emit h.ethernet; -emit h.ipv4; -(372117) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-example-tunnel.p4-error b/testdata/p4_16_samples_outputs/pna-example-tunnel.p4-error index 527adf86dee..3ade61402b0 100644 --- a/testdata/p4_16_samples_outputs/pna-example-tunnel.p4-error +++ b/testdata/p4_16_samples_outputs/pna-example-tunnel.p4-error @@ -1,26 +1 @@ [--Wwarn=mismatch] warning: Mismatched header/metadata struct for key elements in table tunnel_decap_ipv4_tunnel_term_table. Copying all match fields to metadata -mov m.local_metadata__tunnel_id1; t.tunnel_id; -mov m.local_metadata__outer_ipv4_dst0; t.dst_addr; -(502996)PACKET_PARSER_START -extract h.outer_ethernet; -jmpeq PACKET_PARSER_PARSE_IPV4_OTR h.outer_ethernet.ether_type; 2048 -jmp PACKET_PARSER_ACCEPT -PACKET_PARSER_PARSE_IPV4_OTR -extract h.outer_ipv4; -jmp PACKET_PARSER_ACCEPT -PACKET_PARSER_REJECT -PACKET_PARSER_ACCEPT -jmpneq LABEL_FALSE m.pna_main_input_metadata_direction; 0 -LABEL_TRUE -mov m.main_control_tunnel_decap_ipv4_tunnel_term_table_outer_ipv4_src_addr; h.outer_ipv4.src_addr; -mov m.main_control_tunnel_decap_ipv4_tunnel_term_table_outer_ipv4_dst_addr; h.outer_ipv4.dst_addr; -apply tunnel_decap_ipv4_tunnel_term_table -jmp LABEL_END -LABEL_FALSE -apply tunnel_encap_set_tunnel_encap -LABEL_END -emit h.outer_ethernet; -emit h.outer_ipv4; -emit h.ethernet; -emit h.ipv4; -(503002) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-extract-local-header.p4-error b/testdata/p4_16_samples_outputs/pna-extract-local-header.p4-error index f1905dd13ca..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-extract-local-header.p4-error +++ b/testdata/p4_16_samples_outputs/pna-extract-local-header.p4-error @@ -1,27 +0,0 @@ -(324519)MAINPARSERIMPL_START -invalidate h.MainParserT_parser_local_hdr; -extract h.MainParserT_parser_local_hdr; -jmpeq MAINPARSERIMPL_PARSE_H1 h.MainParserT_parser_local_hdr.type1; 4660 -jmpeq MAINPARSERIMPL_PARSE_H2 h.MainParserT_parser_local_hdr.type1; 22136 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_H2 -validate h.h2; -mov h.h2.type1; h.MainParserT_parser_local_hdr.type1; -mov h.h2.type2; h.MainParserT_parser_local_hdr.type2; -mov h.h2.value; h.MainParserT_parser_local_hdr.value; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_H1 -extract h.h1; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -jmpnv LABEL_FALSE h.h1; -jmpnv LABEL_FALSE h.h2; -jmp LABEL_TRUE -LABEL_TRUE -emit h.h1; -emit h.h2; -jmp LABEL_END -LABEL_FALSE -LABEL_END -(324525) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-issue3041.p4-error b/testdata/p4_16_samples_outputs/pna-issue3041.p4-error index 08df934288b..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-issue3041.p4-error +++ b/testdata/p4_16_samples_outputs/pna-issue3041.p4-error @@ -1,29 +0,0 @@ -mov h.ethernet.dstAddr; t.param; -mov h.ethernet.etherType; t.param; -(420382)MAINPARSERIMPL_START -extract h.ethernet; -jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4 -extract h.ipv4_base; -mov m.MainParserT_parser_tmp; h.ipv4_base.version_ihl; -(420041)(420042)jmpeq MAINPARSERIMPL_ACCEPT m.MainParserT_parser_tmp_2; 5 -jmp MAINPARSERIMPL_PARSE_IPV4_OPTIONS -MAINPARSERIMPL_PARSE_IPV4_OPTIONS -lookahead h.option; -jmpeq MAINPARSERIMPL_PARSE_IPV4_OPTION_TIMESTAMP h.option.type; 68 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4_OPTION_TIMESTAMP -(420087)mov m.MainParserT_parser_tmp_1; m.MainParserT_parser_tmp_0; -(420089)mov m.MainParserT_parser_tmp_3; m.MainParserT_parser_tmp_1; -(420091)mov m.MainParserT_parser_tmp_3_extract_tmp; m.MainParserT_parser_tmp_3; -(420153)extract h.ipv4_option_timestamp;m.MainParserT_parser_tmp_3_extract_tmp; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -mov m.pna_main_output_metadata_output_port; 0 -apply tbl -apply tbl2 -emit h.ethernet; -emit h.ipv4_base; -(420388) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4-error b/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4-error index dad11b57896..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4-error +++ b/testdata/p4_16_samples_outputs/pna-lookahead-structure-bit-field.p4-error @@ -1,15 +0,0 @@ -(309500)MAINPARSERIMPL_START -lookahead h.MainParserT_parser_lookahead_tmp; -mov m.local_metadata_f1; h.MainParserT_parser_lookahead_tmp.f; -jmpeq MAINPARSERIMPL_PARSE_H1 m.local_metadata_f1; 1 -jmpeq MAINPARSERIMPL_PARSE_H2 m.local_metadata_f1; 2 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_H2 -extract h.h2; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_H1 -extract h.h1; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -(309506) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4-error b/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4-error index 3798bb921e0..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4-error +++ b/testdata/p4_16_samples_outputs/pna-lookahead-structure.p4-error @@ -1,19 +0,0 @@ -(333961)MAINPARSERIMPL_START -lookahead h.MainParserT_parser_lookahead_tmp_0; -mov m.MainParserT_parser_tmp_3; h.MainParserT_parser_lookahead_tmp_0.f; -mov m.MainParserT_parser_tmp_0; m.MainParserT_parser_tmp_3; -(333779)(333780)jmpeq MAINPARSERIMPL_PARSE_H1 m.MainParserT_parser_tmp_2; 4660 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_H1 -extract h.h1; -lookahead h.MainParserT_parser_lookahead_tmp; -mov m.MainParserT_parser_tmp_4; h.MainParserT_parser_lookahead_tmp.f; -mov m.MainParserT_parser_tmp; m.MainParserT_parser_tmp_4; -(333869)(333870)(333872)(333874)jmpeq MAINPARSERIMPL_PARSE_H2 m.MainParserT_parser_tmp_1; 1 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_H2 -extract h.h2; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -(333967) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4-error b/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4-error index d95a8db393a..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4-error +++ b/testdata/p4_16_samples_outputs/pna-mux-dismantle.p4-error @@ -1,59 +0,0 @@ -mov h.MainControlT_hdr_3_tcp; h.tcp; -(530864)(530865)jmp LABEL_TRUE_1 -LABEL_TRUE_1 -mov m.MainControlT_tmp_3; 1 -jmp LABEL_END_1 -LABEL_FALSE_1 -mov m.MainControlT_tmp_3; 0 -LABEL_END_1 -mov m.local_metadata_rng_result1; m.MainControlT_tmp_3; -mov m.pna_main_output_metadata_output_port; t.vport; -mov m.learnArg; 0 -learn next_hop -(530941)(530942)jmp LABEL_TRUE_2 -LABEL_TRUE_2 -(530946)(530947)jmp LABEL_TRUE_3 -LABEL_TRUE_3 -mov m.MainControlT_tmp_2; m.local_metadata_val1; -jmp LABEL_END_3 -LABEL_FALSE_3 -mov m.MainControlT_tmp_2; m.local_metadata_val2; -LABEL_END_3 -mov m.MainControlT_tmp_1; m.MainControlT_tmp_2; -jmp LABEL_END_2 -LABEL_FALSE_2 -mov m.MainControlT_tmp_1; m.local_metadata_val1; -LABEL_END_2 -mov m.local_metadata_rng_result1; m.MainControlT_tmp_1; -mov m.pna_main_output_metadata_output_port; t.vport; -mov h.ipv4.srcAddr; t.newAddr; -mov m.MainControlT_tmp; 0 -mov m.MainControlT_tmp_0; 1234 -learn next_hop -(531153)MAINPARSERIMPL_START -extract h.ethernet; -jmpeq MAINPARSERIMPL_PARSE_IPV4 h.ethernet.etherType; 2048 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_PARSE_IPV4 -extract h.ipv4; -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -(530783)(530784)jmp LABEL_TRUE -LABEL_TRUE -mov m.MainControlT_tmp_4; 1 -jmp LABEL_END -LABEL_FALSE -mov m.MainControlT_tmp_4; 0 -LABEL_END -mov m.local_metadata_rng_result1; m.MainControlT_tmp_4; -jmpnv LABEL_FALSE_0 h.ipv4; -LABEL_TRUE_0 -apply ipv4_da -apply ipv4_da2 -jmp LABEL_END_0 -LABEL_FALSE_0 -LABEL_END_0 -emit h.ethernet; -emit h.ipv4; -(531159) \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-subparser.p4-error b/testdata/p4_16_samples_outputs/pna-subparser.p4-error index dab901cbf01..e69de29bb2d 100644 --- a/testdata/p4_16_samples_outputs/pna-subparser.p4-error +++ b/testdata/p4_16_samples_outputs/pna-subparser.p4-error @@ -1,14 +0,0 @@ -(319476)MAINPARSERIMPL_START -invalidate h.ethernet; -invalidate h.ipv4; -extract h.ethernet; -jmpeq MAINPARSERIMPL_COMMONPARSER_PARSE_IPV4 h.ethernet.etherType; 2048 -jmp MAINPARSERIMPL_START_0 -MAINPARSERIMPL_COMMONPARSER_PARSE_IPV4 -extract h.ipv4; -jmp MAINPARSERIMPL_START_0 -MAINPARSERIMPL_START_0 -jmp MAINPARSERIMPL_ACCEPT -MAINPARSERIMPL_REJECT -MAINPARSERIMPL_ACCEPT -(319482) \ No newline at end of file From 57e853bb011909ab3a18da20e6a1b66c2b59cffb Mon Sep 17 00:00:00 2001 From: Kamlesh Kumar Date: Tue, 19 Apr 2022 00:43:58 -0800 Subject: [PATCH 4/6] make sure new names are unique Remove uniqued vars --- backends/dpdk/CMakeLists.txt | 4 +- backends/dpdk/backend.cpp | 2 +- ...{dpdkPnaDirection.cpp => dpdkMetadata.cpp} | 26 ++++- .../{dpdkPnaDirection.h => dpdkMetadata.h} | 17 +-- .../pna-direction-main-parser-err.p4 | 2 - testdata/p4_16_samples/pna-direction.p4 | 4 +- .../pna-direction-main-parser-err-midend.p4 | 30 ++--- .../pna-direction-main-parser-err.p4-error | 0 ...pna-direction-main-parser-err.p4.bfrt.json | 61 ++++++++++ .../pna-direction-main-parser-err.p4.spec | 106 ++++++++++++++++++ 10 files changed, 216 insertions(+), 36 deletions(-) rename backends/dpdk/{dpdkPnaDirection.cpp => dpdkMetadata.cpp} (83%) rename backends/dpdk/{dpdkPnaDirection.h => dpdkMetadata.h} (80%) create mode 100644 testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4-error create mode 100644 testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4.bfrt.json create mode 100644 testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4.spec diff --git a/backends/dpdk/CMakeLists.txt b/backends/dpdk/CMakeLists.txt index a464935a2eb..845690d4077 100644 --- a/backends/dpdk/CMakeLists.txt +++ b/backends/dpdk/CMakeLists.txt @@ -58,7 +58,7 @@ set(P4C_DPDK_SOURCES dpdkArch.cpp dpdkContext.cpp dpdkAsmOpt.cpp - dpdkPnaDirection.cpp + dpdkMetadata.cpp dpdkUtils.cpp options.cpp control-plane/bfruntime_ext.cpp @@ -75,7 +75,7 @@ set(P4C_DPDK_HEADERS dpdkContext.h constants.h dpdkAsmOpt.h - dpdkPnaDirection.h + dpdkMetadata.h printUtils.h dpdkUtils.h dpdkProgramStructure.h diff --git a/backends/dpdk/backend.cpp b/backends/dpdk/backend.cpp index 15b94604dda..ca925b89570 100644 --- a/backends/dpdk/backend.cpp +++ b/backends/dpdk/backend.cpp @@ -29,7 +29,7 @@ limitations under the License. #include "ir/ir.h" #include "lib/stringify.h" #include "../bmv2/common/lower.h" -#include "dpdkPnaDirection.h" +#include "dpdkMetadata.h" namespace DPDK { diff --git a/backends/dpdk/dpdkPnaDirection.cpp b/backends/dpdk/dpdkMetadata.cpp similarity index 83% rename from backends/dpdk/dpdkPnaDirection.cpp rename to backends/dpdk/dpdkMetadata.cpp index f030b603680..e60a6aa530d 100644 --- a/backends/dpdk/dpdkPnaDirection.cpp +++ b/backends/dpdk/dpdkMetadata.cpp @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -#include "dpdkPnaDirection.h" +#include "dpdkMetadata.h" #include "dpdkUtils.h" namespace DPDK { @@ -31,11 +31,31 @@ const IR::Node* AddNewMetadataFields::preorder(IR::DpdkStructType *st) { return st; } +// make sure new decls and fields name are unique +void DirectionToRegRead::uniqueNames(IR::DpdkAsmProgram *p) { + P4::MinimalNameGenerator mng; + for (auto st : p->structType) { + if (isMetadataStruct(st)) { + for (auto field : st->fields) + mng.usedName(field->name); + } + } + reg_read_tmp = mng.newName("reg_read_tmp"); + left_shift_tmp = mng.newName("left_shift_tmp"); + P4::MinimalNameGenerator mng1; + for (auto decl : p->externDeclarations) { + mng1.usedName(decl->name); + } + registerInstanceName = mng1.newName("network_port_mask"); +} + const IR::Node* DirectionToRegRead::preorder(IR::DpdkAsmProgram *p) { + uniqueNames(p); p->externDeclarations.push_back(addRegDeclInstance(registerInstanceName)); return p; } +// create and add register declaration instance to program IR::DpdkExternDeclaration* DirectionToRegRead::addRegDeclInstance(cstring instanceName) { auto typepath = new IR::Path("Register"); auto type = new IR::Type_Name(typepath); @@ -52,6 +72,7 @@ IR::DpdkExternDeclaration* DirectionToRegRead::addRegDeclInstance(cstring instan return decl; } +// add new fields in metadata structure void DirectionToRegRead::addMetadataField(cstring fieldName) { if (newFieldName.count(fieldName)) return; @@ -60,6 +81,7 @@ void DirectionToRegRead::addMetadataField(cstring fieldName) { newFieldName.insert(fieldName); } +// check member expression using metadata direction field bool DirectionToRegRead::isDirection(const IR::Member *m) { if (m == nullptr) return false; @@ -80,6 +102,8 @@ const IR::Node *DirectionToRegRead::postorder(IR::DpdkAction *a) { return a; } +// replace direction field uses with register read i.e. +// istd.direction -> (direction_port_mask.read(0) & (32w0x1 << istd.input_port)) void DirectionToRegRead::replaceDirection(const IR::Member *m) { addMetadataField(reg_read_tmp); addMetadataField(left_shift_tmp); diff --git a/backends/dpdk/dpdkPnaDirection.h b/backends/dpdk/dpdkMetadata.h similarity index 80% rename from backends/dpdk/dpdkPnaDirection.h rename to backends/dpdk/dpdkMetadata.h index 36a738df98b..8c8676da546 100644 --- a/backends/dpdk/dpdkPnaDirection.h +++ b/backends/dpdk/dpdkMetadata.h @@ -14,9 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -#ifndef BACKENDS_DPDK_DPDKPNADIRECTION_H_ -#define BACKENDS_DPDK_DPDKPNADIRECTION_H_ +#ifndef BACKENDS_DPDK_DPDKMETADATA_H_ +#define BACKENDS_DPDK_DPDKMETADATA_H_ +#include "frontends/common/resolveReferences/referenceMap.h" #include "ir/ir.h" namespace DPDK { @@ -38,9 +39,6 @@ class DirectionToRegRead : public Transform { public: DirectionToRegRead() { - reg_read_tmp = "reg_read_tmp"; - left_shift_tmp = "left_shift_tmp"; - registerInstanceName = "network_port_mask"; // direction to input metadata field name mapping dirToInput.insert(std::make_pair(cstring("pna_main_input_metadata_direction"), cstring("pna_main_input_metadata_input_port"))); @@ -49,24 +47,19 @@ class DirectionToRegRead : public Transform { dirToInput.insert(std::make_pair(cstring("pna_main_parser_input_metadata_direction"), cstring("pna_main_parser_input_metadata_input_port"))); } - + void uniqueNames(IR::DpdkAsmProgram *p); const IR::Node* preorder(IR::DpdkAsmProgram *p) override; - // create and add register declaration instance to program IR::DpdkExternDeclaration* addRegDeclInstance(cstring instanceName); - // add new fields in metadata structure void addMetadataField(cstring fieldName); - // check member expression using metadata direction field bool isDirection(const IR::Member *m); const IR::Node *postorder(IR::DpdkAction *a); const IR::Node *postorder(IR::DpdkListStatement *l) override; - // replace direction field uses with register read i.e. - // istd.direction -> (direction_port_mask.read(0) & (32w0x1 << istd.input_port)) void replaceDirection(const IR::Member *m); IR::IndexedVector replaceDirectionWithRegRead(IR::IndexedVector stmts); }; } // namespace DPDK -#endif // BACKENDS_DPDK_DPDKPNADIRECTION_H_ +#endif // BACKENDS_DPDK_DPDKMETADATA_H_ diff --git a/testdata/p4_16_samples/pna-direction-main-parser-err.p4 b/testdata/p4_16_samples/pna-direction-main-parser-err.p4 index b372fc05967..d7033cebeab 100644 --- a/testdata/p4_16_samples/pna-direction-main-parser-err.p4 +++ b/testdata/p4_16_samples/pna-direction-main-parser-err.p4 @@ -91,7 +91,6 @@ parser MainParserImpl( in pna_main_parser_input_metadata_t istd) { bit<32> tmpDir; - state start { pkt.extract(hdr.ethernet); transition select(hdr.ethernet.etherType) { @@ -106,7 +105,6 @@ parser MainParserImpl( } else { tmpDir = hdr.ipv4.dstAddr; } - transition accept; } } diff --git a/testdata/p4_16_samples/pna-direction.p4 b/testdata/p4_16_samples/pna-direction.p4 index 68a55ce46cc..78afcafbda5 100644 --- a/testdata/p4_16_samples/pna-direction.p4 +++ b/testdata/p4_16_samples/pna-direction.p4 @@ -77,7 +77,7 @@ control PreControlImpl( { apply { - meta.b = istd.direction != PNA_Direction_t.NET_TO_HOST; + meta.b = istd.direction != PNA_Direction_t.NET_TO_HOST; if (PNA_Direction_t.NET_TO_HOST == istd.direction) { meta.tmpDir = hdr.ipv4.srcAddr; } else { @@ -94,8 +94,6 @@ parser MainParserImpl( inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { - bit<32> tmpDir; - state start { pkt.extract(hdr.ethernet); transition select(hdr.ethernet.etherType) { diff --git a/testdata/p4_16_samples_outputs/pna-direction-main-parser-err-midend.p4 b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err-midend.p4 index 28434e06528..a4e7f1d5585 100644 --- a/testdata/p4_16_samples_outputs/pna-direction-main-parser-err-midend.p4 +++ b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err-midend.p4 @@ -112,29 +112,29 @@ control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in } const default_action = default_route_drop_0(); } - @hidden action pnadirectionmainparsererr144() { + @hidden action pnadirectionmainparsererr138() { tmpDir_1 = hdr.ipv4.srcAddr; } - @hidden action pnadirectionmainparsererr146() { + @hidden action pnadirectionmainparsererr140() { tmpDir_1 = hdr.ipv4.dstAddr; } - @hidden table tbl_pnadirectionmainparsererr144 { + @hidden table tbl_pnadirectionmainparsererr138 { actions = { - pnadirectionmainparsererr144(); + pnadirectionmainparsererr138(); } - const default_action = pnadirectionmainparsererr144(); + const default_action = pnadirectionmainparsererr138(); } - @hidden table tbl_pnadirectionmainparsererr146 { + @hidden table tbl_pnadirectionmainparsererr140 { actions = { - pnadirectionmainparsererr146(); + pnadirectionmainparsererr140(); } - const default_action = pnadirectionmainparsererr146(); + const default_action = pnadirectionmainparsererr140(); } apply { if (PNA_Direction_t.NET_TO_HOST == istd.direction) { - tbl_pnadirectionmainparsererr144.apply(); + tbl_pnadirectionmainparsererr138.apply(); } else { - tbl_pnadirectionmainparsererr146.apply(); + tbl_pnadirectionmainparsererr140.apply(); } if (hdr.ipv4.isValid()) { ipv4_da_lpm.apply(); @@ -143,18 +143,18 @@ control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in } control MainDeparserImpl(packet_out pkt, in headers_t hdr, in main_metadata_t user_meta, in pna_main_output_metadata_t ostd) { - @hidden action pnadirectionmainparsererr169() { + @hidden action pnadirectionmainparsererr155() { pkt.emit(hdr.ethernet); pkt.emit(hdr.ipv4); } - @hidden table tbl_pnadirectionmainparsererr169 { + @hidden table tbl_pnadirectionmainparsererr155 { actions = { - pnadirectionmainparsererr169(); + pnadirectionmainparsererr155(); } - const default_action = pnadirectionmainparsererr169(); + const default_action = pnadirectionmainparsererr155(); } apply { - tbl_pnadirectionmainparsererr169.apply(); + tbl_pnadirectionmainparsererr155.apply(); } } diff --git a/testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4-error b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4-error new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4.bfrt.json b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4.bfrt.json new file mode 100644 index 00000000000..13b95e4a64b --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4.bfrt.json @@ -0,0 +1,61 @@ +{ + "schema_version" : "1.0.0", + "tables" : [ + { + "name" : "pipe.MainControlImpl.ipv4_da_lpm", + "id" : 40097106, + "table_type" : "MatchAction_Direct", + "size" : 1024, + "annotations" : [], + "depends_on" : [], + "has_const_default_action" : true, + "key" : [ + { + "id" : 1, + "name" : "ipv4_addr", + "repeated" : false, + "annotations" : [], + "mandatory" : false, + "match_type" : "LPM", + "type" : { + "type" : "bytes", + "width" : 32 + } + } + ], + "action_specs" : [ + { + "id" : 25584005, + "name" : "MainControlImpl.next_hop", + "action_scope" : "TableAndDefault", + "annotations" : [], + "data" : [ + { + "id" : 1, + "name" : "vport", + "repeated" : false, + "mandatory" : true, + "read_only" : false, + "annotations" : [], + "type" : { + "type" : "bytes", + "width" : 32 + } + } + ] + }, + { + "id" : 19071441, + "name" : "MainControlImpl.default_route_drop", + "action_scope" : "TableAndDefault", + "annotations" : [], + "data" : [] + } + ], + "data" : [], + "supported_operations" : [], + "attributes" : ["EntryScope"] + } + ], + "learn_filters" : [] +} \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4.spec b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4.spec new file mode 100644 index 00000000000..2711d8b221e --- /dev/null +++ b/testdata/p4_16_samples_outputs/pna-direction-main-parser-err.p4.spec @@ -0,0 +1,106 @@ + +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 next_hop_0_arg_t { + bit<32> vport +} + +struct main_metadata_t { + bit<32> pna_pre_input_metadata_input_port + bit<32> pna_pre_input_metadata_direction + bit<32> pna_main_parser_input_metadata_direction + bit<32> pna_main_parser_input_metadata_input_port + bit<32> pna_main_input_metadata_input_port + bit<32> local_metadata_tmpDir + bit<32> pna_main_output_metadata_output_port + bit<32> MainParserT_parser_tmp + bit<32> reg_read_tmp + bit<32> left_shift_tmp +} +metadata instanceof main_metadata_t + +header ethernet instanceof ethernet_t +header ipv4 instanceof ipv4_t + +regarray network_port_mask size 0x1 initval 0 + +action next_hop_0 args instanceof next_hop_0_arg_t { + mov m.pna_main_output_metadata_output_port t.vport + return +} + +action default_route_drop_0 args none { + drop + return +} + +table ipv4_da_lpm { + key { + m.local_metadata_tmpDir lpm + } + actions { + next_hop_0 + default_route_drop_0 + } + default_action default_route_drop_0 args none + size 0x10000 +} + + +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 + jmpeq MAINPARSERIMPL_PARSE_IPV4_TRUE m.MainParserT_parser_tmp 0x1 + jmpeq MAINPARSERIMPL_PARSE_IPV4_FALSE m.MainParserT_parser_tmp 0x0 + jmp MAINPARSERIMPL_NOMATCH + MAINPARSERIMPL_PARSE_IPV4_TRUE : mov m.local_metadata_tmpDir h.ipv4.srcAddr + jmp MAINPARSERIMPL_ACCEPT + MAINPARSERIMPL_PARSE_IPV4_FALSE : regrd m.reg_read_tmp network_port_mask 0x0 + mov m.left_shift_tmp 0x1 + shl m.left_shift_tmp m.pna_main_parser_input_metadata_input_port + mov m.pna_main_parser_input_metadata_direction m.reg_read_tmp + and m.pna_main_parser_input_metadata_direction m.left_shift_tmp + jmpneq LABEL_FALSE 0x0 m.pna_main_parser_input_metadata_direction + mov m.MainParserT_parser_tmp 0x1 + jmp LABEL_END + LABEL_FALSE : mov m.MainParserT_parser_tmp 0x0 + LABEL_END : mov m.local_metadata_tmpDir h.ipv4.dstAddr + jmp MAINPARSERIMPL_ACCEPT + MAINPARSERIMPL_NOMATCH : mov m.pna_pre_input_metadata_parser_error 0x2 + MAINPARSERIMPL_ACCEPT : regrd m.reg_read_tmp network_port_mask 0x0 + mov m.left_shift_tmp 0x1 + shl m.left_shift_tmp m.pna_pre_input_metadata_input_port + mov m.pna_pre_input_metadata_direction m.reg_read_tmp + and m.pna_pre_input_metadata_direction m.left_shift_tmp + jmpneq LABEL_FALSE_0 0x0 m.pna_pre_input_metadata_direction + mov m.local_metadata_tmpDir h.ipv4.srcAddr + jmp LABEL_END_1 + LABEL_FALSE_0 : mov m.local_metadata_tmpDir h.ipv4.dstAddr + LABEL_END_1 : jmpnv LABEL_END_2 h.ipv4 + table ipv4_da_lpm + LABEL_END_2 : emit h.ethernet + emit h.ipv4 + tx m.pna_main_output_metadata_output_port +} + + From 5befd30de8c0444752a88cac2fc65b2aa3eb8f48 Mon Sep 17 00:00:00 2001 From: Kamlesh Kumar Date: Tue, 19 Apr 2022 02:36:34 -0800 Subject: [PATCH 5/6] Added error check --- backends/dpdk/dpdkMetadata.cpp | 8 ++++- .../pna-direction-first.p4 | 1 - .../pna-direction-midend.p4 | 30 +++++++++---------- .../p4_16_samples_outputs/pna-direction.p4 | 1 - 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/backends/dpdk/dpdkMetadata.cpp b/backends/dpdk/dpdkMetadata.cpp index e60a6aa530d..93cf02a1207 100644 --- a/backends/dpdk/dpdkMetadata.cpp +++ b/backends/dpdk/dpdkMetadata.cpp @@ -42,11 +42,17 @@ void DirectionToRegRead::uniqueNames(IR::DpdkAsmProgram *p) { } reg_read_tmp = mng.newName("reg_read_tmp"); left_shift_tmp = mng.newName("left_shift_tmp"); + registerInstanceName = "network_port_mask"; + P4::MinimalNameGenerator mng1; for (auto decl : p->externDeclarations) { mng1.usedName(decl->name); } - registerInstanceName = mng1.newName("network_port_mask"); + // "network_port_mask" name is used in dpdk for initialzing direction port mask + // make sure no such decls exist with that name + if (mng1.newName(registerInstanceName) != registerInstanceName) + ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET,"decl name %s is reserved for dpdk pna", + registerInstanceName); } const IR::Node* DirectionToRegRead::preorder(IR::DpdkAsmProgram *p) { diff --git a/testdata/p4_16_samples_outputs/pna-direction-first.p4 b/testdata/p4_16_samples_outputs/pna-direction-first.p4 index 0ec29deeffe..d887683befa 100644 --- a/testdata/p4_16_samples_outputs/pna-direction-first.p4 +++ b/testdata/p4_16_samples_outputs/pna-direction-first.p4 @@ -49,7 +49,6 @@ control PreControlImpl(in headers_t hdr, inout main_metadata_t meta, in pna_pre_ } parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { - bit<32> tmpDir; state start { pkt.extract(hdr.ethernet); transition select(hdr.ethernet.etherType) { diff --git a/testdata/p4_16_samples_outputs/pna-direction-midend.p4 b/testdata/p4_16_samples_outputs/pna-direction-midend.p4 index 2ea2f97dea2..1b98cd4673d 100644 --- a/testdata/p4_16_samples_outputs/pna-direction-midend.p4 +++ b/testdata/p4_16_samples_outputs/pna-direction-midend.p4 @@ -107,29 +107,29 @@ control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in } const default_action = default_route_drop(); } - @hidden action pnadirection147() { + @hidden action pnadirection136() { tmpDir_0 = hdr.ipv4.srcAddr; } - @hidden action pnadirection149() { + @hidden action pnadirection138() { tmpDir_0 = hdr.ipv4.dstAddr; } - @hidden table tbl_pnadirection147 { + @hidden table tbl_pnadirection136 { actions = { - pnadirection147(); + pnadirection136(); } - const default_action = pnadirection147(); + const default_action = pnadirection136(); } - @hidden table tbl_pnadirection149 { + @hidden table tbl_pnadirection138 { actions = { - pnadirection149(); + pnadirection138(); } - const default_action = pnadirection149(); + const default_action = pnadirection138(); } apply { if (PNA_Direction_t.NET_TO_HOST == istd.direction) { - tbl_pnadirection147.apply(); + tbl_pnadirection136.apply(); } else { - tbl_pnadirection149.apply(); + tbl_pnadirection138.apply(); } if (hdr.ipv4.isValid()) { ipv4_da_lpm_0.apply(); @@ -138,18 +138,18 @@ control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in } control MainDeparserImpl(packet_out pkt, in headers_t hdr, in main_metadata_t user_meta, in pna_main_output_metadata_t ostd) { - @hidden action pnadirection172() { + @hidden action pnadirection153() { pkt.emit(hdr.ethernet); pkt.emit(hdr.ipv4); } - @hidden table tbl_pnadirection172 { + @hidden table tbl_pnadirection153 { actions = { - pnadirection172(); + pnadirection153(); } - const default_action = pnadirection172(); + const default_action = pnadirection153(); } apply { - tbl_pnadirection172.apply(); + tbl_pnadirection153.apply(); } } diff --git a/testdata/p4_16_samples_outputs/pna-direction.p4 b/testdata/p4_16_samples_outputs/pna-direction.p4 index 216f72edb8c..1fa336d3cb3 100644 --- a/testdata/p4_16_samples_outputs/pna-direction.p4 +++ b/testdata/p4_16_samples_outputs/pna-direction.p4 @@ -49,7 +49,6 @@ control PreControlImpl(in headers_t hdr, inout main_metadata_t meta, in pna_pre_ } parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { - bit<32> tmpDir; state start { pkt.extract(hdr.ethernet); transition select(hdr.ethernet.etherType) { From 2a87905e30f8c175a7a4e25124288ab900672df4 Mon Sep 17 00:00:00 2001 From: Kamlesh Kumar Date: Tue, 19 Apr 2022 17:19:03 -0800 Subject: [PATCH 6/6] Added comments and check used names --- backends/dpdk/dpdkMetadata.cpp | 27 ++++++++++++--------------- backends/dpdk/dpdkMetadata.h | 10 +++++++++- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/backends/dpdk/dpdkMetadata.cpp b/backends/dpdk/dpdkMetadata.cpp index 93cf02a1207..3e8a18841c7 100644 --- a/backends/dpdk/dpdkMetadata.cpp +++ b/backends/dpdk/dpdkMetadata.cpp @@ -42,23 +42,25 @@ void DirectionToRegRead::uniqueNames(IR::DpdkAsmProgram *p) { } reg_read_tmp = mng.newName("reg_read_tmp"); left_shift_tmp = mng.newName("left_shift_tmp"); - registerInstanceName = "network_port_mask"; - P4::MinimalNameGenerator mng1; - for (auto decl : p->externDeclarations) { - mng1.usedName(decl->name); - } // "network_port_mask" name is used in dpdk for initialzing direction port mask // make sure no such decls exist with that name - if (mng1.newName(registerInstanceName) != registerInstanceName) + registerInstanceName = "network_port_mask"; + for (auto decl : p->externDeclarations) { + usedNames.insert(decl->name); + } + + if (usedNames.count(registerInstanceName)) ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET,"decl name %s is reserved for dpdk pna", registerInstanceName); } const IR::Node* DirectionToRegRead::preorder(IR::DpdkAsmProgram *p) { - uniqueNames(p); - p->externDeclarations.push_back(addRegDeclInstance(registerInstanceName)); - return p; + uniqueNames(p); + addMetadataField(reg_read_tmp); + addMetadataField(left_shift_tmp); + p->externDeclarations.push_back(addRegDeclInstance(registerInstanceName)); + return p; } // create and add register declaration instance to program @@ -80,11 +82,8 @@ IR::DpdkExternDeclaration* DirectionToRegRead::addRegDeclInstance(cstring instan // add new fields in metadata structure void DirectionToRegRead::addMetadataField(cstring fieldName) { - if (newFieldName.count(fieldName)) - return; - newMetadataFields.push_back(new IR::StructField(IR::ID(fieldName), + newMetadataFields.push_back(new IR::StructField(IR::ID(fieldName), IR::Type::Bits::get(32))); - newFieldName.insert(fieldName); } // check member expression using metadata direction field @@ -111,8 +110,6 @@ const IR::Node *DirectionToRegRead::postorder(IR::DpdkAction *a) { // replace direction field uses with register read i.e. // istd.direction -> (direction_port_mask.read(0) & (32w0x1 << istd.input_port)) void DirectionToRegRead::replaceDirection(const IR::Member *m) { - addMetadataField(reg_read_tmp); - addMetadataField(left_shift_tmp); auto reade = new IR::Member(new IR::PathExpression(IR::ID("m")), IR::ID(reg_read_tmp)); auto reads = new IR::DpdkRegisterReadStatement(reade, registerInstanceName, diff --git a/backends/dpdk/dpdkMetadata.h b/backends/dpdk/dpdkMetadata.h index 8c8676da546..4e0ca5afee6 100644 --- a/backends/dpdk/dpdkMetadata.h +++ b/backends/dpdk/dpdkMetadata.h @@ -22,17 +22,25 @@ limitations under the License. namespace DPDK { +// If any pass requires to add metadata field to metadata structure +// then just have to create and append struct field to static member newMetadataFields +// In passmanager's passes list AddNewMetadataFields should follow the pass which +// added fields into newMetadataFields class AddNewMetadataFields : public Transform { public: static IR::IndexedVector newMetadataFields; const IR::Node* preorder(IR::DpdkStructType *st) override; }; +// This pass adds decl instance of Register extern in dpdk pna program which will +// be used by dpdk backend for initializing the mask for calculating packet direction +// and all the use point of istd.direction will follow below calculation and assignment +// istd.direction = network_port_mask.read(0) & (32w0x1 << istd.input_port) class DirectionToRegRead : public Transform { ordered_map dirToInput; IR::IndexedVector newStmts; IR::IndexedVector &newMetadataFields = AddNewMetadataFields::newMetadataFields; - ordered_set newFieldName; + ordered_set usedNames; cstring reg_read_tmp; cstring left_shift_tmp; cstring registerInstanceName;