# vrrp — VRRPv2 & VRRPv3 First-Hop Gateway Heartbeats (`vrrp`)

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

- **Full Protocol Name:** Virtual Router Redundancy Protocol v2 & v3
- **Keyword:** `vrrp`
- **OSI Layer & Transport:** Layer 3 · IP Proto 112 (TTL 255)
- **Host Endpoint Rule:** Dual-Stack Morphing (v4/v6)
- **Standards:** RFC 3768, RFC 5798
- **Wireshark Display Filter:** `vrrp`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> VRRPv2 / VRRPv3 (IP Proto 112 (TTL 255))`

## Overview

When two routers both claim Priority `255` because a trunk VLAN blocked IP Protocol `112`, chaos ensues. `vrrp` emits `ttl 255` advertisements for both VRRPv2 and VRRPv3 (`00:00:5e:00:01:<vrid>`).

Virtual Router Redundancy Protocol (`vrrp`) provides standards-based First-Hop Redundancy (FHRP) over **IP Protocol `112`** with mandatory **TTL / Hop Limit `255`** (routers discard any VRRP packet arriving with `TTL != 255`).

FrameAssembly defaults to **VRRPv2** (`version 2`, RFC 3768, `advint` in whole seconds, ones-complement checksum) over IPv4 endpoints and automatically upgrades to **VRRPv3** (`version 3`, RFC 5798, 12-bit `Max Advver Int` in centiseconds, pseudo-header checksum) over IPv6 endpoints—or when `version 3` is explicitly requested on IPv4.

## Minimal Quickstart (`vrrp_quickstart.frasm`)

```frameassembly
host gw_master { ip 10.10.1.2 mac 00:00:5e:00:01:0a }
host vrrp_all  { ip 224.0.0.18 }

compile {
    gw_master -> vrrp_all vrrp vrid 10 priority 150 advint 1 vip 10.10.1.1
}
```

### Automatic Wire Calculations

- Sets IPv4 Protocol / IPv6 Next Header to `112` and defaults `ttl` / Hop Limit to `255` per RFC 3768 / RFC 5798.
- Selects VRRPv2 (`version 2`) over IPv4 and VRRPv3 (`version 3`, 12-bit centisecond `Max Adver Int` + pseudo-header checksum) over IPv6 automatically.
- Derives multicast Ethernet MAC `01:00:5e:00:00:12` (`224.0.0.18`) or `33:33:00:00:00:12` (`ff02::12`) automatically.

## Practical Lab Example: Graceful VRRP Master Shutdown (Priority 0), Backup Takeover & VRRPv3 IPv6 (`vrrp_failover_v2_v3.frasm`)

Traces VRID 10 on VLAN 10 where the primary router sends a `priority 0` release, the backup router assumes mastership + sends GARP, alongside an IPv6 VRRPv3 advertisement.

```frameassembly
host rtr_pri   { ip 10.10.10.2 mac 00:00:5e:00:01:0a }
host rtr_bkp   { ip 10.10.10.3 mac 00:00:5e:00:01:0a }
host vrrp_v4   { ip 224.0.0.18 }
host rtr6_pri  { ip fe80::10:2 mac 00:00:5e:00:02:0a }
host vrrp_v6   { ip ff02::12 }

compile {
    // 1. Primary router steady-state VRRPv2 heartbeat (VRID 10, Priority 150)
    rtr_pri -> vrrp_v4 vrrp vrid 10 priority 150 advint 1 vip 10.10.10.1 vlan 10 pcp 6 wait 5ms
    // 2. Primary router initiates graceful shutdown (Priority 0 triggers immediate takeover)
    rtr_pri -> vrrp_v4 vrrp vrid 10 priority 0 advint 1 vip 10.10.10.1 vlan 10 pcp 6 wait 2ms
    // 3. Backup router promotes to Master (Priority 120) and broadcasts GARP for VIP
    rtr_bkp -> vrrp_v4 vrrp vrid 10 priority 120 advint 1 vip 10.10.10.1 vlan 10 pcp 6 wait 1ms
    rtr_bkp -> vrrp_v4 arp gratuitous sendermac 00:00:5e:00:01:0a senderip 10.10.10.1 vlan 10 wait 3ms
    // 4. Dual-stack VRRPv3 over IPv6 (advint 100 = 100 centiseconds = 1.00s)
    rtr6_pri -> vrrp_v6 vrrp version 3 vrid 10 priority 150 advint 100 vip fe80::10:1 vlan 10
}
```

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

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

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

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

## All `vrrp` Keywords & Header Options

Packet line pattern: `src_host -> dst_host vrrp [vrid <1..255>] [priority <0..255>] [advint <0..65535>] [vip <ip>] [version <2|3>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `vrid <1..255>` | 8-bit Virtual Router Identifier (1..255) | `1` | Sets the VRID (matches standard virtual MAC `00:00:5e:00:01:<vrid_hex>` on v4 or `00:00:5e:00:02:<vrid_hex>` on v6). |
| `priority <0..255>` | 8-bit election priority (0..255) | `100` | Sets router election priority (`255` = IP address owner, `100` = default backup, `0` = current Master releasing virtual router). |
| `advint <0..65535>` | u8 seconds (v2) or 12-bit centiseconds (v3) | `1 (v2) / 100 (v3)` | Sets Advertisement Interval (`1` second in VRRPv2; `100` centiseconds = `1.00s` in VRRPv3). |
| `vip <ip>` | IPv4 or IPv6 Virtual IP address | `Source host IP` | Populates the Virtual Router IPv4/IPv6 Address field (`Count IPvX Addr = 1`). |
| `version <2\|3>` | 2 or 3 | `2 (IPv4) / 3 (IPv6)` | Selects RFC 3768 VRRPv2 or RFC 5798 VRRPv3 header & pseudo-header checksum rules. |

## Cross-Layer Options Valid with `vrrp`

| 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 255, 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). |

## Common Mistakes & Quick Fixes

### vrid Starts at 1 (1..255)

- **Avoid:** `r1 -> vrrp_v4 vrrp vrid 0`
- **Valid v3.2.2 Syntax:** `r1 -> vrrp_v4 vrrp vrid 1 priority 120`

Per RFC 3768 / RFC 5798, valid Virtual Router Identifiers are `1..=255` (`0` is invalid). Note that `priority 0` *is* valid and signals Master release.

### VRRPv3 Uses Centiseconds (100 = 1s) Instead of Whole Seconds

- **Valid v3.2.2 Syntax:** `r6 -> vrrp_v6 vrrp version 3 vrid 10 advint 100`

In VRRPv2 `advint 1` is `1` second, whereas in VRRPv3 `advint` is encoded in centiseconds (`100` = `1.00` second, enabling sub-second `advint 10` = `100ms` failovers).
