# Data-Center Overlays (VXLAN, GENEVE, GRE) & VPN Tunnels

> **FrameAssembly v3.2.2** · Anthology 05 (Layer 3 · 13 Recipes) · MIT License · Canonical URL: https://frameassembly-lang.dev/docs/examples/overlays-tunnels-vpns

Spine-leaf EVPN underlay captures (`vxlan` UDP 4789 and `geneve` UDP 6081), `gre` routing encapsulations, `ikev2` SA/Child-SA exchanges, IPsec `esp`/`ah`/`ipsec` headers, and modern `wireguard` handshakes.

## Key Wire & Syntax Takeaways

- `vxlan` (UDP 4789) and `geneve` (UDP 6081) encode 24-bit VNIs and combine cleanly with `df` and `dscp` to verify underlay jumbo-MTU policies.
- `ikev2` switches automatically from UDP 500 on `sainit` to NAT-T UDP 4500 when needed, pairing with `esp`, `ah`, and `ipsec` SPI sequence traces.
- `wireguard` encodes little-endian Noise_IKpsk2 initiation, response, cookie, and transport data frames over both IPv4 and IPv6 UDP 51820.

## 05.01 · IPv6 WireGuard Noise_IKpsk2 Handshake, Cookie Reply & Transport Data (`wireguard_ipv6_tunnel.frasm`)

Runs a complete WireGuard tunnel handshake (initiation, response, cookie, and encrypted data transport) over IPv6 UDP port 51820.

- **Protocols:** `wireguard` (5 Ethernet frames)
- **Wire Behavior:** Encodes little-endian WireGuard message types (1 Initiation, 2 Response, 3 Cookie, 4 Data) with sender, receiver, and nonce counter fields.
- **Wireshark Filter:** `wg`
- **CLI Build:** `frameassembly wireguard_ipv6_tunnel.frasm`

```frameassembly
host roadwarrior { ip 2001:db8:50::25 }
host wg_hub      { ip 2001:db8:50::1 }

compile {
    roadwarrior -> wg_hub wireguard initiation sender 0x0a0b0c0d wait 3ms
    roadwarrior <- wg_hub wireguard response sender 0x11223344 receiver 0x0a0b0c0d wait 2ms
    roadwarrior -> wg_hub wireguard data receiver 0x11223344 counter 0 wait 2ms
    roadwarrior <- wg_hub wireguard data receiver 0x0a0b0c0d counter 0 wait 5ms
    roadwarrior <- wg_hub wireguard cookie receiver 0x0a0b0c0d
}
```

## 05.02 · Data-Center Spine-Leaf Underlay Check (VXLAN UDP 4789 + GENEVE UDP 6081) (`dc_vxlan_and_geneve_vteps.frasm`)

Verifies jumbo-MTU spine ACLs and hardware VTEP tunnel offload across both VXLAN (VNI 10100) and OVN/NSX GENEVE (VNI 20200 with TLV metadata).

- **Protocols:** `vxlan`, `geneve` (3 Ethernet frames)
- **Wire Behavior:** Sets DF bit on outer IPv4 underlay headers and encodes 24-bit VNIs on UDP 4789 and UDP 6081.
- **Wireshark Filter:** `vxlan || geneve`
- **CLI Build:** `frameassembly dc_vxlan_and_geneve_vteps.frasm`

```frameassembly
host vtep_rack01 { ip 10.250.1.11 }
host vtep_rack08 { ip 10.250.1.18 }

compile {
    vtep_rack01 -> vtep_rack08 vxlan vni 10100 df dscp 18 payload "evpn-l2vni-10100-frame" wait 2ms
    vtep_rack01 <- vtep_rack08 vxlan vni 10100 df dscp 18 payload "evpn-l2vni-10100-reply" wait 3ms
    vtep_rack01 -> vtep_rack08 geneve vni 20200 optclass 0x0102 opttype 1 df payload "ovn-geneve-metadata"
}
```

