Fast Program Codes Dissemination for Smart Wireless Software Defined Networks

In smart wireless software defined networks (WSDNs), sensor nodes are deployed in the monitored area to sense data. In order to increase the flexibility of WSDNs configuration, sensor nodes use programmable technology. Thus, programming and software engineering that integrate Internet ofThings (IoT) lead to a smart world. Due to the large capacity of program codes and the limited energy of wireless network, only a subset of nodes is selected to spread program codes, and the remaining nodes are in sleep status to save energy. In this paper, a fast program codes dissemination (FPCD) scheme for smart wireless software defined networking is proposed; many nodes in the area far from the sink will be selected to spread program codes; those areas have much energy left, while the area near the sink chooses less number of active nodes to spread program codes to save energy. Thus, FPCD scheme can reduce delay for spreading program codes while retaining network lifetime.The theoretical analysis and experimental results show that our approach can reduce transmission delay by 10.76%–105.791% while retaining network lifetime compares with previous broadcast schemes.


Introduction
In the Internet of Things (IoT), millions of objects with sensors collect data and send the data to control center servers that analyze, manage, and use the data in order to construct smart world applications, such as smart manufacturing, smart grid, smart and connected health, smart home, and intelligent transportation systems and even smart city [1][2][3][4][5][6].What is more, programming and software engineering are integrated into the Internet of Things and cloud computing, which works towards a smart world.
WSDNs can configure and update program codes in sensor nodes so that IoT has new features, because of the flexibility of configuration and updates of this software, which attracted wide attention of researchers.In WSDNs, program codes in sensor nodes are spread to all network by broadcasting; the program codes have new features after sensor nodes recompiled this program code.Program codes dissemination is a fundamental operation in WSDN [7].Broadcast is one of the main transmission modes for program codes in WSDNs.The aim of broadcast is to propagate program codes to all nodes in a minimum latency.This problem has been studied extensively and has been shown to be NP-hard [8].Some urgent applications such as life monitoring, intelligent transportation systems, and industrial automation often have very stringent requirements on program codes dissemination delay [9], and the system does not work properly by a lack of program codes, which could lead to serious accidents, such as the loss of personnel and property.Nevertheless, the harshness of wireless environments and the characteristics of WSDNs pose severe challenges on designing efficient program codes dissemination scheme.Energy of sensor nodes is limited, and thus sensor nodes usually select a small part of nodes to transmit program codes [10][11][12][13].If the number of active nodes is small, the speed for spreading program codes is slow, and the energy consumption in this time is low; thus, network lifetime is higher.Otherwise, if the larger number of active nodes is selected to transmit program codes, the transmission delay is less, but the network lifetime is low.The issue of tradeoff between lifetime and delay is a challenging issue.There are some researches about program codes (or bulk data) dissemination in wireless sensing networks, those researches mainly focus on how to select the optimal scheduling policy 2 Scientific Programming to minimize energy consumption and broadcasts delay.To the best of our knowledge, these studies only achieved tradeoff between network lifetime and propagation delay, but not optimized network lifetime and the propagation delay at the same time.A fast program codes dissemination (FPCD) scheme is proposed to prolong lifetime and reduce broadcast delay at same time toward smart Internet of Things.The main contributions of the FPCD scheme can be listed as follows: (1) FPCD scheme uses a method of global vision to optimize program codes dissemination and thus reduce program codes dissemination delay while retaining origin broadcasting agreement, which has broad applicability.
In this paper, we not only consider the energy consumption of program codes dissemination, but also the energy consumption of other operations in the network, which can take full advantage of energy to improve broadcast performance.WSDNs not only have broadcast operation of program codes, but also data collection operation.Data operation is a regular behavior, but broadcasting and updating program codes are temporary and infrequent operations [14].For broadcasting program codes, the energy consumption is lower in the area near the sink.But in the process of data collection, the energy consumption in the area far away from the sink is lower, and the energy consumption in the area near the sink is higher.Thus, the FPCD scheme adopts a different strategy, the way is to increase the number of active nodes in the area far away from the sink.Because the transmission delay is related to the number of active nodes, increasing the number of nodes involved in broadcasting can effectively reduce the disseminate delay of program codes.
(2) The optimization parameters and the number of active nodes in different areas are discussed and calculated in the FPCD scheme.The performance of the FPCD scheme outperforms existing ones.Through our simulation study, we demonstrate that, for the proposed scheme, broadcast delay can be reduced and energy efficiency can be enhanced simultaneously.Compared with the former scheme, the broadcast delay can be reduced by as much as 10.76%.More importantly, the proposed scheme improves the performances without harming network lifetime, which is difficult to achieve in the previous schemes.
The rest of this paper is organized as follows.In Section 2, the related works are reviewed.The system model is described in Section 3. In Section 4, a novel FPCD scheme is presented for WSDNs.The performance analysis for FPCD scheme is provided in Section 5. Section 6 shows experimental results and comparison.We conclude in Section 7.

