Understanding QoS Classification and Marking
Classification serves as the fundamental component of Quality of Service (QoS). With out proper classification, all network traffic would be treated identically, preventing any meaningful QoS policies from being implemented. Network packets can be classified based on various criteria: - Physical interfaces and subinterfaces - Layer 2: MAC addresses, Class of Service (CoS), VLAN IDs - Layer 3: IP precedence, Differentiated Services Code Point (DSCP), source and destination IP addresses - Higher layers: TCP/UDP protocols and application-specific data The most critical considerations typically involve Layer 2 and Layer 3 classification. ### Layer 2 Ethernet Frame Structure
A standard Ethernet frame contains: - Destination MAC (DMAC) - Source MAC (SMAC) - TYPE field (identifies upper layer protocol) The TYPE field indicates the encapsulated protocol: - 0x0800: IP - 0x0806: ARP While these fields don't directly provide marking capabilities, trunk links add VLAN identification through 802.1Q encapsulation. The 802.1Q frame includes a 2-byte tag containing: - 3-bit priority field (User Priority) - 1-bit CFI field - 12-bit VLAN ID The 3-bit priority field allows for 8 different Layer 2 traffic markings (0-7). ### Layer 3 IP Header Marking
The IP header contains an 8-bit ToS (Type of Service) field with the following structure: - First 3 bits: IP Precedence - Next 4 bits: DSCP (when the last 2 bits are set to 0) - Last 1 bit: Unused IP Precedence uses only the first 3 bits, providing 8 possible markings (0-7). DSCP utilizes all 6 bits, offering 64 different marking options. ### QoS Classification Methods
Classification involves identifying and categorizing traffic before applying appropriate markings. This process enables subsequent QoS mechanisms to handle traffic according to its classification. #### Access Control Lists (ACLs)
ACLs represent the most common tool for traffic classification based on Layer 2/3 attributes. #### Network-Based Application Recognition (NBAR)
NBAR provides automatic traffic classification directly on interfaces and offers capabilities beyond traditional ACLs, including deep packet inspection of application-layer traffic. ##### NBAR Configuration Example
Router(config)# class-map traffic_classifier
Router(config-cmap)# match protocol http
Router(config-cmap)# match protocol https
Router(config-cmap)# match protocol ftp
Router(config-cmap)# match protocol sip
Router(config-cmap)# exit
Router(config)# policy-map policy_definition
Router(config-pmap)# class traffic_classifier
Router(config-pmap-c)# set dscp ef
Router(config-pmap-c)# exit
Router(config)# interface GigabitEthernet0/1
Router(config-if)# service-policy output policy_definition
NBAR enables deep packet inspection that ACLs cannot perform, particularly for application-layer traffic. ### Marking Techniques
Class-Based Marking (CBMarking)
CBMarking uses the Modular QoS CLI (MQC) framework for traffic marking. ##### Layer 3 Marking Configuration
Router(config)# class-map http_traffic
Router(config-cmap)# match protocol http
Router(config-cmap)# exit
Router(config)# policy-map qos_policy
Router(config-pmap)# class http_traffic
Router(config-pmap-c)# set ip precedence 5
Router(config-pmap-c)# set dscp af21
Router(config-pmap-c)# exit
Router(config)# interface Serial0/0
Router(config-if)# service-policy output qos_policy
When using DSCP marking, predefined values are available: - 0-63: Custom DSCP values - AF11 (001010): Assured Forwarding class 1, low drop probability - AF12 (001100): Assured Forwarding class 1, medium drop probability - AF13 (001110): Assured Forwarding class 1, high drop probability - ... (similar values for AF2-AF4 classes) - CS1-CS7: Class Selector values - EF (101110): Expedited Forwarding - Default (000000): Best effort service Higher numerical values indicate better service priority. #### Layer 2 Marking Configuration
Router(config)# class-map voice_traffic
Router(config-cmap)# match dscp ef
Router(config-cmap)# exit
Router(config)# policy-map qos_policy
Router(config-pmap)# class voice_traffic
Router(config-pmap-c)# set cos 5
Router(config-pmap-c)# exit
Router(config)# interface GigabitEthernet0/0
Router(config-if)# service-policy output qos_policy
Layer 2 CoS values have standard interpretations: - 0: Best effort data - 1: Medium-priority data - 2: High-priority data - 3: Call signaling - 4: Videoconferencing - 5: Voice bearer - 6-7: Reserved #### MPLS Marking
MPLS headers contain an EXP field (3 bits) that supports 8 different markings (0-7). Note that only explicit null (not implicit null) allows for EXP modification. #### Policy-Based Routing (PBR)
PBR can mark traffic but has limitations - it can only set IP precedence, not DSCP values. ##### PBR Configuration Example
Router(config)# access-list 101 permit tcp host 192.168.1.1 host 192.168.2.1 eq 80
Router(config)# route-map pbr_marking permit 10
Router(config-route-map)# match ip address 101
Router(config-route-map)# set ip precedence 3
Router(config)# interface FastEthernet0/1
Router(config-if)# ip policy route-map pbr_marking
VPN Environments and QoS
Special considerations apply to QoS in VPN environments, particularly IPsec VPNs where encryption occurs: 1. **Tunnel Mode Issues**: When using tunnel mode (common in LAN-to-LAN GRE over IPsec), the original packet markings are lost because encryption creates a new IP header. 2. **Transport Mode**: In transport mode, original markings are preserved as ESP/AH headers are added after the IP header. 3. **Pre-classification Solution**: For tunnel interfaces, the "qos pre-classify" command enables classification based on original packet headers before encryption. ##### VPN Pre-classification Configuration
Router(config)# interface Tunnel0
Router(config-if)# qos pre-classify
Router(config-if)# ip policy route-map vpn_policy
QoS Policy Propagation via BGP (QPPB)
QPPB leverages BGP attributes for classification and marking: 1. BGP community attributes can be used to mark routes 2. Only inbound traffic can be marked using QPPB 3. QPPB is independent of BGP routing decisions ##### QPPB Configuration Example
Router(config)# route-map community_marking permit 10
Router(config-route-map)# match community 100:200
Router(config-route-map)# set ip precedence 5
Router(config-route-map)# set qos-group 10
Router(config)# router bgp 65001
Router(config-router)# table-map community_marking
Router(config-router)# exit
Router(config)# interface GigEthernet0/0
Router(config-if)# bgp-policy destination ip-prec-map
Classification and Marking Summary
Classification Methods
-
ACLs: Traditional Layer 2/3 classification - NBAR: Deep packet inspection for application identification - BGP attributes: Community, AS-path, and prefix-based classification #### Marking Methods
-
CBMarking: Using MQC framework with class-maps and policy-maps - PBR: Limited to IP precedence marking - VPN QoS pre-classification: For encrypted tunnel environments - QPPB: For BGP-propagated policies #### Implementation Guidelines
-
Classification typically occurs on inbound interfaces - Marking can be applied on both inbound and outbound interfaces - Different marking schemes have predefined priority levels - Proper documentation of marking schemes is essential for troubleshooting ### Practical Configuration Example
Scenario
- Mark traffic from Router1 to Router2's loopback with IP precedence 5 - Mark traffic from Router2 to Router1's loopback with DSCP 40 ##### Router1 Configuration
Router1(config)# ip access-list extended R1_TO_R2
Router1(config-ext-nacl)# permit ip host 1.1.1.1 host 2.2.2.2
Router1(config-ext-nacl)# exit
Router1(config)# class-map MATCH_R1_TO_R2
Router1(config-cmap)# match access-group name R1_TO_R2
Router1(config-cmap)# exit
Router1(config)# policy-map MARK_R1_TO_R2
Router1(config-pmap)# class MATCH_R1_TO_R2
Router1(config-pmap-c)# set ip precedence 5
Router1(config-pmap-c)# exit
Router1(config)# interface FastEthernet0/0
Router1(config-if)# service-policy output MARK_R1_TO_R2
Router2 Configuration
Router2(config)# ip access-list extended R2_TO_R1
Router2(config-ext-nacl)# permit ip host 2.2.2.2 host 1.1.1.1
Router2(config-ext-nacl)# exit
Router2(config)# class-map MATCH_R2_TO_R1
Router2(config-cmap)# match access-group name R2_TO_R1
Router2(config-cmap)# exit
Router2(config)# policy-map MARK_R2_TO_R1
Router2(config-pmap)# class MATCH_R2_TO_R1
Router2(config-pmap-c)# set dscp 40
Router2(config-pmap-c)# exit
Router2(config)# interface FastEthernet0/0
Router2(config-if)# service-policy output MARK_R2_TO_R1
When implementing QoS classification and marking, understanding the predefined priority levels of different marking schemes is crucial for effective network traffic management.