Particle swarm optimization and artificial bee colony algorithm for clustering and mobile based software-defined wireless sensor networks

With the development of the internet of things, people pay more and more attention to wireless sensor networks. Designing the energy efficient routing is an essential objective for wireless sensor networks. Cluster routing is one of the most popular routing protocols to enhance the network lifetime. However, hotspot problem always exists in cluster-based routing protocol. The task of this study is designing a cluster routing protocol with mobile base station which aims at balancing the energy consumption and prolonging the network lifetime. In this article, we design a particle swarm optimization and artificial bee colony algorithm for clustering and mobile based software-defined wireless sensor networks. The software defined network architecture is used to reduce the energy overhead and computation overhead in sensor nodes. Particle swarm optimization-based cluster routing algorithm is used to calculate the cluster heads and the sojourn locations of base station. Artificial bee colony algorithm-based traversal path algorithm is used to design the move path of the base station. Comparing with relevant protocols, the proposed protocol reduces the energy consumption, enhances the network lifetime and reduces the control overhead.


Introduction
Recently, wireless sensor networks (WSNs) have played an important part in monitoring and surveillance [1]. WSNs always consist of a base station (BS) and hundreds of sensor nodes. However, sensor nodes are often deployed in hard-to-reach locations. So, the replacement of the node battery becomes impossible [2]. Designing an energy efficient routing protocol is one of the best methods to solve this problem.
Cluster routing is an energy efficient routing protocol which can reduce the energy consumption. In cluster-based routing protocols, the sensor nodes are divided into cluster heads (CHs) and cluster members (CMs). CMs transmit the sensor data to cluster head. Then, CHs aggregate the sensor data and transmit the aggregation data to BS. The method of aggregating sensor data reduces the among of data which are transmitted to BS. This way reduces the energy consumption in sensor nodes [3].
In cluster-based routing protocols, CHs always consume more energy than CMs. The unbalanced energy consumption between sensor nodes makes the energy hole in WSNs. This is the hotspot problem in cluster routing [4]. Mobility BS technology is one way which can resolve the hotspot problem efficiently. In mobile BS-based cluster routing, BS moves freely in the network and CHs transmit the aggregation data when BS comes within its proximity.
As mentioned above, mobile BS-supported cluster routing can reduce the energy which is consumed in CHs. Mobile BS can move to the area with less energy, which alleviates the hotspot problem [5][6][7]. With the easing of the hotspot problem, the energy of the network is balanced and the lifetime of the network is enhanced. There are two main 1. The SDN framework is designed in the proposed protocol. This methodology reduces the energy consumption in sensor nodes and enhances the network lifetime. Sensor nodes need less energy for routing setup and controller is responsible for designing the routing of the whole network. 2. The PSO-based cluster routing algorithm is used to determine the CHs and sojourn locations of the BS. This algorithm considers the CHs election and the BS's sojourn locations in an integrated manner. Residual energy, distance to the next hop, the number of CMs in each cluster and distance between each of sojourn locations are all considered in this protocol. This method reduces the energy consumption in CHs and indirectly reduces the travel length of BS. 3. The ABC-based traversal path algorithm is used to calculate the move path of the BS. The method reduces the length of the moving track when it is compared to the random mobility model and the fixed mobility model. Sensor nodes can transmit the sensor data to BS quickly and the latency of the network is reduced.
The organization of the rest part is listed as follows. Section 2 discusses the mobile BS-based cluster routing and SDN-based routing protocols. Section 3 lists the network assumptions and the energy model of the proposed protocol. Section 4 introduces the proposed protocol in details. It consists the SDN framework of the proposed protocol, PSO-based cluster routing algorithm and ABCbased traversal path algorithm. Section 5 analyses the time complexity and the hardware complexity of PACMSD. Section 6 simulates and analyses the proposed protocol with other relevant routing protocols. Section 7 concludes the article.

Related works
Nowadays, the design of the mobile BS-based cluster routing and SDN-based routing protocols in WSNs have gained more and more attention [16]. The related works of these two parts are listed as follows. Guo et al. [12] combined reinforcement learning (RL) with SDN. The proposed protocol improves the performance of network lifetime and network convergence rate. Liao et al. [17] proposed an energy-efficient algorithm based multienergy-space (MES) in SDWSN. This protocol balances the energy consumption of the sensor nodes and prolongs the lifetime of the network. Li et al. [18] used game theoretic in order to improve the network lifetime performance in SDWSN. This protocol increases the energy consumption in sensor nodes.

SDN-based routing protocol
Shabbir et al. [19] proposed an SDN-based routing solution for internet of things (IoT). It uses in the mesh and cluster topological scenario. Singh et al. [20] designed a cloud-based environment parameter monitoring system. The sensor nodes are developed with capabilities of data acquisition. Hawbani et al. [13] used the SDN technology for WSNs and proposed an SDN-based architecture which is named mini software-defined networking (MINI-SDN).
The protocol improves the performance and scalability of the network.
Jurado-Lasso et al. [21] proposed a model-based SDWSN architecture. The proposed model concludes of the neighbor discovery functioning, neighbor advertisement functioning, network configuration functioning and data collection functioning. The proposed protocol is adapted in the static SDWSNs. Results show the protocol reduces the control overhead and prolongs the network lifetime.
Software-defined and fuzzy-based multi-hop unequal cluster routing (SDFMUCR) [22] uses an SDN framework to reduce the routing overhead and computation overhead in sensor nodes. Fuzzy logic (FL) based unequal cluster routing is used to balance the energy consumption of the CHs. This protocol reduces the energy consumption as well as the latency of the network.
Hu et al. [23] used the PSO algorithm for designing the unequal cluster routing protocol in SDWSN. It improves the energy efficiency and extends the network lifetime. It suggests SDWSN can implement the heuristic algorithm. Heuristic algorithm can improve the network performance in SDWSN.

Mobile BS-based cluster routing
Improved ant colony optimization-based approach with mobile sink (IACO-MS) [24] uses the mobile sink to balance the energy consumption between sensor nodes. IACO-MS reduces the path length and prolongs the lifetime of the network. Wang et al. [3] proposed an energy efficient cluster routing with mobile sink. The network is divided into sectors and a cluster head (CH) is elected in each sector. This proposed protocol reduces the energy consumption in cluster heads. Energy efficient clustering scheme (EECS) [1] simultaneously considers the distance, residual energy and the data overhead to select the CHs. It performs well in the network lifetime and throughput. Energy centers searching using particle swarm optimization (EC-PSO) [25] uses the geometric method to select the CHs. It uses an improved PSO to search the energy center and elect the CHs. The mobile data collector is used for balancing the network energy consumption. Gharaei et al. [26] proposed a cluster routing protocol with mobile sink. Network is divided into multiple regions and a CH is selected in each area. CHs transmit the aggregation data to mobile sink by multi-hops and sink moves through the Fermat spiral path. This protocol enhances the network lifetime and balances the energy consumption of sensor nodes.
Particle swarm optimization-based selection (PSOBS) [27] uses the PSO algorithm to calculate the optimal rendezvous points of mobile sink. This protocol reduces the packet loss rate and enhances the throughput of the network. Jiang et al. [28] drew an inspiration from the foraging process about the single-celled organism-slime mold physarum polycephalum. They used the slime mold optimization to design the move path of the sink. Krishnan et al. [29] proposed an enhanced clustering methodology with multiple mobile sinks for collecting data. It uses multiple mobile sinks to collect the sensor data which prolongs the network lifetime and reduces the network latency.
Singh et al. [30] proposed multi-clustered energy efficient routing algorithm with randomly moving sink node (MERAM-R). In this protocol, the method to select the CH nodes is the same as low energy adaptive clustering hierarchy (LEACH) and the sink node randomly moves in the network. It reduces the energy consumption comparing to LEACH. However, it increases the path length of the mobile sink.
Krishnan et al. [31] proposed dynamic clustering approach with ant colony optimization (ACO)-based mobile sink for data collection protocol. It overall considers the residual energy, distance and the number of the neighbor nodes in order to select the CHs. The traversal path of the mobile sink is calculated by ACO. This protocol effectively relieves the hotspot problem as well as prolongs the lifetime of the network.
Ghosh et al. [32] proposed differential evolution (DE) and mobile sink based on demand clustering protocol. This protocol uses an on-demand based clustering, which reduces the energy consumption in the cluster formation phase. DE is used for calculating the set of the CHs and the sojourn locations of the mobile sink. The traversal path of the sink is fixed. This protocol prolongs the network lifetime efficiently.
According to the related works listed above, some conclusions can be drawn as follows. Firstly, some researches proposed the SDN-based architecture for WSN to improve the network performance. However, few studies combine the SDWSN with cluster routing which increases the transmission overhead for sensor nodes. Secondly, in most of the mobile BS-based cluster routing, the BS moves near to CH for collecting the sensor data. This method increases the latency of the network. Thirdly, the related works usually used the distributed routing protocol. The routing is calculated in the sensor nodes which increase the computation overhead in sensor node.
The proposed protocol combines the SDN architecture with the heuristic algorithm. The routing is calculated in the controller which reduces the computation in the sensor node as well as improves the network performance. The proposed protocol designs the CHs and sojourn locations reasonably which reduces the length of traversal path. Fig. 1 is the system model of PACMSD. PACMSD adopts SDN technologies to reduce the routing overhead and computation overhead in the network. Sensor nodes work on the data plane and the PSO algorithm is used for designing cluster routing. BS works on the control plane and the ABC algorithm is used for calculating the moving track of the BS.

