# Test Encrypted SNMPv3 Traps Before an Actual Outage

> **FrameAssembly v3.3.0** · Operational Playbook (Telemetry, VoIP & OT) · Canonical URL: https://frameassembly-lang.dev/use-cases/simulate-snmpv3-trap

Verify Zabbix, PRTG, LibreNMS, or snmptrapd decrypts your SHA-256 + AES-128 traps before 3 AM finds a passphrase typo.

- **Category:** Telemetry, VoIP & OT
- **Capture Filename:** `snmpv3_trap_test.frasm` (2 Ethernet frames)
- **Protocols Exercised:** `vlan`, `snmp3`

## Operational Problem

SNMPv3 traps travel one way (rtr -> nms) with zero handshake—if your EngineID, boot counter, or AES passphrase is off by one character, your collector silently drops the packet and nobody gets paged.

With SNMPv3 GET polling, the collector talks to the router first and learns its EngineID automatically. Traps skip that step: a single UDP 162 packet arrives unannounced, and if snmptrapd or Zabbix disagrees on one nibble of EngineID or SHA-256/AES-128 key localization, nothing shows up in the event log.

Trying to test it with Net-SNMP’s snmptrap CLI usually means fighting missing MIB directories, only for the packet to leave from your laptop Wi-Fi IP instead of 10.250.1.1 so the collector ignores it anyway.

## Scenario & Topology: Edge Router linkDown -> 10s Wait -> linkUp Recovery on VLAN 20

- **Topology:** `Edge Router (10.250.1.1, EngineID 8000000903001c73a00001) -> Mgmt VLAN 20 -> Trap Collector (10.250.100.50:162)`

You moved edge-rtr-01 (10.250.1.1) on VLAN 20 from old SNMPv2c "public" to SNMPv3 authPriv (SHA-256 + AES-128). Two lines emit the router’s exact IP/MAC, send an encrypted TenGigabitEthernet0/1/0 linkDown trap (ifOperStatus = 2), advance 10s on the capture clock, and send the matching linkUp recovery trap (ifOperStatus = 1).

## FrameAssembly Workflow

Runs real RFC 3414/7860 USM key localization + AES-128-CFB encryption to emit a VLAN 20 linkDown trap followed 10s later by linkUp.

### Adapt It for Your Network

1. Set edge_router ip to the exact switch or router management IP your monitoring server expects.
2. Paste your real hex engineid, username, sha256 auth passphrase, and aes priv passphrase.
3. Compile -> double-check decryption in Wireshark’s SNMP Users table -> replay with tcpreplay.

## Runnable Capture Specification (`snmpv3_trap_test.frasm`)

```frameassembly
host edge_router   { ip 10.250.1.1    mac 00:1c:73:a0:00:01 }
host nms_collector { ip 10.250.100.50 mac 00:50:56:a0:00:50 }

flow link_flap_snmpv3_traps(rtr, nms) {
    // 1. Encrypted SNMPv3 authPriv linkDown trap (ifOperStatus = 2 down) on Mgmt VLAN 20
    rtr -> nms vlan 20 snmp3 trap user "noc_sha256_aes" engineid "8000000903001c73a00001"
        engineboots 12 enginetime 86400
        auth sha256 "AuthKey_SHA256_99!" priv aes "PrivKey_AES128_99!"
        oid 1.3.6.1.6.3.1.1.5.3
        varbind 1.3.6.1.2.1.1.5.0 string "edge-rtr-01.dc1"
        varbind 1.3.6.1.2.1.2.2.1.2.5 string "TenGigabitEthernet0/1/0"
        varbind 1.3.6.1.2.1.2.2.1.8.5 int 2 wait 10s

    // 2. Recovery SNMPv3 authPriv linkUp trap 10s later (ifOperStatus = 1 up)
    rtr -> nms vlan 20 snmp3 trap user "noc_sha256_aes" engineid "8000000903001c73a00001"
        engineboots 12 enginetime 86410
        auth sha256 "AuthKey_SHA256_99!" priv aes "PrivKey_AES128_99!"
        oid 1.3.6.1.6.3.1.1.5.4
        varbind 1.3.6.1.2.1.1.5.0 string "edge-rtr-01.dc1"
        varbind 1.3.6.1.2.1.2.2.1.2.5 string "TenGigabitEthernet0/1/0"
        varbind 1.3.6.1.2.1.2.2.1.8.5 int 1 wait 5ms
}

compile {
    link_flap_snmpv3_traps(edge_router, nms_collector)
}
```

## Equivalent CLI Commands

```bash
# 1. Compile the encrypted SNMPv3 authPriv linkDown + linkUp capture
frameassembly snmpv3_trap_test.frasm snmpv3_trap_test.pcap

# 2. Inspect SNMPv3 USM EngineID, Boots, Time, and Username in tshark
tshark -r snmpv3_trap_test.pcap -Y "snmp" -V

# 3. Replay the encrypted traps toward Zabbix, PRTG, LibreNMS, or snmptrapd
sudo tcpreplay -i eth0 snmpv3_trap_test.pcap
```

## Protocol Reference Links

- [`vlan` — IEEE 802.1Q Virtual LAN Tagging & 802.1p QoS](https://frameassembly-lang.dev/docs/protocols/vlan) ([Raw .md](https://frameassembly-lang.dev/docs/protocols/vlan.md))
- [`snmp3` — Simple Network Management Protocol v3 with USM Auth & Privacy](https://frameassembly-lang.dev/docs/protocols/snmp3) ([Raw .md](https://frameassembly-lang.dev/docs/protocols/snmp3.md))
