0070_Cisco: QoS/DSCP

QoS (Quality of Service), ToS (Type of Service), and DSCP (Differentiated Services Code Point) are closely related. They are used to manage network traffic to ensure priority for certain types of data (e.g. voice, video) or limit bandwidth usage.

#QoS
#	1. Bandwidth: kbps, Mbps, Gbps, etc
#	QoS tools allow you to reserv a certain amount of link`s bandwidth for specific kinds of traffic
#	Example: 20% voice traffic, 30% for specific kinds of data traffic, leaving 50% for all other traffic


#	2. Delay
#		- The amount of time it takes traffic to go from source to destination 			   = one-way-delay
#		- The amount of time it takes traffic to go from source to destination	and return = two-way-delay


#	3. Jitter
#		- The variation in one way delay between packets sent by the same application. 10ms = ok, 100ms = high jitter 
#		- Jitter buffer provides a fixing delay to audio packets

#	4. Loss
#		- The % of packets sent that do not reached their destination
#		- Can be caused by faulty cables
#		- Device packet queus get full (discarding packets)

#	QoS Quening
#		-FIFO - First In, First Out. If buffer is full, then Tail Drop.
#	Tail Drop is harmful because it can lead to TCP global synchronization
#	TCP Sliding window - network traffic starts to float
#		->>>Network->Tail Drop->Global TCP window size decrease-Network-underutilized->>> and traffic starts float ...

#	To prevent use RED (Random Early Detaction). Be aware it affects on all kind of traffics!
#	Solution --> Use WRED (Weighted Random Early Detaction)

#===========================
#	Audio quality
#	Delay: 150ms or less
#	Jitter: 30 ms or less
#	Loss: 1% or less
#===========================

# There are many methods of classifying traffic, for example:
#	- An ACL
#	- NBAR (Network Based Application Recognition) - deep packet inspection, looking beyond the layer 3 and 4 up to
#													 layer 7 to identify the specific kind of traffic
#	- The PCP (Priority Code Point) or CoS - field of 802.1Q tag (It works then tag uses only)
#	- DSCP (Differentiated Service Code Point) - field of the IP header can also used to identify high/low priority traffic

#===========================

#	PCP/CoS
#	3 bits = 8 possible values (2^3=8)
#	PCP field in 802.1Q tag
#-----------------------------------------------
#	PCP/CoS values	|		Traffic types		|
#-----------------------------------------------
#	0 -no priority	|	Best effort (default)	|
#-----------------------------------------------
#		1			|		Background			|
#-----------------------------------------------
#		2			|		Excellent effort	|
#-----------------------------------------------
#	3 (like SIP)	|	Critical Application	|
#-----------------------------------------------
#		4			|		Video				|
#-----------------------------------------------
#		5			|		Voice				|
#-----------------------------------------------
#		6			|		Internet work		|	
#-----------------------------------------------
#		7			|		Network control 	|
#-----------------------------------------------

#===========================

#	IP ToS/DSCP (Type of Service / Differentiated Services Code Point)
#	 are mechanisms used to manage traffic priority and service classes in IP networks. 
#	 DSCP is an extension of ToS and provides more granular traffic control.
#	ToS (Type of Service) – 8-bit Field in IPv4 Header:
#		- The first 3 bits: Precedence (priority level)
#		- The next 4 bits: Service parameters (Delay, Throughput, Reliability, Cost).
#		- The last bit: Reserved (unused).

#-----------------------------------------------|
#	Precedence		|		Purpose				|
#-----------------------------------------------|
#		000			|		Routine				|
#-----------------------------------------------|
#		001			|		Priority			|
#-----------------------------------------------|
#		010			|		Immediate			|
#-----------------------------------------------|
#		011			|		Flash				|
#-----------------------------------------------|
#		100			|	  Flash Override		|
#-----------------------------------------------|
#		101			|		Critical			|
#-----------------------------------------------|
#		110			|	Internetwork Control	|
#-----------------------------------------------|
#		111			|		Network Control		|
#-----------------------------------------------|


