A cluster-tree-based trusted routing algorithm using Grasshopper Optimization Algorithm (GOA) in Wireless Sensor Networks (WSNs)

In wireless sensor networks (WSNs), existing routing protocols mainly consider energy efficiency or security separately. However, these protocols must be more comprehensive because many applications should guarantee security and energy efficiency, simultaneously. Due to the limited energy of sensor nodes, these protocols should make a trade-off between network lifetime and security. This paper proposes a cluster-tree-based trusted routing method using the grasshopper optimization algorithm (GOA) called CTTRG in WSNs. This routing scheme includes a distributed time-variant trust (TVT) model to analyze the behavior of sensor nodes according to three trust criteria, including the black hole, sink hole, and gray hole probability, the wormhole probability, and the flooding probability. Furthermore, CTTRG suggests a GOA-based trusted routing tree (GTRT) to construct secure and stable communication paths between sensor nodes and base station. To evaluate each GTRT, a multi-objective fitness function is designed based on three parameters, namely the distance between cluster heads and their parent node, the trust level, and the energy of cluster heads. The evaluation results prove that CTTRG has a suitable and successful performance in terms of the detection speed of malicious nodes, packet loss rate, and end-to-end delay.


Introduction
Wireless sensor network (WSN) is an important element for designing Internet of Things (IoT).It includes sensor nodes, which monitor the environment to gather data and send it to the base station [1,2].In a WSN-based IoT network, intelligent routing is a main and necessary phenomenon for improving the quality of service (QoS) [3,4].Furthermore, providing the energy needed for communications is a major challenge to decrease packet loss.In the routing process, it is necessary to prevent the rapid discharge of sensor nodes and unbalanced energy distribution in the network [5,6].Hence, it is essential to manage the energy consumed by nodes using intelligent machine learning techniques, metaheuristic algorithms, or other optimization strategies to make effective routing decisions and improve network performance [7,8].Many energy-efficient routing approaches are currently available in the literature for WSNs.However, they need to be enhanced for a WSN-based IoT environment [9,10].
Today, IoT has improved universal access for deploying intelligent networks.A network edge provides intelligent services and computing for IoT devices [11,12].Additionally, this deployment improves user's experience and presents efficient and flexible services when any unpleasant event occurs.Edge computing provides fast response and high-quality services because it utilizes an architecture close to end users [13,14].However, there are some security concerns, and security protocols must protect the network from the vulnerability of attacks (VoA).Existing techniques are mainly designed to infer intrusions in the network [15,16].However, determining secure and valid sensor nodes is a challenging issue in recent research.Moreover, attackers continuously change their locations to do their hostile activities around the network [17,18].Trust is an important component of cybersecurity.This component is responsible for determining the security level of sensor nodes during their interaction with each other.It actively identifies trusted nodes and prevents security risks caused by privacy violations, data manipulation or deletion, and other cybersecurity attacks [19,20].This illustrates the importance and necessity of trusted routing protocols.
Because of the special characteristics of sensor nodes, like small size, limited memory capacity, constrained energy source, and low computing power, energy consumption management is essential when designing a trust mechanism.Security and energy efficiency are two very important concepts in WSN-based IoT networks.However, they contradict each other.The deployment of these networks in vulnerable and unfriendly environments has led to their vulnerability to various attacks.Hence, existing routing protocols in WSNs need to implement powerful security mechanisms to secure the data transmission process.Although, the design of these mechanisms is associated with complex calculations that lead to high memory and energy consumption.Solving the challenges mentioned above is our main motivation for designing a trust-aware, energy-efficient, and lightweight routing algorithm.In this paper, a cluster-tree-based trusted routing approach using the grasshopper optimization algorithm (GOA) called CTTRG for WSNs is introduced.In addition to focusing on energy efficiency, the proposed scheme attempts to neutralize several routing attacks, especially black hole attack (BH), sinkhole attack (SH), wormhole attack (WH), gray hole attack (GH), and flooding attack (FA).To ensure security, CTTRG proposes a distributed time-variant trust (TVT) model to evaluate the trust of sensor nodes in the network.Also, to ensure energy efficiency, CTTRG uses a tree-cluster hierarchical topology to determine data transmission paths to the base station.In CTTRG, a technique to construct a GOA-based trusted inter-cluster routing tree (GTRT) is presented.BS is responsible for building this routing tree.In summary, the most important contributions of CTTRG are as follows: • Designing a time-variant trust model based on three trust criteria, namely BH, SH, and GH probability, WH probability, and FA probability, and analyzing the behavior of sensor nodes when cooperating with each other.
• Adding a weight coefficient to the recommendations provided by the recommender nodes.The weight of each recommendation is determined according to the trust level of the recommender nodes and the difference between the recommended trust and the calculated direct trust.
• Constructing a trusted routing tree based on the grasshopper optimization algorithm to form stable and trusted communication paths between the cluster heads (CHs) and the base station (BS).
• Designing a multi-objective fitness function according to the distance between each CH and its parent node, the trust level of each CH, and its energy.
In the following, the organization of this paper is as follows: Section 2 exhibits the most important trusted routing methods in WSNs.In Section 3, the grasshopper optimization algorithm is presented in summary.Section 4 discusses network settings, energy model, and threat model in CTTRG.In Section 5, our method is introduced in detail.Section 6 describes the simulation and evaluation results.Finally, the conclusion of the paper is stated in Section 7.

