This is a good question about MPLS (Multiprotocol Label Switching) technology. Let me break this down comprehensively.
MPLS Label Swapping
MPLS is a mechanism that directs packets through a network based on labels rather than traditional IP routing. Let me explain the key concepts:
1. How MPLS Label Swapping Works
Basic Concept:
- MPLS inserts a label (a short, fixed-length identifier) between the Layer 2 (Ethernet) and Layer 3 (IP) headers
- The label replaces the need for complex IP lookups at each hop
Label Format:
MPLS Label Stack Entry (32 bits):
- Label (20 bits): The actual label value
- Traffic Class/Exp (3 bits): QoS/priority marking
- Bottom of Stack (1 bit): Indicates if this is the last label
- TTL (8 bits): Time to Live
The Swapping Process:
At each Label Switched Router (LSR):
-
Ingress Router (Ingress LSE):
- Performs traditional IP lookup
- Determines the egress point
- Pushes/attaches an MPLS label to the packet
-
Intermediate LSRs:
- Look up the incoming label in the Label Forwarding Information Base (LFIB)
- Replace (swap) the label with the outgoing label
- Forward based on the outgoing label
- Do NOT perform IP lookup
-
Egress Router (Egress LSE):
- Pops (removes) the label
- Performs traditional IP routing on the exposed IP header
- Forwards based on IP destination
2. Packet Travel Through a Label Switched Path (LSP)
Let me illustrate with an example:
Config:
Network: Ingress(R1) -> R2 -> R3 -> R4 -> Egress(R5)
Destination: 10.0.0.0/24
LSP via: R1 -> R2 -> R3 -> R4 -> R5
Label assignments:
- R1 to R2: Label 100
- R2 to R3: Label 200
- R3 to R4: Label 400
- R4 to R5: Label 300 (will be popped)
Step-by-step:
1. IP Packet arrives at R1 (Ingress):
Frame: [Ethernet | IP(dst=10.0.0.5) | Payload]
R1 performs an IP lookup on destination 10.0.0.5, determines the packet belongs to the LSP destined for 10.0.0.0/24, and pushes label 100 onto the packet before forwarding it to R2.
Result: [Ethernet | MPLS Label 100 | IP(dst=10.0.0.5) | Payload]
-
At R2, the incoming label 100 is swapped for label 200 and forwarded to R3:
Frame: [Ethernet | MPLS Label 200 | IP(dst=10.0.0.5) | Payload]
-
At R3, label 200 is swapped for label 400 and sent to R4:
Frame: [Ethernet | MPLS Label 400 | IP(dst=10.0.0.5) | Payload]
-
At R4, label 400 is popped before sending to R5:
Frame: [Ethernet | IP(dst=10.0.0.5) | Payload]
-
R5 performs standard IP routing on the exposed header and delivers the packet to 10.0.0.5.
The LSP follows a fixed path determined at ingress, with each intermediate router performing a single label lookup and either swapping or popping the label based on its forwarding information base.
Labels are only significant between adjacent routers and can be reused elsewhere in the network. This predetermined path and simple lookup mechanism is what makes MPLS efficient compared to traditional routing.
The key performance difference comes down to lookup complexity. IP routing requires checking multiple prefix lengths against a destination address—potentially traversing a tree structure with multiple memory accesses. MPLS label lookup is a direct table lookup on a fixed 20-bit value, which is a single operation with minimal computation overhead. table for O(1) lookup with a single calculation and memory access in the best case.
The fundamental difference comes down to lookup complexity: IP routing requires finding the longest matching prefix across potentially hundreds of thousands of entries using complex tree structures, while MPLS performs a straightforward exact match on a 20-bit label using a hash table. This means MPLS avoids the multiple memory traversals and cache misses inherent to prefix matching, and operates on a smaller, fixed-length key against typically fewer forwarding entries. The result is significantly better cache locality and predictable single-access performance for label-based forwarding. control over paths through the network, enabling VPNs and L2VPN services for traffic isolation, improving QoS granularity with label-based forwarding, and providing a foundation for newer approaches like Segment Routing.
Labels are distributed through protocols like LDP and BGP, with RSVP-TE handling traffic engineering scenarios. The architecture supports stacking multiple labels for cases like VPNs where transport and service labels coexist. An optimization called Penultimate Hop Popping lets the penultimate router remove the label before forwarding to the egress, reducing processing at the final hop.
MPLS Label Swapping Explained
How Label Swapping Works
MPLS inserts a fixed 20-bit label between Layer 2 and Layer 3 headers. At each Label Switched Router (LSR), the label is swapped (replaced) based on a simple lookup table rather than processing the IP header.
Label Structure (32 bits)
┌─────────────────────┬──────┬──┬─────┐
│ Label (20 bits) │ EXP │S │ TTL │
│ [0-1048575] │(3b) │1 │(8b) │
└─────────────────────┴──────┴──┴─────┘
S = Stack bit (last label?)
EXP = Traffic class/QoS marking
Packet Journey Through an LSP
Here's a concrete example:
Network: R1 (Ingress) → R2 → R3 → R4 (Egress)
Destination: 10.0.0.0/24
Label assignments per hop:
R1→R2: 100 | R2→R3: 200 | R3→R4: 400 | R4 pops label
Step-by-Step Forwarding
1. Ingress Router (R1):
Incoming: [Ethernet | IP: 10.0.0.5 | Payload]
↓
IP Lookup → Found: 10.0.0.0/24 matches LSP
Push Label 100
↓
Outgoing: [Ethernet | Label:100 | IP: 10.0.0.5 | Payload]
2. Intermediate Router (R2):
Incoming: [Label:100 | IP: 10.0.0.5 | Payload]
↓
LFIB Lookup: Label 100 → Swap to 200
(NO IP lookup performed)
↓
Outgoing: [Label:200 | IP: 10.0.0.5 | Payload] → R3
3. Intermediate Router (R3):
Incoming: [Label:200 | ...]
↓
LFIB Lookup: Label 200 → Swap to 400
↓
Outgoing: [Label:400 | ...] → R4
4. Egress Router (R4):
Incoming: [Label:400 | IP: 10.0.0.5 | Payload]
↓
LFIB Lookup: Label 400 → POP label
↓
Expose IP header → Traditional IP routing
Outgoing: [IP: 10.0.0.5 | Payload] → Destination
Why 20-bit Label Lookup is Faster
IP Longest Prefix Match (LPM)
Routing Table:
10.0.0.0/8 → Next Hop A
10.1.0.0/16 → Next Hop B
10.1.2.0/24 → Next Hop C
Lookup for 10.1.2.5:
1. Check /24? YES ✓ (match, but keep looking)
2. Check /16? YES ✓ (match, but keep looking)
3. Check /8? YES ✓ (match, but keep looking)
4. Select LONGEST = /24 → Next Hop C
Requires: Multiple comparisons, tree traversal, prefix matching logic
Data Structure: Patricia Trie or Binary Trie
- Requires multiple memory accesses (cache misses)
- Potentially 32 levels to traverse (IPv4)
- Complex bit-by-bit comparison
MPLS Exact Match Label Lookup
Label Forwarding Information Base (LFIB):
Label 100 → [Interface eth1, Outgoing Label 200]
Label 200 → [Interface eth2, Outgoing Label 400]
Label 400 → [Interface eth3, POP]
Lookup for Label 100:
Direct hash: hash(100) → Single memory access
Result: [eth1, 200]
Requires: One calculation, ONE lookup
Performance Comparison
| Factor | IP LPM | MPLS Label |
|---|
| Match Type | Longest prefix (variable) | Exact (fixed 20-bit key) |
| Data Structure | Trie (tree traversal) | Hash table (direct lookup) |
| Complexity | O(k) where k = key bits | O(1) constant time |
| Memory Accesses | 4-10+ accesses | 1-2 accesses |
| Cache Efficiency | Poor (scattered references) | Good (hash table locality) |
| CPU Cycles | 50-100+ cycles | 10-30 cycles |
Why It's Faster (3 Key Reasons)
-
Fixed-Length Key: 20-bit MPLS label vs. variable-length IP prefix matching
- No need to find "longest" — it's an exact match
- Predictable comparison time
-
Hash Table: O(1) direct lookup
// MPLS Lookup (pseudo-code)
lfib_entry = hash_table[incoming_label]; // ONE operation
// IP LPM (simplified)
while (trie_node) {
trie_node = trie_node->child[next_bit]; // MULTIPLE operations
}
-
Smaller LFIB: Typically far fewer entries
- IP routing table: 800K+ entries
- LFIB: 1K-10K entries (per LSP)
- Better cache locality
Real-World Note
Modern hardware (ASIC, hardware switching) can do IP LPM at line rate, so the speed advantage is less critical today. MPLS is now primarily used for:
- Traffic Engineering (explicit paths)
- VPNs (MPLS L3VPN, L2VPN)
- QoS granularity
- Carrier backbone networks
The label switching advantage is most visible on older software-based routers or when comparing millions of routes.