# CoAR: Congestion-Aware Routing Protocol for Low Power and Lossy Networks for IoT Applications
## 4 Proposed Congestion-Aware RPL
### Congestion Detection  
Measuring the congestion situation at each intermediate node, CoAR uses a congestion detection mechanism based on the current queue occupancy and observation of present and past traffic trend. In an IoT application scenario, sometimes congestion is happened because of the burst traffic. When a burst occurs around a node, a significant number of packets will enter the queue of a node at a given time period. A node is then congested in terms of occupied buffer space. CoAR handles this situation by using an adaptive buffer threshold. The dynamic trend with which node queues grow or shrink depends on the difference of the incoming and outgoing traffic rate through the specific node \(i\) at time \(t\). Thus, buffer queues grow with the increase of incoming packet flow than the flow of outgoing packets. The incoming traffic rate \((\lambda_{in})\) and outgoing traffic rate \((\lambda_{out})\) of a node are not constant with time and its increment or decrement is based on the MAC parameters, backoff time of CSMA operation, and number of active nodes. To determine a congestion situation adaptively, the term congestion degree (CD) indicates the changing tendency of the traffic load in a period of time and calculated based on the sliding window. The \(CD\) is defined as the ratio of incoming traffic rate over the outgoing traffic rate within a unit time interval in each node \(i\) as in Equation (18). \[CD(i)=\frac{\lambda_{in}(t)}{\lambda_{out}(t)} \tag{18}\]We use an exponential weighted moving average (EWMA) filter to reduce measurement fluctuations at each node \(i\) to monitor the traffic rate \(\lambda_{in}(t)\) and \(\lambda_{out}(t)\) as in Equations (19) and (20). \[\lambda_{in}(t)=(1-\beta)\times\lambda_{in}(t-1)+\beta\times\lambda^{\prime}_{ in}(t) \tag{19}\]  
where, \(\beta\) is the smoothing factor such that \(0<\beta<1\) and \(\lambda_{in}(t)\), \(\lambda_{in}(t+1)\) and \(\lambda^{\prime}_{in}(t)\) are expected average incoming traffic, old average incoming traffic, and recent incoming traffic rate respectively. \[\lambda_{out}(t)=(1-\alpha)\times\lambda_{out}(t-1)+\alpha\times\lambda^{ \prime}_{out}(t) \tag{20}\]  
where, \(\alpha\) is the smoothing factor such that \(0<\alpha<1\) and \(\lambda_{out}(t)\), \(\lambda_{out}(t-1)\) and \(\lambda^{\prime}_{out}(t)\) are expected average outgoing traffic, old average outgoing traffic, and just transmitted traffic rate respectively, and \(t\) is a unit time. A large value of smoothing factor \(\alpha\) and \(\beta\) reduces the level of smoothing and prioritize to weight to current measurement of traffic. whereas, a value of \(\alpha\) and \(\beta\) close to zero gives greater smoothing effect and less responsive to current changes in traffic. Moreover, in the process of determining the congestion degree, Equations (19) and (20) are updated periodically per incoming and outgoing packet basis. In our work, incipient congestion is detected by using a simple thresholding technique. Queue measurement begins when the queue occupancy of each node traverse 50% of the total queue size. Thus, this threshold is set as a warning line denoted as \(\gamma\). At this instance, the node checks the congestion degree through which the adaptive congestion threshold (\(A_{\tau}\)) of buffer for the given traffic rate considering the remaining queue size can be achieved as in Equation (21). \[A_{\tau}=\gamma+\frac{1}{CD}\times(remaining\ queue\ size) \tag{21}\]  
The \(A_{\tau}\) specifies the anticipated queue level at \(t+1\) based on the current traffic. This \(A_{\tau}\) value allows the affected nodes to tolerate burst traffic. Therefore, the threshold value is set to maximum when incoming traffic is zero or lower than outgoing traffic. Moreover, the threshold value is inversely proportional to the incoming traffic, hence it decreases as the incoming traffic increases. Let us consider that the incoming traffic is double than the outgoing traffic and total queue size is 48 packets.