An Intelligent SDN-Based Clustering Approach for Optimizing IoT Power Consumption in Smart Homes

As a novel technology, the Internet of Things (IoT) has many applications in diverse ﬁ elds, especially in smart homes. IoT includes a variety of communication networks and technologies which facilitate communication between heterogeneous devices. One of the primary challenges of IoT is energy consumption. This paper introduces a new Software De ﬁ ned Network-based (SDN-based) clustering approach using intelligent algorithms for energy conservation in IoT. The proposed method uses an evolutionary algorithm to identify the required number of clusters and ensures their distribution in the environment. A virtual network is also employed to ensure network coverage and the formation of balanced clusters. Clustering, steady, and routing are the main steps of the proposed method that the clustering step is done in SDN. By expanding the steady phase and leveraging energy-based greedy routing, the network ’ s lifetime increases. After simulation in MATLAB, the proposed method is tested then the results are compared with other well-known algorithms. The evaluation results indicate that the proposed method has improved in terms of metrics such as energy consumption and network lifetime. The proposed approach improves energy consumption by 31%, 28%, 8% and 21% than FPA, MCFL, BEEG and NodeRanked respectively. The lifetime has been improved by 34% and 71% than BEEG and NodeRanked, respectively, and more than 100% for MCFL and FPA.


Introduction
In recent years, many researchers and leading technology companies have considered the application and advancement of the Internet of Things (IoT) in various fields, such as smart cities, smart homes, agriculture, and intelligent animal husbandry. IoT consists of numerous self-organized, tiny, and low-cost sensor nodes. IoT nodes, through their sensors, can collect and transmit data from the environment to the base station (sink) [1]. In addition, IoT is responsible for tracking network coverage issues and transferring monitoring results from the sink to the administrator [2,3]. The monitoring center will derive valuable information using artificial intelligence, machine learning, and data mining algorithms from the collected data and provide it to administrators via mobile applications.
Wireless sensor networks (WSNs) are one of the most useful foundations for implementing IoT architecture. The IoT provides the ability to connect various things to the internet. IoT sensors can automatically track, process, and route data and allow various real-time applications. Also, they allow diverse real-time applications such as smart cities and smart homes to be developed [4]. WSN have been in many fields during the past two decades, such as habitat monitoring [5], battlefield target tracking [6], health monitoring [7], gas monitoring [8], and smart homes [9]. The advantages of these networks are combined in a smart home. A smart home can make numerous aspects of health, social, and emotional care more efficient and sustainable for its occupants [10].
Heterogeneous nodes and energy consumption are two primary limitations of the IoT. Flexible layered architecture is required, to deal with the heterogeneous nodes. Software-defined network (SDN) is a modern approach to growing network flexibility. The SDN network distinguishes the control plane from the data plane. This separation makes it possible to dynamically control the network, provide a better quality of service (QoS), and offer network management consistency and simplicity [11]. SDN is a promising approach in WSN and IoT, allowing controllers to be isolated from sensor nodes. The SDN controller decides about various network parts and defines the current input rules based on the information it receives from the network [4]. SDN enables network administrators to manage network services without lower-level details being assessed [12].
Besides, the inadequate battery capacity of the sensor nodes is one of the most critical limiting factors. So, limiting energy use, which directly affects the network lifetime, is one of the vital problems in these networks [13]. Clustering is a key and popular technique for prolonging the network lifetime and efficient network management. It provides a range of benefits, including reducing intracluster communication, balancing the traffic load, and improving its scalability [14].
This paper introduced an energy-efficient clusteringbased routing method. Its primary focus is on balanced and distributed clustering, which helps to extend the network's lifetime. The following are the key features of the proposed approach: (i) Provision of a framework for balanced clustering based on SDN architecture (ii) Clustering based on multiobjective optimization algorithms (iii) Use greedy distributed routing The following is the paper's structure: Section 2 discusses the research literature. We have used a three-tier model for system modelling, which is reviewed in section 3. The proposed method includes phases of set-up, steady state, routing, and reclustering, which will be discussed in section 4. The simulation results are given in section 5. Finally, a review of the achievements and conclusions is provided in section 6.