Related Work
Program codes (or bulk data) dissemination has been formulated and investigated in [15].It can be divided into following types depending on different performance requirements of broadcast operation for different application.
(1) The minimum transmission broadcast (MTB) problem: in such studies, the objective of this study is how to reduce broadcast times.In previous schemes, the node is in an active state.Thus, the method for reducing broadcast times is to find a Minimum Connected Dominating Set (MCDS) of the network [16].In a network as a tree, nodes in the tree can cover the entire network.Thus, as long as one node in the tree broadcasts data packet once, all nodes in the tree can receive the data packet.In [17], authors proved that building a minimum flooding tree is identical to finding an MCDS.
In fact, one goal of reducing broadcast times is to reduce energy consumption.The broadcast method about reducing energy consumption has received a lot of researches.Lim and Kim [18] proposed a heuristic algorithm broadcast BIP (broadcast incremental power).It builds a broadcast tree whose root is source node; in the process of building tree, one node uncovered by the tree will be added to the broadcast tree, and the cost paid is minimized.Wieselthier et al. [19] optimized BIP algorithm; it proposed an effective search algorithm -shrink; the energy consumption can be reduced by reschedule the nonleaf nodes of broadcast tree.
In most WSDNs, in order to save energy, a node alternates between dormant and active states, this method is developed and applied to WSNs for energy conservation [20][21][22][23].In broadcast, due to this mechanism that a node is required to transmit broadcast message multiple times to all its neighbor nodes at different moments.As a result, the MTB problem in duty cycled networks (MTB-DC problem) needs to be investigated for solutions in which both the set of forwarding nodes and their broadcast schedules are identified.
Liu [24] proposed Level-Based Approximation Scheme to identify the forwarding nodes and their corresponding receivers for all time slots and then constructed a broadcast backbone by connecting these forwarding nodes to the broadcast source.
(2) The minimum latency broadcast scheduling (MLBS): in this scheme, it reduces not only the energy consumption of node, but also the transmission time for broadcasting [25,26].
Le Duc et al. [25] considered MLBS in duty cycled WSNs and presented two approximation algorithms, BS-1 and BS-2, that produce a maximum latency of at most ((Δ − 1)) and 13, respectively.Here, Δ is the maximum degree of nodes,  denotes the number of time slots in a scheduling period, and  is the broadcast latency lower bound obtained from the shortest path algorithm.
Zhao et al. [26] proposed a Broadcast over Duty Cycle and LEACH (BOD-LEACH) protocol, takes advantage of the LEACH's energy efficient clustering.The proposed protocol added new common static and dynamic broadcast periods to support and accelerate broadcasting.The dynamic periods are scheduled following the past arrivals of messages and using a Markov chain model.
Khiati and Djenouri demonstrated that epidemic theory is suitable for data dissemination by using broadcasting protocols in wireless sensor networks [27].Khiati and Djenouri found that if the number of selected active nodes is large, the energy consumption is higher, the speed of data dissemination is fast, and converge time is lower.Conversely, if the number of selected active nodes is small, the energy consumption is less; thus, network lifetime is high.Previous schemes adopt fixed parameters to ensure network obtains desired level of performance under dynamic environments.Thus, Khiati and Djenouri proposed an epidemic-based algorithm by dynamically adjusting the number of selected active nodes to meet delay requirements while minimizing energy consumption.
The scheme in [27] is the most similar with the scheme about this paper.But the ratio of active node is equal in the whole network for their scheme.The energy left of network cannot be full used; thus, data dissemination converge time is higher.In the FPCD scheme, the active node ratio is determined according to the adequacy degree of energy which can make full use of energy and improve the level of performance for WSDNs.

Network Model. (1)
We consider WSDNs consisting of a large number of homogenous sensor nodes and one sink node.The sink node is regarded as the control center.Those sensor nodes are deployed in the target area such as environment monitor, industrial field, and smart field [27][28][29][30].The network radius is , and the transmission radius of sensor nodes is .The sink node is in the center of a network.The density of sensor nodes in the network is .The sensor nodes are powered by battery whose energy is limited.The energy of the sink is unlimited.
(2) Duty cycling is adopted by nodes to reduce energy consumption.A node has two statues: awake and sleep.The duty cycle is the ratio of time in awake status to the cycle time.When node is in an awake status, the node can spread data.But the energy consumption in this time is higher.And when node is in a sleep status, its wireless transmission device is turned off, and thus the data cannot be transmitted to other nodes, but their energy consumption in this time is lower 100-1000 times than the energy consumption of node when node is in an awake state.Thus, the smaller duty cycle is, the lower the energy consumption is.But, if duty cycle is low, the ratio of active node is small, the delay of data dissemination will be slower, but network lifetime is longer.On the other hand, if duty cycle is high, the ratio of active node is higher, and the delay of data dissemination will be faster at cost of low lifetime.
(3) Senor node senses surrounding environment; when sensor nodes sense event that interests user, the sensed data can be sent to the sink by multiple-hop method.Considering the probability of occurrence of an event is .But when the operating system of sensor node upgrade, or the debug in software of sensor node need to be fixed, the software codes of operating system need to be spread to all nodes in the network.The sink collects the data which are sensed by node, this process is called data collection, and the process for disseminating program codes to each node is called data dissemination.

Energy Consumption Model.
In this paper, we adopt the topical energy consumption model in [28][29][30][31][32][33], where the transmission energy consumption,   , follows (1) and energy consumption,   , for receiving the following (2): where  elec represents transmitting circuit loss.Both the free space ( 2 power loss) and the multipath fading ( 4 power loss) channel models are used.If the transmission distance is less than the threshold  0 , the power amplifier loss is based on free space model; if the transmission distance is larger than or equal to the threshold  0 , respectively, the multipath attenuation model is used. fs and  amp are the energy required by power amplification in the two models.

Problem Statement.
In a WSDN, the sink disseminates program codes to sensor nodes; then, the sensor nodes diffuse those program codes to the nodes far from the sink.The aim of this paper is to reduce the dissemination delay [34] while minimizing energy consumption.Thus, the aims of this paper are as follows.
(1) Minimization Program Codes Dissemination Delay.In this paper, the dissemination (or broadcast) delay refers to the time between the sink (control center) disseminates program codes and all nodes receive the program codes except for the nodes that never receive program codes through broadcast.Let  init be the time before broadcast program codes, and let  end be the time when all nodes receive the program codes.Thus, the broadcast delay  can be expressed as (2) Maximization Network Lifetime.Network lifetime Γ refers to the elapsed time when the first node dies in the network.
Because the death of first node can affect the connection of network, the program codes sent by the sink cannot broadcast to all nodes.Thus, the aim of this paper is to prolong network lifetime.Let  init stand for the initial energy of nodes in the network, and let   be the consumption energy of node in the network.Thus, network lifetime can be expressed as follows: (3) Maximization Effective Energy Utilization Rate (Denoted as ). refers to the ratio of energy consumption of network to the total energy in the network.  is the energy consumption of node in the network;  init is the initial energy of node in the network.Our target is to maximize energy utilization of whole the network.Thus, the effective energy utilization can be expressed as follows: ) .
(5)  Obviously, the goal of the FPCD is to minimize delay, , maximize the network life, Γ, and make effective energy utilization, , which can be summarized as follows:

