Skip to content

Commit

Permalink
Continuing the implementation of initial entries support in p4c
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jafingerhut committed Jul 23, 2023
1 parent 284c924 commit e332cf0
Show file tree
Hide file tree
Showing 49 changed files with 139 additions and 3 deletions.
19 changes: 16 additions & 3 deletions control-plane/p4RuntimeSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ 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 in the list.
static bool getHasInitialEntries(const IR::P4Table *table) {
BUG_CHECK(table != nullptr, "Failed precondition for getConstTable");
auto entriesList = table->getEntries();
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 @@ -652,6 +660,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 @@ -709,6 +718,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 @@ -970,9 +982,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 @@ -1009,6 +1021,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
16 changes: 16 additions & 0 deletions testdata/p4_16_samples_outputs/init-entries-bmv2.p4.entries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ updates {
}
}
priority: 10
is_const: true
}
}
}
Expand Down Expand Up @@ -119,6 +120,7 @@ updates {
}
}
priority: 40
is_const: true
}
}
}
Expand Down Expand Up @@ -205,6 +207,7 @@ updates {
}
}
priority: 10
is_const: true
}
}
}
Expand Down Expand Up @@ -298,6 +301,7 @@ updates {
}
}
priority: 40
is_const: true
}
}
}
Expand Down Expand Up @@ -384,6 +388,7 @@ updates {
}
}
priority: 11
is_const: true
}
}
}
Expand Down Expand Up @@ -477,6 +482,7 @@ updates {
}
}
priority: 41
is_const: true
}
}
}
Expand Down Expand Up @@ -563,6 +569,7 @@ updates {
}
}
priority: 11
is_const: true
}
}
}
Expand Down Expand Up @@ -656,6 +663,7 @@ updates {
}
}
priority: 41
is_const: true
}
}
}
Expand Down Expand Up @@ -742,6 +750,7 @@ updates {
}
}
priority: 11
is_const: true
}
}
}
Expand Down Expand Up @@ -835,6 +844,7 @@ updates {
}
}
priority: 14
is_const: true
}
}
}
Expand Down Expand Up @@ -921,6 +931,7 @@ updates {
}
}
priority: 11
is_const: true
}
}
}
Expand Down Expand Up @@ -1014,6 +1025,7 @@ updates {
}
}
priority: 14
is_const: true
}
}
}
Expand Down Expand Up @@ -1100,6 +1112,7 @@ updates {
}
}
priority: 2001
is_const: true
}
}
}
Expand Down Expand Up @@ -1224,6 +1237,7 @@ updates {
}
}
priority: 2001
is_const: true
}
}
}
Expand Down Expand Up @@ -1279,6 +1293,7 @@ updates {
}
}
priority: 2001
is_const: true
}
}
}
Expand Down Expand Up @@ -1403,6 +1418,7 @@ updates {
}
}
priority: 2001
is_const: true
}
}
}
Expand Down
Loading

0 comments on commit e332cf0

Please sign in to comment.