Skip to content

snmpagent: Implement an asyncio-based SNMP trap infrastructure supporting link up/down, PSU, and fan traps#366

Open
Griffin-micas wants to merge 1 commit intosonic-net:masterfrom
Griffin-micas:add-linkupdown-psu-fan-trap
Open

snmpagent: Implement an asyncio-based SNMP trap infrastructure supporting link up/down, PSU, and fan traps#366
Griffin-micas wants to merge 1 commit intosonic-net:masterfrom
Griffin-micas:add-linkupdown-psu-fan-trap

Conversation

@Griffin-micas
Copy link

- What I did

  • Added an asyncio-based SNMP Trap infrastructure (TrapInfra) to SONiC SNMP agent.
  • Implemented native support for Link Up/Down and PSU / FAN SNMP traps.
  • Generated traps as AgentX Notify PDUs carrying snmpTrapOID.0 and business varbinds, while keeping the final SNMP notification version and behavior (trap / inform) fully controlled by snmpd configuration.
  • Ensured traps are triggered only on semantic state changes, preventing unnecessary trap storms.

- How I did it

Introduced a generic TrapInfra layer that:

  • Subscribes to Redis keyspace notifications (multi-DB, multi-instance supported).
  • Dispatches events to corresponding trap handlers using asyncio tasks.
  • Wraps handler output into AgentX NotifyPDUs and forwards them to snmpd.

Implemented dedicated trap handlers:

  1. Link Up/Down traps
  • Trap OIDs: linkUp (1.3.6.1.6.3.1.1.5.4), linkDown (1.3.6.1.6.3.1.1.5.3)
  • Varbinds: ifIndex, ifAdminStatus, ifOperStatus
  • Interface index resolved via mibs.get_index_from_str(ifName)
  1. PSU / FAN traps
  • FAN Trap OID: 1.3.6.1.4.1.9.9.117.1.4.1.1.1
  • PSU Trap OID: 1.3.6.1.4.1.9.9.117.1.1.2.1.2
  • Index values derived deterministically from object names (PSU, FANTRAY)

All handlers compute varbinds based on state transitions, not raw field updates.
TrapInfra lifecycle is fully asyncio-managed and supports graceful shutdown.

- How to verify it

  1. Configure SNMP trap destinations in snmpd.
  2. Start snmpagent container and confirm TrapInfra subscriptions are active.
  3. Trigger events on DUT:
    Link state change (config interface shutdown/startup)
    PSU or FAN state change (hardware event or simulated Redis update)
  4. Verify:
    SNMP notifications are sent as v1/v2c Notifications.
    snmpTrapOID.0 matches the expected trap OID.
    Varbind values (ifIndex, ifOperStatus, PSU/FAN status) are correct.
    No duplicate traps are generated without actual semantic state changes.

- Description for the changelog

Add asyncio-based SNMP trap infrastructure with native support for link and PSU/FAN notifications.

Which release branch to backport (provide reason below if selected)

  • 202511

Reason for backport:
This change provides standard SNMP trap support (link, PSU, and FAN), which is required for basic device monitoring and NMS integration.
The implementation is self-contained, does not change existing SNMP behavior unless traps are explicitly configured, and is safe to include in 202511 releases.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 5, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Griffin-micas / name: Griffin Gao (5449e15)

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

…ting link up/down, PSU, and fan traps

Signed-off-by: Griffin Gao <griffin@micasnetworks.com>
@Griffin-micas Griffin-micas force-pushed the add-linkupdown-psu-fan-trap branch from 5c40128 to 5449e15 Compare February 5, 2026 07:02
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Griffin-micas
Copy link
Author

@qiluo-msft Hi Qiluo, could you please take a look at this PR when you have time? Thanks!

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.

2 participants