Skip to content

Commit e99d556

Browse files
Add fboss2-dev delete copp subcommands (cpu-queue, reason)
Delete-side counterparts for the copp config commands: delete copp cpu-queue <id> - remove the whole sw.cpuQueues[] entry; refused while rxReason mappings (the ordered list or the deprecated rxReasonToCPUQueue map, which the agent still reads as a fallback) or matchToAction actions (send-to-queue, user-defined-trap) still reference the queue id, naming each referencing entry delete copp reason <reason-name> - remove the rxReasonToQueueOrderedList entry Per-attribute deletes (cpu-queue <id> name, cpu-queue <id> rate-limit) are left for a follow-up. Queue-id parsing/lookup and reason-name parsing move out of CmdConfigCopp.cpp into the copp_cpu_queue and copp_reason namespaces in a new CoppUtils.{h,cpp} so the config and delete trees share one implementation. Both handlers save with ConfigActionLevel::HITLESS, matching the config-side handlers. This also introduces the `delete copp` parent command node, which does not exist upstream yet (#1379 adds it too, for the cpu-traffic-policy delete; whichever lands second is a trivial merge).
1 parent 76ceb9c commit e99d556

20 files changed

Lines changed: 1192 additions & 58 deletions

cmake/CliFboss2.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,8 @@ add_library(fboss2_config_lib
824824
fboss/cli/fboss2/commands/config/arp/CmdConfigArp.h
825825
fboss/cli/fboss2/commands/config/copp/CmdConfigCopp.cpp
826826
fboss/cli/fboss2/commands/config/copp/CmdConfigCopp.h
827+
fboss/cli/fboss2/commands/config/copp/CoppUtils.cpp
828+
fboss/cli/fboss2/commands/config/copp/CoppUtils.h
827829
fboss/cli/fboss2/commands/config/dhcp/CmdConfigDhcp.cpp
828830
fboss/cli/fboss2/commands/config/dhcp/CmdConfigDhcp.h
829831
fboss/cli/fboss2/commands/config/dhcp/relay_source_override/CmdConfigDhcpRelaySourceOverride.cpp
@@ -1084,6 +1086,12 @@ add_library(fboss2_config_lib
10841086
fboss/cli/fboss2/commands/delete/protocol/static/route/CmdDeleteProtocolStaticRoute.h
10851087
fboss/cli/fboss2/commands/delete/arp/CmdDeleteArp.cpp
10861088
fboss/cli/fboss2/commands/delete/arp/CmdDeleteArp.h
1089+
fboss/cli/fboss2/commands/delete/copp/CmdDeleteCopp.cpp
1090+
fboss/cli/fboss2/commands/delete/copp/CmdDeleteCopp.h
1091+
fboss/cli/fboss2/commands/delete/copp/cpu_queue/CmdDeleteCoppCpuQueue.cpp
1092+
fboss/cli/fboss2/commands/delete/copp/cpu_queue/CmdDeleteCoppCpuQueue.h
1093+
fboss/cli/fboss2/commands/delete/copp/reason/CmdDeleteCoppReason.cpp
1094+
fboss/cli/fboss2/commands/delete/copp/reason/CmdDeleteCoppReason.h
10871095
fboss/cli/fboss2/commands/delete/tunnel/CmdDeleteTunnel.cpp
10881096
fboss/cli/fboss2/commands/delete/tunnel/CmdDeleteTunnel.h
10891097
fboss/cli/fboss2/commands/delete/tunnel/ip_in_ip/CmdDeleteTunnelIpInIp.cpp

cmake/CliFboss2TestConfig.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ add_executable(fboss2_cmd_config_test
3939
fboss/cli/fboss2/test/config/CmdDeleteAclRuleTest.cpp
4040
fboss/cli/fboss2/test/config/CmdDeleteArpTest.cpp
4141
fboss/cli/fboss2/test/config/CmdDeleteConfigInterfaceTest.cpp
42+
fboss/cli/fboss2/test/config/CmdDeleteCoppCpuQueueTest.cpp
43+
fboss/cli/fboss2/test/config/CmdDeleteCoppReasonTest.cpp
4244
fboss/cli/fboss2/test/config/CmdDeleteDhcpTest.cpp
4345
fboss/cli/fboss2/test/config/CmdDeleteInterfaceIpv6NdpTest.cpp
4446
fboss/cli/fboss2/test/config/CmdDeleteInterfaceTest.cpp

cmake/CliFboss2TestIntegrationTest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ add_executable(fboss2_integration_test
1818
fboss/cli/fboss2/test/integration_test/ConfigDhcpSourceOverrideTest.cpp
1919
fboss/cli/fboss2/test/integration_test/ConfigInterfaceDescriptionTest.cpp
2020
fboss/cli/fboss2/test/integration_test/ConfigInterfaceIpv6NdpTest.cpp
21+
fboss/cli/fboss2/test/integration_test/DeleteCoppTest.cpp
2122
fboss/cli/fboss2/test/integration_test/DeleteInterfaceTest.cpp
2223
fboss/cli/fboss2/test/integration_test/ConfigInterfaceMtuTest.cpp
2324
fboss/cli/fboss2/test/integration_test/ConfigInterfaceProfileTest.cpp

fboss/cli/fboss2/BUCK

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ cpp_library(
10741074
"commands/config/acl/rule/CmdConfigAclRule.cpp",
10751075
"commands/config/arp/CmdConfigArp.cpp",
10761076
"commands/config/copp/CmdConfigCopp.cpp",
1077+
"commands/config/copp/CoppUtils.cpp",
10771078
"commands/config/dhcp/CmdConfigDhcp.cpp",
10781079
"commands/config/dhcp/relay_source_override/CmdConfigDhcpRelaySourceOverride.cpp",
10791080
"commands/config/dhcp/reply_source_override/CmdConfigDhcpReplySourceOverride.cpp",
@@ -1194,6 +1195,9 @@ cpp_library(
11941195
"commands/delete/acl/CmdDeleteAcl.cpp",
11951196
"commands/delete/acl/rule/CmdDeleteAclRule.cpp",
11961197
"commands/delete/arp/CmdDeleteArp.cpp",
1198+
"commands/delete/copp/CmdDeleteCopp.cpp",
1199+
"commands/delete/copp/cpu_queue/CmdDeleteCoppCpuQueue.cpp",
1200+
"commands/delete/copp/reason/CmdDeleteCoppReason.cpp",
11971201
"commands/delete/dhcp/CmdDeleteDhcp.cpp",
11981202
"commands/delete/dhcp/relay_source_override/CmdDeleteDhcpRelaySourceOverride.cpp",
11991203
"commands/delete/dhcp/reply_source_override/CmdDeleteDhcpReplySourceOverride.cpp",
@@ -1226,6 +1230,7 @@ cpp_library(
12261230
"commands/config/acl/rule/CmdConfigAclRule.h",
12271231
"commands/config/arp/CmdConfigArp.h",
12281232
"commands/config/copp/CmdConfigCopp.h",
1233+
"commands/config/copp/CoppUtils.h",
12291234
"commands/config/dhcp/CmdConfigDhcp.h",
12301235
"commands/config/dhcp/relay_source_override/CmdConfigDhcpRelaySourceOverride.h",
12311236
"commands/config/dhcp/reply_source_override/CmdConfigDhcpReplySourceOverride.h",
@@ -1333,6 +1338,9 @@ cpp_library(
13331338
"commands/delete/acl/CmdDeleteAcl.h",
13341339
"commands/delete/acl/rule/CmdDeleteAclRule.h",
13351340
"commands/delete/arp/CmdDeleteArp.h",
1341+
"commands/delete/copp/CmdDeleteCopp.h",
1342+
"commands/delete/copp/cpu_queue/CmdDeleteCoppCpuQueue.h",
1343+
"commands/delete/copp/reason/CmdDeleteCoppReason.h",
13361344
"commands/delete/dhcp/CmdDeleteDhcp.h",
13371345
"commands/delete/dhcp/relay_source_override/CmdDeleteDhcpRelaySourceOverride.h",
13381346
"commands/delete/dhcp/reply_source_override/CmdDeleteDhcpReplySourceOverride.h",

fboss/cli/fboss2/CmdListConfig.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
#include "fboss/cli/fboss2/commands/delete/acl/rule/CmdDeleteAclRule.h"
133133
#include "fboss/cli/fboss2/commands/delete/arp/CmdDeleteArp.h"
134134
#include "fboss/cli/fboss2/commands/delete/config/CmdDeleteConfig.h"
135+
#include "fboss/cli/fboss2/commands/delete/copp/CmdDeleteCopp.h"
136+
#include "fboss/cli/fboss2/commands/delete/copp/cpu_queue/CmdDeleteCoppCpuQueue.h"
137+
#include "fboss/cli/fboss2/commands/delete/copp/reason/CmdDeleteCoppReason.h"
135138
#include "fboss/cli/fboss2/commands/delete/dhcp/CmdDeleteDhcp.h"
136139
#include "fboss/cli/fboss2/commands/delete/dhcp/relay_source_override/CmdDeleteDhcpRelaySourceOverride.h"
137140
#include "fboss/cli/fboss2/commands/delete/dhcp/reply_source_override/CmdDeleteDhcpReplySourceOverride.h"
@@ -1163,6 +1166,26 @@ const CommandTree& kConfigCommandTree() {
11631166
commandHandler<CmdDeleteConfig>,
11641167
argRegistrar<CmdDeleteConfigTraits>},
11651168

1169+
{
1170+
"delete",
1171+
"copp",
1172+
"Delete COPP (Control Plane Policing) configuration",
1173+
commandHandler<CmdDeleteCopp>,
1174+
argRegistrar<CmdDeleteCoppTraits>,
1175+
{{
1176+
"cpu-queue",
1177+
"Delete a CPU queue entry",
1178+
commandHandler<CmdDeleteCoppCpuQueue>,
1179+
argRegistrar<CmdDeleteCoppCpuQueueTraits>,
1180+
},
1181+
{
1182+
"reason",
1183+
"Delete a packet-rx reason to CPU queue mapping",
1184+
commandHandler<CmdDeleteCoppReason>,
1185+
argRegistrar<CmdDeleteCoppReasonTraits>,
1186+
}},
1187+
},
1188+
11661189
{
11671190
"delete",
11681191
"dhcp",

fboss/cli/fboss2/commands/config/copp/CmdConfigCopp.cpp

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515

1616
#include <fmt/format.h>
1717
#include <folly/Conv.h>
18-
#include <folly/String.h>
1918
#include <thrift/lib/cpp/util/EnumUtils.h>
20-
#include <cctype>
2119
#include <cstdint>
2220
#include <iostream>
2321
#include <stdexcept>
2422
#include <string>
2523
#include <string_view>
2624
#include <utility>
2725
#include <vector>
26+
#include "fboss/cli/fboss2/commands/config/copp/CoppUtils.h"
2827
#include "fboss/cli/fboss2/gen-cpp2/cli_metadata_types.h"
2928
#include "fboss/cli/fboss2/session/ConfigSession.h"
3029
#include "fboss/cli/fboss2/utils/HostInfo.h"
@@ -39,55 +38,12 @@ constexpr std::string_view kSubCmdRateLimit = "rate-limit";
3938
constexpr std::string_view kRateUnitKbps = "kbps";
4039
constexpr std::string_view kRateUnitPps = "pps";
4140

41+
using copp_cpu_queue::parseQueueId;
42+
4243
// Literal tokens accepted between the reason name and queue id in
4344
// `config copp reason <reason-name> queue <id>`.
4445
constexpr std::string_view kSubCmdQueue = "queue";
4546

46-
// CPU queue IDs are a small platform-bounded set; reject anything that is
47-
// clearly out of range before we construct a PortQueue. The actual per-ASIC
48-
// cap is enforced by the agent (SaiHostifManager::getMaxCpuQueues) at apply
49-
// time.
50-
constexpr int16_t kMaxCpuQueueId = 255;
51-
52-
// Normalize a user-typed reason name: uppercase + dashes->underscores, so
53-
// that "arp", "ARP", "bgp-v6", "bgpv6" all match the cfg::PacketRxReason
54-
// enum names ("ARP", "BGPV6", ...).
55-
std::string normalizeReason(const std::string& v) {
56-
std::string out;
57-
out.reserve(v.size());
58-
for (unsigned char c : v) {
59-
out.push_back(c == '-' ? '_' : std::toupper(c));
60-
}
61-
return out;
62-
}
63-
64-
std::string validReasonNames() {
65-
std::vector<std::string> names;
66-
for (auto value : apache::thrift::TEnumTraits<cfg::PacketRxReason>::values) {
67-
names.push_back(apache::thrift::util::enumNameSafe(value));
68-
}
69-
return folly::join(", ", names);
70-
}
71-
72-
int16_t parseQueueId(const std::string& s, std::string_view context) {
73-
int16_t parsed = 0;
74-
try {
75-
parsed = folly::to<int16_t>(s);
76-
} catch (const folly::ConversionError&) {
77-
throw std::invalid_argument(
78-
fmt::format("Queue ID ({}) must be an integer, got '{}'", context, s));
79-
}
80-
if (parsed < 0 || parsed > kMaxCpuQueueId) {
81-
throw std::invalid_argument(
82-
fmt::format(
83-
"Queue ID ({}) must be in [0, {}], got {}",
84-
context,
85-
kMaxCpuQueueId,
86-
parsed));
87-
}
88-
return parsed;
89-
}
90-
9147
int32_t parseRateMax(const std::string& s, std::string_view unit) {
9248
int32_t parsed = 0;
9349
try {
@@ -112,10 +68,9 @@ int32_t parseRateMax(const std::string& s, std::string_view unit) {
11268
// populated cpuQueues list.
11369
cfg::PortQueue& findOrCreateCpuQueue(cfg::SwitchConfig& swConfig, int16_t id) {
11470
auto& queues = *swConfig.cpuQueues();
115-
for (auto& q : queues) {
116-
if (*q.id() == id) {
117-
return q;
118-
}
71+
auto it = copp_cpu_queue::findCpuQueue(queues, id);
72+
if (it != queues.end()) {
73+
return *it;
11974
}
12075
cfg::PortQueue q;
12176
q.id() = id;
@@ -202,13 +157,7 @@ CoppReasonArgs::CoppReasonArgs(std::vector<std::string> v) {
202157
kSubCmdQueue,
203158
v.size()));
204159
}
205-
cfg::PacketRxReason reason{};
206-
if (!apache::thrift::TEnumTraits<cfg::PacketRxReason>::findValue(
207-
normalizeReason(v[0]), &reason)) {
208-
throw std::invalid_argument(
209-
fmt::format(
210-
"Unknown reason name '{}'. Valid: {}", v[0], validReasonNames()));
211-
}
160+
cfg::PacketRxReason reason = copp_reason::parseReason(v[0]);
212161
if (v[1] != kSubCmdQueue) {
213162
throw std::invalid_argument(
214163
fmt::format(

fboss/cli/fboss2/commands/config/copp/CmdConfigCopp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#pragma once
1212

1313
#include <cstdint>
14+
#include <stdexcept>
1415
#include <string>
1516
#include <vector>
1617
#include "fboss/agent/gen-cpp2/switch_config_types.h"
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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/copp/CoppUtils.h"
12+
13+
#include <fmt/format.h>
14+
#include <folly/Conv.h>
15+
#include <folly/String.h>
16+
#include <thrift/lib/cpp/util/EnumUtils.h>
17+
#include <algorithm>
18+
#include <cctype>
19+
#include <stdexcept>
20+
21+
namespace facebook::fboss {
22+
23+
namespace copp_cpu_queue {
24+
25+
int16_t parseQueueId(const std::string& s, std::string_view context) {
26+
int16_t parsed = 0;
27+
try {
28+
parsed = folly::to<int16_t>(s);
29+
} catch (const folly::ConversionError&) {
30+
throw std::invalid_argument(
31+
fmt::format("Queue ID ({}) must be an integer, got '{}'", context, s));
32+
}
33+
if (parsed < 0 || parsed > kMaxCpuQueueId) {
34+
throw std::invalid_argument(
35+
fmt::format(
36+
"Queue ID ({}) must be in [0, {}], got {}",
37+
context,
38+
kMaxCpuQueueId,
39+
parsed));
40+
}
41+
return parsed;
42+
}
43+
44+
std::vector<cfg::PortQueue>::iterator findCpuQueue(
45+
std::vector<cfg::PortQueue>& queues,
46+
int16_t id) {
47+
return std::find_if(
48+
queues.begin(), queues.end(), [id](const cfg::PortQueue& q) {
49+
return *q.id() == id;
50+
});
51+
}
52+
53+
} // namespace copp_cpu_queue
54+
55+
namespace copp_reason {
56+
57+
std::string normalizeReason(const std::string& v) {
58+
std::string out;
59+
out.reserve(v.size());
60+
for (unsigned char c : v) {
61+
out.push_back(c == '-' ? '_' : std::toupper(c));
62+
}
63+
return out;
64+
}
65+
66+
std::string validReasonNames() {
67+
std::vector<std::string> names;
68+
for (auto value : apache::thrift::TEnumTraits<cfg::PacketRxReason>::values) {
69+
names.push_back(apache::thrift::util::enumNameSafe(value));
70+
}
71+
return folly::join(", ", names);
72+
}
73+
74+
cfg::PacketRxReason parseReason(const std::string& s) {
75+
cfg::PacketRxReason reason{};
76+
if (!apache::thrift::TEnumTraits<cfg::PacketRxReason>::findValue(
77+
normalizeReason(s), &reason)) {
78+
throw std::invalid_argument(
79+
fmt::format(
80+
"Unknown reason name '{}'. Valid: {}", s, validReasonNames()));
81+
}
82+
return reason;
83+
}
84+
85+
} // namespace copp_reason
86+
87+
} // namespace facebook::fboss
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 <cstdint>
14+
#include <string>
15+
#include <string_view>
16+
#include <vector>
17+
#include "fboss/agent/gen-cpp2/switch_config_types.h"
18+
19+
namespace facebook::fboss {
20+
21+
// Shared vocabulary for the copp cpu-queue commands, used by both the
22+
// `config` and `delete` command trees so queue-id parsing and lookup live
23+
// in one place.
24+
namespace copp_cpu_queue {
25+
26+
// CPU queue IDs are a small platform-bounded set; reject anything that is
27+
// clearly out of range before touching the config. The actual per-ASIC cap
28+
// is enforced by the agent (SaiHostifManager::getMaxCpuQueues) at apply
29+
// time.
30+
constexpr int16_t kMaxCpuQueueId = 255;
31+
32+
int16_t parseQueueId(const std::string& s, std::string_view context);
33+
34+
// Return an iterator to the cpuQueues entry with `id`, or end().
35+
std::vector<cfg::PortQueue>::iterator findCpuQueue(
36+
std::vector<cfg::PortQueue>& queues,
37+
int16_t id);
38+
39+
} // namespace copp_cpu_queue
40+
41+
// Shared vocabulary for the copp reason commands, used by both the `config`
42+
// and `delete` command trees so reason-name parsing stays consistent.
43+
namespace copp_reason {
44+
45+
// Normalize a user-typed reason name: uppercase + dashes->underscores, so
46+
// that "arp", "ARP", "ttl-1", "ttl_1" all match the cfg::PacketRxReason
47+
// enum names ("ARP", "TTL_1", ...).
48+
std::string normalizeReason(const std::string& v);
49+
50+
std::string validReasonNames();
51+
52+
cfg::PacketRxReason parseReason(const std::string& s);
53+
54+
} // namespace copp_reason
55+
56+
} // namespace facebook::fboss
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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/delete/copp/CmdDeleteCopp.h"
12+
13+
#include "fboss/cli/fboss2/CmdHandler.cpp"
14+
15+
namespace facebook::fboss {
16+
17+
// Explicit template instantiation
18+
template void CmdHandler<CmdDeleteCopp, CmdDeleteCoppTraits>::run();
19+
20+
} // namespace facebook::fboss

0 commit comments

Comments
 (0)