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: Strip pipename prefix added to table and extern names for bfrt.json while generating context json #3936

Merged
merged 1 commit into from
Mar 23, 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
25 changes: 14 additions & 11 deletions backends/dpdk/dpdkContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ limitations under the License.
#include "printUtils.h"
namespace DPDK {

cstring DpdkContextGenerator::removePipePrefix(cstring tableName) {
if (!options.bfRtSchema.isNullOrEmpty() || !options.tdiFile.isNullOrEmpty()) {
cstring tablename = tableName.find('.');
tablename = tablename.trim(".\t\n\r");
return tablename;
}
return tableName;
}

// This function collects all tables in a vector and sets the table attributes required
// by context json into a map.
void DpdkContextGenerator::CollectTablesAndSetAttributes() {
Expand All @@ -39,8 +48,7 @@ void DpdkContextGenerator::CollectTablesAndSetAttributes() {
tblAttr.direction = direction;
tblAttr.controlName = control->name.originalName;
tblAttr.externalName = tbl->controlPlaneName();
tblAttr.tableHandle =
getHandleId(tblAttr.controlName + "." + tbl->name.originalName);
tblAttr.tableHandle = getHandleId(tblAttr.externalName);
auto size = tbl->getSizeProperty();
tblAttr.size = dpdk_default_table_size;
if (size) tblAttr.size = size->asUnsigned();
Expand Down Expand Up @@ -192,32 +200,27 @@ Util::JsonObject *DpdkContextGenerator::initTableCommonJson(const cstring name,
void DpdkContextGenerator::collectHandleId() {
for (auto &table : p4info.tables()) {
const auto &pre_t = table.preamble();
context_handle_map[pre_t.name()] = pre_t.id();
context_handle_map[removePipePrefix(pre_t.name())] = pre_t.id();
}
for (auto &action : p4info.actions()) {
const auto &pre_a = action.preamble();
context_handle_map[pre_a.name()] = pre_a.id();
}
for (auto &action_prof : p4info.action_profiles()) {
const auto &pre_a = action_prof.preamble();
context_handle_map[pre_a.name()] = pre_a.id();
context_handle_map[removePipePrefix(pre_a.name())] = pre_a.id();
}
for (const auto &externType : p4info.externs()) {
for (const auto &externInstance : externType.instances()) {
const auto &pre_a = externInstance.preamble();
context_handle_map[pre_a.name()] = pre_a.id();
context_handle_map[removePipePrefix(pre_a.name())] = pre_a.id();
}
}
}

size_t DpdkContextGenerator::getHandleId(cstring name) {
size_t id = 0;
for (auto x : context_handle_map) {
if (x.first.find(name.c_str())) {
id = context_handle_map[x.first];
break;
}
}
if (context_handle_map.count(name)) id = context_handle_map[name];
BUG_CHECK(id != 0, "unable to find id for %1%", name);
return id;
}
Expand Down
1 change: 1 addition & 0 deletions backends/dpdk/dpdkContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class DpdkContextGenerator : public Inspector {
void setActionAttributes(const IR::P4Table *table);
void setDefaultActionHandle(const IR::P4Table *table);
void CollectTablesAndSetAttributes();
cstring removePipePrefix(cstring);
};

} // namespace DPDK
Expand Down