forked from sonic-net/sonic-pins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PDPI] Add SortEntities to sequencing. (sonic-net#480)
Co-authored-by: jonathan-dilorenzo <[email protected]>
- Loading branch information
1 parent
c9dcabe
commit b0b2a3a
Showing
11 changed files
with
931 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "p4_pdpi/helpers.h" | ||
|
||
#include <string> | ||
|
||
#include "absl/status/statusor.h" | ||
#include "gutil/collections.h" | ||
#include "gutil/status.h" | ||
#include "p4/config/v1/p4info.pb.h" | ||
#include "p4/v1/p4runtime.pb.h" | ||
#include "p4_pdpi/built_ins.h" | ||
#include "p4_pdpi/ir.pb.h" | ||
|
||
namespace pdpi { | ||
|
||
absl::StatusOr<std::string> EntityToTableName(const pdpi::IrP4Info& info, | ||
const p4::v1::Entity& entity) { | ||
switch (entity.entity_case()) { | ||
case p4::v1::Entity::kTableEntry: { | ||
ASSIGN_OR_RETURN(const IrTableDefinition table, | ||
gutil::FindOrStatus(info.tables_by_id(), | ||
entity.table_entry().table_id())); | ||
return table.preamble().alias(); | ||
} | ||
case p4::v1::Entity::kPacketReplicationEngineEntry: { | ||
if (!entity.packet_replication_engine_entry() | ||
.has_multicast_group_entry()) { | ||
return gutil::InvalidArgumentErrorBuilder() | ||
<< "Expected a `multicast_group_entry`, but got unexpected " | ||
"packet_replication_engine_entry: " | ||
<< entity.packet_replication_engine_entry().DebugString(); | ||
} | ||
return GetMulticastGroupTableName(); | ||
} | ||
default: | ||
return gutil::InvalidArgumentErrorBuilder() | ||
<< "Expected a `table_entry` or " | ||
"`packet_replication_engine_entry`, but got unexpected entity:" | ||
<< entity.DebugString(); | ||
} | ||
} | ||
|
||
} // namespace pdpi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef PINS_P4_PDPI_HELPERS_H_ | ||
#define PINS_P4_PDPI_HELPERS_H_ | ||
|
||
#include <string> | ||
|
||
#include "absl/status/statusor.h" | ||
#include "p4/v1/p4runtime.pb.h" | ||
#include "p4_pdpi/ir.pb.h" | ||
|
||
namespace pdpi { | ||
|
||
// Returns the table name associated with the given entity. | ||
absl::StatusOr<std::string> EntityToTableName(const IrP4Info& info, | ||
const p4::v1::Entity& entity); | ||
} // namespace pdpi | ||
|
||
#endif // PINS_P4_PDPI_HELPERS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "p4_pdpi/helpers.h" | ||
|
||
#include <string> | ||
|
||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
#include "gutil/status_matchers.h" | ||
#include "p4/v1/p4runtime.pb.h" | ||
#include "p4_pdpi/built_ins.h" | ||
#include "p4_pdpi/ir.pb.h" | ||
#include "p4_pdpi/testing/test_p4info.h" | ||
|
||
namespace pdpi { | ||
namespace { | ||
|
||
using gutil::IsOk; | ||
using gutil::IsOkAndHolds; | ||
using testing::Not; | ||
|
||
TEST(EntityToTableNameTest, StandardTableSupported) { | ||
IrP4Info kInfo = GetTestIrP4Info(); | ||
IrTableDefinition kTestTable = kInfo.tables_by_id().begin()->second; | ||
p4::v1::Entity entity; | ||
entity.mutable_table_entry()->set_table_id(kTestTable.preamble().id()); | ||
|
||
EXPECT_THAT(EntityToTableName(kInfo, entity), | ||
IsOkAndHolds(kTestTable.preamble().alias())); | ||
} | ||
|
||
TEST(EntityToTableNameTest, MulticastTableSupported) { | ||
p4::v1::Entity entity; | ||
entity.mutable_packet_replication_engine_entry() | ||
->mutable_multicast_group_entry(); | ||
|
||
ASSERT_OK_AND_ASSIGN( | ||
std::string multicast_group_table_name, | ||
IrBuiltInTableToString(BUILT_IN_TABLE_MULTICAST_GROUP_TABLE)); | ||
|
||
EXPECT_THAT(EntityToTableName(GetTestIrP4Info(), entity), | ||
IsOkAndHolds(multicast_group_table_name)); | ||
} | ||
|
||
TEST(EntityToTableNameTest, OtherPacketReplicationEngineUnsupported) { | ||
p4::v1::Entity entity; | ||
entity.mutable_packet_replication_engine_entry() | ||
->mutable_clone_session_entry(); | ||
|
||
EXPECT_THAT(EntityToTableName(GetTestIrP4Info(), entity), Not(IsOk())); | ||
} | ||
|
||
TEST(EntityToTableNameTest, OtherEntitiesUnsupported) { | ||
p4::v1::Entity entity; | ||
entity.mutable_direct_counter_entry(); | ||
|
||
EXPECT_THAT(EntityToTableName(GetTestIrP4Info(), entity), Not(IsOk())); | ||
} | ||
|
||
} // namespace | ||
} // namespace pdpi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.