Skip to content

[Link Event Damping] Add config/show/clear CLI commands - #4367

Open
DendroLabs wants to merge 5 commits into
sonic-net:masterfrom
DendroLabs:link-event-damping/cli
Open

[Link Event Damping] Add config/show/clear CLI commands#4367
DendroLabs wants to merge 5 commits into
sonic-net:masterfrom
DendroLabs:link-event-damping/cli

Conversation

@DendroLabs

Copy link
Copy Markdown

Summary

Supersedes #3001 by @Ashish1805. Adds complete CLI support for the Link Event Damping feature (HLD: sonic-net/SONiC#1071).

All review feedback from #3001 has been addressed:

Commands added:

config interface dampening <interface> enable [options]

  • Enables AIED dampening with industry-standard defaults (half-life=5s, reuse=1000, suppress=2000, max-suppress=20s, penalty=1000)
  • --monitor flag enables monitor-only mode (RFC 7196 "Calculate But Do Not Damp")
  • Validates: interface exists, reuse < suppress, half-life <= max-suppress-time

config interface dampening <interface> disable

  • Disables dampening on the interface

show interfaces dampening [interface_name]

  • Displays config parameters and operational state (current penalty, suppressed status, time remaining)
  • Shows "(Mon)" for monitor-only mode interfaces
  • Shows per-interface dampening counters when querying a specific port

sonic-clear interfaces dampening [interface_name]

  • Resets penalty to 0 and immediately unsuppresses
  • Standard across Cisco/Juniper; recommended by RFC 2439