#	DSCP (6-bit field) = 64 possible values (0-63)
#	DSCP – Used in QoS for Traffic Classification:
#------------------------------------------------------------------------------------------|
#DSCP Value	|	Binary	|	Class Selector (ToS Precedence)	Purpose (Per-Hop Behavior, PHB)|
#-----------|-----------|------------------------------------------------------------------|
#	0		|	000000	|	CS0 (Best Effort)	Standard traffic						   |
#-----------|-----------|------------------------------------------------------------------|
#	8		|	001000	|	CS1	Background traffic										   |
#-----------|-----------|------------------------------------------------------------------|
#	16		|	010000	|	CS2	Standard data											   |
#-----------|-----------|------------------------------------------------------------------|
#	24		|	011000	|	CS3	Streaming video											   |
#-----------|-----------|------------------------------------------------------------------|
#	32		|	100000	|	CS4	Voice signaling											   |
#-----------|-----------|------------------------------------------------------------------|
#	40		|	101000	|	CS5	VoIP													   |
#-----------|-----------|------------------------------------------------------------------|
#	48		|	110000	|	CS6	Network control											   |
#-----------|-----------|------------------------------------------------------------------|
#	56		|	111000	|	CS7	Reserved (Network Control)								   |
#-----------|-----------|------------------------------------------------------------------|


#Common DSCP Values for QoS:
#-----------|--------------------|--------------------------------|
#	DSCP	| 		PHB			 |			Purpose				  |
#-----------|--------------------|--------------------------------|
#	EF (46)	|Expedited Forwarding| Real-time traffic (e.g., voice)|
#-----------|--------------------|--------------------------------|
#  AF11 (10)| Assured Forwarding | Low priority					  |
#-----------|--------------------|--------------------------------|
#  AF21 (18)| Assured Forwarding | Medium priority				  |
#  AF31 (26)| Assured Forwarding | High priority				  |
#-----------|--------------------|--------------------------------|
#  AF41 (34)| Assured Forwarding | Very high priority             |
#-----------|--------------------|--------------------------------|

#	Mapping DSCP to ToS
#		DSCP uses the first 6 bits of the ToS field. Thus:
#		DSCP (6 bits) + 2 reserved bits = ToS (8 bits)
#		Example:
#			DSCP: 101000 (CS5)
#			ToS: 10100000 (160 in decimal)

#
#		Round-Robin - for guarantee must be in Strict mode. Packets go until the queue is empty.
#					  To avoid traffic stacking use Policing

#	Shaping / Policing
#	Traffic  shaping and policing are both used to control the rate of traffic
#		-Shaping buffers traffic in a queue if the traffic rate goes over the configured rate
#		-Policing drops traffic in the traffic rate goes over the configured rate or re-marking the traffic
#		 instead of dropping it
#	In both cases, classification can be used to allow for different rates for different kinds of traffic

#	Steps
#		1. Classification
#		2. Quening (% bandwidth guarantee)
#		3. Scheduling (Round-Robin, Weighted, CBWFQ<-popular)
#		4. Transmission


#Example
enable
	configure terminal		
#		STEP-1
#		STEP-2
		class-map HTTP_MAP				#Create the HTTP_MAP class
			match protocol http			#Mark HTTP traffic as AF32 & provide min 10% bandwidth as a priority queue
			exit
			
		class-map HTTPS_MAP				#Create the HTTPS_MAP class
			match protocol https		#Mark HTTPS traffic as AF31 & provide min 10% bandwidth as a priority queue
			exit
		class-map ICMP_MAP				#Create the ICMP_MAP class
			match protocol icmp			#Mark ICMP traffic as CS2 & provide min 5% bandwidth as a priority queue
			exit
		
		class-map match-any VOIP				#Create the VOIP class
			match dscp ef
			exit
			
		do show running config | selection class-map
		
#		STEP-3
		policy-map QOS_POLICY					#Create the QoS politice for HTTPS traffic
			class HTTPS_MAP						
			set ip dscp af31 					#
			priority percent 10			
			
			class HTTP_MAP
			police 500000 8000 8000 conform-action transmit exceed-action drop #Limit HTTP up to 500 kbps
			bandwidth percent 10
			
			class ICMP_MAP
			set ip dscp cs2
			bandwidth percent 5
			
			class VOIP
			priority 1000    					#Set min bandwidth 1000 kbps for VoIP
			
			class class-default
			fair-queue       					#The remaining traffic is distributed evenly
			exit
		end
		
#		STEP-4
			interface GigabitEthernet0/0		#Apply the policy to WAN interface
				service-policy output QOS_POLICY
				
#	- class-map: Defines traffic categories based on DSCP or other criteria
#	- policy-map: Sets the processing rules for each class
#	- priority: Guarantees minimum bandwidth
#	- police: Limits the speed of traffic with certain actions when exceeded
#	- class-default: Handles all traffic that does not fall under the rules


	show policy-map interface GigabitEthernet0/0	#to show active politics on the interface
	debug qos										#to debug QoS
	show mls qos interface statistics				#to monitoring packets marked DSCP