## 4 Proposed System
### Selective Forwarding Detection (SFD) Algorithms
#### 4.3.1 MAC Pool of IDs Layer
Otherwise, the traffic is returned to the pool of MAC IDs by confirming the legitimacy of the node as shown in Algorithm 3. ```
1. Input = (AD: Anomaly Detection)
2. Output = (DT: Selective Forwarding Detector)
3. Network parameter = (SN: Sensor node, RT: Route)
4. Attacking parameter = (SFAT: Attacker)
5. RL2 = Anomaly detection based in IDS (RL2 IDS)
6. AD \(\subseteq\) RL2 IDS
7. For (RL2 = 0; RL2 \(\leftarrow\) AD; RL2 \(\leftarrow\)+)
8. RL2 = RL2 + 1
9. If RL2 \(\in\) AD then
10. Compute FN
11. FN = 1/N \(\sum\) FN
12. M = 1
13. Set Alert
14. Rejected
15. Dropped
16. Else if RL2 \(\in\) AD then
17. No Attack
18. Set SN = RT
19. Return
20. SN \(\rightarrow\) MP
21. Declared
22. End if
23. End else
24. End for
```

**Algorithm 3** Anomaly Detection Layer Based on IDS

## 5 Reliable, Energy Efficient and Scalable (RES) Model

The goal of a reliable, energy-efficient and scalable (RES) model is to extend the network lifetime while maintaining the Quality of Service (QoS). The network lifetime is the most significant metric of wireless sensor networks. RES also aims to balance the energy utilization for unevenly distributed sensor nodes to provide longer secure surveillance for military bases. In the military base surveillance, there is a high probability that nodes will die by forwarding heavy traffic. In order to develop reliable communication, we have to determine a reliable path from the sender node to the base station, as the \(\forall K\) number of the sensor nodes in the reliable optimal \(RP\) path is given as:

\[\prod_{t=0}^{\forall K}RP_{tj} \tag{1}\]

Let us assume that WSNs are perceived as the 2D graph with vertex \(V\) and edges \(E\) written as \(G(V,E)\) with transmission range \(T_{r}\) so that the maximum reliable communication can be obtained using Bellman-Ford algorithm's link measurement properties \(BF\) given as:

\[BF=\frac{\theta{\sigma_{y}}^{2}}{T_{r}d_{x}^{-n}} \tag{2}\]

Once, we start searching the reliable path for communication then we can this write as:

\[RP:RP_{max}\ \prod_{(i,j)}^{N}RP_{tj}\ -\ RP_{min}\ \sum_{(i,j\in RP)}^{N}-log \frac{1}{RP_{tj}} \tag{3}\]

Once we are able to find the reliable communication pathway, then we have to balance the energy consumption. We define the network lifetime when the sensor node first time drains its energy. Ideally, prolonging the network lifetime requires satisfying the following conditions: total consumed energy for all sensor nodes in the network, the differences between the node's individual energy consumption, average energy consumption of each sensor node, and energy consumed for transmitting the packet and for receiving the packet. Total consumed energy for all sensor nodes in the network should be considered as minimal \(\prod\Delta E_{m}\). Determining the differences between the node's individual energy consumption \(\Delta E_{m}(1\leq k\ \leq\ S_{n})\) and an average energy consumption \(\Delta E_{a}\) is the minimal energy. The differences can be accumulated as:

\[\rho^{2}=\sum_{k=0}^{n}k\ (\Delta E_{m}-\ \Delta E_{a})^{2} \tag{4}\]

where \(\rho^{2}\) is differences between minimal energy and an average energy of the sensor node. After determining the differences, we focuses on an average energy \(\Delta E_{a}\) consumption of each sensor node that can be written as:

\[\Delta E_{a}=\sum_{k=0}^{n}k(\Delta E_{m}) \tag{5}\]

As well as, we need to determine the number of generated packets generated by sensor node \(k\):

\[\omega_{p}=\left(\Delta\beta_{t}\ \prod_{u\in S(k)}^{n}Y_{uk}-\Delta\gamma_{r}\ \prod_{v\ \in\ S(k)}^{n}Z_{wk}\ \right) \tag{6}\]

Once a node joins and leaves the network, the communication performance is affected and the provision of QoS is degraded. We address scalability in our design to overcome the performance degradation. Let us consider the number of joining nodes \(k_{j}\) in the network. The size of the network is limited and it does not accept a load of more than \(k_{j}\leq 1\ \leq\ k_{t}\).