Label Distribution Protocol (LDP)

Published 2022-01-02 | Updated 2022-10-16


A popular protocol that enables MPLS in your network. While OSPF and IS-IS advertise prefixes to the neighboring routers, LDP advertises labels for those prefixes allowing the packets to be MPLS encapsulated. LDP has two modes, discussed below.

  • Targeted LDP

This session is setup between two routers to exchange label mapping information. This session is established over TCP port 646 between two loopback addresses.

  • Discovery LDP

When LDP is enabled on an interface, the router begin sending LDP Discovery Hello packets to multicast address 224.0.0.2 over UDP port 646. This Hello packet includes the local router ID. Once such a hello packet is received, a targeted LDP session can be established. On Cisco IOS, LDP Discovery is enabled with the mpls ip interface command.

Let's say R1 (1.1.1.1) and R2 (2.2.2.2) are directly connected with OSPF and LDP activated on the R1-R2 interface. R2 will receive the LDP Discovery hello packet from R1 and initialize a targeted LDP session towards 1.1.1.1 sourced from 2.2.2.2. The adjacency will form and they will exchange label mapping messages and populate their respective MPLS forwarding tables.

Note that R1 must advertise the 1.1.1.1/32 route to R2 and R2 must advertise 2.2.2.2/32 to R1, otherwise the targeted LDP session cannot establish properly due to routing lookup failure.

Internet Protocol Version 4, Src: 10.1.2.1, Dst: 224.0.0.2User Datagram Protocol, Src Port: 646, Dst Port: 646Label Distribution Protocol    LSR ID: 1.1.1.1    Hello Message

Internet Protocol Version 4, Src: 2.2.2.2, Dst: 1.1.1.1Transmission Control Protocol, Src Port: 59670, Dst Port: 646Label Distribution Protocol    LSR ID: 2.2.2.2    Address Message        Address 1: 10.1.2.2        Address 2: 2.2.2.2    Label Mapping Message        Prefix: 10.1.2.0        Label: 3    Label Mapping Message        Prefix: 2.2.2.2        Label: 3    Label Mapping Message        Prefix: 1.1.1.1        Generic Label: 16

To conclude, LDP Discovery is used simply to announce the local router ID to directly connected neighbors, allowing a Targeted LDP session to establish.

LDP Session Protection

By entering the command mpls ldp session protection, a targeted LDP session is setup between R1 and R2. The main benefit of the targeted LDP session is that it can be kept alive even if the R1-R2 link goes down, assuming a redundant path (via R3 and R4) is available. Once the R1-R2 link comes back up it can be used immediately because the label mapping information was never lost. Additionally, if there are multiple R1-R2 links only one LDP session is necessary as the advertised labels are not mapped to a specific interface.

The command "show mpls ldp neighbor" output shows how the LDP session changes:

R1#show mpls ldp neigh    Peer LDP Ident: 2.2.2.2:0; Local LDP Ident 1.1.1.1:0        TCP connection: 2.2.2.2.20237 - 1.1.1.1.646        State: Oper; Msgs sent/rcvd: 19/19; Downstream        Up time: 00:04:41        LDP discovery sources:          Ethernet0/0, Src IP addr: 10.1.2.2R1#conf tR1(config)#mpls ldp session protectionR1(config)#endR1#show mpls ldp neigh    Peer LDP Ident: 2.2.2.2:0; Local LDP Ident 1.1.1.1:0        TCP connection: 2.2.2.2.12695 - 1.1.1.1.646        State: Oper; Msgs sent/rcvd: 12/10; Downstream        Up time: 00:00:10        LDP discovery sources:          Targeted Hello 1.1.1.1 -> 2.2.2.2, active, passive

LDP IGP synchronization

By default the LDP-IGP advertising processes are not synchronized. A label can be sent for a prefix that has not yet been advertised by the IGP. Even worse, the IGP may advertise a prefix before LDP has had a chance to advertise a label for it, potentially blackholing traffic by unintentionally stripping MPLS labels.

To avoid traffic blackholing, you can configure your IGP to behave in a more synchronized way. In Cisco IOS the magic command is mpls ldp sync under the OSPF or IS-IS router process. On an interface where the IGP and LDP is enabled but only IGP has an adjacency, the IGP will advertise its routes with the highest possible metric. The neighbor will receive the routes but avoid using this link. Once the LDP adjacency has established, IGP readvertises the routes with the correct metrics, allowing the neighbor to start using the link.

LDP Host Route Label Allocation

By default, LDP will advertise a label for every prefix, even the linknets between the routers. The only prefixes that need a label advertised are generally the loopback-prefixes for each router. By restricting which labels to advertise, LDP scalability and convergence is improved. We configure this with the allocate global host-routes command in the mpls ldp label configuration mode, telling LDP to only advertise labels for /32 prefixes.


LDP Signaling

Let's see how LSPs are signalled throughout the network, focusing on the 1.1.1.1/32 LSP advertised by R1:

Looking at the slideshow above, R1 advertises label 3 for prefix 1.1.1.1/32. R2 and R3 generate their own local label and advertises that to their neighbors, R1 and R4. The LSP is fully signalled when R4 has advertised its prefix/label combo to its neighbors. We have now successfully built a MP2P LSP for the 1.1.1.1/32 prefix. Any traffic destined to 1.1.1.1 will enter this LSP when forwarded by R2, R3 or R4.