Related works
In [21], a trust-aware and energy-efficient routing protocol called TBSEER has been proposed.It obtains the comprehensive trust of each sensor node with regard to three criteria, including adaptive direct trust, indirect trust, and energy.TBSEER counteracts BH, GH, SH, WH, and FA attacks.Furthermore, this approach presents an adaptive punishment structure to detect malicious nodes quickly.After obtaining direct trust based on the mentioned criteria, the sink is responsible for extracting indirect trust.In this case, sensor nodes conserve their energy because they do not perform repeated operations to calculate this parameter.Finally, CHs find secure paths between themselves and the sink node and consider their trust values in this process.This secure routing process protects the network against various attacks.Simulation results show that this method decreases energy consumption in the network.Also, this approach detects malicious nodes quickly and resists routing attacks.
In [22], a trust-aware and energy-efficient secure routing method called TESRP is introduced for WSNs.This scheme utilizes a decentralized trust structure to separate hostile nodes from honest nodes.Furthermore, TESRP employs a multi-facet routing mechanism to decide on routing paths according to trust value, remaining energy, and the number of hops.This strategy has two main advantages, namely secure data transfer and balanced energy consumption.The evaluation results prove that TESRP is better than other routing approaches in terms of consumed energy, throughput, and network longevity.
In [23], a lightweight and attack-resistant trust-based routing scheme called TSSRM is proposed for WSNs.This approach applies a secure path selection mechanism, which considers the trust value and QoS requirements.The goal of TSSRM is to counteract routing attacks and balance energy consumption in the data transmission procedure.TSSRM designs a secure routing strategy and measures the trust of nodes.In the trust evaluation process, this scheme analyzes the behavior of nodes based on their energy and movement.Then, this scheme discovers different paths between sensor nodes.In the secure route selection mechanism, TSSRM calculates the trust of the discovered paths to choose the most prominent routes.Finally, TSSRM merges QoS requirements and the trust value using the Semiring theory.Evaluations performed in this paper confirm the performance of this scheme.
In [24], a secure energy-efficient routing scheme called ECATS is suggested in WSNs with the mobile sink.It utilizes a fuzzy C-Means and an adaptive TDMA scheduling in the clustering process.Also, it introduces a path construction operation to comfort communications and render data packets to the sink node.ECAT presents a new encryption algorithm called Neural Elliptic Galois (NEG) to provide data security and privacy in the network.Additionally, ECATS finds cluster heads based on their consumed energy in the data aggregation operation.ECATS utilizes an ant lion optimization-based TDMA scheduling to enhance energy efficiency and network reliability at the same time.The evaluation results prove the successful performance of ECATS compared to other routing methods.
In [25], an energy balancing secure routing algorithm using the ant colony optimization called QEBSR is introduced for WSNs.QEBSR employs an event-oriented scenario in the data transfer procedure between nodes and BS.In addition, it utilizes an enhanced technique to calculate latency in the data transfer operation and extract the trust coefficient of nodes in the routing procedure.The ACO algorithm is responsible for searching paths using a max-min system.Eventually, the comparison of QEBSR with DEBR and EENC shows that this scheme has a successful performance.
In [26], the authors suggested a blockchain-based routing scheme in WSNs.In this approach, the blockchain technology designs a common storage capacity between sensor nodes to balance network traffic, lower interference, and enhance network security in the routing process.The authors have assumed that nodes sense events and produce a high volume of data.Hence, this data must be transferred in several packets.In this scheme, sensor nodes play the role of coins, and the transaction means the ownership exchanged between nodes and the sink node.Blockchain stores these transactions and shares the network state using a real-time manner.In the route selection procedure, this scheme introduces a cost function, which includes the load density and interference level of nodes.In addition, blockchain is responsible for protecting the discovered paths.Experiments prove that this scheme can be implemented in real-time systems.
In [27], the authors offered a cluster-based routing approach based on neuro-fuzzy rules called FBCFP to perform the routing operation in WSN-based IoT networks.FBCFP executes the network learning procedure based on the energy value, the distance from CHs to BS, the change in the cluster area, and the degree of CH.FBCFP learns the network environment using a convolutional neural network (CNN) and adjusts its initial weights using a fuzzy system.Furthermore, FBCFP employs a fuzzy system to create a strong clustering structure in the network.It considers similar sizes for clusters and utilizes the suitable rules for training the machine learning algorithm to optimize energy usage and QoS requirements in the WSN-based IoT network.According to the experiments performed in this paper, it can be found that FBCFP is well in terms of used energy, PDR, latency, and network longevity.
In [28], the authors suggested a secure routing protocol along with multiple-variant tuples.This scheme employs a symmetric cryptography strategy called Two-Fish (TF) method to detect and separate attackers on WSNs.Furthermore, this method includes an encryption mechanism and an authentication technique to provide security in the network.It utilizes Eligibility Weight Function (EWF) to find guard nodes.This function is protected using a symmetric cryptography technique.The evaluation results confirm that this scheme utilizes more monitoring nodes than other routing schemes.In addition, it deals with mobile attackers and improves packet delivery.
In [29], a cluster-based routing protocol is offered in a WSN-based IoT network.This scheme performs the routing process and the cluster head selection using two metaheuristic algorithms.The rider optimization algorithm (ROA) is employed to find cluster heads and improve QoS and reliability in the network.ROA uses a multi-objective fitness function, which depends on residual energy, distance, and delay.CHs are refreshed after certain iterations to guarantee load balancing in the network.Furthermore, the sailfish optimization algorithm (SFO) is used to select efficient and optimal routes between sensor nodes.This routing process considers several parameters namely throughput, remaining energy, and link quality.The evaluation results show that this scheme can improve execution time, energy consumption, network delay, throughput, packet delivery ratio, and network lifetime.
In [30], a trust-aware cluster-based routing algorithm is suggested in WSNs.This scheme compresses the sensed data in the data aggregation process to reduce overhead.On the other hand, this scheme implements various meta-heuristic algorithms such as artificial bee colony algorithm, ant colony optimization, differential evolution, firefly algorithm, and particle swarm optimization to validate the trust-aware routing process in WSN and make a trade-off between transmission distance, hop-count, number of transmitted messages, and trusted path.The base station has the responsibility to reconstruct the compressed data and check the trust of CHs.Moreover, CHs perform compressed sensing and trust-based data aggregation operations.These operations enhance security and limit overhead in each CH.In this scheme presents an objective function, which minimizes the distance traveled, number of hops, and number of messages and maximizes the trust related to the path.
In [31], a trust-aware routing method (TARM) is presented for WSN-based IoT networks.This scheme utilizes a mobile edge node to receive data from valid nodes.The edge node separates abnormal nodes from normal nodes based on a trust evaluation method.TARM performs the clustering process using a gray wolf optimizer and obtains trust values for each cluster.Then, the edge node receives data packets only from normal nodes through the corresponding cluster heads.TARM uses the artificial bee colony optimization to find the most suitable routes between valid nodes and the edge node.Simulations show that the trust evaluation mechanism proposed in TARM provides high security and has a high detection rate and high accuracy in detecting abnormal nodes.Also, this scheme conserves energy efficiently.
In [32], a trusted clustering protocol is proposed for WSNs.This scheme offers a trust model to detect untrusted nodes.This trust model considers two trust factors namely energy trust and data trust.In addition, this scheme utilizes stochastic fractal search optimization to do the clustering process.For maximizing network lifetime and improving network security, the clustering method proposes a fitness function to choose CHs from the trusted nodes.This function depends on the remaining energy, the number of nodes, the distance to the base station, and the dissipated energy.This clustering method can make load balancing among CHs.Evaluations show the superiority of this scheme in comparison with existing protocols.
In [33], a cluster-based routing approach is presented for heterogeneous WSNs.In the clustering process, K-means algorithm and cat swarm optimization are combined to obtain a new evolutionary approach called calf search optimization algorithm (K-CSOA), which is used to create clusters in the network.In the clustering process, K-CSOA presents a fitness function, which considers six factors, namely node degree, distance from cluster members to CHs, distance from CHs to BS, average and remaining energy, and balancing factor for clusters.The routing process uses ant colony optimization (ACO) to find the most suitable paths in the network.Simulations performed in this paper show the effectiveness of K-CSOA in terms of energy consumption and delay.
Table 1 compares our proposed scheme with the related works.