Network assumption
Some assumptions of the proposed routing protocol are listed as follows: 1. Sensor nodes act as switches randomly distribute in the network and remain stationary after deployment. 2. BS can move within the network. BS contains a controller module which is used to calculate the routing of the entire network. 3. Sensor nodes have the same initial energy. 4. Network links are symmetrical and sensor nodes are homogeneous. 5. BS has sufficient energy and sensor nodes have limited energy. 6. The power of calculation speed and data transmission of the BS is stronger than those of sensor nodes.

Energy model
The energy consumed in WSNs includes the transmission, reception and aggregation. The energy model of the WSNs is the first-order radio model. This model is often used in the cluster routing protocols for calculating the energy consumption of the sensor nodes. PACMSD uses this model because it can compare with other protocols easily. The path loss exponent is 2 when the distance between the receiver and transmitter is less than d 0 . The path loss exponent is 4 when the distance between two nodes is more than d 0 .
In PACMSD, BS moves near to CH for collecting the aggregation data in each cluster. In order to reduce the energy consumption, the distance between BS and CH is designed less than d 0 in PACMSD. Therefore, the path loss exponent is fixed.
The energy required to transmit l bits message is given by Eq. (1).
where E elec is the energy dissipated in the electronics, e fs and e mp denote the energy dissipated in free space and multipath fading respectively. The parameter d is the distance between the sender node and the receiver node, and d 0 ¼ ffiffiffiffiffiffiffiffiffiffiffiffiffi e fs =e mp p is the distance threshold. The energy required to receive l bits message is given by Eq. (2).
The energy required to aggregate l bits message is given by Eq. (3).
where E agg is the energy dissipated to aggregate 1 bit message.

Proposed protocol
This section, the PACMSD will be introduced in details. The SDN framework for the proposed protocol is introduced in Sect. 4

