Skip to content

Commit

Permalink
migrate update mirror tests from hw test to agent mirroring tests
Browse files Browse the repository at this point in the history
Summary: as titled

Reviewed By: jasmeetbagga

Differential Revision: D62596697

fbshipit-source-id: e0deda338f4bceeaacc10e951bdd73b9cc827af7
  • Loading branch information
Parvez Shaikh authored and facebook-github-bot committed Sep 19, 2024
1 parent b8dd697 commit 61014fb
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 124 deletions.
122 changes: 0 additions & 122 deletions fboss/agent/hw/test/HwMirrorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,74 +428,6 @@ TYPED_TEST(HwMirrorTest, PortMirrorUpdateIfMirrorUpdate) {
this->verifyAcrossWarmBoots(setup, verify);
}

TYPED_TEST(HwMirrorTest, UpdatePortMirror) {
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>(
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);

cfg.mirrors()[0] = this->getSpanMirror();
portCfg->ingressMirror().reset();
portCfg->egressMirror().reset();
portCfg = utility::findCfgPort(cfg, this->masterLogicalPortIds()[1]);
portCfg->ingressMirror() = kSpan;
portCfg->egressMirror() = kSpan;
this->applyNewConfig(cfg);
};
auto verify = [=, this]() {
auto mirror = this->getProgrammedState()->getMirrors()->getNodeIf(kSpan);
utility::verifyResolvedMirror(this->getHwSwitch(), mirror);
std::vector<uint64_t> 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());

utility::verifyPortMirrorDestination(
this->getHwSwitch(),
PortID(this->masterLogicalPortIds()[1]),
utility::getMirrorPortIngressFlags(),
destinations[0]);
utility::verifyPortMirrorDestination(
this->getHwSwitch(),
PortID(this->masterLogicalPortIds()[1]),
utility::getMirrorPortEgressFlags(),
destinations[0]);
};
if (this->skipMirrorTest()) {
#if defined(GTEST_SKIP)
GTEST_SKIP();
#endif
return;
}
this->verifyAcrossWarmBoots(setup, verify);
}

