# snmp1 — MIB-Free RFC 1157 Traps, Enterprise OIDs & Polls (`snmp1`)

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

- **Full Protocol Name:** Simple Network Management Protocol v1
- **Keyword:** `snmp1`
- **OSI Layer & Transport:** Layer 7 · UDP 162 (trap) / UDP 161 (get/set)
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 1157, RFC 1155, RFC 3584
- **Wireshark Display Filter:** `snmp`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> UDP 162 (trap) / UDP 161 (get/set) -> SNMPv1`

## Overview

That 22-year-old UPS in the basement closet still only speaks RFC 1157 `Trap-PDU`. `snmp1` encodes `enterprise`, `agentip`, `gentrap 0..6`, and BER `varbind` chains with zero MIB files.

Simple Network Management Protocol v1 (`snmp1`, RFC 1157) encodes ASN.1 BER `version = 0` management PDUs (`get`, `getnext`, `set`, `response` on **UDP `161`**) and legacy v1 `Trap-PDU` (`0xa4` on **UDP `162`**) carrying dedicated `enterprise`, `agent-addr` (`agentip`), `generic-trap` (`gentrap 0..6`), `specific-trap` (`spectrap`), and `time-stamp` (`sysuptime`) header fields.

FrameAssembly compiles valid ASN.1 BER lengths, base-128 variable-length OID sub-identifiers (`40 * arc1 + arc2`), and repeatable typed `varbind` sequences completely offline—zero external MIB files or Net-SNMP libraries required.

## Minimal Quickstart (`snmp1_quickstart.frasm`)

```frameassembly
host ups_01 { ip 10.10.50.12 }
host nms_rx { ip 10.10.50.100 }

compile {
    ups_01 -> nms_rx snmp1 trap community "public" enterprise 1.3.6.1.4.1.318 gentrap 6 spectrap 5 sysuptime 120500 varbind 1.3.6.1.2.1.1.5.0 string "ups-dc1-row4"
}
```

### Automatic Wire Calculations

- Selects UDP `dstport 162` automatically for `trap` (the default PDU) and UDP `161` (with `161 -> ephemeral` port reversal on `<- response`) for `get`, `getnext`, `set`, and `response`.
- Encodes dotted numeric OIDs (`1.3.6.1.4.1.318` or `.1.3.6.1...`) into compact ASN.1 BER base-128 VLQ octets (`0x2b 0x06 0x01 ...`) and computes nested SEQUENCE lengths.
- Supports repeatable `varbind <oid> <type_val>` entries across `string`, `int`, `oidval`, `ipval`, `counter32`, `gauge32`, `timeticks`, `counter64`, and `null` (or `nullval`).

## Practical Lab Example: SNMPv1 System MIB Poll (`sysDescr.0` / `sysName.0`) + ColdStart & Enterprise Traps (`snmp1_poll_and_traps.frasm`)

Polls `sysDescr.0` on UDP 161, returns a multi-varbind `response`, and emits both a standard `gentrap 0` (`coldStart`) and an `enterpriseSpecific` (`gentrap 6`) hardware alarm trap on UDP 162.

```frameassembly
host poller   { ip 172.16.40.10 }
host legacy_sw { ip 172.16.40.25 }

