Energy-aware and Trust-based Secure Routing Protocol for Wireless Sensor Networks Using Adaptive Genetic Algorithm

Due to their working environments, limited resources and communication characteristics, wireless sensor networks face some challenges including energy optimization and security enhancement to extend the network lifetime and guarantee the network security. Therefore, an energy-aware and trust-based routing protocol for wireless sensor networks using adaptive genetic algorithm called TAGA is proposed to not only resist common routing attacks and special trust attacks, but also minimize the energy consumption caused by data transmission. To this end, TAGA constructs the nodes’ comprehensive trust values based on their direct trust values considering the volatilization and adaptive penalty factors, and indirect trust values with the filtering mechanisms. In addition, a novel threshold function is presented to select the optimal cluster heads, which considers the dynamic changes of the nodes’ comprehensive trust values and residual energy. Finally, a genetic algorithm with adaptive crossover probability and mutation probability is applied to find the optimal secure routing for the cluster heads. The simulation results show that TAGA can reduce the number of packets discarded by malicious nodes when facing common attacks and special trust attacks, and effectively improve the energy efficiency compared to the relative secure routing protocols EOSR and IASR.


I. INTRODUCTION
Wireless sensor networks (WSNs) are comprised of multitudinous sensor nodes that are low-priced, low-power and miniature characteristics [1][2][3]. These nodes are datacentric responsible for collecting relevant data in the target area and transmitting the data to the sink node (base station or control center) in a single-hop or multi-hop manner [4,5]. In recent years, wireless sensor networks have been widely spread in aerospace, industry, home, battlefield, and many other fields [6][7][8]. Usually, sensor nodes are deployed in harsh environments or unattended areas, which makes their routing protocols susceptible to all kinds of attacks [9]. Such attacks can be classified as external and internal attacks [10,36]. To enable WSNs to operate in a healthy and secure environment, the security mechanisms based on cryptography and identity verification are proposed to resist external attacks on WSNs. However, such defense mechanisms cannot defend against attacks inside the network [11,12]. This is because it is a prerequisite for realising these schemes that nodes in a network are cooperative and fully reliable [13]. Moreover, they require sophisticated calculations and large amounts of memory, which can incur higher energy overhead. Therefore, security mechanisms using trust have been proposed to solve internal attacks on WSNs have been shown to be feasible [14,15].
Trust-based security mechanisms predict the behavior of the node in the next moment based on its historical behavior [16,17]. They quantify the behavior of nodes by building models. The more good behaviors a node has, the higher the trust value and security will be. However, traditional trustbased security mechanisms also have some drawbacks, such as not being able to defend against multiple types of attacks simultaneously, not being fast enough to identify maliciousness, and high energy consumption. More importantly, there is a spear and a shield, and trust attacks (on-off and bad-mouth attacks) are designed to target trust-based security mechanisms. Its purpose is to destroy the trust evaluation mechanism, thereby paralyzing these defense mechanisms. Therefore, normal nodes will also be evaluated as malicious nodes. Therefore, how to resist both common attacks and trust attacks, as well as to find a secure and energy-saving route for the network, is one of the important issues that many researchers explore.
The routing protocol based on trust and adaptive genetic algorithm proposed in this paper resists common routing attacks and special trust attacks by building a trust model. For example, common attacks include black hole , selective forwarding , sinkhole and hello flooding attacks [18,19]; trust attacks include on-off and bad-mouth attacks [20]. TAGA design the fitness function of an adaptive genetic algorithm (AGA) according to node comprehensive trust value, energy trust value and hop count as parameters to find secure and energy-saving routes. In addition, adaptive crossover probability, adaptive variation probability and random crossover mapping method are introduced in the AGA to enhance the diversity of the population, so as to accelerate the convergence of chromosomes and avoid the local optimum phenomenon.
The main contributions of this paper are as follows: TAGA is developed by integrating trust security mechanism and AGA so that routing can take into account both security and energy saving.
TAGA is improving security by building an adaptive trust model to evaluate the comprehensive trust value of each node to resist common attacks and special trust attacks.
The cluster heads (CHs) selection threshold is improved according to the dynamic changes of trust value and energy, so as to avoid malicious nodes acting as CHs.
The rest of the paper is organized as follows: Section 2 presents the past work of many researchers; Section 3 describes the improved trust proposed in this paper; Section 4 presents the energy model of TAGA; Section 5 describes the pathfinding process of TAGA in detail; Section 6 verifies the performance of TAGA through simulation experiments; Section 7 concludes the paper.

