# glbp — Active-Active Cisco GLBP AVG & AVF Load-Share Frames (`glbp`)

> **FrameAssembly v3.3.0** · Protocol 40 of 81 · Canonical URL: https://frameassembly-lang.dev/docs/protocols/glbp

- **Full Protocol Name:** Cisco Gateway Load Balancing Protocol
- **Keyword:** `glbp`
- **OSI Layer & Transport:** Layer 3 · UDP 3222 (Multicast 224.0.0.102, TTL 1)
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** Cisco GLBP Specification
- **Wireshark Display Filter:** `glbp`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> Cisco GLBP (3222) (UDP 3222 (Multicast 224.0.0.102, TTL 1))`

## Overview

Why let standby routers sit idle? `glbp` runs on UDP `3222` (`224.0.0.102`, `ttl 1`) so an Active Virtual Gateway can hand out `00:07:b4` virtual MACs across up to four forwarding routers.

Gateway Load Balancing Protocol (`glbp`, **UDP `3222`** to link-local multicast `224.0.0.102` / `ff02::66` at `ttl 1`) extends first-hop gateway redundancy beyond active/standby HSRP and VRRP by electing one **Active Virtual Gateway (AVG)** and up to four **Active Virtual Forwarders (AVFs)** sharing traffic across virtual MACs (`00:07:b4:00:xx:yy`).

FrameAssembly encodes the 12-byte GLBP base header (`version`, `group 0..1023`, `ownerid` MAC) followed by structured **Hello (`type 1`)**, **Request/Response (`type 2`)**, and **Plaintext Authentication (`type 3`)** TLVs—including `priority`, `weight`, `hellotime`, `holdtime`, `redirect`, `timeout`, `vip`, and virtual forwarder `vmac`.

## Minimal Quickstart (`glbp_quickstart.frasm`)

```frameassembly
host dist_rtr_a { ip 172.16.10.2 mac 00:50:56:01:00:01 }
host dist_rtr_b { ip 172.16.10.3 mac 00:50:56:01:00:02 }

compile {
    dist_rtr_a -> dist_rtr_b glbp hello group 10 priority 150 weight 100 vip 172.16.10.1 ownerid 00:50:56:01:00:01 vmac 00:07:b4:00:0a:01
}
```

### Automatic Wire Calculations

- Defaults UDP source and destination ports to `3222`, sets IPv4 TTL / IPv6 Hop Limit to `1`, and targets `224.0.0.102` (`01:00:5e:00:00:66`) over IPv4 or `ff02::66` over IPv6 unless overridden.
- Encodes the 10-bit `group` ID (`0..1023`), 6-byte `ownerid`, Hello TLV (state, priority, timers, `vip`), Request/Response Forwarder TLV (`forwarder`, `weight`, `vmac`), and optional Auth TLV.
- Validates at compile time that `group <= 1023` to match the 10-bit GLBP wire header specification.

## Practical Lab Example: Dual-Distribution Router GLBP Group 10 AVG Election & AVF Assignment (`glbp_avg_avf_lab.frasm`)

Captures two distribution routers exchanging authenticated GLBP Hellos on Group 10 (`vip 10.10.20.1`), followed by AVF forwarder slot request and virtual MAC (`00:07:b4:00:0a:02`) assignment.

```frameassembly
host core_dist_1 { ip 10.10.20.2 mac 00:1c:73:a1:00:01 }
host core_dist_2 { ip 10.10.20.3 mac 00:1c:73:a2:00:02 }

