# vxlan — 24-Bit Data-Center VXLAN Overlays on UDP 4789 (`vxlan`)

> **FrameAssembly v3.2.2** · Protocol 14 of 81 · Canonical URL: https://frameassembly-lang.dev/docs/protocols/vxlan

- **Full Protocol Name:** Virtual eXtensible Local Area Network Overlay
- **Keyword:** `vxlan`
- **OSI Layer & Transport:** Layer 3 · UDP 4789 (VNI 1)
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 7348
- **Wireshark Display Filter:** `vxlan`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> VXLAN (UDP 4789 (VNI 1))`

## Overview

When 4,094 VLANs stopped being enough, data centers wrapped Layer 2 inside UDP `4789` and got 16 million VNIs. `vxlan vni 10050` stamps the exact 8-byte `0x08` VXLAN shim.

Virtual eXtensible Local Area Network (`vxlan`) stretches Layer 2 broadcast domains across routed Layer 3 leaf-spine fabrics by encapsulating inner Ethernet frames inside UDP datagrams on **`dstport 4789`**. The 8-byte RFC 7348 VXLAN header sets the `I` flag (`0x08`) and carries a 24-bit VXLAN Network Identifier (`vni` / `vnid`, supporting up to 16.7 million tenant segments `0..16777215`).

FrameAssembly emits the outer Ethernet + IPv4/IPv6 + UDP (`4789`) + 8-byte VXLAN header plus an encapsulated inner Ethernet/IPv4 frame automatically—making EVPN-VXLAN data-plane testing immediate.

## Minimal Quickstart (`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
}
```

### Automatic Wire Calculations

- 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.
- Appends a valid inner Ethernet II + IPv4 frame when `payload`/`hexpayload` is omitted, and validates `vni` bounds (`0..=16777215`).

## Practical Lab Example: 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.

```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
}
```

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

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

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

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

## All `vxlan` Keywords & Header Options

Packet line pattern: `src_host -> dst_host vxlan [vni|vnid <0..16777215>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `vni <0..16777215> \| vnid <0..16777215>` | 24-bit unsigned integer (0..16777215) | `1` | Sets the 24-bit VXLAN Network Identifier in bytes 4..6 of the 8-byte VXLAN header (`vnid` is an exact alias for `vni`). |
| `srcport <0..65535> \| dstport <0..65535>` | 16-bit UDP ports | `srcport 49152, dstport 4789` | Controls outer UDP entropy `srcport` for spine ECMP hashing or overrides `dstport` (e.g., `8472` for Flannel / early Linux VXLAN). |

## Cross-Layer Options Valid with `vxlan`

| 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). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"` or `"de:ad:be:ef"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType u16 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or 16-bit EtherType for this single packet. |
| `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>]` | Label 0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255 | `Unlabeled (at most 1 mpls tag per packet)` | Inserts a 32-bit MPLS label header (`0x8847`) ahead of the Layer 3 header. |
| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 64, 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>]` | IPv4 ID, DF/MF flags, fragment offset 0..8191 | `ipid 1, flags 0, fragoffset 0` | Sets IPv4 Identification, Do-Not-Fragment (`df`), More-Fragments (`mf`), and fragment offset (ignored over IPv6). |
| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (ignored when running over IPv4 hosts). |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 4789 (VNI 1)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |

## Common Mistakes & Quick Fixes

### 24-Bit VNI Upper Bound (16,777,215)

- **Avoid:** `leaf1 -> leaf2 vxlan vni 20000000`
- **Valid v3.2.2 Syntax:** `leaf1 -> leaf2 vxlan vni 16777215`

VXLAN VNIs occupy 24 bits (`0..=16777215` / `0xffffff`). Values exceeding `16777215` are rejected by semantic validation.

### VXLAN Runs Exclusively Over UDP (No transport tcp)

- **Avoid:** `leaf1 -> leaf2 vxlan vni 100 transport tcp`
- **Valid v3.2.2 Syntax:** `leaf1 -> leaf2 vxlan vni 100`

Per RFC 7348, VXLAN is strictly UDP-encapsulated and is not in the 9-protocol `transport` whitelist.