Basic concepts
In recent decades, optimization algorithms inspired by nature have attracted the attention of researchers and academics.These algorithms have been used in engineering, computer science, and other fields to solve complex and real-world problems.In these algorithms, a set of solutions are generated and modified at each iteration to discover the optimal solution in the search space [34,35].Some nature-based algorithms include Particle Swarm Optimization (PSO) [36], Artificial Bee Colony (ABC) algorithm [37], Grey Wolf Optimizer (GWO) [38], Dragonfly Algorithm (DA) [39], and Grasshopper Optimization Algorithm (GOA) [40].In 2017, Saremi et al. presented GOA, which simulates the food search behavior of grasshoppers in nature.Various studies have shown the use of this algorithm for solving many problems.For example, refer to [41][42][43].In CTTRG, GOA is responsible for finding a secure and energyefficient routing tree among cluster heads because the construction of a such routing tree among sensor nodes, especially in dense networks, is difficult and time-consuming.To solve this problem, GOA is chosen because it has been widely used in various fields, especially routing, and has proven its competence and effectiveness.In [44], extensive experiments have been conducted to evaluate GOA compared to other well-known algorithms such as PSO [36], Bat Algorithm (BA) [45], Flower Pollination Algorithm (FPA) [46], Cuckoo Search (CS) [47], Firefly Algorithm (FA) [48], Genetic Algorithms (GA) [49], Differential Evolution (DE) [50], and Gravitational Search Algorithm (GSA) [51].These experiments have shown that GOA works very well and can be used to solve complex real-world problems because it can effectively balance exploration and exploitation and guide virtual grasshoppers towards the global optimum.
In general, the most important advantages of GOA are high-quality exploration operations, avoidance of local optimum, and high convergence speed.The mathematical model presented in Eq 1 is used to model the behavior of grasshoppers in nature: so that i is the index of grasshoppers, X i indicates the position of grasshopper i, S i shows the social interaction, G i shows the gravity force, and A i represents the direction of the wind.In order to create a random behavior, Eq 1 is written as X i = r 1 S i + r 2 G i + r 3 A i where r 1 , r 2 , and r 3 are random coefficients in [0, 1].
so that d ij is the distance from grasshopper i to grasshopper j.This distance is equal to d ij represents a unit vector drawn from grasshopper i to grasshopper j. s is used to express social forces.It is obtained through Eq 3.
so f and l are the attraction intensity and the attractive length, respectively.Change in these parameters causes different behaviors in grasshoppers.This social interaction can be defined as attraction and repulsion.Assume that the distance between two grasshoppers is between 0 and 15.If the distance is in [0, 2.079], the social interaction is repulsion.If the distance is 2.079, the grasshoppers are in the comfort area.Also, if the distance is in [2.079, 4], the social interaction is attraction.G is computed according to Eq 4.
where g displays the gravity constant, and b e g shows a unit vector.A is obtained from Eq 5.
so that u is a fixed value and b e w represents a unit vector in the wind direction.After putting S, G, and A in Eqs 1 and 6 is obtained.
where s r ð Þ ¼ fe À r l À e À r and N represents the number of grasshoppers.However, this equation cannot be used to solve optimization problems because it cannot do exploration and exploitation in the search space around a response.In this mathematical model, grasshoppers reach the comfort area speedily and they cannot be concentrated at a particular point.Therefore, this model is modified as Eq 7 to obtain the new positions of grasshoppers in each iteration.
where ub d and lb d indicate the upper and lower boundaries in the dimension d, respectively.
T d is the best solution in the search area, and c indicates the decreasing coefficient, which lowers the comfort area, repulsion area, and attraction area.Note that S in Eq 7 is almost similar to the component S in Eq 1.However, this equation does not regard gravity force (G) and assumes that the wind (A) moves always toward c T d .Eq 7 shows the next position of grasshoppers.It is dependent on their current position, the position of c T d , and the positions of other grasshoppers.c is an adaptive factor and has been used twice in Eq 7. The leftmost c plays the role of inertial weight in PSO.It is used to lower the motion of grasshoppers around c T d and balance exploration and exploitation in this case.However, the second c reduces attraction, comfort, and repulsion areas.To balance exploration and exploitation, c must be reduced based on iterations.This mechanism strengthens exploitation by increasing iterations.c lowers the comfort area when increasing the number of iterations.c is obtained from Eq 8.
where cmax = 1, cmin = 0.00001, l, and L are the maximum threshold, the minimum threshold, the current iteration, and the maximum number of iterations, respectively.

