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 (#111)

This is part of a larger effort to not expose p4-constraints internals to clients, so we can change internals without breaking clients.

Co-authored-by: PINS Team <[email protected]>
  • Loading branch information
angelazhang8 and PINS Team authored Oct 20, 2023
1 parent e097da9 commit d054e74
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 d054e74

Please sign in to comment.