Skip to content

Link event damping feature#1906

Merged
mramezani95 merged 35 commits into
sonic-net:masterfrom
sivat6:link_event_damping_feature
Jun 12, 2026
Merged

Link event damping feature#1906
mramezani95 merged 35 commits into
sonic-net:masterfrom
sivat6:link_event_damping_feature

Conversation

@sivat6

@sivat6 sivat6 commented May 22, 2026

Copy link
Copy Markdown
Contributor
  1. PR#1331 is not yet merged. Added the changes of Add libsai RedisInterface for link event damping. #1331.

Other changes:

  1. Feature Functionality implementation was missing:
    The existing implementation only defines structures and enums for configuration provisioning. The damping functional logic was not implemented. Implemented the damping algorithm as mentioned in the HLD and invoked during the link event handling.

  2. Missing Damping Statistics
    Damping-related counters mentioned in HLD are not present in STATS_DB. Added the damping stats (pre & post damping counters) to STATS_DB

  3. Physical vs Operational State Mismatch
    The damping algorithm is triggered during link up/down events, with timer and threshold checks handled there.
    Once the maximum suppress time is reached, the actual status update occurs only during the next link event, causing a mismatch. Added the timer thread which periodically checks the damping timer and if the damping ends, it updates the physical link status.

Test Plan: Test plan is already in place (https://github.com/sivat6/sonic-mgmt/blob/master/docs/testplan/Link_event_damping.md)

Test Results: This test plan has 9 major test cases and there are about 54 total test cases (Including sub test cases). All these 54 test cases are executed.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

Comment thread lib/ClientSai.cpp
@prsunny

prsunny commented May 22, 2026

Copy link
Copy Markdown
Contributor

@sivat6 , can you check the build failure?

@prsunny

prsunny commented May 22, 2026

Copy link
Copy Markdown
Contributor

HLD PR - sonic-net/SONiC#1071

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 implements the link event damping feature end-to-end in sairedis/syncd: it introduces Redis-extension PORT attributes to configure damping, applies the damping algorithm to port state change notifications in syncd, and adds a periodic timer to end suppression even without new link events.

Changes:

  • Add Redis-extension PORT attributes and plumbing (libsai ⇄ syncd) for link-event damping algorithm/config.
  • Apply damping during port state change notification processing, plus a timer thread to enforce max-suppress-time expiry.
  • Emit per-port damping counters/state into a dedicated DB table for observability.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
unittest/lib/TestClientServerSai.cpp Adds unit tests for setting Redis PORT damping attributes and client-mode rejection.
syncd/tests/TestSyncdLinkEventDamping.cpp Adds a syncd integration-style test for damping config set behavior.
syncd/tests/Makefile.am Registers the new syncd damping test source file.
syncd/Syncd.h Introduces per-port damping state structure, helper APIs, and thread/db members.
syncd/Syncd.cpp Implements config handling, damping algorithm, timer thread, and stats publishing.
syncd/NotificationProcessor.h Extends constructor to accept an optional “apply damping” callback.
syncd/NotificationProcessor.cpp Filters port state change notifications by applying damping before sending.
lib/sairediscommon.h Adds the Redis op name for damping config set.
lib/Sai.cpp Bypasses metadata for Redis PORT extension attributes and routes them to RedisSai.
lib/RedisRemoteSaiInterface.h Declares Redis PORT attribute detection and damping config setter helpers.
lib/RedisRemoteSaiInterface.cpp Implements Redis PORT attribute set handling and op dispatch to syncd.
lib/ClientSai.cpp Rejects Redis extension attrs (including Redis PORT attrs) in CLIENT mode.

Comment thread syncd/Syncd.cpp
Comment thread syncd/Syncd.cpp
Comment thread syncd/Syncd.cpp
Comment thread syncd/Syncd.cpp
Comment thread syncd/Syncd.cpp
Comment thread syncd/Syncd.cpp Outdated
Comment thread syncd/tests/TestSyncdLinkEventDamping.cpp Outdated
Comment thread lib/RedisRemoteSaiInterface.h
Comment thread lib/RedisRemoteSaiInterface.cpp
Comment thread syncd/Syncd.cpp
@prsunny

prsunny commented May 22, 2026

Copy link
Copy Markdown
Contributor

Please address copilot comments

Comment thread syncd/Syncd.cpp Fixed
Comment thread syncd/Syncd.cpp Fixed
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@sivat6

sivat6 commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

Please address copilot comments

Addressed all copilot comments.

@sivat6 sivat6 closed this May 27, 2026
@sivat6 sivat6 reopened this May 27, 2026
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@prsunny

prsunny commented May 28, 2026

Copy link
Copy Markdown
Contributor

Can you check the build failure?

@sivat6 sivat6 force-pushed the link_event_damping_feature branch from 4bb4573 to 8f4866a Compare May 28, 2026 04:02
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

sivat6 added 15 commits June 12, 2026 10:18
Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
…yncd/tests/TestSyncdLinkEventDamping.cpp

Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
Signed-off-by: Sivakumar Thirukkanna Thevar <sthirukkanna@juniper.net>
@sivat6 sivat6 force-pushed the link_event_damping_feature branch from 46ac713 to 6fc0dd4 Compare June 12, 2026 04:49
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

@sivat6

sivat6 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

/azpw retry

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) stages in build 1136667:

