Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 53 additions & 25 deletions fboss/agent/test/agent_hw_tests/AgentHwAclQualifierTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,20 @@ class AgentHwAclQualifierTest : public AgentHwTest {
return newCfg;
}

SwitchID resolveSwitchId(std::optional<SwitchID> switchID) const {
return switchID.value_or(getCurrentSwitchIdForTesting());
}

void configureAllHwQualifiers(
cfg::AclEntry* acl,
bool enable,
SwitchID switchID = SwitchID(0)) {
std::optional<SwitchID> switchIDOpt = std::nullopt) {
SwitchID switchID = resolveSwitchId(switchIDOpt);
auto masterLogicalPorts =
getAgentEnsemble()->masterLogicalInterfacePortIds({switchID});
configureQualifier(acl->srcPort(), enable, masterLogicalPorts[0]);
CHECK_GE(masterLogicalPorts.size(), 1);
configureQualifier(acl->srcPort(), enable, masterLogicalPorts.at(0));

if ((hwAsicForSwitch(switchID)->getAsicType() !=
cfg::AsicType::ASIC_TYPE_JERICHO2) &&
(hwAsicForSwitch(switchID)->getAsicVendor() !=
Expand All @@ -198,13 +205,15 @@ class AgentHwAclQualifierTest : public AgentHwTest {
// No out support on Chenab in ingress stage
// No out port support on TU1 in ingress stage
// No out port support on TH6 in ingress stage
configureQualifier(acl->dstPort(), enable, masterLogicalPorts[1]);
CHECK_GE(masterLogicalPorts.size(), 2);
configureQualifier(acl->dstPort(), enable, masterLogicalPorts.at(1));
}
}

void configureAllL2QualifiersHelper(
cfg::AclEntry* acl,
SwitchID switchID = SwitchID(0)) {
std::optional<SwitchID> switchIDOpt = std::nullopt) {
SwitchID switchID = resolveSwitchId(switchIDOpt);
auto asic = hwAsicForSwitch(switchID);
bool dstMacEnabled =
(asic->getAsicVendor() != HwAsic::AsicVendor::ASIC_VENDOR_CHENAB);
Expand Down Expand Up @@ -242,7 +251,8 @@ class AgentHwAclQualifierTest : public AgentHwTest {

void configureIp4QualifiersHelper(
cfg::AclEntry* acl,
SwitchID switchID = SwitchID(0)) {
std::optional<SwitchID> switchIDOpt = std::nullopt) {
SwitchID switchID = resolveSwitchId(switchIDOpt);
auto asicType = getAsicType(switchID);
auto asicVendor = getAsicVendor(switchID);
bool enableSrcIpQualifier =
Expand All @@ -269,7 +279,8 @@ class AgentHwAclQualifierTest : public AgentHwTest {

void configureIp6QualifiersHelper(
cfg::AclEntry* acl,
SwitchID switchID = SwitchID(0)) {
std::optional<SwitchID> switchIDOpt = std::nullopt) {
SwitchID switchID = resolveSwitchId(switchIDOpt);
auto asicType = getAsicType(switchID);
auto asicVendor = getAsicVendor(switchID);
auto enableSrcIpQualifier =
Expand Down Expand Up @@ -304,7 +315,8 @@ class AgentHwAclQualifierTest : public AgentHwTest {
bool isIpV4,
QualifierType lookupClassType,
bool enableQualifiers = false,
SwitchID switchID = SwitchID(0)) {
std::optional<SwitchID> switchIDOpt = std::nullopt) {
SwitchID switchID = resolveSwitchId(switchIDOpt);
this->addQualifiers = enableQualifiers;
auto newCfg = initialConfig(*getAgentEnsemble());
if (FLAGS_enable_acl_table_group) {
Expand All @@ -328,17 +340,18 @@ class AgentHwAclQualifierTest : public AgentHwTest {
cfg::AclTableQualifier::OUTER_VLAN,
};

if (getAsicVendor() != HwAsic::AsicVendor::ASIC_VENDOR_CHENAB) {
if (getAsicVendor(switchID) != HwAsic::AsicVendor::ASIC_VENDOR_CHENAB) {
defaultQualifiers.clear();
}
std::vector<cfg::AclTableActionType> actions = {};
if (this->getAsicType() == cfg::AsicType::ASIC_TYPE_TOMAHAWKULTRA1) {
if (this->getAsicType(switchID) ==
cfg::AsicType::ASIC_TYPE_TOMAHAWKULTRA1) {
defaultQualifiers =
utility::genAclQualifiersConfig(this->getAsicType());
actions = utility::genAclActionTypesConfig(this->getAsicType());
utility::genAclQualifiersConfig(this->getAsicType(switchID));
actions = utility::genAclActionTypesConfig(this->getAsicType(switchID));
}
std::vector<cfg::AclTableQualifier> qualifiers = enableQualifiers
? utility::genAclQualifiersConfig(this->getAsicType())
? utility::genAclQualifiersConfig(this->getAsicType(switchID))
: defaultQualifiers;
utility::addAclTable(
&newCfg,
Expand Down Expand Up @@ -391,7 +404,8 @@ class AgentHwAclQualifierTest : public AgentHwTest {
}

void aclVerifyHelper() {
auto client = getAgentEnsemble()->getHwAgentTestClient(SwitchID(0));
SwitchID switchID = getCurrentSwitchIdForTesting();
auto client = getAgentEnsemble()->getHwAgentTestClient(switchID);
auto state = getAgentEnsemble()->getProgrammedState();
auto acl =
utility::getAclEntry(state, kAclName(), FLAGS_enable_acl_table_group)
Expand All @@ -402,11 +416,15 @@ class AgentHwAclQualifierTest : public AgentHwTest {
EXPECT_TRUE(client->sync_isAclEntrySame(acl, utility::kDefaultAclTable()));
}

cfg::AsicType getAsicType(SwitchID switchID = SwitchID(0)) {
cfg::AsicType getAsicType(
std::optional<SwitchID> switchIDOpt = std::nullopt) {
SwitchID switchID = resolveSwitchId(switchIDOpt);
return hwAsicForSwitch(switchID)->getAsicType();
}

HwAsic::AsicVendor getAsicVendor(SwitchID switchID = SwitchID(0)) {
HwAsic::AsicVendor getAsicVendor(
std::optional<SwitchID> switchIDOpt = std::nullopt) {
SwitchID switchID = resolveSwitchId(switchIDOpt);
return hwAsicForSwitch(switchID)->getAsicVendor();
}
};
Expand All @@ -430,7 +448,8 @@ TEST_F(AgentHwAclQualifierTest, AclIp4TcpQualifiers) {
};

auto verify = [=, this]() {
auto client = getAgentEnsemble()->getHwAgentTestClient(SwitchID(0));
auto client = getAgentEnsemble()->getHwAgentTestClient(
getCurrentSwitchIdForTesting());
auto state = getAgentEnsemble()->getProgrammedState();
auto acl =
utility::getAclEntry(state, "ip4_tcp", FLAGS_enable_acl_table_group)
Expand Down Expand Up @@ -463,7 +482,8 @@ TEST_F(AgentHwAclQualifierTest, AclIp6TcpQualifiers) {
};

auto verify = [=, this]() {
auto client = getAgentEnsemble()->getHwAgentTestClient(SwitchID(0));
auto client = getAgentEnsemble()->getHwAgentTestClient(
getCurrentSwitchIdForTesting());
auto state = getAgentEnsemble()->getProgrammedState();
auto acl =
utility::getAclEntry(state, "ip6_tcp", FLAGS_enable_acl_table_group)
Expand Down Expand Up @@ -496,7 +516,8 @@ TEST_F(AgentHwAclQualifierTest, AclIcmp4Qualifiers) {
};

auto verify = [=, this]() {
auto client = getAgentEnsemble()->getHwAgentTestClient(SwitchID(0));
auto client = getAgentEnsemble()->getHwAgentTestClient(
getCurrentSwitchIdForTesting());
auto state = getAgentEnsemble()->getProgrammedState();
auto acl =
utility::getAclEntry(state, "icmp4", FLAGS_enable_acl_table_group)
Expand Down Expand Up @@ -535,7 +556,8 @@ TEST_F(AgentHwAclQualifierTest, AclIcmp6Qualifiers) {
};

auto verify = [=, this]() {
auto client = getAgentEnsemble()->getHwAgentTestClient(SwitchID(0));
auto client = getAgentEnsemble()->getHwAgentTestClient(
getCurrentSwitchIdForTesting());
auto state = getAgentEnsemble()->getProgrammedState();
auto acl =
utility::getAclEntry(state, "icmp6", FLAGS_enable_acl_table_group)
Expand Down Expand Up @@ -586,7 +608,8 @@ TEST_F(AgentHwAclQualifierTest, AclRemove) {
};

auto verify = [=, this]() {
auto client = getAgentEnsemble()->getHwAgentTestClient(SwitchID(0));
auto client = getAgentEnsemble()->getHwAgentTestClient(
getCurrentSwitchIdForTesting());
auto state = getAgentEnsemble()->getProgrammedState();
auto acl = utility::getAclEntry(state, "acl1", FLAGS_enable_acl_table_group)
->toThrift();
Expand Down Expand Up @@ -631,7 +654,8 @@ TEST_F(AgentHwAclQualifierTest, AclModifyQualifier) {
};

auto verify = [=, this]() {
auto client = getAgentEnsemble()->getHwAgentTestClient(SwitchID(0));
auto client = getAgentEnsemble()->getHwAgentTestClient(
getCurrentSwitchIdForTesting());
auto state = getAgentEnsemble()->getProgrammedState();
auto acl = utility::getAclEntry(state, "acl0", FLAGS_enable_acl_table_group)
->toThrift();
Expand Down Expand Up @@ -681,7 +705,8 @@ TEST_F(AgentHwAclQualifierTest, AclEmptyCodeIcmp) {
};

auto verify = [=, this]() {
auto client = getAgentEnsemble()->getHwAgentTestClient(SwitchID(0));
auto client = getAgentEnsemble()->getHwAgentTestClient(
getCurrentSwitchIdForTesting());
auto state = getAgentEnsemble()->getProgrammedState();
auto acl =
utility::getAclEntry(state, "acl0", FLAGS_enable_acl_table_group);
Expand Down Expand Up @@ -711,7 +736,8 @@ TEST_F(AgentHwAclQualifierTest, AclVlanIDQualifier) {
};

auto verify = [=, this]() {
auto client = getAgentEnsemble()->getHwAgentTestClient(SwitchID(0));
auto client = getAgentEnsemble()->getHwAgentTestClient(
getCurrentSwitchIdForTesting());
auto state = getAgentEnsemble()->getProgrammedState();
EXPECT_EQ(
client->sync_getAclTableNumAclEntries(utility::kDefaultAclTable()), 1);
Expand All @@ -737,7 +763,8 @@ TEST_F(AgentHwAclQualifierTest, AclIp4Qualifiers) {
};

auto verify = [=, this]() {
auto client = getAgentEnsemble()->getHwAgentTestClient(SwitchID(0));
auto client = getAgentEnsemble()->getHwAgentTestClient(
getCurrentSwitchIdForTesting());
auto state = getAgentEnsemble()->getProgrammedState();

EXPECT_EQ(
Expand Down Expand Up @@ -770,7 +797,8 @@ TEST_F(AgentHwAclQualifierTest, AclIp6Qualifiers) {
};

auto verify = [=, this]() {
auto client = getAgentEnsemble()->getHwAgentTestClient(SwitchID(0));
auto client = getAgentEnsemble()->getHwAgentTestClient(
getCurrentSwitchIdForTesting());
auto state = getAgentEnsemble()->getProgrammedState();

EXPECT_EQ(
Expand Down
Loading