# Layer 2 Switching, VLAN/QinQ, 802.1X & MPLS Protocols

> **FrameAssembly v3.2.2** · Category 01 (Layer 2 · 8 Protocols) · Canonical URL: https://frameassembly-lang.dev/docs/protocols/categories/l2-switching

Operating-system raw sockets and consumer USB-Ethernet NIC drivers routinely strip or rewrite IEEE 802.1Q (`0x8100`) and IEEE 802.1ad QinQ (`0x88a8`) tags before user-space capture buffers ever see them. FrameAssembly synthesizes every Layer 2 Ethernet II and IEEE 802.3 LLC frame directly in user space—writing exact outer/inner TPIDs, 3-bit 802.1p PCP priorities, IEEE Slow Protocol subtypes, and 32-bit MPLS label shims straight to `.pcap` or `.pcapng`.

All 8 protocols in this group (`arp`, `vlan`, `qinq`, `lldp`, `stp`, `lacp`, `eapol`, and `mpls`) accept MAC-only `host` endpoints (`host sw1 { mac 00:1c:73:aa:bb:01 }`) as well as IP hosts. In addition, `vlan`, `qinq`, and `mpls` work as cross-layer L2 wrappers on any Layer 3, Layer 4, or Layer 7 packet statement.

## Category Wire & Endpoint Rules

- **MAC-Only Endpoints Allowed:** Only these 8 pure Layer 2 protocols compile with MAC-only `host` blocks (`ip` omitted); all 73 Layer 3–7 protocols require plain IPv4 or IPv6 addresses on both endpoints.
- **Automatic IEEE Group Destination MACs:** When `dstmac` is omitted, `arp request` / `garp` broadcast to `ff:ff:ff:ff:ff:ff`, `stp` targets `01:80:c2:00:00:00`, `lacp` targets `01:80:c2:00:00:02`, `eapol` targets `01:80:c2:00:00:03`, and `lldp` targets `01:80:c2:00:00:0e`.
- **Flexible MAC Literals:** Every `mac`, `srcmac`, `dstmac`, `sendermac`, and `actorsys` field accepts Linux colon (`00:1c:73:00:01:02`), Windows hyphen (`00-1C-73-00-01-02`), or Cisco dot-quad (`001c.7300.0102`) hex.
- **Standalone or Cross-Layer Shims:** `vlan <0..4095>`, `qinq <0..4095> innervlan <0..4095>`, and `mpls <0..1048575>` work standalone or appended once onto any L3–L7 frame.

## Multi-Protocol Example: Campus Switch Trunk: LLDP, RSTP, LACP, 802.1X, GARP & QinQ (`l2_switch_trunk_suite.frasm`)

Emits a 6-frame switch-port bring-up sequence combining IEEE 802.1AB LLDP neighbor discovery, 802.1w RSTP BPDU, 802.3ad LACP negotiation, 802.1X EAPOL-Start, VLAN-tagged Gratuitous ARP failover, and double-tagged 802.1ad QinQ.

```frameassembly
host dist_sw { ip 10.10.20.1 mac 00:1c:73:10:00:01 }
host edge_sw { ip 10.10.20.2 mac 00:1c:73:10:00:02 }

compile {
    dist_sw -> edge_sw lldp chassisid "00:1c:73:10:00:01" portid "TenGigE1/0/1" ttl 120 sysname "dist-sw-01" wait 2ms
    dist_sw -> edge_sw stp rstp rootid "32768:00:1c:73:10:00:01" bridgeid "32768:00:1c:73:10:00:01" portid 0x8001 cost 2000 wait 2ms
    dist_sw -> edge_sw lacp actorsys 00:1c:73:10:00:01 actorkey 10 actorport 1 actorstate 0x3d partnersys 00:1c:73:10:00:02 partnerkey 10 partnerport 1 wait 2ms
    edge_sw -> dist_sw eapol start version 2 wait 2ms
    dist_sw -> edge_sw vlan 20 pcp 6 arp garp senderip 10.10.20.1 sendermac 00:1c:73:10:00:01 wait 2ms
    dist_sw -> edge_sw qinq 500 innervlan 20 pcp 5 payload "metro-trunk-probe"
}
```

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

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

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

# 4. Verify dissected protocol fields in tshark
tshark -r l2_switch_trunk_suite.pcap -Y "lldp || stp || lacp || eapol || arp || vlan"
```

- **Wireshark Display Filter:** `lldp || stp || lacp || eapol || arp || vlan`

## Protocols in Category 01 (8 Native Builders)

| # | Keyword | Protocol | Default Port / Proto | Endpoint Rule | Wireshark Filter | Spec URL |
| --- | --- | --- | --- | --- | --- | --- |
| 1 | `arp` | Address Resolution Protocol & Gratuitous ARP | `EtherType 0x0806` | MAC-Only or IP | `arp` | https://frameassembly-lang.dev/docs/protocols/arp |
| 2 | `vlan` | IEEE 802.1Q Virtual LAN Tagging & 802.1p QoS | `TPID 0x8100 (VID 1)` | MAC-Only or IP | `vlan` | https://frameassembly-lang.dev/docs/protocols/vlan |
| 3 | `qinq` | IEEE 802.1ad Provider Bridge Double VLAN Tagging (S-Tag + C-Tag) | `Outer 0x88a8 + Inner 0x8100` | MAC-Only or IP | `vlan.etype == 0x88a8 \|\| vlan` | https://frameassembly-lang.dev/docs/protocols/qinq |
| 4 | `lldp` | IEEE 802.1AB Link Layer Discovery Protocol | `EtherType 0x88cc` | MAC-Only or IP | `lldp` | https://frameassembly-lang.dev/docs/protocols/lldp |
| 5 | `stp` | IEEE 802.1D Spanning Tree & IEEE 802.1w Rapid Spanning Tree | `802.3 LLC 0x4242 -> 01:80:c2:00:00:00` | MAC-Only or IP | `stp` | https://frameassembly-lang.dev/docs/protocols/stp |
| 6 | `lacp` | IEEE 802.3ad / 802.1AX Link Aggregation Control Protocol | `EtherType 0x8809 (Slow Subtype 0x01)` | MAC-Only or IP | `lacp` | https://frameassembly-lang.dev/docs/protocols/lacp |
| 7 | `eapol` | IEEE 802.1X Port-Based Network Access Control (EAP over LAN) | `EtherType 0x888e -> 01:80:c2:00:00:03` | MAC-Only or IP | `eapol \|\| eap` | https://frameassembly-lang.dev/docs/protocols/eapol |
| 8 | `mpls` | Multiprotocol Label Switching Unicast Shim | `EtherType 0x8847 (Label 16)` | MAC-Only or IP | `mpls` | https://frameassembly-lang.dev/docs/protocols/mpls |
