# hsrp — Cisco HSRPv1 (1985) & HSRPv2 (2029) Standby Frames (`hsrp`)

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

- **Full Protocol Name:** Cisco Hot Standby Router Protocol v1 & v2
- **Keyword:** `hsrp`
- **OSI Layer & Transport:** Layer 3 · UDP 1985 (v1) / UDP 2029 (v2)
- **Host Endpoint Rule:** Dual-Stack Morphing (v4/v6)
- **Standards:** RFC 2281
- **Wireshark Display Filter:** `hsrp || hsrp2`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> HSRPv1 / HSRPv2 (UDP 1985 (v1) / UDP 2029 (v2))`

## Overview

Cisco’s classic gateway protocol: `hsrp` writes HSRPv1 (`UDP 1985`) on IPv4 and automatically upgrades to TLV-formatted HSRPv2 (`UDP 2029`) on IPv6 endpoints.

Hot Standby Router Protocol (`hsrp`, RFC 2281) is Cisco’s First-Hop Redundancy Protocol. Between IPv4 hosts, FrameAssembly builds 20-byte **HSRPv1** Hellos on **UDP `1985 -> 1985`** (Opcode `0` Hello, State, `hellotime`, `holdtime`, Priority, Group, 8-byte cleartext `auth` string, and Virtual IP `vip`). Between IPv6 hosts, `hsrp` automatically switches to **HSRPv2** TLV format on **UDP `2029 -> 2029`**.

Fields `group`, `priority`, `state`, `hellotime`, and `holdtime` each take a 1-byte value (`0..255`).

## Minimal Quickstart (`hsrp_quickstart.frasm`)

```frameassembly
host dist_sw1 { ip 10.20.10.2 mac 00:00:0c:07:ac:0a }
host all_rtrs { ip 224.0.0.2 }

compile {
    dist_sw1 -> all_rtrs hsrp group 10 priority 110 state 16 vip 10.20.10.1
}
```

### Automatic Wire Calculations

- Defaults UDP source and destination ports to `1985 -> 1985` on IPv4 (HSRPv1) or `2029 -> 2029` on IPv6 (HSRPv2 TLV).
- Zero-pads or truncates `auth` cleanly into the fixed 8-byte RFC 2281 Authentication Data field (default `"cisco\0\0\0"`).
- Validates `hellotime` and `holdtime` within `0..=255` (`u8`) at compile time and derives `01:00:5e:00:00:02` (`224.0.0.2`) multicast MACs automatically.

## Practical Lab Example: Campus VLAN 20 Active/Standby HSRP Pair Plus HSRPv2 IPv6 Gateway (`hsrp_active_standby.frasm`)

Models two distribution switches exchanging Active (`state 16`, `priority 110`) and Standby (`state 8`, `priority 100`) HSRPv1 Hellos on VLAN 20 alongside an IPv6 HSRPv2 Active router.

```frameassembly
host dist_a   { ip 10.20.20.2 mac 00:00:0c:07:ac:14 }
host dist_b   { ip 10.20.20.3 mac 00:1c:73:20:00:03 }
host hsrp_v4  { ip 224.0.0.2 }
host dist6_a  { ip fe80::20:2 mac 00:05:73:a0:00:14 }
host hsrp_v6  { ip ff02::66 }

compile {
    // 1. Active router (state 16, priority 110, virtual MAC 00:00:0c:07:ac:14 for group 20)
    dist_a -> hsrp_v4 hsrp group 20 priority 110 state 16 hellotime 3 holdtime 10 auth "corpkey1" vip 10.20.20.1 vlan 20 ttl 1 dscp 48 wait 3ms
    // 2. Standby router (state 8, priority 100) monitoring Active peer
    dist_b -> hsrp_v4 hsrp group 20 priority 100 state 8 hellotime 3 holdtime 10 auth "corpkey1" vip 10.20.20.1 vlan 20 ttl 1 dscp 48 wait 5ms
    // 3. HSRPv2 over IPv6 on UDP 2029 -> ff02::66
    dist6_a -> hsrp_v6 hsrp group 20 priority 110 state 16 hellotime 3 holdtime 10 vip 2001:db8:20::1 vlan 20 ttl 255
}
```

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

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

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

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

## All `hsrp` Keywords & Header Options

Packet line pattern: `src_host -> dst_host hsrp [group <0..255>] [priority <0..255>] [state <0..255>] [hellotime <0..255>] [holdtime <0..255>] [auth "<text>"] [vip <ip>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `group <0..255>` | Whole number (0..255) (0..255) | `1` | Sets the Standby Group number (HSRPv1 virtual MACs follow `00:00:0c:07:ac:<group_hex>`). |
| `priority <0..255>` | Whole number (0..255) (0..255) | `100` | Sets router election priority (higher value wins when preemption is enabled). |
| `state <0..255>` | 8-bit RFC 2281 HSRP state code | `16 (Active)` | Sets router state: `0` Initial, `1` Learn, `2` Listen, `4` Speak, `8` Standby, `16` Active. |
| `hellotime <0..255> \| holdtime <0..255>` | 8-bit unsigned integers (seconds) | `hellotime 3, holdtime 10` | Sets the 1-byte Hello Time and Hold Time fields in seconds. |
| `auth "<text>"` | ASCII string (up to 8 bytes in v1) | `"cisco"` | Populates the 8-byte Authentication Data field in HSRPv1 packets. |
| `vip <ip>` | IPv4 or IPv6 Virtual IP address | `Source host IP` | Sets the shared Virtual IP address served by the HSRP group. |

## Cross-Layer Options Valid with `hsrp`

| 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 1985 (v1) / UDP 2029 (v2)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |

## Common Mistakes & Quick Fixes

### hellotime and holdtime Must Be Between 0 and 255 Seconds

- **Avoid:** `dist_a -> hsrp_v4 hsrp hellotime 300`
- **Valid v3.2.2 Syntax:** `dist_a -> hsrp_v4 hsrp hellotime 3 holdtime 10`

RFC 2281 stores `hellotime` and `holdtime` as 1-byte fields in seconds, so values above `255` are rejected.

### Numeric State Codes (16 = Active, 8 = Standby)

- **Avoid:** `dist_a -> hsrp_v4 hsrp state "active"`
- **Valid v3.2.2 Syntax:** `dist_a -> hsrp_v4 hsrp state 16`

`state` takes its numeric RFC 2281 bit value (`16` Active, `8` Standby, `4` Speak, `2` Listen).
