# SNMPv1, SNMPv2c & Encrypted SNMPv3 USM Protocols

> **FrameAssembly v3.2.2** · Category 04 (Layer 7 · 3 Protocols) · Canonical URL: https://frameassembly-lang.dev/docs/protocols/categories/l7-snmp

Validating Zabbix, PRTG, Checkmk, LibreNMS, or `snmptrapd` alert pipelines normally requires either pulling live fiber on a maintenance window or fighting `snmptrap` MIB search paths and Net-SNMP engineBoot caches. FrameAssembly encodes ASN.1 BER Object Identifiers and all 9 SMI varbind types directly from numeric OIDs with zero external MIB files.

For `snmp3`, the compiler executes genuine RFC 3414 and RFC 7860 password-to-key (`Ku -> Kul`) localization against your hex `engineid`, signs the whole message with live HMAC (`md5`, `sha`, `sha256`, `sha384`, or `sha512`), and encrypts the `ScopedPDU` with `aes` (AES-128-CFB) or `des` so Wireshark and `snmptrapd` decrypt the capture natively.

## Category Wire & Endpoint Rules

- **Automatic Port 161 vs. Port 162 Selection:** `trap`, `inform`, and `report` default to UDP `dstport 162`; `get`, `getnext`, `getbulk`, `set`, and `response` default to UDP `dstport 161`.
- **Strict SMI Value Keywords (`string` & `oidval`):** Repeatable `varbind <oid> <type> <val>` clauses use `string "<text>"` (never `str`), `int`, `oidval <oid>`, `ipval <ipv4>`, `counter32`, `gauge32`, `timeticks`, `counter64`, `opaque`, or `null`.
- **SNMPv2c / SNMPv3 Trap OID Convention:** Pass `sysuptime <ticks>` to prepend `sysUpTime.0` (`1.3.6.1.2.1.1.3.0`) and `varbind 1.3.6.1.6.3.1.1.4.1.0 oidval <trap_oid>` for `snmpTrapOID.0` (never a hallucinated `trapoid` keyword).
- **Even-Length Hex `engineid` Validation:** `snmp3` validates at compile time that `engineid` is even-length ASCII hex (e.g. `"80001f888001020304"`) before deriving localized `authPriv` keys.

## Multi-Protocol Example: SNMPv1 Enterprise Trap, SNMPv2c GetBulk & Encrypted SNMPv3 USM Trap (`snmp_v1_v2c_v3_usm.frasm`)

Generates an RFC 1157 SNMPv1 enterprise trap, an SNMPv2c 64-bit interface counter `getbulk` + `response` poll on UDP 161, and an RFC 7860 SHA-256 + AES-128 encrypted SNMPv3 `linkDown` trap on UDP 162.

```frameassembly
host core_rtr { ip 10.40.1.1 }
host nms_srv  { ip 10.40.1.100 }

compile {
    core_rtr -> nms_srv snmp1 trap community "noc-ro" enterprise 1.3.6.1.4.1.9.9.43 gentrap 6 spectrap 1 sysuptime 125000 varbind 1.3.6.1.2.1.1.5.0 string "core-rtr-01" wait 3ms
    nms_srv -> core_rtr snmp2 getbulk community "noc-ro" reqid 901 nonrepeaters 0 maxrepetitions 5 oid 1.3.6.1.2.1.31.1.1.1.6 wait 2ms
    nms_srv <- core_rtr snmp2 response community "noc-ro" reqid 901 varbind 1.3.6.1.2.1.31.1.1.1.6.1 counter64 98412044500 wait 3ms
    core_rtr -> nms_srv snmp3 trap user "secops" engineid "80001f888001020304" engineboots 4 enginetime 3600 auth sha256 "AuthSecret2026!" priv aes "PrivSecret2026!" sysuptime 410000 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3 varbind 1.3.6.1.2.1.2.2.1.2.1 string "TenGigE0/0/1"
}
```

```bash
# 1. Eyeball relative timestamps, ports & wire lengths in your terminal
frameassembly show snmp_v1_v2c_v3_usm.frasm

# 2. Compile .frasm -> classic .pcap (tcpdump/tcpreplay/Suricata) or nanosecond .pcapng
frameassembly snmp_v1_v2c_v3_usm.frasm snmp_v1_v2c_v3_usm.pcap
frameassembly snmp_v1_v2c_v3_usm.frasm snmp_v1_v2c_v3_usm.pcapng

# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture
frameassembly reverse snmp_v1_v2c_v3_usm.pcap snmp_v1_v2c_v3_usm_edited.frasm

# 4. Verify dissected protocol fields in tshark
tshark -r snmp_v1_v2c_v3_usm.pcap -Y "snmp"
```

- **Wireshark Display Filter:** `snmp`

## Protocols in Category 04 (3 Native Builders)

| # | Keyword | Protocol | Default Port / Proto | Endpoint Rule | Wireshark Filter | Spec URL |
| --- | --- | --- | --- | --- | --- | --- |
| 32 | `snmp1` | Simple Network Management Protocol v1 | `UDP 162 (trap) / UDP 161 (get/set)` | Dual-Stack IPv4/IPv6 | `snmp` | https://frameassembly-lang.dev/docs/protocols/snmp1 |
| 33 | `snmp2` | Simple Network Management Protocol v2c | `UDP 162 (trap/inform) / UDP 161 (get/getbulk)` | Dual-Stack IPv4/IPv6 | `snmp` | https://frameassembly-lang.dev/docs/protocols/snmp2 |
| 34 | `snmp3` | Simple Network Management Protocol v3 with USM Auth & Privacy | `UDP 162 (trap/inform/report) / UDP 161 (get/getbulk)` | Dual-Stack IPv4/IPv6 | `snmp` | https://frameassembly-lang.dev/docs/protocols/snmp3 |