New features not in any other NOS vendor:

  • Monitor-only mode (--monitor): Calculates penalties and emits syslog but does NOT suppress events. Allows safe parameter tuning in production. Recommended by RFC 7196; no vendor has implemented this.
  • Syslog integration: Syncd emits WARNING on suppress, NOTICE on unsuppress (addresses use new file location for sys eeprom and sfp eeprom on msn2700 #1 industry complaint about silent suppression)

Test plan

  • config interface dampening enable writes correct fields to CONFIG_DB PORT table
  • config interface dampening disable resets all fields
  • config interface dampening enable --monitor sets algorithm to "aied-monitor"
  • Parameter validation rejects invalid combinations (reuse >= suppress, etc.)
  • show interfaces dampening displays configured interfaces
  • show interfaces dampening <port> shows counters
  • sonic-clear interfaces dampening writes clear flag to STATE_DB
  • Existing sonic-utilities tests pass (no regressions)

🤖 Generated with Claude Code

Co-Authored-By: Ashish Singh ashish.singh@google.com

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@linux-foundation-easycla

linux-foundation-easycla Bot commented Mar 17, 2026

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

@azure-pipelines

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

Implements CLI support for RFC 2439/7196 link event dampening:
- config interface dampening enable/disable: configure AIED dampening
  with validation (IntRange per review feedback), monitor-only mode,
  and configurable flap-penalty
- show interfaces dampening: display config and operational state from
  CONFIG_DB and STATE_DB with per-interface counters
- sonic-clear interfaces dampening: reset penalty via STATE_DB flag

Supersedes sonic-net#3001 with improvements:
- click.IntRange validation (per @Junchao-Mellanox review)
- Monitor-only mode per RFC 7196 "Calculate But Do Not Damp"
- Configurable flap-penalty (vs hardcoded 1000)
- Show command with operational state and counters
- Clear command per RFC 2439 Section 4.8.6

Signed-off-by: DendroLabs <info@dendrolabs.com>
- Guard against exponential overflow in ceiling calculation
- Add interface alias support to clear command
- Improve error handling consistency

Signed-off-by: DendroLabs <info@dendrolabs.com>
@DendroLabs
DendroLabs force-pushed the link-event-damping/cli branch from cf10a20 to f484733 Compare March 17, 2026 15:56
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@DendroLabs

Copy link
Copy Markdown
Author

/easycla

- Add missing blank line before dampening subgroup (E302)
- Fix continuation line indentation in warning messages (E127)

Signed-off-by: DendroLabs <info@dendrolabs.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

Tests cover config enable/disable, show, and clear commands:
- Config: defaults, custom params, monitor mode, validation
  (invalid interface, reuse>=suppress, half-life>max-suppress,
  IntRange bounds, overflow warning)
- Show: no config, disabled, configured, monitor mode display
- Clear: specific interface, all interfaces, no config, invalid

Signed-off-by: DendroLabs <info@dendrolabs.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

Signed-off-by: DendroLabs <info@dendrolabs.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@DendroLabs

Copy link
Copy Markdown
Author

Hi @prsunny @Junchao-Mellanox — friendly ping on this PR. The companion sairedis PRs are progressing (sonic-net/sonic-sairedis#1798 merged, sonic-net/sonic-sairedis#1935 open for review), and this CLI PR addresses all the feedback from the original #3001. CI was green when submitted. Would appreciate a review when you get a chance. Thanks!

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

Pull request overview

This PR adds end-to-end CLI support in sonic-utilities for the Link Event Dampening feature by introducing new config, show, and sonic-clear commands, along with unit tests.

Changes:

  • Added config interface dampening <interface> enable|disable to configure AIED dampening parameters (including monitor-only mode) in CONFIG_DB.
  • Added show interfaces dampening [interface] to display dampening configuration plus operational state/counters.
  • Added sonic-clear interfaces dampening [interface] to request clearing (reset/unsuppress) of dampening state via STATE_DB, and added unit tests for the new CLIs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
config/main.py Adds dampening subgroup under config interface with enable/disable commands and parameter validation.
show/interfaces/__init__.py Adds show interfaces dampening plus helper to print per-interface dampening counters.
clear/main.py Adds sonic-clear interfaces dampening command that writes clear requests to STATE_DB.
tests/link_event_damping_test.py Adds unit tests covering config/show/clear CLI behavior and validation scenarios.

Comment thread config/main.py
Comment on lines +6392 to +6396
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")

Comment thread config/main.py
Comment on lines +6449 to +6453
if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")

Comment thread clear/main.py
Comment on lines +794 to +798
click.echo("Error: invalid interface alias {}".format(alias))
sys.exit(1)
if interface_name not in port_table:
click.echo("Error: Interface {} does not exist".format(interface_name))
sys.exit(1)
Comment thread clear/main.py
Comment on lines +811 to +813
state_db = SonicV2Connector(host="127.0.0.1")
state_db.connect(state_db.STATE_DB)

Comment on lines +1463 to +1465
config_db = db.cfgdb
state_db = db.db

@prsunny

prsunny commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

@DendroLabs , could you check copilot comments and address them.

@qiluo-msft qiluo-msft closed this Jun 9, 2026
auto-merge was automatically disabled June 9, 2026 18:11

Pull request was closed

@qiluo-msft qiluo-msft reopened this Jun 9, 2026
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

Comment thread clear/main.py
Without an interface name, clears dampening on all interfaces.
The interface is immediately unsuppressed if currently damped.
"""
config_db = ConfigDBConnector()

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.

host CONFIG_DB only — on multi-ASIC, PORT lives in per-namespace CONFIG_DB and that's where orchagent reads. Same issue with ctx.obj['config_db'] in the enable/disable commands. See how config interface ip add resolves the namespace via multi_asic.get_port_namespace(port) / db.cfgdb_clients[ns].

@prsunny

prsunny commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

@DendroLabs , could you address comment?

@DendroLabs

Copy link
Copy Markdown
Author

Thanks @prsunny. Before I push the namespace fixes, I want to surface something I ran into while wiring the CLI against the now merged syncd implementation (#1906), because I think it is a design question worth settling together rather than me papering over it in the CLI.

What I am trying to do: make show/clear interfaces dampening work end to end as the operator facing front door for this feature, the same way operators already use show/clear for every other port level function.

Where the CLI and the merged syncd schema do not line up today:

  1. STATE_DB key format. [port2alias]: Fix to get right number of return values #1906 writes the LINK_EVENT_DAMPING_STATS table keyed by the raw SAI port VID (oid:0x...). Every other operator facing STATE_DB port table (PORT_TABLE, transceiver, and so on) is keyed by port name (Ethernet0). Keying by VID means the CLI has to go through COUNTERS_PORT_NAME_MAP just to find a row, and anyone inspecting STATE_DB by hand cannot map entries back to ports. I would like to propose the stats table be keyed by port name for consistency and operator usability.

  2. Manual clear. RFC 2439 section 4.8.6 calls out operator ability to manually clear damping, and Cisco and Juniper both expose it (clear interface dampening). The merged syncd does not yet have a handler for a clear request, so sonic-clear interfaces dampening has nothing to talk to. I would like to add that path so the clear command is real.

  3. Monitor only mode. RFC 7196 recommends a dry run capability so operators can validate thresholds in production before any real suppression. My earlier work implemented this as an aied-monitor algorithm value (penalties and syslog computed, events not suppressed). The merged swss algorithm map only accepts disabled and aied, so there is currently no home for it. I think it is a meaningful safety feature and would like to find the right place for it.

Why it matters: without these, the CLI either reports N/A against a real switch (show), silently does nothing (clear), or rejects a documented mode (monitor). I would rather get the schema right than ship a front end that quietly does not match the back end.

That said, I am very happy to defer to you and @sivat6 on how to land this. If you would prefer I align the CLI to the existing VID keyed schema for now and treat the clear and monitor pieces as later follow ups, I am glad to do that and keep moving on the namespace fixes in parallel. If you would rather settle the schema first, I am happy to go whichever way fits best with how you see this feature evolving. Just let me know the direction you would like and I will follow it.

@prsunny

prsunny commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

@DendroLabs , my ask is to address copilot comments and from @qiluo-msft . not sure which one specifically you are referring to.

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.

5 participants