## 05.03 · Minimal Two-Block VXLAN (`vxlan`) Quickstart (`vxlan_quickstart.frasm`)

Smallest zero-boilerplate `host` + `compile` capture for Virtual eXtensible Local Area Network Overlay (UDP 4789 (VNI 1), Dual-Stack IPv4/IPv6).

- **Protocols:** `vxlan` (1 Ethernet frame)
- **Wire Behavior:** Wraps the packet in UDP `dstport 4789` with ephemeral outer `srcport` and computes the outer IPv4/IPv6 + UDP checksums.
- **Wireshark Filter:** `vxlan`
- **CLI Build:** `frameassembly vxlan_quickstart.frasm`

```frameassembly
host vtep_leaf1 { ip 172.16.0.11 }
host vtep_leaf2 { ip 172.16.0.12 }

compile {
    vtep_leaf1 -> vtep_leaf2 vxlan vni 10100
}
```

## 05.04 · Minimal Two-Block IKEv2 (`ikev2`) Quickstart (`ikev2_quickstart.frasm`)

Smallest zero-boilerplate `host` + `compile` capture for Internet Key Exchange Protocol Version 2 (UDP 500 -> 500 (NAT-T 4500), Dual-Stack IPv4/IPv6).

- **Protocols:** `ikev2` (2 Ethernet frames)
- **Wire Behavior:** Defaults both `srcport` and `dstport` to IANA IKE port `500` (avoiding ephemeral `49152` source ports blocked by strict VPN ACLs).
- **Wireshark Filter:** `isakmp`
- **CLI Build:** `frameassembly ikev2_quickstart.frasm`

```frameassembly
host initiator { ip 198.51.100.10 }
host responder { ip 203.0.113.20 }

compile {
    initiator -> responder ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 msgid 0 wait 3ms
    initiator <- responder ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 responderspi 0x1122334455667788 flags 0x20 msgid 0
}
```

## 05.05 · Minimal Two-Block WireGuard (`wireguard`) Quickstart (`wireguard_quickstart.frasm`)

Smallest zero-boilerplate `host` + `compile` capture for WireGuard Noise_IK Secure Network Tunnel (UDP 51820, Dual-Stack IPv4/IPv6).

- **Protocols:** `wireguard` (2 Ethernet frames)
- **Wire Behavior:** Defaults UDP `dstport` to `51820` and writes the 4-byte WireGuard message header (`Type` `1..4` followed by three mandatory `0x00` reserved bytes).
- **Wireshark Filter:** `wg`
- **CLI Build:** `frameassembly wireguard_quickstart.frasm`

```frameassembly
host wg_laptop { ip 198.51.100.42 }
host wg_relay  { ip 203.0.113.10 }

compile {
    wg_laptop -> wg_relay wireguard initiation sender 0x01020304 wait 2ms
    wg_laptop <- wg_relay wireguard response sender 0x0a0b0c0d receiver 0x01020304
}
```

## 05.06 · GRE / NVGRE (`gre`): Keyed Dual-Stack GRE Tunnel Sequence & Transparent Ethernet Bridging (GRETAP) (`gre_overlay_lab.frasm`)

Demonstrates an RFC 2890 keyed + checksummed GRE tunnel exchange over IPv4 followed by an IPv6 outer GRETAP (`greproto 0x6558`) overlay frame.

- **Protocols:** `gre` (4 Ethernet frames)
- **Wire Behavior:** Sets outer IPv4 Protocol or IPv6 Next Header to `47` and defaults `greproto` to `0x0800` (IPv4) with an inner probe header when `payload` is omitted. Dynamically toggles GRE header flag bits (`0x8000` for `checksum`, `0x2000` for `grekey`/`key`, `0x1000` for `greseq`) and inserts only the active 32-bit extension words in RFC 2890 order (`Checksum+Reserved1`, `Key`, `Sequence`).
- **Wireshark Filter:** `gre`
- **CLI Build:** `frameassembly show gre_overlay_lab.frasm`