System model
The system model is formed of three items: network settings, energy consumption mechanism, and threat model.

Network settings
In CTTRG, sensor nodes (i.e.SN 1 , SN 2 , . .., SN i , . .., SN N so that N is the number of nodes) have been randomly arranged in the network environment.• Network nodes and the BS are static.
• BS utilizes an unlimited energy source.
• Network nodes are homogeneous, meaning that they use a similar energy source.
• Some equipment installed on sensor nodes are radio communication modules and positioning devices.
• The identifier of each SN i is unique.

Energy consumption mechanism
In CTTRG, the energy model is defined in two modes, namely free space and multi-path.To transfer k bits to SN j , the energy used by SN i is obtained from Eq 9.
Moreover, the energy used by SN j to receive this packet is calculated according to Eq 10: so that d ¼ ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffiffi indicates the distance between SN i and SN j with spatial coordinates (x i , y i ) and (x j , y j ), respectively.E elec represents the energy used for the transmitter/ receiver electrical equipment.Also, E fs and E mp are the energy needed by an amplifier in the free space model and the multi-path model, respectively.d 0 expresses the transfer distance threshold so that d 0 ¼ ffi ffi ffi ffi ffi

Attack model
In WSNs, there is a need to prevent or reduce security risks caused by dynamic topology, deploying in dangerous environments, lack of a central controller, and wireless links.Trust is an important component in cybersecurity.It determines the trust level of each node when interacting with other sensor nodes [52,53].In fact, a security system seeks to actively identify reliable nodes and reduce security risks because these risks may violate privacy, manipulate or delete data, and provide a bed for other cybersecurity attacks.This shows the importance of a trusted routing protocol [54,55].In this paper, CTTRG deals with routing attacks, especially black hole (BH), sinkhole (SH), wormhole (WH), gray hole (GH), and flooding attack (FA).
• The BH node communicates with other nodes and creates fake paths in the network.The goal of this communication is to prevent data packets from being delivered to the destination and delete all the packets.To build fake routes, the BH node is waiting to receive route requests (RREQs) from other network nodes.As soon as the request is received, the BH node quickly responds to the requesting node.Note that these routes are fake, and in fact, there is not any path to the desired node [56,57].Additionally, to increase the attractiveness of these fake routes and absorb network traffic, the BH node adjusts the parameters associated with these paths such as delay and hops in the best possible case.
• The SH node is similar to the BH node, except that the SH node is aware of the position of the sink node and tries to attract all traffic toward the sink.Then, it prevents the packets from being sent to the sink.The attack is more dangerous than BH.
• A GH node is similar to BH, except that GH is smarter.GH does not eliminate all data packets, but focuses on a particular type of packets or on a specific node and removes all packets sent to that node, in other cases, it shows a normal behavior [58,59].As a result, it is difficult to identify GH.
• WH attack will be carried out by two attacker nodes.These two nodes create a tunnel between themselves and encourage other nodes to use this tunnel for sending their data packets.They make this tunnel very attractive in terms of routing parameters to attract the network traffic.The attack provides a suitable bed for tracking the communications of transmitter nodes, copying data packets, manipulating the packets, or removing them.
• The FA node targets a specific node and sends a large number of fake route requests to it.Since the target node processes these requests and stores some information, its energy level is greatly reduced, and its memory overflows.Hence, the target node cannot respond to the real requests of legal nodes.Because of the constrained energy of sensor nodes, this attack causes serious damage to the network [60,61].

The proposed method
In this section, the cluster-tree-based trusted routing method using the GOA algorithm (CTTRG) will be introduced for wireless sensor networks.This method includes two main mechanisms: the time-variant trust (TVT) model and the GOA-based trusted inter-cluster routing tree (GTRT).A diagram of proposed method is presented in Fig 2.

