Skip to content

[pfcwd]: Reject start when detection or restoration time is below polling interval#4599

Open
Bojun-Feng wants to merge 1 commit into
sonic-net:masterfrom
Bojun-Feng:bug/pfcwd-invalid-polling-interval
Open

[pfcwd]: Reject start when detection or restoration time is below polling interval#4599
Bojun-Feng wants to merge 1 commit into
sonic-net:masterfrom
Bojun-Feng:bug/pfcwd-invalid-polling-interval

Conversation

@Bojun-Feng

@Bojun-Feng Bojun-Feng commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

What I did

Fix #4520

Added validation to reject pfcwd start when detection time or restoration time is smaller than the configured polling interval. Previously, the CLI accepted any value within the Click argument range (100–5000ms for detection, 100–60000ms for restoration) without cross-checking against the global POLL_INTERVAL. This results in a nonsensical configuration where the watchdog cannot accurately detect or restore within the configured timeframe.

The reverse direction is already validated. pfcwd interval rejects values exceeding any configured detection/restoration time. The YANG model also enforces both constraints via must clauses, but only during config load / GCU operations and not through the pfcwd start CLI path which writes directly to ConfigDB.

Also fixed existing unit tests that were using detection/restoration values below the mock POLL_INTERVAL, which were never caught because no validation existed.

How I did it

  • Read POLL_INTERVAL from PFC_WD|GLOBAL in start_cmd before writing config, reject invalid settings
  • Use strict greater-than comparison (equal values are allowed, consistent with interval command)
  • Update existing tests to use valid values (≥ POLL_INTERVAL)
  • Add rejection tests for invalid values

How to verify it

admin@sonic:~$ sudo pfcwd interval 500
admin@sonic:~$ sudo pfcwd start --action drop Ethernet0 200
detection time 200ms is smaller than the configured polling interval 500ms, please use a larger detection time or reduce the polling interval
admin@sonic:~$ sudo pfcwd start --action drop --restoration-time 200 Ethernet0 600
restoration time 200ms is smaller than the configured polling interval 500ms, please use a larger restoration time or reduce the polling interval
admin@sonic:~$ sudo pfcwd start --action drop --restoration-time 500 Ethernet0 500
(succeeds — equal values are allowed)

Previous command output (if the output of a command-line utility has changed)

admin@sonic:~$ sudo pfcwd interval 500
admin@sonic:~$ sudo pfcwd start --action drop Ethernet0 200
(silently accepted — invalid configuration applied to ConfigDB)

New command output (if the output of a command-line utility has changed)

admin@sonic:~$ sudo pfcwd interval 500
admin@sonic:~$ sudo pfcwd start --action drop Ethernet0 200
detection time 200ms is smaller than the configured polling interval 500ms, please use a larger detection time or reduce the polling interval

…ling interval

* Add validation in start_cmd to reject detection_time < configured POLL_INTERVAL
* Add validation in start_cmd to reject restoration_time < configured POLL_INTERVAL
* Fix existing tests that used detection_time below POLL_INTERVAL (nonsensical values)
* Add rejection tests: detection_time only, restoration_time only

Signed-off-by: Bojun-Feng <bojundf@gmail.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PFC Watchdog Allows Invalid Configuration where Polling Interval Exceeds Detection Time

2 participants