QoS Classification and Marking
Learn how to classify and mark network traffic using DSCP, CoS, and ACLs to prioritize critical applications.
1. Executive Summary & Objective
Before a network can effectively prioritize, police, or shape traffic, it must first be able to identify what type of traffic is flowing through its interfaces. Classification and Marking are the fundamental prerequisites of any Quality of Service (QoS) implementation. Classification is the process of inspecting traffic to determine its nature (e.g., Voice, Video, Database), while Marking is the act of embedding a prioritization tag directly into the packet or frame header so that downstream devices can apply policies without needing to re-inspect the traffic deeply.
The primary objective of this module is to deliver a comprehensive technical overview of traffic classification and marking mechanisms across both Layer 2 and Layer 3 of the OSI model. By the conclusion of this lesson, you will possess a strong command of Class of Service (CoS) and Differentiated Services Code Point (DSCP) architectures. You will learn how to configure robust classification boundaries using Network-Based Application Recognition (NBAR) and Access Control Lists (ACLs), and how to mark traffic effectively using Modular QoS CLI (MQC) on Cisco routers as well as MikroTik RouterOS. This foundational knowledge is essential for building scalable QoS trust boundaries across an enterprise network.
2. Core Concept & Theory
The lifecycle of a packet traversing a QoS-enabled network follows a strict sequence: Classify β Mark β Queue β Schedule β Shape/Police. If classification and marking fail, all subsequent queuing and shaping mechanisms are rendered useless because they rely on these marks to distinguish priority levels.
Classification
Classification can occur at multiple layers:
- Layer 2 / 3 Headers: Checking source/destination IP, MAC addresses, or TCP/UDP ports.
- Deep Packet Inspection (DPI): Looking past the headers into the payload to identify specific application signatures (e.g., matching the exact bit pattern of RTP voice payloads or BitTorrent traffic). Ciscoβs NBAR (Network-Based Application Recognition) is a prime example of a DPI engine used for QoS classification.
Marking
Once classified, the router or switch must βcolorβ or mark the traffic. Marking ensures that the deep inspection overhead is only incurred once (usually at the network edge), while core devices simply read the tag and forward appropriately.
Layer 2 Marking: Class of Service (CoS) At Layer 2, marking relies on the 802.1Q VLAN tag, which contains a 3-bit Priority Code Point (PCP) field. This provides 8 distinct priority levels (0 through 7).
- CoS 0 is default (Best Effort).
- CoS 5 is universally standard for Voice payload.
- Limitation: CoS markings are stripped the moment a packet crosses a Layer 3 routing boundary, meaning CoS is only useful within a single LAN or spanning a switched domain.
Layer 3 Marking: Differentiated Services Code Point (DSCP) At Layer 3, marking is placed inside the IPv4/IPv6 header within a 6-bit DSCP field, yielding 64 possible values. Because this marking is in the IP header, it survives routing hops across the globe.
- Expedited Forwarding (EF - Value 46): Strictly for Voice (low latency, jitter, loss).
- Assured Forwarding (AF): Offers varying levels of guaranteed bandwidth and drop precedence (e.g., AF41 for Video, AF21 for Business Apps).
- Class Selector (CS): Maintained for backward compatibility with older IP Precedence markings (e.g., CS3 for Call Signaling).
Trust Boundaries
A critical concept in QoS design is the βTrust Boundary.β It defines the network perimeter where incoming markings are trusted versus overwritten. As a best practice, never trust markings from standard user PCs (they could intentionally mark their torrent traffic as EF). Always move the trust boundary as close to the edge as possibleβsuch as trusting a physical Cisco IP Phone, but overwriting traffic entering from a userβs workstation switch port.
3. Architecture & Topology
Imagine an enterprise campus network spanning a multi-story building.
- Access Layer Switches (Edge): Connected to user PCs, IP Phones, and local printers.
- Distribution/Core Switches: High-throughput switches routing traffic between floors and to the WAN edge.
- WAN Router: The gateway to remote branches.
In this architecture, the Access Layer Switch serves as the strict QoS Trust Boundary.
- When an IP Phone sends voice packets, the Access Switch is configured to trust the CoS 5 / DSCP 46 markings originating from that specific voice VLAN.
- Conversely, when a user PC on the data VLAN sends traffic, the Access Switch is configured to strip any existing DSCP markings (re-marking them to 0 / Best Effort).
- The Access Switch then uses ACLs or NBAR to identify specific critical business applications (e.g., Salesforce CRM web traffic) originating from PCs and marks them with DSCP AF21.
- As packets flow up to the Core Switch and out the WAN Router, these devices do not perform DPI. They are configured simply to trust the DSCP markings applied by the Access Switch, rapidly mapping DSCP EF to priority queues and AF21 to bandwidth-guaranteed queues.
4. Command Execution & Deployment
Deploying classification and marking primarily utilizes the Modular QoS CLI (MQC) on Cisco IOS, which standardizes QoS configuration into Class Maps (Classification), Policy Maps (Marking/Actions), and Service Policies (Application).
Scenario: Marking Voice and Business Apps on Cisco IOS
! Step 1: Define class maps for Classification
! Using NBAR for voice
class-map match-any VOICE-TRAFFIC
match protocol rtp audio
match dscp ef
! Using an ACL for business applications
ip access-list extended BUSINESS-ACL
permit tcp any host 10.0.5.100 eq 443
permit tcp any host 10.0.5.101 eq 8080
class-map match-any BUSINESS-APPS
match access-group name BUSINESS-ACL
! Step 2: Define policy map for Marking
policy-map MARK-TRAFFIC
class VOICE-TRAFFIC
set dscp ef
class BUSINESS-APPS
set dscp af21
class class-default
set dscp default
! Step 3: Apply to interface inbound
interface GigabitEthernet0/0
description Inbound from LAN
service-policy input MARK-TRAFFIC
Scenario: Establishing Trust Boundaries
! Trust DSCP on uplinks to the core
interface GigabitEthernet0/24
mls qos trust dscp
! Re-mark everything on standard access ports (Untrusted)
interface GigabitEthernet0/1
mls qos trust cos
mls qos cos 0
Scenario: Marking Traffic on MikroTik RouterOS
RouterOS utilizes mangle firewall rules to intercept and mark traffic.
/ip firewall mangle
add chain=prerouting protocol=udp dst-port=5060-5061 \
action=set-priority new-priority=5 \
comment="Mark SIP signaling"
add chain=prerouting protocol=udp dst-port=10000-20000 \
action=mark-packet new-packet-mark=voip-rtp passthrough=yes \
comment="Mark RTP voice traffic"
add chain=postrouting packet-mark=voip-rtp \
action=change-dscp new-dscp=46 comment="Set DSCP EF for voice"
5. Verification & Troubleshooting
After applying classification and marking policies, rigorous verification is essential to ensure traffic is hitting the appropriate buckets and receiving the correct DSCP tags.
Verification Commands (Cisco IOS)
- Verify Class Map Configurations:
Router# show class-map
This confirms that the NBAR protocols or ACLs are correctly attached to your class maps.
- Verify Policy Map Actions:
Router# show policy-map
This shows the logical structure of how classes are mapped to marking actions (e.g., set dscp ef).
- Verify Real-Time Marking Statistics: The ultimate validation command.
Router# show policy-map interface GigabitEthernet0/0
What to look for: Look at the pkts matched counter under each class. If you are making a VoIP call or accessing the business server, the counters under VOICE-TRAFFIC or BUSINESS-APPS should rapidly increment. If the traffic is only incrementing under class-default, your classification (ACL or NBAR) is failing to identify the traffic.
Troubleshooting Scenarios
- Traffic bypassing classification: If business app traffic is falling into
class-default, verify the ACL syntax. Ensure the ACL isnβt filtering the wrong direction or missing a port. - Markings lost across WAN: If traffic leaves the router marked as EF but arrives at the remote branch as BE (0), the Service Provider is stripping the markings. You must contact the ISP to ensure they honor your DSCP tags across their MPLS/WAN core.
6. Hands-on: build the classifier in real Python
A QoS policy map is just a classifier that stamps each packet with a DSCP value. Build that logic yourself β classify(app) returns the DSCP mark for a traffic type, then you mark a stream and count the real-time traffic. This runs real Python; click Run, then Check my work.
That classify function is conceptually identical to a Cisco MQC class-map + policy-map: match the traffic, set the DSCP, and everything downstream honours the mark. You just wrote a QoS policy in nine lines.
π§ͺ Want to practise this on your own computer? See how to set up your lab →