Skip to content

[Nexthop][fboss2-dev] Add CLI commands for configuring priority group policies - #843

Closed
benoit-nexthop wants to merge 1 commit into
meta:mainfrom
nexthop-ai:fboss2-cli-prototype_part19
Closed

benoit-nexthop wants to merge 1 commit into
meta:mainfrom
nexthop-ai:fboss2-cli-prototype_part19

Conversation

@benoit-nexthop

@benoit-nexthop benoit-nexthop commented Jan 26, 2026 •

Copy link
Copy Markdown
Contributor

Pre-submission checklist

  • 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
  • pre-commit run

Summary

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 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.

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:

======================================================================
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

Sample usage

[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": [
       {

@meta-cla meta-cla Bot added the CLA Signed label Jan 26, 2026
@benoit-nexthop
benoit-nexthop force-pushed the fboss2-cli-prototype_part19 branch 2 times, most recently from 01bdd17 to 3e5ac6a Compare January 28, 2026 00:28
@benoit-nexthop benoit-nexthop changed the title [Nexthop][fboss2-dev] Add CLI commands for configuring port queue configs (queuing-policy) [Nexthop][fboss2-dev] Add CLI commands for configuring priority group policies Jan 28, 2026
@benoit-nexthop
benoit-nexthop force-pushed the fboss2-cli-prototype_part19 branch 4 times, most recently from db0cd35 to d94d34c Compare January 28, 2026 18:49
@benoit-nexthop
benoit-nexthop force-pushed the fboss2-cli-prototype_part19 branch from d94d34c to a46a1d0 Compare January 29, 2026 02:05
@benoit-nexthop
benoit-nexthop force-pushed the fboss2-cli-prototype_part19 branch from a46a1d0 to 5982895 Compare March 9, 2026 20:29
@benoit-nexthop
benoit-nexthop requested review from a team as code owners March 9, 2026 20:29
@meta-codesync

meta-codesync Bot commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

@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": [
       {
```
@benoit-nexthop
benoit-nexthop force-pushed the fboss2-cli-prototype_part19 branch from 5982895 to fbe8f4d Compare March 10, 2026 00:45
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@benoit-nexthop has updated the pull request. You must reimport the pull request before landing.

@joseph5wu joseph5wu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? We prefer not to add too much unnecessary bypass logic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove unused include for this PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@joseph5wu joseph5wu Mar 13, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +271 to +278
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this option for? You used - in the group_config but _ here? Are they different?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These maps onto this enum.

@meta-codesync

meta-codesync Bot commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

@joseph5wu merged this pull request in edf7d84.

meta-codesync Bot pushed a commit that referenced this pull request Mar 17, 2026
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
@benoit-nexthop
benoit-nexthop deleted the fboss2-cli-prototype_part19 branch March 20, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants