# Computer network technologies and services/MPLS

Multiprotocol Label Switching (MPLS) is the enabling technology for the new broadband (IP) public network. It can be considered as a protocol architecture (or a suite of protocols) to control different sub-protocols.
MPLS operates at a layer that is generally considered to lie between traditional definitions of layer 2 (data-link layer) and layer 3 (network layer).

## Benefits

* MPLS introduction simplifies the traditional 'big onion'.
IP protocol was developed for research purpose and was not designed to be sold as a service. It is a so-called 'best-effort protocol', which means that there is no explicit purpose in giving a guaranteed reliable service (speed, delays...).
When IP was starting to become a commercial good, the International Telecommunication Union (ITU) started developing protocols (such as ATM, frame relay, etc.) targeting service reliability and stability, thinking they would have been permeating the computer telecommunication world. Nevertheless end users have kept using IP, and as a result service providers nowadays have to deal with a lot of protocols in order to carry IP to end users: this 'big onion' makes very few sense for service providers due to high maintenance, equipment and software development costs to guarantee interoperability.
Cisco Systems was the first vendor to implement tag switching into their routers, then IETF adopted the protocol and named it as MPLS.
MPLS combines the best features from the connection-less protocols with the best ones from the connection-oriented protocols, representing the solution for the 'big onion' problem for two reasons:
* MPLS provides an IP-based network with a greater service reliability and a single unified control plane more isolated from the data plane:
** in IP control and data planes are continuously updated on every change in the network;
** in MPLS updating occurs just when a new LSP is set up; since there is a separation between data plane and control plane it is possible to set up paths with independent constraints;
* MPLS allows to re-use the traditional ATM devices by simply updating their software.

### Main features

* possibility of \ul{traffic engineering}: distributing traffic load over the network to avoid congestions;
* protocol independence (multi-protocol) → useful for transition from IPv4 to IPv6;
* designed to grant quality of service (not yet supported);
* unified control plane: it can be used for any network besides IP (e.g. MPλS for optical networks);
* fast fault recovery: two paths between a pair of nodes can be created, so that in case of failure in the first path the LSR can just notify the failure and quickly deviate the traffic to the second path (instead in IP it is difficult to insert two paths into a routing table, and if a link fails routers need to exchange routing information and perform sophisticated algorithms to find another path).

## Network architecture

A Label Switch Router (LSR) is the device responsible for switching the labels used to route packets. LSRs are called label edge routers when placed at the edges of the MPLS cloud. LSRs combine smartness of routers and speed of switches: they are able to route in a clever way like routers, avoiding complicated data structures and algorithms like switches.
MPLS clouds can be gradually deployed: they can grow up and can be integrated to each other.

## Data plane

Data plane is the capability of switching packets based on their labels.

### MPLS header

IP packets are prefixed with an MPLS header containing one or more label stack entries. Each label stack entry contains four fields:
* label: routing is based on this field instead of the IP destination address;
* traffic class (exp): for quality of service (QoS) priority and Explicit Congestion Notification (ECN);
* bottom of stack flag (S): if set, the current label is the last one in the stack;
* Time to Live (TTL).

### Label switching