II. RELATED WORK
In [21], a security and trust-aware routing scheme is proposed, which differs from other methods in that it acquires trust by using fuzzy logic. The fuzzy logic contains two inputs and one output. The source and destination are used as input to the fuzzy logic, and TU (trust and untrust) is used as output. The fuzzy logic is used to distinguish between normal and unnatural sensors, where unnatural sensors can be considered as internal attacks. For the routing of this scheme, they utilize the MDS-MAP (multidimensional scaling mapping) algorithm to decide the best path with less error. But this scheme requires the support of fuzzy system, Dijkstra algorithm, MDS-MAP algorithm, so the complexity is high. In [22], a trust-based secure directed diffusion routing protocol (TSDDR) is proposed to guarantee the confidentiality of data during transmission. The trust model of TSDDR considers two factors: direct trust value and energy consumption. In constructing the direct trust value, they use the Beta model with penalty function 1 β W ( )  and tuning function 1 1 + ( ( ))    to help construct the direct trust. Although the penalty function and tuning function are introduced in the direct trust model, the burden from the historical evaluation is not considered. In [5], an algorithm based on ant and trust called MPASR is proposed to alleviate the burden caused by historical evaluation by introducing η (weakening factor), as well as to save energy. The trust type of MPASR is modeled as Beta distribution, and the comprehensive trust value is calculated with direct and indirect trust values. Unlike previous studies, MPASR filters out unnecessary third-party nodes in order to save energy when calculating indirect trust values. Then in the route establishment phase, MPASR integrates the trust value, residual energy and delay to obtain a comprehensive pheromone that is an important factor to improve the traditional ant colony algorithm, which in turn finds the most appropriate transmission route for each node in the network.
In [23], a hybrid optimization algorithm called Monarch-Cat Swarm Optimization (M-CSO) is proposed to ensure the effective security of the network. Nodes are identified as secure or not by calculating the tolerance constant according to trust, connectivity and Quality of Service. The opportunity routing of M-CSO is done by integrating the MBO (Monarch Butterfly Optimization) and the CSO (Cat Swarm Optimization), which balances the advantages and disadvantages of both algorithms. However, in the establishment of the trust model, the consideration is not comprehensive enough, which makes the evaluation not accurate enough. In [24], the Secure Quality of Service (QoS) aware Energy Efficient Routing (SQEER) protocol is proposed, which is designed based on trust and energy models. SQEER calculates three types of trust values to improve the security of network communication and the accuracy of evaluation. The protocol calculates the total trust value from direct and indirect trust values. QoS and trust are then applied together in an integrated way to the security CHs selection mechanism. Finally, the optimal path is selected based on path trust, energy and hop count. In [25], an algorithm combining trust and opportunistic routing called ETOR is proposed, which consists of two components. One uses tolerance constants to carefully select safety nodes, and the other selects some of these nodes to form a route. In the routing phase, a new hybrid fitness function is designed to select the optimal secure route. This function specifically involves parameters such as energy, trust, QoS, connectivity, distance, hop count and network traffic. ETOR is superior to M-CSO and SQEER in terms of energy efficiency and trust model design. In [37], an effective fuzzy path selection approach is proposed to reduce the impact of selective forwarding attacks. This approach is roughly divided into two phases: the first phase is when the compromised node is monitored; the second phase is when a new secure route is selected using fuzzy rules. This method takes the average link residual energy and hop count as inputs for fuzzy control and then obtains the candidate chance values for a particular route. Finally, a new disjoint secure route is selected to resist selective forwarding attacks.
In [26], base station (BS) controlled secure routing protocol (BSCSRP) is proposed. The CH selection mechanism of BSCSRP is based on the classical LEACH (Low Energy Adaptive Clustering Hierarchy) protocol. However, the CHs election threshold of BSCSRP only considers the residual energy of nodes. BSCSRP considers direct trust, indirect trust, packet drop trust and attribute trust when constructing a comprehensive trust model. The energy, distance and delay parameters in communication are used as the basis for path selection. But BSCSRP does not consider whether this CH is secure or not when selecting the CH. In [27], a multidimensional secure cluster routing scheme (MSCR) in hierarchical WSNs is proposed to participate in the selection of CHs based on several factors, including security. MSCR first constructs the trust synthesis, the environmental factors, and the security domain. Then, MSCR also takes LEACH protocol as the basic framework to improve the CHs election thresholds by introducing the energy domain, the distance domain, the environment domain and the security domain. Although MSCR contributes in the CHs election phase, all CHs of the network transmit their collected data to the BS in a single-hop manner. Therefore, applying MSCR to large-scale networks shows poor performance. In [28], a trust-based dynamic slicing mechanism (TDSM) is proposed to improve the performance of WSNs. This mechanism evaluates the corresponding trust degree based on data forwarding, latency and packet loss and then averages these three values. The node with the largest communication trust value is used as the CHs in the CHs selection phase; the node with a communication trust value less than 4 is the discard node; the rest are the member nodes. Finally, each node splits its data into different pieces and sends them to the corresponding nodes. The corresponding nodes mix the received slices with their own sensed data and sends them to the corresponding multi-hop link.
None of the above schemes can resist trust attacks. Once a malicious node launches a trust attack, many normal nodes with trust-based security mechanisms will be paralyzed. In [29], an energy-optimized secure routing algorithm (EOSR) is proposed, which is designed as a multi-factor routing method. The comprehensive trust of EOSR is a combination of direct and indirect trust values. In constructing the direct trust model, EOSR considers that the uncooperative behavior may be from malicious or normal nodes. Thus EOSR corrects the accuracy of the direct trust model. In addition, the deviation degree is introduced to filter false recommendations when calculating the indirect trust value. Finally, EOSR combines the AODV (Ad hoc On-demand Distance Vector Routing) protocol, trust, residual energy and hop count to calculate the combined path cost. Thus, the path with the smallest combined path cost is selected as the optimal route. In [30], Information-Aware Secure Routing in WSNs (IASR) is proposed. IASR calculates the direct attack probability based on the communication behavior of nodes and then calculates the indirect attack probability and filters the malicious evaluation value according to the direct attack probability. Finally, direct and indirect trust are simply integrated to get the integrated trust. Using the Dijkstra algorithm as the basis of pathfinding, the total state value of nodes in the whole path is calculated based on the trust value (attack probability) associated with the state (remaining energy and distance to the sink). Therefore, the optimal route with minimum cost can be found. Although these two schemes consider the impact of trust attacks, they do not consider the negative impact of historical evaluation on the current evaluation. In addition, the node with bad behavior is not penalized to speed them up to be identified. Therefore, these two schemes will lose a large number of packets when attacked.
All the acronyms mentioned in this paper are listed in Table I

