Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPDK Backend: Change array index[] in table keys in context.json to $ to match with the key name in bfrt.json #3963

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion backends/dpdk/dpdkContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[<index>] with hdr$<index>.
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);
Expand Down
2 changes: 2 additions & 0 deletions backends/dpdk/dpdkContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
#ifndef BACKENDS_DPDK_DPDKCONTEXT_H_
#define BACKENDS_DPDK_DPDKCONTEXT_H_

#include <regex>

#include "constants.h"
#include "control-plane/bfruntime.h"
#include "dpdkProgramStructure.h"
Expand Down
1 change: 1 addition & 0 deletions testdata/p4_16_samples/psa-header-stack.p4
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ control MyIC(
table tbl {
key = {
a.ethernet.srcAddr : exact;
a.vlan_tag[0].ether_type : exact;
}
actions = {
NoAction;
Expand Down
3 changes: 2 additions & 1 deletion testdata/p4_16_samples_outputs/psa-header-stack-first.p4
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion testdata/p4_16_samples_outputs/psa-header-stack-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 7 additions & 6 deletions testdata/p4_16_samples_outputs/psa-header-stack-midend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<ethernet_t>(d.ethernet);
buffer.emit<vlan_tag_h>(d.vlan_tag[0]);
buffer.emit<vlan_tag_h>(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();
}
}

Expand Down
3 changes: 2 additions & 1 deletion testdata/p4_16_samples_outputs/psa-header-stack.p4
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions testdata/p4_16_samples_outputs/psa-header-stack.p4-error
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[--Wwarn=mismatch] warning: Mismatched header/metadata struct for key elements in table tbl. Copying all match fields to metadata
12 changes: 12 additions & 0 deletions testdata/p4_16_samples_outputs/psa-header-stack.p4.bfrt.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" : [
Expand Down
26 changes: 26 additions & 0 deletions testdata/p4_16_samples_outputs/psa-header-stack.p4.p4info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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"
}
}
}
}
9 changes: 7 additions & 2 deletions testdata/p4_16_samples_outputs/psa-header-stack.p4.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down