# A Resource Oriented Route Selection Framework Using Contextual Information Based on Fuzzy Logic
## 4 Proposed Approach
As a queue fluctuation, the difference between the current queue length and last round queue utilization is considered. We define the state of the nodes based on the queue fluctuation. It is an important routing metric, because data packet spent in the queue impacts the packet delivery ratio and end-to-end packet delivery delay. Since some IoT based smart city applications (patient monitoring, real-time application) do not perform well if delay is larger than predefined threshold. As explained, the smart city networking is typically characterized by the heterogeneity of networks and these networks present multi-service that provides more than one application or service. This indicates not only the presence of several traffic types within the network, but also the large and sudden surge of data. As a result, a high data generation rate is often uncontrolled and it leads to congestion in response to queue fill up. Thus, queue fluctuations can be a simple indication of traffic trends (how a node's queue grows or shrinks) and reflect the situation of a congested node in terms of occupied buffer space. The queue length information is recorded in per unit time \(t\), in which the information indicates the changing tendency of the traffic load and it is calculated based on the sliding window. We assume that, at any time, each LLN device is able to compute its queue length. We define the queue fluctuation as in Equation (2). \[\zeta(n)=\left\{ \begin{array}{c}\frac{Q_{var}(n)-Q_{lat}(n)}{Q_{var}(n)-Q_{var }(n)}\\ 0\end{array} \right. \tag{2}\]  
In which \(\zeta(n)\) denotes the ratio of the queue length fluctuation of a node \(n\). Where, \(Q_{cur}\)_represent_ the current queue length of a node \(n\), \(Q_{lst}\) represent the last round queue length of a node \(n\), \(Q_{mx}\) represent the max queue length of a node. The queue length fluctuation of a node is set to zero only if it satisfies the condition \(Q_{cur}(n)=Q_{mx}(n)\) at a node \(n\). In fact, the ratio of the queue fluctuation reflects the trend of the queue length. The larger value of \(\zeta(n)\) indicates the higher queue overflow probability:  
\[\phi(n)=\frac{1}{m}{\sum\limits_{i=1}^{m}}\Big{(}\zeta_{i}(p_{n})-\overline{ \zeta}\Big{)}^{2} \tag{3}\]  
\[\overline{\zeta}=\frac{\sum\limits_{i=1}^{m}\zeta_{i}(p_{n})}{m} \tag{4}\]  
where, \(\phi(n)\) is the dynamic traffic indicator in the network. It indicates the traffic tendency during last \(m\) times for \(\zeta(n)\). \(P_{n}\) represents the parent of a node \(n\). The \(m\) value is a design parameter that can be based on resources in the network. During the simulation tests, we consider \(m\) as the queue utilization counter within a certain time. In our experiment, the value of \(m\) is set to 6, while taking into account the resource of the Tmote sky node. Finally, the queue fluctuation index (QFI) is obtained as in Equation (5). \[QFI=\alpha\times\phi(n)+(1-\alpha)\times\zeta(n) \tag{5}\]  
where, \(\alpha\) is the weight factor, such that \(0<\alpha<1\), and used to prioritize the current measurement of the queue. The \(QFI\) metric is used to avoid selecting a parent node with limited resources. In the context of resource availability, we define three states depending on the QFI: _High_, _Medium_, and _Low_. The residual energy index (REI) is an energy metric that allows for us to make a wise decision by providing a better understanding of the network situation. Considering the residual energy for the nodes in the OF will be useful in terms of network lifetime, since it is essential for all applications. The REI of a node \(n\) is defined, as in Equation (6). \[REI(n)=\frac{E_{max}(n)-E_{cur}(n)}{E_{max}(n)} \tag{6}\]  
where, \(E_{max}(n)\) is the maximum energy level of a node \(n\) initially. \(E_{cur}(n)\) is the current energy level of a node \(n\). The \(E_{cur}(n)\) of a node can be obtained based on the energy consumptions during the different operating states of the node.