I actually started this CoS series a while back, then got sidetracked by other labs and random detours and stopped after the first part. The first post was Junos QoS: Policing Customer Traffic, where two customers were rate-limited on the ingress interfaces of PE-1.
This is the second part of that lab. The policing from the first session is still there. This session adds the next CoS layer on top of it. We are going to teach PE-1 to read the DSCP value of incoming packets, map it to an internal forwarding class, and then rewrite the DSCP value again when the traffic leaves toward the sink. So classification is the decision the router makes on ingress, and rewrite is the value the router stamps back on egress.
Overview
The lab runs on one vMX router and three Linux hosts in PNETLab. HOST-1 and HOST-2 are the customer sources. HOST-3 is the sink where the traffic ends.
The order inside PE-1 for a packet coming from a customer is:
| Stage | What happens |
|---|---|
| Ingress interface | Receives customer traffic. |
| Classifier | Reads DSCP, assigns forwarding-class + loss-priority. |
| Policer | Checks rate against the customer limit. |
| Forwarding decision | Selects the egress path toward ge-0/0/2. |
| Scheduler | Uses forwarding-class for egress queuing decisions. |
| Rewrite | Stamps outgoing DSCP based on forwarding-class. |
| Egress interface | Sends traffic toward HOST-3. |
In a real network you do not trust the DSCP values the customer sends. You classify the traffic on your own terms at the edge and rewrite the marking on the way out, so the rest of the network sees the value you decided, not the value the customer chose.
Step 1: Define the Forwarding Classes
First we configure the forwarding classes. We define classes from 0 through 3. The queue numbers matter in session 3, in this lab they are only labels.
set class-of-service forwarding-classes class be queue-num 0set class-of-service forwarding-classes class ef queue-num 1set class-of-service forwarding-classes class af queue-num 2set class-of-service forwarding-classes class nc queue-num 3This does not change live traffic by itself. It only creates the internal names that the classifier and the rewrite rule are going to reference.
Step 2: Configure the DSCP Classifier
The classifier teaches PE-1 how to read the incoming DSCP values. The first line imports the default DSCP mappings, then only the values needed for this lab are overridden.
set class-of-service classifiers dscp dscp-classifier import defaultset class-of-service classifiers dscp dscp-classifier forwarding-class ef loss-priority low code-points efset class-of-service classifiers dscp dscp-classifier forwarding-class af loss-priority low code-points af41set class-of-service classifiers dscp dscp-classifier forwarding-class nc loss-priority low code-points [cs3 af31]set class-of-service classifiers dscp dscp-classifier forwarding-class be loss-priority high code-points beConfiguration details:
| Code-point | Forwarding class | Loss priority | Queue |
|---|---|---|---|
ef (46) | ef | low | 1 |
af41 (34) | af | low | 2 |
cs3 (24), af31 (26) | nc | low | 3 |
be (0) | be | high | 0 |
The import default statement brings in all the default DSCP-to-class mappings, so any value that is not listed above still gets a class instead of being unclassified. Without the import default an unmapped DSCP value would not have a forwarding class. We mark be with high loss priority on purpose. Best-effort is the traffic that should be dropped first when the link is congested.
Step 3: Apply the Classifier to the Customer Interfaces
The classifier only makes sense on ingress, where the customer traffic arrives. It is applied at the logical unit level on the two customer-facing interfaces.
set class-of-service interfaces ge-0/0/0 unit 0 classifiers dscp dscp-classifierset class-of-service interfaces ge-0/0/1 unit 0 classifiers dscp dscp-classifierStep 4: Configure the DSCP Rewrite Rule
The rewrite rule decides which DSCP value leaves PE-1 toward HOST-3, based on the forwarding class the packet ended up in.
set class-of-service rewrite-rules dscp dscp-rewrite forwarding-class ef loss-priority low code-point efset class-of-service rewrite-rules dscp dscp-rewrite forwarding-class af loss-priority low code-point af41set class-of-service rewrite-rules dscp dscp-rewrite forwarding-class nc loss-priority low code-point cs3set class-of-service rewrite-rules dscp dscp-rewrite forwarding-class be loss-priority low code-point beset class-of-service rewrite-rules dscp dscp-rewrite forwarding-class be loss-priority high code-point beTraffic that comes in as AF31 is classified into nc and the rewrite stamps it back out as CS3. So the value that leaves is not the value that arrived. So instead of using what the customer marks the traffic as, we rewrite our own.
Step 5: Apply the Rewrite Rule to the Egress Interface
The rewrite goes on ge-0/0/2, because that is the interface facing the sink. It is applied at the logical unit level.
set class-of-service interfaces ge-0/0/2 unit 0 rewrite-rules dscp dscp-rewriteStep 6: Verify Classification and Rewriting
On the vMX show interfaces queue ge-0/0/2 reports queue statistics as not applicable. Because of that queue counters cannot be used. Instead we will use show class-of-service interface to confirm the policy is bound, and tcpdump on HOST-3 to read the actual bits on the wire.
First confirm the bindings on PE-1:
show class-of-service interface ge-0/0/0show class-of-service interface ge-0/0/2
On ge-0/0/0 the classifier dscp-classifier is bound on ingress. On ge-0/0/2 the rewrite rule dscp-rewrite is bound on egress.
For the exact markings we will use ping -Q with a raw ToS byte. One thing to keep in mind is DSCP and ToS are not the same number. ToS is the full byte and DSCP is the top six bits, so the ToS value is the DSCP value shifted left by two.
| DSCP alias | DSCP | ToS in (hex) | Forwarding class | ToS out (hex) |
|---|---|---|---|---|
be | 0 | 0x00 | be | 0x00 |
af41 | 34 | 0x88 | af | 0x88 |
ef | 46 | 0xb8 | ef | 0xb8 |
af31 | 26 | 0x68 | nc | 0x60 (cs3) |
On HOST-3, start the capture:
tcpdump -i ens4 -n -vvv icmpFrom HOST-1, send one short test per marking:
ping -Q 0x00 -c 3 172.16.3.2 # be, should stay 0x00ping -Q 0x88 -c 3 172.16.3.2 # af41, should stay 0x88ping -Q 0xb8 -c 3 172.16.3.2 # ef, should stay 0xb8ping -Q 0x68 -c 3 172.16.3.2 # af31 in, should leave as cs3 0x60
The last test is the only useful one actually. The packet enters with AF31 (0x68) and arrives on HOST-3 as CS3 (0x60). This test proves both halves of the pipeline. The classifier on ge-0/0/0 mapped AF31 into nc, and the rewrite rule on ge-0/0/2 stamped CS3 on the way out.
How It Works
If we follow one packet from HOST-1 to HOST-3. Say HOST-1 sends a packet marked AF31.
- The packet arrives on
ge-0/0/0, the customer ingress interface. - The classifier
dscp-classifierreads the DSCP value. AF31 is in thenclist, so the packet is assigned the forwarding classncwith low loss priority. From here the router works with the class, not with the original DSCP bits. - The policer checks the rate on the same interface. If the customer is inside the limit, the packet passes.
- PE-1 makes the forwarding decision and sends the packet toward
ge-0/0/2, because HOST-3 is on that interface. - The rewrite rule
dscp-rewritelooks at the forwarding classncand stamps the DSCP value CS3 into the header. - The packet leaves
ge-0/0/2toward HOST-3 carrying CS3 (0x60), not the AF31 (0x68) it came in with.
- The forwarding class is the internal label. It carries the decision through the router and it is not written in the packet.
- The classifier maps an ingress DSCP value to a forwarding class. It runs on the customer interfaces.
- The rewrite rule maps a forwarding class back to a DSCP value on egress. It runs on the interface facing the sink.
