From 1a78b17f9e8b84155a14095b808174f07e9117d6 Mon Sep 17 00:00:00 2001 From: Usha Gupta Date: Tue, 4 Apr 2023 11:42:55 +0000 Subject: [PATCH] Change array index[] in table keys in context.json to $ to match with the key name in bfrt.json --- backends/dpdk/dpdkContext.cpp | 6 ++++- backends/dpdk/dpdkContext.h | 2 ++ testdata/p4_16_samples/psa-header-stack.p4 | 1 + .../psa-header-stack-first.p4 | 3 ++- .../psa-header-stack-frontend.p4 | 3 ++- .../psa-header-stack-midend.p4 | 13 +++++----- .../p4_16_samples_outputs/psa-header-stack.p4 | 3 ++- .../psa-header-stack.p4-error | 1 + .../psa-header-stack.p4.bfrt.json | 12 +++++++++ .../psa-header-stack.p4.p4info.txt | 26 +++++++++++++++++++ .../psa-header-stack.p4.spec | 9 +++++-- 11 files changed, 67 insertions(+), 12 deletions(-) diff --git a/backends/dpdk/dpdkContext.cpp b/backends/dpdk/dpdkContext.cpp index 37295abca1f..c0c524fbbce 100644 --- a/backends/dpdk/dpdkContext.cpp +++ b/backends/dpdk/dpdkContext.cpp @@ -169,7 +169,11 @@ void DpdkContextGenerator::addKeyField(Util::JsonArray *keyJson, const cstring n cstring fieldName = name.findlast('.'); auto instanceName = name.replace(fieldName, ""); fieldName = fieldName.trim(".\t\n\r"); - keyField->emplace("name", nameAnnotation); + std::string keyName(nameAnnotation); + // Replace header stack indices hdr[] with hdr$. + std::regex hdrStackRegex(R"(\[([0-9]+)\])"); + keyName = std::regex_replace(keyName, hdrStackRegex, "$$$1"); + keyField->emplace("name", keyName); keyField->emplace("instance_name", instanceName); keyField->emplace("field_name", fieldName); auto match_kind = toStr(key->matchType); diff --git a/backends/dpdk/dpdkContext.h b/backends/dpdk/dpdkContext.h index aa55c1e86fd..52a63c2b54e 100644 --- a/backends/dpdk/dpdkContext.h +++ b/backends/dpdk/dpdkContext.h @@ -17,6 +17,8 @@ limitations under the License. #ifndef BACKENDS_DPDK_DPDKCONTEXT_H_ #define BACKENDS_DPDK_DPDKCONTEXT_H_ +#include + #include "constants.h" #include "control-plane/bfruntime.h" #include "dpdkProgramStructure.h" diff --git a/testdata/p4_16_samples/psa-header-stack.p4 b/testdata/p4_16_samples/psa-header-stack.p4 index 1db3bf0c8da..1590749c024 100644 --- a/testdata/p4_16_samples/psa-header-stack.p4 +++ b/testdata/p4_16_samples/psa-header-stack.p4 @@ -85,6 +85,7 @@ control MyIC( table tbl { key = { a.ethernet.srcAddr : exact; + a.vlan_tag[0].ether_type : exact; } actions = { NoAction; diff --git a/testdata/p4_16_samples_outputs/psa-header-stack-first.p4 b/testdata/p4_16_samples_outputs/psa-header-stack-first.p4 index 9742d22392a..4dcddf49a70 100644 --- a/testdata/p4_16_samples_outputs/psa-header-stack-first.p4 +++ b/testdata/p4_16_samples_outputs/psa-header-stack-first.p4 @@ -73,7 +73,8 @@ control MyIC(inout header_t a, inout EMPTY_M b, in psa_ingress_input_metadata_t } table tbl { key = { - a.ethernet.srcAddr: exact @name("a.ethernet.srcAddr"); + a.ethernet.srcAddr : exact @name("a.ethernet.srcAddr"); + a.vlan_tag[0].ether_type: exact @name("a.vlan_tag[0].ether_type"); } actions = { NoAction(); diff --git a/testdata/p4_16_samples_outputs/psa-header-stack-frontend.p4 b/testdata/p4_16_samples_outputs/psa-header-stack-frontend.p4 index 4467bed670e..b0393add76a 100644 --- a/testdata/p4_16_samples_outputs/psa-header-stack-frontend.p4 +++ b/testdata/p4_16_samples_outputs/psa-header-stack-frontend.p4 @@ -72,7 +72,8 @@ control MyIC(inout header_t a, inout EMPTY_M b, in psa_ingress_input_metadata_t } @name("MyIC.tbl") table tbl_0 { key = { - a.ethernet.srcAddr: exact @name("a.ethernet.srcAddr"); + a.ethernet.srcAddr : exact @name("a.ethernet.srcAddr"); + a.vlan_tag[0].ether_type: exact @name("a.vlan_tag[0].ether_type"); } actions = { NoAction_1(); diff --git a/testdata/p4_16_samples_outputs/psa-header-stack-midend.p4 b/testdata/p4_16_samples_outputs/psa-header-stack-midend.p4 index adae80d00a0..00344f8dee6 100644 --- a/testdata/p4_16_samples_outputs/psa-header-stack-midend.p4 +++ b/testdata/p4_16_samples_outputs/psa-header-stack-midend.p4 @@ -65,7 +65,8 @@ control MyIC(inout header_t a, inout EMPTY_M b, in psa_ingress_input_metadata_t } @name("MyIC.tbl") table tbl_0 { key = { - a.ethernet.srcAddr: exact @name("a.ethernet.srcAddr"); + a.ethernet.srcAddr : exact @name("a.ethernet.srcAddr"); + a.vlan_tag[0].ether_type: exact @name("a.vlan_tag[0].ether_type"); } actions = { NoAction_1(); @@ -87,19 +88,19 @@ control MyEC(inout EMPTY_H a, inout EMPTY_M b, in psa_egress_input_metadata_t c, } control MyID(packet_out buffer, out EMPTY_CLONE a, out EMPTY_RESUB b, out EMPTY_BRIDGE c, inout header_t d, in EMPTY_M e, in psa_ingress_output_metadata_t f) { - @hidden action psaheaderstack118() { + @hidden action psaheaderstack119() { buffer.emit(d.ethernet); buffer.emit(d.vlan_tag[0]); buffer.emit(d.vlan_tag[1]); } - @hidden table tbl_psaheaderstack118 { + @hidden table tbl_psaheaderstack119 { actions = { - psaheaderstack118(); + psaheaderstack119(); } - const default_action = psaheaderstack118(); + const default_action = psaheaderstack119(); } apply { - tbl_psaheaderstack118.apply(); + tbl_psaheaderstack119.apply(); } } diff --git a/testdata/p4_16_samples_outputs/psa-header-stack.p4 b/testdata/p4_16_samples_outputs/psa-header-stack.p4 index dbbf153b7fd..2ecdb92cef0 100644 --- a/testdata/p4_16_samples_outputs/psa-header-stack.p4 +++ b/testdata/p4_16_samples_outputs/psa-header-stack.p4 @@ -73,7 +73,8 @@ control MyIC(inout header_t a, inout EMPTY_M b, in psa_ingress_input_metadata_t } table tbl { key = { - a.ethernet.srcAddr: exact; + a.ethernet.srcAddr : exact; + a.vlan_tag[0].ether_type: exact; } actions = { NoAction; diff --git a/testdata/p4_16_samples_outputs/psa-header-stack.p4-error b/testdata/p4_16_samples_outputs/psa-header-stack.p4-error index e69de29bb2d..610fe07fb35 100644 --- a/testdata/p4_16_samples_outputs/psa-header-stack.p4-error +++ b/testdata/p4_16_samples_outputs/psa-header-stack.p4-error @@ -0,0 +1 @@ +[--Wwarn=mismatch] warning: Mismatched header/metadata struct for key elements in table tbl. Copying all match fields to metadata diff --git a/testdata/p4_16_samples_outputs/psa-header-stack.p4.bfrt.json b/testdata/p4_16_samples_outputs/psa-header-stack.p4.bfrt.json index b5246dbf4ff..d812c79bf3d 100644 --- a/testdata/p4_16_samples_outputs/psa-header-stack.p4.bfrt.json +++ b/testdata/p4_16_samples_outputs/psa-header-stack.p4.bfrt.json @@ -21,6 +21,18 @@ "type" : "bytes", "width" : 48 } + }, + { + "id" : 2, + "name" : "a.vlan_tag$0.ether_type", + "repeated" : false, + "annotations" : [], + "mandatory" : false, + "match_type" : "Exact", + "type" : { + "type" : "bytes", + "width" : 16 + } } ], "action_specs" : [ diff --git a/testdata/p4_16_samples_outputs/psa-header-stack.p4.p4info.txt b/testdata/p4_16_samples_outputs/psa-header-stack.p4.p4info.txt index ac8f5e98f71..74bedfc59f5 100644 --- a/testdata/p4_16_samples_outputs/psa-header-stack.p4.p4info.txt +++ b/testdata/p4_16_samples_outputs/psa-header-stack.p4.p4info.txt @@ -13,6 +13,12 @@ tables { bitwidth: 48 match_type: EXACT } + match_fields { + id: 2 + name: "a.vlan_tag[0].ether_type" + bitwidth: 16 + match_type: EXACT + } action_refs { id: 21257015 } @@ -27,4 +33,24 @@ actions { } } type_info { + serializable_enums { + key: "ether_type_t" + value { + underlying_type { + bitwidth: 16 + } + members { + name: "TPID" + value: "\201\000" + } + members { + name: "IPV4" + value: "\010\000" + } + members { + name: "IPV6" + value: "\206\335" + } + } + } } diff --git a/testdata/p4_16_samples_outputs/psa-header-stack.p4.spec b/testdata/p4_16_samples_outputs/psa-header-stack.p4.spec index dde33fd595e..bb6b6cf06ba 100644 --- a/testdata/p4_16_samples_outputs/psa-header-stack.p4.spec +++ b/testdata/p4_16_samples_outputs/psa-header-stack.p4.spec @@ -35,6 +35,8 @@ struct EMPTY_M { bit<16> psa_ingress_input_metadata_parser_error bit<8> psa_ingress_output_metadata_drop bit<32> psa_ingress_output_metadata_egress_port + bit<48> MyIC_tbl_ethernet_srcAddr + bit<16> MyIC_tbl_key } metadata instanceof EMPTY_M @@ -49,7 +51,8 @@ action NoAction args none { table tbl { key { - h.ethernet.srcAddr exact + m.MyIC_tbl_ethernet_srcAddr exact + m.MyIC_tbl_key exact } actions { NoAction @@ -74,7 +77,9 @@ apply { MYIP_PARSE_VLAN_TAG2 : mov m.psa_ingress_input_metadata_parser_error 0x3 MYIP_ACCEPT : jmpnv LABEL_FALSE h.ethernet jmp LABEL_END_0 - LABEL_FALSE : table tbl + LABEL_FALSE : mov m.MyIC_tbl_ethernet_srcAddr h.ethernet.srcAddr + mov m.MyIC_tbl_key h.vlan_tag_0.ether_type + table tbl LABEL_END_0 : jmpneq LABEL_DROP m.psa_ingress_output_metadata_drop 0x0 emit h.ethernet emit h.vlan_tag_0