## 4 Bespoke Network Emulator
### Modification of NetEm  
For the reasons stated above, the NetEm's built-in distribution of packet delays was not an appropriate choice for emulating realistic traffic. Hence, the Log-normal distribution parameters and PDF relationships obtained from real-traffic data were used to create an empirical delay distribution table that could be integrated into NetEm. NetEm allows the inclusion of custom delay distribution with mean and standard deviation using iproute2, GNU compiler and marketable utility. A bash script was used to create a bespoke version of NetEm, where a custom long-tail delay distribution could be generated using any \(\mu\) and \(\sigma\) parameters of the distribution.  
As mentioned previously, it is understood from queuing theory that one of the most important pairs of QoS metrics is Delay and Loss. So, it was decided to implement this  
Figure 2: Average Hourly Delay Values for four UK operators.  
pair of QoS first, in the bespoke NetEm. To implement the linearly correlated Delay-Loss parameter in NetEm, a simple bash script was written. The script started off by importing randomly generated custom delay distribution. A python script was used to generate instantaneous loss depending on the value of the delay, correlation coefficient and average loss. This allowed us to emulate Delay and Loss with the required correlated percentage. Furthermore, the rate at which the packet delay were updated was kept at two per second to nullify the effect of jitter. In this way, only the impact of correlated Delay-Loss could be observed. The algorithm used to generate the required packet loss is given below.  
Let us assume that the delay distribution is an array of positive delay values, \(D\) (in ms) of size \(N\). We then need to generate an array of length \(N\) of loss values, \(L\) for each corresponding delay values. To start off, we generate random noise array, the same length as \(D\). We can then find the least square linear regression of the noise \(Q\) such that \(Q=AZ\), where \(A=\begin{bmatrix}D&1\end{bmatrix}\) and \(Z=\begin{bmatrix}m&c\end{bmatrix}\), where \(m\) is the gradient and \(c\) is the y-intercept \(Q\). So \(Q=mD+c\) and the residuals \(R\) of noise on \(D\) is \(R=noise-q\) such that the \(R\) and \(D\) have zero correlation between them.  
Since \(D\) has correlation of 1 with itself, and 0 with \(R\), we can easily find the appropriate linear combination to have an array with any required correlation value. Equation (1) gives the linear combination formula to generate an array of loss \(L\):  
\[L=C_{1}D+C_{2}R \tag{1}\]  
where,  
\[C_{1}=r*\sigma(R) \tag{2}\] \[C_{2}=\sqrt{(1-r^{2})*\sigma(D)} \tag{3}\]  
where, \(r\) is the Pearson Correlation Coefficient, \(\sigma(R)\) and \(\sigma(D)\) are the standard deviation of the residuals and delay values respectively.  
Now, the issue is the generated loss array can range from a negative value to more than 100 depending on delay and randomly generated noise values. However, the loss input value in NetEm was in %, hence we had to scale and shift the generated array to give us an array ranging from 0 to 100.  
Figure 3 shows the flowchart of the processes taken by the bespoke emulator. Once NetEm was initiated, it requested from the user which of the existing network interfaces to use for emulation. The user was then prompted to choose between applying the traffic control to packets entering (ingress) or leaving (egress) the interface. The user then had the option of using the default NetEm delay distribution or to generate custom delay distribution. The user then had the option to add the percentage of packet losses with or without correlation to delay. If correlated loss was chosen, a correlation value between 0 and 1 had to be specified. This simple, yet effective, change to NetEm would allow the user to emulate more realistic network scenarios than the default setup.