III. TRUST MODEL
Since a normal node is captured as a malicious node, security schemes based on cryptographic mechanisms cannot defend it. Therefore, human-to-human trust relationships are applied to WSNs to evaluate whether or not each node is captured as a malicious node. The higher a node is trusted, the higher its security. The watchdog mechanism is used for reconnaissance to obtain the data source of trust evaluation [19] and mainly monitors the nodes in the route for sending and receiving packets. In TAGA, hierarchical trust values are used to maintain the dynamic behavior of trust.

A. DIRECT TRUST VALUE
The direct trust value is meant to be obtained by the nodes that personally monitor the behavior of their neighbors. In this paper, The direct trust model is constructed by monitoring the status of neighbor nodes receiving and sending data packets. The direct trust of node i evaluating neighbor node j can be expressed as: Where t ij P T denotes trust values that node i has evaluated node j in the past, i.e., historical trust values. It aims to limit the high trust values evaluated long time ago, thus improving the security, accuracy and speeding up identification in WSNs.
t ij N T indicates the trust value of node j evaluated by node i in the current evaluation cycle, and satisfies   .  and 1 - are the measuring factor of historical and current trust values, 0 <  < 1,whose values are set in terms of the specific circumstances. For fairness, the value of  is usually set to 0.5. j R and j S denote under the penalty mechanism the ratio of the number of data received and sent by node j to the total number of packets, respectively, and are expressed as follows: Where, j re and j se respectively represent the number of packets that j received and sent. j rj and j us denote the number of data that j rejected to received and sent, respectively. Message denotes the total number of packets received and sent by node j.  is the adaptive penalty factor.
It serves to speed up the decline of trust value of malicious nodes.The expression formula of  is as follows: where j BP is the ratio of abnormal behavior j AB to normal behavior j NB in the last five trust evaluation cycles.
a 、 b and c represent changeable parameters of  , respectively, and control the strength of the penalty to node j. Their magnitudes depend on the specifics of the network. When node j is successfully caught at some point, j AB increases sharply, which leads to a decrease in j BP . Under the action of j BP ,  decreases Correspondingly, which results in fast dropping current values. Therefore, the adaptive penalty factor  is helpful to improve the recognition speed.
In the perfect case, when a node becomes a malicious node, it can be identified immediately enough. However, in reality, it takes a period of evaluation cycle to identify it as a malicious node. Therefore, how to shorten the evaluation cycle is one of the issues discussed by many researchers. Malicious nodes are normal nodes with high trust value before they are captured, so the high historical trust value acts as a hindrance to the current evaluation. Therefore, the introduction of volatilization factor  to reduce the effect of historical trust value is helpful to speed up the recognition speed. Its value is taken in the range of [0, 0.5]. The expression formula for the historical trust value is as follows.

