-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into HEAD
- Loading branch information
Showing
8 changed files
with
515 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
parameters: | ||
- name: timeout | ||
type: number | ||
default: 180 | ||
default: 240 | ||
|
||
- name: log_artifact_name | ||
type: string | ||
|
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,89 @@ | ||
#ifndef SONIC_SWSS_COMMON_COMMON_SAIACLSCHEMA_H_ | ||
#define SONIC_SWSS_COMMON_COMMON_SAIACLSCHEMA_H_ | ||
|
||
#include <set> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
// This file describes the AppDB ACL schema values between the P4RT app and | ||
// OrchAgent and the capabilities of OrchAgent. | ||
|
||
namespace swss | ||
{ | ||
namespace acl | ||
{ | ||
|
||
// Enumeration of ACL stages. | ||
enum class Stage | ||
{ | ||
kLookup, | ||
kIngress, | ||
kEgress | ||
}; | ||
|
||
// Enumeration of expected data formats for match fields and action parameters. | ||
enum class Format | ||
{ | ||
kNone, // No value is expected (e.g. DROP action). | ||
kHexString, // Numerical value represented as hexadecimal. "0x1234" | ||
kMac, // MAC address. "11:22:33:44:55:66" | ||
kIPv4, // IPv4 address in canonical format. "128.0.0.1" | ||
kIPv6, // IPv6 address in canonical format. "2002:1:128::" | ||
kString // String value. "Port0" | ||
}; | ||
|
||
// Schema information for deciphering match fields. | ||
struct MatchFieldSchema | ||
{ | ||
std::set<Stage> stages; // Stages where this match field can be used. | ||
Format format; // Expected format for this match field in AppDB. | ||
int bitwidth; // Bitwidth of the match field (if not string). | ||
}; | ||
|
||
// Schema information for deciphering actions and action parameters. | ||
struct ActionSchema | ||
{ | ||
Format format; // Expected format for the action parameter in AppDB. | ||
int bitwidth; // Bitwidth of the action parameter (if not string & not none). | ||
}; | ||
|
||
// Returns the SAI stage enum matching the AppDB name. | ||
// "LOOKUP" --> SAI_ACL_STAGE_LOOKUP (Not yet standard) | ||
// "INGRESS" --> SAI_ACL_STAGE_INGRESS | ||
// "EGRESS" --> SAI_ACL_STAGE_EGRESS | ||
// | ||
// Throws std::invalid_argument if the name does not match a stage. | ||
Stage StageFromName(const std::string &name); | ||
|
||
// Returns the AppDB name for a SAI stage enum. See StageFromName. | ||
const std::string &StageName(Stage stage); | ||
|
||
// Returns the Format enum matching the AppDB format name. | ||
// "HEX_STRING" --> kHexString | ||
// "MAC" --> kMac | ||
// "IP" --> kIP | ||
// "IPV6" --> kIPv6 | ||
// "IPV4" --> kIPv4 | ||
// "STRING" --> kString | ||
// | ||
// Throws std::invalid_argument if the name does not match a Format. | ||
Format FormatFromName(const std::string &name); | ||
|
||
// Returns the AppDB format name for a Format enum. | ||
const std::string &FormatName(Format format); | ||
|
||
// Returns the schema for a match field. | ||
// | ||
// Throws std::invalid_argument for unknown match fields and match fields | ||
// without schemas. | ||
const MatchFieldSchema &MatchFieldSchemaByName(const std::string &match_field_name); | ||
|
||
// Returns the schema for a action. | ||
// | ||
// Throws std::invalid_argument for unknown actions and actions without schemas. | ||
const ActionSchema &ActionSchemaByName(const std::string &action_name); | ||
|
||
} // namespace acl | ||
} // namespace swss | ||
|
||
#endif // SONIC_SWSS_COMMON_COMMON_SAIACLSCHEMA_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
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,87 @@ | ||
#include <gmock/gmock.h> | ||
#include <gtest/gtest.h> | ||
|
||
#include <stdexcept> | ||
|
||
#include "common/saiaclschema.h" | ||
|
||
namespace swss | ||
{ | ||
namespace acl | ||
{ | ||
namespace | ||
{ | ||
|
||
using ::testing::AllOf; | ||
using ::testing::Field; | ||
using ::testing::UnorderedElementsAre; | ||
|
||
class FormatTest : public testing::TestWithParam<Format> | ||
{ | ||
}; | ||
|
||
TEST_P(FormatTest, StringConversionIsConsistent) | ||
{ | ||
EXPECT_EQ(FormatFromName(FormatName(GetParam())), GetParam()); | ||
} | ||
|
||
INSTANTIATE_TEST_CASE_P(SaiAclSchemaTest, FormatTest, | ||
testing::Values(Format::kNone, Format::kHexString, Format::kMac, Format::kIPv4, Format::kIPv6, | ||
Format::kString), | ||
[](const testing::TestParamInfo<FormatTest::ParamType> ¶m_info) { | ||
return FormatName(param_info.param); | ||
}); | ||
|
||
class StageTest : public testing::TestWithParam<Stage> | ||
{ | ||
}; | ||
|
||
TEST_P(StageTest, StringConversionIsConsistent) | ||
{ | ||
EXPECT_EQ(StageFromName(StageName(GetParam())), GetParam()); | ||
} | ||
|
||
INSTANTIATE_TEST_CASE_P(SaiAclSchemaTest, StageTest, testing::Values(Stage::kLookup, Stage::kIngress, Stage::kEgress), | ||
[](const testing::TestParamInfo<StageTest::ParamType> ¶m_info) { | ||
return StageName(param_info.param); | ||
}); | ||
|
||
TEST(SaiAclSchemaTest, MatchFieldSchemaByNameSucceeds) | ||
{ | ||
EXPECT_THAT( | ||
MatchFieldSchemaByName("SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6"), | ||
AllOf(Field(&MatchFieldSchema::stages, UnorderedElementsAre(Stage::kLookup, Stage::kIngress, Stage::kEgress)), | ||
Field(&MatchFieldSchema::format, Format::kIPv6), Field(&MatchFieldSchema::bitwidth, 128))); | ||
} | ||
|
||
TEST(SaiAclSchemaTest, ActionSchemaByNameSucceeds) | ||
{ | ||
EXPECT_THAT(ActionSchemaByName("SAI_ACL_ENTRY_ATTR_ACTION_SET_INNER_VLAN_ID"), | ||
AllOf(Field(&ActionSchema::format, Format::kHexString), Field(&ActionSchema::bitwidth, 12))); | ||
} | ||
|
||
// Invalid Lookup Tests | ||
|
||
TEST(SaiAclSchemaTest, InvalidFormatNameThrowsException) | ||
{ | ||
EXPECT_THROW(FormatFromName("Foo"), std::invalid_argument); | ||
} | ||
|
||
TEST(SaiAclSchemaTest, InvalidStageNameThrowsException) | ||
{ | ||
EXPECT_THROW(StageFromName("Foo"), std::invalid_argument); | ||
} | ||
|
||
TEST(SaiAclSchemaTest, InvalidMatchFieldNameThrowsException) | ||
{ | ||
EXPECT_THROW(MatchFieldSchemaByName("Foo"), std::invalid_argument); | ||
} | ||
|
||
TEST(SaiAclSchemaTest, InvalidActionNameThrowsException) | ||
{ | ||
EXPECT_THROW(ActionSchemaByName("Foo"), std::invalid_argument); | ||
} | ||
|
||
} // namespace | ||
} // namespace acl | ||
} // namespace swss |