SDN framework for the proposed protocol
The proposed protocol uses the SDN technologies to calculate the network routing and the traversal path of the BS. The wireless sensor network (WSN) consists of a BS and sensor nodes. The controller module which is used to calculate the routing of the whole network is in the BS. Sensor nodes only need to transmit the topology information to the BS. This methodology reduces the energy consumption and computation overhead in sensor node.  This architecture consists of the data plane, control plane, southbound interface, northbound interface and application layer. Sensor nodes include the sensor module, sending module and receiving module. They work on the data plane. The node locations information and the residual energy information need to be transmitted to BS through sending module in order to calculate the routing of the network. Sensor module is responsible for sensing the environment. Receiving module is used to receive the control messages from BS. BS works on the control plane. It includes the topology information module, controller module, mobile module, flow table and data management module. Topology information module is used to manage the topology information of sensor nodes. Controller module uses the topology information to design the flow table of the sensor node and the traversal path of the BS. The sensor data is managed in the data management module. The application layer consists of many kinds of applications. Application layer gets the resource form underlying network through the northbound interface. Southbound interface is used to exchange data between the sensor node and BS.
The proposed protocol consists of four phases. These four phases are the topology discovery phase, flow table generation phase, flow table delivery phase and the topology maintain phase. The detail introduction of these four phases is given as follows.
Topology discovery phase: Topology discovery phase aims at collecting the information from the sensor nodes. Then the information is used to calculate the routing of the entire network.
In the topology discovery phase, BS broadcasts the topology request Topo req message to the sensor nodes. After receiving the Topo req message, sensor node establishes a temporary one-way secure channel to BS. Then the sensor node rebroadcasts the Topo req message until this message gets to the edge of the network. Next, sensor node packets the residual energy and the node location information of itself into topology reply Topo rep message and transmits the Topo rep message through the secure channel. Sensor node discards the message when it receives the same Topo req message. This methodology avoids the message flooding in the network. After receiving the Topo rep message, BS records the information of the sensor node to the topology information module. So far, the topology discovery phase is finished.
Flow table generation phase: Flow table generation phase aims at calculating the routing of the sensor nodes and the traversal path of the base station. This phase is operated in the controller module within the BS. Firstly, controller module uses the information in topology information module to determine the CH nodes and the sojourn points of the BS. This process uses a PSO-based cluster routing algorithm which will be detail introduced in Sect. 4.2. Then controller calculates the traversal path of the BS according to the BS's sojourn points. An ABCbased traversal path algorithm which is introduced in Sect. 4.3 is used in this process. Then, the mobile module in BS will get the sojourn locations and the traversal path from controller module. So far, the flow table generation phase is finished. These calculation processes are all operated in the controller module in BS, which reduces the computation overhead and the routing overhead in sensor nodes.
Flow table delivery phase: Flow table delivery phase aims at delivering the flow table Flow tab message to sensor nodes. So, the sensor nodes know the routing information of itself. The flow table consists of the CH flag Flag CH , set of the CMs Set CM , next hop H next , number of the timedivision multiple access (TDMA) time slot Slot TDMA and sojourn location of BS Loc soj . The Flag CH indicates whether the sensor node is CH. If the sensor node is CH, the Flag CH is '1'. If the sensor node is cluster member (CM), the Flag CH is '0'. The Set CM is the set of the CMs for a CH. For CMs, the Set CM is U. Controller module generates the TDMA schedule for CMs in this phase and Slot TDMA is the number of the TDMA time slot for CMs. The Loc soj is the corresponding sojourn locations of BS for cluster heads.
In the flow table delivery phase, BS moves in the network according to the moving path which is calculated by controller module. In each sojourn location, BS establishes two-way secure channels to sensor nodes. Then, BS delivers the flow table to sensor nodes hop by hop. When  Topology maintain phase: Topology maintain phase aims at collecting the sensor data from the network and detecting the information of the node in order to update the routing of the whole network. In the topology maintain phase, CMs transmit the sensor data packet along with its residual energy to CH in its own TDMA time slot. When it receives the whole data packets from CMs, CH aggregates the data packets to an aggregation data Data agg packet. If the Set CM changes, it means that at least one of sensor nodes in the network is dead. Then CH transmits the topology repair Topo repa message to BS.
BS moves according to the traversal path which is calculated in the controller module in the topology maintain phase. BS will stay for a while in each of sojourn locations. In each sojourn location, BS transmits the BS arrival Arv BS message to CH. After receiving the Arv BS message, CH transmits the Data agg packet to BS. Then BS moves to the next sojourn location. After receiving the Topo repa message from sensor nodes, BS returns to the topology discovery phase and recalculates the routing of the whole network. In addition, controller module will check the information of the sensor node in each round. If the network satisfies the conditions listed in Sect. 4.2, BS returns to the topology discovery phase. So far, the topology maintain phase is finished.
TDMA mechanism: In PACMSD, CMs transmit the sensor data to CH. The CH aggregates the data and transmits the aggregation data to BS. This method reduces the amount of data which is transmitted in the network. Meanwhile, this methodology reduces the bandwidth utilization of the sensor nodes. PACMSD uses the TDMA mechanism in which CHs transmit the aggregation data to BS in different slots. This mechanism avoids the collision of the message as well as provides enough bandwidth for data transmission. The transmission frequencies are different in each of clusters which avoids the interference between the clusters.
Secure channel: The channel in the proposed protocol includes the normal channel and the secure channel. Normal channel is used to transmit the data packet and secure channel is used to transmit the control message. These two channels work at different frequencies, which avoids the collision between the control message and the data message. Meanwhile, the traffic load in each channel is reduced. The secure channel aims at security, reliable and less energy consumption. Secure channel consists of the one-way secure channel and the two-way secure channel.
The establishment of these two secure channels is given as follows.
The one-way secure channel is established in the topology discovery phase. After receiving the Topo req message from other nodes, sensor node establishes a temporary one-way secure channel between itself and the sender node. Then sensor node responses the Topo rep message to BS through this secure channel.
The two-way secure channel is established in the flow table delivery phase. When the controller module generates the routing of the whole network, it will first establish temporary two-way secure channels between BS and the sensor nodes. Then BS delivers the flow table to sensor nodes through secure channel. Receiving the flow table from BS, sensor nodes respond the ACK message to BS through this secure channel. Then, sensor node forwards the flow table to next hop and the routing of the whole network is established.
The flow table of the proposed protocol is simple, so the control overhead of the network is low. The topology of the WSNs is not stationary, which makes the secure channels not absolute secure. Therefore, the secure channels should be used as less as possible. Fig. 3 is flowchart of PACMSD protocol.

