diff --git a/control-plane/p4RuntimeSerializer.cpp b/control-plane/p4RuntimeSerializer.cpp index e6120d824ca..c520a5c8e4b 100644 --- a/control-plane/p4RuntimeSerializer.cpp +++ b/control-plane/p4RuntimeSerializer.cpp @@ -1584,7 +1584,7 @@ void P4RuntimeSerializer::serializeP4RuntimeIfRequired(const IR::P4Program *prog std::vector files; std::vector formats; - // only generate P4Info is required by use-provided options + // only generate P4Info is required by user-provided options if (options.p4RuntimeFile.isNullOrEmpty() && options.p4RuntimeFiles.isNullOrEmpty() && options.p4RuntimeEntriesFile.isNullOrEmpty() && options.p4RuntimeEntriesFiles.isNullOrEmpty()) { diff --git a/frontends/CMakeLists.txt b/frontends/CMakeLists.txt index 9a2acc3eeda..a44f4b1e192 100644 --- a/frontends/CMakeLists.txt +++ b/frontends/CMakeLists.txt @@ -33,6 +33,7 @@ set (P4_FRONTEND_SRCS p4/frontend.cpp p4/functionsInlining.cpp p4/hierarchicalNames.cpp + p4/duplicateActionControlPlaneNameCheck.cpp p4/inlining.cpp p4/localizeActions.cpp p4/methodInstance.cpp @@ -110,6 +111,7 @@ set (P4_FRONTEND_HDRS p4/frontend.h p4/functionsInlining.h p4/hierarchicalNames.h + p4/duplicateHierarchicalNameCheck.h p4/inlining.h p4/localizeActions.h p4/methodInstance.h diff --git a/frontends/p4/duplicateActionControlPlaneNameCheck.cpp b/frontends/p4/duplicateActionControlPlaneNameCheck.cpp new file mode 100644 index 00000000000..13dd2b1c1e1 --- /dev/null +++ b/frontends/p4/duplicateActionControlPlaneNameCheck.cpp @@ -0,0 +1,93 @@ +/* +Copyright 2024 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include "duplicateActionControlPlaneNameCheck.h" + +#include "lib/log.h" + +namespace P4 { + +cstring DuplicateActionControlPlaneNameCheck::getName(const IR::IDeclaration *decl) { + return decl->getName(); +} + +void DuplicateActionControlPlaneNameCheck::checkForDuplicateName(cstring name, + const IR::Node *node) { + bool foundDuplicate = false; + auto *otherNode = node; + auto [it, inserted] = actions.insert(std::pair(name, node)); + if (!inserted) { + foundDuplicate = true; + otherNode = (*it).second; + } + if (foundDuplicate) { + error(ErrorType::ERR_DUPLICATE, "%1%: conflicting control plane name: %2%", node, + otherNode); + } +} + +const IR::Node *DuplicateActionControlPlaneNameCheck::postorder(IR::P4Action *action) { + // Actions declared at the top level that the developer did not + // write a @name annotation for it, should be included in the + // duplicate name check. They do not yet have a @name annotation + // by the time this pass executes, so this method will handle + // such actions. + if (findContext() == nullptr) { + auto annos = action->annotations; + bool hasNameAnnotation = false; + if (annos != nullptr) { + auto nameAnno = annos->getSingle(IR::Annotation::nameAnnotation); + if (nameAnno) { + hasNameAnnotation = true; + } + } + if (!hasNameAnnotation) { + // name is what this top-level action's @name annotation + // will be, after LocalizeAllActions pass adds one. + cstring name = "." + action->name; + checkForDuplicateName(name, action); + } + } + return action; +} + +const IR::Node *DuplicateActionControlPlaneNameCheck::postorder(IR::Annotation *annotation) { + if (annotation->name != IR::Annotation::nameAnnotation) return annotation; + // The node the annotation belongs to + CHECK_NULL(getContext()->parent); + auto *annotatedNode = getContext()->parent->node; + CHECK_NULL(annotatedNode); + // We are only interested in name annotations on actions here, as + // the P4Runtime API control plane generation code already checks + // for duplicate control plane names for other kinds of objects. + if (!annotatedNode->is()) { + return annotation; + } + cstring name = annotation->getName(); + if (!name.startsWith(".")) { + if (!stack.empty()) { + name = absl::StrCat(absl::StrJoin(stack, ".", + [](std::string *out, cstring s) { + absl::StrAppend(out, s.string_view()); + }), + ".", name.string_view()); + } + } + checkForDuplicateName(name, annotatedNode); + return annotation; +} + +} // namespace P4 diff --git a/frontends/p4/duplicateActionControlPlaneNameCheck.h b/frontends/p4/duplicateActionControlPlaneNameCheck.h new file mode 100644 index 00000000000..18156cc1ace --- /dev/null +++ b/frontends/p4/duplicateActionControlPlaneNameCheck.h @@ -0,0 +1,91 @@ +/* +Copyright 2024 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#ifndef FRONTENDS_P4_DUPLICATEACTIONCONTROLPLANENAMECHECK_H_ +#define FRONTENDS_P4_DUPLICATEACTIONCONTROLPLANENAMECHECK_H_ + +#include "ir/ir.h" +#include "ir/visitor.h" + +namespace P4 { + +/** + * This pass does not change anything in the IR. It only gives an + * error if it finds two objects with the same hierarchical name. I + * am not certain, but it might be that at this point in the front + * end, the only way such a duplicate can happen is due to @name + * annotations. @name annotations are definitely taken into account + * in this duplicate check. + * + * See also the pass HierarchicalNames, on which the implementation of + * this pass was based. + * + * This pass should be run before pass LocalizeAllActions, because + * LocalizeAllActions can create actions with duplicate names, by + * design, that were not created by the P4 developer. We should not + * issue an error if that pass creates duplicate hierarchical names. + */ +class DuplicateActionControlPlaneNameCheck : public Transform { + std::vector stack; + /// Used for detection of conflicting control plane names among actions. + string_map actions; + + public: + cstring getName(const IR::IDeclaration *decl); + + DuplicateActionControlPlaneNameCheck() { + setName("DuplicateActionControlPlaneNameCheck"); + visitDagOnce = false; + } + const IR::Node *preorder(IR::P4Parser *parser) override { + stack.push_back(getName(parser)); + return parser; + } + const IR::Node *postorder(IR::P4Parser *parser) override { + stack.pop_back(); + return parser; + } + + const IR::Node *preorder(IR::P4Control *control) override { + stack.push_back(getName(control)); + return control; + } + const IR::Node *postorder(IR::P4Control *control) override { + stack.pop_back(); + return control; + } + + const IR::Node *preorder(IR::P4Table *table) override { + visit(table->annotations); + prune(); + return table; + } + + void checkForDuplicateName(cstring name, const IR::Node *node); + + const IR::Node *postorder(IR::P4Action *action) override; + + const IR::Node *postorder(IR::Annotation *annotation) override; + // Do not change name annotations on parameters + const IR::Node *preorder(IR::Parameter *parameter) override { + prune(); + return parameter; + } +}; + +} // namespace P4 + +#endif /* FRONTENDS_P4_DUPLICATEACTIONCONTROLPLANENAMECHECK_H_ */ diff --git a/frontends/p4/frontend.cpp b/frontends/p4/frontend.cpp index 4c3275463ff..0fd1da169c6 100644 --- a/frontends/p4/frontend.cpp +++ b/frontends/p4/frontend.cpp @@ -35,6 +35,7 @@ limitations under the License. #include "deprecated.h" #include "directCalls.h" #include "dontcareArgs.h" +#include "duplicateActionControlPlaneNameCheck.h" #include "entryPriorities.h" #include "evaluator/evaluator.h" #include "frontends/common/constantFolding.h" @@ -234,6 +235,15 @@ const IR::P4Program *FrontEnd::run(const CompilerOptions &options, const IR::P4P if (policy->optimize(options)) { passes.addPasses({ new Inline(&typeMap, *policy, options.optimizeParserInlining), + }); + } + if (policy->controlPlaneAPIGenEnabled(options)) { + passes.addPasses({ + new DuplicateActionControlPlaneNameCheck(), + }); + } + if (policy->optimize(options)) { + passes.addPasses({ new InlineActions(&typeMap, *policy), new LocalizeAllActions(*policy), new UniqueNames(), diff --git a/frontends/p4/frontend.h b/frontends/p4/frontend.h index 14ad2f345a1..0695ef38298 100644 --- a/frontends/p4/frontend.h +++ b/frontends/p4/frontend.h @@ -60,6 +60,18 @@ class FrontEndPolicy : public RemoveUnusedPolicy { return options.optimizationLevel > 0; } + /// Indicates whether control plane API generation is enabled. + /// @returns default to false unless a command line option was + /// given explicitly enabling control plane API generation. + virtual bool controlPlaneAPIGenEnabled(const CompilerOptions &options) const { + if (options.p4RuntimeFile.isNullOrEmpty() && options.p4RuntimeFiles.isNullOrEmpty() && + options.p4RuntimeEntriesFile.isNullOrEmpty() && + options.p4RuntimeEntriesFiles.isNullOrEmpty()) { + return false; + } + return true; + } + /// Get policy for the constant folding pass. @see ConstantFoldingPolicy /// @returns Defaults to nullptr, which causes constant folding to use the default policy, which /// does not modify the pass defaults in any way. diff --git a/testdata/p4_16_errors/actions-with-duplicate-control-plane-names1.p4 b/testdata/p4_16_errors/actions-with-duplicate-control-plane-names1.p4 new file mode 100644 index 00000000000..561174209c8 --- /dev/null +++ b/testdata/p4_16_errors/actions-with-duplicate-control-plane-names1.p4 @@ -0,0 +1,130 @@ +/* +Copyright 2024 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include +#include + +typedef bit<48> EthernetAddress; + +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +struct headers_t { + ethernet_t ethernet; +} + +struct metadata_t { +/* + bit<4> a; + bit<4> b; +*/ +} + +parser parserImpl( + packet_in pkt, + out headers_t hdr, + inout metadata_t meta, + inout standard_metadata_t stdmeta) +{ + state start { + pkt.extract(hdr.ethernet); + transition accept; + } +} + +control verifyChecksum( + inout headers_t hdr, + inout metadata_t meta) +{ + apply { } +} + +action foo1() { +} + +@name("foo2") +action bar() { +} + +control ingressImpl( + inout headers_t hdr, + inout metadata_t meta, + inout standard_metadata_t stdmeta) + +{ + bit<8> tmp1; + bit<8> tmp2; + + // Action a1's control plane name should conflict with the name of + // top-level action foo1, and cause a compile-time error message, + // if you enable P4Info file generation. + @name(".foo1") action a1 (bit<8> x, bit<8> y) { tmp1 = x; tmp2 = y; } + + // Action a2's control plane name should conflict with the control + // plane name of top-level action bar, and cause a compile-time + // error message, if you enable P4Info file generation. + @name(".foo2") action a2 (bit<8> x, bit<8> y) { tmp1 = x; tmp2 = y; } + + table t1 { + actions = { NoAction; a1; a2; foo1; bar; } + key = { hdr.ethernet.etherType: exact; } + default_action = NoAction(); + size = 512; + } + apply { + tmp1 = hdr.ethernet.srcAddr[7:0]; + tmp2 = hdr.ethernet.dstAddr[7:0]; + t1.apply(); + // This is here simply to ensure that the compiler cannot + // optimize away the effects of t1 and t2, which can only + // assign values to variables tmp1 and tmp2. + hdr.ethernet.etherType = (bit<16>) (tmp1 - tmp2); + } +} + +control egressImpl( + inout headers_t hdr, + inout metadata_t meta, + inout standard_metadata_t stdmeta) +{ + apply { } +} + +control updateChecksum( + inout headers_t hdr, + inout metadata_t meta) +{ + apply { } +} + +control deparserImpl( + packet_out pkt, + in headers_t hdr) +{ + apply { + pkt.emit(hdr.ethernet); + } +} + +V1Switch(parserImpl(), + verifyChecksum(), + ingressImpl(), + egressImpl(), + updateChecksum(), + deparserImpl()) main; diff --git a/testdata/p4_16_errors/issue1949-bmv2.p4 b/testdata/p4_16_errors/issue1949-bmv2.p4 new file mode 100644 index 00000000000..5eb22a115a7 --- /dev/null +++ b/testdata/p4_16_errors/issue1949-bmv2.p4 @@ -0,0 +1,84 @@ +/* +Copyright 2019 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include +#include + +header h1_t { + bit<8> f1; + bit<8> f2; +} + +struct headers_t { + h1_t h1; +} + +struct metadata_t { +} + +parser parserImpl(packet_in packet, + out headers_t hdr, + inout metadata_t meta, + inout standard_metadata_t stdmeta) +{ + state start { + packet.extract(hdr.h1); + transition accept; + } +} + +control ingressImpl(inout headers_t hdr, + inout metadata_t meta, + inout standard_metadata_t stdmeta) +{ + @name(".foo") action act1() { + hdr.h1.f1 = hdr.h1.f1 >> 2; + } + @name(".foo") action act2() { + hdr.h1.f1 = hdr.h1.f1 << 3; + } + table t1 { + key = { hdr.h1.f1 : exact; } + actions = { act1; act2; NoAction; } + const default_action = NoAction; + } + apply { + t1.apply(); + } +} + +control verifyChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +control egressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + apply { + } +} + +control updateChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +control deparserImpl(packet_out packet, in headers_t hdr) { + apply { + } +} + +V1Switch(parserImpl(), verifyChecksum(), ingressImpl(), egressImpl(), updateChecksum(), deparserImpl()) main; + diff --git a/testdata/p4_16_errors/multicast-bmv2.p4 b/testdata/p4_16_errors/multicast-bmv2.p4 new file mode 100644 index 00000000000..808fefc0c3d --- /dev/null +++ b/testdata/p4_16_errors/multicast-bmv2.p4 @@ -0,0 +1,152 @@ +#include +#include + +struct routing_metadata_t { + bit<32> nhop_ipv4; +} + +header ethernet_t { + bit<48> dstAddr; + bit<48> srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + bit<32> srcAddr; + bit<32> dstAddr; +} + +struct metadata { + @name("routing_metadata") + routing_metadata_t routing_metadata; +} + +struct headers { + @name("ethernet") + ethernet_t ethernet; + @name("ipv4") + ipv4_t ipv4; +} + +parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name("parse_ethernet") state parse_ethernet { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + @name("parse_ipv4") state parse_ipv4 { + packet.extract(hdr.ipv4); + transition accept; + } + @name("start") state start { + transition parse_ethernet; + } +} + +control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".rewrite_mac") action rewrite_mac(bit<48> smac) { + hdr.ethernet.srcAddr = smac; + } + @name("._drop") action _drop() { + mark_to_drop(standard_metadata); + } + @name("send_frame") table send_frame { + actions = { + rewrite_mac; + _drop; + } + key = { + standard_metadata.egress_port: exact; + } + size = 256; + } + apply { + send_frame.apply(); + } +} + +control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".bcast") action bcast() { + standard_metadata.mcast_grp = 1; + } + @name(".set_dmac") action set_dmac(bit<48> dmac) { + hdr.ethernet.dstAddr = dmac; + } + @name("._drop") action _drop() { + mark_to_drop(standard_metadata); + } + @name(".set_nhop") action set_nhop(bit<32> nhop_ipv4, bit<9> port) { + meta.routing_metadata.nhop_ipv4 = nhop_ipv4; + standard_metadata.egress_spec = port; + hdr.ipv4.ttl = hdr.ipv4.ttl + 8w255; + } + @name(".set_nhop_redirect") action set_nhop_redirect(bit<32> nhop_ipv4, bit<9> port) { + meta.routing_metadata.nhop_ipv4 = nhop_ipv4; + standard_metadata.egress_spec = port; + hdr.ipv4.ttl = hdr.ipv4.ttl + 8w255; + } + @name("broadcast") table broadcast { + actions = { + bcast; + } + size = 1; + } + @name("forward") table forward { + actions = { + set_dmac; + _drop; + } + key = { + meta.routing_metadata.nhop_ipv4: exact; + } + size = 512; + } + @name("ipv4_lpm") table ipv4_lpm { + actions = { + set_nhop; + _drop; + } + key = { + hdr.ipv4.dstAddr: lpm; + } + size = 1024; + } + apply { + if (hdr.ipv4.isValid()) { + ipv4_lpm.apply(); + forward.apply(); + } + else { + broadcast.apply(); + } + } +} + +control DeparserImpl(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control verifyChecksum(inout headers hdr, inout metadata meta) { + apply { } +} + +control computeChecksum(inout headers hdr, inout metadata meta) { + apply { } +} + +V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main; diff --git a/testdata/p4_16_errors_outputs/actions-with-duplicate-control-plane-names1-first.p4 b/testdata/p4_16_errors_outputs/actions-with-duplicate-control-plane-names1-first.p4 new file mode 100644 index 00000000000..483e7b604f8 --- /dev/null +++ b/testdata/p4_16_errors_outputs/actions-with-duplicate-control-plane-names1-first.p4 @@ -0,0 +1,84 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +typedef bit<48> EthernetAddress; +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +struct headers_t { + ethernet_t ethernet; +} + +struct metadata_t { +} + +parser parserImpl(packet_in pkt, out headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + state start { + pkt.extract(hdr.ethernet); + transition accept; + } +} + +control verifyChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +action foo1() { +} +@name("foo2") action bar() { +} +control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + bit<8> tmp1; + bit<8> tmp2; + @name(".foo1") action a1(bit<8> x, bit<8> y) { + tmp1 = x; + tmp2 = y; + } + @name(".foo2") action a2(bit<8> x, bit<8> y) { + tmp1 = x; + tmp2 = y; + } + table t1 { + actions = { + NoAction(); + a1(); + a2(); + foo1(); + bar(); + } + key = { + hdr.ethernet.etherType: exact @name("hdr.ethernet.etherType"); + } + default_action = NoAction(); + size = 512; + } + apply { + tmp1 = hdr.ethernet.srcAddr[7:0]; + tmp2 = hdr.ethernet.dstAddr[7:0]; + t1.apply(); + hdr.ethernet.etherType = (bit<16>)(tmp1 - tmp2); + } +} + +control egressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + apply { + } +} + +control updateChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +control deparserImpl(packet_out pkt, in headers_t hdr) { + apply { + pkt.emit(hdr.ethernet); + } +} + +V1Switch(parserImpl(), verifyChecksum(), ingressImpl(), egressImpl(), updateChecksum(), deparserImpl()) main; diff --git a/testdata/p4_16_errors_outputs/actions-with-duplicate-control-plane-names1.p4 b/testdata/p4_16_errors_outputs/actions-with-duplicate-control-plane-names1.p4 new file mode 100644 index 00000000000..31e4f5d82f8 --- /dev/null +++ b/testdata/p4_16_errors_outputs/actions-with-duplicate-control-plane-names1.p4 @@ -0,0 +1,84 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +typedef bit<48> EthernetAddress; +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +struct headers_t { + ethernet_t ethernet; +} + +struct metadata_t { +} + +parser parserImpl(packet_in pkt, out headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + state start { + pkt.extract(hdr.ethernet); + transition accept; + } +} + +control verifyChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +action foo1() { +} +@name("foo2") action bar() { +} +control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + bit<8> tmp1; + bit<8> tmp2; + @name(".foo1") action a1(bit<8> x, bit<8> y) { + tmp1 = x; + tmp2 = y; + } + @name(".foo2") action a2(bit<8> x, bit<8> y) { + tmp1 = x; + tmp2 = y; + } + table t1 { + actions = { + NoAction; + a1; + a2; + foo1; + bar; + } + key = { + hdr.ethernet.etherType: exact; + } + default_action = NoAction(); + size = 512; + } + apply { + tmp1 = hdr.ethernet.srcAddr[7:0]; + tmp2 = hdr.ethernet.dstAddr[7:0]; + t1.apply(); + hdr.ethernet.etherType = (bit<16>)(tmp1 - tmp2); + } +} + +control egressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + apply { + } +} + +control updateChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +control deparserImpl(packet_out pkt, in headers_t hdr) { + apply { + pkt.emit(hdr.ethernet); + } +} + +V1Switch(parserImpl(), verifyChecksum(), ingressImpl(), egressImpl(), updateChecksum(), deparserImpl()) main; diff --git a/testdata/p4_16_errors_outputs/actions-with-duplicate-control-plane-names1.p4-stderr b/testdata/p4_16_errors_outputs/actions-with-duplicate-control-plane-names1.p4-stderr new file mode 100644 index 00000000000..29506558ce9 --- /dev/null +++ b/testdata/p4_16_errors_outputs/actions-with-duplicate-control-plane-names1.p4-stderr @@ -0,0 +1,6 @@ +actions-with-duplicate-control-plane-names1.p4(77): [--Werror=duplicate] error: .foo1: conflicting control plane name: foo1 + @name(".foo1") action a1 (bit<8> x, bit<8> y) { tmp1 = x; tmp2 = y; } + ^^ +actions-with-duplicate-control-plane-names1.p4(58) +action foo1() { + ^^^^ diff --git a/testdata/p4_16_errors_outputs/issue1949-bmv2-first.p4 b/testdata/p4_16_errors_outputs/issue1949-bmv2-first.p4 new file mode 100644 index 00000000000..01dee47f960 --- /dev/null +++ b/testdata/p4_16_errors_outputs/issue1949-bmv2-first.p4 @@ -0,0 +1,67 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +header h1_t { + bit<8> f1; + bit<8> f2; +} + +struct headers_t { + h1_t h1; +} + +struct metadata_t { +} + +parser parserImpl(packet_in packet, out headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + state start { + packet.extract(hdr.h1); + transition accept; + } +} + +control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + @name(".foo") action act1() { + hdr.h1.f1 = hdr.h1.f1 >> 2; + } + @name(".foo") action act2() { + hdr.h1.f1 = hdr.h1.f1 << 3; + } + table t1 { + key = { + hdr.h1.f1: exact @name("hdr.h1.f1"); + } + actions = { + act1(); + act2(); + NoAction(); + } + const default_action = NoAction(); + } + apply { + t1.apply(); + } +} + +control verifyChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +control egressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + apply { + } +} + +control updateChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +control deparserImpl(packet_out packet, in headers_t hdr) { + apply { + } +} + +V1Switch(parserImpl(), verifyChecksum(), ingressImpl(), egressImpl(), updateChecksum(), deparserImpl()) main; diff --git a/testdata/p4_16_errors_outputs/issue1949-bmv2.p4 b/testdata/p4_16_errors_outputs/issue1949-bmv2.p4 new file mode 100644 index 00000000000..3255df59142 --- /dev/null +++ b/testdata/p4_16_errors_outputs/issue1949-bmv2.p4 @@ -0,0 +1,67 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +header h1_t { + bit<8> f1; + bit<8> f2; +} + +struct headers_t { + h1_t h1; +} + +struct metadata_t { +} + +parser parserImpl(packet_in packet, out headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + state start { + packet.extract(hdr.h1); + transition accept; + } +} + +control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + @name(".foo") action act1() { + hdr.h1.f1 = hdr.h1.f1 >> 2; + } + @name(".foo") action act2() { + hdr.h1.f1 = hdr.h1.f1 << 3; + } + table t1 { + key = { + hdr.h1.f1: exact; + } + actions = { + act1; + act2; + NoAction; + } + const default_action = NoAction; + } + apply { + t1.apply(); + } +} + +control verifyChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +control egressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + apply { + } +} + +control updateChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +control deparserImpl(packet_out packet, in headers_t hdr) { + apply { + } +} + +V1Switch(parserImpl(), verifyChecksum(), ingressImpl(), egressImpl(), updateChecksum(), deparserImpl()) main; diff --git a/testdata/p4_16_errors_outputs/issue1949-bmv2.p4-stderr b/testdata/p4_16_errors_outputs/issue1949-bmv2.p4-stderr new file mode 100644 index 00000000000..f0f3a46d7fb --- /dev/null +++ b/testdata/p4_16_errors_outputs/issue1949-bmv2.p4-stderr @@ -0,0 +1,6 @@ +issue1949-bmv2.p4(50): [--Werror=duplicate] error: .foo: conflicting control plane name: .foo + @name(".foo") action act2() { + ^^^^ +issue1949-bmv2.p4(47) + @name(".foo") action act1() { + ^^^^ diff --git a/testdata/p4_16_errors_outputs/multicast-bmv2-first.p4 b/testdata/p4_16_errors_outputs/multicast-bmv2-first.p4 new file mode 100644 index 00000000000..44fb930e118 --- /dev/null +++ b/testdata/p4_16_errors_outputs/multicast-bmv2-first.p4 @@ -0,0 +1,162 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +struct routing_metadata_t { + bit<32> nhop_ipv4; +} + +header ethernet_t { + bit<48> dstAddr; + bit<48> srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + bit<32> srcAddr; + bit<32> dstAddr; +} + +struct metadata { + @name("routing_metadata") + routing_metadata_t routing_metadata; +} + +struct headers { + @name("ethernet") + ethernet_t ethernet; + @name("ipv4") + ipv4_t ipv4; +} + +parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name("parse_ethernet") state parse_ethernet { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + @name("parse_ipv4") state parse_ipv4 { + packet.extract(hdr.ipv4); + transition accept; + } + @name("start") state start { + transition parse_ethernet; + } +} + +control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".rewrite_mac") action rewrite_mac(bit<48> smac) { + hdr.ethernet.srcAddr = smac; + } + @name("._drop") action _drop() { + mark_to_drop(standard_metadata); + } + @name("send_frame") table send_frame { + actions = { + rewrite_mac(); + _drop(); + @defaultonly NoAction(); + } + key = { + standard_metadata.egress_port: exact @name("standard_metadata.egress_port"); + } + size = 256; + default_action = NoAction(); + } + apply { + send_frame.apply(); + } +} + +control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".bcast") action bcast() { + standard_metadata.mcast_grp = 16w1; + } + @name(".set_dmac") action set_dmac(bit<48> dmac) { + hdr.ethernet.dstAddr = dmac; + } + @name("._drop") action _drop() { + mark_to_drop(standard_metadata); + } + @name(".set_nhop") action set_nhop(bit<32> nhop_ipv4, bit<9> port) { + meta.routing_metadata.nhop_ipv4 = nhop_ipv4; + standard_metadata.egress_spec = port; + hdr.ipv4.ttl = hdr.ipv4.ttl + 8w255; + } + @name(".set_nhop_redirect") action set_nhop_redirect(bit<32> nhop_ipv4, bit<9> port) { + meta.routing_metadata.nhop_ipv4 = nhop_ipv4; + standard_metadata.egress_spec = port; + hdr.ipv4.ttl = hdr.ipv4.ttl + 8w255; + } + @name("broadcast") table broadcast { + actions = { + bcast(); + @defaultonly NoAction(); + } + size = 1; + default_action = NoAction(); + } + @name("forward") table forward { + actions = { + set_dmac(); + _drop(); + @defaultonly NoAction(); + } + key = { + meta.routing_metadata.nhop_ipv4: exact @name("meta.routing_metadata.nhop_ipv4"); + } + size = 512; + default_action = NoAction(); + } + @name("ipv4_lpm") table ipv4_lpm { + actions = { + set_nhop(); + _drop(); + @defaultonly NoAction(); + } + key = { + hdr.ipv4.dstAddr: lpm @name("hdr.ipv4.dstAddr"); + } + size = 1024; + default_action = NoAction(); + } + apply { + if (hdr.ipv4.isValid()) { + ipv4_lpm.apply(); + forward.apply(); + } else { + broadcast.apply(); + } + } +} + +control DeparserImpl(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control verifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control computeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main; diff --git a/testdata/p4_16_errors_outputs/multicast-bmv2.p4 b/testdata/p4_16_errors_outputs/multicast-bmv2.p4 new file mode 100644 index 00000000000..fdf4220703c --- /dev/null +++ b/testdata/p4_16_errors_outputs/multicast-bmv2.p4 @@ -0,0 +1,154 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +struct routing_metadata_t { + bit<32> nhop_ipv4; +} + +header ethernet_t { + bit<48> dstAddr; + bit<48> srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + bit<32> srcAddr; + bit<32> dstAddr; +} + +struct metadata { + @name("routing_metadata") + routing_metadata_t routing_metadata; +} + +struct headers { + @name("ethernet") + ethernet_t ethernet; + @name("ipv4") + ipv4_t ipv4; +} + +parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name("parse_ethernet") state parse_ethernet { + packet.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 16w0x800: parse_ipv4; + default: accept; + } + } + @name("parse_ipv4") state parse_ipv4 { + packet.extract(hdr.ipv4); + transition accept; + } + @name("start") state start { + transition parse_ethernet; + } +} + +control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".rewrite_mac") action rewrite_mac(bit<48> smac) { + hdr.ethernet.srcAddr = smac; + } + @name("._drop") action _drop() { + mark_to_drop(standard_metadata); + } + @name("send_frame") table send_frame { + actions = { + rewrite_mac; + _drop; + } + key = { + standard_metadata.egress_port: exact; + } + size = 256; + } + apply { + send_frame.apply(); + } +} + +control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".bcast") action bcast() { + standard_metadata.mcast_grp = 1; + } + @name(".set_dmac") action set_dmac(bit<48> dmac) { + hdr.ethernet.dstAddr = dmac; + } + @name("._drop") action _drop() { + mark_to_drop(standard_metadata); + } + @name(".set_nhop") action set_nhop(bit<32> nhop_ipv4, bit<9> port) { + meta.routing_metadata.nhop_ipv4 = nhop_ipv4; + standard_metadata.egress_spec = port; + hdr.ipv4.ttl = hdr.ipv4.ttl + 8w255; + } + @name(".set_nhop_redirect") action set_nhop_redirect(bit<32> nhop_ipv4, bit<9> port) { + meta.routing_metadata.nhop_ipv4 = nhop_ipv4; + standard_metadata.egress_spec = port; + hdr.ipv4.ttl = hdr.ipv4.ttl + 8w255; + } + @name("broadcast") table broadcast { + actions = { + bcast; + } + size = 1; + } + @name("forward") table forward { + actions = { + set_dmac; + _drop; + } + key = { + meta.routing_metadata.nhop_ipv4: exact; + } + size = 512; + } + @name("ipv4_lpm") table ipv4_lpm { + actions = { + set_nhop; + _drop; + } + key = { + hdr.ipv4.dstAddr: lpm; + } + size = 1024; + } + apply { + if (hdr.ipv4.isValid()) { + ipv4_lpm.apply(); + forward.apply(); + } else { + broadcast.apply(); + } + } +} + +control DeparserImpl(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + packet.emit(hdr.ipv4); + } +} + +control verifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control computeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main; diff --git a/testdata/p4_16_errors_outputs/multicast-bmv2.p4-stderr b/testdata/p4_16_errors_outputs/multicast-bmv2.p4-stderr new file mode 100644 index 00000000000..835e09d908e --- /dev/null +++ b/testdata/p4_16_errors_outputs/multicast-bmv2.p4-stderr @@ -0,0 +1,6 @@ +multicast-bmv2.p4(87): [--Werror=duplicate] error: ._drop: conflicting control plane name: ._drop + @name("._drop") action _drop() { + ^^^^^ +multicast-bmv2.p4(62) + @name("._drop") action _drop() { + ^^^^^ diff --git a/testdata/p4_16_samples/actions-almost-duplicate-names1.p4 b/testdata/p4_16_samples/actions-almost-duplicate-names1.p4 new file mode 100644 index 00000000000..15084de9388 --- /dev/null +++ b/testdata/p4_16_samples/actions-almost-duplicate-names1.p4 @@ -0,0 +1,152 @@ +/* +Copyright 2024 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include +#include + +typedef bit<48> EthernetAddress; + +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +struct headers_t { + ethernet_t ethernet; +} + +struct metadata_t { +} + +parser parserImpl( + packet_in pkt, + out headers_t hdr, + inout metadata_t meta, + inout standard_metadata_t stdmeta) +{ + state start { + pkt.extract(hdr.ethernet); + transition accept; + } +} + +control verifyChecksum( + inout headers_t hdr, + inout metadata_t meta) +{ + apply { } +} + +action foo1() { +} + +@name("foo2") +action foo2() { +} + +@name(".baz") +action foo3() { +} + +control ingressImpl( + inout headers_t hdr, + inout metadata_t meta, + inout standard_metadata_t stdmeta) +{ + bit<8> tmp1; + bit<8> tmp2; + + // This is not a name conflict with foo1, because it has a top + // level name ".foo1", but a1 will have hierarchical name + // "ingressImpl.foo1". + @name("foo1") action a1 (bit<8> x, bit<8> y) { tmp1 = x >> 1; tmp2 = y; } + + // This should not be a name conflict with foo2, because it has a + // top level name ".foo2", but a2 will have hierarchical name + // "ingressImpl.foo2". + // TODO: However, it is a @name conflict in the current p4c + // implementation until a PR like #4970 is merged in. + //@name("foo2") action a2 (bit<8> x, bit<8> y) { tmp1 = x >> 2; tmp2 = y; } + + @name(".bar") action a3 (bit<8> x, bit<8> y) { tmp1 = x >> 3; tmp2 = y; } + // This is not a name conflict with a3, because it has a top level + // name ".bar", but a4 will have hierarchical name + // "ingressImpl.bar". + @name("bar") action a4 (bit<8> x, bit<8> y) { tmp1 = x >> 4; tmp2 = y; } + + // This is not a name conflict with foo3, because it has a top + // level name ".baz", but a5 will have hierarchical name + // "ingressImpl.baz". + @name("baz") action a5 (bit<8> x, bit<8> y) { tmp1 = x >> 5; tmp2 = y; } + + table t1 { + actions = { + NoAction; + a1; + //a2; + a3; + a4; + a5; + foo1; + foo2; + foo3; + } + key = { hdr.ethernet.etherType: exact; } + default_action = NoAction(); + size = 512; + } + apply { + tmp1 = hdr.ethernet.srcAddr[7:0]; + tmp2 = hdr.ethernet.dstAddr[7:0]; + t1.apply(); + // This is here simply to ensure that the compiler cannot + // optimize away the effects of t1 and t2, which can only + // assign values to variables tmp1 and tmp2. + hdr.ethernet.etherType = (bit<16>) (tmp1 - tmp2); + } +} + +control egressImpl( + inout headers_t hdr, + inout metadata_t meta, + inout standard_metadata_t stdmeta) +{ + apply { } +} + +control updateChecksum( + inout headers_t hdr, + inout metadata_t meta) +{ + apply { } +} + +control deparserImpl( + packet_out pkt, + in headers_t hdr) +{ + apply { + pkt.emit(hdr.ethernet); + } +} + +V1Switch(parserImpl(), + verifyChecksum(), + ingressImpl(), + egressImpl(), + updateChecksum(), + deparserImpl()) main; diff --git a/testdata/p4_16_samples/multicast-bmv2.p4 b/testdata/p4_16_samples/multicast-bmv2.p4 index 808fefc0c3d..b912801932a 100644 --- a/testdata/p4_16_samples/multicast-bmv2.p4 +++ b/testdata/p4_16_samples/multicast-bmv2.p4 @@ -59,7 +59,7 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t @name(".rewrite_mac") action rewrite_mac(bit<48> smac) { hdr.ethernet.srcAddr = smac; } - @name("._drop") action _drop() { + @name("_drop") action _drop() { mark_to_drop(standard_metadata); } @name("send_frame") table send_frame { @@ -84,7 +84,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ @name(".set_dmac") action set_dmac(bit<48> dmac) { hdr.ethernet.dstAddr = dmac; } - @name("._drop") action _drop() { + @name("_drop") action _drop() { mark_to_drop(standard_metadata); } @name(".set_nhop") action set_nhop(bit<32> nhop_ipv4, bit<9> port) { diff --git a/testdata/p4_16_samples/name_annotations_to_p4info-bmv2.p4 b/testdata/p4_16_samples/name_annotations_to_p4info-bmv2.p4 new file mode 100644 index 00000000000..bb1f7627cc0 --- /dev/null +++ b/testdata/p4_16_samples/name_annotations_to_p4info-bmv2.p4 @@ -0,0 +1,69 @@ +/* +Copyright 2021 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 + +struct H { }; +struct M { + bit<32> hash1; +} + +parser ParserI(packet_in pk, out H hdr, inout M meta, inout standard_metadata_t smeta) { + state start { transition accept; } +} + +@name("altIngressName") +control IngressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) { + @name("blue") + action foo(@name("orange") bit<9> port) { + smeta.egress_spec = port; + } + + @name("red") + table foo_table { + key = { + smeta.ingress_port : exact @name("green"); + } + actions = { + @name("yellow") foo; + @name("grey") NoAction; + } + const default_action = NoAction(); + } + apply { + foo_table.apply(); + } +}; + +control EgressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) { + apply { } +}; + +control DeparserI(packet_out pk, in H hdr) { + apply { } +} + +control VerifyChecksumI(inout H hdr, inout M meta) { + apply { } +} + +control ComputeChecksumI(inout H hdr, inout M meta) { + apply { } +} + +V1Switch(ParserI(), VerifyChecksumI(), IngressI(), EgressI(), + ComputeChecksumI(), DeparserI()) main; diff --git a/testdata/p4_16_samples/named_meter_1-bmv2.p4 b/testdata/p4_16_samples/named_meter_1-bmv2.p4 index 80c156d848e..1e2f85fe56f 100644 --- a/testdata/p4_16_samples/named_meter_1-bmv2.p4 +++ b/testdata/p4_16_samples/named_meter_1-bmv2.p4 @@ -76,11 +76,11 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ size = 16; default_action = NoAction(); } - @name("m_action") action m_action_0(bit<9> meter_idx) { + @name("m_action_2") action m_action_0(bit<9> meter_idx) { standard_metadata.egress_spec = meter_idx; my_meter.read(meta.meta.meter_tag); } - @name("_nop") action _nop_0() { + @name("_nop_2") action _nop_0() { my_meter.read(meta.meta.meter_tag); } @name("m_table") table m_table { diff --git a/testdata/p4_16_samples/named_meter_bmv2.p4 b/testdata/p4_16_samples/named_meter_bmv2.p4 index f420c6efeeb..1f0ecf84210 100644 --- a/testdata/p4_16_samples/named_meter_bmv2.p4 +++ b/testdata/p4_16_samples/named_meter_bmv2.p4 @@ -75,12 +75,12 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ size = 16; default_action = NoAction(); } - @name("m_action") action m_action_0(bit<9> meter_idx) { + @name("m_action_2") action m_action_0(bit<9> meter_idx) { standard_metadata.egress_spec = meter_idx; standard_metadata.egress_spec = 9w1; my_meter.read(meta.meta.meter_tag); } - @name("_nop") action _nop_0() { + @name("_nop_2") action _nop_0() { my_meter.read(meta.meta.meter_tag); } @name("m_table") table m_table { diff --git a/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1-first.p4 b/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1-first.p4 new file mode 100644 index 00000000000..d606f50225e --- /dev/null +++ b/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1-first.p4 @@ -0,0 +1,97 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +typedef bit<48> EthernetAddress; +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +struct headers_t { + ethernet_t ethernet; +} + +struct metadata_t { +} + +parser parserImpl(packet_in pkt, out headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + state start { + pkt.extract(hdr.ethernet); + transition accept; + } +} + +control verifyChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +action foo1() { +} +@name("foo2") action foo2() { +} +@name(".baz") action foo3() { +} +control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + bit<8> tmp1; + bit<8> tmp2; + @name("foo1") action a1(bit<8> x, bit<8> y) { + tmp1 = x >> 1; + tmp2 = y; + } + @name(".bar") action a3(bit<8> x, bit<8> y) { + tmp1 = x >> 3; + tmp2 = y; + } + @name("bar") action a4(bit<8> x, bit<8> y) { + tmp1 = x >> 4; + tmp2 = y; + } + @name("baz") action a5(bit<8> x, bit<8> y) { + tmp1 = x >> 5; + tmp2 = y; + } + table t1 { + actions = { + NoAction(); + a1(); + a3(); + a4(); + a5(); + foo1(); + foo2(); + foo3(); + } + key = { + hdr.ethernet.etherType: exact @name("hdr.ethernet.etherType"); + } + default_action = NoAction(); + size = 512; + } + apply { + tmp1 = hdr.ethernet.srcAddr[7:0]; + tmp2 = hdr.ethernet.dstAddr[7:0]; + t1.apply(); + hdr.ethernet.etherType = (bit<16>)(tmp1 - tmp2); + } +} + +control egressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + apply { + } +} + +control updateChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +control deparserImpl(packet_out pkt, in headers_t hdr) { + apply { + pkt.emit(hdr.ethernet); + } +} + +V1Switch(parserImpl(), verifyChecksum(), ingressImpl(), egressImpl(), updateChecksum(), deparserImpl()) main; diff --git a/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1-frontend.p4 b/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1-frontend.p4 new file mode 100644 index 00000000000..71981918730 --- /dev/null +++ b/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1-frontend.p4 @@ -0,0 +1,99 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +typedef bit<48> EthernetAddress; +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +struct headers_t { + ethernet_t ethernet; +} + +struct metadata_t { +} + +parser parserImpl(packet_in pkt, out headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + state start { + pkt.extract(hdr.ethernet); + transition accept; + } +} + +control verifyChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + @name("ingressImpl.tmp1") bit<8> tmp1_0; + @name("ingressImpl.tmp2") bit<8> tmp2_0; + @noWarn("unused") @name(".NoAction") action NoAction_1() { + } + @name(".foo1") action foo1_0() { + } + @name("ingressImpl.foo2") action foo2_0() { + } + @name(".baz") action foo3_0() { + } + @name("ingressImpl.foo1") action a1(@name("x") bit<8> x, @name("y") bit<8> y) { + tmp1_0 = x >> 1; + tmp2_0 = y; + } + @name(".bar") action a3(@name("x") bit<8> x_4, @name("y") bit<8> y_4) { + tmp1_0 = x_4 >> 3; + tmp2_0 = y_4; + } + @name("ingressImpl.bar") action a4(@name("x") bit<8> x_5, @name("y") bit<8> y_5) { + tmp1_0 = x_5 >> 4; + tmp2_0 = y_5; + } + @name("ingressImpl.baz") action a5(@name("x") bit<8> x_6, @name("y") bit<8> y_6) { + tmp1_0 = x_6 >> 5; + tmp2_0 = y_6; + } + @name("ingressImpl.t1") table t1_0 { + actions = { + NoAction_1(); + a1(); + a3(); + a4(); + a5(); + foo1_0(); + foo2_0(); + foo3_0(); + } + key = { + hdr.ethernet.etherType: exact @name("hdr.ethernet.etherType"); + } + default_action = NoAction_1(); + size = 512; + } + apply { + tmp1_0 = hdr.ethernet.srcAddr[7:0]; + tmp2_0 = hdr.ethernet.dstAddr[7:0]; + t1_0.apply(); + hdr.ethernet.etherType = (bit<16>)(tmp1_0 - tmp2_0); + } +} + +control egressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + apply { + } +} + +control updateChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +control deparserImpl(packet_out pkt, in headers_t hdr) { + apply { + pkt.emit(hdr.ethernet); + } +} + +V1Switch(parserImpl(), verifyChecksum(), ingressImpl(), egressImpl(), updateChecksum(), deparserImpl()) main; diff --git a/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1-midend.p4 b/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1-midend.p4 new file mode 100644 index 00000000000..d1cca333c64 --- /dev/null +++ b/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1-midend.p4 @@ -0,0 +1,116 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +header ethernet_t { + bit<48> dstAddr; + bit<48> srcAddr; + bit<16> etherType; +} + +struct headers_t { + ethernet_t ethernet; +} + +struct metadata_t { +} + +parser parserImpl(packet_in pkt, out headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + state start { + pkt.extract(hdr.ethernet); + transition accept; + } +} + +control verifyChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + @name("ingressImpl.tmp1") bit<8> tmp1_0; + @name("ingressImpl.tmp2") bit<8> tmp2_0; + @noWarn("unused") @name(".NoAction") action NoAction_1() { + } + @name(".foo1") action foo1_0() { + } + @name("ingressImpl.foo2") action foo2_0() { + } + @name(".baz") action foo3_0() { + } + @name("ingressImpl.foo1") action a1(@name("x") bit<8> x, @name("y") bit<8> y) { + tmp1_0 = x >> 1; + tmp2_0 = y; + } + @name(".bar") action a3(@name("x") bit<8> x_4, @name("y") bit<8> y_4) { + tmp1_0 = x_4 >> 3; + tmp2_0 = y_4; + } + @name("ingressImpl.bar") action a4(@name("x") bit<8> x_5, @name("y") bit<8> y_5) { + tmp1_0 = x_5 >> 4; + tmp2_0 = y_5; + } + @name("ingressImpl.baz") action a5(@name("x") bit<8> x_6, @name("y") bit<8> y_6) { + tmp1_0 = x_6 >> 5; + tmp2_0 = y_6; + } + @name("ingressImpl.t1") table t1_0 { + actions = { + NoAction_1(); + a1(); + a3(); + a4(); + a5(); + foo1_0(); + foo2_0(); + foo3_0(); + } + key = { + hdr.ethernet.etherType: exact @name("hdr.ethernet.etherType"); + } + default_action = NoAction_1(); + size = 512; + } + @hidden action actionsalmostduplicatenames1l113() { + tmp1_0 = hdr.ethernet.srcAddr[7:0]; + tmp2_0 = hdr.ethernet.dstAddr[7:0]; + } + @hidden action actionsalmostduplicatenames1l119() { + hdr.ethernet.etherType = (bit<16>)(tmp1_0 - tmp2_0); + } + @hidden table tbl_actionsalmostduplicatenames1l113 { + actions = { + actionsalmostduplicatenames1l113(); + } + const default_action = actionsalmostduplicatenames1l113(); + } + @hidden table tbl_actionsalmostduplicatenames1l119 { + actions = { + actionsalmostduplicatenames1l119(); + } + const default_action = actionsalmostduplicatenames1l119(); + } + apply { + tbl_actionsalmostduplicatenames1l113.apply(); + t1_0.apply(); + tbl_actionsalmostduplicatenames1l119.apply(); + } +} + +control egressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + apply { + } +} + +control updateChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +control deparserImpl(packet_out pkt, in headers_t hdr) { + apply { + pkt.emit(hdr.ethernet); + } +} + +V1Switch(parserImpl(), verifyChecksum(), ingressImpl(), egressImpl(), updateChecksum(), deparserImpl()) main; diff --git a/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1.p4 b/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1.p4 new file mode 100644 index 00000000000..a85e79f001b --- /dev/null +++ b/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1.p4 @@ -0,0 +1,97 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +typedef bit<48> EthernetAddress; +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +struct headers_t { + ethernet_t ethernet; +} + +struct metadata_t { +} + +parser parserImpl(packet_in pkt, out headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + state start { + pkt.extract(hdr.ethernet); + transition accept; + } +} + +control verifyChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +action foo1() { +} +@name("foo2") action foo2() { +} +@name(".baz") action foo3() { +} +control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + bit<8> tmp1; + bit<8> tmp2; + @name("foo1") action a1(bit<8> x, bit<8> y) { + tmp1 = x >> 1; + tmp2 = y; + } + @name(".bar") action a3(bit<8> x, bit<8> y) { + tmp1 = x >> 3; + tmp2 = y; + } + @name("bar") action a4(bit<8> x, bit<8> y) { + tmp1 = x >> 4; + tmp2 = y; + } + @name("baz") action a5(bit<8> x, bit<8> y) { + tmp1 = x >> 5; + tmp2 = y; + } + table t1 { + actions = { + NoAction; + a1; + a3; + a4; + a5; + foo1; + foo2; + foo3; + } + key = { + hdr.ethernet.etherType: exact; + } + default_action = NoAction(); + size = 512; + } + apply { + tmp1 = hdr.ethernet.srcAddr[7:0]; + tmp2 = hdr.ethernet.dstAddr[7:0]; + t1.apply(); + hdr.ethernet.etherType = (bit<16>)(tmp1 - tmp2); + } +} + +control egressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) { + apply { + } +} + +control updateChecksum(inout headers_t hdr, inout metadata_t meta) { + apply { + } +} + +control deparserImpl(packet_out pkt, in headers_t hdr) { + apply { + pkt.emit(hdr.ethernet); + } +} + +V1Switch(parserImpl(), verifyChecksum(), ingressImpl(), egressImpl(), updateChecksum(), deparserImpl()) main; diff --git a/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1.p4-stderr b/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1.p4-stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1.p4.entries.txtpb b/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1.p4.entries.txtpb new file mode 100644 index 00000000000..5cb9652623a --- /dev/null +++ b/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1.p4.entries.txtpb @@ -0,0 +1,3 @@ +# proto-file: p4/v1/p4runtime.proto +# proto-message: p4.v1.WriteRequest + diff --git a/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1.p4.p4info.txtpb b/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1.p4.p4info.txtpb new file mode 100644 index 00000000000..76b13ff0639 --- /dev/null +++ b/testdata/p4_16_samples_outputs/actions-almost-duplicate-names1.p4.p4info.txtpb @@ -0,0 +1,146 @@ +# proto-file: p4/config/v1/p4info.proto +# proto-message: p4.config.v1.P4Info + +pkg_info { + arch: "v1model" +} +tables { + preamble { + id: 49173205 + name: "ingressImpl.t1" + alias: "t1" + } + match_fields { + id: 1 + name: "hdr.ethernet.etherType" + bitwidth: 16 + match_type: EXACT + } + action_refs { + id: 21257015 + } + action_refs { + id: 30176274 + } + action_refs { + id: 21008649 + } + action_refs { + id: 27458909 + } + action_refs { + id: 24058105 + } + action_refs { + id: 25646030 + } + action_refs { + id: 17174663 + } + action_refs { + id: 28708850 + } + initial_default_action { + action_id: 21257015 + } + size: 512 +} +actions { + preamble { + id: 21257015 + name: "NoAction" + alias: "NoAction" + annotations: "@noWarn(\"unused\")" + } +} +actions { + preamble { + id: 25646030 + name: "foo1" + alias: "foo1" + } +} +actions { + preamble { + id: 17174663 + name: "ingressImpl.foo2" + alias: "foo2" + } +} +actions { + preamble { + id: 28708850 + name: "baz" + alias: "baz" + } +} +actions { + preamble { + id: 30176274 + name: "ingressImpl.foo1" + alias: "ingressImpl.foo1" + } + params { + id: 1 + name: "x" + bitwidth: 8 + } + params { + id: 2 + name: "y" + bitwidth: 8 + } +} +actions { + preamble { + id: 21008649 + name: "bar" + alias: "bar" + } + params { + id: 1 + name: "x" + bitwidth: 8 + } + params { + id: 2 + name: "y" + bitwidth: 8 + } +} +actions { + preamble { + id: 27458909 + name: "ingressImpl.bar" + alias: "ingressImpl.bar" + } + params { + id: 1 + name: "x" + bitwidth: 8 + } + params { + id: 2 + name: "y" + bitwidth: 8 + } +} +actions { + preamble { + id: 24058105 + name: "ingressImpl.baz" + alias: "ingressImpl.baz" + } + params { + id: 1 + name: "x" + bitwidth: 8 + } + params { + id: 2 + name: "y" + bitwidth: 8 + } +} +type_info { +} diff --git a/testdata/p4_16_samples_outputs/multicast-bmv2-first.p4 b/testdata/p4_16_samples_outputs/multicast-bmv2-first.p4 index 44fb930e118..549f83c13a1 100644 --- a/testdata/p4_16_samples_outputs/multicast-bmv2-first.p4 +++ b/testdata/p4_16_samples_outputs/multicast-bmv2-first.p4 @@ -60,7 +60,7 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t @name(".rewrite_mac") action rewrite_mac(bit<48> smac) { hdr.ethernet.srcAddr = smac; } - @name("._drop") action _drop() { + @name("_drop") action _drop() { mark_to_drop(standard_metadata); } @name("send_frame") table send_frame { @@ -87,7 +87,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ @name(".set_dmac") action set_dmac(bit<48> dmac) { hdr.ethernet.dstAddr = dmac; } - @name("._drop") action _drop() { + @name("_drop") action _drop() { mark_to_drop(standard_metadata); } @name(".set_nhop") action set_nhop(bit<32> nhop_ipv4, bit<9> port) { diff --git a/testdata/p4_16_samples_outputs/multicast-bmv2-frontend.p4 b/testdata/p4_16_samples_outputs/multicast-bmv2-frontend.p4 index 95148afd70f..25a2fed91b6 100644 --- a/testdata/p4_16_samples_outputs/multicast-bmv2-frontend.p4 +++ b/testdata/p4_16_samples_outputs/multicast-bmv2-frontend.p4 @@ -62,7 +62,7 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t @name(".rewrite_mac") action rewrite_mac(@name("smac") bit<48> smac) { hdr.ethernet.srcAddr = smac; } - @name("._drop") action _drop() { + @name("egress._drop") action _drop() { mark_to_drop(standard_metadata); } @name("egress.send_frame") table send_frame_0 { @@ -95,10 +95,10 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ @name(".set_dmac") action set_dmac(@name("dmac") bit<48> dmac) { hdr.ethernet.dstAddr = dmac; } - @name("._drop") action _drop_2() { + @name("ingress._drop") action _drop_2() { mark_to_drop(standard_metadata); } - @name("._drop") action _drop_3() { + @name("ingress._drop") action _drop_3() { mark_to_drop(standard_metadata); } @name(".set_nhop") action set_nhop(@name("nhop_ipv4") bit<32> nhop_ipv4_1, @name("port") bit<9> port) { diff --git a/testdata/p4_16_samples_outputs/multicast-bmv2-midend.p4 b/testdata/p4_16_samples_outputs/multicast-bmv2-midend.p4 index 10afd1f4bb2..7845e575bc9 100644 --- a/testdata/p4_16_samples_outputs/multicast-bmv2-midend.p4 +++ b/testdata/p4_16_samples_outputs/multicast-bmv2-midend.p4 @@ -61,7 +61,7 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t @name(".rewrite_mac") action rewrite_mac(@name("smac") bit<48> smac) { hdr.ethernet.srcAddr = smac; } - @name("._drop") action _drop() { + @name("egress._drop") action _drop() { mark_to_drop(standard_metadata); } @name("egress.send_frame") table send_frame_0 { @@ -94,10 +94,10 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ @name(".set_dmac") action set_dmac(@name("dmac") bit<48> dmac) { hdr.ethernet.dstAddr = dmac; } - @name("._drop") action _drop_2() { + @name("ingress._drop") action _drop_2() { mark_to_drop(standard_metadata); } - @name("._drop") action _drop_3() { + @name("ingress._drop") action _drop_3() { mark_to_drop(standard_metadata); } @name(".set_nhop") action set_nhop(@name("nhop_ipv4") bit<32> nhop_ipv4_1, @name("port") bit<9> port) { diff --git a/testdata/p4_16_samples_outputs/multicast-bmv2.p4 b/testdata/p4_16_samples_outputs/multicast-bmv2.p4 index fdf4220703c..f608cc80b0f 100644 --- a/testdata/p4_16_samples_outputs/multicast-bmv2.p4 +++ b/testdata/p4_16_samples_outputs/multicast-bmv2.p4 @@ -60,7 +60,7 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t @name(".rewrite_mac") action rewrite_mac(bit<48> smac) { hdr.ethernet.srcAddr = smac; } - @name("._drop") action _drop() { + @name("_drop") action _drop() { mark_to_drop(standard_metadata); } @name("send_frame") table send_frame { @@ -85,7 +85,7 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ @name(".set_dmac") action set_dmac(bit<48> dmac) { hdr.ethernet.dstAddr = dmac; } - @name("._drop") action _drop() { + @name("_drop") action _drop() { mark_to_drop(standard_metadata); } @name(".set_nhop") action set_nhop(bit<32> nhop_ipv4, bit<9> port) { diff --git a/testdata/p4_16_samples_outputs/multicast-bmv2.p4.p4info.txtpb b/testdata/p4_16_samples_outputs/multicast-bmv2.p4.p4info.txtpb index eb21c0eabd8..c22ccb32dbb 100644 --- a/testdata/p4_16_samples_outputs/multicast-bmv2.p4.p4info.txtpb +++ b/testdata/p4_16_samples_outputs/multicast-bmv2.p4.p4info.txtpb @@ -39,7 +39,7 @@ tables { id: 25234447 } action_refs { - id: 19143480 + id: 19344232 } action_refs { id: 21257015 @@ -67,7 +67,7 @@ tables { id: 23300268 } action_refs { - id: 19143480 + id: 19344232 } action_refs { id: 21257015 @@ -95,7 +95,7 @@ tables { id: 31165400 } action_refs { - id: 19143480 + id: 25850727 } action_refs { id: 21257015 @@ -136,9 +136,9 @@ actions { } actions { preamble { - id: 19143480 - name: "_drop" - alias: "_drop" + id: 19344232 + name: "ingress._drop" + alias: "ingress._drop" } } actions { @@ -170,5 +170,12 @@ actions { bitwidth: 48 } } +actions { + preamble { + id: 25850727 + name: "egress._drop" + alias: "egress._drop" + } +} type_info { } diff --git a/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2-first.p4 b/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2-first.p4 new file mode 100644 index 00000000000..7e294ece67a --- /dev/null +++ b/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2-first.p4 @@ -0,0 +1,57 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +struct H { +} + +struct M { + bit<32> hash1; +} + +parser ParserI(packet_in pk, out H hdr, inout M meta, inout standard_metadata_t smeta) { + state start { + transition accept; + } +} + +@name("altIngressName") control IngressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) { + @name("blue") action foo(@name("orange") bit<9> port) { + smeta.egress_spec = port; + } + @name("red") table foo_table { + key = { + smeta.ingress_port: exact @name("green"); + } + actions = { + @name("yellow") foo(); + @name("grey") NoAction(); + } + const default_action = NoAction(); + } + apply { + foo_table.apply(); + } +} + +control EgressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) { + apply { + } +} + +control DeparserI(packet_out pk, in H hdr) { + apply { + } +} + +control VerifyChecksumI(inout H hdr, inout M meta) { + apply { + } +} + +control ComputeChecksumI(inout H hdr, inout M meta) { + apply { + } +} + +V1Switch(ParserI(), VerifyChecksumI(), IngressI(), EgressI(), ComputeChecksumI(), DeparserI()) main; diff --git a/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2-frontend.p4 b/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2-frontend.p4 new file mode 100644 index 00000000000..8b83caba873 --- /dev/null +++ b/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2-frontend.p4 @@ -0,0 +1,59 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +struct H { +} + +struct M { + bit<32> hash1; +} + +parser ParserI(packet_in pk, out H hdr, inout M meta, inout standard_metadata_t smeta) { + state start { + transition accept; + } +} + +@name("IngressI.altIngressName") control IngressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) { + @noWarn("unused") @name(".NoAction") action NoAction_1() { + } + @name("IngressI.blue") action foo(@name("orange") bit<9> port) { + smeta.egress_spec = port; + } + @name("IngressI.red") table foo_table_0 { + key = { + smeta.ingress_port: exact @name("green"); + } + actions = { + @name("yellow") foo(); + @name("grey") NoAction_1(); + } + const default_action = NoAction_1(); + } + apply { + foo_table_0.apply(); + } +} + +control EgressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) { + apply { + } +} + +control DeparserI(packet_out pk, in H hdr) { + apply { + } +} + +control VerifyChecksumI(inout H hdr, inout M meta) { + apply { + } +} + +control ComputeChecksumI(inout H hdr, inout M meta) { + apply { + } +} + +V1Switch(ParserI(), VerifyChecksumI(), IngressI(), EgressI(), ComputeChecksumI(), DeparserI()) main; diff --git a/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2-midend.p4 b/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2-midend.p4 new file mode 100644 index 00000000000..8b83caba873 --- /dev/null +++ b/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2-midend.p4 @@ -0,0 +1,59 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +struct H { +} + +struct M { + bit<32> hash1; +} + +parser ParserI(packet_in pk, out H hdr, inout M meta, inout standard_metadata_t smeta) { + state start { + transition accept; + } +} + +@name("IngressI.altIngressName") control IngressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) { + @noWarn("unused") @name(".NoAction") action NoAction_1() { + } + @name("IngressI.blue") action foo(@name("orange") bit<9> port) { + smeta.egress_spec = port; + } + @name("IngressI.red") table foo_table_0 { + key = { + smeta.ingress_port: exact @name("green"); + } + actions = { + @name("yellow") foo(); + @name("grey") NoAction_1(); + } + const default_action = NoAction_1(); + } + apply { + foo_table_0.apply(); + } +} + +control EgressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) { + apply { + } +} + +control DeparserI(packet_out pk, in H hdr) { + apply { + } +} + +control VerifyChecksumI(inout H hdr, inout M meta) { + apply { + } +} + +control ComputeChecksumI(inout H hdr, inout M meta) { + apply { + } +} + +V1Switch(ParserI(), VerifyChecksumI(), IngressI(), EgressI(), ComputeChecksumI(), DeparserI()) main; diff --git a/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2.p4 b/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2.p4 new file mode 100644 index 00000000000..1ef534477dd --- /dev/null +++ b/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2.p4 @@ -0,0 +1,57 @@ +#include +#define V1MODEL_VERSION 20180101 +#include + +struct H { +} + +struct M { + bit<32> hash1; +} + +parser ParserI(packet_in pk, out H hdr, inout M meta, inout standard_metadata_t smeta) { + state start { + transition accept; + } +} + +@name("altIngressName") control IngressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) { + @name("blue") action foo(@name("orange") bit<9> port) { + smeta.egress_spec = port; + } + @name("red") table foo_table { + key = { + smeta.ingress_port: exact @name("green"); + } + actions = { + @name("yellow") foo; + @name("grey") NoAction; + } + const default_action = NoAction(); + } + apply { + foo_table.apply(); + } +} + +control EgressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) { + apply { + } +} + +control DeparserI(packet_out pk, in H hdr) { + apply { + } +} + +control VerifyChecksumI(inout H hdr, inout M meta) { + apply { + } +} + +control ComputeChecksumI(inout H hdr, inout M meta) { + apply { + } +} + +V1Switch(ParserI(), VerifyChecksumI(), IngressI(), EgressI(), ComputeChecksumI(), DeparserI()) main; diff --git a/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2.p4-stderr b/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2.p4-stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2.p4.entries.txtpb b/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2.p4.entries.txtpb new file mode 100644 index 00000000000..5cb9652623a --- /dev/null +++ b/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2.p4.entries.txtpb @@ -0,0 +1,3 @@ +# proto-file: p4/v1/p4runtime.proto +# proto-message: p4.v1.WriteRequest + diff --git a/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2.p4.p4info.txtpb b/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2.p4.p4info.txtpb new file mode 100644 index 00000000000..f9668fdcbe1 --- /dev/null +++ b/testdata/p4_16_samples_outputs/name_annotations_to_p4info-bmv2.p4.p4info.txtpb @@ -0,0 +1,52 @@ +# proto-file: p4/config/v1/p4info.proto +# proto-message: p4.config.v1.P4Info + +pkg_info { + arch: "v1model" +} +tables { + preamble { + id: 49805857 + name: "IngressI.red" + alias: "red" + } + match_fields { + id: 1 + name: "green" + bitwidth: 9 + match_type: EXACT + } + action_refs { + id: 23079077 + } + action_refs { + id: 21257015 + } + const_default_action_id: 21257015 + initial_default_action { + action_id: 21257015 + } + size: 1024 +} +actions { + preamble { + id: 21257015 + name: "NoAction" + alias: "NoAction" + annotations: "@noWarn(\"unused\")" + } +} +actions { + preamble { + id: 23079077 + name: "IngressI.blue" + alias: "blue" + } + params { + id: 1 + name: "orange" + bitwidth: 9 + } +} +type_info { +} diff --git a/testdata/p4_16_samples_outputs/named_meter_1-bmv2-first.p4 b/testdata/p4_16_samples_outputs/named_meter_1-bmv2-first.p4 index 2d70d5b316e..b4b618b7596 100644 --- a/testdata/p4_16_samples_outputs/named_meter_1-bmv2-first.p4 +++ b/testdata/p4_16_samples_outputs/named_meter_1-bmv2-first.p4 @@ -60,11 +60,11 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ size = 16; default_action = NoAction(); } - @name("m_action") action m_action_0(bit<9> meter_idx) { + @name("m_action_2") action m_action_0(bit<9> meter_idx) { standard_metadata.egress_spec = meter_idx; my_meter.read(meta.meta.meter_tag); } - @name("_nop") action _nop_0() { + @name("_nop_2") action _nop_0() { my_meter.read(meta.meta.meter_tag); } @name("m_table") table m_table { diff --git a/testdata/p4_16_samples_outputs/named_meter_1-bmv2-frontend.p4 b/testdata/p4_16_samples_outputs/named_meter_1-bmv2-frontend.p4 index 551a3b2c470..2d08c566a81 100644 --- a/testdata/p4_16_samples_outputs/named_meter_1-bmv2-frontend.p4 +++ b/testdata/p4_16_samples_outputs/named_meter_1-bmv2-frontend.p4 @@ -60,11 +60,11 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ size = 16; default_action = NoAction_1(); } - @name("ingress.m_action") action m_action_0(@name("meter_idx") bit<9> meter_idx) { + @name("ingress.m_action_2") action m_action_0(@name("meter_idx") bit<9> meter_idx) { standard_metadata.egress_spec = meter_idx; my_meter.read(meta.meta.meter_tag); } - @name("ingress._nop") action _nop_0() { + @name("ingress._nop_2") action _nop_0() { my_meter.read(meta.meta.meter_tag); } @name("ingress.m_table") table m_table_0 { diff --git a/testdata/p4_16_samples_outputs/named_meter_1-bmv2-midend.p4 b/testdata/p4_16_samples_outputs/named_meter_1-bmv2-midend.p4 index 716d31df623..fe5f2004863 100644 --- a/testdata/p4_16_samples_outputs/named_meter_1-bmv2-midend.p4 +++ b/testdata/p4_16_samples_outputs/named_meter_1-bmv2-midend.p4 @@ -59,11 +59,11 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ size = 16; default_action = NoAction_1(); } - @name("ingress.m_action") action m_action_0(@name("meter_idx") bit<9> meter_idx) { + @name("ingress.m_action_2") action m_action_0(@name("meter_idx") bit<9> meter_idx) { standard_metadata.egress_spec = meter_idx; my_meter.read(meta._meta_meter_tag0); } - @name("ingress._nop") action _nop_0() { + @name("ingress._nop_2") action _nop_0() { my_meter.read(meta._meta_meter_tag0); } @name("ingress.m_table") table m_table_0 { diff --git a/testdata/p4_16_samples_outputs/named_meter_1-bmv2.p4 b/testdata/p4_16_samples_outputs/named_meter_1-bmv2.p4 index a9544c63639..75cfab9d1a0 100644 --- a/testdata/p4_16_samples_outputs/named_meter_1-bmv2.p4 +++ b/testdata/p4_16_samples_outputs/named_meter_1-bmv2.p4 @@ -60,11 +60,11 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ size = 16; default_action = NoAction(); } - @name("m_action") action m_action_0(bit<9> meter_idx) { + @name("m_action_2") action m_action_0(bit<9> meter_idx) { standard_metadata.egress_spec = meter_idx; my_meter.read(meta.meta.meter_tag); } - @name("_nop") action _nop_0() { + @name("_nop_2") action _nop_0() { my_meter.read(meta.meta.meter_tag); } @name("m_table") table m_table { diff --git a/testdata/p4_16_samples_outputs/named_meter_1-bmv2.p4.p4info.txtpb b/testdata/p4_16_samples_outputs/named_meter_1-bmv2.p4.p4info.txtpb index 398c9670544..5fd57eb7b5b 100644 --- a/testdata/p4_16_samples_outputs/named_meter_1-bmv2.p4.p4info.txtpb +++ b/testdata/p4_16_samples_outputs/named_meter_1-bmv2.p4.p4info.txtpb @@ -43,10 +43,10 @@ tables { match_type: EXACT } action_refs { - id: 24512981 + id: 18971545 } action_refs { - id: 26939440 + id: 27693640 } action_refs { id: 21257015 @@ -81,9 +81,9 @@ actions { } actions { preamble { - id: 24512981 - name: "ingress.m_action" - alias: "m_action" + id: 18971545 + name: "ingress.m_action_2" + alias: "m_action_2" } params { id: 1 @@ -91,6 +91,13 @@ actions { bitwidth: 9 } } +actions { + preamble { + id: 27693640 + name: "ingress._nop_2" + alias: "_nop_2" + } +} direct_meters { preamble { id: 368209065 diff --git a/testdata/p4_16_samples_outputs/named_meter_bmv2-first.p4 b/testdata/p4_16_samples_outputs/named_meter_bmv2-first.p4 index 4234a05c5d6..08560c03e6f 100644 --- a/testdata/p4_16_samples_outputs/named_meter_bmv2-first.p4 +++ b/testdata/p4_16_samples_outputs/named_meter_bmv2-first.p4 @@ -60,12 +60,12 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ size = 16; default_action = NoAction(); } - @name("m_action") action m_action_0(bit<9> meter_idx) { + @name("m_action_2") action m_action_0(bit<9> meter_idx) { standard_metadata.egress_spec = meter_idx; standard_metadata.egress_spec = 9w1; my_meter.read(meta.meta.meter_tag); } - @name("_nop") action _nop_0() { + @name("_nop_2") action _nop_0() { my_meter.read(meta.meta.meter_tag); } @name("m_table") table m_table { diff --git a/testdata/p4_16_samples_outputs/named_meter_bmv2-frontend.p4 b/testdata/p4_16_samples_outputs/named_meter_bmv2-frontend.p4 index 8ca214c1191..49b7140c8f3 100644 --- a/testdata/p4_16_samples_outputs/named_meter_bmv2-frontend.p4 +++ b/testdata/p4_16_samples_outputs/named_meter_bmv2-frontend.p4 @@ -60,11 +60,11 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ size = 16; default_action = NoAction_1(); } - @name("ingress.m_action") action m_action_0(@name("meter_idx") bit<9> meter_idx) { + @name("ingress.m_action_2") action m_action_0(@name("meter_idx") bit<9> meter_idx) { standard_metadata.egress_spec = 9w1; my_meter_0.read(meta.meta.meter_tag); } - @name("ingress._nop") action _nop_0() { + @name("ingress._nop_2") action _nop_0() { my_meter_0.read(meta.meta.meter_tag); } @name("ingress.m_table") table m_table_0 { diff --git a/testdata/p4_16_samples_outputs/named_meter_bmv2-midend.p4 b/testdata/p4_16_samples_outputs/named_meter_bmv2-midend.p4 index 0bdd39f7a1c..7c2b71cd7a1 100644 --- a/testdata/p4_16_samples_outputs/named_meter_bmv2-midend.p4 +++ b/testdata/p4_16_samples_outputs/named_meter_bmv2-midend.p4 @@ -59,11 +59,11 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ size = 16; default_action = NoAction_1(); } - @name("ingress.m_action") action m_action_0(@name("meter_idx") bit<9> meter_idx) { + @name("ingress.m_action_2") action m_action_0(@name("meter_idx") bit<9> meter_idx) { standard_metadata.egress_spec = 9w1; my_meter_0.read(meta._meta_meter_tag0); } - @name("ingress._nop") action _nop_0() { + @name("ingress._nop_2") action _nop_0() { my_meter_0.read(meta._meta_meter_tag0); } @name("ingress.m_table") table m_table_0 { diff --git a/testdata/p4_16_samples_outputs/named_meter_bmv2.p4 b/testdata/p4_16_samples_outputs/named_meter_bmv2.p4 index 3f53812af01..c6f394e2cd4 100644 --- a/testdata/p4_16_samples_outputs/named_meter_bmv2.p4 +++ b/testdata/p4_16_samples_outputs/named_meter_bmv2.p4 @@ -60,12 +60,12 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_ size = 16; default_action = NoAction(); } - @name("m_action") action m_action_0(bit<9> meter_idx) { + @name("m_action_2") action m_action_0(bit<9> meter_idx) { standard_metadata.egress_spec = meter_idx; standard_metadata.egress_spec = 9w1; my_meter.read(meta.meta.meter_tag); } - @name("_nop") action _nop_0() { + @name("_nop_2") action _nop_0() { my_meter.read(meta.meta.meter_tag); } @name("m_table") table m_table { diff --git a/testdata/p4_16_samples_outputs/named_meter_bmv2.p4.p4info.txtpb b/testdata/p4_16_samples_outputs/named_meter_bmv2.p4.p4info.txtpb index 30a57fc6528..c351804ae74 100644 --- a/testdata/p4_16_samples_outputs/named_meter_bmv2.p4.p4info.txtpb +++ b/testdata/p4_16_samples_outputs/named_meter_bmv2.p4.p4info.txtpb @@ -43,10 +43,10 @@ tables { match_type: EXACT } action_refs { - id: 24512981 + id: 18971545 } action_refs { - id: 26939440 + id: 27693640 } action_refs { id: 21257015 @@ -81,9 +81,9 @@ actions { } actions { preamble { - id: 24512981 - name: "ingress.m_action" - alias: "m_action" + id: 18971545 + name: "ingress.m_action_2" + alias: "m_action_2" } params { id: 1 @@ -91,6 +91,13 @@ actions { bitwidth: 9 } } +actions { + preamble { + id: 27693640 + name: "ingress._nop_2" + alias: "_nop_2" + } +} direct_meters { preamble { id: 354402025