```frameassembly
host edge_a_v4 { ip 172.16.100.1 }
host edge_b_v4 { ip 172.16.100.2 }
host vtep_a_v6 { ip 2001:db8:47::1 }
host vtep_b_v6 { ip 2001:db8:47::2 }

compile {
    // 1. Minimal 4-byte RFC 2784 GRE keepalive
    edge_a_v4 -> edge_b_v4 gre payload "keepalive-1" wait 2ms
    // 2. Full 16-byte GRE header (C=1, K=1, S=1) with tunnel key 5000
    edge_a_v4 -> edge_b_v4 gre grekey 5000 greseq 10 checksum dscp 46 payload "wan-voice-tunnel" wait 2ms
    edge_a_v4 <- edge_b_v4 gre grekey 5000 greseq 1 checksum dscp 46 payload "wan-voice-reply" wait 3ms
    // 3. GRE over IPv6 carrying Transparent Ethernet Bridging (0x6558)
    vtep_a_v6 -> vtep_b_v6 gre grekey 0x00102000 greproto 0x6558 hexpayload "ffffffffffff001b21aa00010806"
}
```

## 05.07 · VXLAN (`vxlan`): Multi-Tenant EVPN-VXLAN Underlay Carrying L2VNI 10100 & L3VNI 50000 (`vxlan_evpn_fabric.frasm`)

Simulates leaf VTEPs exchanging multi-tenant VXLAN traffic across ECMP UDP source ports, plus an IPv6 underlay VXLAN encapsulation.

- **Protocols:** `vxlan`, `vlan` (3 Ethernet frames)
- **Wire Behavior:** Wraps the packet in UDP `dstport 4789` with ephemeral outer `srcport` and computes the outer IPv4/IPv6 + UDP checksums. Writes the 8-byte RFC 7348 VXLAN header (`08 00 00 00 <24-bit VNI> 00`) with the mandatory `I` bit (`0x08`) set.
- **Wireshark Filter:** `vxlan`
- **CLI Build:** `frameassembly show vxlan_evpn_fabric.frasm`

```frameassembly
host leaf1_vtep { ip 10.255.0.11 mac 00:1c:73:aa:00:11 }
host leaf2_vtep { ip 10.255.0.12 mac 00:1c:73:aa:00:12 }
host vtep6_a    { ip 2001:db8:255::11 }
host vtep6_b    { ip 2001:db8:255::12 }

compile {
    // Tenant A L2VNI 10100 with outer UDP entropy port 52101 and underlay VLAN 4090
    leaf1_vtep -> leaf2_vtep vxlan vni 10100 srcport 52101 vlan 4090 dscp 26 wait 1ms
    // Tenant B Symmetric IRB L3VNI 50000 with different ECMP hash port 58420
    leaf2_vtep -> leaf1_vtep vxlan vnid 50000 srcport 58420 vlan 4090 dscp 46 wait 2ms
    // IPv6 underlay VXLAN on legacy Linux port 8472
    vtep6_a -> vtep6_b vxlan vni 20200 dstport 8472 flowlabel 0x33445
}
```

## 05.08 · GENEVE (`geneve`): Kubernetes OVN & Cilium GENEVE Overlay With Security Identity TLVs (`geneve_cni_tlvs.frasm`)

Models pod-to-pod overlay packets carrying OVN (`0x0102`) and Cilium (`0x0104`) option classes, plus a Layer 3 IPv6 inner payload (`protocoltype 0x86dd`).

- **Protocols:** `geneve` (3 Ethernet frames)
- **Wire Behavior:** Encapsulates over UDP `dstport 6081` with computed IPv4/IPv6 and UDP pseudo-header checksums. Writes the 8-byte RFC 8926 GENEVE base header (`Ver=0`, dynamic `OptLen` in 4-byte words, `Protocol Type=0x6558` TEB, and 24-bit `VNI`).
- **Wireshark Filter:** `geneve`
- **CLI Build:** `frameassembly show geneve_cni_tlvs.frasm`