Research Motivation. (1)
The energy left in non-hotspots area is abundant but not in use.
Besides program codes dissemination, WSDNs can collect data from sensor nodes.In the process of data collection, sensor nodes in the network send data to the sink, nodes in the area near the sink transmit much more data to the sink, and thus the energy consumption of nodes in the area near the sink is more than the energy consumption of nodes in the area far away from the sink.It is shown in Figure 1 that the energy consumption of node is unbalanced.The left energy of node is given in Figure 2. As can be seen, many nodes in the network have much energy left.According to relevant research, when the network dies from hotspots problem, the energy left in the network is up to 90%.Thus, the main idea of proposed scheme is to make full use of the energy left in the nonhotspots area to increase the number of active nodes to transmit program codes to reduce dissemination delay.
(2) The number of active nodes is large and the dissemination delay is small, but the energy consumption is higher.
When the sink spreads program codes to all nodes except the nodes that never receive program codes in the network, if the dissemination delay of program codes is smaller, the performance in the network is better.However, in WSDNs, nodes use the way of duty cycling to save energy.When duty cycle of network is smaller, the ratio of active node in the network is lower, and the number of nodes in an awake status is smaller, resulting in the speed for spreading program The number of active nodes The transmission delay codes being slower; thus, the transmission delay is bigger.Figure 3 shows the relationship between delivery delay and different number of active nodes.As can be seen, the more the number of active nodes is, the less the dissemination delay is.For some emergency event, the number of active nodes should be increased to reduce transmission delay.The reason is that if there are many active nodes, the sink will have many neighbor nodes in the range of transmission radius.When the sink node wants to spread program codes to the network.In program codes transmission, the program codes can be spread from one node to many nodes, the time for spreading program codes to the network is short, and the transmission delay is less.Otherwise, the transmission delay is higher.
(3) If using energy left in the network to increase the number of active nodes, the dissemination delay can be reduced while retaining network lifetime.
In previous schemes, the system cannot reduce dissemination delay under the condition that network lifetime cannot be reduced.The reason is that the larger the number of active nodes is, the less the transmission delay is, but the higher the energy consumption of node is.Thus, increasing the number of active nodes may affect the energy consumption to damage network lifetime.The relationship between the energy consumption and the number of active nodes is shown in Figure 4. From Figure 4, with the number of active nodes growing, the energy consumption grows.The main idea of the proposed scheme is to make full use of the energy left in the network to increase the number of active nodes to reduce the transmission delay.In the FPCD scheme, the number of active nodes is adjusted dynamically according to the energy left in the network while retaining network lifetime.
From the above analysis, the broadcast quality of overall network is based on the residual energy.Adjusting the number of active nodes dynamically can achieve better comprehensive broadcast performances.For this reason, a fast program codes dissemination (FPCD) scheme is proposed.

The Calculation of Energy Consumption of the Network.
The nodes at different distances from the sink have definite energy consumption.The value is given by theoretical analysis.Considering that all nodes in network adopt the same duty cycle.The energy consumption of nodes at different areas is calculated.
Firstly, because nodes in different areas use same duty cycle, the number of active nodes in different areas is the same.Due to the same broadcast operation in different areas, the energy consumption in different areas is the same.But the main operation of WSDN is data collection.In the process of data collection, the energy consumption is unbalanced, the energy consumption for data collection is given in Theorem 1.

Theorem 1.
Considering network radius is , transmission radius of node is .The probability of occurrence of an event is , each data packet is transmitted to the sink using shortest routing path.Considering node  whose distance from the sink is ,  =  + ,   is the energy consumption for transmission of one-bit data.  is the energy consumption for receiving one-bit data.After one round of data collection, the energy consumption    for data operation of node  is Proof.Considering network radius is , the node transmission radius is , the generation rate of event is .The data packet is routed based on the shortest routing.Considering node whose distance from sink is ,  = ℎ + , where ℎ is the hop counts from the node to the sink.The number of transmitting data loaded by this node is The number of receiving data loaded by this node is And   is the energy consumption for transmitting data.  is the energy consumption for receiving data.So the energy consumption of node  is

