EXP bit and MPLS queuing
CLI reference:/mpls/mangle
An MPLS label adds 32 bits (4 bytes) to the packet. The 32 bits are:
- The label value (20 bits).
- The EXP field, "experimental" (3 bits). RFC 5462 renames it to Traffic Class.
- The bottom of stack flag (1 bit).
- The time to live (TTL, 8 bits).
RFC 3032 reserved the EXP bits for experimental use. RFC 3270 defines how they carry Differentiated Services (QoS) information, like the 802.1Q priority in a VLAN tag. The field has 3 bits, so it carries values from 0 to 7: eight traffic classes.
EXP field treatment in RouterOS
RouterOS keeps two marks for each packet it processes: "priority" and "ingress priority". They are not fields in the packet headers. When RouterOS receives an MPLS packet, it sets the ingress priority to the EXP value of the top label. When RouterOS adds a label, it sets the EXP bits to the priority of the packet (not the ingress priority). When RouterOS switches an MPLS packet, it copies the ingress priority to the priority. This way, label switching carries the priority along the whole label switched path.
More on priority and ingress priority is on the WMM and VLAN priority page.
The EXP field depends on what the router does with the packet:
- When RouterOS switches the packet (removes the received label and adds a new one), the new label has the
same EXP value as the received label:
- RouterOS sets the ingress priority to the EXP bits of the received label.
- Switching copies the ingress priority to the priority.
- RouterOS adds the new label with its EXP bits set to the priority.
- When RouterOS switches the packet with penultimate hop popping (it removes the received label and adds no
new one), the EXP value stays in the priority of the packet. Other MAC protocols, such as WMM or 802.1Q
VLAN, can use it. For example, when the next hop is behind a VLAN interface:
- RouterOS sets the ingress priority to the EXP bits of the received label.
- Switching copies the ingress priority to the priority.
- RouterOS sends the packet to the next hop without a label, through the VLAN interface.
- The VLAN interface sets the 802.1Q priority in the VLAN header to the priority of the packet.
- When RouterOS sends a packet into a label switched path (it adds the first label), it sets the EXP bits to the priority. Set the priority with firewall rules, for example from the DSCP field of the IP header.
- When RouterOS receives a packet for local processing, it sets the ingress priority to the EXP field of the received packet. Firewall rules can then use it to set the DSCP field or to set the priority from the ingress priority.
Penultimate hop popping can lose the QoS information of the label switched path at the last hop. To keep it
up to the egress router, use the explicit null label instead of the implicit null label for the last hop
(use-explicit-null=yes on the egress router, see LDP). MPLS TE tunnels use the explicit null
label for the last hop by default.
MPLS mangle and queuing
The IP firewall works only on IP traffic: it cannot mark MPLS packets for queues. Queue IP traffic on the ingress edge router before it adds the label, or on the egress edge router after it removes the label.
/mpls/mangle works on MPLS packets. It matches the EXP bits of
the packet and can add a packet mark, change the EXP bits, or both:
- In the
forwardchain, on label switching (P) routers, for packets the router switches. - In the
outputchain, on edge (PE) routers, for packets the router sends after it added the label.
Mark and rewrite EXP on a P router
In this example R2 is a P router in the LDP example network. It marks the switched packets that
have EXP 0, limits them with a queue tree on its link to R3 (ether3), and changes their EXP to 3:
/mpls/mangle
add chain=forward exp=0 set-exp=3 set-mark=exp0
/queue/tree
add name=mpls-exp0 parent=ether3 packet-mark=exp0 max-limit=800k
MPLS packets cannot be queued with queues that use the global queue (simple queues, or a queue tree with
parent=global): a simple queue with packet-marks=exp0 does not count them. Use a queue tree with an
interface as the parent.
A traceroute from R1 to R4 shows the change: hop 1 is R3, which receives the packets with EXP 3. Hop 0 is R2, which applies the rule. R1 sends the packets with EXP 0, so the EXP value shown for hop 0 is not the value that R2 received. Label values can differ from the outputs on the LDP page, because each router assigns its labels on its own.
[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.2ms 2.4 1.2 4.2 1.3 <MPLS:L=18,E=3>
1 10.0.23.2 0% 3 1.2ms 1.4 1.2 1.7 0.2 <MPLS:L=18,E=3>
2 10.255.255.4 0% 3 1ms 1.1 1 1.1 0
The rule matches the packets that R2 switches in both directions: the ping requests toward R4 and the
replies toward R1. The PACKETS column counts both, and the queue tree counts only the packets it queued
toward R3:
[admin@MikroTik] > /mpls/mangle/print
Columns: CHAIN, EXP, SET-EXP, SET-MARK, PACKETS
# CHAIN EXP SET-EXP SET-MARK PACKETS
0 forward 0 3 exp0 58
[admin@MikroTik] > /queue/tree/print stats
0 name="mpls-exp0" parent=ether3 packet-mark=exp0 rate=3216 packet-rate=6
queued-bytes=0 queued-packets=0 bytes=1756 packets=26 dropped=0
How the rules combine
MPLS mangle rules do not run one after another like IP firewall mangle rules. MPLS mangle applies all actions for an EXP value together, based on the EXP value the packet arrived with. For example:
/mpls/mangle
add chain=forward exp=0 set-mark=m0
add chain=forward exp=0 set-exp=3
add chain=forward exp=3 set-mark=m3
A packet that arrives with EXP 0 gets the mark m0 and EXP 3. The third rule does not apply to it, although
the second rule changed its EXP to 3:
[admin@MikroTik] > /mpls/mangle/print
Columns: CHAIN, EXP, SET-EXP, SET-MARK, PACKETS
# CHAIN EXP SET-EXP SET-MARK PACKETS
0 forward 0 m0 20
1 forward 0 3 20
2 forward 3 m3 0
For each EXP value and chain, only one rule can set each action. A second rule with the same action for the same EXP value fails:
[admin@MikroTik] > /mpls/mangle/add chain=forward exp=0 set-mark=m4
failure: conflicting forward set-mark rule (/mpls/mangle/add; line 1)