Skip to content

Commit

Permalink
Consider switch drain state when computing the blink state of LEDs
Browse files Browse the repository at this point in the history
Summary:
Today we only look at the portDrainState which will only be set when specific ports are drained. This doesn't indicate if the entire switch is drained. We need to account for switch drain state also so that we can blink LEDs indicating that the port is safe to operate or not.

Overall we blink the LED when

1. port is inactive (other side, either port or the entire switch, is drained)
2. local port state is drained (local port is drained)
3. local switch state is drained (local switch is drained)

Reviewed By: shri-khare

Differential Revision:
D64372511

Privacy Context Container: L1125642

fbshipit-source-id: 97707b5ba40a246af58673f05e9775b719077a20
  • Loading branch information
Harshit Gulati authored and facebook-github-bot committed Oct 15, 2024
1 parent e899f7f commit 30f0ea8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion fboss/led_service/FsdbSwitchStateSubscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ void FsdbSwitchStateSubscriber::subscribeToState(
// used by LED manager thread later
auto newSwitchStateData = apache::thrift::BinarySerializer::deserialize<
fboss::state::SwitchState>(*contents);
auto& swSettings = newSwitchStateData.switchSettingsMap().value();
auto swPortMaps = newSwitchStateData.portMaps().value();

std::map<short, LedManager::LedSwitchStateUpdate> ledSwitchStateUpdate;

for (auto& [switchStr, oneSwPortMap] : swPortMaps) {
bool switchDrained = false;
if (swSettings.find(switchStr) != swSettings.end()) {
switchDrained =
swSettings[switchStr].actualSwitchDrainState().value() ==
cfg::SwitchDrainState::DRAINED;
}
for (auto& [onePortId, onePortInfo] : oneSwPortMap) {
ledSwitchStateUpdate[onePortId].swPortId = onePortId;
ledSwitchStateUpdate[onePortId].portName =
Expand All @@ -72,8 +79,15 @@ void FsdbSwitchStateSubscriber::subscribeToState(
if (auto activeState = onePortInfo.portActiveState()) {
ledSwitchStateUpdate[onePortId].activeState = *activeState;
}
// We consider the port drained if either the individual port is
// drained or the entire switch is drained. This status is used to set
// blink pattern on the LEDs. We blink the LED when
// 1) port is inactive (other side, either port or the entire switch,
// is drained) 2) local port state is drained (local port is drained)
// 3) local switch state is drained (local switch is drained)
ledSwitchStateUpdate[onePortId].drained =
onePortInfo.get_drainState() == cfg::PortDrainState::DRAINED;
onePortInfo.get_drainState() == cfg::PortDrainState::DRAINED ||
switchDrained;
}
}

Expand Down

0 comments on commit 30f0ea8

Please sign in to comment.