Adjustable Calculation of the Number of Active Nodes.
Compared with previous scheme, the FPCD scheme can adjust the number of active nodes based on the remaining energy.Therefore, the calculating method of the number of active nodes in different regions of the network is given in this section.
Theorem 2. Considering node  whose distance from the sink is ,  = ℎ + ,   is the energy consumption for transmission one bit data.  is the energy consumption for receiving one bit data. is the length of program codes.The number of active nodes in the area at  m distance from the sink is   in one duty cycle, after one round of program code transmission, the total energy consumption    of the area whose distance from the sink is  is Proof.In the FPCD scheme, for node  whose distance from the sink is ,  = ℎ+.When the sink spreads program codes to all nodes except the nodes that never receive the packet, the total energy consumption of the area whose distance from the sink is  include two kinds of energy: one is the energy consumption for receiving program codes from the last hop node and the other energy consumption is the consumed energy for spreading program codes to the next hop nodes.
There are   active nodes in this area, this area will receive   program codes from the last node, and thus the energy consumption for receiving those program codes is But those program codes should be spread to next nodes; in the next areas, there are  + active nodes, each active node should receive those program codes once.Thus, the energy consumption for transmitting program codes is The total energy consumption   pro of the area whose distance from the sink is  is Theorem 3. Considering node  whose distance from the sink is ,  = ℎ + . max is the maximum energy consumption for data collection and spread program code in the network.
The number of nodes in the area at  distance from the sink is    .In the FPCD scheme, considering the optimized number of active nodes in the area at  = ℎ +  distance from the sink is Proof.In the FPCD scheme, the aim is to make full use of the energy left to increase the number of active nodes to reduce the transmission delay.For node  whose distance from the sink is ,  = ℎ + .According to Theorem 2, the total energy consumption of the area at  m distance from the sink is   pro , the energy consumption of nodes at  m distance from the sink is   data according to Theorem 1.In order to increase the number of active nodes to reduce transmission delay while retaining network lifetime, the total energy consumption in this area at  m distance from the sink is   pro +  total   data .Thus, the difference between the maximum energy consumption of the network and the total energy consumption in this area is Δ =  max − (  pro +   total   data ).The total energy consumption of this area should be close to the maximum energy consumption to make full use of the energy left in this area.That is, It can be seen that   can be instead as   , and  is a constant.Equation ( 16) is The optimizable number of active nodes in different areas is 4.4.Scheduling Method.The number of active nodes is adjusted adaptively by the FPCD scheme according to the energy left of node.The main goal of FPCD scheme is to increase the number of active nodes in the area far away from the sink to reduce the transmission delay while retaining network lifetime.In this paper, program codes are transmitted to all nodes after the sink receives the data from all sensor nodes.First, the sink collects data from sensor nodes, and the nodes consume energy.Second, the sink spreads program codes.This scheme mainly studies the program codes transmission.In the beginning of program codes transmission, the energy of nodes is the energy left of node in data collection.In the process of data collection, sensor nodes sense data from the surrounding environment, and then the sensed data can be transmitted to the sink.When those data packets are transmitted from the area at  distance to the sink, the message about energy consumption for transmitting data packet is recorded in the area at  distance from the sink; it is   .In the FPCD scheme, when the sink spreads program codes to nodes in the network, the program codes can be spread to their neighbor nodes, until the program codes to all nodes except the nodes that never receive the program codes.Before the sink spreads the program codes, the maximum energy consumption  max is set as 0, the message about  max is stored in the program codes.When one node receives the program codes, the energy consumption of node  for transmitting the program codes is   , the area where the node stays will record the energy consumption If   >  max , the maximum energy consumption can be instead as   ; that is,  max =   .After a round of program codes transmission, the message about the maximum energy consumption of nodes will be returned to the sink.Considering the requirements transmission delay is   , the transmission delay in this transmission is   .In the FPCD scheme, its aim is that the number of active nodes can be adjusted dynamically to ensure the transmission delay   in program codes dissemination smaller than the requirement transmission delay   , and network lifetime is higher as soon as possible.
The sink will send messages including ( max ,   ,   ) to nodes at  distance from the sink.For node  at  distance from the sink, when node  receives the message from the sink, if   >   , it shows that the transmission delay in this time is bigger than the requirement transmission delay, the number of active node should be increased to reduce transmission delay.But if   <   , it shows that the transmission delay in this time is smaller than the requirement transmission delay, the number of active node should be reduced to improve network lifetime.
When   >   , the transmission delay is higher than the requirement transmission delay, the number of active nodes should be increased, and the method for increasing the number of active node is as follows.
(1) When node  receives the feedback message from the sink, it first computes the energy difference between the maximum energy consumption  max and the energy consumption   ; it is as follows: When the area at  distance from the sink increase one active node, the energy consumption in the area can increase  Δ , the number of increased active nodes is If Δ < 1, the number of active nodes will add 1 in the next round of program codes dissemination, if the energy consumption of this area is lower than  max , the number of active nodes is correct in this area.But when the energy consumption of this area is higher than  max , the number of active nodes does not need to be adjusted.
If Δ > 1, the areas at  distance from the sink will increase by Δ active nodes, the number of adjustable active nodes in this area is as follows: The number of active nodes will be instead with the value   + Δ if the transmission delay is smaller than the requirement transmission delay in the next process of program codes transmission.But if the transmission delay is higher than the requirement transmission delay in the network, the number of active nodes will be instead with   + Δ, and the number of active nodes in the areas nearest the sink adds one.
When   <   , the transmission delay is smaller than the requirement transmission delay; in order to improve the network lifetime, the number of active nodes in the area near the sink is reduced by 1.
Each area at  distance from the sink has marking information B  which is used to express whether the number of active node in this area should be adjusted.B  = 1 shows the number of active nodes in this area should be adjusted in the next process of program codes transmission, B  = 0 shows the number of active node in this area is not adjusted in the next process of program codes transmission, continuing the process of adjusting the number of active nodes in different areas, until all B  are 0 in the network.It shows the number of active nodes in this area is optimized.
When nodes are in an active status, the nodes will spread program codes in the duty cycle time, until the program code reaches all nodes except the nodes that never receive program codes.The number of active nodes in the area will be adjusted in the next cycle time, until the system reaches stable status.
The FPCD scheme algorithm is given in Algorithm 1.

