From bccb69b604eff455e51354ea53ed5e796af9f6af Mon Sep 17 00:00:00 2001 From: Parvez Shaikh Date: Thu, 19 Sep 2024 10:20:03 -0700 Subject: [PATCH] migrate remove mirror tests from hw test to agent mirroring tests Summary: as titled Reviewed By: jasmeetbagga Differential Revision: D62768987 fbshipit-source-id: 709b0936036cbedbb58f696385590e7b7b789bcd --- fboss/agent/hw/test/HwMirrorTests.cpp | 129 ------------------ .../agent_hw_tests/AgentMirroringTests.cpp | 38 ++++++ 2 files changed, 38 insertions(+), 129 deletions(-) diff --git a/fboss/agent/hw/test/HwMirrorTests.cpp b/fboss/agent/hw/test/HwMirrorTests.cpp index 85784e24a44ef..5030505686a32 100644 --- a/fboss/agent/hw/test/HwMirrorTests.cpp +++ b/fboss/agent/hw/test/HwMirrorTests.cpp @@ -192,34 +192,6 @@ class HwMirrorTest : public HwTest { TYPED_TEST_SUITE(HwMirrorTest, TestTypes); -TYPED_TEST(HwMirrorTest, MirrorRemoved) { - auto setup = [=, this]() { - auto cfg = this->initialConfig(); - cfg.mirrors()->push_back(this->getSpanMirror()); - cfg.mirrors()->push_back(this->getErspanMirror()); - this->applyNewConfig(cfg); - auto newState = this->getProgrammedState()->clone(); - auto mnpuMirrors = - this->getProgrammedState()->getMirrors()->modify(&newState); - auto mirror = mnpuMirrors->getNodeIf(kSpan); - mnpuMirrors->removeNode(mirror); - this->applyNewState(newState); - }; - auto verify = [=, this]() { - auto local = this->getProgrammedState()->getMirrors()->getNodeIf(kSpan); - EXPECT_EQ(local, nullptr); - auto erspan = this->getProgrammedState()->getMirrors()->getNodeIf(kErspan); - utility::verifyUnResolvedMirror(this->getHwSwitch(), erspan); - }; - if (this->skipMirrorTest()) { -#if defined(GTEST_SKIP) - GTEST_SKIP(); -#endif - return; - } - this->verifyAcrossWarmBoots(setup, verify); -} - TYPED_TEST(HwMirrorTest, UnresolvedToUnresolvedUpdate) { auto setup = [=, this]() { auto params = this->testParams(); @@ -428,59 +400,6 @@ TYPED_TEST(HwMirrorTest, PortMirrorUpdateIfMirrorUpdate) { this->verifyAcrossWarmBoots(setup, verify); } -TYPED_TEST(HwMirrorTest, RemovePortMirror) { - auto setup = [=, this]() { - auto params = this->testParams(); - auto cfg = this->initialConfig(); - cfg.mirrors()->push_back(this->getErspanMirror()); - auto portCfg = utility::findCfgPort(cfg, this->masterLogicalPortIds()[0]); - portCfg->ingressMirror() = kErspan; - portCfg->egressMirror() = kErspan; - this->applyNewConfig(cfg); - - auto mirror = this->getProgrammedState()->getMirrors()->getNodeIf(kErspan); - auto newMirror = std::make_shared( - mirror->getID(), - mirror->getEgressPortDesc(), - mirror->getDestinationIp()); - newMirror->setEgressPortDesc( - PortDescriptor(this->masterLogicalPortIds()[1])); - newMirror->setMirrorTunnel(MirrorTunnel( - params.ipAddrs[2], - params.ipAddrs[3], - params.macAddrs[2], - params.macAddrs[3])); - this->updateMirror(newMirror); - - portCfg->ingressMirror().reset(); - portCfg->egressMirror().reset(); - this->applyNewConfig(cfg); - }; - auto verify = [=, this]() { - auto mirror = this->getProgrammedState()->getMirrors()->getNodeIf(kErspan); - utility::verifyResolvedMirror(this->getHwSwitch(), mirror); - std::vector destinations; - utility::getAllMirrorDestinations(this->getHwSwitch(), destinations); - ASSERT_EQ(destinations.size(), 1); - - utility::verifyPortNoMirrorDestination( - this->getHwSwitch(), - PortID(this->masterLogicalPortIds()[0]), - utility::getMirrorPortIngressFlags()); - utility::verifyPortNoMirrorDestination( - this->getHwSwitch(), - PortID(this->masterLogicalPortIds()[0]), - utility::getMirrorPortEgressFlags()); - }; - if (this->skipMirrorTest()) { -#if defined(GTEST_SKIP) - GTEST_SKIP(); -#endif - return; - } - this->verifyAcrossWarmBoots(setup, verify); -} - TYPED_TEST(HwMirrorTest, HwMirrorStat) { auto setup = [=, this]() { auto cfg = this->initialConfig(); @@ -647,54 +566,6 @@ TYPED_TEST(HwMirrorTest, HwUnresolvedMirrorStat) { this->verifyAcrossWarmBoots(setup, verify); } -TYPED_TEST(HwMirrorTest, RemoveAclMirror) { - auto setup = [=, this]() { - auto params = this->testParams(); - auto cfg = this->initialConfig(); - cfg.mirrors()->push_back(this->getErspanMirror()); - cfg::AclEntry acl; - acl.name() = "acl0"; - acl.dstIp() = "192.168.0.0/16"; - this->addAclMirror(kErspan, acl, cfg); - this->applyNewConfig(cfg); - - auto mirrors = this->getProgrammedState()->getMirrors(); - auto mirror = mirrors->getNodeIf(kErspan); - auto newMirror = std::make_shared( - mirror->getID(), - mirror->getEgressPortDesc(), - mirror->getDestinationIp()); - newMirror->setEgressPortDesc( - PortDescriptor(this->masterLogicalPortIds()[1])); - newMirror->setMirrorTunnel(MirrorTunnel( - params.ipAddrs[2], - params.ipAddrs[3], - params.macAddrs[2], - params.macAddrs[3])); - this->updateMirror(newMirror); - - for (auto& match2Action : *cfg.dataPlaneTrafficPolicy()->matchToAction()) { - if (*match2Action.matcher() == "acl0") { - match2Action.action()->ingressMirror().reset(); - match2Action.action()->egressMirror().reset(); - } - } - this->applyNewConfig(cfg); - }; - auto verify = [=, this]() { - auto mirror = this->getProgrammedState()->getMirrors()->getNodeIf(kErspan); - utility::verifyResolvedMirror(this->getHwSwitch(), mirror); - utility::verifyNoAclMirrorDestination(this->getHwSwitch(), kErspan); - }; - if (this->skipMirrorTest()) { -#if defined(GTEST_SKIP) - GTEST_SKIP(); -#endif - return; - } - this->verifyAcrossWarmBoots(setup, verify); -} - TYPED_TEST(HwMirrorTest, HwMirrorLimitExceeded) { if (this->skipMirrorTest()) { #if defined(GTEST_SKIP) diff --git a/fboss/agent/test/agent_hw_tests/AgentMirroringTests.cpp b/fboss/agent/test/agent_hw_tests/AgentMirroringTests.cpp index b925b427cb7a5..0296037d46ce8 100644 --- a/fboss/agent/test/agent_hw_tests/AgentMirroringTests.cpp +++ b/fboss/agent/test/agent_hw_tests/AgentMirroringTests.cpp @@ -339,6 +339,36 @@ class AgentMirroringTest : public AgentHwTest { this->verifyAcrossWarmBoots(setup, verify); } + void testRemoveMirror(const std::string& mirrorName) { + auto setup = [=, this]() { + const auto& ensemble = *getAgentEnsemble(); + this->resolveMirror(mirrorName); + + auto config = utility::onePortPerInterfaceConfig( + ensemble.getSw(), + ensemble.masterLogicalPortIds(), + true /*interfaceHasSubnet*/); + + this->applyNewConfig(config); + }; + auto verify = [=, this]() { + auto mirror = getProgrammedState()->getMirrors()->getNodeIf(mirrorName); + EXPECT_EQ(mirror, nullptr); + auto scopeResolver = getAgentEnsemble()->getSw()->getScopeResolver(); + auto scope = scopeResolver->scope(mirror); + for (auto switchID : scope.switchIds()) { + auto client = getAgentEnsemble()->getHwAgentTestClient(switchID); + WITH_RETRIES({ + EXPECT_EVENTUALLY_FALSE(client->sync_isPortMirrored( + getTrafficPort(*getAgentEnsemble()), mirrorName, isIngress())); + EXPECT_TRUE(client->sync_isAclEntryMirrored( + kMirrorAcl, mirrorName, isIngress())); + }); + } + }; + this->verifyAcrossWarmBoots(setup, verify); + } + void testPortMirrorWithLargePacket(const std::string& mirrorName) { auto setup = [=, this]() { this->resolveMirror(mirrorName); }; auto verify = [=, this]() { @@ -617,10 +647,18 @@ TYPED_TEST(AgentIngressPortSpanMirroringTest, UpdateSpanPortMirror) { this->testUpdatePortMirror(kIngressSpan); } +TYPED_TEST(AgentIngressAclSpanMirroringTest, RemoveSpanMirror) { + this->testRemoveMirror(utility::kIngressSpan); +} + TYPED_TEST(AgentIngressPortErspanMirroringTest, ErspanPortMirror) { this->testPortMirror(utility::kIngressErspan); } +TYPED_TEST(AgentIngressAclSpanMirroringTest, RemoveErspanMirror) { + this->testRemoveMirror(utility::kIngressErspan); +} + TYPED_TEST(AgentIngressPortErspanMirroringTest, UpdateErspanPortMirror) { this->testUpdatePortMirror(kIngressErspan); }