Time-variant trust (TVT) model
In a conventional trust model, the trust of nodes is periodically refreshed, but the trust value is constant in each period.Whereas, this is not true, and trust is a time-variant variable and has no fixed value in each period.Therefore, if a time-variant weight coefficient is considered for trust parameters, it can provide a more accurate estimation of the trust value.In CTTRG, a decentralized time-variant trust model is proposed to get the trust value of nodes.TVT contains three components: time-variant direct trust (TVDT), recommended trust (RT), and time-variant final trust (TVFT).

TVDT component.
In CTTRG, the TVDT component includes an initial value and a dynamic coefficient.The initial value is dependent on the three trust criteria, namely the BH, SH, and GH probability (p SBG ), the WH probability (p WH ), and the FA probability (p FA ).These three criteria are defined based on the analysis of the behavior of sensor nodes when interacting with each other.Now, suppose that SN i attempts to obtain an accurate estimation of the trust value corresponding to SN j .To achieve this goal, SN i interacts directly with SN j to acquire three criteria p j SBG , p j WH , and p j FA .
• p j SBG : This criterion examines the possibility that SN j is a SH node, a BH node, or a GH node.These three attacks are very similar to each other and have little difference, which was discussed in Section 4.3.The most important feature of the SH, BH, and GH nodes is that they have very low packet reception and sending rates and delete all (or more) data packets.Therefore, p j SBG is obtained according to Eq 11.
where PK received j indicates the number of packets received by SN j and PK totalÀ receiving j is the total number of packets that should be received by SN j .Moreover, PK sent j expresses the number of packets sent by SN j and PK totalÀ sending j indicates the total number of packets, which should be sent by SN j .λ is also a fixed number adjusted in [0, 1].λ expresses the weight associated with the packet reception rate and determines the relative importance of the packet reception rate and the packet sending rate.This weight can be adjusted based on the requirements of the application.
• p j WH : This criterion examines the possibility that SN j is a WH node.The most important feature of WH nodes is that they tend to form various paths and absorb the traffic of the surrounding nodes.This tendency to absorb network traffic causes congestion in the WH nodes and consequently they experience a very long queuing delay.The second feature of these nodes is low package reception rate because they eliminate many received packets.Another feature of WH nodes is that they copy some data packets and relay the duplicated packets on the network.Therefore, they experience high redundancy rate.Finally, p j WH is defined in Eq 12: where T Q j indicates a queuing delay of SN j .This parameter is inserted into hello packets.N i expresses the set of neighbors of SN i .Finally, NPK j and DPK j describe the number of new and duplicate packets received from SN j , respectively.In addition, C 1 is the weight coefficient related to the delay parameter, C 2 is the weight coefficient related to the packet reception rate, and C 3 is the weight coefficient related to the redundancy rate such that C 1 , C 2 , and C 3 are fixed numbers in [0, 1] and These weights show the importance of these factors and can be set in accordance with the requirements of the application.
• p j FA : This criterion examines the probability that SN j is a FA node.The most important feature of FA nodes is high energy consumption, and the second feature is high route request sending rate.Another feature of these nodes is a large number of duplicate packets.According to the mentioned points above, Eq 13 calculates p j FA .
where ℓ 1 is the weight coefficient related to the energy factor, ℓ 2 is the weight coefficient related to the packet sending rate, and ℓ 3 is the weight coefficient related to the redundancy rate such that ℓ 1 , ℓ 2 , and ℓ 3 are fixed numbers in [0, 1] and P 3 importance of these factors and can be set in accordance with the requirements of the application.E res;t j and E res;tÀ 1 j represent the remaining energy of SN j in two moments t and t − 1, respectively.E ini is the initial energy of sensor nodes.E res;t j is defined in Eq 14.
where EC t j expresses the energy consumption of SN j at the moment t.It is obtained from Eq 15 according to the energy model stated in Section 4.2.
where E j tx , E j rx , and n EC express the energy needed to send the packets, the energy needed to receive the packets, and the number of data transfer operations performed by SN j , respectively.
Finally, the initial value of the TVDT component in [t − 1, t] (i.e.TVDT ij (t − 1)) is defined in Eq 16: Now, TVDT ij (t) will be calculated by Eq 17.
where μ TVDT and σ TVDT are the mean and standard deviation of TVDT ij (t) calculated by Eqs 19 and 20.
s TVDT ¼ ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi 5.1.2The RT component.In this section, the recommended trust component in the TVT model will be introduced.RT represents that SN i not only relies on its interactions to calculate the trust of SN j , but also uses the trust values recommended by the recommended nodes (RN k ).In TVT, RN k is a common node between SN i and SN j , and R = {RN 1 , RN 2 , . .., RN k , . .., RN |R| } is a set that contains all RN k nodes.In TVT, SN i considers a weight coefficient CT ik (t − 1) for accepting the trust recommended by each RN k .This coefficient expresses the importance of the recommendation provided by RN k .It includes two criteria and is obtained according to Eq 21: • Initial trust of SN i relative to RN k (TVDT ik (t − 1)): According to this criterion, SN i does not consider the recommendation provided by an unreliable RN k .
• The difference between the trust recommended by RN k and the trust calculated by SN i : According to this criterion, SN i prefers the RN k nodes that the TVDT calculated by them is closer to TVDT calculated by SN i .
According to the above criteria, RT ij is calculated according to Eq 22.
so that α 2 [0, 1] is a regulatory coefficient.Algorithm 1 describes how to calculate the trust values of sensor nodes.The time complexity of this algorithm is calculated based on the following steps: • Lines 1 and 2 of Algorithm 1 includes two nested For loops so that each loop is repeated N times.
• There is an IF command inside these nesting loops.It includes the following commands: • Lines 4 to 9 consist of 6 commands with fixed run times r 1 , r 2 , r 3 , r 4 , r 5 , and r 6 , respectively.
• Line 10 contains a For loop, which is repeated |R| times and has four commands (lines 11 to 14) with fixed run times r 7 , r 8 , r 9 , and r 10 , respectively.
Suppose that there is a fixed number such as r so that r > r 7 +r 8 +r 9 +r 10 .In this case, Eq 24 is rewritten to obtain Eq 25: • Lines 16 and 17 are two commands with fixed execution times, r 11 and r 12 , respectively.Hence, the overall execution time of this IF is obtained from Eq 26: If a fixed number like p is considered: According to the above, the time complexity of Algorithm 1 is calculated based on Eq 28: end for 20: end for End