TYPED_TEST(HwMirrorTest, RemovePortMirror) {
auto setup = [=, this]() {
auto params = this->testParams();
Expand Down Expand Up @@ -715,60 +647,6 @@ TYPED_TEST(HwMirrorTest, HwUnresolvedMirrorStat) {
this->verifyAcrossWarmBoots(setup, verify);
}

TYPED_TEST(HwMirrorTest, UpdateAclMirror) {
auto setup = [=, this]() {
auto params = this->testParams();
auto cfg = this->initialConfig();
cfg.mirrors()->push_back(this->getSpanMirror());
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>(
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);

cfg.mirrors()->clear();
cfg.mirrors()->push_back(this->getSpanMirror());
for (auto& match2Action : *cfg.dataPlaneTrafficPolicy()->matchToAction()) {
if (*match2Action.matcher() == "acl0") {
match2Action.action()->ingressMirror() = kSpan;
match2Action.action()->egressMirror() = kSpan;
}
}
this->applyNewConfig(cfg);
};
auto verify = [=, this]() {
auto erspan = this->getProgrammedState()->getMirrors()->getNodeIf(kErspan);
EXPECT_EQ(erspan, nullptr);

auto span = this->getProgrammedState()->getMirrors()->getNodeIf(kSpan);
utility::verifyResolvedMirror(this->getHwSwitch(), span);
utility::verifyAclMirrorDestination(this->getHwSwitch(), kSpan);
};
if (this->skipMirrorTest()) {
#if defined(GTEST_SKIP)
GTEST_SKIP();
#endif
return;
}
this->verifyAcrossWarmBoots(setup, verify);
}

TYPED_TEST(HwMirrorTest, RemoveAclMirror) {
auto setup = [=, this]() {
auto params = this->testParams();
Expand Down
62 changes: 60 additions & 2 deletions fboss/agent/test/agent_hw_tests/AgentMirroringTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,10 @@ class AgentMirroringTest : public AgentHwTest {
for (auto switchID : scope.switchIds()) {
auto client = getAgentEnsemble()->getHwAgentTestClient(switchID);
verifyMirrorProgrammed(client.get(), fields);
EXPECT_TRUE(
client->sync_isAclEntryMirrored(kMirrorAcl, mirrorName, isIngress()));
WITH_RETRIES({
EXPECT_EVENTUALLY_TRUE(client->sync_isAclEntryMirrored(
kMirrorAcl, mirrorName, isIngress()));
});
}
}

Expand Down Expand Up @@ -288,6 +290,26 @@ class AgentMirroringTest : public AgentHwTest {
this->verifyAcrossWarmBoots(setup, verify);
}

void testUpdatePortMirror(const std::string& mirrorName) {
auto setup = [=, this]() {
this->resolveMirror(mirrorName);
auto cfg = initialConfig(*getAgentEnsemble());
cfg.mirrors()->clear();
utility::addMirrorConfig<AddrT>(
&cfg,
*getAgentEnsemble(),
mirrorName,
false /* truncate */,
48 /* dscp */);
this->applyNewConfig(cfg);
};
auto verify = [=, this]() {
this->verify(mirrorName);
this->verifyPortMirrorProgrammed(mirrorName);
};
this->verifyAcrossWarmBoots(setup, verify);
}

void testAclMirror(const std::string& mirrorName) {
auto setup = [=, this]() { this->resolveMirror(mirrorName); };
auto verify = [=, this]() {
Expand All @@ -297,6 +319,26 @@ class AgentMirroringTest : public AgentHwTest {
this->verifyAcrossWarmBoots(setup, verify);
}

void testUpdateAclMirror(const std::string& mirrorName) {
auto setup = [=, this]() {
this->resolveMirror(mirrorName);
auto cfg = initialConfig(*getAgentEnsemble());
cfg.mirrors()->clear();
utility::addMirrorConfig<AddrT>(
&cfg,
*getAgentEnsemble(),
mirrorName,
false /* truncate */,
48 /* dscp */);
this->applyNewConfig(cfg);
};
auto verify = [=, this]() {
this->verify(mirrorName);
this->verifyAclMirrorProgrammed(mirrorName);
};
this->verifyAcrossWarmBoots(setup, verify);
}

void testPortMirrorWithLargePacket(const std::string& mirrorName) {
auto setup = [=, this]() { this->resolveMirror(mirrorName); };
auto verify = [=, this]() {
Expand Down Expand Up @@ -571,18 +613,34 @@ TYPED_TEST(AgentIngressPortSpanMirroringTest, SpanPortMirror) {
this->testPortMirror(utility::kIngressSpan);
}

TYPED_TEST(AgentIngressPortSpanMirroringTest, UpdateSpanPortMirror) {
this->testUpdatePortMirror(kIngressSpan);
}

TYPED_TEST(AgentIngressPortErspanMirroringTest, ErspanPortMirror) {
this->testPortMirror(utility::kIngressErspan);
}

TYPED_TEST(AgentIngressPortErspanMirroringTest, UpdateErspanPortMirror) {
this->testUpdatePortMirror(kIngressErspan);
}

TYPED_TEST(AgentIngressAclSpanMirroringTest, SpanAclMirror) {
this->testAclMirror(utility::kIngressSpan);
}

TYPED_TEST(AgentIngressAclSpanMirroringTest, UpdateSpanAclMirror) {
this->testUpdateAclMirror(kIngressSpan);
}

TYPED_TEST(AgentIngressAclErspanMirroringTest, ErspanAclMirror) {
this->testAclMirror(utility::kIngressErspan);
}

TYPED_TEST(AgentIngressAclErspanMirroringTest, UpdateErspanAclMirror) {
this->testUpdateAclMirror(kIngressErspan);
}

TYPED_TEST(
AgentIngressPortErspanMirroringTruncateTest,
TrucatePortErspanMirror) {
Expand Down

0 comments on commit 61014fb

Please sign in to comment.