B. INDIRECT TRUST VALUE
Although nodes can be evaluated by direct trust, if the level of information interaction between nodes is not enough or is affected by the channel, direct trust is not accurate enough to measure the trustworthiness of a node [30]. Therefore, it is necessary to introduce indirect trust to enhance the accuracy of trust assessment. The indirect trust value is the trust value provided by the common nodes between the node and the target node. In other words, the direct trust value provided by the common trusted neighbor nodes of node i and node j is used to calculate the indirect trust value of node j. The indirect trust value of node i to node j is expressed as: Where h PB stands for the set of trusted nodes that are jointly owned by i and j. The common neighbor nodes of i and j may be trusted or untrusted. Therefore it is necessary to filter the neighbor nodes. Moreover, if a third-party node k launches bad-mouth attacks, the trust mechanism can suffer a devastating disaster due to malicious evaluations. To avoid bad-mouth attacks and enhance the security of the trust mechanism, this paper uses Equation 8 to filter the false evaluations.
Where D represents the median that i evaluates node Bx.
As shown in Figure 1, Bx stands for the node jointly owned by i and third-party node k, , and l is the number of common neighbor nodes. t k d is related to whether the value recommended by k is reliable. Therefore, the recommendation threshold is set to guarantee the authenticity of the recommended values. If t k d is greater than the threshold  , the value recommended by node k is not ad-opted by node i and the abnormal behavior of k increases by l. Instead, node k is added to h PB . The size of the threshold value  depends on the specific application; in this paper,  is set to 0.5. Note that the direct trust values recommended by the nodes in the set h PB are trusted, but it does not mean that these nodes are trusted themselves.

FIGURE 1. Common neighbors of node i and third-party node k
In order to improve the accuracy of trust evaluation, the weight of node k is set as follows: Where node k is from h PB to avoid malicious destruction of the weights.

C. COMPREHENSIVE TRUST VALUE
The comprehensive trust value combines the direct and the indirect to ultimately express the basis of whether a node is trusted or not. The higher the comprehensive trust value, as shown in formula 10, the higher the security level and trustworthiness of the node.
(1 ) * * if Where η is their weight coefficient. According to Equation 11, if node k, the common neighbor of node i and node j, initiates bad-mouth attack, the calculation prefers the direct value. Conversely, for fairness, the weight coefficients for both direct and indirect are 0.5. The node that initiates the bad-mouth attack may be either a third-party node k or the evaluated. If it is the former, the calculation of the comprehensive trust value focuses more on the result of the evaluator's assessment. On the contrary, the direct and indirect trust values are considered in combination.

IV. ENERGY MODEL
Usually, the nodes in WSNs are deployed in harsh and unattended environments, which prevents the nodes from replenishing their energy. Therefore, it is important to consider the energy consumption while enhancing the security of the network to avoid rapid energy depletion of the nodes. In this paper, we use a similar energy model as used in [30,34]. The energy consumed by node i to send s-bits of data to node j at a distance d is as follows:  (12) The energy consumed by node j to receive the s-bits data sent by node i is as follows: Where elec E denotes the energy cost of transmitting 1 bit by the transmitter; fs  and mp  denotes the energy cost of the free-space and multi-path fading models, respectively; Additionally, 0 d is the threshold value for an amplifier to adjust its power.
The energy consumption of s-bits data aggregation is: The energy cost to fuse 1 bit of data is pb E . Assuming that the initial energy of each node is 0 E , the remaining energy of each node is Thus, for j , the energy trust value is:

V. SECURE ROUTING
The third section describes the trust evaluation mechanism of TAGA, which aims to evaluate the security level of individual nodes. This section, on the other hand, aims at finding the safest and most energy-efficient route through an AGA to achieve secure routing in WSNs.

A. SELECTION OF CHs
TAGA is a hierarchical routing protocol that first selects the nodes with the highest combined capability as the CHs based on the comprehensive trust value and the remaining energy. Since the main function of the CHs are to receive and forward the data sent by the nodes in the cluster and to forward the data from other CHs, the node with high overall quality must be selected as the CH. In traditional trust-based secure routing protocols, only nodes with high security are considered as CHs, which is deficient. Because if a node does not have much-remaining energy but has a high-security level, then this node is bound to take the role of CH. So, in this case, these nodes are always selected as CHs, and then his energy decreases very quickly.
The secure routing in this paper is in terms of the framework of classical LEACH protocol, a hierarchical network topology with operational phases including cluster construction phase and stable data transmission phase. However, in these two phases, the selection of CHs and data transmission on the path make the WSNs full of crisis and energy wastage. Therefore, it is necessary to improve the CHs selection mechanism and path planning method. The improved CHs selection mechanism is shown in the following equation.
( (1 ) ) Where, p is the percentage of the number of CHs in the network to the total number of nodes, r is the number of rounds the network is running, and G is the set of nodes that were not selected as CHs in the previous round and have residual energy greater than the average. In order to select high quality CHs with high security and sufficient energy, the average of the comprehensive trust value t j C and the minmax normalization of energy trust value j E ' are introduced.
 is adaptive weight. Traditional trust-based security schemes use fixed weights, which makes them inadequate to adapt to changes in the network. Since in the early stage of network operation, the comprehensive trust value of nodes has not yet reached the state of convergence, the comprehensive trust value is relatively volatile, which makes it poor to judge the security of nodes. Therefore, in the early stages of the network, energy trust should be favored more compared to the comprehensive trust. After the initial stage of the network, the assessed value of the nodes is stable and the energy in the network gradually decreases with the operation of the network. Therefore gradually focus on the role played by the comprehensive trust value in CHs selection. The formula for the weighting factor is as follows.
Where Q is a constant, which takes values between 0.5 and 1. r1 indicates the number of rounds the network is running when the standard deviation of the comprehensive trust value of the nodes is less than a specific threshold  . ( ) r  indicates the total energy consumed by the network as it runs.
Where '' j E denotes the energy trust value of j when the number of running rounds is r1.

B. ROUTING BASED ON AGA
Since the single-hop approach is used in the stable phase of LEACH protocol, but this approach is not suitable for largescale networks. However, if the multi-hop approach is used, the CHs need to forward the collected data through multiple nodes to the BS, which will also have a crisis. So the paths sought by the CHs must be safe and energy-efficient.
Currently, the research of AGA has been relatively mature and extensive [31], but few of them have been combined with trust mechanisms. Genetic manipulation involves four main processes: coding, selection, crossover, and mutation. In TAGA, real number coding is used instead of binary coding to represent chromosomes, and a new fitness function is designed to determine the quality of chromosomes [35]. In addition, random crossover and dynamic mutation methods from the literature [32,33] are used to enhance the population diversity and improve the algorithm convergence.

1) ENCODING
The AGA uses different coding methods will produce the effect, so the AGA is first faced with how to use the appropriate chromosome coding method. The most commonly used encoding methods are binary encoding and real encoding, and real encoding has the advantage of higher accuracy. Assuming that the network consists of N nodes, then each node is given a unique positive integer (or ID) between 1 and N, and the BS is denoted as N+1. Thus when nh nodes are selected as CH, then the genes of this chromosome are composed of their respective codes, and the chromosome length is nh.
To expedite the aggregation of the AGA and obtain an efficient solution, the gene position of each source CH has its own corresponding set i g , as shown in Figure 2. Only j CH that satisfies the following three conditions at the same time can be added to the set gene i g of source