PSO-based cluster routing algorithm
PSO algorithm is an intelligent heuristic algorithm which is derived from the birds swarming habit definition. In PSO, particles can move to the optimal location according to the position best and the global best. The process of the PSO algorithm is given as follow.
In the initial, M particles random distributed in D-dimensional space and the fitness value f i t ð Þ of each particle is calculated, where i is the number of particles and t is the number of current iteration. Then the particle position best pb i t ð Þ and the particle global best gb t ð Þ are calculated, where pb i t ð Þ is the particle position with the best f i t ð Þ in each iteration and gb t ð Þ is given by Eq. (4).
Then the velocity of the particle v i;d t þ 1 ð Þ and the position of the particle x i;d t þ 1 ð Þ are updated by Eq. (5) and (6).
where d is the number of particle dimension. The x is the inertia weight of the particle. The parameters c 1 and c 2 are the learning factors. The r 1 and r 2 are two random numbers. Then particles enter to the next iteration until the iteration satisfies the convergence condition or reaches the maximum number of iterations. The proposed protocol uses a PSO-based cluster routing algorithm to calculate the set of CHs and the sojourn locations of BS. This algorithm aims at reducing and balancing the energy consumption of sensor nodes as well as reducing the path length of BS. This protocol needs to meet the following conditions. 1. The residual energy of CHs should be as much as possible in order to transmit the aggregated data to BS. 2. The number of the CMs in each cluster should be as even as possible in order to balance the energy consumption in each cluster. 3. The distance between the CM and the CH should be less, so the energy consumption for intra cluster routing is low. 4. The distance between the CHs and the locations of BS should be less so the energy consumption for inter cluster routing is low. 5. The distribution of BS sojourn locations should be concentrated so the length of the BS's traversal path can be reduced.
According to the conditions mentioned above, the fitness value of the proposed algorithm f t ð Þ is related to the relative transmission overhead O tran , the relative residual energy E re , the discrete degree of the CMs in each cluster D CM and the discrete degree of the sojourn locations for BS D soj .
Before introducing the relative transmission overhead, the energy consumed for transmitting the sensor data to BS E total in the whole network is given by Eq. (7).
where N CH is the number of CHs in the entire network and N CM is the number of CMs in the entire network. The energy consumed for each CH E CH i is given by Eq. (8).
where N CM i is the number of CMs in each cluster, d BS i is the distance between CH and the corresponding sojourn location of BS, k is the size of each data packet and agg is the data aggregation rate. The energy consumed for each CM E CM j is given by Eq. (9).
where d CH j is the distance between CM and the CH. According to Eq. (1), (2), (3), (7), (8) and (9), E total is given by Eq. (10). In order to balance the energy consumption, this equation assumes that the number of CMs in each cluster is equal.
Where N total is the total sensor nodes in the network. In Eq. (10), only the d CH j and the d BS i are variable and all the other parameters are invariable. Therefore, relative transmission overhead is the normalization of the sum of the squares of the distance to next-hop node for sensor nodes. The relative transmission overhead is given by Eq. (11), where d i is the distance between the sensor node and next hop node. The network with less O tran should have a larger f t ð Þ.
According to Eq. (8) and (9), CH consumes more energy than CM. Therefore, the residual energy in CHs should be higher in the network. Relative residual energy is the normalization of the sum of the residual energy for CHs and is given by Eq. (12).
where E i is the residual energy of the i th CH and E max is the maximum residual energy of the sensor nodes in the network. The network with more E re should have a larger f t ð Þ.
In order to balance the energy consumption in each cluster, the number of CMs in each cluster should be balanced. D CM indicates the discrete degree of the CMs in each cluster and is the normalization of the standard deviation for the number of CMs in the network. The discrete degree of the CMs in the network is given by Eq. (13).
Where N CM max is the number of CMs in a cluster which has the maximum N CM i . The network with less D CM should have a larger f t ð Þ. If the sojourn locations of BS are close to each other, the length of the BS traversal path will be shortened. If the length of the BS traversal path is short, the latency to transmit the data to BS for each sensor node can be reduced. Before defining the discrete degree of the sojourn locations for BS, the center of the sojourn locations is given by Eq. (14) and (15) at first.
where N soj is the number of sojourn locations. The x c ; y c ð Þ is the center location of the sojourn locations and the x Soj i ; y Soj i is a sojourn location of BS. The distance between the center location and each sojourn location d C i is given by Eq. (16) and d C mean which is the mean value of d C i is given by Eq. (17).
The discrete degree of the sojourn locations for BS is given by (18).
Where d C max is the maximum value of d C i . The network with less D soj should have a larger f t ð Þ. The fitness function for this algorithm is given by Eq. (19).
The PSO algorithm is adapt to solve the continuous problem, but the solve of the optimal set of CHs is a discrete problem. So, the proposed protocol improved the PSO algorithm in order to adapt the discrete problem.
In the PSO-based cluster routing algorithm, the particle location includes the set of CHs x CH i t ð Þ and the set of the sojourn location x Soj i t ð Þ. Equation (20) represents the particle location.
where F i is the flag of a sensor node, '1' represents that the sensor node is CH and '0' represents that the sensor node is CM. The velocity of the particle may beyond the boundaries. Therefore, a velocity transformation function is proposed to keep the velocity of particles within a specified range. The velocity transformation function is given by Eq. (21).
where v max and v min is the boundary of the particle. v max 0 is the maximum value of v i;d t ð Þ and v min 0 is the minimum value of v i;d t ð Þ. At the beginning of PSO, a large inertial weight is beneficial to global search. At the end of PSO, a small inertial weight is beneficial to local search. In order to implement the process mentioned above, a linearly decreasing inertia weight is used in the proposed algorithm. The inertia weight for each iteration x t ð Þ is given by Eq. (22).
where x max and x min is the boundary of the inertia weight. The T is the maximum number of the iterations. The process of the PSO-based cluster routing algorithm is given by algorithm 1. The set of the CHs and the sojourn locations which are calculated by PSO-based cluster routing algorithm is given by Fig. 4 After determining the set of CHs, each CM will join the CH which is the closest of itself. Then, the controller module in BS generates the flow table for each sensor node. Finally, BS delivers the flow table to sensor nodes in the flow table delivery phase.
In most of the cluster routing protocols, the routing of the whole network is recalculated in each round. This methodology can balance the energy consumption between sensor nodes. However, it increases the control overhead in the entire network as well as reduces the network stability. The proposed protocol uses an on-demand clustering. The controller module in BS will only recalculate the routing when the network satisfies the conditions given as follows.
1. The number of alive nodes changes in the network. 2. The network has run more than the threshold value of the round r max after calculating the routing of the network. 3. The standard deviation of the residual energy in the network is more than threshold value E th . When the network satisfies the inequality (23), controller module will recalculate the routing of the network, where E mean is the mean value of E i which is given by Eq. (24). This condition aims at balancing the residual energy of the sensor nodes and prolonging the lifetime of the network. ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi ffi

