MPLS Label Stack Decoder
Decode raw MPLS shim-header bytes and inspect every label stack entry, including its 20-bit label value, Traffic Class, Bottom-of-Stack bit, TTL and reserved-label meaning.
—
—
—
What Is an MPLS Label Stack?
Multiprotocol Label Switching forwards packets using short label values rather than performing a complete network-layer destination lookup at every MPLS hop. Each MPLS shim header contains a label plus Traffic Class, Bottom-of-Stack and TTL fields.
Multiple MPLS headers can be stacked. The first header is the outer or top label, while the header whose S bit equals 1 identifies the bottom of the MPLS label stack.
MPLS Shim Header Format
31 12 11 9 8 7 0
+-------------------------+------+---+----------------+
| Label (20 bits) | TC | S | TTL (8) |
+-------------------------+------+---+----------------+
Label = 20 bits
TC = 3 bits
S = 1 bit
TTL = 8 bits
Total = 32 bits = 4 bytesMPLS Label Field
The Label field occupies the upper 20 bits of the shim header. Its numerical range is 0 through 1,048,575.
20-bit maximum:
2^20 - 1
= 1,048,575
= 0xFFFFFLabel values from 0 through 15 are reserved for special purposes rather than ordinary dynamically assigned MPLS forwarding labels.
MPLS Traffic Class Field
The three-bit Traffic Class field is commonly called TC. Historically this field was also called EXP. Its interpretation can depend on the MPLS QoS model being used.
TC range:
000 = 0
001 = 1
...
111 = 7MPLS Bottom-of-Stack Bit
The S bit marks the final label in the current MPLS stack.
S = 0
Another MPLS label follows
S = 1
This is the bottom labelA normal label stack should therefore have S=0 on all entries except the final entry, where S=1.
MPLS TTL Field
The final eight bits of every MPLS shim header contain the TTL value. Like IP TTL or Hop Limit, it helps prevent indefinite forwarding loops.
TTL range:
0 through 255Reserved MPLS Labels
| Label | Name | Meaning |
|---|---|---|
| 0 | IPv4 Explicit NULL | Pop the label and continue forwarding as IPv4 |
| 1 | Router Alert | Packet requires special examination |
| 2 | IPv6 Explicit NULL | Pop the label and continue forwarding as IPv6 |
| 3 | Implicit NULL | Signals penultimate-hop popping; normally not sent in the label stack |
| 7 | Entropy Label Indicator | Signals that an entropy label follows |
| 13 | Generic Associated Channel Label | Identifies an associated channel |
MPLS Label Stack Example
Top Label:
100
TC = 3
S = 0
TTL = 64
Bottom Label:
200
TC = 1
S = 1
TTL = 63
Decoded stack:
[100]
↓
[200, Bottom]How to Calculate an MPLS Shim Header
A 32-bit MPLS entry can be constructed mathematically from its four fields.
Header =
(Label << 12)
|
(TC << 9)
|
(S << 8)
|
TTLThe decoder performs the reverse operation to recover each field.
How to Extract an MPLS Label
Label =
Header >>> 12
TC =
(Header >>> 9) & 0x7
S =
(Header >>> 8) & 0x1
TTL =
Header & 0xFFSingle MPLS Label vs Label Stack
An MPLS packet can contain only one label or multiple stacked labels. A single-label packet has its S bit set to 1 in that only shim header.
For multiple labels, the outer labels use S=0 while the final MPLS shim header uses S=1.