Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 53 additions & 11 deletions fboss/cli/fboss2/commands/config/interface/CmdConfigInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <fmt/format.h>
#include <folly/Conv.h>
#include <folly/String.h>
#include <folly/logging/xlog.h>
#include <thrift/lib/cpp/util/EnumUtils.h>
#include <thrift/lib/cpp2/FieldRef.h>
#include <algorithm>
Expand Down Expand Up @@ -189,7 +190,8 @@ std::string applyProfileImpl(
const utility::PortProfileSupportMap& qsfpSupportedProfiles,
const utils::InterfaceList& interfaces,
const std::string& value,
cli::ConfigActionLevel* actionLevel) {
cli::ConfigActionLevel* actionLevel,
std::vector<std::string>* warnings) {
// Parse once (throws std::invalid_argument on a bad string) and thread the
// enum through the rest of the flow.
const cfg::PortProfileID requestedProfile = parsePortProfile(value);
Expand Down Expand Up @@ -222,12 +224,40 @@ std::string applyProfileImpl(

utility::PortProfileChangeResult result;
try {
result = utility::applyPortProfileChanges(
swConfig, platformMapping, requests, qsfpSupportedProfiles);
result =
utility::applyPortProfileChanges(swConfig, platformMapping, requests);
} catch (const FbossError& error) {
throw std::invalid_argument(error.what());
}

// The agent applies any platform-supported profile from its config whatever
// the transceiver, so a transceiver mismatch only warns here.
if (warnings != nullptr) {
for (const auto& request : result.requestedPorts) {
const auto qsfpProfiles = qsfpSupportedProfiles.find(request.portName);
if (qsfpProfiles == qsfpSupportedProfiles.end() ||
qsfpProfiles->second.empty() ||
std::find(
qsfpProfiles->second.begin(),
qsfpProfiles->second.end(),
requestedProfile) != qsfpProfiles->second.end()) {
continue;
}
std::vector<std::string> supportedNames;
supportedNames.reserve(qsfpProfiles->second.size());
for (const auto profileID : qsfpProfiles->second) {
supportedNames.push_back(apache::thrift::util::enumNameSafe(profileID));
}
warnings->push_back(
fmt::format(
"Warning: profile '{}' is not supported by the transceiver on "
"port {}. Supported profiles: [{}]",
apache::thrift::util::enumNameSafe(requestedProfile),
request.portName,
folly::join(", ", supportedNames)));
}
}

const auto profileSpeed = result.requestedPorts.empty()
? cfg::PortSpeed::DEFAULT
: result.requestedPorts.front().speed;
Expand Down Expand Up @@ -275,7 +305,8 @@ std::string applyProfile(
const HostInfo& hostInfo,
const utils::InterfaceList& interfaces,
const std::string& value,
cli::ConfigActionLevel* actionLevel = nullptr) {
cli::ConfigActionLevel* actionLevel = nullptr,
std::vector<std::string>* warnings = nullptr) {
cfg::PlatformMapping platformMappingConfig;
auto agentClient =
utils::createClient<apache::thrift::Client<FbossCtrl>>(hostInfo);
Expand All @@ -286,9 +317,14 @@ std::string applyProfile(
auto qsfpClient =
utils::createClient<apache::thrift::Client<QsfpService>>(hostInfo);
qsfpClient->sync_getAllPortSupportedProfiles(qsfpSupportedProfiles, true);
} catch (const std::exception&) {
// QsfpService unavailable; applyPortProfileChanges falls back to platform
// mapping support.
} catch (const std::exception& ex) {
XLOG(WARN) << "Unable to query qsfp_service for supported profiles: "
<< ex.what();
if (warnings != nullptr) {
warnings->emplace_back(
"Warning: qsfp_service is unreachable, so the profile was not "
"checked against the transceiver");
}
}

const PlatformMapping platformMapping(platformMappingConfig);
Expand All @@ -298,7 +334,8 @@ std::string applyProfile(
qsfpSupportedProfiles,
interfaces,
value,
actionLevel);
actionLevel,
warnings);
}

// Creates the virtual loopback interface for `index`, plus its backing VLAN
Expand Down Expand Up @@ -723,9 +760,10 @@ CmdConfigInterfaceTraits::RetType CmdConfigInterface::queryClient(
// (LookupClassRouteUpdater dereferences the removed port's now-absent
// interface). See T281221621.
cli::ConfigActionLevel actionLevel = cli::ConfigActionLevel::HITLESS;
std::vector<std::string> warnings;
if (profileValue.has_value()) {
results.push_back(
applyProfile(hostInfo, interfaces, *profileValue, &actionLevel));
results.push_back(applyProfile(
hostInfo, interfaces, *profileValue, &actionLevel, &warnings));
changed = true;
ConfigSession::getInstance().rebuildPortMap();
}
Expand Down Expand Up @@ -873,8 +911,12 @@ CmdConfigInterfaceTraits::RetType CmdConfigInterface::queryClient(

std::string interfaceList = folly::join(", ", interfaces.getNames());
std::string attrList = folly::join(", ", results);
return fmt::format(
auto out = fmt::format(
"Successfully configured interface(s) {}: {}", interfaceList, attrList);
for (const auto& warning : warnings) {
out += "\n" + warning;
}
return out;
}

void CmdConfigInterface::printOutput(const RetType& logMsg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,15 @@ class CmdConfigInterface
// warmboot/coldboot can escalate it too.
cfg::PortProfileID parsePortProfile(const std::string& profile);

// `qsfpSupportedProfiles` is advisory: a requested profile missing from a
// port's non-empty entry is still applied, and reported in `warnings`.
std::string applyProfileImpl(
cfg::SwitchConfig& swConfig,
const PlatformMapping& platformMapping,
const utility::PortProfileSupportMap& qsfpSupportedProfiles,
const utils::InterfaceList& interfaces,
const std::string& value,
cli::ConfigActionLevel* actionLevel = nullptr);
cli::ConfigActionLevel* actionLevel = nullptr,
std::vector<std::string>* warnings = nullptr);

} // namespace facebook::fboss
143 changes: 132 additions & 11 deletions fboss/cli/fboss2/test/config/CmdConfigInterfaceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,37 @@ TEST_F(ApplyProfileSubsumeTestFixture, subsumeEscalatesToColdboot) {
EXPECT_EQ(actionLevel, cli::ConfigActionLevel::DISRUPTIVE_SERVICE_RESTART);
}

TEST_F(ApplyProfileSubsumeTestFixture, warnsOnExistingPortUnsupportedByQsfp) {
setupTestableConfigSession(
"config interface", "eth1/1/1 profile PROFILE_400G_8_PAM4_RS544X2N");
auto platformMapping = makeSubsumePlatformMapping();
auto& swConfig = *ConfigSession::getInstance().getAgentConfig().sw();
utils::InterfaceList interfaces({"eth1/1/1"});
const utility::PortProfileSupportMap qsfpSupportedProfiles{
{"eth1/1/1", {cfg::PortProfileID::PROFILE_100G_4_NRZ_CL91}}};
std::vector<std::string> warnings;

applyProfileImpl(
swConfig,
platformMapping,
qsfpSupportedProfiles,
interfaces,
"PROFILE_400G_8_PAM4_RS544X2N",
nullptr,
&warnings);

ASSERT_EQ(swConfig.ports()->size(), 1u);
EXPECT_EQ(
*swConfig.ports()->front().profileID(),
cfg::PortProfileID::PROFILE_400G_8_PAM4_RS544X2N);
ASSERT_EQ(warnings.size(), 1u);
EXPECT_EQ(
warnings[0],
"Warning: profile 'PROFILE_400G_8_PAM4_RS544X2N' is not supported by the "
"transceiver on port eth1/1/1. Supported profiles: "
"[PROFILE_100G_4_NRZ_CL91]");
}

// ============================================================================
// applyProfileImpl pending-port (creation) tests
// ============================================================================
Expand Down Expand Up @@ -1969,24 +2000,114 @@ TEST_F(CreatePendingInterfacePortsTestFixture, createsSupportedInterfacePort) {

TEST_F(
CreatePendingInterfacePortsTestFixture,
rejectsProfileUnsupportedByQsfp) {
warnsOnlyForPortsUnsupportedByQsfp) {
setupTestableConfigSession();
auto platformMapping = makePendingMapping();
cfg::SwitchConfig config;
utils::InterfaceList interfaces(
std::vector<std::string>{"eth1/1/1"}, /*allowMissing*/ true);
std::vector<std::string>{"eth1/1/1", "eth1/1/2"}, /*allowMissing*/ true);
const utility::PortProfileSupportMap qsfpSupportedProfiles{
{"eth1/1/1", {cfg::PortProfileID::PROFILE_100G_4_NRZ_CL91}},
{"eth1/1/2", {cfg::PortProfileID::PROFILE_400G_8_PAM4_RS544X2N}}};
std::vector<std::string> warnings;

applyProfileImpl(
config,
platformMapping,
qsfpSupportedProfiles,
interfaces,
"PROFILE_100G_4_NRZ_CL91",
nullptr,
&warnings);

ASSERT_EQ(config.ports()->size(), 2u);
for (const auto& port : *config.ports()) {
EXPECT_EQ(*port.profileID(), cfg::PortProfileID::PROFILE_100G_4_NRZ_CL91);
}
ASSERT_EQ(warnings.size(), 1u);
EXPECT_EQ(
warnings[0],
"Warning: profile 'PROFILE_100G_4_NRZ_CL91' is not supported by the "
"transceiver on port eth1/1/2. Supported profiles: "
"[PROFILE_400G_8_PAM4_RS544X2N]");
}

TEST_F(
CreatePendingInterfacePortsTestFixture,
noWarningWhenQsfpSupportsOrDoesNotReportPort) {
setupTestableConfigSession();
auto platformMapping = makePendingMapping();
utils::InterfaceList interfaces(
std::vector<std::string>{"eth1/1/1"}, /*allowMissing*/ true);
for (const auto& qsfpSupportedProfiles :
{utility::PortProfileSupportMap{
{"eth1/1/1", {cfg::PortProfileID::PROFILE_100G_4_NRZ_CL91}}},
utility::PortProfileSupportMap{{"eth1/1/1", {}}},
utility::PortProfileSupportMap{}}) {
cfg::SwitchConfig config;
std::vector<std::string> warnings;
applyProfileImpl(
config,
platformMapping,
qsfpSupportedProfiles,
interfaces,
"PROFILE_100G_4_NRZ_CL91",
nullptr,
&warnings);
EXPECT_EQ(config.ports()->size(), 1u);
EXPECT_TRUE(warnings.empty());
}
}

TEST_F(
CreatePendingInterfacePortsTestFixture,
queryClientPrintsQsfpWarningAfterSuccess) {
setupTestableConfigSession();
EXPECT_CALL(getMockAgent(), getPlatformMapping(_))
.WillRepeatedly(
DoAll(SetArgReferee<0>(makePendingPlatformMapping()), Return()));
const std::map<std::string, std::vector<cfg::PortProfileID>> qsfpProfiles{
{"eth1/1/1", {cfg::PortProfileID::PROFILE_400G_8_PAM4_RS544X2N}}};
EXPECT_CALL(getQsfpService(), getAllPortSupportedProfiles(_, _))
.WillRepeatedly(DoAll(SetArgReferee<0>(qsfpProfiles), Return()));

EXPECT_THROW(
applyProfileImpl(
config,
platformMapping,
qsfpSupportedProfiles,
interfaces,
"PROFILE_100G_4_NRZ_CL91"),
std::invalid_argument);
EXPECT_TRUE(config.ports()->empty());
InterfacesConfig config(
{"eth1/1/1", "profile", "PROFILE_100G_4_NRZ_CL91", "mtu", "9000"});
auto result = CmdConfigInterface().queryClient(localhost(), config);

EXPECT_THAT(
result, StartsWith("Successfully configured interface(s) eth1/1/1: "));
EXPECT_THAT(
result,
EndsWith(
"mtu=9000\nWarning: profile 'PROFILE_100G_4_NRZ_CL91' is not "
"supported by the transceiver on port eth1/1/1. Supported profiles: "
"[PROFILE_400G_8_PAM4_RS544X2N]"));
}

TEST_F(
CreatePendingInterfacePortsTestFixture,
queryClientReportsUnreachableQsfpService) {
setupTestableConfigSession();
EXPECT_CALL(getMockAgent(), getPlatformMapping(_))
.WillRepeatedly(
DoAll(SetArgReferee<0>(makePendingPlatformMapping()), Return()));
EXPECT_CALL(getQsfpService(), getAllPortSupportedProfiles(_, _))
.WillRepeatedly(Throw(std::runtime_error("qsfp_service down")));

InterfacesConfig config({"eth1/1/1", "profile", "PROFILE_100G_4_NRZ_CL91"});
auto result = CmdConfigInterface().queryClient(localhost(), config);

EXPECT_THAT(
result, StartsWith("Successfully configured interface(s) eth1/1/1: "));
EXPECT_THAT(
result,
EndsWith(
"\nWarning: qsfp_service is unreachable, so the profile was not "
"checked against the transceiver"));
EXPECT_THAT(result, Not(HasSubstr("is not supported by the transceiver")));
ASSERT_EQ(
ConfigSession::getInstance().getAgentConfig().sw()->ports()->size(), 1u);
}

// Creating a port removes nothing, so the action level stays HITLESS (no
Expand Down
1 change: 1 addition & 0 deletions fboss/cli/fboss2/test/integration_test/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ cpp_binary(
"//fboss/cli/fboss2:fboss2-config-lib", # @manual
"//fboss/cli/fboss2:fboss2-lib", # @manual
"//fboss/lib/config:fboss_config_utils",
"//fboss/qsfp_service/if:qsfp-cpp2-services",
"//neteng/fboss/bgp/if:bgp_thrift-cpp2-services",
"//neteng/fboss/bgp/public_tld/configerator/structs/neteng/fboss/bgp:bgp_config_oss-cpp2-types",
"//thrift/lib/cpp/transport:transport-core",
Expand Down
Loading
Loading