>_nexthopreachable

Classifying and Marking Customer Traffic with Junos CoS

Ali Bahadır Coşkun7 min read

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.

CoS lab topology

The order inside PE-1 for a packet coming from a customer is:

StageWhat happens
Ingress interfaceReceives customer traffic.
ClassifierReads DSCP, assigns forwarding-class + loss-priority.
PolicerChecks rate against the customer limit.
Forwarding decisionSelects the egress path toward ge-0/0/2.
SchedulerUses forwarding-class for egress queuing decisions.
RewriteStamps outgoing DSCP based on forwarding-class.
Egress interfaceSends 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.

junos
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 3

This 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.

junos
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 be

Configuration details:

Code-pointForwarding classLoss priorityQueue
ef (46)eflow1
af41 (34)aflow2
cs3 (24), af31 (26)nclow3
be (0)behigh0

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.

junos
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-classifier

Step 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.

junos
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 be

Traffic 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.

junos
set class-of-service interfaces ge-0/0/2 unit 0 rewrite-rules dscp dscp-rewrite

Step 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:

text
show class-of-service interface ge-0/0/0show class-of-service interface ge-0/0/2
show class-of-service interface on PE-1: classifier on ingress, rewrite on egress

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 aliasDSCPToS in (hex)Forwarding classToS out (hex)
be00x00be0x00
af41340x88af0x88
ef460xb8ef0xb8
af31260x68nc0x60 (cs3)

On HOST-3, start the capture:

bash
tcpdump -i ens4 -n -vvv icmp

From HOST-1, send one short test per marking:

bash
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
tcpdump on HOST-3 showing the rewritten ToS bytes

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.

  1. The packet arrives on ge-0/0/0, the customer ingress interface.
  2. The classifier dscp-classifier reads the DSCP value. AF31 is in the nc list, so the packet is assigned the forwarding class nc with low loss priority. From here the router works with the class, not with the original DSCP bits.
  3. The policer checks the rate on the same interface. If the customer is inside the limit, the packet passes.
  4. PE-1 makes the forwarding decision and sends the packet toward ge-0/0/2, because HOST-3 is on that interface.
  5. The rewrite rule dscp-rewrite looks at the forwarding class nc and stamps the DSCP value CS3 into the header.
  6. The packet leaves ge-0/0/2 toward 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.