```frameassembly
host node_az1 { ip 10.128.1.10 }
host node_az2 { ip 10.128.2.20 }

compile {
    // 1. OVN-Kubernetes pod egress carrying Option Class 0x0102
    node_az1 -> node_az2 geneve vni 4010 optclass 0x0102 opttype 1 srcport 55100 wait 1ms
    // 2. Cilium return packet carrying Option Class 0x0104
    node_az1 <- node_az2 geneve vni 4010 optclass 0x0104 opttype 2 srcport 59200 wait 2ms
    // 3. Direct L3 IPv4 payload inside GENEVE (protocoltype 0x0800) for GWLB appliance test
    node_az1 -> node_az2 geneve vni 100 optclass 0x0108 opttype 1 protocoltype 0x0800
}
```

## 05.09 · IPsec (ESP Alias) (`ipsec`): IKEv2 Tunnel Bring-Up Followed by Bidirectional IPsec Data Frames (`ipsec_site_to_site.frasm`)

Pairs an `ikev2` `SA_INIT` + `IKE_AUTH` negotiation on UDP 500 with encrypted `ipsec` tunnel-mode (`nextheader 4`) data packets in both directions.

- **Protocols:** `ipsec` (6 Ethernet frames)
- **Wire Behavior:** Sets outer IPv4 Protocol or IPv6 Next Header to `50` (ESP). Encodes the 4-byte `spi` (default `0x00000100`), 4-byte ESP `seq` (default `1`), 8-byte `iv`, block-aligned ciphertext + 2-byte ESP trailer (`Pad Length` + `nextheader`), and 12-byte `icv` authentication tag.
- **Wireshark Filter:** `esp`
- **CLI Build:** `frameassembly show ipsec_site_to_site.frasm`

```frameassembly
host gw_west { ip 198.51.100.10 }
host gw_east { ip 203.0.113.20 }

compile {
    // 1. IKEv2 SA_INIT and IKE_AUTH key exchange on UDP 500
    gw_west -> gw_east ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 msgid 0 nextheader 33 wait 3ms
    gw_west <- gw_east ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 responderspi 0x1122334455667788 flags 0x20 wait 3ms
    gw_west -> gw_east ikev2 auth initiatorspi 0xa1b2c3d4e5f60708 responderspi 0x1122334455667788 msgid 1 nextheader 46 wait 4ms
    // 2. Bidirectional IPsec ESP tunnel frames (outbound SPI 0x1001, inbound SPI 0x2002)
    gw_west -> gw_east ipsec spi 0x00001001 seq 1 iv "0102030405060708" icv "aabbccddeeff001122334455" nextheader 4 wait 1ms
    gw_west -> gw_east ipsec spi 0x00001001 seq 2 iv "090a0b0c0d0e0f10" icv "112233445566778899aabbcc" nextheader 4 wait 2ms
    gw_west <- gw_east ipsec spi 0x00002002 seq 1 iv "f1f2f3f4f5f6f7f8" icv "99887766554433221100ffaa" nextheader 4
}
```

## 05.10 · IPsec ESP (`esp`): Dual-Stack IPv4 & IPv6 ESP Security Associations With DiffServ QoS (`esp_dualstack_vpn.frasm`)

Emits unidirectional outbound and inbound ESP Security Associations across both IPv4 and IPv6 WAN endpoints with preserved DiffServ markings.

- **Protocols:** `esp` (3 Ethernet frames)
- **Wire Behavior:** Emits IPv4 Protocol `50` or IPv6 Next Header `50` with computed outer IPv4 header checksum and exact payload length. Aligns ciphertext + padding + 2-byte trailer (`Pad Length`, `Next Header`) cleanly to cipher block boundaries before appending the `icv`.
- **Wireshark Filter:** `esp`
- **CLI Build:** `frameassembly show esp_dualstack_vpn.frasm`

