Skip to content

Commit f3bff62

Browse files
fboss2 config/delete protocol bgp policy as-path-list commands
Adds `config protocol bgp policy as-path-list <name> [entry <seq-num>] [<attribute> <value> ...]` and `delete protocol bgp policy as-path-list <name>` — the first of the BGP policy object-type command families, under a new `policy` grouping node (config + delete) beneath `protocol bgp` (sibling to global/neighbor/peer-group). - as-path-list dispatcher with a two-level key (list name + entry sequence-number) writing bgp_policy.BgpPolicies.aspath_lists[] through the typed ConfigSession; asn-regexp sets the AsPathType union's inline AsPath arm (.as_path.as_path.asn_regexp), match-logic maps to MatchValueLogicOperator, plus per-list and per-entry description. - shared template attribute-handler factories (BgpCliAttrHandlers.h), reused by the upcoming community-list/prefix-list/routing-policy types. - unit tests (16) + integration (10/10) on a test device. The commit-path integration tests confirm bgpd accepts and adopts the .policies blob end-to-end via the getRunningConfig RPC.
1 parent 84a208a commit f3bff62

17 files changed

Lines changed: 1479 additions & 0 deletions

cmake/CliFboss2.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,11 @@ add_library(fboss2_config_lib
881881
fboss/cli/fboss2/commands/config/protocol/bgp/neighbor/CmdConfigProtocolBgpNeighbor.h
882882
fboss/cli/fboss2/commands/config/protocol/bgp/peer-group/CmdConfigProtocolBgpPeerGroup.cpp
883883
fboss/cli/fboss2/commands/config/protocol/bgp/peer-group/CmdConfigProtocolBgpPeerGroup.h
884+
fboss/cli/fboss2/commands/config/protocol/bgp/BgpCliAttrHandlers.h
885+
fboss/cli/fboss2/commands/config/protocol/bgp/policy/CmdConfigProtocolBgpPolicy.cpp
886+
fboss/cli/fboss2/commands/config/protocol/bgp/policy/CmdConfigProtocolBgpPolicy.h
887+
fboss/cli/fboss2/commands/config/protocol/bgp/policy/as-path-list/CmdConfigProtocolBgpPolicyAsPathList.cpp
888+
fboss/cli/fboss2/commands/config/protocol/bgp/policy/as-path-list/CmdConfigProtocolBgpPolicyAsPathList.h
884889
fboss/cli/fboss2/commands/config/ptp/CmdConfigPtp.cpp
885890
fboss/cli/fboss2/commands/config/ptp/CmdConfigPtp.h
886891
fboss/cli/fboss2/commands/config/ptp/transparent_clock/CmdConfigPtpTransparentClock.cpp
@@ -967,6 +972,10 @@ add_library(fboss2_config_lib
967972
fboss/cli/fboss2/commands/delete/protocol/bgp/neighbor/CmdDeleteProtocolBgpNeighbor.h
968973
fboss/cli/fboss2/commands/delete/protocol/bgp/peer-group/CmdDeleteProtocolBgpPeerGroup.cpp
969974
fboss/cli/fboss2/commands/delete/protocol/bgp/peer-group/CmdDeleteProtocolBgpPeerGroup.h
975+
fboss/cli/fboss2/commands/delete/protocol/bgp/policy/CmdDeleteProtocolBgpPolicy.cpp
976+
fboss/cli/fboss2/commands/delete/protocol/bgp/policy/CmdDeleteProtocolBgpPolicy.h
977+
fboss/cli/fboss2/commands/delete/protocol/bgp/policy/as-path-list/CmdDeleteProtocolBgpPolicyAsPathList.cpp
978+
fboss/cli/fboss2/commands/delete/protocol/bgp/policy/as-path-list/CmdDeleteProtocolBgpPolicyAsPathList.h
970979
fboss/cli/fboss2/commands/delete/protocol/CmdDeleteProtocol.h
971980
fboss/cli/fboss2/commands/delete/protocol/static/CmdDeleteProtocolStatic.cpp
972981
fboss/cli/fboss2/commands/delete/protocol/static/CmdDeleteProtocolStatic.h

fboss/cli/fboss2/BUCK

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,8 @@ cpp_library(
11011101
"commands/config/protocol/bgp/global/CmdConfigProtocolBgpGlobal.cpp",
11021102
"commands/config/protocol/bgp/neighbor/CmdConfigProtocolBgpNeighbor.cpp",
11031103
"commands/config/protocol/bgp/peer-group/CmdConfigProtocolBgpPeerGroup.cpp",
1104+
"commands/config/protocol/bgp/policy/CmdConfigProtocolBgpPolicy.cpp",
1105+
"commands/config/protocol/bgp/policy/as-path-list/CmdConfigProtocolBgpPolicyAsPathList.cpp",
11041106
"commands/config/protocol/static/CmdConfigProtocolStatic.cpp",
11051107
"commands/config/protocol/static/route/add/CmdConfigProtocolStaticRouteAdd.cpp",
11061108
"commands/config/ptp/CmdConfigPtp.cpp",
@@ -1145,6 +1147,8 @@ cpp_library(
11451147
"commands/delete/protocol/bgp/CmdDeleteProtocolBgp.cpp",
11461148
"commands/delete/protocol/bgp/neighbor/CmdDeleteProtocolBgpNeighbor.cpp",
11471149
"commands/delete/protocol/bgp/peer-group/CmdDeleteProtocolBgpPeerGroup.cpp",
1150+
"commands/delete/protocol/bgp/policy/CmdDeleteProtocolBgpPolicy.cpp",
1151+
"commands/delete/protocol/bgp/policy/as-path-list/CmdDeleteProtocolBgpPolicyAsPathList.cpp",
11481152
"commands/delete/protocol/static/CmdDeleteProtocolStatic.cpp",
11491153
"commands/delete/protocol/static/route/CmdDeleteProtocolStaticRoute.cpp",
11501154
"commands/delete/qos/CmdDeleteQos.cpp",
@@ -1200,6 +1204,9 @@ cpp_library(
12001204
"commands/config/protocol/bgp/global/CmdConfigProtocolBgpGlobal.h",
12011205
"commands/config/protocol/bgp/neighbor/CmdConfigProtocolBgpNeighbor.h",
12021206
"commands/config/protocol/bgp/peer-group/CmdConfigProtocolBgpPeerGroup.h",
1207+
"commands/config/protocol/bgp/BgpCliAttrHandlers.h",
1208+
"commands/config/protocol/bgp/policy/CmdConfigProtocolBgpPolicy.h",
1209+
"commands/config/protocol/bgp/policy/as-path-list/CmdConfigProtocolBgpPolicyAsPathList.h",
12031210
"commands/config/protocol/static/CmdConfigProtocolStatic.h",
12041211
"commands/config/protocol/static/route/StaticRouteUtils.h",
12051212
"commands/config/protocol/static/route/add/CmdConfigProtocolStaticRouteAdd.h",
@@ -1245,6 +1252,8 @@ cpp_library(
12451252
"commands/delete/protocol/bgp/CmdDeleteProtocolBgp.h",
12461253
"commands/delete/protocol/bgp/neighbor/CmdDeleteProtocolBgpNeighbor.h",
12471254
"commands/delete/protocol/bgp/peer-group/CmdDeleteProtocolBgpPeerGroup.h",
1255+
"commands/delete/protocol/bgp/policy/CmdDeleteProtocolBgpPolicy.h",
1256+
"commands/delete/protocol/bgp/policy/as-path-list/CmdDeleteProtocolBgpPolicyAsPathList.h",
12481257
"commands/delete/protocol/static/CmdDeleteProtocolStatic.h",
12491258
"commands/delete/protocol/static/route/CmdDeleteProtocolStaticRoute.h",
12501259
"commands/delete/qos/CmdDeleteQos.h",

fboss/cli/fboss2/CmdListConfig.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "fboss/cli/fboss2/commands/config/protocol/bgp/global/CmdConfigProtocolBgpGlobal.h"
4242
#include "fboss/cli/fboss2/commands/config/protocol/bgp/neighbor/CmdConfigProtocolBgpNeighbor.h"
4343
#include "fboss/cli/fboss2/commands/config/protocol/bgp/peer-group/CmdConfigProtocolBgpPeerGroup.h"
44+
#include "fboss/cli/fboss2/commands/config/protocol/bgp/policy/CmdConfigProtocolBgpPolicy.h"
45+
#include "fboss/cli/fboss2/commands/config/protocol/bgp/policy/as-path-list/CmdConfigProtocolBgpPolicyAsPathList.h"
4446
#include "fboss/cli/fboss2/commands/config/protocol/static/CmdConfigProtocolStatic.h"
4547
#include "fboss/cli/fboss2/commands/config/protocol/static/route/add/CmdConfigProtocolStaticRouteAdd.h"
4648
#include "fboss/cli/fboss2/commands/config/ptp/CmdConfigPtp.h"
@@ -84,6 +86,8 @@
8486
#include "fboss/cli/fboss2/commands/delete/protocol/bgp/CmdDeleteProtocolBgp.h"
8587
#include "fboss/cli/fboss2/commands/delete/protocol/bgp/neighbor/CmdDeleteProtocolBgpNeighbor.h"
8688
#include "fboss/cli/fboss2/commands/delete/protocol/bgp/peer-group/CmdDeleteProtocolBgpPeerGroup.h"
89+
#include "fboss/cli/fboss2/commands/delete/protocol/bgp/policy/CmdDeleteProtocolBgpPolicy.h"
90+
#include "fboss/cli/fboss2/commands/delete/protocol/bgp/policy/as-path-list/CmdDeleteProtocolBgpPolicyAsPathList.h"
8791
#include "fboss/cli/fboss2/commands/delete/protocol/static/CmdDeleteProtocolStatic.h"
8892
#include "fboss/cli/fboss2/commands/delete/protocol/static/route/CmdDeleteProtocolStaticRoute.h"
8993
#include "fboss/cli/fboss2/commands/delete/qos/CmdDeleteQos.h"
@@ -378,6 +382,23 @@ const CommandTree& kConfigCommandTree() {
378382
commandHandler<CmdConfigProtocolBgpNeighbor>,
379383
argRegistrar<CmdConfigProtocolBgpNeighborTraits>,
380384
},
385+
{
386+
"policy",
387+
"Configure BGP policy objects",
388+
commandHandler<CmdConfigProtocolBgpPolicy>,
389+
argRegistrar<CmdConfigProtocolBgpPolicyTraits>,
390+
{{
391+
"as-path-list",
392+
"Configure BGP AS-path list: <name> "
393+
"[entry <seq-num>] [<attribute> <value> ...] "
394+
"(description; entry <seq-num> "
395+
"asn-regexp|description|match-logic)",
396+
commandHandler<
397+
CmdConfigProtocolBgpPolicyAsPathList>,
398+
argRegistrar<
399+
CmdConfigProtocolBgpPolicyAsPathListTraits>,
400+
}},
401+
},
381402
},
382403
},
383404
{
@@ -656,6 +677,19 @@ const CommandTree& kConfigCommandTree() {
656677
"Delete a BGP peer-group: <name>",
657678
commandHandler<CmdDeleteProtocolBgpPeerGroup>,
658679
argRegistrar<CmdDeleteProtocolBgpPeerGroupTraits>,
680+
},
681+
{
682+
"policy",
683+
"Delete BGP policy objects",
684+
commandHandler<CmdDeleteProtocolBgpPolicy>,
685+
argTypeHandler<CmdDeleteProtocolBgpPolicyTraits>,
686+
{{
687+
"as-path-list",
688+
"Delete a BGP AS-path list: <name>",
689+
commandHandler<CmdDeleteProtocolBgpPolicyAsPathList>,
690+
argRegistrar<
691+
CmdDeleteProtocolBgpPolicyAsPathListTraits>,
692+
}},
659693
}},
660694
},
661695
{
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) 2004-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
*/
10+
11+
#pragma once
12+
13+
#include <fmt/core.h>
14+
#include <cstddef>
15+
#include <functional>
16+
#include <optional>
17+
#include <string>
18+
#include <string_view>
19+
#include <utility>
20+
#include <vector>
21+
#include "fboss/cli/fboss2/commands/config/protocol/bgp/BgpCliValueParsers.h"
22+
#include "fmt/format.h"
23+
24+
/**
25+
* Generic, target-typed per-attribute handler factories shared by the BGP
26+
* `config protocol bgp policy ...` dispatchers.
27+
*
28+
* Unlike the per-command factories in the neighbor/peer-group dispatchers
29+
* (which are hard-wired to a single thrift struct), these are templated on the
30+
* target type T so the same parsing/validation logic can mutate any policy
31+
* object (AsPathList, AsPathListEntry, and — as later object types land —
32+
* CommunityList, PrefixList, BgpPolicyTerm, ...). A handler validates its
33+
* tokens and either mutates T or returns an error the caller surfaces without
34+
* persisting.
35+
*/
36+
namespace facebook::fboss::bgpcli {
37+
38+
using Tokens = std::vector<std::string>;
39+
40+
// A per-attribute handler mutating a typed thrift target T in place.
41+
template <typename T>
42+
using AttrHandler = std::function<Result(T&, const Tokens&)>;
43+
44+
// A single-token string value (names, regex patterns, policy names).
45+
template <typename T>
46+
AttrHandler<T> stringAttr(
47+
std::string_view name,
48+
std::string_view valueName,
49+
std::function<void(T&, const std::string&)> set) {
50+
return [name, valueName, set = std::move(set)](
51+
T& target, const Tokens& values) -> Result {
52+
if (values.size() != 1) {
53+
return err(fmt::format("Error: {} requires <{}>", name, valueName));
54+
}
55+
set(target, values[0]);
56+
return ok(fmt::format("Successfully set {} to: {}", name, values[0]));
57+
};
58+
}
59+
60+
// A free-text string value that may span multiple CLI tokens (descriptions);
61+
// the tokens are re-joined with single spaces.
62+
template <typename T>
63+
AttrHandler<T> joinedStringAttr(
64+
std::string_view name,
65+
std::function<void(T&, const std::string&)> set) {
66+
return
67+
[name, set = std::move(set)](T& target, const Tokens& values) -> Result {
68+
if (values.empty()) {
69+
return err(fmt::format("Error: {} requires <string>", name));
70+
}
71+
std::string joined = values[0];
72+
for (size_t i = 1; i < values.size(); ++i) {
73+
joined += " " + values[i];
74+
}
75+
set(target, joined);
76+
return ok(fmt::format("Successfully set {} to: {}", name, joined));
77+
};
78+
}
79+
80+
// A value drawn from a fixed set of names, mapped to an enum by `lookup`
81+
// (returns std::nullopt for an unrecognized name). `valueDesc` documents the
82+
// accepted names in both the usage and the rejection message.
83+
template <typename T, typename Enum>
84+
AttrHandler<T> enumAttr(
85+
std::string_view name,
86+
std::string_view valueDesc,
87+
std::function<std::optional<Enum>(const std::string&)> lookup,
88+
std::function<void(T&, Enum)> set) {
89+
return [name, valueDesc, lookup = std::move(lookup), set = std::move(set)](
90+
T& target, const Tokens& values) -> Result {
91+
if (values.size() != 1) {
92+
return err(fmt::format("Error: {} requires <{}>", name, valueDesc));
93+
}
94+
auto parsed = lookup(values[0]);
95+
if (!parsed) {
96+
return err(
97+
fmt::format(
98+
"Error: Invalid {} value '{}'; expected {}",
99+
name,
100+
values[0],
101+
valueDesc));
102+
}
103+
set(target, *parsed);
104+
return ok(fmt::format("Successfully set {} to: {}", name, values[0]));
105+
};
106+
}
107+
108+
} // namespace facebook::fboss::bgpcli
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2004-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
*/
10+
11+
#include "fboss/cli/fboss2/commands/config/protocol/bgp/policy/CmdConfigProtocolBgpPolicy.h"
12+
13+
#include "fboss/cli/fboss2/CmdHandler.cpp"
14+
15+
namespace facebook::fboss {
16+
17+
CmdConfigProtocolBgpPolicyTraits::RetType
18+
CmdConfigProtocolBgpPolicy::queryClient(const HostInfo& /* hostInfo */) {
19+
return "BGP policy configuration. Use subcommands: as-path-list";
20+
}
21+
22+
void CmdConfigProtocolBgpPolicy::printOutput(const RetType& output) {
23+
std::cout << output << std::endl;
24+
}
25+
26+
// Explicit template instantiation
27+
template void
28+
CmdHandler<CmdConfigProtocolBgpPolicy, CmdConfigProtocolBgpPolicyTraits>::run();
29+
30+
} // namespace facebook::fboss
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2004-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
*/
10+
11+
#pragma once
12+
13+
#include "fboss/cli/fboss2/CmdHandler.h"
14+
#include "fboss/cli/fboss2/commands/config/protocol/bgp/CmdConfigProtocolBgp.h"
15+
16+
namespace facebook::fboss {
17+
18+
// Grouping node for `config protocol bgp policy <object-type> ...`. Holds no
19+
// state of its own; the per-object-type dispatchers (as-path-list, and later
20+
// community-list/prefix-list/routing-policy) are its subcommands. Mirrors
21+
// CmdConfigProtocolBgp.
22+
struct CmdConfigProtocolBgpPolicyTraits : public WriteCommandTraits {
23+
using ParentCmd = CmdConfigProtocolBgp;
24+
using ObjectArgType = std::monostate;
25+
using RetType = std::string;
26+
};
27+
28+
class CmdConfigProtocolBgpPolicy : public CmdHandler<
29+
CmdConfigProtocolBgpPolicy,
30+
CmdConfigProtocolBgpPolicyTraits> {
31+
public:
32+
using ObjectArgType = CmdConfigProtocolBgpPolicyTraits::ObjectArgType;
33+
using RetType = CmdConfigProtocolBgpPolicyTraits::RetType;
34+
35+
RetType queryClient(const HostInfo& hostInfo);
36+
37+
void printOutput(const RetType& output);
38+
};
39+
40+
} // namespace facebook::fboss

0 commit comments

Comments
 (0)