# mpls — 32-Bit RFC 3032 MPLS Label Shims (0x8847) (`mpls`)

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

- **Full Protocol Name:** Multiprotocol Label Switching Unicast Shim
- **Keyword:** `mpls`
- **OSI Layer & Transport:** Layer 2 · EtherType 0x8847 (Label 16)
- **Host Endpoint Rule:** MAC-Only or IP
- **Standards:** RFC 3032, RFC 5462
- **Wireshark Display Filter:** `mpls`
- **Wire Encapsulation:** `Ethernet II -> MPLS Shim (0x8847)`

## Overview

No need to boot four virtual provider-edge routers just to get a 4-byte `0x8847` shim — tack `mpls 16040 exp 6 bos 1 mplsttl 64` onto any packet line and call it a day.

Multiprotocol Label Switching (`mpls`) inserts a 32-bit shim header (`EtherType 0x8847`) between Layer 2 Ethernet/VLAN headers and the inner Layer 3 packet. The 4-byte shim packs a 20-bit Label (`0..1048575`), 3-bit Traffic Class / Experimental QoS field (`exp` or `tc`), 1-bit Bottom-of-Stack indicator (`bos`), and an 8-bit MPLS Time-To-Live (`mplsttl`).

In FrameAssembly v3.2.0, `mpls` works both as a standalone Layer 2 protocol (`p1 -> p2 mpls 16000 exp 5 bos 1 mplsttl 64`) between MAC-only Label Switch Routers (LSRs) and as a cross-layer modifier attached once to any IPv4 or IPv6 packet statement.

## Minimal Quickstart (`mpls_quickstart.frasm`)

```frameassembly
host pe_west { mac 00:1c:73:aa:00:01 }
host p_core  { mac 00:1c:73:bb:00:02 }

compile {
    pe_west -> p_core mpls 16000
}
```

### Automatic Wire Calculations

- Sets Ethernet II (or inner VLAN/QinQ) EtherType to `0x8847` (MPLS Unicast).
- Bit-packs the 20-bit `label` (`default 16`), 3-bit `exp`/`tc` (`default 0`), 1-bit `bos` (`default 1`), and 8-bit `mplsttl` (`default 64`) into the big-endian 32-bit RFC 3032 shim.
- When attached as a cross-layer modifier on an IPv4 or IPv6 frame, places the complete checksummed IP + L4 + L7 packet immediately after the Bottom-of-Stack MPLS shim.

## Practical Lab Example: SR-MPLS L3VPN Core Transit Over 802.1Q Sub-Interfaces (`mpls_sr_l3vpn.frasm`)

Models two Provider Edge routers exchanging MPLS-labeled BGP control traffic, VoIP EF traffic (`exp 5`), and dual-stack IPv6 customer probes across VLAN 400.

```frameassembly
host pe1_v4 { ip 10.100.1.10 mac 00:1c:73:10:01:01 }
host pe2_v4 { ip 10.100.2.20 mac 00:1c:73:20:02:02 }
host ce1_v6 { ip 2001:db8:50::10 mac 00:1c:73:10:01:01 }
host ce2_v6 { ip 2001:db8:60::20 mac 00:1c:73:20:02:02 }

compile {
    // 1. Standalone MPLS OAM probe over VLAN 400
    pe1_v4 -> pe2_v4 mpls 16001 exp 6 bos 1 mplsttl 64 vlan 400 payload "sr-oam-ping" wait 2ms
    // 2. L3VPN IPv4 HTTPS TLS ClientHello inside MPLS label 24010
    pe1_v4 -> pe2_v4 tcp syn srcport 52443 dstport 443 win 65535 mss 1440 vlan 400 mpls 24010 exp 4 bos 1 mplsttl 63 wait 1ms
    pe1_v4 <- pe2_v4 tcp syn ack win 65535 mss 1440 vlan 400 mpls 24020 exp 4 bos 1 mplsttl 63 wait 1ms
    pe1_v4 -> pe2_v4 tcp ack vlan 400 mpls 24010 exp 4 bos 1 mplsttl 63 wait 1ms
    pe1_v4 -> pe2_v4 tls clienthello sni "erp.vrf-prod.internal" alpn "h2" vlan 400 mpls 24010 exp 4 bos 1 mplsttl 63 wait 2ms
    // 3. 6VPE IPv6 ICMPv6 Echo inside MPLS label 24055
    ce1_v6 -> ce2_v6 icmp echorequest id 9 seq 1 vlan 400 mpls 24055 tc 5 bos 1 mplsttl 62
}
```

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

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

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

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

## All `mpls` Keywords & Header Options

Packet line pattern: `src_host -> dst_host mpls [<0..1048575>] [exp|tc <0..7>] [bos <0|1>] [mplsttl <0..255>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `mpls [<0..1048575>] \| label <0..1048575>` | 20-bit unsigned integer (0..1048575) | `16` | Sets the 20-bit MPLS Label (`0..15` reserved special-purpose labels such as `0` IPv4 Explicit Null / `3` Implicit Null; `16..1048575` general labels). |
| `exp <0..7> \| tc <0..7>` | 3-bit unsigned integer (0..7) | `0` | Sets the 3-bit RFC 5462 Traffic Class (formerly Experimental `EXP`) QoS field (`tc` and `exp` are exact aliases). |
| `bos <0\|1>` | 1-bit flag (0 or 1) | `1` | Sets the Bottom-of-Stack bit (`1` marks the innermost label preceding the L3 payload). |
| `mplsttl <0..255>` | Whole number (0..255) (0..255) | `64` | Sets the 8-bit MPLS shim TTL independently of the inner IPv4/IPv6 `ttl` modifier. |

## Cross-Layer Options Valid with `mpls`

| 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`). |

## Common Mistakes & Quick Fixes

### At Most One mpls (Or label) Clause Per Packet Line

- **Avoid:** `pe1 -> pe2 mpls label 16001 exp 6 bos 1`
- **Valid v3.2.2 Syntax:** `pe1 -> pe2 mpls 16001 exp 6 bos 1`

FrameAssembly supports one MPLS shim per packet, and `label <0..1048575>` is an alias for `mpls <0..1048575>` on L3/L7 packets. On a standalone `mpls` frame, pass the label number directly (`mpls 16001`) instead of combining `mpls` and `label`.

### Use mplsttl for the Shim TTL vs ttl for Inner IP

- **Avoid:** `Assuming ttl 255 changes the MPLS shim TTL`
- **Valid v3.2.2 Syntax:** `pe1 -> pe2 icmp ttl 64 mpls 16000 mplsttl 255`

`mplsttl` controls the 8-bit TTL inside the MPLS shim (`0x8847`), whereas `ttl` controls the inner IPv4 Time-To-Live or IPv6 Hop Limit.
