# Layer 3 Control, Tunnels, VPN, Routing & Redundancy

> **FrameAssembly v3.2.2** · Category 02 (Layer 3 · 20 Protocols) · Canonical URL: https://frameassembly-lang.dev/docs/protocols/categories/l3-routing-overlay-vpn

Booting multi-vendor router VMs just to test one eBGP 4-byte ASN capability, an OSPFv3 pseudo-header checksum, or a VXLAN DF/PMTUD black hole wastes hours of lab RAM. FrameAssembly compiles all 20 Layer 3 control, overlay, IPsec/WireGuard VPN, dynamic routing, FHRP, and SDN protocols directly into deterministic `.pcap` captures.

Dual-stack protocols (`icmp`, `ospf`, `rip`, `vrrp`, `hsrp`, `pim`, `bfd`, `bgp`, `vxlan`, `geneve`, `gre`, `ipsec`/`esp`/`ah`, `ikev2`, and `wireguard`) switch their wire framing and checksum math automatically when run over IPv6 `host` pairs, while FrameAssembly strictly enforces IPv4-only `igmp` and IPv6-only `ndp`/`mld`.

## Category Wire & Endpoint Rules

- **Dual-Stack Header & Checksum Morphing:** Switching endpoint `host` blocks from IPv4 to IPv6 automatically morphs `icmp` (Proto `1` -> ICMPv6 `58`), `ospf` (OSPFv2 -> OSPFv3 RFC 5340), `rip` (`520` -> RIPng `521`), `vrrp` (v2 -> v3), and `hsrp` (`1985` -> HSRPv2 `2029`).
- **RFC Hop-Limit & TTL Defaults:** `ndp`, `vrrp`, and `bfd` default to `ttl 255` so Hop-Limit / GTSM security checks pass out of the box; `ospf`, `igmp`, and `mld` default to link-local `ttl 1`.
- **Automatic 4-Byte BGP AS_TRANS (`23456`):** When `bgp open asn <u32>` exceeds `65535`, FrameAssembly writes `23456` (`AS_TRANS`) in the 16-bit header and appends RFC 6793 Capability `65` automatically.
- **ESP Authoring vs. Reverse Parity:** `ipsec` and `esp` share identical IP Protocol `50` wire builders; `frameassembly reverse` always emits canonical `esp` so gateway IPs can be scrubbed cleanly.

## Multi-Protocol Example: Underlay Routing, BFD Liveness, VXLAN Overlay & WireGuard (`l3_routing_vxlan_vpn.frasm`)

Builds a stateful TCP 179 eBGP 4-byte ASN OPEN + NLRI UPDATE exchange, a TTL-255 BFD Up control packet, an OSPFv2 Hello, a VXLAN VNI 10020 overlay packet with `df` set, and a 148-byte WireGuard handshake initiation.

```frameassembly
host spine1 { ip 10.255.0.1 }
host leaf1  { ip 10.255.0.2 }

compile {
    leaf1 -> spine1 tcp syn srcport 51900 dstport 179 win 65535 mss 1460 wait 1ms
    leaf1 <- spine1 tcp syn ack win 65535 mss 1460 wait 1ms
    leaf1 -> spine1 tcp ack wait 1ms
    leaf1 -> spine1 bgp open asn 4200000010 holdtime 90 bgpid 10.255.0.2 wait 2ms
    leaf1 <- spine1 bgp update asn 4200000001 prefix "10.40.0.0/16" nexthop 10.255.0.1 wait 2ms
    leaf1 -> spine1 bfd state 3 mydisc 0x1001 yourdisc 0x2002 mintx 50000 minrx 50000 mult 3 wait 2ms
    leaf1 -> spine1 ospf hello routerid 10.255.0.2 areaid 0.0.0.0 wait 2ms
    leaf1 -> spine1 vxlan vni 10020 df wait 2ms
    leaf1 -> spine1 wireguard initiation sender 0x0a0b0c0d
}
```

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

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

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

