← Interview Prep

MPLS — Theory

Label switching that sits between L2 and L3: how forwarding on a fixed-length label replaces the IP lookup, and the services it unlocks.

MPLS (Multiprotocol Label Switching) forwards packets on a short, fixed-length label instead of doing a longest-prefix-match IP lookup at every hop. The label is inserted in a shim header between the L2 frame and the L3 packet — hence the informal name "Layer 2.5." The point is not raw speed (modern silicon does line-rate IP lookups anyway) but decoupling the data plane from the control plane: the core forwards on labels it was told to install, and rich services (VPNs, TE, FRR) are expressed by which labels get pushed at the edge.

The core (P routers) never looks at the customer IP header — it only swaps a top label. All the intelligence lives at the edge (PE routers), which map a packet into a FEC and push the right label stack. This edge-smart / core-dumb split is the entire value proposition of MPLS.

The label & shim header

An MPLS label is a 32-bit shim. The EtherType announcing it is 0x8847 for unicast (0x8848 for multicast). Multiple shims can be stacked.

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                Label (20 bits)                | TC  |S|   TTL   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     Ethernet: [ DA | SA | 0x8847 | MPLS shim(s) | IP packet ... ]
FieldSizePurpose
Label20 bitsThe forwarding value (0–1,048,575). Values 0–15 are reserved (see below).
Traffic Class (TC)3 bitsQoS / CoS marking — formerly called EXP bits. Carries the DiffServ class through the LSP; 8 classes.
Bottom of Stack (S)1 bitS=1 marks the last (innermost) label — the next header is L3. S=0 means more labels follow.
TTL8 bitsHop count, decremented per LSR; mirrors IP TTL. Uniform vs pipe mode governs how it maps to the IP TTL.

Label stack

Labels stack LIFO. The outer/top label is what the transport (the LSP) forwards on; inner labels identify a service. A typical L3VPN packet carries two labels:

  +-----------------+  <- transport label (LDP/RSVP/SR) : how to reach the egress PE
  | outer  S=0      |
  +-----------------+  <- VPN/service label (BGP)        : which VRF / which pseudowire
  | inner  S=1      |
  +-----------------+
  | customer IP payload ...
  +-----------------+

Reserved labels to know: 0 = IPv4 Explicit NULL, 2 = IPv6 Explicit NULL, 1 = Router Alert, 3 = Implicit NULL (the "pop and forward" signal used for PHP).

Roles: PE/LER vs P/LSR, FEC, LIB/LFIB

TermWhat it is
LER / PELabel Edge Router (a.k.a. Provider Edge). Sits at the LSP boundary. On ingress it classifies the packet into a FEC and pushes the label stack; on egress it pops and does the final IP lookup / hands to the VRF.
LSR / PLabel Switch Router (Provider core). Interior transit node — it only swaps the top label and forwards. Never inspects the customer IP header.
FECForwarding Equivalence Class — the set of packets treated identically (same label, same path). Usually "all traffic to egress PE prefix X," but can be per-VPN, per-CoS, etc. Classification into a FEC happens once, at ingress.
LSPLabel Switched Path — the unidirectional chain of label operations from ingress LER to egress LER for a given FEC. Bidirectional traffic uses two LSPs.
LIBLabel Information Base — control-plane table: every label learned from every neighbour for every FEC (the "RIB of labels").
LFIBLabel Forwarding Information Base — data-plane table actually used to forward: incoming label → operation (swap/pop) + outgoing label + next hop. Analogous to the FIB/CEF for IP.

How an LSP gets built

  1. The IGP (OSPF/IS-IS) floods reachability so every router knows the next hop toward each FEC prefix.
  2. A label distribution protocol (LDP, RSVP-TE, BGP-LU, or SR via the IGP) assigns a local label to each FEC and advertises it to neighbours — building the LIB.
  3. Each router picks, for the IGP next hop, the label its downstream neighbour advertised, and installs an LFIB entry: in-label → swap to out-label, send to next hop. The stitched chain of these entries is the LSP.

Downstream-unsolicited is the usual LDP mode: a router advertises "to reach FEC X, send me label L" without being asked. Labels are locally significant — each hop chooses its own values.

Label operations: PUSH, SWAP, POP

OperationWhoMeaning
PUSHIngress LER/PEImpose one or more labels onto an unlabeled (or already-labeled) packet — entering the LSP.
SWAPCore LSR/PReplace the top label with the outgoing label from the LFIB and forward — transit.
POPEgress (or penultimate) LERRemove the top label. If it was the last label, resume normal L3 forwarding.

Worked example — hop-by-hop

PE1 sends a customer packet toward prefix behind PE2, across core P1→P2. Transport labels are locally significant; the VPN label (assigned by PE2) is untouched until egress.

Topology:   CE1 --- PE1 --- P1 --- P2 --- PE2 --- CE2
                    (LER)  (LSR)  (LSR)  (LER)