Performance Analysis in Theory
5.1.Broadcast Delay Analysis.This section analyzes the transmission delay in the FPCD scheme.Program codes are generated by the sink and then are spread to the area far away from the sink.In this paper, the broadcast method for At this stage, the area of program codes dissemination is not expanded, but the number of broadcast nodes is increased.Thus, the delay of program codes dissemination can be divided into two parts: (1) the delay in the expansion phase; (2) the delay in stabilization phase.The delay in the expansion phase mainly depends on the time for spreading program codes to the network boundary.However, the requirement time for spreading program codes to the network boundary is very complex; it depends on several factors: (1) network size: the larger the network is, the longer the transmission delay is; (2) the transmission radius of node: the bigger the transmission radius is, the farther the transmission distance is when program codes are transmitted once, and thus the lower the transmission delay is; (3) the ratio of active node: apparently, the larger the number of active nodes is, the farther the distance traveled is, and the smaller the delay is.In the following, we analyze the expected distance for spreading program codes to the area far away from the sink, so that the expected hop for spreading program codes to the network boundary can be got in theory, which can obtain the minimum expected propagation delay in the first stage.
Definition 4 (dissemination forwarding distance ).As shown in Figure 5, node  is broadcast node, node  is in the transmission range of node , and the distance from node  to the sink is farther than the distance from nodes in the transmission range of node  to the sink. line  is used to connect the sink  and node , and  is the intersection of broadcast radius of node  and line .The length from longitudinal projection point of node  in line  to  is broadcast forwarding distance .
/ * * the requirement minimum transmission delay is   , the energy consumption of the area at  distance from the sink is   after the data collection is over.* * / Initialize: each area at  distance from the sink records the energy consumption in the last program code spread period:   .The maximum energy consumption  max = 0. Δ is a delay threshold Part I: The action of node in message report to sink: (1) For program code P which reach node  at  distance from the sink Do (2) E  =   +   ; // the energy consumption will be record in // this area ( 3) End if (6) (25) If (the current reliability do not meet the requirement of application) // the number of active nodes in the area near sink can be reduced.(26) L e t  =   − 1 // The number of active nodes in the area with largest energy consumption minus 1 End if (27) End if (28) End for (29) For each data flow where   > 0 and |  | > Δ // the current transmission delay is bigger than that the requirement // transmission delay of application, the number of active nodes // should be increased.( 30) Continuesteps( 15), ( 16), (17), and (18) (31) If the area at  distance from the sink receives the tuples; (32) If B  = 1 // The number of active nodes in this area is increased (33) The number of active nodes in this area should be adjust according to steps (45)-( 51 Because the transmission range is , broadcast forwarding distance  is in [0, 2].If  > , this shows that program codes can be transmitted to nodes whose distance from the sink is longer than the distance from node  to the sink.But if  < , this shows that program codes cannot be transmitted to nodes whose distance from the sink is longer than the distance form node  to the sink.The reason is that when node  broadcasts program codes, all nodes in the broadcast radius range of node , whose distance from the sink is longer than the distance from node  to the sink, are in sleep states, and areas whose distance from the sink is shorter than the distance from node  to the sink have active nodes, and thus  < .Such a broadcast is meaningful, and the program codes can be spread in the next time.
Theorem 5. Considering the distance from node  to the sink is  m, the transmission radius is  and the density of network is .The ratio of active node is .When program codes are spread once by node , the expected traveled propagation distance is G  : where 2 . ( Proof.As shown in Figure 5, when the maximum distance for spreading program codes is  −  + , it shows that all nodes in the shaded areas are in sleep status, but some nodes in the range of  −  +  distance are in active status.The area of the black shaded area in Figure 6 is calculated as follows: the sector area ∢ as the center of  minus arcuate area Ĉ which is the intersecting area of the arc as the center of the sink  and the arc as the center of .The arcuate area Ĉ is divided into two parts: one is the area of the red shaded part, and the other is the area of triangle R.The area of the red shaded part is the sector area ∢ minus the area of triangle R.Due to  = ∠ = 2cos −1 (( 2 + ( +  − ) 2 −  2 )/2( +  − )).Thus, the area of sector area ∢ is 2cos −1 (( 2 + ( +  − ) 2 −  2 )/2( +  − ))( +  − ) 2 , the length of line  is ( 2 + ( +  − ) 2 −  2 )/2, and the length of line  is √( +  − ) 2 − (( 2 + ( +  − ) 2 −  2 )/2) 2 .The area of triangle R is as follows: Thus, the area of red shaded area is 2 . (26) The length of line  is ( 2 + ( +  − ) 2 −  2 )/2 −  = (( +  − ) 2 −  2 −  2 )/2.The area of triangle R is ).Thus, the area of sector area ∢ is 2 2 cos −1 ((( +  − ) 2 −  2 −  2 )/2), the area of the black shaded area in Figure 6 is However, the number of nodes in shaded area is    , the probability of which all nodes in shaded area are in sleep status is (1 − )     .But the probability of which area within the range of distance  −  +  from the sink has nodes in awake status is as follows: considering the width of this area is   |   → 0, thus the area of this area is ( −  + )  .
The number of nodes in this area is ( −  + )  ; thus, the probability of which area has one node at least in awake status is as follows: The probability of spreading program codes to the area at  −  +  distance from the sink is as follows: In this time, the forward propagation distance is  − .Therefore, the total expected forwarding distance is as follows: Since the expected forwarding distance is shown in Theorem 5 when program codes is spread in one hop, the following will estimate broadcast times of spreading program codes from the sink to the network boundary.G  in Theorem 5 is the expected forwarding distance of spreading program codes from nodes at  m distance from the sink to other node.Because the G  in different distance has little difference, using G to express the forwarding distance in the network with transmission radius is .If the distance from the sink to the network boundary is , the hop count can be calculated as Since the delay for spreading program codes in each hop is , the time for spreading program codes from the sink to the network boundary is H  .When program codes is spread to the network boundary, the network will be into the second stage.In the process of spreading program codes to network boundary, nodes that receive program codes will broadcast the program codes to neighbor nodes, nodes in the network boundary will be the last to receive the program codes.Thus, the time for spreading program codes in second stage is the time of spreading program codes to nodes in the network boundary.The required time in second stage is regarded as the time in which all nodes in the broadcast cycle receive program codes, considering the duty length of node is , its duty cycle  can ensure the ratio  of active node.Because program codes can be broadcast once in one , thus after (1/) cycle, each node will be in awake status once, all nodes can receive the program codes.From the above analysis, it can be obtained that the propagation delay of the entire network is as follows: Theorem 5 gives the dissemination forwarding distance.Many factors affect dissemination forwarding distance; Figure 7 shows the relationship between the active node ratio and forwarding distance.In Figure 7, the forwarding distance refers to the transmission distance for spreading program codes to the area far away from the sink; it is expressed as ⃗ .As can be seen from Figure 5, if most areas in the transmission radius of node  do not have nodes in active status, then ⃗  ≤ 0. The probability of this situation is (1 − )  2 /2 , it is small.Thus, generally speaking, ⃗  > 0. The bigger  is, the probability that there are active node in the area far away from the sink in the range of broadcast of node  is bigger, and ⃗  is larger.The results are shown in Figure 7; the bigger  is, the bigger ⃗  is, which shows that the forwarding distance of broadcast once is bigger, and the delay of spreading program codes to entire network is smaller.
Figure 8 shows the ⃗  in different .Its trend is the greater node density is, the greater its ⃗  is.If the number of active nodes is large, the probability that the node far away from the sink in the range of broadcast of node  receive program codes is larger, the longer the forwarding distance is.At the same time, when the density of node is increased, program    codes are easily diffused and the delay for spreading program codes is smaller.
Figure 9 shows the forwarding distance under different transmission radius .As can be seen, the bigger  is, the bigger ⃗  is, and the smaller the transmission delay is.But when  = , the delay of network in the first stage is 0. Figure 10 gives ⃗  under different  and .The rule is that the bigger  is and the bigger  is, the bigger ⃗  is.Figures 11 and 12 give the transmission delay under different node density  and different active node ratio .The transmission delay in the figure is referred to the expected delay of network.The rule is that when the node density and the active node ratio  are increased, the dissemination delay is reduced.Its reason is that when  and  are increased, large number of nodes can receive the program codes in program codes dissemination, the data can be broadcast to other nodes by those nodes, the speed for broadcasting data is fast.When  and  are increased, the forwarding distance is longer when program codes broadcast once according to Theorem 5, the speed of spreading program codes to network boundary is fast, and the delay is small.The bigger  is, the longer forwarding distance is, and the smaller the delay is.
Based on Section 4, Figure 13 shows the value of  in different areas.In the FPCD scheme, the area near the sink adopts the same  with the previous scheme; it is the initial values 0.2 and 0.3 of  in Figure 13.Then, the FPCD scheme increases the  in the area far from the sink according to the energy consumption.It can be seen that  in the area far away from the sink is higher than the initial .
Since different areas have different  in the FPCD scheme, the forwarding distance in different areas is different.The  bigger  is, the longer the forwarding distance is, and the delay is smaller; it is shown in Figure 14. Figure 15 gives the dissemination delay in the FPCD scheme and other schemes.
Compared to the scheme with the same , the dissemination delay in the FPCD scheme is reduced by 13.25%-27.57%.

