# snmp2 — MIB-Free SNMPv2c Traps, Informs & GetBulk Sweeps (`snmp2`)

> **FrameAssembly v3.2.2** · Protocol 33 of 81 · Canonical URL: https://frameassembly-lang.dev/docs/protocols/snmp2

- **Full Protocol Name:** Simple Network Management Protocol v2c
- **Keyword:** `snmp2`
- **OSI Layer & Transport:** Layer 7 · UDP 162 (trap/inform) / UDP 161 (get/getbulk)
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 3416, RFC 3418, RFC 2863
- **Wireshark Display Filter:** `snmp`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> UDP 162 (trap/inform) / UDP 161 (get/getbulk) -> SNMPv2c`

## Overview

Testing a Zabbix, PRTG, or Prometheus alert rule from your desk? `snmp2 trap` and `snmp2 inform` pack `sysUpTime.0`, `snmpTrapOID.0`, and 64-bit `counter64` varbinds straight from numeric OIDs.

Simple Network Management Protocol v2c (`snmp2`, RFC 3416) upgrades SNMPv1 (`version = 1`) with high-throughput **`getbulk`** table retrieval (`0xa5` using `nonrepeaters` and `maxrepetitions`), 64-bit **`counter64`** `ifXTable` interface counters, acknowledged **`inform`** notifications (`0xa6`), and unified varbind-based **`SNMPv2-Trap`** (`0xa7`) framing.

When `sysuptime` is provided on `snmp2 trap`, `inform`, or `report`, FrameAssembly automatically prepends the mandatory RFC 3416 `sysUpTime.0` (`1.3.6.1.2.1.1.3.0`) varbind ahead of your `snmpTrapOID.0` (`1.3.6.1.6.3.1.1.4.1.0`) and payload varbinds.

## Minimal Quickstart (`snmp2_quickstart.frasm`)

```frameassembly
host core_sw { ip 10.20.1.1 }
host nms_srv { ip 10.20.1.50 }

compile {
    nms_srv -> core_sw snmp2 getbulk community "ops-ro" reqid 501 nonrepeaters 0 maxrepetitions 10 oid 1.3.6.1.2.1.31.1.1.1.6 wait 2ms
    nms_srv <- core_sw snmp2 response community "ops-ro" reqid 501 varbind 1.3.6.1.2.1.31.1.1.1.6.1 counter64 98765432100
}
```

### Automatic Wire Calculations

- Encodes `GetBulkRequest` (`0xa5`) overloading the BER error-status and error-index slots with `nonrepeaters` (default `0`) and `maxrepetitions` (default `10`) per RFC 3416.
- Automatically prepends `1.3.6.1.2.1.1.3.0` (`sysUpTime.0` `TimeTicks`) on `trap` (`0xa7`), `inform` (`0xa6`), and `report` (`0xa8`) when `sysuptime` is specified.
- Routes `trap`, `inform`, and `report` to UDP `162` and `get`/`getnext`/`getbulk`/`set` to UDP `161`, reversing ports automatically on `<- response`.

## Practical Lab Example: ifXTable 64-Bit Counter Walk + Acknowledged SNMPv2c LinkDown Inform (`snmp2_getbulk_and_inform.frasm`)

Walks 64-bit high-capacity interface counters via `getbulk` on UDP 161, then delivers a reliable `snmp2 inform` (`linkDown` `1.3.6.1.6.3.1.1.5.3`) on UDP 162 with manager `response` acknowledgment.

```frameassembly
host nms_poller { ip 10.30.10.20 }
host dist_sw    { ip 10.30.10.1 }

compile {
    // 1. High-capacity 64-bit interface counter bulk poll on UDP 161
    nms_poller -> dist_sw snmp2 getbulk community "infra-ro" reqid 2001 nonrepeaters 1 maxrepetitions 5 varbind 1.3.6.1.2.1.1.3.0 null varbind 1.3.6.1.2.1.31.1.1.1.6 null wait 2ms
    nms_poller <- dist_sw snmp2 response community "infra-ro" reqid 2001 varbind 1.3.6.1.2.1.1.3.0 timeticks 43200000 varbind 1.3.6.1.2.1.31.1.1.1.6.101 counter64 184502910440 varbind 1.3.6.1.2.1.31.1.1.1.1.101 string "TenGigabitEthernet1/0/1" wait 5ms
    // 2. Acknowledged SNMPv2c InformRequest for linkDown (1.3.6.1.6.3.1.1.5.3) on UDP 162
    dist_sw -> nms_poller snmp2 inform community "infra-trap" reqid 9001 sysuptime 43200500 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.1.101 int 101 varbind 1.3.6.1.2.1.2.2.1.8.101 int 2 wait 1ms
    dist_sw <- nms_poller snmp2 response community "infra-trap" reqid 9001 varbind 1.3.6.1.2.1.1.3.0 timeticks 43200500 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3
}
```

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

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

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

# 4. Verify dissected protocol fields in tshark
tshark -r snmp2_getbulk_and_inform.pcap
```

## All `snmp2` Keywords & Header Options