ABC-based traversal path algorithm
ABC is inspired by the foraging behavior in bee colonies. The goal of the bee colonies is to find the optimal honey source in the search space. According to the divide of work, the colony of bees includes the employed bees, onlooker bees and scout bees. The operation of the ABC algorithm is divided into the initialization stage, the employed bee stage, the onlooker bee stage and the scout bee stage. In the initialization stage, honey sources X 1 ; X 2 ; Á Á Á ; X N f grandom distribute in the search space according to Eq. (25).
where N is the number of honey sources and D is the dimensions of the search space.
In the employed bee stage, each employed bee searches a new neighboring honey source according to Eq. (26).
Where X k is a honey source except X i . Then, the objective function f X i ð Þ and f V i ð Þ is calculated. If the solution of f V i ð Þ is better than f X i ð Þ, the X i is replaced by V i . Next, the fitness value function fit X i ð Þ is calculated according to Eq. (27).
In the onlooker bee stage, the onlooker bees use the greedy selection method to select the optimal honey source. An employed bee generates a random number r at first. Then r is compared to probability P i . The calculation of P i is given by Eq. (28). If r is less than P i , the employed bee will convert to onlooker bee. If r is greater the P i , employed bee updates the honey source of itself according to Eq. (25).
In the scout bee stage, an onlooker bee may change to scout bee in order to avoid the local optimum. If a honey source of the onlooker bee doesn't change after I th iterations, the onlooker bee will convert to scout and generate a new honey source according to Eq. (25). The I th is the threshold of the iterations. The proposed protocol uses the ABC algorithm to solve the traveling salesman problem. Each honey source is an N soj Â N soj matrix which has random numbers between 0 and 1. The first column and the diagonal of the matrix is 0. An example to process the random matrix into the traversal path is given as (29).
Assume N soj ¼ 4 and the starting position of the path is '1' which is represented as path X i ð Þ 1 ¼ 1. Then find the maximum number in the first row. The maximum number of this column is 3. So path X i ð Þ 2 ¼ 3 and the third column of the matrix is update to 0. Next, find the maximum number in the third row, which is 0.92. So path X i ð Þ 3 ¼ 2 and update the second column of the matrix to 0. Finally, path X i ð Þ 4 ¼ 4 and the traversal path of the mobile BS is 1-3-2-4. The f X i ð Þ is the path length which is given as Eq. (30).
ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi ffi Fig. 5 is the traversal path of the mobile BS which is calculated by ABC-based traversal path algorithm. The process of the ABC-based traversal path algorithm is given by algorithm 2.

Time complexity
The proposed protocol uses the SDN framework. The cluster routing of the network and the traversal path of the mobile BS are both calculated in the BS. The BS can be recharged, so the energy for BS is unlimited. So, the routing computation in BS cannot influence the network lifetime and the energy consumed in sensor nodes.
For the PSO-based cluster routing algorithm, the fitness function is calculated in the initialize phase. The time complexity is O M Â n ð Þ. The time complexity in the iteration process is O M Â n Â T PSO ð Þ . Where n ¼ N total þ N soj , M is the number of particles and T PSO is the maximum iteration number. Therefore, the time complexity of the PSO-based cluster routing algorithm is O M Â n Â T PSO ð Þ . For the ABC-based traversal path algorithm, the time complexity is O N Â N soj 2 À Á in the initialization stage. The time complexity is O N Â N soj 2 Â T ABC À Á for the other three phases. Where T ABC is the maximum iteration number and N is the number of bees. Therefore, the time complexity of the ABC-based traversal path algorithm is O N Â N soj 2 Â T ABC À Á . Table 1 is the complexity in implementing the PACMSD algorithm on hardware. Since PACMSD is an iterative procedure, we analysis only one single iteration because the same hardware resources can be reused for the next iterations [33]. The PSO-based cluster routing algorithm consists of

