Skip to content
TheChatArchiveThe Chat Archive
GPT 5.1 Codex Max· openaiHugging Face Frontier Reasoning Traces

Explain MPLS label swapping. How does a packet travel through a label switched path? Why…

  1. User

    Explain MPLS label swapping. How does a packet travel through a label switched path? Why is 20-bit label lookup faster than longest prefix IP match?

  2. Assistant

    Explaining MPLS label swapping and path forwarding

    MPLS routers forward packets by swapping the top 20-bit label on each hop using a label forwarding table (LFIB) that maps incoming labels to outgoing labels and interfaces. Packets enter the MPLS domain at the ingress router, which classifies them into Forwarding Equivalence Classes and pushes labels; intermediate routers swap labels to steer packets along a predefined unidirectional Label Switched Path, and the egress router pops labels and forwards the original IP packet. Label lookup is faster than IP longest prefix match because the fixed-length 20-bit label enables simple exact-match table lookups—often via direct indexing or SRAM—avoiding the complex, variable-length prefix searches and slower TCAM-based lookups required for IP routing. What MPLS adds to a normal IP‑only network is a second, very simple forwarding plane.

    An MPLS “label” is a 20‑bit value carried in a 32‑bit shim header that sits between the layer‑2 header and the layer‑3 payload. Labels are not globally significant; each LSR allocates labels for the forwarding equivalence classes (FECs) it can reach and tells its neighbours “if you want to send me traffic for FEC X, use label N”. The neighbour installs that binding in its label forwarding table.

    When a labelled packet arrives on an LSR, the device does not re‑run the IP routing algorithm. It looks at the topmost label, does an exact lookup in its LFIB for “incoming label X on interface Y”, and the matching entry tells it which interface to use next and which label action to perform. The usual action in the core is swap: replace the incoming value with the outgoing value that the downstream neighbour advertised, and send the packet on. The ingress edge router performs a push to impose the initial label stack on an unlabeled IP packet, and the egress edge router performs a pop (or its penultimate neighbour does, using the implicit‑null label) to remove the outermost label so that normal IP forwarding can take over. If there is a stack of labels, only the top label is examined at each hop; inner labels are used for services such as L3VPNs.

    An LSP is the unidirectional sequence of such label bindings across the network. It is set up by a control protocol such as LDP or RSVP‑TE: each hop programs an LFIB entry for the FEC, and from then on packets follow that path simply by having their labels swapped at each LSR until they reach the terminating LER.

    This forwarding is fast because of its simplicity. In the IP case you must perform a longest‑prefix match over variable‑length masks (for IPv4 32‑bit addresses, for IPv6 128‑bit addresses) to find the “best” route, which in hardware is typically implemented with TCAMs or tree‑walking algorithms. In the MPLS case you have a fixed 20‑bit field and you only ever do an exact match on the whole field. That allows implementations to treat the label as an array index or hash key in fast SRAM, and it avoids the extra compare‑logic, priority resolution and wider memories needed for longest‑prefix matches. The smaller, fixed‑length search key and exact‑match semantics translate into less hardware and shorter look‑up times.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.