```frameassembly
host hub_v4    { ip 198.51.100.1 }
host spoke_v4  { ip 203.0.113.50 }
host hub_v6    { ip 2001:db8:100::1 }
host spoke_v6  { ip 2001:db8:200::50 }

compile {
    // IPv4 ESP tunnel (SPI 0x1010 -> 0x2020) with Expedited Forwarding (dscp 46)
    spoke_v4 -> hub_v4 esp spi 0x00001010 seq 101 iv "1011121314151617" icv "a1a2a3a4a5a6a7a8a9aaabac" nextheader 4 dscp 46 df wait 1ms
    spoke_v4 <- hub_v4 esp spi 0x00002020 seq 88 iv "2021222324252627" icv "b1b2b3b4b5b6b7b8b9babbbc" nextheader 4 dscp 46 df wait 3ms
    // IPv6 ESP tunnel (Next Header 50, inner Next Header 41 = IPv6-in-IPv6)
    spoke_v6 -> hub_v6 esp spi 0x00061010 seq 1 iv "3031323334353637" icv "c1c2c3c4c5c6c7c8c9cacbcc" nextheader 41 flowlabel 0x50001
}
```

## 05.11 · IPsec AH (`ah`): Authenticated Dual-Stack Router Peering Using IPsec AH (Protocol 51) (`ah_authenticated_peering.frasm`)

Emits bidirectional IPv4 and IPv6 RFC 4302 Authentication Header packets demonstrating 32-bit vs 64-bit ICV alignment.

- **Protocols:** `ah` (3 Ethernet frames)
- **Wire Behavior:** Sets outer IPv4 Protocol or IPv6 Next Header to `51` (Authentication Header). Computes RFC 4302 `Payload Len = (total_ah_bytes / 4) - 2` automatically and zero-pads `icv` to 4-byte (IPv4) or 8-byte (IPv6) alignment.
- **Wireshark Filter:** `ah`
- **CLI Build:** `frameassembly show ah_authenticated_peering.frasm`

```frameassembly
host core_a_v4 { ip 172.16.51.1 }
host core_b_v4 { ip 172.16.51.2 }
host core_a_v6 { ip 2001:db8:51::1 }
host core_b_v6 { ip 2001:db8:51::2 }

compile {
    // IPv4 AH (24-byte header: Payload Len = 4, 12-byte 96-bit ICV)
    core_a_v4 -> core_b_v4 ah spi 0x00002001 seq 1 nextheader 59 icv "00112233445566778899aabb" payload "cleartext-signed-v4" wait 2ms
    core_a_v4 <- core_b_v4 ah spi 0x00002002 seq 1 nextheader 59 icv "aabbccddeeff001122334455" payload "cleartext-ack-v4" wait 3ms
    // IPv6 AH (aligned to 8-octet boundary per RFC 4302 §2.2)
    core_a_v6 -> core_b_v6 ah spi 0x00062001 seq 1 nextheader 59 icv "0102030405060708090a0b0c" payload "cleartext-signed-v6"
}
```

## 05.12 · IKEv2 (`ikev2`): IKEv2 SA_INIT on UDP 500 Floating to NAT-Traversal UDP 4500 + DPD Check (`ikev2_natt_dpd.frasm`)

Traces a complete IKEv2 phase: `SA_INIT` on UDP `500`, NAT-T port float to UDP `4500` for encrypted `IKE_AUTH` (`nextpayload 46`), and an `INFORMATIONAL` Dead Peer Detection exchange.