Hardware complexity
square root operations and 2M þ 4 operations of take the maximum value.
The ABC-based traversal path algorithm consists of N Â operations of take the maximum value.

Simulation results
The proposed protocol PACMSD is compared with the MERAM-R [30], ACO-based protocol [31] and DE-based protocol [32]. The detail of these three protocols is introduced in Sect. 2. The simulation parameters are given by Table 2.
The article aims at verifying the proposed protocol performs well both in small-scale network and large-scale network. Therefore, the network scale is different and other parameters are same in two scenarios. The proposed protocol and the comparison protocols are simulated in two different scenarios. In scenario 1, 100 sensor nodes randomly distribute in the 200 m Â 200 m network. In scenario 2, 400 sensor nodes randomly distribute in the 400 m

ð29Þ
Â 400 m network [31,32,34]. The initial energy of each sensor node is 0.5 J. The size of each data message and control message is 4000 bits and 32 bits respectively. The E elec , e fs , e mp , E agg and agg are the parameters in the first-order radio model. This paper selects the parameter values which are used in most of the articles [24].
We use the Matrix Laboratory (MATLAB) to simulate the performance of these protocols. Each scenario is simulated for 50 times and the average of these results is used to represent the performance of the protocols. This methodology reduces the error in the simulation process. The simulation results are shown as follows.

Energy consumption
In this article, the energy of sensor nodes is used for transmitting data, receiving data, aggregating data and calculating routing. The energy consumed in the idle phase and sleep phase is much less than other phases. Therefore, the energy consumed in these two phases are not considered. In the simulation, we evaluate the residual energy of each node according to the number of messages, the transmission distance and the complexity of the algorithm. In reality, the energy monitoring system and the circuit measuring equipment can be used to evaluate the residual energy of each node [35]. Figure 6 (a) is the total residual energy for sensor nodes in scenario 1 and Fig. 6 (b) is the total residual energy for sensor nodes in scenario 2. In these two figures, PACMSD consumes less energy than the comparison protocols. It shows the proposed protocol reduces the energy consumption both in the small network and the large network.
For MERAM-R and ACO-based protocol, sensor nodes need to calculate the network routing in each round. This method increases the energy consumption for calculating the routing and transmitting the control message. The DEbased protocol uses an on-demand clustering method which reduces the energy consumption for transmitting the control message. For PACMSD, it uses the SDN architecture in the WSNs. All the calculations are processed in the controller module within the BS. Sensor nodes only need to transmit the information of itself to BS. This method reduces the computation overhead and the control overhead in the routing setup phase. The proposed protocol also uses an on-demand clustering which overall considers the standard deviation of the residual energy and the threshold value of the round. Therefore, the proposed protocol reduces the energy consumption in network.  to show the lifetime of the simulated protocols, three performance parameters are used. These three parameters are the first node dies (FND), half node dies (HND) and last node dies (LND). FND is the number of the round when the first sensor node dies. HND is the number of the round when half of the sensor nodes die. LND is the number of the round when all the sensor nodes die. Figure 8 is the statistics of FND, HND and LND in different scenarios. The network connectivity is reduced when a node dies in the network. Some nodes cannot transmit the sensor data to BS. Therefore, FND is used to denote the network lifetime in this simulation. According to Fig. 7 The CHs are randomly generated in MERAM-R and a node with less residual energy can become the CH. This makes the energy unbalanced in the network and reduces the network lifetime. ACO-based protocol and DE-based protocol consider the residual energy when select the set of CHs. This methodology balances the energy consumption and prolongs the lifetime of the network. However, they don't consider the number of neighbor nodes and a cluster  can be large. This will increase the energy consumption for these sensor nodes and reduce the network lifetime.