A Label Switched Path (LSP) is a path set up by a signaling protocol that links a source label edge router (ingress) to a drain one (egress):
* when the ingress LSR receives a packet, it adds a label to it and forwards it to the next hop of the LSP previously created;
* when the egress LSR receives a packet, it strips off its label and forwards it out of the MPLS cloud.
A Forwarding Equivalence Class (FEC) is a set of packets which may be forwarded in the same way; that is, they may be bound to the same MPLS labels. Labels are not unique over the whole MPLS cloud, but they are changed on each hop (label swapping). Consider that granting the uniqueness of the labels all over the network would require too complex protocols and too long labels.
Using labels enables MPLS to provide two kinds of services:
* fast lookup: IP routing, based on the `longest prefix matching' algorithm, is sophisticated, difficult to be optimized and not fast enough when dealing with a wide amount of routes.
    MPLS provides a faster lookup with respect to IP because packet-forwarding decisions are made solely on the label, placed before the IP packet, without the need to examine the contents of the packet itself: each label in fact can be used as key to access the routing table as an array or hash table in order to expedite the route discovery;
* traffic engineering: IP tends to aggregate the traffic, but having lots of packets going through the same path doesn't provide an efficient service. This can not be avoided easily as it would require a static route configuration → expensive and not scalable.
    MPLS is able to control the traffic like a connection-oriented protocol: MPLS routing involves both source and destination labels, and routers can assign to a new packet flow the label corresponding to the least-loaded path in order to avoid congestion and allow traffic distribution. Moreover a failure in a path due to a non-working node will not affect the other paths.

#### Hierarchy and scalability

MPLS is very scalable: inside a big MPLS cloud of domain 1 it is possible to define in a hierarchical way a smaller MPLS cloud of domain 2 and so on, and multiple label stack entries can be stored next to each other in a stack data structure. The label stack entries are added from the inner one to the outer one while the packet enters clouds of higher domain and stripped off from the outer one to the inner one while the packet exits clouds of lower domain, and LSRs not at the edges of the clouds always process the outer label stack entry. This hierarchy of labels can correspond to a hierarchy of providers, and the number of labels is limited only by the Ethernet frame size.
This technique introduces some advantages:
* it reduces the size of the routing and forwarding tables, because they do not have to be comprehensive;
* it allows to re-use the existing switching hardware (ATM, frame relay, etc.): MPLS headers are put directly into the 2-level headers, so that they can be processed by the existing hardware that now processes the level 2 simply by upgrading its software.

## Control plane

Control plane is the capability of choosing the labels to be inserted into the packets.
The creation of a forwarding table (and in a broader sense of the LSP) for a specific FEC is performed in three steps:
* label binding: it is always performed by the downstream node, which chooses a label for the FEC, and this can be performed in two ways (not mutually exclusive):
** unsolicited: the downstream node can decide any time to assign labels, even if there is no traffic in the network;
** on-demand: the upstream node can asks the downstream node for a fixed label;
* label distribution: the downstream node communicates the chosen label to the upstream node;
* label mapping: the upstream node creates a new entry in its forwarding table by binding incoming packets, coming from a specific port with a specific label, to outcoming packets, going out of a specific port with a specific label.
Labels can be assigned in two ways:
* statically: network manager sets LSPs manually, like permanent virtual circuits (PVC) in connection-oriented technologies like ATM → this solution does not scale and limits the interoperability among different service providers;
* dynamically: label binding, distribution and mapping are performed automatically by LSRs without manual intervention:
** data-driven: the creation of an LSP is triggered by the reception of data packets, and each LSR autonomously chooses labels based on the traffic;
** control-driven: at some point the LSR assigns a label, even if there is no traffic;
** topology-driven (or protocol-driven): whenever a new destination is discovered, an LSP is created towards this destination → no traffic engineering: the network works exactly like an IP network;
** explicit: the creation of LPSs, usually initiated by label edge routers either data-driven or by manual configuration, is performed through explicit signaling.

## Protocols
### Label distribution protocols

Three protocols, incompatible to each other, can be used by the downstream node in order to communicate to the upstream node the label bindings:
* Label Distribution Protocol (LDP): designed specifically for label distribution;
* extended Border Gateway Protocol (BGP): the downstream node includes in BGP routing messages, used to advertise new destinations, a new field that tells the upstream node the chosen labels (only for protocol-driven label binding);
* extended Resource Reservation Protocol (RSVP): the downstream node includes in RSVP messages, used to notify the traffic types of packet flows for quality of service, a new field that tells the upstream node the chosen labels: Computer network technologies and services/Quality of service.

### Routing protocols

The traditional routing protocols can be enhanced to support traffic engineering because they carry information about routing constraints.
Thanks to routing protocols such as OSPF-TE and IS-IS-TE (based on OSPF, IS-IS, BGP-4), every node can collect information about the network topology in order to know which nodes are its upstream nodes to be notified with the label bindings.
There are two possible routing strategies:
* hop-by-hop (as it is in IP routing): distributed routing protocol where each LSR decides by itself according to the shortest path criterion, so it may happen that all routers choose the same path → risk of congestion;
* explicit (possibility of constraint-based routing): centralized routing protocol where the egress LSRs are advertised to understand which links are currently the most loaded ones and choose the least loaded links for creating new LSPs so that they are disjointed as much as possible from other paths.
    In order to support explicit routing, the basic distribution labels should be extended:
   * Constraint-based Routing LDP (CR-LDP) is an extension to LDP;
   * RSVP for Traffic Engineering (RSVP-TE) is an extension to RSVP.

## References

* ↑ An overhead is required to keep available two LSPs for the same FEC.