compile {
    // 1. Poll sysDescr.0 (1.3.6.1.2.1.1.1.0) on UDP 161
    poller -> legacy_sw snmp1 get community "ops-ro" reqid 1001 oid 1.3.6.1.2.1.1.1.0 wait 2ms
    poller <- legacy_sw snmp1 response community "ops-ro" reqid 1001 varbind 1.3.6.1.2.1.1.1.0 string "Managed L2 Switch v4.2" varbind 1.3.6.1.2.1.1.3.0 timeticks 8640000 wait 5ms
    // 2. Generic coldStart trap (gentrap 0, spectrap 0) on UDP 162
    legacy_sw -> poller snmp1 trap community "ops-ro" enterprise 1.3.6.1.4.1.9.1.516 agentip 172.16.40.25 gentrap 0 spectrap 0 sysuptime 120 wait 2ms
    // 3. Enterprise-specific PSU fault trap (gentrap 6, spectrap 42) with typed varbinds
    legacy_sw -> poller snmp1 trap community "ops-ro" enterprise 1.3.6.1.4.1.9.9.13 gentrap 6 spectrap 42 sysuptime 45000 varbind 1.3.6.1.2.1.1.5.0 string "sw-idf-03" varbind 1.3.6.1.4.1.9.9.13.1.5.1.3.1 int 4
}
```

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

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

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

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

## All `snmp1` Keywords & Header Options

Packet line pattern: `src_host -> dst_host snmp1 [trap | get | getnext | set | response] [community "<text>"] [enterprise <oid>] [agentip <ipv4>] [gentrap <0..6>] [spectrap <number>] [sysuptime <number>] [reqid <number>] [oid <oid>] [varbind <oid> <type_val> ...]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `trap \| get \| getnext \| set \| response` | SNMPv1 PDU type keyword | `trap (PDU 0xa4 on UDP 162)` | Selects ASN.1 BER PDU context tag (`0xa0` GetRequest, `0xa1` GetNextRequest, `0xa2` GetResponse, `0xa3` SetRequest, `0xa4` v1 Trap). |
| `community "<text>"` | Double-quoted OCTET STRING | `"public"` | Sets the cleartext SNMPv1 community string. |
| `enterprise <oid>` | Dotted numeric OID (>= 2 arcs) | `1.3.6.1.4.1.8072.3.2.10` | Sets the `enterprise` OBJECT IDENTIFIER inside SNMPv1 `trap` PDUs. |
| `agentip <ipv4>` | IPv4 dotted-quad literal | `Source IPv4 (or 0.0.0.0 on IPv6)` | Sets the 4-byte `NetworkAddress` (`agent-addr`) inside SNMPv1 `trap` PDUs. |
| `gentrap <0..6> \| spectrap <number>` | gentrap: 0..6, spectrap: u32 | `gentrap 6, spectrap 1` | Sets `generic-trap` (`0`=coldStart, `1`=warmStart, `2`=linkDown, `3`=linkUp, `4`=authFailure, `5`=egpNeighborLoss, `6`=enterpriseSpecific) and `specific-trap`. |
| `sysuptime <number> \| reqid <number>` | Whole number | `sysuptime 1000, reqid 1` | Sets `time-stamp` (`TimeTicks` hundredths of a second) on `trap` or `request-id` on `get`/`getnext`/`set`/`response`. |
| `oid <oid>` | Dotted numeric OID | `1.3.6.1.2.1.1.1.0` | Shorthand that appends a `NULL`-valued varbind (`<oid> = NULL`) for `get` / `getnext` requests. |
| `varbind <oid> string "<text>" \| int <number> \| oidval <oid> \| ipval <ipv4> \| counter32 <number> \| gauge32 <number> \| timeticks <number> \| counter64 <number> \| null \| nullval` | Repeatable OID + SMI value keyword | `Omitted` | Appends an ASN.1 BER `VarBind` `(OID, SMI-value)` pair to the `VarBindList` SEQUENCE (`null` and `nullval` are interchangeable aliases). |

## Cross-Layer Options Valid with `snmp1`

| 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) / UDP 161 (get/set)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |

## Common Mistakes & Quick Fixes

### Always Spell Out varbind <oid> string "<val>" (Never str)

- **Avoid:** `ups_01 -> nms_rx snmp1 trap varbind 1.3.6.1.2.1.1.5.0 str "ups-01"`
- **Valid v3.2.2 Syntax:** `ups_01 -> nms_rx snmp1 trap varbind 1.3.6.1.2.1.1.5.0 string "ups-01"`

The SMI OCTET STRING varbind type keyword in FrameAssembly v3.2.0 is strictly `string` (never `str`).

### getbulk and inform Require snmp2 or snmp3

- **Avoid:** `poller -> legacy_sw snmp1 getbulk maxrepetitions 10 oid 1.3.6.1.2.1.2.2.1`
- **Valid v3.2.2 Syntax:** `poller -> legacy_sw snmp2 getbulk maxrepetitions 10 oid 1.3.6.1.2.1.2.2.1`

RFC 1157 SNMPv1 predates `GetBulkRequest` (`0xa5`) and `InformRequest` (`0xa6`); switch the protocol keyword to `snmp2` or `snmp3` for bulk table walks.
