# Delay and loss tests using netem on a healthy network

[![](https://books.netdev.com.tr/uploads/images/gallery/2022-11/scaled-1680-/image-1668154502209.png)](https://books.netdev.com.tr/uploads/images/gallery/2022-11/image-1668154502209.png)

## Purpose of this document
We needed a lab environment that can provide a "break on purpose network" to developers to test their code on it.
You can add;

- delay
- packet loss
- jitter
- duplicate packets
- unordered flows

to a connection on the fly. To do it we need "netem" modules help.

## NETEM
Since kernel 2.6 netem is included in iproute2 package, basically all modern distro's has it now.
You can find a documentation on [Netem](https://docs.mikronet.tech/attachments/8)


i am going to explain the required steps here ;

- create a master traffic class on interface ens8
	
    	sudo tc qdisc add dev ens8 root handle 1: prio
- Attach a subclass to tc 1: as 3         
	
    
    	sudo tc qdisc add dev ens8 parent 1:3 handle 30: netem delay 1000ms
    	sudo tc filter add dev ens8 protocol ip parent 1:0 prio 3 u32 match ip dst 51.195.19.172 flowid 1:3