## 4 The Proposed QoS-Aware Routing
### Parameter Estimations  
Estimation of Queuing DelayAs shown in Figure 2, several queues are used for storing the different classes of data packets. The transmission scheduling of data packets from different queues is also different, to be discussed soon, and therefore, each class of data packets from a single node \(i\) may experience separate estimation of queuing delay \(d_{q}^{i}\). We calculate this delay as the time difference between the insertion time of the packet at the queuing system and the time at which it enters into the position of transmission. Note here that we omitted the processing time of a packet at the node because it is trivial and is assumed to be almost the same for all packet types. An Exponentially-Weighted Moving Average (EWMA) formula may suffice to estimate the running average queuing delays for each packet type \(\hat{d}_{q}^{i}[packet.type]\). Algorithm 3 shows the steps for estimating queuing delays, wherein, the weighting for each older data point decreases exponentially, giving much more importance to recent observations \(d_{q}^{i}[packet.type]\). The degree of weighing decrease is expressed as a constant smoothing factor \(\alpha\), a number usually between 0 and 0.4. In our simulation, we use \(\alpha=0.2\)Estimation of Transmission DelayEach node \(i\in\mathcal{N}\) in the MAC layer measures the average packet transmission delay \(\hat{d}_{tr}^{i}\) from itself using a Weighted Average Transmission Delay (WATD) method. WATD is very similar to the WALI method [20], which measures packet loss intervals for TCP congestion control. The WATD that works as follows. It measures the instantaneous delay for each packet transmission, \(d_{tr}^{i}(n)\), which is the delay for the \(n^{th}\) packet transmission measured as the time duration from the time at which the packet is ready for transmission (becoming the head of the transmission queue) to the time of successful transfer of its last bit and calculates the average value for the last \(P\) packets using (13),  
\[\hat{d}_{tr}^{i}=\frac{\sum_{n=1}^{P}d_{tr}^{i}(n)\times w_{n}}{ \sum_{n=1}^{P}w_{n}} \tag{13}\]  
where,  
\[w_{n}=1-\frac{n-P/2}{P/2+1},\quad P/2<n\leq P\]  
For \(P=8\), this gives weights of 1, 1, 1, 1, 0.8, 0.6, 0.4 and 0.2 for \(w_{1}\) through \(w_{8}\), respectively. Note that \(d_{tr}^{i}\) includes all delays due to media contention, such as channel sensing, RTS/CTS if any (depending on the chosen MAC protocol), backoff time slots, retransmissions, _etc._ Also note that the sensitivity of the average value \(\hat{d}_{tr}^{i}\) depends on the value of \(P\). In practice, a value of \(P=8\), with the most recent four samples equally weighted, appears to be a lower bound that still achieves a reasonable balance between resilience to link variations and fast response to real changes in the network conditions. Estimation of Link ReliabilityEach node \(i\in\mathcal{N}\) in the MAC layer also measures the average link reliability \(\hat{r}_{i,j}\) separately for all of the downstream nodes \(j\in\mathcal{D}_{i}\) using Windowed Mean EWMA (WMEWMA), which is very similar to EWMA but updates the estimated parameter in regular time intervals instead of doing it for every packet. This method is more appropriate for measuring link reliability. WMEWMA counts the total number of transmission attempts \(TxCounter\) required (including the retransmissions) to send all of the packets of the current window \(W\) and the number of packets successfully transmitted \(SucCounter\) of the same window. Therefore, the ratio \(\frac{SucCounter}{TxCounter}\) represents the success probability of the link for the window, which we regard as the link reliability in this paper.