Related Work
This section discusses the first various clustering methods then evaluates SDN-based approaches. Generally, clustering algorithms can be classified into the following categories: (i) Hierarchical clustering algorithms (ii) Virtual grid-based clustering algorithms (based on virtual grid) (iii) Fuzzy logic-based clustering algorithms (based on Fuzzy logic) (iv) Based on metaheuristic algorithms (metaheuristicbased clustering algorithms) The key aim of hierarchical clustering is to preserve the energy levels of clusters by using multistep paths. The LEACH method is the most well-known hierarchical clustering method [15]. This method uses a random probability function to pick cluster-head nodes. ( [16] and [17] attempt to enhance the LEACH method. In [18], each node is allocated a rank depending on the route's cost and the number of connections between nodes, and CHs are selected based on this rank. A routing approach for optimizing network lifetime and reducing data latency is proposed in [19]. The cluster-based routing protocol (CRPD) is presented in [20]. In CRPD, the energy efficiency has been enhanced by clustering and routing algorithms through periodic updating of the network topology. In [21], only nodes with an energy greater than 20% of the initial energy can be nominated as headers.
Grid-based methods use GPS or location detection algorithms to make nodes be aware of their geographical location [22]. An energy-based, scalable georouting was introduced in [23], where the last position of the sink is stored and updated in several intersecting nodes. The other nodes will locate the sink's last position by sending a message to the closest crossover node. The key emphasis of BEEG [24] is on getting the cluster size. The optimum size causes reduced transmission and energy consumption. In [25], the routing fixed-parameter tractable (RFPT) algorithm and the load balancing virtual grid are used for routing and less time complexity. It uses an FPT-approximate clustering algorithm and a supreme routing tree that optimally connects all nodes.
The high speed of inference in fuzzy logic makes it possible to use it in real-time environments [26]. The use of a fuzzy method to pick the CHs decreases computational complexity. A fuzzy-based approach to reducing battery consumption for WSN maintenance for smart homes is applied in [27]. In this approach, a fuzzy logic controller (FLC) sets the network nodes' sleep time dynamically. Multistage fuzzy clustering is implemented in [28]. The CHs are chosen based on residual energy, the number of neighbors, and the distance to the sink. A method named DUCF is introduced in [29]. In DUCF, parameters such as residual energy, base station distance, and node degree are considered fuzzy inputs. CH selection increases each round's energy consumption by using this method.
Metaheuristic algorithms can be used to routing and select CHs. A routing method based on an ant colony algorithm to prolong the network's lifetime was suggested in [30]. In [31], the flower pollination algorithm (FPA) was used to control the grid's energy level. A dynamic particle swarm optimization (PSO) clustering algorithm was used in [32] to determine the position of the CHs. Adaptive clustering based on node distribution makes cluster distribution more logical, effectively balancing grid energy consumption. A combination form of heuristic algorithm and K-means algorithm is implemented in [32]. It selects optimum clustering depending on the distance between the clusters, the distance from within the clusters, and the number of CHs. An improved bee algorithm is used to cluster creation. New clusters are created using based on the remained energy of the nodes. In [33], the authors presented a multiobjective cluster head selection algorithm for IoT networks in smart cities.
The introduction of SDN led to the development of several approaches using a centralized controller. The global 2 Wireless Communications and Mobile Computing knowledge of network devices like AUVs or sensors is accessible to the SDN-based controller [34] [35]. Under current conditions, the network can be managed effectively, and rules can be extended. In [36], DRL helps to monitor packets' flow in the WSN via SDN architecture, and the 2D and 3D convolution layers of two CNN models are used to evaluate. In [37], the Low-Power Network Routing Protocol (RPL) is introduced using the Multihop Clustering technique (MHC-RPL). In [38], the authors provide an SDNbased framework for Quality of Service-based routing on the Internet of Underwater Things. The primary approach of this method is to collect route information at the base station and select the best route based on the probability of packet loss and delay.

System Model
Today, the Internet of Things has resulted in the massive volume of data being produced. The use of traditional methods for processing this big data has encountered numerous problems. Cloud computing has been proposed, to address these issues. Many IoT applications, like smart city app, need latency-aware computations [39]. Processing IoT requests over the Cloud alone is not an efficient solution, especially for some time-sensitive applications. Because delays in data transfer and processing in the Cloud layer reduce system performance. Fog computing is introduced to address this issue. It acts as an intermediate layer between the Cloud layer and IoT devices. Fog devices can be placed close to IoT nodes, allowing latency to be noticeably reduced. Therefore, a three-tier architecture is proposed to better manage smart city applications. Figure 1 shows the architecture of the system. Like [40], we use a three-tier architecture. In the first layer are IoT devices that communicate via wireless communications and, after collecting data through sensors, send data packets to the sink. Data is collected and processed in the sink. If more processing is required, the data is sent to the Fog layer. The Fog layer can be formed by one or more Fog domains. Tasks will be offloaded to the Cloud when more processing is required.
Here, our focus is on the first layer. The goal is to use the SDN architecture for optimal management in the first layer to minimize the need for processing in the Fog and Cloud layers.
Some instruments, such as cameras and mobile devices, are wired directly to AC power and do not have energy consumption restrictions. Others may be dispersed randomly into the environment or travel in the ambit, such as motion sensors, temperature, vibration, and sound. City power cannot, however, be used, and batteries are supplied. Equation (1) shows the energy consumption model [31].
where d 0 is obtained as Equation (2).
That E T x represents the loss of transmitter and receiver energy, ε f s is the booster energy in space, and ε mp is the energy consumed by multipath emission. E Rx is the energy to receive packets, obtained from Equation (3).
where E DA is the energy of data aggregation. Therefore, Equation (4) denotes the total cost of transfer and receive.
By combining smart homes, smart streets, and highways, a smart city will be created. IoT plays a vital role in these cities. This technology consists of numerous heterogeneous devices, which enhances the need for SDN. Therefore, in this paper, an SDN-based architecture is used.

The Proposed Method
The proposed protocol has four stages: set-up, steady state, routing, and reclustering. Each phase is divided into subsections. In the following, each of the phases is examined.

Set-Up Phase.
First, the nodes transmit information such as position and energy level to the sink, and the network enters the setup phase. The set-up phase is divided into two parts: identifying the appropriate number of clusters and centralized clustering, which are performed in the SDN. After gathering sensor data, the sink utilizes the SDN to calculate the required number of clusters. The purpose of this subphase is to minimize energy usage. Because increasing the number of clusters increases energy consumption, a limited number of clusters ignores the benefits of clustering in addition to increasing energy consumption. The optimal number of clusters is determined using Equation (5) [41].
where K opt is the number of clusters, N is the number of IoT devices, M is the area space, and d toBS is the average distance between nodes and the sink, which is calculated according to Equation (6).
In the second stage of the set-up, the sink selects cluster heads according to the previous step information. The startup process has a lot of computing and routing overhead. In SDN, the controllers, which provides a global view of the 3 Wireless Communications and Mobile Computing whole network. To maintain a global network view, SDN controllers need to gather information from the whole of the network. To reduce traffic, this phase does periodically, not in every round. So, it is prevented from sending additional packets as much as possible. The reclustering process is then done locally to mitigate the transferring of packets. A genetic multiobjective algorithm considers multiple requirements for determining clusters. This approach considers parameters such as cluster centrality, balance, and distribution. The genetic algorithm runs in the sink and generates the virtual grid proportional to the number of clusters.
The virtual grid picks the initial CHs instead of random nodes. The virtual grid ensures that CHs are distributed throughout the environment. However, because the number of CHs is always smaller than the number of cells and the density of each cell's nodes is not equal with another one, the genetic algorithm chooses the final clusters. The objective function is defined to maintain the balance and centrality of clusters. Based on Equation (7), the general purpose is to minimize the square error value by having a given number of clusters. x and u i denote the sensor's location and cluster centers, respectively.
The number of cluster members is estimated to ensure that the clusters are balanced. The objective function, the disparity between the largest and smallest clusters, is minimized. Equation (8) ensures that the cluster balancing conditions are met.
Consequently, the final objective function of the sum of Equations (7) and (8) is obtained as Equation (9).
Algorithm 1 shows the set-up phase algorithm. It is implemented in the sink and begins by gathering data from all IoT devices and calculates the number of clusters required. It then constructs a virtual grid and selects a candidate cluster head from each cell at random. This is necessary for cluster head distribution throughout the environment. Finally, the genetic algorithm chooses the final cluster heads to create balanced clusters.

Steady-State Phase.
After selecting the CHs and sending the CHs information to all nodes, the non-CH nodes are connected to the nearest CH by receiving the header information and the form of the final clusters. Each CH assigns its cluster members a Time Division Media Access (TDMA-based) scheduler and notifies the nodes. Therefore, cluster members are active only in their time slots and send information that improves energy consumption.
At this phase, the nodes sense the environment and send the collected data to CH. Instead of sending several packets, CHs send a packet to the sink by aggregating data. CH may act as a header in the next round and does not need a recluster phase if CH energy is not below the threshold. Several steady phases are implemented, for one setup phase. So, the amount of energy saved in this method, assuming that j is the number of steady state with one setup phase, will be equal to Equation (10).
where α and β are a subset of nodes that α ∪ β = AllNo des and α ∩ β = ∅, when the energy of a CH is lower than the threshold, that CH selects the most appropriate node as its CH based on its member's information and transmits the new CH information to the others. The threshold value for each cluster is calculated as Equation (11).
That γ is a numerical value between (0, 1), and E k r is the average energy of the cluster member nodes. The second phase algorithm is shown in Algorithm 2. This algorithm is executed by the cluster head and determines the time of sending the data to the sink and the time of performing the clustering again.

Reclustering
Phase. If CH energy is smaller than the threshold value, CH locally identifies one of the cluster members as CH in the next round. If the CH energy exceeds the threshold value, the CH will reach the routing phase directly. As the sensors' computing power is much smaller than that of the sink, Equation (12) is used (for determining the new cluster head) that does not require much computing power.
W i determines the fitness criteria of each node for CH, where E i is the energy of the node, E k r is the average energy of the nodes in the cluster, and the denominator determines the distance of each node to the candidate node. Algorithm 3 shows the reclustering algorithm. It performs reclustering locally, with the minimum number of packets possible.

Routing Phase.
Each CH sends data through intermediate steps after collecting and aggregating data instead of directly sending it to its sink. The cluster obtains the value of the objective function given in Equation (4) for all adjacent clusters, utilizing information such as the neighbor's position and energy level. Consequently, neighbors with fewer distances from the sink and more energy from the other neighbors than the sink's distance are candidates for the next step. The routing phase is indicated in Algorithm 4. This algorithm is implemented in clusters' head and they send data to the sink in several steps using intermediate nodes. Create an initial population 4: Evaluation individuals//based on objective f unction do for ði = 0 ; i ≤ jN S j/2 ; i++Þ 5: Select two parents in the population 6: Generate two offspring by crossover operation between two parents 7: Insert two offspring into new generation list end for 8: Mutation some of of f spring in the new generation list 9: Evaluation individuals 10: Select

Experimental Result
In this section, the proposed method evaluated in five different scenarios. And it compared with recent algorithms, such as NR_LEACH [15], BEEG (GRID) [24], Adaptive MCFL [28] and FPA [31]. NR LEACH is a hierarchical protocol, BEEG is chosen from network-based protocols, MCFL comes from fuzzy-based protocols, and FPA is a metaheuristic protocol. MATLAB software was used for evaluation. The parameters assessed and studied in this paper include the network's lifetime, number of alive nodes, and death of the first node and average energy consumption, the routing overhead, and the computational complexity.  Table 1. The nodes are assumed to be altered in the environment randomly. The same scenarios are used for a fair assessment of the algorithms. Besides, CBR traffic is considered for all algorithms with the same transmission rate. The lower the energy consumption, the higher the algorithm efficiency. The proposed algorithm runs the clustering phase locally in comparison to other methods. This local selection avoids the transfer of additional packets to the sink and reduces network traffic. The proposed solution retains its consistency with increasing grid size, whereas the FPA, MCFL, and Node-Ranked methods are not flexible. The BEEG is scalable and the Node-Ranked performs better in small networks than large ones.

Energy Consumption. Energy consumption is
The average energy consumption in all networks is shown in Figure 2(f). Generally, there is a probability that energy consumption will rise with an increasing number of nodes. However, in the 150 × 150 scale network, the three proposed approaches, BEEG, and Node-Ranking, indicate decreased energy consumption; this may be caused by a reduction in the sensor area's node density.

Death of the First Node.
When different tasks are distributed among nodes, the first node is the last to die. The halflife node criterion is given in Figure 3 with the death of the first node. Figures 3(a)-3(e) show the criteria half-life node and first dead node for different scenarios. Figures 3(f) and 3(g) demonstrate the first dead node and the half-life node for all states, respectively.
Comparison of various methods indicates that the proposed approach works better than others. It uses the SDN architecture intelligently to select CHs and balance clusters. The current CH also handles the local selection of the next cluster head. As a result, selecting a specific node a CH-  6 Wireless Communications and Mobile Computing node repeatedly is prevented. So, distinct network duties are distributed across all nodes. Furthermore, the nodes with the most significant energy are used in routing, creating a shorter path to the sink. Considering the CHs energy, the longer the steady-state stage prevents the spread of additional packets. The results indicate that the proposed methods and BEEG are scalable. FPA clustering and MCFL need to send sensors data in the sink. The collection of this data requires a significant number of packets to be sent. Since delivery and reception of packets are the most critical factor in energy consumption, increasing traffic would waste energy resources. BEEG and Node-Ranked execute clustering locally and avoid additional packets from being sent. However, they cannot benefit from SDN.

Network Lifetime.
Increasing network lifetime is one of the most critical priorities of designing IoT. Figure 4 displays the network lifetime diagram with various methods. The death of 20% of nodes as a measure of network lifetime is regarded here.
As the nodes with the most energy are chosen in the reclustering phase, the network lifetime increases. The proposed method also ensures that clusters are balanced and that there are an adequate number of them.

Alive
Nodes. The more active nodes, the more network coverage. IoT coverage is one of the qualities of service requirements (QoS). The number of packets increases in the network by increasing the number of nodes. Nodes lose a certain amount of energy to send and receive each packet. Thus, by increasing the number of packets, the nodes' energy reduces. Another benefit of clustering is the easier handling of the number of packets sent via data aggregation. Figure 5 indicates the number of live nodes for various scenarios.
The proposed method saves energy due to consideration of the energy criterion in the routing phase. In the final rounds, the network will practically lose its connection due to the intermediate nodes' death and will not have the requisite efficiency. Our approach distributes energy consumption among nodes by dividing the various tasks between them. BEEG, MCFL and FPA do not consider the distribution of tasks. 5.6. Routing Overhead. The routing overhead specifies how many routing packets for each data packet are sent. The lower the value, the better because it indicates that fewer    Wireless Communications and Mobile Computing routing packets have been sent. The routing overhead is seen in various situations in Figure 6.
The routing overhead in the proposed method is lower than the rest of the approaches. It is because of the increase in steady-state duration and local clustering. More routing packets are sent due to centralized execution in MCFL, Node-Ranked, and FPA clustering. But, the reclustering process is distributed locally in the BEEG.    Where N iter is the number of evolutionary algorithm iterations, N pop is the original population, and N nodes is the number of nodes. It needs to collect all network information in the sink for clustering. Therefore, this method is not scalable.
In the MCFL algorithm, clustering is performed in the sink. It attempts to improve the steady phase, and the CHs will remind in the next round if have the appropriate condition. MCFL uses a fuzzy scheme. The time complexity of a fuzzy system ranges from OðNI × NIF + ðMOD + NIÞ × LÞ to OðNI × NIF × NID + ðMOD + NIÞ × LÞ base on the form of membership functions and the process of defuzzification (Kim, 2000). Where NI is the number of inputs, NIF is the number of fuzzy sets of inputs, NID is the number of discretization of the discourse input universe, and L is the number of rules.
The BEEG algorithm uses a virtual grid such that sensors information does not have to be collected in the sink. The clustering is performed locally depending on the maximum remaining resources. A node is chosen as the CHs in each cell. This approach guarantees that CHs are balanced and distributed and avoid any broadcasting packets. The complexity of time for this process is Oðk × mÞ, while k is the number of virtual network cells and m is the average number of members per cell.
The Node-Ranked algorithm has to rank the nodes, and this ranking is performed in the sink, so the broadcast prob-lem influences it. The time complexity for choosing the right CHs is OðnlognÞ. Because we have n nodes and must rank each node's value before selecting the k nodes with the highest rank value. Ranking with complexity OðnÞ is completed; then, sorting with complexity OðnlognÞ is used to choose the top k nodes. First, n nodes are ranked, and then, k nodes with the highest rank are selected from them. The ranking complexity is O ðnÞ, and sorting with O ðnlognÞ complexity is used to select k nodes.
The proposed approach uses local clustering such that we do not need to broadcast packets. But to take advantage of SDN, information is collected periodically in the sink. The localization of clustering is also decreased with the improvements in the steady phase. The time complexity for finding the right CH in this method is OðnÞ. However, an evolutionary algorithm and virtual grid have been used to ensure clusters' distribution and equilibrium at the beginning of the network operations. Since this step is done rarely and periodically, it can be overlooked.
It is worth mentioning that since our proposed architecture takes the use of SDN, it considerably outperforms other solutions in terms of various performance metrics. As aforementioned in the previous sections, the number of clusters in the network significantly affects the network's energy consumption and routing overhead. For this reason, leveraging SDN architecture to compute the number of required clusters with respect to the current status of the network leads to conservation in energy as well as decreasing the overhead of routing. In a nutshell, the centralized nature of SDN helps to make optimize solutions in network management and     Wireless Communications and Mobile Computing increase its efficiency together with end-users satisfaction. Our simulation results confirm that using SDN architecture is feasible for smart homes and superior to other non-SDN solutions.

Conclusion
This paper introduces a new method for optimizing energy efficiency on the IoT using an effective SDN-based energy clustering protocol. The proposed method involves four stages of set-up, the steady state, the routing phase, and the reclustering phase. Clusters are optimally generated in the set-up process using the SDN platform and using a multiobjective optimization algorithm. The goal of this phase is to accurately determine the number of clusters required and cluster them in a balanced manner. For this purpose, a virtual grid distributes clusters in the environment, and a genetic algorithm is used to create balanced clusters. In the clustering, the centrality of the cluster has also been considered in addition to the balance of clusters.
In the steady state, data are collected and sent to the sink. As long as the CH energy is not less than the threshold that is set dynamically and intelligently, the CH will remain in the next round. Otherwise, it enters the third phase. Increasing the duration of the stability phase reduces both traffic and energy consumption. In the third phase, the current CH identifies the next CH based on the remaining energy. Each CH selects the appropriate node to be the next cluster head locally. The fitness function, which uses the two criteria of distance and energy, is used to choose the next cluster from among the members of the cluster. In the fourth phase, packets are routed through a greedy algorithm. In routing, the node with the shortest distance to the sink and the highest energy among all members of the cluster is selected as the next hop.
The implementation results indicate that the proposed method due to suitable performance can be used in smart homes. It effectively reduces energy consumption and increases network lifetime. Also, it shows a significant improvement in other criteria. However, the calculation overhead of the proposed method is a reasonable amount. An SDN-based routing method could be considered in future work.
Smart homes are the cornerstone of smart cities and can play an important role in urban management. They are used in various fields such as health care, security, and energy saving. On the other hand, the IoT is expected to cover all aspects of life in the coming years. SDN-based applications based on the IoT-Fog-Cloud architecture seem to be a good solution for smart homes and smart cities.

Data Availability
The datasets used and/or analyzed during the current study are available from the corresponding author on reasonable request.