GOA-based trusted inter-cluster routing tree (GTRT)
In CTTRG, a GTRT tree is formed on the network to establish reliable connections between CHs and BS.BS uses the GOA algorithm to build a GTRT tree.It acquires information related to each CH node, for example, the distance to the BS, the trust level, and energy through the periodic exchange of hello messages.Furthermore, it puts all CHs in a set such as TR = {CH 1 , CH 2 , . .., CH q , . .., CH Q } (so that Q is the number of CHs in the network).In the routing tree construction issue, each grasshopper acts as a GTRT tree and specifies the routing path between each CH and BS.The following steps are executed to find the best GTRT tree: • Population formation: Each grasshopper plays the role of a GTRT tree and specifies the arrangement of CHs in the tree.This grasshopper is shown as an array with Q elements so that each element of this array represents the spatial coordinates of CH.In the population formation process, a CH is randomly chosen from the TR set, and its spatial coordinates are inserted into the relevant element of the array.
• GTRT tree corresponding to each grasshopper: This step contains four stages to extract a GTRT tree from a grasshopper: • Stage 1: In all grasshoppers, BS corresponds to the root of the GTRT tree.
• Stage 2: In each grasshopper, the first and second elements of the array are the left and right children of BS namely LP and RP, respectively.
• Stage 3: Note that GTRT is a binary tree, and at each level of this tree, the leftmost parent first identifies its left and right children based on the relevant array.For example, the third and fourth elements of the array are known as left and right children of LP, and the fifth and sixth elements of the array are known as left and right children of RP.
• Stage 4: Stage 3 is repeated to join all CHs to the relevant tree.
• Evaluation: In the GTRT tree construction algorithm, a multi-objective fitness function is considered to evaluate GTRT trees.Then, the positions of grasshoppers will be updated based on this fitness function in each iteration.The purpose of this update process is to change the positions of cluster heads in the routing tree and build the most suitable GTRT tree.To achieve this goal, the GTRT tree construction algorithm considers a multi-objective strategy so that the GTRT tree is built based on three factors, i.e. the distance between CHs and their parent node, the remaining energy of the cluster heads, and their trust level.In this regard, GTRT trees are evaluated in accordance with the fitness function in Eq 29.
so that β is a fixed number in [0, 1] that determines the effect of f 1 and f 2 on F fitness .After this evaluation, BS identifies the best response ( c T d ) in the population.In the GTRT problem, the BS is looking for a tree in which the distance between each CH to its parent is short.The reason behind the selection of this factor is that in the data transmission process between a cluster head node and the base station, if the distance between each cluster head and its parent node is the shortest, this cluster head will transmit data packets to its parent node in the GTRT tree at a high speed (less delay).As a result, it will consume less energy in the data transfer process.Hence, f 1 focuses on the distance of each CH to its parent and is calculated through Eq 30.
ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi . Also, (x i , y i ) and (x p , y p ) express the coordinates of CH i and its parent (Parent i ), respectively.On the other hand, energy is a very effective factor on network performance because the energy of cluster heads is dropped after performing several data transmission processes.Therefore, if the cluster head nodes with less energy are placed in the higher levels of the GTRT tree, their energy will be depleted faster because the nodes placed in the higher levels of the GTRT tree must transmit more data packets, as a result, their energy consumption will be higher.Note that in addition to sending the data related to their cluster members, these nodes must also transmit the data received from the cluster heads in their subtree to the base station.Also, BS considers the trust level of CHs in the fitness function to build the most secure GTRT tree among the cluster head nodes.The meaning of the most secure routing tree is that nodes with higher trust level are placed in the higher levels of the GTRT tree because as mentioned above, these nodes have more responsibilities and their security is more important than the nodes in the lower levels of the GTRT tree.Hence, the BS is looking for a tree that puts the more secure and high-energy CHs at the higher level of GTRT.As a result, f 2 focuses on the order of CHs in GTRT based on their energy and trust through Eq 31.
where E x res;t describes the remaining energy of CH x , E min = 15%E ini is the minimum energy threshold, and E ini indicates the primary energy of the network nodes.Furthermore, TVFT x (t) is the trust of CH x , and D indicates the tree depth, and @ is a fixed number in [0, 1].
• End condition: This stage specifies the stopping condition of the GTRT algorithm, so that the GTRT algorithm is run on 300 iterations, and the optimized GTRT is determined at the final iteration.Finally, BS informs the status of CHs in GTRT by sending a GTRT message that includes the arrangement of CHs in the routing tree.
• Grasshopper updating operation: The position of CHs in the relevant grasshopper will be refreshed using Eq 7.
Algorithm 2 explains how to build a GTRT tree.Time complexity of Algorithm 2 is obtained based on the following steps: • Line 1 contains a command with a constant execution time c 1 .
• Line 2 is a While loop and emphasizes that Algorithm 2 is repeated throughout the simulation period (i.e.t sim ).
• In Line 3, there is an IF condition inside this While loop.
• Inside this IF command, there is a For loop (lines 4-7).This loop is repeated Q times and includes two commands (Lines 5 and 6) with fixed run times c 2 and c 3 .
If we consider a fixed number such as c so that c > c 2 +c 3 .In this case, Eq 32 is rewritten to obtain Eq 33: Therefore, the overall execution time of this IF is obtained from Eq 34: • In line 9, there is an IF command that includes the following commands: • Lines 10, 11 and 12 have three commands with fixed run times c 4 , c 5 , and c 6 .
• Time complexity of Line 13 is equal to O(Q).
• Time complexity of Line 14 is equal to O(Q).
• Time complexity of Line 15 depends on the fitness function presented in Eq 29.Its time complexity is equal to O(Q).
• Line 16 is executed at a fixed time c 6 .Therefore, the run time of this IF is obtained from Eq 35: There is a fixed number such as h, which meets the following condition: • In Line 17, a While loop is repeated 300 times (It is the end condition of the GOA algorithm.Generally, it is displayed as K).
• Lines 18 and 19 contain two commands with fixed run times a 1 and a 2 , respectively.
• Line 20 is dependent on the number of grasshoppers (for example, PG).
• Time complexity of Line 21 is equal to O(Q).
• Time complexity of Line 22 depends on the fitness function and is equal to O(Q).
• Time complexity of Line 23 is determined based on the number of grasshoppers.Therefore, the run time of this While is obtained from Eq 37: IF PG < Q and there is a fixed number such as a, the run time of this While is calculated based on Eq 38: • Line 25 has a fixed runtime.
According to the points mentioned above, the time complexity of Algorithm 2 is O(KQ), so that K is equal to the end condition and Q is the number of cluster heads.
Algorithm 2 GOA-based trusted routing tree (GTRT) for q = 1 to Q do 5: CH q : Forward a Hello packet to the base station; 6: BS: Save the position, the trust amount, and the remaining energy of CH q in its storage space;