In practice, only traffic from R4 to 1.1.1.1/32 will be labeled since R2 and R3 was instructed by R1 to pop any label when forwarding. This instruction was sent via the reserved label 3; pop the label before forwarding. This is how PHP is performed. Note that the label advertised by R4 will most likely not be used since R2 and R3 have better paths to R1.

Let's pretend that the R1-R3 link goes down and R3 then send some traffic to R1 via R4 and R2. Using traceroute we can see the labels used at each hop along the path:

R3#traceroute 1.1.1.1 numeric  probe 1  1 10.3.4.4 [MPLS: Label 18 Exp 0] 1 msec  2 10.2.4.2 [MPLS: Label 16 Exp 0] 1 msec  3 10.1.2.1 1 msec

In the traceroute output we can see that R3 pushed label 18 when sending the packet to R4. R4 swapped the label for 16 and forwarded to R2. R2 removed the label and forwarded the native IP packet to R1.

Cisco IOS LDP configuration

This is the configuration used in the topology above to enable LDP and advertise the loopback labels:

mpls ldp session protectionmpls ldp label allocate global host-routes!interface Loopback0 ip address 1.1.1.1 255.255.255.255 ip ospf 1 area 0interface FastEthernet2/0 ip address 10.1.2.1 255.255.255.0 ip ospf 1 area 0 mpls ipinterface FastEthernet3/0 ip address 10.1.3.1 255.255.255.0 ip ospf 1 area 0 mpls ip!router ospf 1 mpls ldp sync!R1#show mpls forwardingLocal      Outgoing   Prefix        Outgoing   Next HopLabel      Label      or Tunnel Id  interface16         Pop Label  2.2.2.2/32    Fa2/0      10.1.2.218         Pop Label  3.3.3.3/32    Fa3/0      10.1.3.320         20         4.4.4.4/32    Fa2/0      10.1.2.2           20         4.4.4.4/32    Fa3/0      10.1.3.3

mpls ldp session protectionmpls ldp label allocate global host-routesinterface Loopback0 ip address 2.2.2.2 255.255.255.255 ip ospf 1 area 0interface FastEthernet1/0 ip address 10.1.2.2 255.255.255.0 ip ospf 1 area 0 mpls ipinterface FastEthernet4/0 ip address 10.2.4.2 255.255.255.0 ip ospf 1 area 0 mpls iprouter ospf 1 mpls ldp syncR2#show mpls forwardingLocal      Outgoing   Prefix        Outgoing   Next HopLabel      Label      or Tunnel Id  interface16         Pop Label  1.1.1.1/32    Fa1/0      10.1.2.118         18         3.3.3.3/32    Fa1/0      10.1.2.1           16         3.3.3.3/32    Fa4/0      10.2.4.420         Pop Label  4.4.4.4/32    Fa4/0      10.2.4.4

mpls ldp session protectionmpls ldp label allocate global host-routesinterface Loopback0 ip address 3.3.3.3 255.255.255.255 ip ospf 1 area 0interface FastEthernet1/0 ip address 10.1.3.3 255.255.255.0 ip ospf 1 area 0 mpls ipinterface FastEthernet4/0 ip address 10.3.4.3 255.255.255.0 ip ospf 1 area 0 mpls iprouter ospf 1 mpls ldp syncR3#show mpls forwardingLocal      Outgoing   Prefix        Outgoing   Next HopLabel      Label      or Tunnel Id  interface16         16         2.2.2.2/32    Fa1/0      10.1.3.1           17         2.2.2.2/32    Fa4/0      10.3.4.417         Pop Label  1.1.1.1/32    Fa1/0      10.1.3.120         Pop Label  4.4.4.4/32    Fa4/0      10.3.4.4

mpls ldp session protectionmpls ldp label allocate global host-routesinterface Loopback0 ip address 4.4.4.4 255.255.255.255 ip ospf 1 area 0interface FastEthernet2/0 ip address 10.2.4.4 255.255.255.0 ip ospf 1 area 0 mpls ipinterface FastEthernet3/0 ip address 10.3.4.4 255.255.255.0 ip ospf 1 area 0 mpls iprouter ospf 1 mpls ldp syncR4#show mpls forwardingLocal      Outgoing   Prefix        Outgoing   Next HopLabel      Label      or Tunnel Id  interface16         Pop Label  3.3.3.3/32    Fa3/0      10.3.4.317         Pop Label  2.2.2.2/32    Fa2/0      10.2.4.218         16         1.1.1.1/32    Fa2/0      10.2.4.2           17         1.1.1.1/32    Fa3/0      10.3.4.3

The command to enable LDP in Cisco IOS is configuring mpls ip under the interface. This triggers LDP Discovery Hello packets which in turn triggers a Targeted LDP session.

The MPLS forwarding table show that labels have been advertised for the router loopbacks and nothing else. Where ECMP is performed, each path has its own label assigned based on the next-hop router.

Conclusion

We have now taken a brief look into the LDP protocol discovery mode triggering a targeted LDP session. We have looked into various LDP knobs to improve resiliency and scalability. Thanks for reading, have a great rest of your day!

Copyright 2021-2026, Emil Boklund.
All Rights Reserved.