Packet line pattern: `src_host -> dst_host snmp2 [trap | inform | report | get | getnext | getbulk | set | response] [community "<text>"] [reqid <number>] [nonrepeaters <number>] [maxrepetitions <number>] [sysuptime <number>] [oid <oid>] [varbind <oid> <type_val> ...]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `trap \| inform \| report \| get \| getnext \| getbulk \| set \| response` | SNMPv2c PDU type keyword | `trap (PDU 0xa7 on UDP 162)` | Selects RFC 3416 BER PDU tag (`0xa0`..`0xa3` or `0xa5` GetBulk, `0xa6` Inform, `0xa7` SNMPv2-Trap, `0xa8` Report). |
| `community "<text>"` | Double-quoted OCTET STRING | `"public"` | Sets the SNMPv2c community string. |
| `nonrepeaters <number> \| maxrepetitions <number>` | Whole number | `nonrepeaters 0, maxrepetitions 10` | Sets scalar `non-repeaters` count and tabular `max-repetitions` row count on `getbulk` PDUs. |
| `sysuptime <number>` | 32-bit TimeTicks (1/100s) | `Omitted (or auto-prepended when set)` | Prepends `1.3.6.1.2.1.1.3.0 = TimeTicks(<sysuptime>)` as the first varbind on `trap`, `inform`, and `report`. |
| `reqid <number> \| oid <oid>` | u32 request ID, dotted OID | `reqid 1, oid 1.3.6.1.2.1.1.1.0` | Sets 32-bit `request-id` and appends a `NULL`-valued query OID. |
| `varbind <oid> string "<text>" \| int <number> \| oidval <oid> \| ipval <ipv4> \| counter32 <number> \| gauge32 <number> \| timeticks <number> \| counter64 <number> \| null \| nullval` | Repeatable OID + SMIv2 value keyword | `Omitted` | Appends typed SMIv2 `VarBind` entries (`null` and `nullval` are interchangeable aliases; use `1.3.6.1.6.3.1.1.4.1.0 oidval <oid>` for `snmpTrapOID.0`). |

## Cross-Layer Options Valid with `snmp2`

| Option | Range / Format | Default | Effect |
| --- | --- | --- | --- |
| `wait <number><ns\|us\|ms\|s\|m>` | Time gap (ns, us, ms, s, m) | `10ms` | Advances the packet timestamp clock after sending this packet and before the next packet (`wait 0ns` sends back-to-back). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"` or `"de:ad:be:ef"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType u16 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or 16-bit EtherType for this single packet. |
| `vlan <0..4095> [pcp <0..7>] [dei <0\|1>]` | VLAN ID 0..4095, PCP 0..7, DEI 0..1 | `Untagged` | Wraps the packet in an IEEE 802.1Q VLAN tag (`0x8100`) with optional 802.1p QoS priority. |
| `qinq <0..4095> [innervlan <0..4095>]` | Outer S-VLAN 0..4095, Inner C-VLAN 0..4095 | `Untagged (innervlan 1 when qinq is set)` | Double-tags the packet with outer IEEE 802.1ad S-Tag (`0x88a8`) plus inner IEEE 802.1Q C-Tag (`0x8100`). |
| `mpls <0..1048575> [label <0..1048575>] [exp\|tc <0..7>] [bos <0\|1>] [mplsttl <0..255>]` | Label 0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255 | `Unlabeled (at most 1 mpls tag per packet)` | Inserts a 32-bit MPLS label header (`0x8847`) ahead of the Layer 3 header. |
| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 64, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |
| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>]` | IPv4 ID, DF/MF flags, fragment offset 0..8191 | `ipid 1, flags 0, fragoffset 0` | Sets IPv4 Identification, Do-Not-Fragment (`df`), More-Fragments (`mf`), and fragment offset (ignored over IPv6). |
| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (ignored when running over IPv4 hosts). |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 162 (trap/inform) / UDP 161 (get/getbulk)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |

## Common Mistakes & Quick Fixes

### Pass snmpTrapOID.0 via varbind 1.3.6.1.6.3.1.1.4.1.0 oidval <oid> (Never trapoid)

- **Avoid:** `dist_sw -> nms_poller snmp2 trap trapoid 1.3.6.1.6.3.1.1.5.3`
- **Valid v3.2.2 Syntax:** `dist_sw -> nms_poller snmp2 trap sysuptime 5000 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3`

In RFC 3416 SNMPv2c/v3, trap OIDs are regular varbinds rather than dedicated v1 header slots. Pass `1.3.6.1.6.3.1.1.4.1.0` (`snmpTrapOID.0`) with the `oidval` type keyword.

### Use string (Not str) for Text Varbinds

- **Avoid:** `dist_sw -> nms_poller snmp2 response varbind 1.3.6.1.2.1.1.5.0 str "core-sw"`
- **Valid v3.2.2 Syntax:** `dist_sw -> nms_poller snmp2 response varbind 1.3.6.1.2.1.1.5.0 string "core-sw"`

Always write `string "<value>"` for OCTET STRING varbinds across `snmp1`, `snmp2`, and `snmp3`.
