Skip to content

Commit

Permalink
[fuzzer] Refactor test to use entities instead of table entries.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 599538637
  • Loading branch information
kishanps authored and VSuryaprasad-HCL committed Oct 22, 2024
1 parent c90bcc5 commit 059f647
Show file tree
Hide file tree
Showing 3 changed files with 518 additions and 0 deletions.
23 changes: 23 additions & 0 deletions p4_fuzzer/switch_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,29 @@ bool SwitchState::IsTableEmpty(const uint32_t table_id) const {
return FindOrDie(ordered_tables_, table_id).empty();
}

std::optional<Entity> SwitchState::GetEntity(const Entity& entity) const {
std::optional<Entity> result = std::nullopt;
if (entity.packet_replication_engine_entry().has_multicast_group_entry()) {
std::optional<MulticastGroupEntry> multicast_group_entry =
GetMulticastGroupEntry(
entity.packet_replication_engine_entry().multicast_group_entry());
if (multicast_group_entry.has_value()) {
*result->mutable_packet_replication_engine_entry()
->mutable_multicast_group_entry() =
*std::move(multicast_group_entry);
}
}

if (entity.has_table_entry()) {
std::optional<TableEntry> table_entry = GetTableEntry(entity.table_entry());
if (table_entry.has_value()) {
*result->mutable_table_entry() = *std::move(table_entry);
}
}

return result;
}

std::optional<TableEntry> SwitchState::GetTableEntry(
const TableEntry& entry) const {
const UnorderedTableEntries& table =
Expand Down
4 changes: 4 additions & 0 deletions p4_fuzzer/switch_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ class SwitchState {
return ordered_multicast_entries_.size();
};

// Returns the current state of an entity (or nullopt if it is not
// present). Only the uniquely identifying fields of `entity` are considered.
std::optional<p4::v1::Entity> GetEntity(const p4::v1::Entity& entity) const;

// Returns the current state of a table entry (or nullopt if it is not
// present). Only the uniquely identifying fields of entry are considered.
std::optional<p4::v1::TableEntry> GetTableEntry(
Expand Down
Loading

0 comments on commit 059f647

Please sign in to comment.