Simulation and results
In order to analyze the performance of CTTRG, this method is run on NS2, and the experimental results of CTTRG are compared to those of TBSEER [21], TESRP [22] and TSSRM [23].The reasons behind the selection of these methods are summarized below: • CTTRG, TBSEER, TSSRM, and TESRP are energy-efficient methods and pay attention to the energy parameter in the routing process.In addition, CTTRG, TBSEER, and TSSRM have considered an energy parameter in the trust evaluation process.
• CTTRG, TBSEER, TSSRM, and TESRP have presented powerful and distributed trust mechanisms in their methods.
• CTTRG, TBSEER, TSSRM, and TESRP have the ability to detect and isolate hostile nodes in the network.As a result, a secure environment is provided for data transfer between trusted nodes.• TBSEER, CTTRG, and TSSRM can resist various attacks such as Wormhole, Gray hole, and Flooding.
• TBSEER and CTTRG are hierarchical methods and use the clustering technique, which will improve the energy efficiency of these methods.
In the simulation operation, various methods deal with five attacks, namely BH, SH, WH, GH, and FA, and their results are evaluated and analyzed.In this operation, there are 100 sensor nodes in a network with size 100×100m 2 .Each node has energy equal to one joule, and its initial trust level is 0.5.Moreover, the trust threshold is 0.35 so, if the trust of the nodes is lower than this threshold, those nodes are marked as hostile nodes.Moreover, the sizes of control packets and data packets are 400 bits and 4, 000 bits, respectively.Table 2 states the most important simulation settings.recognize and separate GH nodes in 12 rounds.It has a good performance.In Fig 5, a SH attack occurs on the network.The detection speed of CTTRG and TBSEER is slow and close to TSSRM, so that CTTRG identifies the SH nodes after 25 rounds.However, TBSEER requires 28 rounds to detect and separate these SH nodes.The reason for the successful performance of the suggested scheme in this experiment is that the TVT system used in CTTRG contains a dynamic and time-variant coefficient.It will be reduced or increased using the historical trust values of each node.Hence, CTTRG quickly reduces the trust level of hostile nodes in each round and identifies these nodes in shorter rounds.In Fig 6, a FA attack occurs on the network, and 5% of the network nodes are hostile.All routing approaches slowly reduce the trust level of the FA nodes and detect such an attack.However, our scheme has shown the best performance in identifying this attack because CTTRG uses a parameter called the FA probability to calculate the trust value.Furthermore, it quickly detects these nodes based on the energy level change and the number of duplicate packets.Finally, in the last experiment, Fig 7 considers the WH nodes in the network.CTTRG has identified the attack in 5 rounds and TBSEER has identified the WH nodes in 8 rounds.However, TSSRM and TESRP cannot detect this attack because they do not diminish the trust level of the WH nodes.