- **Protocols:** `ikev2` (6 Ethernet frames)
- **Wire Behavior:** Defaults both `srcport` and `dstport` to IANA IKE port `500` (avoiding ephemeral `49152` source ports blocked by strict VPN ACLs). Writes the 28-byte RFC 7296 IKEv2 header (`Version 0x20`, exact 32-bit `Length`, 64-bit SPIs) and defaults `responderspi` to `0` on `sainit` requests.
- **Wireshark Filter:** `isakmp`
- **CLI Build:** `frameassembly show ikev2_natt_dpd.frasm`

```frameassembly
host branch_fw { ip 198.51.100.15 }
host cloud_vpn { ip 203.0.113.99 }

compile {
    // 1. IKE_SA_INIT on UDP 500 -> 500 (Next Payload 33 = Security Association)
    branch_fw -> cloud_vpn ikev2 sainit initiatorspi 0x9080706050403020 responderspi 0 msgid 0 flags 0x08 nextpayload 33 wait 4ms
    branch_fw <- cloud_vpn ikev2 sainit initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 0 flags 0x20 nextpayload 33 wait 4ms
    // 2. Float to UDP 4500 for IKE_AUTH (Next Payload 46 = Encrypted & Authenticated SK)
    branch_fw -> cloud_vpn ikev2 auth srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 1 flags 0x08 nextpayload 46 wait 5ms
    branch_fw <- cloud_vpn ikev2 auth srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 1 flags 0x20 nextpayload 46 wait 50ms
    // 3. INFORMATIONAL Dead Peer Detection (DPD) liveness check
    branch_fw -> cloud_vpn ikev2 informational srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 2 flags 0x08 nextpayload 46 wait 3ms
    branch_fw <- cloud_vpn ikev2 informational srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 2 flags 0x20 nextpayload 46
}
```

## 05.13 · WireGuard (`wireguard`): Full 1-RTT Noise_IK Handshake, Transport Data Stream, and Under-Load Cookie (`wireguard_handshake_data.frasm`)

Captures a WireGuard initiator completing a 1-RTT handshake (`initiation` + `response`), exchanging encrypted `data` frames with incrementing counters, and handling a `cookie` challenge.

- **Protocols:** `wireguard` (7 Ethernet frames)
- **Wire Behavior:** Defaults UDP `dstport` to `51820` and writes the 4-byte WireGuard message header (`Type` `1..4` followed by three mandatory `0x00` reserved bytes). Emits exact-length handshake structures: `148` bytes for `initiation` (`Type 1`), `92` bytes for `response` (`Type 2`), and `64` bytes for `cookie` (`Type 3`).
- **Wireshark Filter:** `wg`
- **CLI Build:** `frameassembly show wireguard_handshake_data.frasm`

```frameassembly
host roadwarrior { ip 198.51.100.88 }
host corp_wg_gw  { ip 203.0.113.5 }

compile {
    // 1. Optional DoS Cookie Reply challenge (64 bytes, Type 3)
    roadwarrior -> corp_wg_gw wireguard initiation sender 0x11112222 wait 2ms
    roadwarrior <- corp_wg_gw wireguard cookie receiver 0x11112222 wait 3ms
    // 2. Full 1-RTT Noise_IKpsk2 Handshake (148B Initiation -> 92B Response)
    roadwarrior -> corp_wg_gw wireguard initiation sender 0x33334444 wait 2ms
    roadwarrior <- corp_wg_gw wireguard response sender 0xaaaabbbb receiver 0x33334444 wait 2ms
    // 3. Encrypted Transport Data packets (Type 4) swapping receiver indices
    roadwarrior -> corp_wg_gw wireguard data receiver 0xaaaabbbb counter 0 payload "inner-ipv4-syn" wait 1ms
    roadwarrior <- corp_wg_gw wireguard data receiver 0x33334444 counter 0 payload "inner-ipv4-synack" wait 1ms
    roadwarrior -> corp_wg_gw wireguard data receiver 0xaaaabbbb counter 1 payload "inner-ipv4-ack"
}
```