✅Stage Test:

  • Job vstest: retried.

Comment thread syncd/Syncd.h
/**
* @brief Link event damping configuration and state per port
*/
struct LinkEventDampingPortState

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this should go to separate header

Comment thread syncd/Syncd.h
* @return true if should suppress, false if should propagate
*/
bool applyAiedAlgorithm(
_In_ sai_object_id_t portVid,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

wrong alignment

Comment thread syncd/Syncd.cpp
Comment on lines +1200 to +1250
// Damping exits when EITHER:
// 1. Time-based: damping_duration_ms >= max_suppress_time
// 2. Penalty-based: current_penalty < reuse_threshold (decay-based recovery)
if (state.is_damping_active)
{
// Check timeout - never suppress longer than max_suppress_time
// This is a hard timestamp-based limit to prevent infinite suppression
uint64_t damping_duration_ms = currentTimeMs - state.damping_start_time_ms;

if (damping_duration_ms >= state.aied_config.max_suppress_time)
{
// Store temporary strings to avoid dangling pointers
std::string physicalStatusStr = sai_serialize_port_oper_status(state.physical_status);
std::string advertisedStatusStr = sai_serialize_port_oper_status(state.advertised_status);
SWSS_LOG_NOTICE("Port VID %s exiting damped state: max suppress time (%u ms) "
"exceeded. Duration: %lu ms. Physical state: %s, Advertised state: %s",
portVidStr.c_str(), state.aied_config.max_suppress_time,
damping_duration_ms, physicalStatusStr.c_str(),
advertisedStatusStr.c_str());
state.is_damping_active = false;
state.damping_start_time_ms = 0; // Reset timer when exiting damping

// Propagate last link event when penalty decays below reuse threshold
if (state.advertised_status != state.physical_status)
{
state.pending_state_sync = true;
SWSS_LOG_NOTICE("Port VID %s state mismatch detected on damping "
"exit (timeout): physical=%s, advertised=%s. "
"Marking for state sync on next notification.",
portVidStr.c_str(), physicalStatusStr.c_str(),
advertisedStatusStr.c_str());
}
state.advertised_status = state.physical_status;

// Write updated state to STATE_DB after exiting damping
writeDampingCountersToStateDb(portVid, state);
}
// Check reuse threshold - exit if penalty decays below threshold
// Penalty decays based on last_decay_time tracking
else if (state.current_penalty < state.aied_config.reuse_threshold)
{
// Store temporary strings to avoid dangling pointers
std::string physicalStatusStr = sai_serialize_port_oper_status(state.physical_status);
std::string advertisedStatusStr = sai_serialize_port_oper_status(state.advertised_status);
SWSS_LOG_NOTICE("Port VID %s exiting damped state: penalty (%u) < "
"reuse_threshold (%u). Penalty decayed due to exponential decay "
"formula. Physical state: %s, Advertised state: %s",
portVidStr.c_str(), state.current_penalty,
state.aied_config.reuse_threshold, physicalStatusStr.c_str(),
advertisedStatusStr.c_str());
state.is_damping_active = false;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

code quality in this function and ohters really suffers, and its not keeping same standard as entire project missing spaces empty lines, just many blobs of code not readable, commnets before else if ..

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.

9 participants