2) SELECTION OPERATOR
The reproduction of species in nature is a process of survival of the fittest. Similarly, in AGA, the operation of selecting high quality individuals and eliminating low quality individuals from a large number of individuals is called selection operator. At present, the roulette wheel selection method is the most common and simplest method of selection operator in AGA. The expression formula for the probability of each individual being selected is as follows: Where x and f(x) represent individual x and the fitness value of individual x, respectively. M represents the size of the population.

3) CROSSOVER OPERATOR
The crossover operator means that two-parent individuals exchange corresponding genes to form the next generation. Its purpose is to enhance population diversity and promote population evolution. The traditional crossover operator randomly selects two individuals based on the crossover probability and randomly generates crossover positions for exchanging some genes.
To further enhance the population diversity and the search range, the random cross mapping method is introduced to break the limitation of the number of fixed crossover points in traditional genetic algorithms [32]. The random cross mapping method means that the crossover length is fixed as half of the chromosome length, but the crossover start point and endpoint are not fixed. Suppose the chromosome length is L and the crossover length is: First, a starting crossover position is randomly selected, and then the end crossover point is extended L' units backwards along the chromosome from the starting point. For example, two chromosomes A and B of length 7 (shown in Figure 3), then a crossover segment of crossover length 3 is generated under the random crossover mapping method. Figure 3 shows the three cases generated under this method. In addition to the above random cross mapping method, crossover probability and mutation probability can also increase population diversity. However, the fixed crossover probability preset by traditional genetic algorithms may lead to low population diversity in the early stages of the algorithm, which may lead to an early convergence situation. In the process of population evolution, different individuals behave differently, then the crossover probability of the population should also vary according to the fitness of each individual. The adaptive crossover probability [33] involving the number of evolutionary generations and the fitness values of the corresponding generations are shown below.

4) MUTATION OPERATOR
When the population diversity is low, all individuals tend to be optimal, which is likely to fall into local optimization in advance. So the mutation probability should be increased to break through the convergence state of individuals. The formula for adaptive mutation is as follows: where pmmin and pmmax represents the maximum and minimum values of mutation probability, respectively.
To avoid invalid mutations, the variant code at each gene position must be chosen randomly from the corresponding set i g . Table 2 shows the set corresponding to each gene position, for example the set corresponding to position 5 is 5 g = [4,1,3]. Figure 4(a) represents the effective mutation that the gene code at position 5 is mutated from 4 to 1. Figure  4(b) indicates the invalid mutation that 4 mutates to 6 at gene position 5.

5) FITNESS FUNCTION
Each chromosome is potentially the optimal solution, but the chromosome with the highest fitness value at the end of the iteration is the optimal route. As shown in Figure 5, assuming that the third row represents the chromosome with the highest fitness, the optimal route for the source cluster head CH1 is 1 OR = {1, 3, 101}. Similarly, the optimal path for source cluster head CH7 is 7 OR ={7, 6, 2, 101}. TAGA mainly uses two dimensions, the average comprehensive trust value on the link and the energy consumed by CH, to compose the fitness function so as to find a path with high security and small energy cost at the same time. The fitness function for the kth gene position in a certain chromosome is as follows: represent the maximum and minimum energy consumption of all links in all chromosomes, respectively. Therefore, the fitness function of the chromosome is: Where nh is the length of the chromosome.

C. THE PSEUDO-CODE OF TAGA
The pseudo-code of TAGA is as follows: VOLUME XX, 2017

D. TIME COMPLEXITY OF TAGA
The proposed TAGA uses comprehensive trust values to evaluate the security of individual nodes and adaptive genetic algorithms to evaluate the security of links, thus improving the network's ability to cope with attacks. Therefore its time complexity can be expressed as O(TAGA) = O(time complexity of the trust model + time complexity of AGA). The trust model of TAGA is to construct the comprehensive trust by combining direct and indirect trust values. Assuming that the network has n nodes, the time complexity of constructing direct trust is O(n*s), where s is the number of neighbor nodes. Since indirect trust is obtained by multiplying the corresponding direct trust, the time complexity of indirect trust is O (n * s). Similarly, the time complexity of comprehensive trust is O(n*s). So, O(time complexity of the trust model)=O(n*s). Encoding chromosomes with length k during the execution of the adaptive genetic algorithm produces a time complexity of O(k). The time complexity that AGA generates the initial population is O(k*p),where p is the population size. The average time complexity of computing the fitness value is O(p*k 2 ),while it is O(p*k) and O(p*k 2 ) in the best and worst cases, respectively. The time complexity of the crossover and variation operations are O(p/2) and O(p), respectively. After performing I iterations, the time complexity of AGA is O(k+k*p+I*(k 2 +3/2)*p), which is O(I*p*k 2 ). The number of CHs in the network is much less than the number of nodes, so the time complexity of AGA can be simplified to O(n 2 ). Therefore the overall time complexity is O(TAGA)=O(n*s+n 2 ). Since s is less than n, O(TAGA)=O(n 2 ).