Ingress PE1 :  PUSH  [transport=17][vpn=90] onto IP packet
               (classify into FEC "prefix behind PE2" + VRF label)

  PE1 ── [17][90] IP ──▶ P1
P1  LFIB   :  in 17  -> SWAP to 22, next hop P2
  P1  ── [22][90] IP ──▶ P2
P2 is penultimate hop; PE2 advertised implicit-null (label 3):
P2  LFIB   :  in 22  -> POP (PHP), next hop PE2
  P2  ── [90] IP ──▶ PE2                (top transport label removed)
Egress PE2 :  in 90 -> POP vpn label, IP lookup in the VRF
  PE2 ── IP ──▶ CE2

Notice PE2 receives only the single VPN label 90 (transport already popped by P2), so it does exactly one label lookup to pick the VRF — that saving is the whole reason for PHP.

PHP & explicit-null

PHP (Penultimate Hop Popping): the egress PE tells the second-to-last router (the penultimate hop) to pop the transport label before forwarding, by advertising the special implicit-null label 3 for its FECs.

TTL handling: uniform vs pipe mode

When a packet enters the LSP the ingress must decide how the MPLS TTL relates to the IP TTL, and on egress whether the tunnel's hops are exposed. This controls what a customer's traceroute reveals.

ModeIngress (push)Egress (pop)Traceroute sees
UniformCopy IP TTL into the MPLS label TTL.Copy the (decremented) MPLS TTL back into the IP TTL.Every P router in the core — the LSP hops are visible. Default on many platforms.
PipeSet the label TTL to a fixed value (e.g. 255), independent of IP TTL.Discard the MPLS TTL; IP TTL is decremented by just 1 for the whole tunnel.The core as a single hop — P routers are hidden. Preferred by SPs who don't want to expose topology.

Short pipe is a variant where the egress PE uses the customer's (inner) marking for its final queuing decision rather than the tunnel's TC, while still hiding the core hops. The interview point: uniform exposes the core to traceroute, pipe hides it as one hop.

Control plane: how labels are distributed

MPLS forwarding is one thing; signaling which label maps to which FEC is a separate control plane. Four options, each a topic of its own:

ProtocolWhat it distributesUse it for
LDPOne label per IGP prefix (FEC), following the IGP shortest path. Simple, hop-by-hop, no bandwidth awareness.Baseline transport LSPs for L3VPN/L2VPN. See the LDP topic.
RSVP-TELabels along an explicitly computed, constraint-based path (bandwidth, affinity, SRLG). Holds soft state per LSP.Traffic Engineering and FRR / fast-reroute. See the RSVP-TE / MPLS-TE topic.
BGP-LULabels carried in BGP (AFI/SAFI label-unicast), stitching LSPs across areas/ASes (inter-AS, seamless MPLS).Scaling and inter-domain transport. See the BGP-LU topic.
Segment Routing (SR-MPLS)No separate signaling protocol — labels (SIDs) are advertised by the IGP; the source encodes the path as a label stack. Stateless core.SR replaces LDP/RSVP; TE without per-LSP state. See the Segment Routing topic.

Services MPLS enables

Everything above is transport. The reason operators run MPLS is the services layered on top, expressed by the inner (service) label:

ServiceWhat it does
L3VPN (RFC 4364 / 2547bis)Per-customer routing tables (VRFs) on the PE; VPNv4/VPNv6 routes carried in MP-BGP with Route Distinguishers & Route Targets; a BGP-assigned VPN label picks the VRF at egress.
L2VPN — VPWS / pseudowirePoint-to-point L2 circuit (Ethernet, ATM, FR) tunneled over MPLS — "wire emulation" (Martini/PWE3). One PW label per circuit.
L2VPN — VPLSMultipoint Ethernet — makes a set of sites look like one bridged LAN; a full mesh of pseudowires with MAC learning in the core.
EVPNModern L2/L3 VPN: MAC/IP learning moved to the control plane via BGP (EVPN AFI), all-active multihoming, and MPLS or VXLAN data planes. Supersedes VPLS.
Traffic Engineering (MPLS-TE)Steer traffic onto explicit paths that honor bandwidth/affinity constraints rather than plain IGP shortest path (RSVP-TE or SR-TE).
FRR (Fast Reroute)Sub-50 ms failover by pre-computing backup LSPs (link/node protection, or SR TI-LFA) and switching locally on failure.

MTU considerations

Each label adds 4 bytes to the frame. A packet is enlarged by 4 × (number of labels), and that growth happens inside the provider network where the customer can't see it.

ScenarioOverhead
Single label (plain LDP transport, PHP)+4 bytes
Two labels (L3VPN: transport + VPN)+8 bytes
Three labels (e.g. TE + VPN, or FRR bypass active)+12 bytes

Likely follow-up questions

More company-bank questions (Meta-style)

Related: Life of a Packet · BGP.