LDP
CLI reference:/mpls/ldp/mpls/ldp/interface/mpls/ldp/neighbor/mpls/ldp/local-mapping/mpls/ldp/remote-mapping/mpls/forwarding-table/mpls/ldp/advertise-filter/mpls/ldp/accept-filter
RouterOS implements the Label Distribution Protocol (LDP, RFC 5036 and RFC 7552) for IPv4 and IPv6. LDP routers (label switching routers, LSRs) exchange labels for the routes in their routing tables and so build label switched paths (LSPs) along the paths of the routing protocol. See MPLS for how label switching works.
Prerequisites for MPLS
Loopback address
Give every router of the MPLS network a loopback address: a /32 address on the built-in lo interface, which
does not depend on the state of any physical interface. Use it as the LSR ID and as the LDP transport address.
It is not a strict requirement, but:
- Two routers have one LDP session, no matter how many links connect them. With the loopback address as the transport address, the session does not depend on the state or the addresses of one link.
- With the loopback address as the transport address, penultimate hop popping works as intended when a packet carries several labels, as with VPLS.
/ip/address
add address=10.255.255.1/32 interface=lo
IP connectivity
LDP distributes labels for active routes, so IP routing must work first. By default, LDP distributes labels for active IGP routes: connected, static and routes learned from routing protocols, except BGP. Configure the IGP as described on its own page, for example OSPF or static routes. LDP supports ECMP routes.
Before you configure LDP, check that each router reaches the loopback address of every other router, with a ping or a traceroute from loopback address to loopback address.
Example setup
The example builds LDP on a chain of four routers. Each router has a loopback address 10.255.255.N, and OSPF runs on the links and announces the loopback addresses.
graph LR
R1["<b>R1</b><br/>lo 10.255.255.1"]
R2["<b>R2</b><br/>lo 10.255.255.2"]
R3["<b>R3</b><br/>lo 10.255.255.3"]
R4["<b>R4</b><br/>lo 10.255.255.4"]
R1 ---|"ether2 - ether2<br/>10.0.12.0/30"| R2
R2 ---|"ether3 - ether2<br/>10.0.23.0/30"| R3
R3 ---|"ether3 - ether2<br/>10.0.34.0/30"| R4
IP reachability
The IP and OSPF configuration of the four routers:
R1
/ip/address
add address=10.255.255.1/32 interface=lo
add address=10.0.12.1/30 interface=ether2
/routing/ospf/instance
add name=ospf-v2 router-id=10.255.255.1
/routing/ospf/area
add name=backbone instance=ospf-v2
/routing/ospf/interface-template
add area=backbone interfaces=ether2 type=ptp
add area=backbone interfaces=lo passive
R2
/ip/address
add address=10.255.255.2/32 interface=lo
add address=10.0.12.2/30 interface=ether2
add address=10.0.23.1/30 interface=ether3
/routing/ospf/instance
add name=ospf-v2 router-id=10.255.255.2
/routing/ospf/area
add name=backbone instance=ospf-v2
/routing/ospf/interface-template
add area=backbone interfaces=ether2,ether3 type=ptp
add area=backbone interfaces=lo passive
R3
/ip/address
add address=10.255.255.3/32 interface=lo
add address=10.0.23.2/30 interface=ether2
add address=10.0.34.1/30 interface=ether3
/routing/ospf/instance
add name=ospf-v2 router-id=10.255.255.3
/routing/ospf/area
add name=backbone instance=ospf-v2
/routing/ospf/interface-template
add area=backbone interfaces=ether2,ether3 type=ptp
add area=backbone interfaces=lo passive
R4
/ip/address
add address=10.255.255.4/32 interface=lo
add address=10.0.34.2/30 interface=ether2
/routing/ospf/instance
add name=ospf-v2 router-id=10.255.255.4
/routing/ospf/area
add name=backbone instance=ospf-v2
/routing/ospf/interface-template
add area=backbone interfaces=ether2 type=ptp
add area=backbone interfaces=lo passive
Check that the loopback addresses are reachable, for example from R4 to R1:
[admin@MikroTik] > /tool/traceroute 10.255.255.1 src-address=10.255.255.4 count=3
Columns: ADDRESS, LOSS, SENT, LAST, AVG, BEST, WORST, STD-DEV
# ADDRESS LOSS SENT LAST AVG BEST WORST STD-DEV
0 10.0.34.1 0% 3 0.5ms 0.5 0.5 0.5 0
1 10.0.23.1 0% 3 0.7ms 0.7 0.7 0.7 0
2 10.255.255.1 0% 3 1.2ms 1.2 1.1 1.2 0
LDP setup
Enable LDP on the interfaces that connect to other LDP routers. Do not enable it on interfaces that connect to customer networks. On R1:
/mpls/ldp
add afi= lsr-id=10.255.255.1 transport-addresses=10.255.255.1
/mpls/ldp/interface
add interface=ether2
With transport-addresses=10.255.255.1, the router opens LDP sessions from this address and advertises
it to LDP neighbors as its transport address.
R2:
/mpls/ldp
add afi= lsr-id=10.255.255.2 transport-addresses=10.255.255.2
/mpls/ldp/interface
add interface=ether2
add interface=ether3
R3:
/mpls/ldp
add afi= lsr-id=10.255.255.3 transport-addresses=10.255.255.3
/mpls/ldp/interface
add interface=ether2
add interface=ether3
R4:
/mpls/ldp
add afi= lsr-id=10.255.255.4 transport-addresses=10.255.255.4
/mpls/ldp/interface
add interface=ether2
Check the LDP sessions and labels
When the sessions are up, R2 has two LDP neighbors. The O flag marks an operational session. The p flag
marks the neighbor for which this router has the passive role: of two neighbors, the one with the higher
transport address opens the TCP connection. The addresses list holds all addresses of the neighbor, also
those of interfaces that do not run LDP, such as a management interface in 192.168.99.0/24.
[admin@MikroTik] > /mpls/ldp/neighbor/print
Flags: D - DYNAMIC; O - OPERATIONAL; p - PASSIVE
Columns: TRANSPORT, LOCAL-TRANSPORT, PEER, ADDRESSES
# TRANSPORT LOCAL-TRANSPORT PEER ADDRESSES
0 DO 10.255.255.1 10.255.255.2 10.255.255.1:0 10.0.12.1
10.255.255.1
192.168.99.1
1 DOp 10.255.255.3 10.255.255.2 10.255.255.3:0 10.0.23.2
10.0.34.1
10.255.255.3
192.168.99.3
The local mapping table shows which label the router assigned to each route and to which peers it
advertised the binding. The router advertises the implicit null label (impl-null) for its own connected
networks. Each print in this section is limited to the networks of the example:
[admin@MikroTik] > /mpls/ldp/local-mapping/print where dst-address in 10.0.0.0/8
Flags: I - INACTIVE; D - DYNAMIC; E - EGRESS; G - GATEWAY; L - LOCAL
Columns: VRF, DST-ADDRESS, LABEL, PEERS
# VRF DST-ADDRESS LABEL PEERS
0 IDE L main 10.0.12.0/30 impl-null 10.255.255.1:0
10.255.255.3:0
1 IDE L main 10.0.23.0/30 impl-null 10.255.255.1:0
10.255.255.3:0
2 D G main 10.0.34.0/30 16 10.255.255.1:0
10.255.255.3:0
3 D G main 10.255.255.1 17 10.255.255.1:0
10.255.255.3:0
4 IDE L main 10.255.255.2 impl-null 10.255.255.1:0
10.255.255.3:0
5 D G main 10.255.255.3 18 10.255.255.1:0
10.255.255.3:0
6 D G main 10.255.255.4 19 10.255.255.1:0
10.255.255.3:0
The remote mapping table shows the labels that neighbors assigned to routes and advertised to this router:
[admin@MikroTik] > /mpls/ldp/remote-mapping/print where dst-address in 10.0.0.0/8
Flags: I - INACTIVE; D - DYNAMIC
Columns: VRF, DST-ADDRESS, NEXTHOP, LABEL, PEER
# VRF DST-ADDRESS NEXTHOP LABEL PEER
0 ID main 10.255.255.2 18 10.255.255.1:0
1 D main 10.255.255.1 10.0.12.1 impl-null 10.255.255.1:0
2 ID main 10.255.255.3 19 10.255.255.1:0
3 ID main 10.255.255.4 20 10.255.255.1:0
4 ID main 10.0.12.0/30 impl-null 10.255.255.1:0
5 ID main 10.0.23.0/30 16 10.255.255.1:0
6 ID main 10.0.34.0/30 17 10.255.255.1:0
7 ID main 10.0.12.0/30 16 10.255.255.3:0
8 ID main 10.0.23.0/30 impl-null 10.255.255.3:0
9 D main 10.0.34.0/30 10.0.23.2 impl-null 10.255.255.3:0
10 ID main 10.255.255.2 18 10.255.255.3:0
11 ID main 10.255.255.1 17 10.255.255.3:0
12 D main 10.255.255.3 10.0.23.2 impl-null 10.255.255.3:0
13 D main 10.255.255.4 10.0.23.2 19 10.255.255.3:0
R2 received label bindings for all routes from both neighbors, R1 and R3 (liberal label retention). A remote mapping is active only when the neighbor that advertised it is the next hop of the route. For example, the route to 10.255.255.4 goes through 10.0.23.2 (R3):
[admin@MikroTik] > /ip/route/print where dst-address=10.255.255.4/32
Flags: D - DYNAMIC; A - ACTIVE; o - OSPF
Columns: DST-ADDRESS, GATEWAY, ROUTING-TABLE, DISTANCE
DST-ADDRESS GATEWAY ROUTING-TABLE DISTANCE
DAo 10.255.255.4/32 10.0.23.2%ether3 main 110
So the only active mapping for 10.255.255.4 is the one from R3, with label 19 (entry 13). When R2 routes traffic to 10.255.255.4, it adds label 19.
The forwarding table holds the label switching rules:
[admin@MikroTik] > /mpls/forwarding-table/print
Flags: L - LDP
Columns: LABEL, VRF, PREFIX, NEXTHOPS
# LA VRF PREFIX NEXTHOPS
0 L 17 main 10.255.255.1 { label=impl-null; nh=10.0.12.1; interface=ether2 }
1 L 16 main 10.0.34.0/30 { label=impl-null; nh=10.0.23.2; interface=ether3 }
2 L 18 main 10.255.255.3 { label=impl-null; nh=10.0.23.2; interface=ether3 }
3 L 19 main 10.255.255.4 { label=19; nh=10.0.23.2; interface=ether3 }
Entry 3 says that when R2 receives a packet with label 19, it replaces the label with label 19 (assigned by R3) and sends the packet to R3. Labels do not have to be unique along a path: each router assigns its labels on its own.
For 10.255.255.3, the outgoing label is impl-null. R3 is the egress router for its own loopback address:
the traffic ends on R3 and needs no label there, so R3 advertises the implicit null label for it. The
implicit null label tells R2 to send traffic for 10.255.255.3 to R3 without a label. In the same way, R3
sends traffic for 10.255.255.4 to R4 without a label.
When a router removes the label instead of replacing it with a real label, it does penultimate hop popping. The egress router then does not have to look up a label for a packet that it routes anyway.
To keep the label up to the egress router, set use-explicit-null=yes on the LDP instance of the egress
router and restart its LDP instance. The router then advertises the explicit null label for its own
networks instead of the implicit null label: expl-null (label 0) for IPv4 networks and expl-null6
(label 2) for IPv6 networks.
Use traceroute in MPLS networks
RFC 4950 adds MPLS extensions to ICMP: an ICMP message can carry the label stack that was on the packet that caused it. The ICMP messages of interest for MPLS are Time Exceeded and Fragmentation Needed.
A label carries a TTL field as well as the label value. With propagate-ttl=yes in
/mpls/settings (the default), a router that adds a label to an IP
packet copies the IP TTL to the label, and the router that removes the last label copies the label TTL back
to the IP header. A traceroute that supports the MPLS extension therefore shows the routers inside the MPLS
network and the labels they received. The traceroute from R1 to R4:
[admin@MikroTik] > /tool/traceroute 10.255.255.4 src-address=10.255.255.1 count=3
Columns: ADDRESS, LOSS, SENT, LAST, AVG, BEST, WORST, STD-DEV, STATUS
# ADDRESS LOSS SENT LAST AVG BEST WORST STD-DEV STATUS
0 10.0.12.2 0% 3 1.4ms 1.3 1.3 1.4 0 <MPLS:L=19,E=0>
1 10.0.23.2 0% 3 1.1ms 1.1 1.1 1.2 0 <MPLS:L=19,E=0>
2 10.255.255.4 0% 3 1ms 1.1 1 1.3 0.1
The STATUS column shows the labels that were on the packet when it caused the ICMP Time Exceeded message. R2 received the probe with label 19, the label it advertised for 10.255.255.4. R3 also received label 19, because R2 replaced label 19 with label 19. R4 received the probe without a label, because R3 did penultimate hop popping.
With propagate-ttl=no on the ingress router, it does not copy the IP TTL to the label, and the
traceroute shows only the destination.
ICMP errors are label-switched
A router that produces an ICMP error for a labeled packet does not route the error back to the source of the packet. In an MPLS network, the router can have no route to that source, for example with asymmetric LSPs or with MPLS VPN traffic. Instead, the router sends the ICMP error further along the LSP of the original packet. The router at the end of the LSP routes the error back to the source.
As a result, a traceroute in an MPLS network does not find the point of a failure the way it does in an IP network. If the LSP is broken anywhere after the router that produced the error, or the end of the LSP cannot route the error back to the source, no ICMP reply comes back from that hop.
Optimize label distribution
Label binding filters
Not all label bindings of the example are necessary. For example, R1 and R3 never use each other's IP route bindings. If the MPLS network only connects customer Ethernet segments with VPLS, the bindings for the links between the routers are not needed either. The routes that matter are the /32 routes to the tunnel endpoints and the customer networks.
Label binding filters reduce the bindings the routers distribute, and with them the resource usage and the network load. RouterOS has two filter lists:
/mpls/ldp/advertise-filter: which label bindings the router advertises to LDP neighbors./mpls/ldp/accept-filter: which label bindings the router accepts from LDP neighbors.
Each list is ordered. A rule matches a binding when the rule's prefix includes the binding's prefix, and when the rule's neighbor matches (no neighbor matches all neighbors). A binding that matches no rule is advertised or accepted.
In the example, all routers can advertise only the bindings for the loopback addresses, which reach the tunnel endpoints. Add these two rules on all routers:
/mpls/ldp/advertise-filter
add prefix=10.255.255.0/24 advertise=yes
add prefix=0.0.0.0/0 advertise=no
The first rule advertises the bindings for routes inside 10.255.255.0/24, which holds the loopback addresses. The second rule is necessary because a binding that matches no rule is advertised. No accept filter is needed: no router advertises the other bindings.
Filter changes do not affect the mappings that the neighbors already have. To apply the filters, restart the LDP sessions by disabling and enabling the LDP instance on each router where you changed the filters. Dynamic neighbors cannot be removed from the neighbor table.
/mpls/ldp/disable [find]
/mpls/ldp/enable [find]
Then the remote mapping table of R2 holds only the loopback addresses:
[admin@MikroTik] > /mpls/ldp/remote-mapping/print where dst-address in 10.0.0.0/8
Flags: I - INACTIVE; D - DYNAMIC
Columns: VRF, DST-ADDRESS, NEXTHOP, LABEL, PEER
# VRF DST-ADDRESS NEXTHOP LABEL PEER
14 ID main 10.255.255.2 16 10.255.255.1:0
15 D main 10.255.255.1 10.0.12.1 impl-null 10.255.255.1:0
16 ID main 10.255.255.3 17 10.255.255.1:0
17 ID main 10.255.255.4 18 10.255.255.1:0
18 ID main 10.255.255.2 17 10.255.255.3:0
19 ID main 10.255.255.1 16 10.255.255.3:0
20 D main 10.255.255.3 10.0.23.2 impl-null 10.255.255.3:0
21 D main 10.255.255.4 10.0.23.2 18 10.255.255.3:0
LDP on IPv6 and dual-stack links
RouterOS implements RFC 7552 for LDP on dual-stack links. The LDP
instance selects the supported address families (AFIs) with afi, and each LDP interface can limit them
further with its own afi.
The following command lets the instance of R1 use IPv4 and IPv6, prefers IPv6 for the session, and adds an IPv6 loopback address as a second transport address. The IPv6 loopback addresses must be reachable over IPv6 routing, as the IPv4 ones are over IPv4 routing.
/mpls/ldp
set [find] afi=, preferred-afi= \
transport-addresses=10.255.255.1,fd00::1
When both neighbors are configured this way, the session uses the IPv6 transport addresses and the routers
exchange labels for IPv4 and IPv6 routes. In /mpls/ldp/neighbor, the used-afi field shows both families.
An LDP interface with afi=ip sends only IPv4 hellos. A neighbor on that link that prefers IPv6 then
sets up an IPv4 session after a delay (meanwhile the neighbor can show the T flag, throttled), and the
routers exchange only IPv4 labels: used-afi shows ip. Use the same AFI settings on both ends of a link.
The rest of this section describes how RouterOS selects the address family.
The router sends hellos as follows:
- If an interface has only one AFI:
- The router does not send the dual-stack element.
- The router sends hellos only if the interface has an IP address of that AFI.
- If an interface has both AFIs:
- The router always sends the dual-stack element, with the value of
preferred-afi. - The router sends hellos for each AFI for which the interface has an address.
- The router always sends the dual-stack element, with the value of
From the received hellos, the peer decides which AFI to use for the connection and for which AFIs to bind and send labels. To use an AFI, LDP must receive a hello of that AFI: the hello carries the transport address. The active and passive roles follow from the received transport addresses.
The router receives and processes hellos as follows:
- If the LDP instance has only one AFI (all interfaces can use only that AFI):
- It drops hellos of other AFIs.
- It ignores the dual-stack element.
- It determines the role and sends labels for that AFI only.
- If the LDP instance has both AFIs (interfaces can have different combinations of AFIs):
- It drops hellos of AFIs that the interface does not support.
- It ignores the dual-stack element if the interface supports only one AFI.
- It drops the hello if the preference in the received dual-stack element does not match its own
preferred-afi.
If the hellos change, the router ends the existing session only if the address family used for labels changes.
The router sets the dual-stack element only on an interface that supports both AFIs:
- Such an interface should receive hellos of both AFIs:
- LDP waits for a hello of the preferred AFI before it continues.
- If it receives hellos of only one AFI:
- If the missing hello is of the preferred AFI, it is an error.
- Otherwise, LDP waits for the missing hello for three hello intervals:
- If the hello arrives in that time, the peer is dual-stack.
- If it does not arrive, the peer is single-stack.
- If it arrives later, LDP restarts the session.
- The dual-stack element tells the peer that LDP wants to distribute labels for both AFIs.
With preferred-afi=ipv6, the received hellos (IPv4, IPv6, with or without the dual-stack element ds6)
lead to these results:
- ipv4: wait three hello intervals. Without changes, use an IPv4 session and distribute IPv4 labels.
- ipv4+ds6: wait for the IPv6 hello, because the dual-stack element says that IPv6 is coming.
- ipv6: wait three hello intervals. Without changes, use an IPv6 session and distribute IPv6 labels.
- ipv6+ds6: use an IPv6 session and distribute IPv6 labels.
- ipv4,ipv6: use an IPv6 session and distribute IPv4 and IPv6 labels.
- ipv4,ipv6+ds6: use an IPv6 session and distribute IPv4 and IPv6 labels.
All LDP parameters are described in the LDP CLI reference.