Lifetime of the network
The proposed protocol overall considers the relative transmission overhead, the relative residual energy, the discrete degree of the CMs in each cluster and the discrete degree of the sojourn locations for BS. It also uses the PSO-based cluster routing algorithm to make these parameters balanced. The SDN architecture reduces the energy consumption in the topology discovery phase and the flow table generation phase. Therefore, the proposed protocol prolongs the network lifetime.
It can be seen that the number of alive nodes in Fig. 7 starts falling exactly after 700 rounds in both scenarios for PACMSD protocol. However, the simulation curves begin to fall for other protocols is different in differentiated scenarios. MERAM-R selects the CHs in each round randomly. The ACO-based protocol and the DE-based protocol only consider the residual energy and the distance to CHs in the CH selection phase. All the comparison protocols don't consider the number of CMs in each cluster which makes the energy consumption for each of CHs different. With the increasing of the network scale, the energy consumption for each sensor node is more and more unbalanced. Therefore, the simulation curve begins to fall earlier with the increasing of the network.
The proposed protocol overall considers the relative transmission overhead, the relative residual energy and the discrete of CMs in each cluster. Meanwhile, the PSO-based cluster routing algorithm is used to balance the energy consumption in the network. Beyond that, the mean of the node degreed is same in these two scenarios. So, the simulation curves begin to fall almost at the same round for PACMSD. Figure 9 is the average length of the BS traversal path in each round when the last node dies for different protocols. The proposed protocol aims at reducing the length of the traversal path for BS. The movement speed of the mobile BS for each protocol is same. If the path length is short, nodes can transmit the sensor data to BS quickly. So, the latency of the sensor nodes can be reduced.

Length of the traversal path
In Fig. 9, In MERAM-R, the BS randomly move in the network. So, the path length of the mobile BS is the longest. In DEbased protocol, the network is divided into sub regions and the mobile BS passes these sub regions sequentially. It doesn't use any method to reduce the travel length, so the performance of DE-based protocol is worse than ACObased protocol and PACMSD. ACO-based protocol uses ACO to calculate the move path of BS, which reduces the length of the moving path.
In PACMSD, the PSO-based cluster routing algorithm considers the discrete degree of the sojourn locations for BS, which reduces the distance between each sojourn location. Meanwhile, the ABC-based traversal path algorithm is used to calculate the traversal path, which further reduces the length of the traversal path. Therefore, PACMSD reduces the length of the traversal path. 6.4 Control overhead Figure 10 is the statistics of control overhead for each of protocols in different scenarios. Control overhead is the average number of control messages in each round. If the control overhead is low, the energy consumed for transmitting the control message is low. Reducing the control overhead can relieve network congestion as well as increase the network stabilization. According to Fig. 10, PACMSD performs better than MERAM-R by 77.2%, ACO-based protocol by 76.6% and DE-based protocol by 89.4% in scenario 1. PACMSD performs better than MERAM-R by 60.8%, ACO-based protocol by 49.7% and DE-based protocol by 79.7% in scenario 2.
In MERAM-R, control messages are needed in the cluster formation phase. In ACO-based protocol, each sensor node needs control message to collect the information of neighbor nodes in order to elect the CH. Without using on-demand cluster routing, these two protocols need more control overhead than PACMSD. The DE-based protocol uses the on-demand cluster routing. However, it uses DE-based cluster routing in a distributed routing protocol and the DE algorithm requires iteration. Therefore, it needs more control message in order to determine the optimal set of CHs.
In PACMSD, sensor nodes only need transmit the information of itself to BS and all the calculation process is operated in the controller module within BS. This method reduces the control overhead in the topology discovery phase and the flow table generation phase. The proposed protocol also uses an on-demand cluster routing which reduces the control overhead similarly. Therefore, PACMSD reduces the control overhead of the network. Table 3 lists the simulation results for different protocols. Thereinto, the energy consumption is the energy consumed for all sensor nodes within a round before the first node dies. It can be seen that PACMSD performs better than comparison protocols in all the network performance.

Conclusion
In this paper, the proposed protocol uses SDN architecture in WSNs. The routing of the entire network is calculated in the controller module. It reduces the computation overhead and the control overhead in sensor nodes. The PSO-based cluster routing algorithm is used for determining the set of the CHs and the sojourn locations of BS. It balances the energy consumption in network. The ABC-based traversal path algorithm is used for calculating the traversal path of the mobile BS. This method reduces the length of the traversal path. According to the simulations, the proposed protocol performs better than MERAM-R, ACO-based protocol and DE-based protocol. It reduces the energy consumption, prolongs the network lifetime, reduces the control overhead and reduces the path length of the mobile BS.
Author Contributions L.S. (PhD student) is the main author of the current paper. She has put forward the main idea, proposed the plan, designed the experiment, and wrote the manuscript. W.M. is the PhD advisor. He has suggested improvements in the main ideas of manuscript research and writing. Z.M. has analyzed the proposed method, proposed improvement suggestions, and modified the grammar of the paper.
Funding This work is supported by Ministry of Education, China-111 project (NO. B17007). This work is supported by Director Funds of Beijing Key Laboratory of Network System Architecture and Convergence (2019BKLNSAC-ZJ-06).

Declarations
Conflicts of interest The authors declare no conflict of interest.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons. org/licenses/by/4.0/.