From 2f569d148ede674ab6ce2020577279358df03635 Mon Sep 17 00:00:00 2001 From: Jeffrey Leung Date: Thu, 19 Dec 2024 17:27:28 -0800 Subject: [PATCH] Set MISMATCH_NBR port error in LldpManager Summary: Set PortError to the new value of MISMATCHED_NEIGHBOR when an endpoint does not match the expected neighbor in config in LldpManager. Reviewed By: jasmeetbagga Differential Revision: D66662930 fbshipit-source-id: 6eafd30b225fa3d70aa548a85c578a3c5ef27ca0 --- fboss/agent/LldpManager.cpp | 3 ++- fboss/agent/test/LldpManagerTest.cpp | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fboss/agent/LldpManager.cpp b/fboss/agent/LldpManager.cpp index 491fa2e86f3af..348e666ca2aec 100644 --- a/fboss/agent/LldpManager.cpp +++ b/fboss/agent/LldpManager.cpp @@ -135,9 +135,10 @@ void LldpManager::handlePacket( auto newState = state->clone(); auto newPort = state->getPorts()->getNodeIf(pid)->modify(&newState); newPort->setLedPortExternalState(PortLedExternalState::CABLING_ERROR); + newPort->addError(PortError::MISMATCHED_NEIGHBOR); return newState; }; - sw_->updateState("set port LED state from lldp", updateFn); + sw_->updateState("set port error and LED state from lldp", updateFn); } else { // clear the cabling error led state if needed if (port->getLedPortExternalState().has_value() && diff --git a/fboss/agent/test/LldpManagerTest.cpp b/fboss/agent/test/LldpManagerTest.cpp index eaa08deea6bc4..12b93cdbbae84 100644 --- a/fboss/agent/test/LldpManagerTest.cpp +++ b/fboss/agent/test/LldpManagerTest.cpp @@ -42,6 +42,7 @@ using ::testing::_; namespace { // TODO(joseph5wu) Network control strict priority queue const uint8_t kNCStrictPriorityQueue = 7; + unique_ptr setupTestHandle(bool enableLldp = false) { // Setup a default state object // reusing this, as this seems to be legit RSW config under which we should @@ -315,19 +316,21 @@ TEST(LldpManagerTest, LldpValidationPass) { lldpValidationPassHelper(cfg::SwitchType::VOQ, std::nullopt /* vlanID */); } -TEST(LldpManagerTest, LldpValidationFail) { +TEST(LldpManagerTest, MismatchedNeighbor) { auto lldpValidationFailHelper = [](cfg::SwitchType switchType, PortID portID, std::optional vlanID) { + auto systemName = "somesysname0"; + auto portName = "portname"; + cfg::SwitchConfig config = testConfigA(switchType); *config.ports()[0].routable() = true; config.ports()[0].Port::name() = "FooP0"; config.ports()[0].Port::description() = "FooP0 Port Description here"; config.ports()[0].expectedLLDPValues()[cfg::LLDPTag::SYSTEM_NAME] = - "somesysname0"; - config.ports()[0].expectedLLDPValues()[cfg::LLDPTag::PORT_DESC] = - "someportdesc0"; + systemName; + config.ports()[0].expectedLLDPValues()[cfg::LLDPTag::PORT] = portName; for (const auto& v : *config.ports()[0].expectedLLDPValues()) { auto port_name = std::string(""); @@ -372,14 +375,16 @@ TEST(LldpManagerTest, LldpValidationFail) { EXPECT_EQ( port->getLedPortExternalState().value(), PortLedExternalState::CABLING_ERROR); + EXPECT_EQ(port->getActiveErrors().size(), 1); + EXPECT_EQ(port->getActiveErrors().at(0), PortError::MISMATCHED_NEIGHBOR); auto validPkt = LldpManager::createLldpPkt( sw, MacAddress("2:2:2:2:2:10"), vlanID, - "somesysname0", - "someportdesc0", - "somedesc", + systemName, + portName, + "someportdesc", 1, LldpManager::SYSTEM_CAPABILITY_ROUTER); handle->rxPacket( @@ -395,4 +400,5 @@ TEST(LldpManagerTest, LldpValidationFail) { lldpValidationFailHelper( cfg::SwitchType::VOQ, PortID(5), std::nullopt /* vlanID */); } + } // unnamed namespace