# A Lightweight Secure and Energy-Efficient Fog-Based Routing Protocol for Constraint Sensors Network
## 3 Proposed SEFR Protocol
### Methodology of SEFR  
The detailed discussion of the methodology for the proposed SEFR protocol is explained in this section. It is divided into three phases. Different clusters are produced for balancing a load of sensor nodes with uniform energy consumption. Each cluster has a single cluster head, which aims to collect, aggregate, and route the members' data to the adjacent cluster head. The SEFR protocol uses a dynamic threshold that is comprised of multi-factors, and accordingly, optimal nodes are identified for the role of cluster heads. The data routing is accomplished in two steps. First, sensors' data is routed from cluster heads to fog nodes, and second, fog nodes that are located at the network edges transmit the incoming data towards cloud services using QoS parameters. Such a strategy imposes the least calls of route maintenance and improves the response time for critical applications. Also, it provides two tiers of security until data is delivered to remote users. In the beginning, sensor nodes initiate the hello message in the network field, so they may flood their positioning coordinates in the observing field. Upon receiving the information, neighbors make an entry in their routing tables and send an acknowledgment ACK message back to the source node along with their positioning coordinates. Accordingly, source nodes also make an entry of their neighbors' position in their routing tables. Once all the nodes stored the neighbors' information, then the SEFR protocol initiates the process of cluster head selection. Unlike most of the existing solutions that form the cluster boundaries only based on the distance parameter, the SEFR protocol sets a dynamic threshold to define the particular region based on distance and energy factors. The nodes that come within the computed region are considered as candidate nodes for the selection of cluster heads. Furthermore, the neighbor cluster heads are interconnected with each other to establish a virtual backbone structure and initiate the method for data routing towards fog nodes that are placed on network boundaries. Let us consider that \(T_{r}\) is a transmission radius, the distance of the farthest node from the cloud server is \(D_{\text{n}}\) and the maximum distance is denoted by \(D_{\text{max}}\). The \(D_{\text{max}}\) indicates the radius of the network dimensions. Similarly, \(E_{\text{n}}\) is the residual energy and \(E_{\text{max}}\) is the maximum energy, then the threshold value \(D\) is denoted in Equation (3). \[D =T_{r}\,\left(\frac{D_{\text{n}}}{D_{\text{max}}}\,+\,\frac{E_{\text{n}}}{E_ {\text{max}}}\right) \tag{3}\]  
Based on the computed threshold \(D\), the SEFR protocol determines the set of nodes and initiates the cluster head selection process among them. Then, the nodes that have a residual energy level more than a certain threshold are selected as cluster heads. Afterward, they announce their position, and the nodes with the least transmission distance join them, which results in formulating a unique cluster. If more than one cluster head lies in the transmission range of ordinary sensors, then the nearest cluster head is selected for the formulation of the cluster. Subsequently, the SEFR protocol slightly increases the threshold value to further gather the sensor nodes that are still not a part of any cluster, and it repeats the same procedure until the required process is completed. When the cluster formation phase is over, the SEFR protocol initiates the process of data routing from cluster heads to fog nodes. The SEFR protocol uses QoS-aware parameters to evaluate the routing decision and achieves energy-efficient and stable data transmission. The source cluster head identifies the neighbor cluster heads from their routing tables and inquires them to share their up-to-date information. Accordingly, the neighbor cluster heads compute their residual energy, distance to fog nodes, and packet queuing factors. In the SEFR protocol, the packet queuing factor depends on the ratio of estimated delivered and dropped packets.