compile {
    // 1. AVG (core_dist_1, priority 150) & Standby AVG (core_dist_2, priority 120) exchange Hellos
    core_dist_1 -> core_dist_2 glbp hello group 10 state 32 priority 150 hellotime 3000 holdtime 10000 vip 10.10.20.1 ownerid 00:1c:73:a1:00:01 auth "corp-fhrp" wait 2ms
    core_dist_1 <- core_dist_2 glbp hello group 10 state 16 priority 120 hellotime 3000 holdtime 10000 vip 10.10.20.1 ownerid 00:1c:73:a2:00:02 auth "corp-fhrp" wait 2ms
    // 2. AVF 2 Request from core_dist_2 and Response assigning virtual MAC 00:07:b4:00:0a:02
    core_dist_1 <- core_dist_2 glbp request group 10 forwarder 2 weight 100 ownerid 00:1c:73:a2:00:02 auth "corp-fhrp" wait 1ms
    core_dist_1 -> core_dist_2 glbp response group 10 forwarder 2 state 32 weight 100 redirect 600 timeout 14400 vmac 00:07:b4:00:0a:02 ownerid 00:1c:73:a1:00:01 auth "corp-fhrp"
}
```

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

# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'
frameassembly glbp_avg_avf_lab.frasm glbp_avg_avf_lab.pcap
frameassembly glbp_avg_avf_lab.frasm glbp_avg_avf_lab.pcapng

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

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

## All `glbp` Keywords & Header Options

Packet line pattern: `src_host -> dst_host glbp [hello | request | response] [version <0..255>] [group <0..1023>] [ownerid <mac>] [state <0..255>] [priority <0..255>] [weight <0..255>] [forwarder <0..255>] [hellotime <number>] [holdtime <number>] [redirect <0..65535>] [timeout <0..65535>] [vip <ip>] [vmac <mac>] [auth "<text>"]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `hello \| request \| response` | GLBP TLV message mode | `hello` | Selects Hello TLV (`1`) or Forwarder Request / Response TLV (`2`). |
| `group <0..1023>` | 10-bit GLBP group number (0..1023) | `1` | Packs the 10-bit GLBP virtual router group into bytes 2..3 of the GLBP header. |
| `priority <0..255> \| weight <0..255>` | 8-bit AVG priority and AVF weight | `priority 100, weight 100` | `priority` governs AVG election; `weight` governs AVF load-sharing eligibility. |
| `state <0..255> \| forwarder <0..255>` | GLBP state code and AVF slot index (1..4) | `state 32 (Active), forwarder 1` | Sets gateway/forwarder state (`4`=Speak, `8`=Standby, `16`=Listen, `32`=Active) and AVF index. |
| `vip <ip> \| vmac <mac> \| ownerid <mac>` | Virtual IP, Virtual Forwarder MAC & Owner MAC | `Host IP / 00:07:b4:00:01:01 / source MAC` | Populates the Virtual IP in Hello TLVs, the `00:07:b4` AVF MAC, and the 6-byte Owner ID. |
| `hellotime <number> \| holdtime <number>` | 32-bit timers in milliseconds | `hellotime 3000, holdtime 10000` | Sets the 4-byte millisecond Hello Interval (`3000` = 3s) and Hold Time (`10000` = 10s). |
| `redirect <0..65535> \| timeout <0..65535>` | 16-bit timers in seconds | `redirect 600, timeout 14400` | Sets the AVG ARP redirect timer (`600s`) and secondary AVF forwarder timeout (`14400s` = 4h). |
| `auth "<text>"` | Quoted plaintext authentication key | `Omitted (no Auth TLV)` | Appends a GLBP Type `3` Plaintext Authentication TLV. |

## Cross-Layer Options Valid with `glbp`

| 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). |
| `comment "<text>"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"`, `"de:ad:be:ef"`, or `"\x01\x02"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType 0..65535 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or standalone Layer 2 16-bit EtherType. |
| `fcs \| badfcs` | Ethernet CRC-32 trailer flags (choose one) | `Omitted` | `fcs` appends a valid IEEE 802.3 4-byte CRC-32 Frame Check Sequence trailer; `badfcs` XOR-corrupts the CRC-32 for NIC/tap negative tests. |
| `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>]` | Repeatable label stack (0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255) | `Unlabeled (auto bos=0 on outer labels, bos=1 on bottom)` | Prepends one or more 32-bit MPLS label shims (`0x8847`, e.g. `mpls 16000 mpls 24010`) ahead of Layer 2 EoMPLS or Layer 3 payloads. |
| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 1, 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>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |
| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 3222 (Multicast 224.0.0.102, TTL 1)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `badchecksum \| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |

## Common Mistakes & Quick Fixes

### GLBP Group Numbers Are 10-Bit (0..1023)

- **Avoid:** `r1 -> r2 glbp hello group 2048 vip 10.0.0.1`
- **Valid v3.3.0 Syntax:** `r1 -> r2 glbp hello group 1023 vip 10.0.0.1`

Unlike HSRPv2 (12-bit `0..4095`), GLBP allocates 10 bits for the Group ID (`0..1023`).

### GLBP hellotime Is in Milliseconds (u32), Unlike HSRP Seconds (u8)

- **Avoid:** `Assuming hellotime 3000 overflows like HSRP`
- **Valid v3.3.0 Syntax:** `r1 -> r2 glbp hello group 10 hellotime 3000 holdtime 10000`

GLBP encodes 32-bit millisecond timers (`3000` = 3 seconds) to support sub-second tuning, whereas HSRPv1 uses 8-bit second timers.