# 4. Verify dissected protocol fields in tshark
tshark -r l3_routing_vxlan_vpn.pcap -Y "bgp || bfd || ospf || vxlan || wg"
```

- **Wireshark Display Filter:** `bgp || bfd || ospf || vxlan || wg`

## Protocols in Category 02 (20 Native Builders)

| # | Keyword | Protocol | Default Port / Proto | Endpoint Rule | Wireshark Filter | Spec URL |
| --- | --- | --- | --- | --- | --- | --- |
| 9 | `icmp` | Internet Control Message Protocol v4 & Dual-Stack ICMPv6 | `IP Proto 1 (v4) / NextHdr 58 (v6)` | Dual-Stack Morphing (v4/v6) | `icmp \|\| icmpv6` | https://frameassembly-lang.dev/docs/protocols/icmp |
| 10 | `ndp` | IPv6 Neighbor Discovery Protocol | `ICMPv6 NextHdr 58 (Hop Limit 255)` | IPv6-Only | `icmpv6.type >= 133 && icmpv6.type <= 137` | https://frameassembly-lang.dev/docs/protocols/ndp |
| 11 | `igmp` | Internet Group Management Protocol v1, v2 & v3 | `IPv4 Proto 2 (TTL 1)` | IPv4-Only | `igmp` | https://frameassembly-lang.dev/docs/protocols/igmp |
| 12 | `mld` | Multicast Listener Discovery v1 & v2 (IPv6) | `ICMPv6 NextHdr 58 (Hop Limit 1)` | IPv6-Only | `icmpv6.type >= 130 && icmpv6.type <= 132` | https://frameassembly-lang.dev/docs/protocols/mld |
| 13 | `gre` | Generic Routing Encapsulation (GRE, GRETAP & NVGRE) | `IP Proto 47` | Dual-Stack IPv4/IPv6 | `gre` | https://frameassembly-lang.dev/docs/protocols/gre |
| 14 | `vxlan` | Virtual eXtensible Local Area Network Overlay | `UDP 4789 (VNI 1)` | Dual-Stack IPv4/IPv6 | `vxlan` | https://frameassembly-lang.dev/docs/protocols/vxlan |
| 15 | `geneve` | Generic Network Virtualization Encapsulation | `UDP 6081 (Proto 0x6558)` | Dual-Stack IPv4/IPv6 | `geneve` | https://frameassembly-lang.dev/docs/protocols/geneve |
| 16 | `ipsec` | IPsec Encapsulating Security Payload (Protocol Alias) | `IP Proto 50 (ESP)` | Dual-Stack IPv4/IPv6 | `esp` | https://frameassembly-lang.dev/docs/protocols/ipsec |
| 17 | `esp` | IPsec Encapsulating Security Payload | `IP Proto 50` | Dual-Stack IPv4/IPv6 | `esp` | https://frameassembly-lang.dev/docs/protocols/esp |
| 18 | `ah` | IPsec Authentication Header | `IP Proto 51` | Dual-Stack IPv4/IPv6 | `ah` | https://frameassembly-lang.dev/docs/protocols/ah |
| 19 | `ikev2` | Internet Key Exchange Protocol Version 2 | `UDP 500 -> 500 (NAT-T 4500)` | Dual-Stack IPv4/IPv6 | `isakmp` | https://frameassembly-lang.dev/docs/protocols/ikev2 |
| 20 | `wireguard` | WireGuard Noise_IK Secure Network Tunnel | `UDP 51820` | Dual-Stack IPv4/IPv6 | `wg` | https://frameassembly-lang.dev/docs/protocols/wireguard |
| 21 | `ospf` | Open Shortest Path First — OSPFv2 & Dual-Stack OSPFv3 | `IP Proto 89 (TTL 1)` | Dual-Stack Morphing (v4/v6) | `ospf` | https://frameassembly-lang.dev/docs/protocols/ospf |
| 22 | `bgp` | Border Gateway Protocol 4 & 4-Byte ASN Capability | `TCP 179` | Dual-Stack IPv4/IPv6 | `bgp` | https://frameassembly-lang.dev/docs/protocols/bgp |
| 23 | `rip` | Routing Information Protocol — RIPv2 & Dual-Stack RIPng | `UDP 520 (RIPv2) / UDP 521 (RIPng)` | Dual-Stack Morphing (v4/v6) | `rip \|\| ripng` | https://frameassembly-lang.dev/docs/protocols/rip |
| 24 | `pim` | Protocol Independent Multicast — Sparse Mode | `IP Proto 103` | Dual-Stack IPv4/IPv6 | `pim` | https://frameassembly-lang.dev/docs/protocols/pim |
| 25 | `vrrp` | Virtual Router Redundancy Protocol v2 & v3 | `IP Proto 112 (TTL 255)` | Dual-Stack Morphing (v4/v6) | `vrrp` | https://frameassembly-lang.dev/docs/protocols/vrrp |
| 26 | `hsrp` | Cisco Hot Standby Router Protocol v1 & v2 | `UDP 1985 (v1) / UDP 2029 (v2)` | Dual-Stack Morphing (v4/v6) | `hsrp \|\| hsrp2` | https://frameassembly-lang.dev/docs/protocols/hsrp |
| 27 | `bfd` | Bidirectional Forwarding Detection Control Packet | `UDP 3784 (Multihop 4784, TTL 255)` | Dual-Stack IPv4/IPv6 | `bfd` | https://frameassembly-lang.dev/docs/protocols/bfd |
| 28 | `openflow` | OpenFlow SDN Control Channel (OpenFlow 1.3 / 1.4) | `TCP 6653` | Dual-Stack IPv4/IPv6 | `openflow_v4 \|\| openflow` | https://frameassembly-lang.dev/docs/protocols/openflow |