Detection speed
In the next experiment, the detection speed of different schemes is evaluated in the presence of several hostile nodes (between 1-10).) than BSEER to diagnose FA nodes.However, our scheme is 10.34% and 20.63% faster than TSSRM and TESRP, respectively.Obviously, an opposite relationship is between the number of hostile nodes and the detection speed so that if a lot of hostile nodes attack the network, the detection rate will be lowered in different schemes because the nodes can participate with each other, and this decreases the accuracy of the recommendations provided by the recommended nodes.However, in CTTRG, these recommendations are prioritized, meaning that if a recommender node is not reliable or secure, its recommendation is very different from the direct trust evaluated by the trusted nodes and hence, this recommendation has less priority than other recommendations, and has little effect on the final trust.missing data packets.On the other hand, three factors, namely the distance between each CH to its parent, the trust level of the network nodes, and their energy are considered when forming a GTRT tree.This causes the creation of a stable and secure tree between CHs.

Delay
Delay is the average time required to send a packet from the source node to the BS.In Fig 13, CTTRG decreases delay by 9.40%, 14.62%, and 23.73% compared to TBSEER, TSSRM, and TESRP, respectively.In CTTRG, delay is reduced in the routing process because it transfers data packets through the optimized GTRT tree.As shown in Fig 13, delay is directly proportional to the number of hostile nodes in the network, so if the number of these nodes is high, the data transfer operation is delayed in all routing methods.This is because the security systems can difficultly detect a high number of malicious nodes on the network and hence, some hostile nodes are not identified and will have a negative effect on network performance.

Energy consumption
In Fig 14, the energy consumed in different schemes is compared with each other.Based on this figure, it can be seen that CTTRG has improved energy consumption by 8.42%, 22.66%, and 28.38% compared to TBSEER, TSSRM, and TESRP, respectively.The main reason for this improvement is that CTTRG uses tree-cluster topology, which greatly increases the efficiency of our method in terms of energy consumption.On the other hand, in the GTRT tree construction process, the remaining energy of cluster heads is considered as an important factor in the fitness function.As a result, the designed GTRT tree balances the energy consumption of CHs in the network and increases network lifetime.

Conclusion
In this paper, a cluster-tree-based trusted routing method using the grasshopper optimization algorithm is proposed for WSNs.CTTRG contains two components: the time-variant trust mechanism and the GOA-based trusted routing tree.The TVT mechanism analyzes the behavior of sensor nodes and measures their trust level based on the three criteria, including the BH, GH, and SH probability, the WH probability, and the FA probability.Additionally, the GTRT tree is looking for safe and trust communication paths between CHs and BS.CTTRG is run on NS2 and its performance is compared with TBSEER, TSSRM, and TESRP.The experimental results show that CTTRG lowers the detection speed of BH nodes by 2.46%, 13.74%, and 23.69%, the detection speed of GH nodes by 2.28%, 9.82%, and 17.097%, and the detection speed of SH nodes by 6.78%, 19.22%, and 27.62% in comparison with TBSEER, TSSRM, and TESRP, respectively.However, CTTRG has a lower speed (approximately 5.45%) than TBSEER to diagnose FA nodes.In addition, our scheme lowers PLR by 26.23%, 38.36%, and 50.18% and delay by 9.40%, 14.62%, and 23.73% compared to TBSEER, TSSRM, and TESRP, respectively.In future research directions, we will use new techniques, for example, machine learning or meta-heuristic algorithms to enhance the strength of the trust system in CTTRG.Furthermore, GTRT tree can be constructed using different nature-based algorithms to obtain the best tree.thank Michal Merta, and Zdene ˇk Truhla ´ř for their help with the research connected with the topic of the article.

Fig 1 .
Fig 1. Network model in CTTRG.https://doi.org/10.1371/journal.pone.0289173.g001 Fig 1 displays the network model.Additionally, the nodes are partitioned into multiple clusters using the LEACH algorithm, and CHs are selected from sensor nodes rotationally.The following assumptions are summarized for the network model used in CTTRG:

Fig 7 .Fig 8 .
Fig 7. Trust changes of WH nodes in different schemes.https://doi.org/10.1371/journal.pone.0289173.g007 Fig 8 shows the detection speed of different schemes for a BH attack.This figure proves that CTTRG has the best detection speed and diagnoses the BH nodes approximately 2.46%, 13.74%, and 23.69% faster than TBSEER, TSSRM, and TESRP, respectively.Moreover, Fig 9 compares the detection speed of different approaches for a GH attack.According to this figure, CTTRG has improved the detection speed of GH nodes by

6. 3
Packet loss rate (PLR) PLR means the ratio of the number of packets, which do not arrive at the BS to all packets sent to BS.The PLR results in different schemes are stated in Fig 12 when there are 1-8 hostile nodes in the network.According to this figure, CTTRG has the lowest PLR and reduces it by 26.23%, 38.36%, and 50.18% in comparison with TBSEER, TSSRM, and TESRP, respectively.This is due to the powerful security mechanism designed in CTTRG, which identifies hostile nodes quickly.It will also prevent the effect of malicious nodes and reduces the number of

Table 1 .
(Continued) 1) is the initial trust value of RN k relative to SN j , and |R| is the number of members of R = {RN 1 , RN 2 , . .., RN k , . .., RN |R| }. 5.1.3TVFT component.Now, given that TVDT is a time-variant function.Therefore, TVFT is also defined as a time-variant trust function provided in Eq 23.
so that N indicates the number of sensor nodes and |R| represents the number of recommender nodes.Algorithm 1 Time variant trust model (TVT model) SN 1 , SN 2 , . .., SN i , . .., SN N : Sensor nodes in the network Output: TVFT t ij : Time variant final trust of SN j estimated by SN i . Input: 1 , CH 2 , . .., CH q , . .., CH Q }: