Skip to content

Commit

Permalink
Set MISMATCH_NBR port error in LldpManager
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jleung51 authored and facebook-github-bot committed Dec 20, 2024
1 parent 68b49ee commit 2f569d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion fboss/agent/LldpManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() &&
Expand Down
20 changes: 13 additions & 7 deletions fboss/agent/test/LldpManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ using ::testing::_;
namespace {
// TODO(joseph5wu) Network control strict priority queue
const uint8_t kNCStrictPriorityQueue = 7;

unique_ptr<HwTestHandle> setupTestHandle(bool enableLldp = false) {
// Setup a default state object
// reusing this, as this seems to be legit RSW config under which we should
Expand Down Expand Up @@ -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> 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("<no name set>");
Expand Down Expand Up @@ -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(
Expand All @@ -395,4 +400,5 @@ TEST(LldpManagerTest, LldpValidationFail) {
lldpValidationFailHelper(
cfg::SwitchType::VOQ, PortID(5), std::nullopt /* vlanID */);
}

} // unnamed namespace

0 comments on commit 2f569d1

Please sign in to comment.