# VLANs, QinQ, MPLS, Tunnel Soup & Dual-Stack IPv6

> **FrameAssembly v3.2.2** · Workflow Guide 05 · Canonical URL: https://frameassembly-lang.dev/docs/vlans-tunnels-and-ipv6

Stamp 802.1Q / 802.1ad QinQ tags that OS NIC drivers usually eat, stack MPLS/VXLAN/WireGuard/IPsec headers, and reuse one `flow(a, b)` across IPv4 & IPv6.

## Key Takeaways

- Laptop NIC drivers love eating outer 802.1Q and QinQ tags on live captures — FrameAssembly writes `0x8100`, `0x88a8`, and `0x8847` straight into the file.
- Slap `vlan`, `qinq`, `mpls`, `ttl`, `dscp`, `ecn`, or IPv6 `flowlabel` onto almost any Layer 3–7 statement.
- Write `flow peer_check(a, b) { ... }` once and run it on both IPv4 router pairs and IPv6 router pairs.

## 1. 802.1Q, Carrier QinQ & MPLS Without Driver Tag-Eating

Ever capture on a laptop USB dongle for twenty minutes only to realize Windows or Linux hardware offload silently stripped every 802.1Q tag? FrameAssembly writes exact IEEE 802.1Q (`0x8100`), 802.1ad QinQ (`0x88a8` S-Tag + `0x8100` C-Tag), and 32-bit MPLS (`0x8847`) shims straight to `.pcap`.

Use `vlan`, `qinq`, and `mpls` either as pure Layer 2 frames (even between MAC-only switch hosts) or as cross-layer modifiers on any IP/TCP/UDP/L7 frame:

### `trunk_qinq_mpls.frasm`

```frameassembly
host pe_west { ip 172.16.100.1 mac 00:1c:73:aa:00:01 }
host pe_east { ip 172.16.100.2 mac 00:1c:73:aa:00:02 }

compile {
    // 1. Voice VLAN 200 + 802.1p priority 5 (pcp 5) + DiffServ EF (dscp 46)
    pe_west -> pe_east rtp pt 0 seq 100 timestamp 160 ssrc 0x12345678 vlan 200 pcp 5 dscp 46 wait 2ms

    // 2. Metro-E QinQ: outer S-VLAN 1000 -> inner C-VLAN 40 carrying OSPF Hello
    pe_west -> pe_east ospf hello routerid 10.0.0.1 areaid 0 qinq 1000 innervlan 40 pcp 6 wait 2ms

    // 3. MPLS label 24010 (EXP 6, BoS 1) carrying BGP Keepalive
    pe_west -> pe_east bgp keepalive mpls 24010 exp 6 bos 1 mplsttl 64
}
```

## 2. Tunnel Soup: VXLAN, GENEVE, GRE, IKEv2, ESP & WireGuard

Need a clean reference `.pcap` to debug underlay UDP ports, `df` MTU drops, or VPN firewall ACLs? One `compile` block covers `gre`, `vxlan` (UDP 4789), `geneve` (UDP 6081), `ikev2` (UDP 500), `esp` / `ipsec` / `ah`, and `wireguard` (UDP 51820):

### `vpn_and_overlays.frasm`

```frameassembly
host vtep_a { ip 10.0.250.11 }
host vtep_b { ip 10.0.250.12 }

compile {
    vtep_a -> vtep_b vxlan vni 10500 dscp 16 df wait 2ms
    vtep_a -> vtep_b geneve vni 20500 optclass 0x0102 opttype 1 wait 2ms
    vtep_a -> vtep_b ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 responderspi 0 msgid 0 wait 3ms
    vtep_a <- vtep_b ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 responderspi 0x1122334455667788 msgid 0 wait 3ms
    vtep_a -> vtep_b wireguard initiation sender 0x01020304
}
```

## 3. Dual-Stack Magic: One `flow(a, b)` for Both IPv4 & IPv6

70 of the 73 Layer 3–7 protocols work identically over IPv4 and IPv6, while `icmp`, `ospf`, `rip`, `vrrp`, `hsrp`, and `dhcp` morph between their v4 and v6 wire encodings automatically based on your host IPs (`igmp` stays IPv4-only; `ndp` and `mld` stay IPv6-only).

Wrap your sequence in `flow peer_check(a, b) { ... }` once, then call it on both v4 and v6 router pairs:

### `dual_stack_ping_and_bgp.frasm`

```frameassembly
host rtr_a_v4 { ip 192.0.2.1 }
host rtr_b_v4 { ip 192.0.2.2 }
host rtr_a_v6 { ip 2001:db8:1::1 }
host rtr_b_v6 { ip 2001:db8:1::2 }

flow peer_check(a, b) {
    a -> b icmp echorequest id 50 seq 1 wait 1ms
    a <- b icmp echoreply id 50 seq 1 wait 2ms
    a -> b tcp syn srcport 50179 dstport 179 win 65535 mss 1440 wait 1ms
    a <- b tcp syn ack win 65535 mss 1440 wait 1ms
    a -> b tcp ack wait 1ms
    a -> b bgp open asn 4200000001 holdtime 90 bgpid 192.0.2.1
}

compile {
    peer_check(rtr_a_v4, rtr_b_v4)
    peer_check(rtr_a_v6, rtr_b_v6)
}
```

> **4-Byte BGP ASNs (`asn > 65535`) Just Work:** Pass `asn 4200000001` and FrameAssembly automatically puts `AS_TRANS` (`23456`) in the legacy 16-bit slot + appends RFC 6793 Capability 65 with your 32-bit ASN.
