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.
[P4-PDPI] Add entity-level convenience functions for reading entries …
…and deprecate table entry-level counterparts.Refactor SplitUpWriteRequest into ExtractWriteRequets to avoid copies.[PDPI] Add utility functions for determining if a field has a p4 runtime translated type.[p4rt session] Reduce log spam. (sonic-net#508) Co-authored-by: kishanps <[email protected]> Co-authored-by: smolkaj <[email protected]>
- Loading branch information
1 parent
286ce86
commit 6d37e7d
Showing
10 changed files
with
235 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "p4_pdpi/ir_properties.h" | ||
|
||
#include "p4/config/v1/p4info.pb.h" | ||
#include "p4_pdpi/ir.pb.h" | ||
|
||
namespace pdpi { | ||
|
||
bool HasP4RuntimeTranslatedType(const IrMatchFieldDefinition& match_field) { | ||
return match_field.match_field().has_type_name() && | ||
match_field.format() == pdpi::Format::STRING; | ||
} | ||
|
||
bool HasP4RuntimeTranslatedType( | ||
const IrActionDefinition::IrActionParamDefinition& param) { | ||
return param.param().has_type_name() && | ||
param.format() == pdpi::Format::STRING; | ||
} | ||
|
||
} // 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,19 @@ | ||
#ifndef PINS_P4_PDPI_IR_PROPERTIES_H_ | ||
#define PINS_P4_PDPI_IR_PROPERTIES_H_ | ||
|
||
#include "p4_pdpi/ir.pb.h" | ||
|
||
namespace pdpi { | ||
|
||
// Returns true if `match_field` has a P4Runtime-translated translated type,as | ||
// expressed through an @p4runtime_translation annotation. | ||
bool HasP4RuntimeTranslatedType(const IrMatchFieldDefinition& match_field); | ||
|
||
// Returns true if `param` has a P4Runtime-translated type, as expressed through | ||
// an @p4runtime_translation annotation | ||
bool HasP4RuntimeTranslatedType( | ||
const IrActionDefinition::IrActionParamDefinition& param); | ||
|
||
} // namespace pdpi | ||
|
||
#endif // PINS_P4_PDPI_IR_PROPERTIES_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,76 @@ | ||
#include "p4_pdpi/ir_properties.h" | ||
|
||
#include "gtest/gtest.h" | ||
#include "gutil/testing.h" | ||
|
||
namespace pdpi { | ||
namespace { | ||
|
||
using gutil::ParseProtoOrDie; | ||
|
||
TEST(HasP4RuntimeTranslatedType, P4RuntimeTranslatedTypeMatchFieldReturnsTrue) { | ||
EXPECT_FALSE( | ||
HasP4RuntimeTranslatedType(ParseProtoOrDie<IrMatchFieldDefinition>( | ||
R"pb( | ||
match_field { id: 1 name: "dragon_field" match_type: EXACT } | ||
format: HEX_STRING | ||
)pb"))); | ||
|
||
EXPECT_FALSE( | ||
HasP4RuntimeTranslatedType(ParseProtoOrDie<IrMatchFieldDefinition>( | ||
R"pb( | ||
match_field { | ||
id: 1 | ||
name: "dragon_field" | ||
match_type: EXACT | ||
type_name { name: "dragon_type" } | ||
} | ||
format: HEX_STRING | ||
)pb"))); | ||
|
||
EXPECT_TRUE( | ||
HasP4RuntimeTranslatedType(ParseProtoOrDie<IrMatchFieldDefinition>( | ||
R"pb( | ||
match_field { | ||
id: 1 | ||
name: "dragon_field" | ||
match_type: EXACT | ||
type_name { name: "dragon_type" } | ||
} | ||
format: STRING | ||
)pb"))); | ||
} | ||
|
||
TEST(HasP4RuntimeTranslatedType, P4RuntimeTranslatedTypeParameterReturnsTrue) { | ||
EXPECT_FALSE(HasP4RuntimeTranslatedType( | ||
ParseProtoOrDie<IrActionDefinition::IrActionParamDefinition>( | ||
R"pb( | ||
param { id: 1 name: "dragon_param" } | ||
format: HEX_STRING | ||
)pb"))); | ||
|
||
EXPECT_FALSE(HasP4RuntimeTranslatedType( | ||
ParseProtoOrDie<IrActionDefinition::IrActionParamDefinition>( | ||
R"pb( | ||
param { | ||
id: 1 | ||
name: "dragon_param" | ||
type_name { name: "dragon_type" } | ||
} | ||
format: HEX_STRING | ||
)pb"))); | ||
|
||
EXPECT_TRUE(HasP4RuntimeTranslatedType( | ||
ParseProtoOrDie<IrActionDefinition::IrActionParamDefinition>( | ||
R"pb( | ||
param { | ||
id: 1 | ||
name: "dragon_param" | ||
type_name { name: "dragon_type" } | ||
} | ||
format: STRING | ||
)pb"))); | ||
} | ||
|
||
} // 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
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.