Skip to content

Commit

Permalink
Add an API to get TableInfo from ConstraintInfo through a lookup usin…
Browse files Browse the repository at this point in the history
…g table_id

Code in P4 fuzzer uses ConstraintInfo to lookup TableInfo. Since p4fuzzer presubmit checks that any new code added to p4infra Github builds, we need to first sync this change to p4infra Github. This CL will enable these changes: https://critique.corp.google.com/cl/574299826. This is part of the work to support actions in P4-constraints by allowing users to add constraint annotations for actions. Please see the design doc at https://docs.google.com/document/d/11Nkn3_BAa43OX4I-_DPsoUokebGdRYx6QAk7eGVAyLc/edit?resourcekey=0-gO31LvkRyylb07KB1m3RMg for more information.

PUBLIC: [p4-fuzzer] Add ConstraintInfo API for retrieving TableInfo given table_id.
PiperOrigin-RevId: 574581354
  • Loading branch information
PINS Team authored and angelazhang8 committed Oct 20, 2023
1 parent e097da9 commit acdae64
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions p4_constraints/backend/constraint_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ std::optional<AttributeInfo> GetAttributeInfo(
return absl::nullopt;
}

const TableInfo* GetTableInfoOrNull(const ConstraintInfo& constraint_info,
uint32_t table_id) {
auto it = constraint_info.find(table_id);
if (it == constraint_info.end()) return nullptr;
return &it->second;
}

absl::StatusOr<ConstraintInfo> P4ToConstraintInfo(
const p4::config::v1::P4Info& p4info) {
// Allocate output.
Expand Down
5 changes: 5 additions & 0 deletions p4_constraints/backend/constraint_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ using ConstraintInfo = absl::flat_hash_map<uint32_t, TableInfo>;
absl::StatusOr<ConstraintInfo> P4ToConstraintInfo(
const p4::config::v1::P4Info& p4info);

// Returns a unique pointer to the TableInfo associated with a given table_id
// or std::nullptr if the table_id cannot be found.
const TableInfo* GetTableInfoOrNull(const ConstraintInfo& constraint_info,
uint32_t table_id);

// Table entry attribute accessible in the constraint language, e.g. priority.
struct AttributeInfo {
std::string name;
Expand Down

0 comments on commit acdae64

Please sign in to comment.