Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meru800bia: adds initial data_corral_service support #151

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmake/PlatformDataCorralService.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ add_library(data_corral_service_lib
fboss/platform/data_corral_service/darwin/DarwinChassisManager.cpp
fboss/platform/data_corral_service/darwin/DarwinPlatformConfig.cpp
fboss/platform/data_corral_service/darwin/DarwinFruModule.cpp
fboss/platform/data_corral_service/meru800bia/Meru800biaChassisManager.cpp
fboss/platform/data_corral_service/meru800bia/Meru800biaPlatformConfig.cpp
fboss/platform/data_corral_service/meru800bia/Meru800biaFruModule.cpp
)

target_link_libraries(data_corral_service_lib
Expand Down
8 changes: 8 additions & 0 deletions fboss/platform/data_corral_service/ChassisManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,12 @@ class ChassisManager {
std::unique_ptr<ChassisMonitor> monitor_;
};

enum ChassisLedColor {
OFF = 0,
RED = 1,
GREEN = 2,
BLUE = 3,
AMBER = 4,
};

} // namespace facebook::fboss::platform::data_corral_service
4 changes: 4 additions & 0 deletions fboss/platform/data_corral_service/DataCorralServiceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "fboss/lib/platforms/PlatformProductInfo.h"
#include "fboss/platform/data_corral_service/DataCorralServiceImpl.h"
#include "fboss/platform/data_corral_service/darwin/DarwinChassisManager.h"
#include "fboss/platform/data_corral_service/meru800bia/Meru800biaChassisManager.h"
#include "fboss/platform/weutil/Weutil.h"