Broadcast Times Analysis.
In program codes dissemination, broadcasting program codes is the most energyconsuming operation; therefore, the best method to save energy is to reduce broadcast times.There is an example to illustrate the relationship of  and broadcast times.The bigger  is, the smaller the requirement broadcast times are.The most special case is that when  = , it shows that the sink broadcasts program codes once, and all nodes in the network can receive program codes.If  = 1, all nodes in the network can receive data when the sink spread program codes once.But if  is smaller, the number of nodes that receive data is less;  thus, the requirement broadcast times are long.Theorem 6 gives the requirement broadcast times in a certain .
Figure 16 shows the relationship between  and broadcast times.With the increase of , the requirement broadcast times of program codes dissemination are reduced.The broadcast times can be obtained according to the different  in different areas in Figure 13 and Theorem 6 (see Figure 17).Finally, Figure 18 shows the total broadcast times in the FPCD scheme and other schemes; it can be seen that the FPCD scheme can reduce the requirement broadcast times greatly.ratio of active node is .The requirement broadcast times B of all the network and the number of receiving data R are Proof.The number of nodes within the communication range is n  =  2 .When one node broadcasts program codes, n  − 1 nodes will receive the data.Because the status of node will change in the (1/) cycle, thus the number of nodes updated is n  each cycle.That is to say, in the (1/) cycle, the status of each node can be updated once, and there are The same active ratio scheme with initial  = 0.2 FPCD scheme with initial  = 0.5 The same active ratio scheme with initial  = 0.5  The number of broadcast packets in the network is n  =  2 .A total of communication cell is m =  2 / 2  =  2 / 2 ; thus, the amount of broadcast in entire network is as follows: broadcast time is B = m(1/) = ( 2 / 2 )(1/); the times for receiving data are as follows: Scientific Programming

Energy Consumption and Network Lifetime
Analysis.This section analyzes the energy consumption in the FPCD scheme and previous schemes.Firstly, as long as the network has energy left, the FPCD scheme can make full use of left energy to increase the number of active nodes, thereby improving the performance of program codes dissemination.Thus, energy efficiency in the FPCD scheme is 100% in theory.
Considering the energy efficiency in other schemes.From the above analysis, each node receives program codes once.If one node receives new data, the node can spread the data once.Thus, the energy consumption of program codes dissemination is balanced.But in the process of data collection, the energy consumption of network is not balanced.The energy left of network is given.
In the process of data collection, the energy consumption of node nearest the sink is The energy consumption of the area at  distance from the sink Thus, the energy left in the area at  distance from the sink is The remaining energy of entire network is that considering a small arc area at the  distance from the sink, the width of the arc area is   ; when   → 0, the area of this arc area is 2  ; thus, the remaining energy of this area is 2     .So the energy left of all network is as follows: The available energy consumption of the network is  2  max .
Thus, the energy efficient is as follows: Based on the above analysis, Figure 19 gives the energy consumption of data collection in different areas.As can be seen, the energy consumption in the area near the sink is higher than the energy consumption in the area far away from the sink; thus, the area far away from the sink has much energy left.It can be seen from Figure 20 that most areas have 80% energy left; the average energy left reaches 90%. Figure 21 shows the energy consumption in the FPCD scheme and the previous scheme.It shows that the remaining energy network can fully be used for program dissemination, the FPCD scheme has a very high energy efficiency, and it is more than 4 times that in other strategies.

Experimental Results and Analyses
OMNET++ is employed for experimental verification [35].Without loss of generality, the network parameters are as follows: network radius  = 400 m, packet transfer radius  = 50 m, event generation probability of node in one round  = 0.1, and 200 nodes are deployed.Other parameters settings refer to Table 1.We compare FPCD scheme against the same active ratio scheme.In the same active ratio scheme, the  number of active nodes in different areas is the same.That is, the number of active nodes in the area far from the sink is the same as the number of active nodes in the area near the sink.Program codes not only are transmitted to the network boundary but also are transmitted to the neighbor nodes.The aim is that all nodes in the network receive the program codes produced by the sink.

Comparative Analysis of Broadcast Times.
The number of broadcast nodes is shown in Figure 22.As can be seen, the number of broadcast nodes in the FPCD scheme is higher than that in the same active ratio scheme.When the ratio of active nodes in the area near the sink is 30%, the number of broadcast nodes in those two schemes is higher than the number of broadcast nodes in the network with 20% active nodes in the area near to the sink.The ratio of the number of broadcast nodes in the FPCD scheme to the same active ratio scheme is shown in Figure 23.From Figure 23, the number of broadcast nodes in the FPCD scheme is 1.08889-2 times that in the same active ratio scheme when the ratio of active nodes in the area near the sink is 30%.The number of broadcast nodes in the FPCD scheme is 1.08824-2.5times that in the same active ratio scheme when the ratio of active nodes in FPCD scheme with 30% ratio of active nodes near the sink The same active ratio scheme with 30% ratio of active nodes near the sink FPCD scheme with 20% ratio of active nodes near the sink The same active ratio scheme with 20% ratio of active nodes near the sink  FPCD scheme/the same active ratio scheme with 30% ratio of active nodes near the sink FPCD scheme/the same active ratio scheme with 20% ratio of active nodes near the sink Rounds The ratio of the number of broadcast nodes the area near to the sink is 20%.It shows that FPCD scheme has better performance.

