Repository navigation
[Nexthop][fboss2-dev] Add CLI commands for configuring priority group policies - #843
benoit-nexthop wants to merge 1 commit into
Conversation
01bdd17 to
3e5ac6a
Compare
db0cd35 to
d94d34c
Compare
d94d34c to
a46a1d0
Compare
a46a1d0 to
5982895
Compare
|
@joseph5wu has imported this pull request. If you are a Meta employee, you can view this in D95879391. |
Implements new fboss2-dev CLI commands for configuring PFC priority
group policies (`portPgConfigs` in `SwitchConfig`). This allows
configuring per-port priority group settings for traffic prioritization
and buffer management.
New command: `config qos priority-group-policy <policy-name> group-id <id> <attr> <value> [<attr> <value> ...]`
Where <attr> can be:
- `min-limit-bytes`
- `headroom-limit-bytes`
- `resume-offset-bytes`
- `static-limit-bytes`
- `scaling-factor` (accepts `MMUScalingFactor` enum values like `ONE_HALF`, `TWO`, etc)
- `buffer-pool-name`
Multiple attributes can be set in a single command, or one at a time.
The implementation doesn't declare the sub-subcommands in a conventional
way in order to avoid an explosion of `.h` / `.cpp` pairs.
Also updates `ConfigSession::restartAgent()` to use `sudo` for `systemctl restart`
since the CLI may be run by non-root users.
New end to end tests:
```
======================================================================
CLI E2E Test: PFC Configuration
======================================================================
[Step 0] Cleaning up any existing test config...
Copying system config to session config...
Removing PFC-related configs...
Updating metadata for AGENT_RESTART...
Committing cleanup...
Using CLI from FBOSS_CLI_PATH: /home/admin/benoit/fboss2-dev
[CLI] Running: config session commit
[CLI] Completed in 4.90s: config session commit
Cleanup complete
[Step 1] Configuring buffer pool 'cli_e2e_test_buffer_pool'...
[CLI] Running: config qos buffer-pool cli_e2e_test_buffer_pool shared-bytes 78773528
[CLI] Completed in 0.08s: config qos buffer-pool cli_e2e_test_buffer_pool shared-bytes 78773528
[CLI] Running: config qos buffer-pool cli_e2e_test_buffer_pool headroom-bytes 4405376
[CLI] Completed in 0.07s: config qos buffer-pool cli_e2e_test_buffer_pool headroom-bytes 4405376
Buffer pool configured
[Step 2] Configuring priority group policy 'cli_e2e_test_pg_policy'...
Using single-attribute commands for group-ids 2 and 6...
Configuring group-id 2 (one attribute at a time)...
[CLI] Running: config qos priority-group-policy cli_e2e_test_pg_policy group-id 2 min-limit-bytes 14478
[CLI] Completed in 0.08s: config qos priority-group-policy cli_e2e_test_pg_policy group-id 2 min-limit-bytes 14478
...
Using multi-attribute commands for group-ids 0 and 7...
Configuring group-id 0 (all attributes at once)...
[CLI] Running: config qos priority-group-policy cli_e2e_test_pg_policy group-id 0 min-limit-bytes 4826 headroom-limit-bytes 0 resume-offset-bytes 9652 scaling-factor TWO buffer-pool-name cli_e2e_test_buffer_pool
[CLI] Completed in 0.08s: config qos priority-group-policy cli_e2e_test_pg_policy group-id 0 min-limit-bytes 4826 headroom-limit-bytes 0 resume-offset-bytes 9652 scaling-factor TWO buffer-pool-name cli_e2e_test_buffer_pool
Configuring group-id 7 (all attributes at once)...
[CLI] Running: config qos priority-group-policy cli_e2e_test_pg_policy group-id 7 min-limit-bytes 4826 headroom-limit-bytes 0 resume-offset-bytes 9652 scaling-factor TWO buffer-pool-name cli_e2e_test_buffer_pool
[CLI] Completed in 0.07s: config qos priority-group-policy cli_e2e_test_pg_policy group-id 7 min-limit-bytes 4826 headroom-limit-bytes 0 resume-offset-bytes 9652 scaling-factor TWO buffer-pool-name cli_e2e_test_buffer_pool
All priority groups configured
[Step 3] Committing configuration...
[CLI] Running: config session commit
[CLI] Completed in 15.55s: config session commit
Configuration committed successfully
[Step 4] Verifying configuration...
Buffer pool 'cli_e2e_test_buffer_pool' verified
Priority group policy 'cli_e2e_test_pg_policy' verified
======================================================================
TEST PASSED
======================================================================
[Step 5] Cleaning up test config...
Copying system config to session config...
Removing PFC-related configs...
Updating metadata for AGENT_RESTART...
Committing cleanup...
[CLI] Running: config session commit
[CLI] Completed in 6.67s: config session commit
Cleanup complete
```
```
[admin@fboss101 ~]$ ~/benoit/fboss2-dev config qos buffer-pool sample_buffer_pool shared-bytes 78773528
Successfully set shared-bytes for buffer-pool 'sample_buffer_pool' to 78773528
[admin@fboss101 ~]$ ~/benoit/fboss2-dev config qos buffer-pool sample_buffer_pool headroom-bytes 4405376
Successfully set headroom-bytes for buffer-pool 'sample_buffer_pool' to 4405376
[admin@fboss101 ~]$ ~/benoit/fboss2-dev config qos priority-group-policy sample_pg_policy group-id 2 min-limit-bytes 14478 headroom-limit-bytes 726440 resume-offset-bytes 9652 scaling-factor ONE_HALF buffer-pool-name sample_buffer_pool
Successfully configured priority-group-policy 'sample_pg_policy' group-id 2
[admin@fboss101 ~]$ ~/benoit/fboss2-dev config session diff
--- current live config
+++ session config
@@ -121,6 +121,12 @@
"arpAgerInterval": 5,
"arpRefreshSeconds": 20,
"arpTimeoutSeconds": 60,
+ "bufferPoolConfigs": {
+ "sample_buffer_pool": {
+ "headroomBytes": 4405376,
+ "sharedBytes": 78773528
+ }
+ },
"clientIdToAdminDistance": {
"0": 20,
"1": 1,
@@ -2196,6 +2202,19 @@
"maxNeighborProbes": 300,
"mirrorOnDropReports": [],
"mirrors": [],
+ "portPgConfigs": {
+ "sample_pg_policy": [
+ {
+ "bufferPoolName": "sample_buffer_pool",
+ "headroomLimitBytes": 726440,
+ "id": 2,
+ "minLimitBytes": 14478,
+ "name": "pg2",
+ "resumeOffsetBytes": 9652,
+ "sramScalingFactor": 8
+ }
+ ]
+ },
"portQueueConfigs": {},
"ports": [
{
```
5982895 to
fbe8f4d
Compare
|
@benoit-nexthop has updated the pull request. You must reimport the pull request before landing. |
joseph5wu
left a comment
There was a problem hiding this comment.
Please consider add unit tests like you always did in previous PR
|
|
||
| // Current linter doesn't properly handle the template functions which need the | ||
| // following headers | ||
| // IWYU pragma: begin_keep |
There was a problem hiding this comment.
Why do we need this? We prefer not to add too much unnecessary bypass logic
There was a problem hiding this comment.
It's necessary so that the includes don't get flagged as unused. Probably not used inside Meta because you have a different syntax internally, but it's needed on our end to run the check for unused includes.
| * | ||
| */ | ||
|
|
||
| #include <algorithm> |
There was a problem hiding this comment.
Please remove unused include for this PR
There was a problem hiding this comment.
It's fixing a mistake from an earlier PR, there is a sort() call on line 702, so this #include should've been added already.
| static const re2::RE2 kValidPoolNamePattern("^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"); | ||
|
|
||
| for (const auto& [attr, value] : config.getAttributes()) { | ||
| if (attr == "min-limit-bytes") { |
There was a problem hiding this comment.
Can we define all these attribute names as const and a map for the valid attributes like you did in
https://github.com/facebook/fboss/blob/main/fboss/cli/fboss2/commands/config/qos/buffer_pool/CmdConfigQosBufferPool.cpp#L28
So it can be easier to adjust the attribute names in the future without changing too many places like here and all the other loggings.
There was a problem hiding this comment.
The code in that file is also comparing attributes directly, are you saying you want a constant for each name in addition to a map listing valid names?
There was a problem hiding this comment.
Yeah, if the link I commented earlier can use a bit improvement too.
To me, the code might look cleaner if we can do:
/**
* Custom type for priority group configuration.
*
* Parses command line arguments in the format:
* <group-id> [<attr1> <val1> [<attr2> <val2> ...]]
*
* For example:
* 2 min-limit-bytes 42 headroom-limit-bytes 2048
*/
class PriorityGroupConfig : public utils::BaseObjectArgType<std::string> {
public:
// Supported attribute names
static inline const std::string MIN_LIMIT_BYTES = "min-limit-bytes";
static inline const std::string HEADROOM_LIMIT_BYTES = "headroom-limit-bytes";
static inline const std::string RESUME_OFFSITE_BYTES = "resume-offset-bytes";
...
And then all the places where need to use these strings, can just use the static const types.
Basically just wanna avoid typing all these strings everywhere. And it will be super annoying to debug if there's a typo.
I'm landing this PR at the moment. But think about it for your future PRs.
As we're introducing more and more CLIs and some of them needs multiple attributes, so I still think it will make the code cleaner to use the String variables to control all these "magic string" values in the code.
| case utils::ObjectArgTypeId::OBJECT_ARG_TYPE_ID_SCALING_FACTOR: | ||
| subCmd->add_option( | ||
| "scaling_factor", | ||
| args, | ||
| "MMU scaling factor (ONE, EIGHT, ONE_128TH, ONE_64TH, ONE_32TH, " | ||
| "ONE_16TH, ONE_8TH, ONE_QUARTER, ONE_HALF, TWO, FOUR, ONE_32768TH, " | ||
| "ONE_HUNDRED_TWENTY_EIGHT)"); | ||
| break; |
There was a problem hiding this comment.
What's this option for? You used - in the group_config but _ here? Are they different?
|
@joseph5wu merged this pull request in edf7d84. |
Summary: **Pre-submission checklist** - [x] I've ran the linters locally and fixed lint errors related to the files I modified in this PR. You can install the linters by running `pip install -r requirements-dev.txt && pre-commit install` - [x] `pre-commit run` Implements new fboss2-dev CLI commands for configuring PFC (Priority Flow Control) settings on individual interfaces. This allows enabling/disabling PFC, setting watchdog parameters, and associating priority group policies with ports. The command uses a key-value pair syntax that allows setting multiple attributes in a single command: ``` config interface <port> pfc-config <attr> <value> [<attr> <value> ...] ``` Valid attributes: - `tx enabled|disabled` - Enable/disable PFC transmission - `rx enabled|disabled` - Enable/disable PFC reception - `tx-duration enabled|disabled` - Enable/disable TX duration - `rx-duration enabled|disabled` - Enable/disable RX duration - `priority-group-policy <name>` - Set priority group policy - `watchdog-detection-time <ms>` - Set watchdog detection time - `watchdog-recovery-time <ms>` - Set watchdog recovery time - `watchdog-recovery-action drop|no-drop` - Set watchdog recovery action Note: this change is part of a series, the previous one is #843, the next one is #863. Pull Request resolved: #862 Test Plan: New end-to-end tests: ``` ====================================================================== CLI E2E Test: PFC Configuration ====================================================================== [Step 0] Cleaning up any existing test config... [...] Cleanup complete [Step 1] Configuring buffer pool 'cli_e2e_test_buffer_pool'... [...] Buffer pool configured [Step 2] Configuring priority group policy 'cli_e2e_test_pg_policy'... [...] All priority groups configured [Step 3] Configuring PFC on port 'eth1/1/1'... Using single-attribute commands for tx, rx, priority-group-policy... [CLI] Running: config interface eth1/1/1 pfc-config tx enabled [CLI] Completed in 0.07s: config interface eth1/1/1 pfc-config tx enabled [CLI] Running: config interface eth1/1/1 pfc-config rx enabled [CLI] Completed in 0.06s: config interface eth1/1/1 pfc-config rx enabled [CLI] Running: config interface eth1/1/1 pfc-config priority-group-policy cli_e2e_test_pg_policy [CLI] Completed in 0.06s: config interface eth1/1/1 pfc-config priority-group-policy cli_e2e_test_pg_policy Using multi-attribute command for all watchdog settings... [CLI] Running: config interface eth1/1/1 pfc-config watchdog-detection-time 150 watchdog-recovery-time 1000 watchdog-recovery-action no-drop [CLI] Completed in 0.06s: config interface eth1/1/1 pfc-config watchdog-detection-time 150 watchdog-recovery-time 1000 watchdog-recovery-action no-drop Port PFC configured [Step 4] Committing configuration... [CLI] Running: config session commit [CLI] Completed in 11.84s: config session commit Configuration committed successfully [Step 5] Verifying configuration... Buffer pool 'cli_e2e_test_buffer_pool' verified Priority group policy 'cli_e2e_test_pg_policy' verified Port 'eth1/1/1' PFC config verified ====================================================================== TEST PASSED ====================================================================== [Step 6] Cleaning up test config... [...] Cleanup complete ``` ## Sample usage Setting multiple attributes at once: ``` [admin@fboss101 ~]$ ~/benoit/fboss2-dev config interface eth1/1/1 pfc-config tx enabled rx enabled priority-group-policy sample_pg_policy Successfully configured PFC for interface(s) eth1/1/1 [admin@fboss101 ~]$ ~/benoit/fboss2-dev config interface eth1/1/1 pfc-config watchdog-detection-time 150 watchdog-recovery-time 1000 watchdog-recovery-action no-drop Successfully configured PFC for interface(s) eth1/1/1 [admin@fboss101 ~]$ ~/benoit/fboss2-dev config session diff --- current live config +++ session config @@ -2218,6 +2218,16 @@ "rx": false, "tx": false }, + "pfc": { + "portPgConfigName": "sample_pg_policy", + "rx": true, + "tx": true, + "watchdog": { + "detectionTimeMsecs": 150, + "recoveryAction": 0, + "recoveryTimeMsecs": 1000 + } + }, "portType": 0, "profileID": 39, "queues_DEPRECATED": [], ``` Reviewed By: srikrishnagopu, AarjunC Differential Revision: D96549936 Pulled By: joseph5wu fbshipit-source-id: 0cf88e5db3fdcf3bd4a70ffb98a4f4bb6c1d7cc1
Pre-submission checklist
pip install -r requirements-dev.txt && pre-commit installpre-commit runSummary
Implements new fboss2-dev CLI commands for configuring PFC priority
group policies (
portPgConfigsinSwitchConfig). This allowsconfiguring per-port priority group settings for traffic prioritization
and buffer management.
New command:
config qos priority-group-policy <policy-name> group-id <id> <attr> <value> [<attr> <value> ...]Where can be:
min-limit-bytesheadroom-limit-bytesresume-offset-bytesstatic-limit-bytesscaling-factor(acceptsMMUScalingFactorenum values likeONE_HALF,TWO, etc)buffer-pool-nameMultiple attributes can be set in a single command, or one at a time.
The implementation doesn't declare the sub-subcommands in a conventional
way in order to avoid an explosion of
.h/.cpppairs.Also updates
ConfigSession::restartAgent()to usesudoforsystemctl restartsince the CLI may be run by non-root users.
Note: this change is part of a series, the previous one is #838, the next one is #862.
Test Plan
New end to end tests:
Sample usage