Skip to content

Commit

Permalink
Continuing the implementation of initial entries support in p4c (#4080)
Browse files Browse the repository at this point in the history
* Continuing the implementation of initial entries support in p4c
These changes update the contents of P4Info and table entries files as
generated by p4c, to match what has been agreed upon by the P4 API
work group in this pull request
p4lang/p4runtime#432

* Comment-only change to poke CI.

* Update p4runtime commit SHA

* Update p4runtime commit SHA for Bazel builds

* Correctly handle case when table->getEntries() is null

* Update a few more expected output files, and make linter happy

* Update bazel/p4c_deps.bzl

Co-authored-by: Radostin Stoyanov <[email protected]>

---------

Co-authored-by: Radostin Stoyanov <[email protected]>
  • Loading branch information
jafingerhut and rst0git authored Aug 16, 2023
1 parent 3bf3c9c commit bfef774
Show file tree
Hide file tree
Showing 55 changed files with 148 additions and 6 deletions.
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
4 changes: 2 additions & 2 deletions bazel/p4c_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ filegroup(
git_repository(
name = "com_github_p4lang_p4runtime",
remote = "https://github.com/p4lang/p4runtime",
# Newest commit on main branch as of April 11, 2023.
commit = "d76a3640a223f47a43dc34e5565b72e43796ba57",
# Newest commit on main branch as of August 11, 2023.
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

0 comments on commit bfef774

Please sign in to comment.