VI. SIMULATION
This section focuses on verifying the performance of TAGA by MTALB in the face of different attacks and comparing it with IASR and EOSR. We randomly deploy 100 nodes in an area of 100*100m 2 . The trust threshold is set to 0.35. The simulation time is in rounds. It is assumed that some internal nodes are caught as malicious nodes and then launch the attacks, when the network is running to the 100th round. Other simulation parameters are set in Table 3.    Figure 7(b) shows the integrated trust value variation curve for all normal nodes and the convergence after the 20th round. From Figure 7(a), it can be seen that at 20 rounds, the maximum standard deviation is 0.1125, and the minimum standard deviation is 0.090994. So in this paper, the threshold  is set at 0.08. Figure 8 shows that with the increase of malicious nodes, the number of packets discarded by malicious nodes in the network gradually increases. The black hole attack is a mali-cious node tricking the nodes in the network to establish routing connections with it, resulting in the packets to be forwarded being discarded maliciously. As the malicious nodes discard all the received packets. Therefore, according to Equation (3), when TAGA evaluates the trust value of the malicious nodes, the current trust value will decrease rapidly. Thereby, compared with IASR and EOSR, the trust value of the malicious node quickly drops below the trust threshold. It speeds up the speed of identifying malicious nodes and reduces the number of malicious dropped packets as much as possible. As can be seen in Figure 8, the number of packet loss for TAGA is reduced by an average of 16.96% and 25.48% compared to IASR and EOSR, respectively.   Figure 9 shows that as the number of malicious nodes launching hello flood attacks increases, the number of discarded packets by malicious nodes in the network gradually increases. The hello flood attack means that a malicious node broadcasts hello packets using a signal with enough energy to make more distant nodes mistake it as its direct neighbor. As a result, a large number of packets are rejected by the malicious node. TAGA based on equation (2) can make the current trust value decrease quickly for malicious nodes. As can be seen in Figure 9, the number of discarded packets in TAGA is much lower than that of IASR and EOSR. The number of lost packets in TAGA is reduced by 19.83% and 33.13% on average compared with IASR and EOSR, respectively. Figure 10(a) shows that as the number of malicious nodes launching selective forwarding attacks increases, the number of discarded packets by malicious nodes in the network gradually increases. The selective forwarding attack means that the malicious node forwards or discards important packets with a certain probability, and the black hole attack is formed when the packets are discarded with a 100% probability. In this paper, the malicious node discards the received packets with a probability of 70%. From the combination of Figure 10(a) and Figure 8, it is clear that the malicious nodes that initiate the selective forwarding attacks discard more packets than the malicious nodes that initiate the black hole attacks. This is because the malicious nodes both send certain packets and discard some packets, making it more difficult to identify the malicious nodes. As can be seen in Figure 10(a), the number of lost packets for TAGA is reduced by 10.11% and 21.54% on average compared with IASR and EOSR, respectively.  shows that the number of discarded packets by malicious nodes in the network gradually decreases as the drop probability increases when there are 30% malicious nodes in the network. This experiment was conducted to verify the impact of the difference in the discard probability on the network. As can be seen from Figure 10(b), the smaller the probability of malicious drops, the greater the damage to the network and the greater the difficulty in identi-VOLUME XX, 2017 fying malicious nodes.  Figure 11 shows that as the number of malicious nodes launching sinkhole attacks increases, the number of packets discarded by malicious nodes in the network gradually increases. The sinkhole attack means that the malicious node creates a black hole centered on itself that attracts all nodes in a specific area to send packets to it. It can be seen from Figure 11 that the number of lost packets for TAGA decrease on average by 20.83% and 36.2% compared to IASR and EOSR, respectively.  Figure 12 shows that with the increase of malicious nodes launching on-off attacks, the number of packets discarded by malicious nodes in the network gradually increases. The on-off attacks mean that malicious nodes periodically perform both good and malicious behaviors, which brings great challenges to the trust evaluation mechanisms. As can be seen from Figure 12, on-off attacks are more destructive compared to the above attacks. Since TAGA uses the penalty mechanism, TAGA is able to identify malicious nodes quickly and minimize the damage caused by malicious nodes to the network. The number of lost packets in TAGA is reduced by 26.72% and 35.45% on average compared to IASR and EOSR, respectively.   Figure 13 shows that with the increase of malicious nodes launching bad-mouth attacks, the number of false trust values spread by malicious nodes in the network gradually increases. The bad-mouth attack is when the evaluator evaluates the target nodes, the malicious node provides false trust value to the evaluator, which causes the evaluator to incorrectly evaluate the trust value of the target nodes, making the trust value of the target nodes decrease. When IASR computes the indirect values, it uses the weighting coefficient m  , which can effectively avoid the influence of malicious recommendations. EOSR uses the deviation degree of indirect trust to filter each false recommendation. However, the trust models of both schemes cannot make the trust value of the adverse nodes that launch the bad-mouth attacks lower. So in both schemes, malicious nodes will continue to spread false recommendations. While the adaptive penalty factor in TAGA can effectively reduce the trust of the adverse nodes, and the credibility constructed by using the median of direct trust can effectively filter the false recommendation values.  Figure 14 shows that the energy consumption in the network increases with the number of rounds. First, TAGA uses LEACH as the basic framework to improve the CH election threshold based on the trust value and residual energy of nodes, so that nodes with high security and high energy as CHs. Second, TAGA uses AGA to select secure routes for CHs. In constructing the fitness function of the AGA, the optimal path selection is controlled using the comprehensive trust value within each hop and energy consumption. IASR jointly controls the path selection based on the energy consumption from the node to the BS, the remaining energy of the relay node and the trust value. Therefore, the relay node which is far away may be selected. While EOSR may select the node with less hops but less residual energy as a relay node based on the path evaluation formula. Therefore the energy cost of TAGA is lower than that of IASR and EOSR. Compared with IASR and EOSR, the energy efficiency of TAGA has increased by 4.97% and 14.84%.

