Skip to content

Commit

Permalink
[P4RT] Refactor AppDbEntry to store IrEntity, Entity, and EntityKey i…
Browse files Browse the repository at this point in the history
…nstead of `TableEntry` types. (sonic-net#469)

* [P4RT] Support read requests containing packet replication engine entities. Support for reading back entries still needed.
add `batch_set()` for TableAdapter

* Make the test reproducible & Reduce the default number of entries installed.

* [P4RT] Do not run IPv4 tests by default & allow WCMP watch port in performance tests.

* [P4RT] Do not run IPv4 tests by default & allow WCMP watch port in performance tests.

* [P4RT] Refactor `AppDbEntry` to store `IrEntity`, `Entity`, and `EntityKey` instead of `TableEntry` types.

---------

Co-authored-by: kishanps <[email protected]>
  • Loading branch information
divyagayathri-hcl and kishanps authored Aug 14, 2024
1 parent d64a213 commit 301cbb0
Show file tree
Hide file tree
Showing 16 changed files with 633 additions and 422 deletions.
37 changes: 36 additions & 1 deletion p4rt_app/p4runtime/ir_translation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ absl::Status TranslateAction(const TranslateTableEntryOptions& options,
}

for (auto& param : *action.mutable_params()) {
// If the paramter field isn't a port then ignore it.
// If the parameter field isn't a port then ignore it.
const pdpi::IrActionDefinition::IrActionParamDefinition* param_def =
gutil::FindOrNull(action_def->params_by_name(), param.name());
if (param_def == nullptr) {
Expand Down Expand Up @@ -330,6 +330,41 @@ void Convert64BitIpv6AclMatchFieldsTo128Bit(
}
}

absl::StatusOr<pdpi::IrEntity> TranslatePiEntityForOrchAgent(
const p4::v1::Entity& pi_entity, const pdpi::IrP4Info& ir_p4_info,
bool translate_port_ids,
const boost::bimap<std::string, std::string>& port_translation_map,
const CpuQueueTranslator& cpu_queue_translator, bool translate_key_only) {
pdpi::IrEntity ir_entity;
switch (pi_entity.entity_case()) {
case p4::v1::Entity::kTableEntry: {
ASSIGN_OR_RETURN(
*ir_entity.mutable_table_entry(),
TranslatePiTableEntryForOrchAgent(
pi_entity.table_entry(), ir_p4_info, translate_port_ids,
port_translation_map, cpu_queue_translator, translate_key_only));
break;
}
case p4::v1::Entity::kPacketReplicationEngineEntry: {
// Updated in later CL in this chain.
ASSIGN_OR_RETURN(ir_entity,
pdpi::PiEntityToIr(ir_p4_info, pi_entity,
pdpi::TranslationOptions{
.key_only = translate_key_only,
}));
break;
}
default: {
ASSIGN_OR_RETURN(ir_entity,
pdpi::PiEntityToIr(ir_p4_info, pi_entity,
pdpi::TranslationOptions{
.key_only = translate_key_only,
}));
}
}
return ir_entity;
}

absl::StatusOr<pdpi::IrTableEntry> TranslatePiTableEntryForOrchAgent(
const p4::v1::TableEntry& pi_table_entry, const pdpi::IrP4Info& ir_p4_info,
bool translate_port_ids,
Expand Down
10 changes: 9 additions & 1 deletion p4rt_app/p4runtime/ir_translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ void TranslateIrP4InfoForOrchAgent(pdpi::IrP4Info& p4_info);
// If the IPv6 address is larger than 64 bits, does nothing.
void Convert64BitIpv6AclMatchFieldsTo128Bit(pdpi::IrTableEntry& ir_table_entry);

// Translates a PI table entry from the controller into an IR format with fields
// Translates a PI entity from the controller into an IR format with field
// values consumable by the OA.
absl::StatusOr<pdpi::IrEntity> TranslatePiEntityForOrchAgent(
const p4::v1::Entity& pi_entity, const pdpi::IrP4Info& ir_p4_info,
bool translate_port_ids,
const boost::bimap<std::string, std::string>& port_translation_map,
const CpuQueueTranslator& cpu_queue_translator, bool translate_key_only);

// Translates a PI table entry from the controller into an IR format with field
// values consumable by the OA.
absl::StatusOr<pdpi::IrTableEntry> TranslatePiTableEntryForOrchAgent(
const p4::v1::TableEntry& pi_table_entry, const pdpi::IrP4Info& ir_p4_info,
Expand Down
31 changes: 31 additions & 0 deletions p4rt_app/p4runtime/ir_translation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -797,5 +797,36 @@ TEST(TranslateTableEntry, FailsIfAppDbQueueIsNotAString) {
EXPECT_FALSE(TranslateTableEntry(options, ir_table_entry).ok());
}

TEST(TranslateEntity, FailsIfPacketReplicationHasDuplicateReplicas) {
p4::v1::Entity pi_entity;
// This packet replication entry is invalid, due to the duplicate replica.
ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(
R"pb(
packet_replication_engine_entry {
multicast_group_entry {
multicast_group_id: 1
replicas { port: "Ethernet0" instance: 0 }
replicas { port: "Ethernet0" instance: 0 }
}
}
)pb",
&pi_entity));

EXPECT_FALSE(TranslatePiEntityForOrchAgent(
pi_entity, GetIrP4Info(), /*translate_port_ids=*/true,
/*port_translation_map=*/{}, EmptyCpuQueueTranslator(),
/*translate_key_only=*/false)
.ok());
}

TEST(TranslateEntity, UnsupportedEntityTypeFails) {
p4::v1::Entity pi_entity;
EXPECT_FALSE(TranslatePiEntityForOrchAgent(
pi_entity, GetIrP4Info(), /*translate_port_ids=*/true,
/*port_translation_map=*/{}, EmptyCpuQueueTranslator(),
/*translate_key_only=*/false)
.ok());
}

} // namespace
} // namespace p4rt_app
Loading

0 comments on commit 301cbb0

Please sign in to comment.