namespace {
Expand All @@ -38,6 +39,9 @@ void DataCorralServiceImpl::init() {
if (type == PlatformType::PLATFORM_DARWIN) {
chassisManager_ =
std::make_unique<DarwinChassisManager>(kRefreshIntervalInMs);
} else if (type == PlatformType::PLATFORM_MERU800BIA) {
chassisManager_ =
std::make_unique<Meru800biaChassisManager>(kRefreshIntervalInMs);
} else {
XLOG(WARN) << "Unable to instantiate ChassisManager for platform "
<< toString(type);
Expand Down
34 changes: 17 additions & 17 deletions fboss/platform/data_corral_service/darwin/DarwinChassisManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ const std::string kSetColorFailure = "set.color.failure";
namespace facebook::fboss::platform::data_corral_service {

void DarwinChassisLed::setColorPath(
DarwinLedColor color,
ChassisLedColor color,
const std::string& path) {
XLOG(DBG2) << "led " << name_ << ", color " << color << ", sysfs path "
<< path;
paths_[color] = path;
}

void DarwinChassisLed::setColor(DarwinLedColor color) {
void DarwinChassisLed::setColor(ChassisLedColor color) {
if (color_ != color) {
if (!facebook::fboss::writeSysfs(paths_[color], "1")) {
XLOG(ERR) << "failed to set color " << color << " for led " << name_;
Expand All @@ -61,7 +61,7 @@ void DarwinChassisLed::setColor(DarwinLedColor color) {
fb303::fbData->setCounter(kSetColorFailure, 0);
}

DarwinLedColor DarwinChassisLed::getColor() {
ChassisLedColor DarwinChassisLed::getColor() {
for (auto const& colorPath : paths_) {
std::string brightness = facebook::fboss::readSysfs(colorPath.second);
try {
Expand All @@ -75,7 +75,7 @@ DarwinLedColor DarwinChassisLed::getColor() {
throw;
}
}
return DarwinLedColor::OFF;
return ChassisLedColor::OFF;
}

void DarwinChassisManager::initModules() {
Expand All @@ -94,43 +94,43 @@ void DarwinChassisManager::initModules() {
pemLed_ = std::make_unique<DarwinChassisLed>(kPemLed);
for (auto attr : *platformConfig.chassisAttributes()) {
if (*attr.name() == kSystemLed + kLedRed) {
sysLed_->setColorPath(DarwinLedColor::RED, *attr.path());
sysLed_->setColorPath(ChassisLedColor::RED, *attr.path());
} else if (*attr.name() == kSystemLed + kLedGreen) {
sysLed_->setColorPath(DarwinLedColor::GREEN, *attr.path());
sysLed_->setColorPath(ChassisLedColor::GREEN, *attr.path());
} else if (*attr.name() == kFanLed + kLedRed) {
fanLed_->setColorPath(DarwinLedColor::RED, *attr.path());
fanLed_->setColorPath(ChassisLedColor::RED, *attr.path());
} else if (*attr.name() == kFanLed + kLedGreen) {
fanLed_->setColorPath(DarwinLedColor::GREEN, *attr.path());
fanLed_->setColorPath(ChassisLedColor::GREEN, *attr.path());
} else if (*attr.name() == kPemLed + kLedRed) {
pemLed_->setColorPath(DarwinLedColor::RED, *attr.path());
pemLed_->setColorPath(ChassisLedColor::RED, *attr.path());
} else if (*attr.name() == kPemLed + kLedGreen) {
pemLed_->setColorPath(DarwinLedColor::GREEN, *attr.path());
pemLed_->setColorPath(ChassisLedColor::GREEN, *attr.path());
}
}
}

void DarwinChassisManager::programChassis() {
DarwinLedColor sysLedColor = DarwinLedColor::GREEN;
DarwinLedColor fanLedColor = DarwinLedColor::GREEN;
DarwinLedColor pemLedColor = DarwinLedColor::GREEN;
ChassisLedColor sysLedColor = ChassisLedColor::GREEN;
ChassisLedColor fanLedColor = ChassisLedColor::GREEN;
ChassisLedColor pemLedColor = ChassisLedColor::GREEN;

for (auto& fru : fruModules_) {
if (!fru.second->isPresent()) {
XLOG(DBG2) << "Fru module " << fru.first << " is absent";
sysLedColor = DarwinLedColor::RED;
sysLedColor = ChassisLedColor::RED;
if (std::strncmp(
fru.first.c_str(), kDarwinFan.c_str(), kDarwinFan.length()) ==
0) {
fanLedColor = DarwinLedColor::RED;
fanLedColor = ChassisLedColor::RED;
} else if (
std::strncmp(
fru.first.c_str(), kDarwinPem.c_str(), kDarwinPem.length()) ==
0) {
pemLedColor = DarwinLedColor::RED;
pemLedColor = ChassisLedColor::RED;
}
}
}
if (sysLedColor == DarwinLedColor::GREEN) {
if (sysLedColor == ChassisLedColor::GREEN) {
XLOG(DBG4) << "All fru modules are present";
}
fb303::fbData->setCounter(fmt::format("{}.color", kSystemLed), sysLedColor);
Expand Down
18 changes: 6 additions & 12 deletions fboss/platform/data_corral_service/darwin/DarwinChassisManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,21 @@

namespace facebook::fboss::platform::data_corral_service {

enum DarwinLedColor {
OFF = 0,
RED = 1,
GREEN = 2,
};

class DarwinChassisLed {
public:
explicit DarwinChassisLed(const std::string& name)
: name_(name), color_(DarwinLedColor::OFF) {}
void setColorPath(DarwinLedColor color, const std::string& path);
: name_(name), color_(ChassisLedColor::OFF) {}
void setColorPath(ChassisLedColor color, const std::string& path);
const std::string& getName() {
return name_;
}
void setColor(DarwinLedColor color);
DarwinLedColor getColor();
void setColor(ChassisLedColor color);
ChassisLedColor getColor();

private:
std::string name_;
DarwinLedColor color_;
std::unordered_map<DarwinLedColor, std::string> paths_;
ChassisLedColor color_;
std::unordered_map<ChassisLedColor, std::string> paths_;
};

class DarwinChassisManager : public ChassisManager {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// Copyright 2023-present Facebook. All Rights Reserved.

#include "fboss/platform/data_corral_service/meru800bia/Meru800biaChassisManager.h"

#include <fb303/ServiceData.h>
#include <folly/logging/xlog.h>
#include <thrift/lib/cpp2/protocol/Serializer.h>

#include "fboss/lib/CommonFileUtils.h"
#include "fboss/platform/data_corral_service/meru800bia/Meru800biaFruModule.h"
#include "fboss/platform/data_corral_service/meru800bia/Meru800biaPlatformConfig.h"

namespace {
// TODO: support modules

// leds in meru800bia chassis
const std::string kSystemLed = "SystemLed";
const std::string kFanLed = "FanLed";
const std::string kPsuLed = "PsuLed";
const std::string kSmbLed = "SmbLed";

// colors available in leds
const std::string kLedBlue = "Blue";
const std::string kLedAmber = "Amber";

const std::string kSetColorFailure = "set.color.failure";
} // namespace

namespace facebook::fboss::platform::data_corral_service {

void Meru800biaChassisLed::setColorPath(
ChassisLedColor color,
const std::string& path) {
XLOG(DBG2) << "led " << name_ << ", color " << color << ", sysfs path "
<< path;
paths_[color] = path;
}

void Meru800biaChassisLed::setColor(ChassisLedColor color) {
if (color_ != color) {
if (!facebook::fboss::writeSysfs(paths_[color], "1")) {
XLOG(ERR) << "failed to set color " << color << " for led " << name_;
fb303::fbData->setCounter(kSetColorFailure, 1);
return;
}
for (auto const& colorPath : paths_) {
if (colorPath.first != color) {
if (!facebook::fboss::writeSysfs(colorPath.second, "0")) {
XLOG(ERR) << "failed to unset color " << color << " for led "
<< name_;
fb303::fbData->setCounter(kSetColorFailure, 1);
return;
}
}
}
XLOG(INFO) << "Set led " << name_ << " from color " << color_
<< " to color " << color;
color_ = color;
}
fb303::fbData->setCounter(kSetColorFailure, 0);
}

ChassisLedColor Meru800biaChassisLed::getColor() {
for (auto const& colorPath : paths_) {
std::string brightness = facebook::fboss::readSysfs(colorPath.second);
try {
if (std::stoi(brightness) > 0) {
color_ = colorPath.first;
return color_;
}
} catch (const std::exception& ex) {
XLOG(ERR) << "failed to parse present state from " << colorPath.second
<< " where the value is " << brightness;
throw;
}
}
return ChassisLedColor::OFF;
}

void Meru800biaChassisManager::initModules() {
XLOG(DBG2) << "instantiate fru modules and chassis leds";
auto platformConfig = apache::thrift::SimpleJSONSerializer::deserialize<
DataCorralPlatformConfig>(getMeru800biaPlatformConfig());
for (auto fru : *platformConfig.fruModules()) {
auto name = *fru.name();
auto fruModule = std::make_unique<Meru800biaFruModule>(name);
fruModule->init(*fru.attributes());
fruModules_.emplace(name, std::move(fruModule));
}

sysLed_ = std::make_unique<Meru800biaChassisLed>(kSystemLed);
fanLed_ = std::make_unique<Meru800biaChassisLed>(kFanLed);
psuLed_ = std::make_unique<Meru800biaChassisLed>(kPsuLed);
smbLed_ = std::make_unique<Meru800biaChassisLed>(kSmbLed);
for (auto attr : *platformConfig.chassisAttributes()) {
if (*attr.name() == kSystemLed + kLedAmber) {
sysLed_->setColorPath(ChassisLedColor::AMBER, *attr.path());
} else if (*attr.name() == kSystemLed + kLedBlue) {
sysLed_->setColorPath(ChassisLedColor::BLUE, *attr.path());
} else if (*attr.name() == kFanLed + kLedAmber) {
fanLed_->setColorPath(ChassisLedColor::AMBER, *attr.path());
} else if (*attr.name() == kFanLed + kLedBlue) {
fanLed_->setColorPath(ChassisLedColor::BLUE, *attr.path());
} else if (*attr.name() == kPsuLed + kLedAmber) {
psuLed_->setColorPath(ChassisLedColor::AMBER, *attr.path());
} else if (*attr.name() == kPsuLed + kLedBlue) {
psuLed_->setColorPath(ChassisLedColor::BLUE, *attr.path());
} else if (*attr.name() == kSmbLed + kLedAmber) {
smbLed_->setColorPath(ChassisLedColor::AMBER, *attr.path());
} else if (*attr.name() == kSmbLed + kLedBlue) {
smbLed_->setColorPath(ChassisLedColor::BLUE, *attr.path());
}
}
}

void Meru800biaChassisManager::programChassis() {
ChassisLedColor sysLedColor = ChassisLedColor::BLUE;
ChassisLedColor fanLedColor = ChassisLedColor::BLUE;
ChassisLedColor psuLedColor = ChassisLedColor::BLUE;
ChassisLedColor smbLedColor = ChassisLedColor::BLUE;

for (auto& fru : fruModules_) {
if (!fru.second->isPresent()) {
XLOG(DBG2) << "Fru module " << fru.first << " is absent";
sysLedColor = ChassisLedColor::AMBER;
}
}
if (sysLedColor == ChassisLedColor::BLUE) {
XLOG(DBG4) << "All fru modules are present";
}
fb303::fbData->setCounter(fmt::format("{}.color", kSystemLed), sysLedColor);
fb303::fbData->setCounter(fmt::format("{}.color", kFanLed), fanLedColor);
fb303::fbData->setCounter(fmt::format("{}.color", kPsuLed), psuLedColor);
fb303::fbData->setCounter(fmt::format("{}.color", kSmbLed), smbLedColor);
sysLed_->setColor(sysLedColor);
fanLed_->setColor(fanLedColor);
psuLed_->setColor(psuLedColor);
smbLed_->setColor(smbLedColor);
}

} // namespace facebook::fboss::platform::data_corral_service
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2023-present Facebook. All Rights Reserved.

#pragma once

#include <fboss/platform/data_corral_service/ChassisManager.h>

namespace facebook::fboss::platform::data_corral_service {

class Meru800biaChassisLed {
public:
explicit Meru800biaChassisLed(const std::string& name)
: name_(name), color_(ChassisLedColor::OFF) {}
void setColorPath(ChassisLedColor color, const std::string& path);
const std::string& getName() {
return name_;
}
void setColor(ChassisLedColor color);
ChassisLedColor getColor();

private:
std::string name_;
ChassisLedColor color_;
std::unordered_map<ChassisLedColor, std::string> paths_;
};

class Meru800biaChassisManager : public ChassisManager {
public:
explicit Meru800biaChassisManager(int refreshInterval)
: ChassisManager(refreshInterval) {}
virtual void initModules() override;
virtual void programChassis() override;

private:
std::unique_ptr<Meru800biaChassisLed> sysLed_;
std::unique_ptr<Meru800biaChassisLed> fanLed_;
std::unique_ptr<Meru800biaChassisLed> psuLed_;
std::unique_ptr<Meru800biaChassisLed> smbLed_;
};

} // namespace facebook::fboss::platform::data_corral_service
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2023-present Facebook. All Rights Reserved.

#include <fboss/lib/CommonFileUtils.h>
#include <fboss/platform/data_corral_service/meru800bia/Meru800biaFruModule.h>
#include <folly/logging/xlog.h>
#include <filesystem>

namespace facebook::fboss::platform::data_corral_service {

void Meru800biaFruModule::init(std::vector<AttributeConfig>& attrs) {
XLOG(DBG2) << "init " << getFruId();
for (auto attr : attrs) {
if (*attr.name() == "present") {
presentPath_ = *attr.path();
}
}
refresh();
}

void Meru800biaFruModule::refresh() {
if (std::filesystem::exists(std::filesystem::path(presentPath_))) {
std::string presence = facebook::fboss::readSysfs(presentPath_);
try {
isPresent_ = (std::stoi(presence) > 0);
} catch (const std::exception& ex) {
XLOG(ERR) << "failed to parse present state from " << presentPath_
<< " where the value is " << presence;
throw;
}
XLOG(DBG4) << "refresh " << getFruId() << " present state is " << isPresent_
<< " after reading " << presentPath_;
} else {
XLOG(ERR) << "\"" << presentPath_ << "\""
<< " does not exists";
}
}

} // namespace facebook::fboss::platform::data_corral_service