F. SUMMARY TABLE
After the above simulations for different scenarios, we summarize the proposed TAGA scheme in Table 5. The total discards in Table 5 shows that the nodes that initiate the onoff attacks drop the most packets and the sinkhole attacks drop the least packets. Both black hole attacks and sinkhole attacks discard all received packets; selective forwarding attacks and on-off attacks discard some packets. This shows that it is easier to defend malicious nodes with a large number of dropped packets and harder to defend malicious nodes with partially dropped packets. It can be seen from the average discards in Table 5 that the average number of packets discarded by malicious nodes in the scenario of 1000m*1000m is less than 100m*100m. This is because the number of packets dropped by each malicious node in each evaluation cycle increases significantly leading to the rapid identification of malicious nodes. When TAGA faces black hole attacks, Hello flood attacks, selective forwarding attacks, sinkhole attacks, and on-off attacks in the 1000m*1000m scenario, the average number of packet loss is 36.48% 、 63.6%、47.49%、44.09% and 39.09% lower than that in the 100m*100m scenario, respectively.

VII. CONCLUSION
In this paper, an energy-aware and trust-based routing protocol for wireless sensor networks using adaptive genetic algorithm called TAGA is presented to resist common routing attacks and special trust attacks so as to resist multiple attacks, improve the speed of identifying the attackers, and select secure and energy efficient routes. In TAGA, adaptive penalty factors, volatilization factors and filtering mechanisms are designed to construct the comprehensive trust values, which are used to evaluate the security performance of the nodes. Then an improved adaptive genetic algorithm with a novel CH election threshold is applied to select the secure and high-energy nodes as CHs. Finally, an adaptive genetic algorithm is adopted to find the optimal path for each CH. The simulation results verify the effectiveness of TAGA, and indicate that it can effectively decrease the impact of the malicious nodes, reduce the number of lost packets, and improve the network energy utilization.