Comparative Analysis of Broadcast Delay.
The transmission delay of network under different proportion of active nodes in the area near the sink in the FPCD scheme and the same active ratio scheme is given in Figure 24.As can be seen, (1) with the increase of the ratio of active nodes Scientific Programming in the area near the sink, the transmission delay of network is reduced in those two schemes.The reason is that with the increase of ratio of active nodes in the area near to the sink, the energy consumption of the nodes nearest the sink is increased.Thus, there is more energy left in the areas far away from the sink, the energy left in the areas far away from the sink should be used to increase the number of active nodes while retaining the network lifetime.Thus, the program codes can be transmitted to all nodes except the nodes that never receive the program codes with a short time.
(2) The transmission relay of network in the FPCD scheme is smaller than that of the same active ratio scheme.
The ratio of transmission delay of network under different ratio of active nodes in the area near the sink in the FPCD scheme to the same active ratio scheme is given in Figure 25.As can be seen, the transmission delay of network in FPCD scheme is 0.63921 times that in the same active ratio scheme when the ratio of active nodes in the area near the sink is 30%.It shows that the FPCD scheme has better performance.
The transmission delay of network under different transmission radius  in the FPCD scheme and the same active ratio scheme is given in Figure 26.It can be seen that no matter what the transmission radius  is, the transmission delay of network in the FPCD scheme is smaller than that of the same active ratio scheme.The transmission delay of network is reduced with the increase of transmission radius .The reasons are that (1) in the FPCD scheme, the number of active nodes in the area far away from the sink is increased, when the sink spreads program codes to nodes; there are many nodes in the range of transmission radius; the program codes can be spread to all nodes quickly; thus, the program codes can be spread to all nodes except the nodes that never receive the program codes with a very short time.In the FPCD scheme, the number of active nodes in the area far away from the sink is increased.Thus, the transmission delay The ratio of active nodes in the area near the sink FPCD scheme/the same active ratio scheme The ratio of transmission delay FPCD scheme with 40% ratio of active nodes near the sink The same active ratio scheme with 40% ratio of active nodes near the sink FPCD scheme with 20% ratio of active nodes near the sink The same active ratio scheme with 20% ratio of active nodes near the sink is reduced.(2) When the  increase, the hop count from the sink to nodes which are farthest from the sink is reduced.When the sink spread the program codes to the nodes, the program codes can reach the nodes far away from the sink in a small hop count, so the transmission delay is reduced.
The ratio of transmission delay of network under different transmission radius  in the FPCD scheme to the same active ratio scheme is given in Figure 27.The transmission delay in FPCD scheme is 1.1076-2.05791times that in the same active FPCD scheme/the same active ratio scheme with 40% ratio of active nodes near the sink FPCD scheme/the same active ratio scheme with 20% ratio of active nodes near the sink r The ratio of transmission delay ratio scheme when the ratio of active nodes in the area near the sink is 20%.The transmission delay of network under different network radius  in the FPCD scheme and the same active ratio scheme is shown in Figure 28.It can be seen that the transmission delay of network in the FPCD scheme is smaller than that in the same active ratio scheme.The transmission delay of network is increased with the increase of network radius .The larger the network radius  is, the hop counts from the sink to the nodes which farthest from the sink is increased due to the fixed transmission radius.Thus, when the sink sends program codes, the nodes which are farthest  from the sink receive the program codes at more hop count, resulting in bigger transmission delay.

Comparative Analysis of Energy Consumption and Network Lifetime.
The energy consumption of nodes in different areas in the FPCD scheme and the same active ratio scheme is given in Figure 29.As can be seen, (1) when the nodes' distance from the sink is 10, the energy consumption of nodes in the area in the FPCD scheme is lower than that in the same active ratio scheme.(2) But when the nodes' distance from the sink is bigger than 20, the energy consumption of nodes in those areas in the FPCD scheme is higher than the energy consumption of nodes in those areas in the same active ratio scheme, and the energy consumption in those areas is not bigger than the maximum energy consumption in the network, which shows that the FPCD scheme cannot affect the network lifetime.The reason is that, in the FPCD scheme, the number of active nodes in the area far away from the sink is increased.The number of receiving program codes is more, and the number of transmitting program codes is more.Thus, the energy consumption in this area in FPCD scheme is much higher than that of the same active ratio scheme.
The ratio of energy consumption of nodes in different areas in the FPCD scheme to the same active ratio scheme is shown in Figure 30.It can be seen that (1) when the nodes' distance from the sink is 30, the energy consumption of this area in FPCD scheme is 0.96263 times that of the same active ratio scheme.In the other areas, the energy consumption in the FPCD scheme is 1.00148-10.23938times that in the same active ratio scheme.It shows that the FPCD scheme can make full use of the energy left in the area far from the sink while retaining network lifetime.
The total of energy consumption under different ratios of active nodes in the area near the sink in FPCD scheme and the same active ratio scheme is given in Figure 31.As can be seen, (1) with the increase of the ratio of active nodes The ratio of active nodes in the area near the sink

PCDE scheme
The same active ratio scheme in the area near the sink, the total of energy consumption is increased.
(2) The total of energy consumption in the FPCD scheme is higher than that in the same active ratio scheme.
In the FPCD scheme, the number of active nodes in the area far from the sink is increased.When the proportion of active nodes nearest the sink is increased, the energy consumption of nodes near the sink is higher.Thus, there is more energy left to increase the number of active nodes in the areas far away from the sink.Thus, the number of active nodes in the areas far away from the sink is more.Nodes in areas far from the sink consume more energy, and thus the total of energy consumption in the network increased.Network lifetime under different proportion of active nodes nearest to the sink in the FPCD scheme and the same active ratio scheme is given in Figure 32.As can be seen, the network lifetime in the FPCD scheme is not lower than that in PCDE scheme.Though the total of energy consumption in the FPCD scheme is higher than that in the same active ratio scheme, the FPCD scheme cannot affect the network lifetime.
The total of energy consumption under different network radius  in the FPCD scheme and the same active ratio scheme is given in Figure 33.From Figure 33, the total of energy consumption in the FPCD scheme is higher than that of the same active ratio scheme.In the FPCD scheme, the number of active nodes in the area far from the sink is increased.When the sink spreads program codes, nodes far from the sink receive large number of program codes from the last nodes, and the energy consumption in this areas for receiving the program codes is increased.But at the same time, those nodes will transmit those program codes to many active nodes, the energy consumption for transmitting program codes is increased.In the same active ratio scheme, the number of active nodes is the same in different areas.Thus, the total of energy consumption in the FPCD scheme is higher than that in the same active ratio scheme.It can be seen from Figure 29.The energy consumption in the area near to the sink in the FPCD scheme is smaller than that in the same active ratio scheme and the energy consumption in other areas in the FPCD scheme is higher than that of the same active ratio scheme.The total of energy consumption in the FPCD scheme is higher than that of the same active ratio scheme.It shows that the FPCD scheme can improve energy efficient.
Network lifetime under different network radius  in the FPCD scheme and the same active ratio scheme is given in Figure 34.As can be seen, the network lifetime in the FPCD scheme is not lower than that in the same active ratio scheme.FPCD scheme with 40% ratio of active nodes near the sink The same active ratio scheme with 40% ratio of active nodes near the sink FPCD scheme with 20% ratio of active nodes near the sink The same active ratio scheme with 20% ratio of active nodes near the sink Though the number of active nodes in the area far away from the sink is increased, the energy consumption of this area is not higher than the energy consumption of nodes near to the sink.Thus, the network lifetime in the FPCD scheme is not lower than that of the same active ratio scheme.
The total of energy consumption under different network radius  in the FPCD scheme and the same active ratio scheme is given in Figure 35.From Figure 35, the total of energy consumption in the FPCD scheme is higher than that in the same active ratio scheme.With the increase of the network radius , due to the fixed transmission radius , the hop counts from the sink to nodes farthest from the sink are increased.The energy consumption for spreading the program codes from the sink to nodes farthest from the sink is higher.So the total of energy consumption of network in the FPCD scheme is higher than that in the same active ratio scheme.
Network lifetime under different network radius  in the FPCD scheme and the same active ratio scheme is given in Figure 36.As can be seen, network lifetime in the FPCD scheme is not lower than that of the same active ratio scheme.It shows that the FPCD scheme cannot damage the network lifetime.Tough the FPCD scheme has better performance from Figure 36, it makes full use of the energy to improve the number of active nodes far from the sink.

