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
5 changes: 5 additions & 0 deletions cmake/CliFboss2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,9 @@ add_library(fboss2_config_lib
fboss/cli/fboss2/commands/config/protocol/bgp/policy/as-path-list/BgpAsPathListCliUtils.h
fboss/cli/fboss2/commands/config/protocol/bgp/policy/as-path-list/CmdConfigProtocolBgpPolicyAsPathList.cpp
fboss/cli/fboss2/commands/config/protocol/bgp/policy/as-path-list/CmdConfigProtocolBgpPolicyAsPathList.h
fboss/cli/fboss2/commands/config/protocol/bgp/policy/community-list/BgpCommunityListCliUtils.h
fboss/cli/fboss2/commands/config/protocol/bgp/policy/community-list/CmdConfigProtocolBgpPolicyCommunityList.cpp
fboss/cli/fboss2/commands/config/protocol/bgp/policy/community-list/CmdConfigProtocolBgpPolicyCommunityList.h
fboss/cli/fboss2/commands/config/ptp/CmdConfigPtp.cpp
fboss/cli/fboss2/commands/config/ptp/CmdConfigPtp.h
fboss/cli/fboss2/commands/config/ptp/transparent_clock/CmdConfigPtpTransparentClock.cpp
Expand Down Expand Up @@ -1114,6 +1117,8 @@ add_library(fboss2_config_lib
fboss/cli/fboss2/commands/delete/protocol/bgp/policy/CmdDeleteProtocolBgpPolicy.h
fboss/cli/fboss2/commands/delete/protocol/bgp/policy/as-path-list/CmdDeleteProtocolBgpPolicyAsPathList.cpp
fboss/cli/fboss2/commands/delete/protocol/bgp/policy/as-path-list/CmdDeleteProtocolBgpPolicyAsPathList.h
fboss/cli/fboss2/commands/delete/protocol/bgp/policy/community-list/CmdDeleteProtocolBgpPolicyCommunityList.cpp
fboss/cli/fboss2/commands/delete/protocol/bgp/policy/community-list/CmdDeleteProtocolBgpPolicyCommunityList.h
fboss/cli/fboss2/commands/delete/protocol/CmdDeleteProtocol.h
fboss/cli/fboss2/commands/delete/protocol/static/CmdDeleteProtocolStatic.cpp
fboss/cli/fboss2/commands/delete/protocol/static/CmdDeleteProtocolStatic.h
Expand Down
2 changes: 2 additions & 0 deletions cmake/CliFboss2TestConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_executable(fboss2_cmd_config_test
fboss/cli/fboss2/test/config/CmdConfigBgpNeighborTest.cpp
fboss/cli/fboss2/test/config/CmdConfigBgpPeerGroupTest.cpp
fboss/cli/fboss2/test/config/CmdConfigBgpPolicyAsPathListTest.cpp
fboss/cli/fboss2/test/config/CmdConfigBgpPolicyCommunityListTest.cpp
fboss/cli/fboss2/test/config/CmdConfigCoppTest.cpp
fboss/cli/fboss2/test/config/CmdConfigDataPlaneTrafficPolicyTest.cpp
fboss/cli/fboss2/test/config/CmdConfigDhcpTest.cpp
Expand Down Expand Up @@ -53,6 +54,7 @@ add_executable(fboss2_cmd_config_test
fboss/cli/fboss2/test/config/CmdDeleteBgpNeighborTest.cpp
fboss/cli/fboss2/test/config/CmdDeleteBgpPeerGroupTest.cpp
fboss/cli/fboss2/test/config/CmdDeleteBgpPolicyAsPathListTest.cpp
fboss/cli/fboss2/test/config/CmdDeleteBgpPolicyCommunityListTest.cpp
fboss/cli/fboss2/test/config/CmdDeleteConfigInterfaceTest.cpp
fboss/cli/fboss2/test/config/CmdDeleteCoppQueueTest.cpp
fboss/cli/fboss2/test/config/CmdDeleteCoppReasonTest.cpp
Expand Down
1 change: 1 addition & 0 deletions cmake/CliFboss2TestIntegrationTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_executable(fboss2_integration_test
fboss/cli/fboss2/test/integration_test/ConfigBgpNeighborTest.cpp
fboss/cli/fboss2/test/integration_test/ConfigBgpPeerGroupTest.cpp
fboss/cli/fboss2/test/integration_test/ConfigBgpPolicyAsPathListTest.cpp
fboss/cli/fboss2/test/integration_test/ConfigBgpPolicyCommunityListTest.cpp
fboss/cli/fboss2/test/integration_test/ConfigBgpSessionTest.cpp
fboss/cli/fboss2/test/integration_test/ConfigConcurrentSessionsTest.cpp
fboss/cli/fboss2/test/integration_test/ConfigHostnameTest.cpp
Expand Down
5 changes: 5 additions & 0 deletions fboss/cli/fboss2/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,7 @@ cpp_library(
"commands/config/protocol/bgp/peer-group/CmdConfigProtocolBgpPeerGroup.cpp",
"commands/config/protocol/bgp/policy/CmdConfigProtocolBgpPolicy.cpp",
"commands/config/protocol/bgp/policy/as-path-list/CmdConfigProtocolBgpPolicyAsPathList.cpp",
"commands/config/protocol/bgp/policy/community-list/CmdConfigProtocolBgpPolicyCommunityList.cpp",
"commands/config/protocol/static/CmdConfigProtocolStatic.cpp",
"commands/config/protocol/static/route/add/CmdConfigProtocolStaticRouteAdd.cpp",
"commands/config/ptp/CmdConfigPtp.cpp",
Expand Down Expand Up @@ -1253,6 +1254,7 @@ cpp_library(
"commands/delete/protocol/bgp/peer-group/CmdDeleteProtocolBgpPeerGroup.cpp",
"commands/delete/protocol/bgp/policy/CmdDeleteProtocolBgpPolicy.cpp",
"commands/delete/protocol/bgp/policy/as-path-list/CmdDeleteProtocolBgpPolicyAsPathList.cpp",
"commands/delete/protocol/bgp/policy/community-list/CmdDeleteProtocolBgpPolicyCommunityList.cpp",
"commands/delete/protocol/static/CmdDeleteProtocolStatic.cpp",
"commands/delete/protocol/static/route/CmdDeleteProtocolStaticRoute.cpp",
"commands/delete/qos/CmdDeleteQos.cpp",
Expand Down Expand Up @@ -1330,6 +1332,8 @@ cpp_library(
"commands/config/protocol/bgp/policy/CmdConfigProtocolBgpPolicy.h",
"commands/config/protocol/bgp/policy/as-path-list/BgpAsPathListCliUtils.h",
"commands/config/protocol/bgp/policy/as-path-list/CmdConfigProtocolBgpPolicyAsPathList.h",
"commands/config/protocol/bgp/policy/community-list/BgpCommunityListCliUtils.h",
"commands/config/protocol/bgp/policy/community-list/CmdConfigProtocolBgpPolicyCommunityList.h",
"commands/config/protocol/static/CmdConfigProtocolStatic.h",
"commands/config/protocol/static/route/StaticRouteUtils.h",
"commands/config/protocol/static/route/add/CmdConfigProtocolStaticRouteAdd.h",
Expand Down Expand Up @@ -1400,6 +1404,7 @@ cpp_library(
"commands/delete/protocol/bgp/peer-group/CmdDeleteProtocolBgpPeerGroup.h",
"commands/delete/protocol/bgp/policy/CmdDeleteProtocolBgpPolicy.h",
"commands/delete/protocol/bgp/policy/as-path-list/CmdDeleteProtocolBgpPolicyAsPathList.h",
"commands/delete/protocol/bgp/policy/community-list/CmdDeleteProtocolBgpPolicyCommunityList.h",
"commands/delete/protocol/static/CmdDeleteProtocolStatic.h",
"commands/delete/protocol/static/route/CmdDeleteProtocolStaticRoute.h",
"commands/delete/qos/CmdDeleteQos.h",
Expand Down
53 changes: 37 additions & 16 deletions fboss/cli/fboss2/CmdListConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "fboss/cli/fboss2/commands/config/protocol/bgp/peer-group/CmdConfigProtocolBgpPeerGroup.h"
#include "fboss/cli/fboss2/commands/config/protocol/bgp/policy/CmdConfigProtocolBgpPolicy.h"
#include "fboss/cli/fboss2/commands/config/protocol/bgp/policy/as-path-list/CmdConfigProtocolBgpPolicyAsPathList.h"
#include "fboss/cli/fboss2/commands/config/protocol/bgp/policy/community-list/CmdConfigProtocolBgpPolicyCommunityList.h"
#include "fboss/cli/fboss2/commands/config/protocol/static/CmdConfigProtocolStatic.h"
#include "fboss/cli/fboss2/commands/config/protocol/static/route/add/CmdConfigProtocolStaticRouteAdd.h"
#include "fboss/cli/fboss2/commands/config/ptp/CmdConfigPtp.h"
Expand Down Expand Up @@ -110,6 +111,7 @@
#include "fboss/cli/fboss2/commands/delete/protocol/bgp/peer-group/CmdDeleteProtocolBgpPeerGroup.h"
#include "fboss/cli/fboss2/commands/delete/protocol/bgp/policy/CmdDeleteProtocolBgpPolicy.h"
#include "fboss/cli/fboss2/commands/delete/protocol/bgp/policy/as-path-list/CmdDeleteProtocolBgpPolicyAsPathList.h"
#include "fboss/cli/fboss2/commands/delete/protocol/bgp/policy/community-list/CmdDeleteProtocolBgpPolicyCommunityList.h"
#include "fboss/cli/fboss2/commands/delete/protocol/static/CmdDeleteProtocolStatic.h"
#include "fboss/cli/fboss2/commands/delete/protocol/static/route/CmdDeleteProtocolStaticRoute.h"
#include "fboss/cli/fboss2/commands/delete/qos/CmdDeleteQos.h"
Expand Down Expand Up @@ -423,15 +425,26 @@ const CommandTree& kConfigCommandTree() {
commandHandler<CmdConfigProtocolBgpPolicy>,
argRegistrar<CmdConfigProtocolBgpPolicyTraits>,
{{
"as-path-list",
"Configure BGP AS-path list: <name> "
"[<attribute> <value> ...] (description, "
"regex, boolean-operator)",
commandHandler<
CmdConfigProtocolBgpPolicyAsPathList>,
argRegistrar<
CmdConfigProtocolBgpPolicyAsPathListTraits>,
}},
"as-path-list",
"Configure BGP AS-path list: <name> "
"[<attribute> <value> ...] (description, "
"regex, boolean-operator)",
commandHandler<
CmdConfigProtocolBgpPolicyAsPathList>,
argRegistrar<
CmdConfigProtocolBgpPolicyAsPathListTraits>,
},
{
"community-list",
"Configure BGP community-list: <name> "
"[<attribute> <value> ...] "
"(boolean-operator, community, description, "
"exact-match)",
commandHandler<
CmdConfigProtocolBgpPolicyCommunityList>,
argRegistrar<
CmdConfigProtocolBgpPolicyCommunityListTraits>,
}},
},
},
},
Expand Down Expand Up @@ -781,13 +794,21 @@ const CommandTree& kConfigCommandTree() {
commandHandler<CmdDeleteProtocolBgpPolicy>,
argTypeHandler<CmdDeleteProtocolBgpPolicyTraits>,
{{
"as-path-list",
"Delete a BGP AS-path list, or one of its regexes: "
"<name> [regex <regex>]",
commandHandler<CmdDeleteProtocolBgpPolicyAsPathList>,
argRegistrar<
CmdDeleteProtocolBgpPolicyAsPathListTraits>,
}},
"as-path-list",
"Delete a BGP AS-path list, or one of its regexes: "
"<name> [regex <regex>]",
commandHandler<CmdDeleteProtocolBgpPolicyAsPathList>,
argRegistrar<
CmdDeleteProtocolBgpPolicyAsPathListTraits>,
},
{
"community-list",
"Delete a BGP community-list: <name>",
commandHandler<
CmdDeleteProtocolBgpPolicyCommunityList>,
argRegistrar<
CmdDeleteProtocolBgpPolicyCommunityListTraits>,
}},
}},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@

#pragma once

#include <fmt/format.h>
#include <folly/Conv.h>
#include <cstddef>
#include <cstdint>
#include <exception>
#include <limits>
#include <optional>
#include <stdexcept>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

/**
* Value parsing helpers shared by the BGP config dispatchers
Expand Down Expand Up @@ -93,4 +98,58 @@ inline std::optional<int64_t> parseAsn4Byte(const std::string& value) {
return static_cast<int64_t>(*parsed);
}

// ---- constructor-time token parsing ----------------------------------------
// Unlike the value parsers above, this runs while constructing a command's
// ObjectArgType, where throwing std::invalid_argument IS the framework's
// error channel — the message is surfaced to the user as the parse error.

// The `<list-name> [<keyword> <member-name>]` prefix, for the *delete*
// command of a policy list whose members are keyed objects (prefix-list
// entries): the list name, the optional member selected by `keyword`, and
// where any remaining tokens begin.
//
// Only delete parses this shape by hand. The config side reaches the same
// grammar through CLI11 subcommand nesting instead — the member keyword is a
// registered subcommand there, so each level gets its own already-split token
// vector and never calls this helper. Lists whose members are a flat string
// list in the daemon (as-path-list `regex`, community-list `community`) have
// no member level at all: their optional `<keyword> <value>` selector is a
// plain attribute-style pair, parsed inline by their own delete command.
struct ListMemberSelector {
std::string listName;
std::optional<std::string> memberName;
// Index of the first token after the parsed prefix (== tokens.size() when
// nothing follows). The delete dispatcher rejects any tail.
size_t restStart;
};

// Parse the prefix. `objectName` is the list flavor for messages (e.g.
// "community-list"), `memberKeyword` selects the nested member (e.g.
// `community`), and `usage` is the whole-command usage line thrown when no
// tokens were given. A second token other than `memberKeyword` is left to
// the caller (restStart == 1), which delete rejects as an unexpected token.
inline ListMemberSelector parseListMemberSelector(
const std::vector<std::string>& tokens,
std::string_view objectName,
std::string_view memberKeyword,
std::string_view usage) {
if (tokens.empty()) {
throw std::invalid_argument(std::string(usage));
}
if (tokens[0].empty()) {
throw std::invalid_argument(
fmt::format("Error: {} name must not be empty", objectName));
}
ListMemberSelector selector{tokens[0], std::nullopt, 1};
if (tokens.size() > 1 && tokens[1] == memberKeyword) {
if (tokens.size() < 3 || tokens[2].empty()) {
throw std::invalid_argument(
fmt::format("Error: `{}` requires a <name>", memberKeyword));
}
selector.memberName = tokens[2];
selector.restStart = 3;
}
return selector;
}

} // namespace facebook::fboss::bgpcli
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@

#pragma once

#include <string>
#include <variant>
#include "fboss/cli/fboss2/CmdHandler.h"
#include "fboss/cli/fboss2/commands/config/protocol/bgp/CmdConfigProtocolBgp.h"
#include "fboss/cli/fboss2/utils/HostInfo.h"

namespace facebook::fboss {

// Grouping node for `config protocol bgp policy <object-type> ...`. Holds no
// state of its own; the per-object-type dispatchers (as-path-list, and later
// community-list/prefix-list/routing-policy) are its subcommands. Mirrors
// CmdConfigProtocolBgp.
// state of its own; the per-object-type dispatchers (as-path-list,
// community-list, and later prefix-list/routing-policy) are its subcommands.
// Mirrors CmdConfigProtocolBgp.
struct CmdConfigProtocolBgpPolicyTraits : public WriteCommandTraits {
using ParentCmd = CmdConfigProtocolBgp;
using ObjectArgType = std::monostate;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 <neteng/fboss/bgp/public_tld/configerator/structs/neteng/fboss/bgp/gen-cpp2/bgp_config_types.h>
#include <algorithm>
#include <string>
#include "configerator/structs/neteng/bgp_policy/thrift/gen-cpp2/bgp_policy_types.h"

/**
* Lookup/create helpers for the community-list CLI family, shared between the
* list-level dispatcher (CmdConfigProtocolBgpPolicyCommunityList) and its
* delete counterpart. A CommunityList is keyed by name. Its values live in the
* flat `communities` string list, which is the field bgpd matches against; the
* structured members[] are never read by bgpd and have no CLI.
*/
namespace facebook::fboss::bgpcli {

inline bool communityListExists(
const bgp::thrift::BgpConfig& cfg,
const std::string& name) {
if (!cfg.policies().has_value()) {
return false;
}
const auto& lists = *cfg.policies()->community_lists();
return std::any_of(lists.begin(), lists.end(), [&](const auto& list) {
return *list.name() == name;
});
}

// Find the community-list keyed by name, creating it if absent. Setting an
// attribute on a not-yet-created list implicitly creates it, so command
// ordering stays forgiving; a bare `community-list <name>` creates one
// explicitly. CommunityList's only key field is `name`.
inline bgp::bgp_policy::CommunityList& findOrCreateCommunityList(
bgp::thrift::BgpConfig& cfg,
const std::string& name) {
auto& lists = *cfg.policies().ensure().community_lists();
for (auto& list : lists) {
if (*list.name() == name) {
return list;
}
}
lists.emplace_back();
auto& list = lists.back();
list.name() = name;
return list;
}

} // namespace facebook::fboss::bgpcli
Loading
Loading