# An Energy-Efficient and Secure Routing Protocol for Intrusion Avoidance in IoT-Based WSN
## 3 Proposed Intrusion Avoidance Protocol
### Optimize Clusters  
The number of nodes is dispersed randomly in a square sized network field at the beginning of initialization phase. Each node remains static and has a unique ID with limited constraints. The BS has no restriction in terms of innumerable resources. In the beginning, BS broadcasts its locality in hop-by-hop manner over the monitoring field and all the nodes received it. Furthermore, the routing table of each node is updated by incorporating the neighbor's information. Afterwards, ESR protocol announces the cluster head selection mechanism in the network field in a scattered manner. By using residual energy \(e_{i}\), the Received Signal Strength Indicator (\(RSSI_{i}\)), proximity from BS \(d_{i\ to\ BS}\) and queue length \(QLi_{i}\) factors, the competitive value \(C_{v}\) is computed for all the nodes. Each node receives its neighbor's information through the exchange of control messages. Firstly, node energy is the most contributing factor in the survival of the network thus maximum residual energy of a node is given more significance. Secondly, the uses of RSSI measure the performance of the wireless link that offers a good packet reception rate if the RSSI value is more than a certain threshold. ESR protocol computes the RSSI threshold, which is the average reception rate of beacon packets from \(N\) neighbors at a certain time period (\(\Delta t\)) as given in Equation (1). The node's RSSI value must be greater than the computed threshold. If the RSSI value is less than the threshold, it indicates low link quality, which results in a rise in the probability of packets lose ratio. Let \(X\) denote the reception rate of beacon packets, then the following equation is used to compute the value of the RSSI threshold. \[RSSI_{threshold}=\frac{X}{N} \tag{1}\]  
Thirdly, the shortest path of node towards BS minimizes energy consumption and longer the network lifetime. In the end, the factor of queue length \(QLi_{i}\) improves data delivery performance and measures the congestion level at the node level. \(RR_{i}\) is the reception of packets in bytes at node \(i\)  
Figure 2: Block diagram of the energy-efficient and secure routing protocol (ESR) protocol. and TB is the total buffer size in bytes, then the queue length \(QL_{i}\) of a node \(i\) can be computed using Equation (2). \[QL_{i}=\frac{RR_{i}}{TB} \tag{2}\]  
Finally, all the factors are summarized based on weighted means as shown in Equation (3), and the nodes are appointed as initial cluster heads based on the highest competitive value \(C_{v}\) Accordingly, proposed ESR protocol selects an optimize cluster heads based intrinsic qualities and generated clusters are more adaptable. The computed value of \(C_{v}\) is normalized in the series of [0,1]. \[C_{v}=\text{w1}\times e_{i}+\text{w2}\times RSSI_{i}+\text{w3}\times\left( \frac{1}{d_{i\text{ }to\text{ }BS}}\right)+\text{w4}\times QL_{i} \tag{3}\]  
In Equation (3), weighting factors are denoted by w1, w2, w3 and w4 for different selection aspects, namely the node's residual energy, RSSI, proximity from BS and queue length. During the selection process, all the weighting factors signify the particular impact in computing the competitive value of nodes, whereas w1 + w2 + w3 + w4 = 1. The sensitivity analysis of the weighting factors is discussed in Section 4. The evaluated competitive value is in the series of [0,1] as all the residual energy, RSSI, proximity from BS and queue length have values in the same range. Firstly, the residual energy metric makes the cluster selection mechanism more adaptive. Furthermore, the RSSI facet is unified in the selection mechanism of the cluster head, which shows the performance of the wireless link. Moreover, based on the smallest distance from BS, an appropriate node is considered for the selection of the cluster head. Each node transmits beacon packets to its neighbors at an interval of the fixed period. On receiving beacons packets, the neighbor node evaluates its RSSI value and sends back towards the source node.