Skip to content
Closed
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
4 changes: 4 additions & 0 deletions cmake/CliFboss2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,10 @@ add_library(fboss2_config_lib
fboss/cli/fboss2/commands/config/interface/CmdConfigInterfaceDescription.cpp
fboss/cli/fboss2/commands/config/interface/CmdConfigInterfaceMtu.h
fboss/cli/fboss2/commands/config/interface/CmdConfigInterfaceMtu.cpp
fboss/cli/fboss2/commands/config/interface/switchport/CmdConfigInterfaceSwitchport.h
fboss/cli/fboss2/commands/config/interface/switchport/access/CmdConfigInterfaceSwitchportAccess.h
fboss/cli/fboss2/commands/config/interface/switchport/access/vlan/CmdConfigInterfaceSwitchportAccessVlan.h
fboss/cli/fboss2/commands/config/interface/switchport/access/vlan/CmdConfigInterfaceSwitchportAccessVlan.cpp
fboss/cli/fboss2/commands/config/qos/CmdConfigQos.h
fboss/cli/fboss2/commands/config/qos/buffer_pool/CmdConfigQosBufferPool.cpp
fboss/cli/fboss2/commands/config/qos/buffer_pool/CmdConfigQosBufferPool.h
Expand Down
1 change: 1 addition & 0 deletions cmake/CliFboss2Test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ add_executable(fboss2_cmd_test
fboss/cli/fboss2/test/CmdConfigHistoryTest.cpp
fboss/cli/fboss2/test/CmdConfigInterfaceDescriptionTest.cpp
fboss/cli/fboss2/test/CmdConfigInterfaceMtuTest.cpp
fboss/cli/fboss2/test/CmdConfigInterfaceSwitchportAccessVlanTest.cpp
fboss/cli/fboss2/test/CmdConfigQosBufferPoolTest.cpp
fboss/cli/fboss2/test/CmdConfigReloadTest.cpp
fboss/cli/fboss2/test/CmdConfigSessionDiffTest.cpp
Expand Down
4 changes: 4 additions & 0 deletions fboss/cli/fboss2/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ cpp_library(
"commands/config/history/CmdConfigHistory.cpp",
"commands/config/interface/CmdConfigInterfaceDescription.cpp",
"commands/config/interface/CmdConfigInterfaceMtu.cpp",
"commands/config/interface/switchport/access/vlan/CmdConfigInterfaceSwitchportAccessVlan.cpp",
"commands/config/qos/buffer_pool/CmdConfigQosBufferPool.cpp",
"commands/config/rollback/CmdConfigRollback.cpp",
"commands/config/session/CmdConfigSessionCommit.cpp",
Expand All @@ -867,6 +868,9 @@ cpp_library(
"commands/config/interface/CmdConfigInterface.h",
"commands/config/interface/CmdConfigInterfaceDescription.h",
"commands/config/interface/CmdConfigInterfaceMtu.h",
"commands/config/interface/switchport/CmdConfigInterfaceSwitchport.h",
"commands/config/interface/switchport/access/CmdConfigInterfaceSwitchportAccess.h",
"commands/config/interface/switchport/access/vlan/CmdConfigInterfaceSwitchportAccessVlan.h",
"commands/config/qos/CmdConfigQos.h",
"commands/config/qos/buffer_pool/CmdConfigQosBufferPool.h",
"commands/config/rollback/CmdConfigRollback.h",
Expand Down
12 changes: 12 additions & 0 deletions fboss/cli/fboss2/CmdHandlerImplConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include "fboss/cli/fboss2/commands/config/interface/CmdConfigInterface.h"
#include "fboss/cli/fboss2/commands/config/interface/CmdConfigInterfaceDescription.h"
#include "fboss/cli/fboss2/commands/config/interface/CmdConfigInterfaceMtu.h"
#include "fboss/cli/fboss2/commands/config/interface/switchport/CmdConfigInterfaceSwitchport.h"
#include "fboss/cli/fboss2/commands/config/interface/switchport/access/CmdConfigInterfaceSwitchportAccess.h"
#include "fboss/cli/fboss2/commands/config/interface/switchport/access/vlan/CmdConfigInterfaceSwitchportAccessVlan.h"
#include "fboss/cli/fboss2/commands/config/qos/CmdConfigQos.h"
#include "fboss/cli/fboss2/commands/config/qos/buffer_pool/CmdConfigQosBufferPool.h"
#include "fboss/cli/fboss2/commands/config/rollback/CmdConfigRollback.h"
Expand All @@ -36,6 +39,15 @@ template void CmdHandler<
CmdConfigInterfaceDescriptionTraits>::run();
template void
CmdHandler<CmdConfigInterfaceMtu, CmdConfigInterfaceMtuTraits>::run();
template void CmdHandler<
CmdConfigInterfaceSwitchport,
CmdConfigInterfaceSwitchportTraits>::run();
template void CmdHandler<
CmdConfigInterfaceSwitchportAccess,
CmdConfigInterfaceSwitchportAccessTraits>::run();
template void CmdHandler<
CmdConfigInterfaceSwitchportAccessVlan,
CmdConfigInterfaceSwitchportAccessVlanTraits>::run();
template void CmdHandler<CmdConfigHistory, CmdConfigHistoryTraits>::run();
template void CmdHandler<CmdConfigRollback, CmdConfigRollbackTraits>::run();
template void
Expand Down
22 changes: 22 additions & 0 deletions fboss/cli/fboss2/CmdListConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include "fboss/cli/fboss2/commands/config/interface/CmdConfigInterface.h"
#include "fboss/cli/fboss2/commands/config/interface/CmdConfigInterfaceDescription.h"
#include "fboss/cli/fboss2/commands/config/interface/CmdConfigInterfaceMtu.h"
#include "fboss/cli/fboss2/commands/config/interface/switchport/CmdConfigInterfaceSwitchport.h"
#include "fboss/cli/fboss2/commands/config/interface/switchport/access/CmdConfigInterfaceSwitchportAccess.h"
#include "fboss/cli/fboss2/commands/config/interface/switchport/access/vlan/CmdConfigInterfaceSwitchportAccessVlan.h"
#include "fboss/cli/fboss2/commands/config/qos/CmdConfigQos.h"
#include "fboss/cli/fboss2/commands/config/qos/buffer_pool/CmdConfigQosBufferPool.h"
#include "fboss/cli/fboss2/commands/config/rollback/CmdConfigRollback.h"
Expand Down Expand Up @@ -56,6 +59,25 @@ const CommandTree& kConfigCommandTree() {
"Set interface MTU",
commandHandler<CmdConfigInterfaceMtu>,
argTypeHandler<CmdConfigInterfaceMtuTraits>,
},
{
"switchport",
"Configure switchport settings",
commandHandler<CmdConfigInterfaceSwitchport>,
argTypeHandler<CmdConfigInterfaceSwitchportTraits>,
{{
"access",
"Configure access mode settings",
commandHandler<CmdConfigInterfaceSwitchportAccess>,
argTypeHandler<CmdConfigInterfaceSwitchportAccessTraits>,
{{
"vlan",
"Set access VLAN (ingressVlan) for the interface",
commandHandler<CmdConfigInterfaceSwitchportAccessVlan>,
argTypeHandler<
CmdConfigInterfaceSwitchportAccessVlanTraits>,
}},
}},
}},
},

Expand Down
3 changes: 3 additions & 0 deletions fboss/cli/fboss2/CmdSubcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ CLI::App* CmdSubcommands::addCommand(
"<name> <attr> <value> [<attr> <value> ...] where <attr> is one "
"of: shared-bytes, headroom-bytes, reserved-bytes");
break;
case utils::ObjectArgTypeId::OBJECT_ARG_TYPE_VLAN_ID:
subCmd->add_option("vlan_id", args, "VLAN ID (1-4094)");
break;
case utils::ObjectArgTypeId::OBJECT_ARG_TYPE_ID_UNINITIALIZE:
case utils::ObjectArgTypeId::OBJECT_ARG_TYPE_ID_NONE:
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

#pragma once

#include "fboss/cli/fboss2/CmdHandler.h"
#include "fboss/cli/fboss2/commands/config/interface/CmdConfigInterface.h"
#include "fboss/cli/fboss2/utils/CmdUtils.h"
#include "fboss/cli/fboss2/utils/InterfaceList.h"

namespace facebook::fboss {

struct CmdConfigInterfaceSwitchportTraits : public WriteCommandTraits {
using ParentCmd = CmdConfigInterface;
static constexpr utils::ObjectArgTypeId ObjectArgTypeId =
utils::ObjectArgTypeId::OBJECT_ARG_TYPE_ID_NONE;
using ObjectArgType = std::monostate;
using RetType = std::string;
};

class CmdConfigInterfaceSwitchport : public CmdHandler<
CmdConfigInterfaceSwitchport,
CmdConfigInterfaceSwitchportTraits> {
public:
RetType queryClient(
const HostInfo& /* hostInfo */,
const utils::InterfaceList& /* interfaces */) {
throw std::runtime_error(
"Incomplete command, please use one of the subcommands");
}

void printOutput(const RetType& /* model */) {}
};

} // namespace facebook::fboss
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

#pragma once

#include "fboss/cli/fboss2/CmdHandler.h"
#include "fboss/cli/fboss2/commands/config/interface/switchport/CmdConfigInterfaceSwitchport.h"
#include "fboss/cli/fboss2/utils/CmdUtils.h"
#include "fboss/cli/fboss2/utils/InterfaceList.h"

namespace facebook::fboss {

struct CmdConfigInterfaceSwitchportAccessTraits : public WriteCommandTraits {
using ParentCmd = CmdConfigInterfaceSwitchport;
static constexpr utils::ObjectArgTypeId ObjectArgTypeId =
utils::ObjectArgTypeId::OBJECT_ARG_TYPE_ID_NONE;
using ObjectArgType = std::monostate;
using RetType = std::string;
};

class CmdConfigInterfaceSwitchportAccess
: public CmdHandler<
CmdConfigInterfaceSwitchportAccess,
CmdConfigInterfaceSwitchportAccessTraits> {
public:
RetType queryClient(
const HostInfo& /* hostInfo */,
const utils::InterfaceList& /* interfaces */) {
throw std::runtime_error(
"Incomplete command, please use one of the subcommands");
}

void printOutput(const RetType& /* model */) {}
};

} // namespace facebook::fboss
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

#include "fboss/cli/fboss2/commands/config/interface/switchport/access/vlan/CmdConfigInterfaceSwitchportAccessVlan.h"

#include <unordered_set>

#include <folly/Conv.h>
#include "fboss/cli/fboss2/session/ConfigSession.h"

namespace facebook::fboss {

CmdConfigInterfaceSwitchportAccessVlanTraits::RetType
CmdConfigInterfaceSwitchportAccessVlan::queryClient(
const HostInfo& hostInfo,
const utils::InterfaceList& interfaces,
const CmdConfigInterfaceSwitchportAccessVlanTraits::ObjectArgType&
vlanIdValue) {
if (interfaces.empty()) {
throw std::invalid_argument("No interface name provided");
}

// Extract the VLAN ID (validation already done in VlanIdValue constructor)
int32_t vlanId = vlanIdValue.getVlanId();

// Collect the logical port IDs we need to update
std::unordered_set<int32_t> portIds;

// Update ingressVlan for all resolved ports
for (const utils::Intf& intf : interfaces) {
cfg::Port* port = intf.getPort();
if (port) {
port->ingressVlan() = vlanId;
portIds.insert(*port->logicalID());
}
}

// Also update the vlanPorts entries for these ports
auto& config = ConfigSession::getInstance().getAgentConfig();
auto& vlanPorts = *config.sw()->vlanPorts();
for (auto& vlanPort : vlanPorts) {
if (portIds.count(*vlanPort.logicalPort())) {
vlanPort.vlanID() = vlanId;
}
}

// Save the updated config
// VLAN changes require agent warmboot as reloadConfig() doesn't apply them
ConfigSession::getInstance().saveConfig(
cli::ServiceType::AGENT, cli::ConfigActionLevel::AGENT_WARMBOOT);

std::string interfaceList = folly::join(", ", interfaces.getNames());
std::string message = "Successfully set access VLAN for interface(s) " +
interfaceList + " to " + std::to_string(vlanId);

return message;
}

void CmdConfigInterfaceSwitchportAccessVlan::printOutput(
const CmdConfigInterfaceSwitchportAccessVlanTraits::RetType& logMsg) {
std::cout << logMsg << std::endl;
}

} // namespace facebook::fboss
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

#pragma once

#include <folly/Conv.h>
#include <folly/String.h>
#include "fboss/cli/fboss2/CmdHandler.h"
#include "fboss/cli/fboss2/commands/config/interface/switchport/access/CmdConfigInterfaceSwitchportAccess.h"
#include "fboss/cli/fboss2/utils/CmdUtils.h"
#include "fboss/cli/fboss2/utils/InterfaceList.h"

namespace facebook::fboss {

// Custom type for VLAN ID argument with validation
class VlanIdValue : public utils::BaseObjectArgType<int32_t> {
public:
/* implicit */ VlanIdValue(std::vector<std::string> v) {
if (v.empty()) {
throw std::invalid_argument("VLAN ID is required");
}
if (v.size() != 1) {
throw std::invalid_argument(
"Expected single VLAN ID, got: " + folly::join(", ", v));
}

try {
int32_t vlanId = folly::to<int32_t>(v[0]);
// VLAN IDs are typically 1-4094 (0 and 4095 are reserved)
if (vlanId < 1 || vlanId > 4094) {
throw std::invalid_argument(
"VLAN ID must be between 1 and 4094 inclusive, got: " +
std::to_string(vlanId));
}
data_.push_back(vlanId);
} catch (const folly::ConversionError&) {
throw std::invalid_argument("Invalid VLAN ID: " + v[0]);
}
}

int32_t getVlanId() const {
return data_[0];
}

const static utils::ObjectArgTypeId id =
utils::ObjectArgTypeId::OBJECT_ARG_TYPE_VLAN_ID;
};

struct CmdConfigInterfaceSwitchportAccessVlanTraits
: public WriteCommandTraits {
using ParentCmd = CmdConfigInterfaceSwitchportAccess;
static constexpr utils::ObjectArgTypeId ObjectArgTypeId =
utils::ObjectArgTypeId::OBJECT_ARG_TYPE_VLAN_ID;
using ObjectArgType = VlanIdValue;
using RetType = std::string;
};

class CmdConfigInterfaceSwitchportAccessVlan
: public CmdHandler<
CmdConfigInterfaceSwitchportAccessVlan,
CmdConfigInterfaceSwitchportAccessVlanTraits> {
public:
using ObjectArgType =
CmdConfigInterfaceSwitchportAccessVlanTraits::ObjectArgType;
using RetType = CmdConfigInterfaceSwitchportAccessVlanTraits::RetType;

RetType queryClient(
const HostInfo& hostInfo,
const utils::InterfaceList& interfaces,
const ObjectArgType& vlanId);

void printOutput(const RetType& logMsg);
};

} // namespace facebook::fboss
8 changes: 5 additions & 3 deletions fboss/cli/fboss2/session/ConfigSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ void ConfigSession::restartService(
if (level == cli::ConfigActionLevel::AGENT_COLDBOOT) {
// Step 1: Stop the service
try {
folly::Subprocess stopProc({"/usr/bin/systemctl", "stop", serviceName});
folly::Subprocess stopProc(
{"/usr/bin/sudo", "/usr/bin/systemctl", "stop", serviceName});
stopProc.waitChecked();
} catch (const std::exception& ex) {
throw std::runtime_error(
Expand Down Expand Up @@ -488,7 +489,8 @@ void ConfigSession::restartService(

// Step 3: Start the service
try {
folly::Subprocess startProc({"/usr/bin/systemctl", "start", serviceName});
folly::Subprocess startProc(
{"/usr/bin/sudo", "/usr/bin/systemctl", "start", serviceName});
startProc.waitChecked();
} catch (const std::exception& ex) {
throw std::runtime_error(
Expand All @@ -498,7 +500,7 @@ void ConfigSession::restartService(
// For warmboot, just do a simple restart
try {
folly::Subprocess restartProc(
{"/usr/bin/systemctl", "restart", serviceName});
{"/usr/bin/sudo", "/usr/bin/systemctl", "restart", serviceName});
restartProc.waitChecked();
} catch (const std::exception& ex) {
throw std::runtime_error(
Expand Down
1 change: 1 addition & 0 deletions fboss/cli/fboss2/test/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ cpp_unittest(
"CmdConfigHistoryTest.cpp",
"CmdConfigInterfaceDescriptionTest.cpp",
"CmdConfigInterfaceMtuTest.cpp",
"CmdConfigInterfaceSwitchportAccessVlanTest.cpp",
"CmdConfigQosBufferPoolTest.cpp",
"CmdConfigReloadTest.cpp",
"CmdConfigSessionDiffTest.cpp",
Expand Down
Loading
Loading