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

Continuing the implementation of initial entries support in p4c #4080

Merged
merged 8 commits into from
Aug 16, 2023
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ set(FETCHCONTENT_QUIET OFF)
FetchContent_Declare(
p4runtime
GIT_REPOSITORY https://github.com/p4lang/p4runtime.git
GIT_TAG d76a3640a223f47a43dc34e5565b72e43796ba57
GIT_TAG 1e771c4e05c4e7e250df00212b3ca02ee3202d71
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(p4runtime)
Expand Down
2 changes: 1 addition & 1 deletion bazel/p4c_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ filegroup(
name = "com_github_p4lang_p4runtime",
remote = "https://github.com/p4lang/p4runtime",
# Newest commit on main branch as of April 11, 2023.
jafingerhut marked this conversation as resolved.
Show resolved Hide resolved
commit = "d76a3640a223f47a43dc34e5565b72e43796ba57",
commit = "1e771c4e05c4e7e250df00212b3ca02ee3202d71",
shallow_since = "1680213111 -0700",
# strip_prefix is broken; we use patch_cmds as a workaround,
# see https://github.com/bazelbuild/bazel/issues/10062.
Expand Down
20 changes: 17 additions & 3 deletions control-plane/p4RuntimeSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ static bool getConstTable(const IR::P4Table *table) {
return ep->isConstant;
}

/// @return true if @table has an 'entries' or 'const entries'
/// property, and there is at least one entry.
static bool getHasInitialEntries(const IR::P4Table *table) {
BUG_CHECK(table != nullptr, "Failed precondition for getHasInitialEntries");
auto entriesList = table->getEntries();
if (entriesList == nullptr) return false;
return (entriesList->entries.size() >= 1);
}

static std::vector<ActionRef> getActionRefs(const IR::P4Table *table, ReferenceMap *refMap) {
std::vector<ActionRef> actions;
for (auto action : table->getActionList()->actionList) {
Expand Down Expand Up @@ -655,6 +664,7 @@ class P4RuntimeAnalyzer {
auto actions = getActionRefs(tableDeclaration, refMap);

bool isConstTable = getConstTable(tableDeclaration);
bool hasInitialEntries = getHasInitialEntries(tableDeclaration);

auto name = archHandler->getControlPlaneName(tableBlock);
auto annotations = tableDeclaration->to<IR::IAnnotated>();
Expand Down Expand Up @@ -712,6 +722,9 @@ class P4RuntimeAnalyzer {
if (isConstTable) {
table->set_is_const_table(true);
}
if (hasInitialEntries) {
table->set_has_initial_entries(true);
}

archHandler->addTableProperties(symbols, p4Info, table, tableBlock);
}
Expand Down Expand Up @@ -973,9 +986,9 @@ static void analyzeParser(P4RuntimeAnalyzer &analyzer, const IR::ParserBlock *pa
}
}

/// A converter which translates the 'const entries' for P4 tables (if any)
/// into a P4Runtime WriteRequest message which can be used by a target to
/// initialize its tables.
/// A converter which translates the 'entries' or 'const entries' for
/// P4 tables (if any) into a P4Runtime WriteRequest message which can
/// be used by a target to initialize its tables.
class P4RuntimeEntriesConverter {
private:
friend class P4RuntimeAnalyzer;
Expand Down Expand Up @@ -1012,6 +1025,7 @@ class P4RuntimeEntriesConverter {
protoEntry->set_table_id(tableId);
addMatchKey(protoEntry, table, e->getKeys(), refMap, typeMap);
addAction(protoEntry, e->getAction(), refMap, typeMap);
protoEntry->set_is_const(isConst || e->isConst);
if (needsPriority) {
if (!isConst) {
// The entry has a priority, use it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ updates {
}
}
}
is_const: true
}
}
}
Expand All @@ -43,6 +44,7 @@ updates {
}
}
}
is_const: true
}
}
}
Expand All @@ -60,6 +62,7 @@ updates {
}
}
}
is_const: true
}
}
}
Expand All @@ -77,6 +80,7 @@ updates {
}
}
}
is_const: true
}
}
}
Expand All @@ -101,6 +105,7 @@ updates {
}
}
}
is_const: true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ tables {
}
size: 1024
is_const_table: true
has_initial_entries: true
}
actions {
preamble {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ updates {
}
}
priority: 3
is_const: true
}
}
}
Expand All @@ -48,6 +49,7 @@ updates {
}
}
priority: 2
is_const: true
}
}
}
Expand All @@ -72,6 +74,7 @@ updates {
}
}
priority: 1
is_const: true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ tables {
}
size: 1024
is_const_table: true
has_initial_entries: true
}
actions {
preamble {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ updates {
}
}
}
is_const: true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tables {
const_default_action_id: 25652968
size: 1024
is_const_table: true
has_initial_entries: true
}
actions {
preamble {
Expand Down
2 changes: 2 additions & 0 deletions testdata/p4_16_samples_outputs/bvec-hdr-bmv2.p4.entries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ updates {
}
}
}
is_const: true
}
}
}
Expand All @@ -41,6 +42,7 @@ updates {
}
}
}
is_const: true
}
}
}
1 change: 1 addition & 0 deletions testdata/p4_16_samples_outputs/bvec-hdr-bmv2.p4.p4info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ tables {
}
size: 1024
is_const_table: true
has_initial_entries: true
}
actions {
preamble {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ updates {
action_id: 25440736
}
}
is_const: true
}
}
}
Expand All @@ -33,6 +34,7 @@ updates {
action_id: 18556685
}
}
is_const: true
}
}
}
2 changes: 2 additions & 0 deletions testdata/p4_16_samples_outputs/checksum-l4-bmv2.p4.p4info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tables {
const_default_action_id: 21257015
size: 1024
is_const_table: true
has_initial_entries: true
}
tables {
preamble {
Expand All @@ -44,6 +45,7 @@ tables {
const_default_action_id: 21257015
size: 1024
is_const_table: true
has_initial_entries: true
}
actions {
preamble {
Expand Down
6 changes: 6 additions & 0 deletions testdata/p4_16_samples_outputs/crc32-bmv2.p4.entries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ updates {
action_id: 24785092
}
}
is_const: true
}
}
}
Expand All @@ -33,6 +34,7 @@ updates {
action_id: 22867470
}
}
is_const: true
}
}
}
Expand All @@ -52,6 +54,7 @@ updates {
action_id: 32601303
}
}
is_const: true
}
}
}
Expand All @@ -71,6 +74,7 @@ updates {
action_id: 17405675
}
}
is_const: true
}
}
}
Expand All @@ -90,6 +94,7 @@ updates {
action_id: 31935968
}
}
is_const: true
}
}
}
Expand All @@ -109,6 +114,7 @@ updates {
action_id: 24997060
}
}
is_const: true
}
}
}
1 change: 1 addition & 0 deletions testdata/p4_16_samples_outputs/crc32-bmv2.p4.p4info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ tables {
const_default_action_id: 32121835
size: 1024
is_const_table: true
has_initial_entries: true
}
actions {
preamble {
Expand Down
Loading
Loading