Conclusion
WSDNs have the important function for propagating program codes, but for some urgent applications, they often have The same active ratio scheme with 40% ratio of active nodes near the sink FPCD scheme with 40% ratio of active nodes near the sink very stringent requirements on program codes dissemination delay.So it is important to minimum transmission delay for spreading program codes while maximizing the network lifetime.In previous schemes, the transmission delay and network lifetime cannot be optimized at the same time.
In this paper, a fast program codes dissemination (FPCD) scheme for wireless software defined networking is proposed to reduce the transmission delay while maximum network lifetime.The innovation of FPCD scheme is that the number of active nodes in different areas can be adjusted dynamically according to the energy difference between the energy consumption in this area and the maximum energy consumption in the network.The energy left can be full used to increase the number of active nodes to reduce the transmission delay while maximum the network lifetime.Thus, FPCD scheme has better performances.

Figure 2 :
Figure 2: The left energy of WSDN.

Figure 3 :
Figure 3: The dissemination delay under different number of active nodes.

Figure 4 :
Figure 4: The energy consumption in different areas.

Figure 5 :
Figure 5: The illustration of the broadcast forwarding distance.

Figure 6 :
Figure 6: The calculation of the broadcast forwarding distance.

Figure 7 :
Figure 7: The relation of  and forwarding distance.

Figure 8 :
Figure 8: The relation of  and forwarding distance.

2 5 Figure 13 :
Figure 13: The value of  in a FPCD scheme.

Figure 14 :
Figure 14: The forwarding distance in a FPCD scheme.

Theorem 6 .Figure 15 :Figure 16 :
Figure 15: The dissemination delay in FPCD scheme and other schemes under different .

Figure 17 :r
Figure 17: The broadcast times in different areas in FPCD scheme and other schemes.

Figure 18 :
Figure 18: The broadcast times in FPCD scheme and the scheme with same  under different .

Figure 19 :Figure 20 :
Figure 19: The energy consumption for data collection in different areas.

Figure 21 :
Figure 21: The energy efficiency in the FPCD scheme and other schemes.

Figure 22 :
Figure 22:  The number of broadcast nodes in FPCD scheme and the same active ratio scheme.

Figure 23 :
Figure 23:The ratio of number of broadcast nodes in FPCD scheme to the same active ratio scheme.

Figure 24 :
Figure 24: The transmission delay under difference ratio of active nodes in the area near the sink.

Figure 25 :
Figure 25:The ratio of transmission delay under difference ratio of active nodes in the area near the sink in FPCD scheme to PCDE scheme.

Figure 26 :
Figure 26: The transmission delay under different transmission radius  in FPCD scheme and the same active ratio scheme.

Figure 27 :Figure 28 :
Figure 27:The ratio transmission delay under different transmission radius  in FPCD scheme to the same active ratio scheme.

Figure 29 :
Figure 29: The energy consumption in different areas.

Figure 30 :
Figure 30: The ratio of energy consumption in different areas in FPCD scheme to PCDE scheme.

Figure 31 :
Figure31: The total of energy consumption under different ratio of active nodes in the area near the sink in FPCD scheme and the same active ratio scheme.

Figure 32 :
Figure32: Network lifetime under different ratio of active nodes in the area near the sink in FPCD scheme and the same active ratio scheme.

Figure 33 :
Figure33: The total of energy consumption under different transmission radius  in FPCD scheme and the same active ratio scheme.

FPCD
scheme with 20% ratio of active nodes near the sink The same active ratio scheme with 20% ratio of active nodes near the sink Network lifetime

Figure 34 :Figure 35 :
Figure 34: Network lifetime under different transmission radius  in FPCD scheme and the same active ratio scheme.

Figure 36 :
Figure 36: Network lifetime under different transmission radius  in FPCD scheme and the same active ratio scheme.
send program code P with  max to next node (7)   =   −   , (14) For each program code flow where   < 0 and |  | > Δ // the current transmission delay is lower than that the requirement // transmission delay of application, the number of active nodes // should be reduced.(15) The last node in the program code path send tuple ( max ,   ,   ) along the reverse routing directions to different areas in this program code flow path; // feedback control the data flow which do not meet the // requirement of application (16) Sink get   ,  max from program code P; (17)  max can be updated by sink after a round of program codes transmission (18) Sink send ( max ,   ,   ) to each area in the network; (19) Each area receives the tuple do action as steps (20)−(27); (20) If B  = 1 // The number of active nodes in this area is reduced to reach // the stable state (21) The number of active nodes in this area should be adjust according to steps (45)-(51); (22) update max ,   ; (23) sendtuple( max ,   ,   ) to each node; (24) Else Continue the steps (13)-(42) for adjusting the number of active nodes, until |  | < Δ; (44) The method for adjusting the number of active nodes in the area at  distance from the sink (45) Let Δ =  max −   ,  Δ = Δ;