1 Introduction

Wireless sensor networks have made great progress in military reconnaissance, environmental monitoring, medical services, smart home, personnel positioning, industrial and commercial fields. However, with the increasing demand for awareness of the surrounding information, new requirements have been put forward to the wireless sensor network [1]. In typical wireless ad hoc networks, besides the wireless sensor network, it also includes Ad hoc network and so on. The network protocol of wireless sensor originates from Ad hoc network. However, there are many differences and emphasis on the application purposes and use scenarios of these two kinds of self-organizing networks [2]. In addition to the low transmission rate requirements for wireless sensor networks, the network layer routing protocol focused on this paper is discussed as an example.

Energy aspects: Energy is not a key problem in the Ah hoc network. However, the wireless sensor network needs to solve the problem of hard work energy supply under the bad environment in the field. The routing algorithm of the traditional Ad hoc network cannot meet its requirements [3].

Network scale aspect: The application of wireless sensor network is often large network with a large number of nodes [4]. A large number of sensor network nodes are also testing the network and routing capabilities of traditional routing algorithms [5].

The continuous changes in the topology of the network structure: Wireless sensor network (WSN) should be able to solve the problem of frequent changes of network structure caused by node failure and movement [6].

In view of the particularity of wireless sensor network application and the special requirements of people to wireless sensor network, at present, the existing network protocols cannot meet the needs of people at present. As a result, the research and improvement of wireless sensor network protocol has been forced in the eyebrow [7].

2 Research and improvement of energy efficient routing algorithm

2.1 Energy algorithm model with minimum path

In minimum total transmission power routing (MTPR), The wireless signal transmission attenuation model of nodes in wireless sensor network is as follows:

$$ Gij = \frac{\zeta }{{d^{r} }} $$
(1)

\( \zeta \) is the attenuation coefficient of the wireless channel and \( d \) is the propagation distance of the signal. When conducting short distance transmission, r = 2 is set. When conducting long distance transmission, r = 4 is set. In order to ensure that node j can successfully receive nodes/sent packets, the signal is received by the node j through the d distance. When a certain bit error rate (BER) is required, the signal to noise ratio (SNR) of the wireless signal must be larger than a certain value \( \phi \). The function of BER after receiving a packet is reported as \( \phi \) (BER). In order to ensure that the packet sent by the node i is successfully received by the node j, the packet SNR must satisfy the following formula:

$$ SNR = \frac{{p_{0} G_{ij} }}{{\sum_{k \ne j} {p_{k} G_{kj} + \eta {}_{j}} }}\phi (BER) $$
(2)

In the formula (2), p0 is the transmit power of the antenna in node i. Gij is the attenuation model of the wireless channel. \( \eta {}_{j} \) is the noise received by the node j. Taking formula (2) into formula (1), formula (3) can be obtained:

$$ SNR = \frac{{p_{0} \frac{\zeta }{{d_{ij}^{r} }}}}{{\sum_{k \ne j} {p_{k} \frac{\zeta }{{d_{ij}^{r} }} + \eta {}_{j}} }}\phi (BER) $$
(3)

According to formula (2), whether the packet sent by the node i is correctly received by the node j depends on the following factors: the transmission power p0 of the node i; channel noise \( \eta {}_{j} \); distance between nodes i and j. It is further assumed that if the channel noise is certain, whether the packet can be successfully forwarded depends on the transmission power p0 of the node i and the distance d between two points [8].

Assuming that the collection of all nodes in the network is V = {1, 2, 3,…, n}. The link between any two points i and j is L(i, j). R is the collection of the path of the source node s to the destination node d. The total energy consumption between an arbitrary source node and the destination node is defined as:

$$ p_{j} = \sum\limits_{i,j \in l} {p(i,j)\quad \quad l \in R} $$
(4)

The minimum energy of the path is:

$$ p_{ \hbox{min} } = { \hbox{min} }\{ p_{l} \} = \hbox{min} \left\{ {\sum\limits_{{{\text{i,j}} \in {\text{l}}}} {p(i,j)} \quad l \in R} \right\} $$
(5)

According to the attenuation characteristics of wireless channel, it is known that in order to obtain the path of minimum energy consumption, that is to obtain pmin, we should increase the number of relay nodes as much as possible between the source and destination nodes to reduce the loss of energy. However, as the number of routing hops increases, the stability is worse. The possibility of moving or invalidation of the intermediate nodes is large [9]. Therefore, the maximum number of relay nodes is added between the source node and the destination node, and the node is not necessarily the best route. The relevant researchers put forward the concept of node forwarding packet overhead for this problem. The forwarding packet energy consumption model is defined as follows:

$$ C(i,j) = p_{r} (i,j) + p_{r} (i) $$
(6)

Pr(i) is the energy consumed by the node i after receiving the packet. pr(i, j) is the energy consumed by the node i after sending packets. It is applied to the shortest path algorithm of Bellman-Ford, and the energy consumption of the source node/destination node is as follows:

$$ C(i) = { \hbox{min} }\{ C(i,j)\} + c(j)\} = \hbox{min} \{ p_{r} (i,j) + p_{r} (i) + c(j)\} $$
(7)

Node j is a neighbour node of node i. c(j) is the minimum energy consumption of node j to reach the destination node. Further, according to the energy dissipation model of the formula (1), the formula (7) can be further transformed into:

$$ C(i) = { \hbox{min} }\{ E_{\text{elec}} \times k \times (i,j)\} + c(j)\} $$
(8)

In the formula, C(i) is the minimum energy consumption of node i to reach the destination node. k is the packet length. pr is related to the distance (the actual distance, not the weight value) between the node i and the j.

2.2 Minimum energy efficient routing algorithm based on condition

Although the minimum energy consumption algorithm reduces the energy consumption of the entire network, it does not pay attention to the energy consumption of each node in the network. As a result, a key node is used too frequently and the energy is exhausted. In addition, network segmentation reduces the lifetime of the entire network. The MBCR algorithm is proposed in order to solve the problem [10].

The MBCR algorithm focuses on the residual energy of the path. To some extent, it mitigates the shortcomings of the minimum energy consumption routing algorithm. However, the algorithm still does not solve this problem thoroughly [11]. Because it does not pay attention to every network node, there is still a problem of overuse of a node in the network. Moreover, the energy consumption of the whole network is too high because the energy consumption problem of the whole network is not taken into account [12].

In order to overcome the shortcomings of the MBCR algorithm, a MMBCR routing algorithm is proposed to ensure that no nodes are overused to lead to energy consumption.

The MMBCR routing algorithm uses the energy reciprocal of the node with the smallest residual energy in each path as the sum of the weight of the path. Thus, compared to the MBCR algorithm, the MMBCR routing algorithm can do better in avoiding the node energy being overconsumed in the path. However, the MMBCR algorithm and the MBCR routing algorithm bring other problems. When selecting the best routing in the network, the node may increase the hop number greatly in order to avoid a node with low energy. In this way, the total energy consumption of the whole network will rise, and the total energy consumption in the network is too fast. In the same way, the lifetime of the entire network will be shortened [13].

It can be seen from the above analysis that the energy consumption of the nodes in the network cannot be balanced at the same time when the total energy consumption is reduced as much as possible in the wireless sensor network. That is to say, MTPR and MMBCR algorithm cannot be effective at the same time, this is an irreconcilable contradiction. However, there must be a trade-off between the two in the wireless sensor network. Therefore, in order to coordinate the contradiction between the two routing protocols, the CMMBCRW routing algorithm is proposed.

In all paths of a node to the destination node in a network, when there is a path where all the remaining energy of nodes is greater than a threshold, the minimum energy total energy efficient algorithm is adopted. This purpose is the original intention of the CMMBCR routing algorithm. In all paths of a node reaching the destination node, the remaining energy of at least one node is less than the threshold value. The minimum and maximum battery overhead routing algorithm is used [14].

The CMMBCR algorithm is specifically described as: assuming that the residual energy of a path r is:

$$ E^{r}_{left - \hbox{min} e} = \mathop {\hbox{min} }\limits_{i \in r} \{ e_{i}^{t} \} $$
(9)

The set A is a set of routing sets in the network path with the residual energy of the path greater than a threshold value. The expression is as follows:

$$ E^{r} \mathop {_{left - \hbox{min} e} }\limits_{{{\text{r}} \in R}} \ge \gamma $$
(10)

In the formula, R is the set of routes for any source node in the network to reach its destination node. \( \gamma \) is the default threshold value. Assuming that the set Q is the set of all paths for a source node to reach the destination node. The routing algorithm is selected as follows:

When \( A \cap Q \ne \emptyset \), the minimum total energy efficient routing algorithm is used to select the best route in \( A \cap Q \).

When \( A \cap Q \ne \emptyset \), a balanced energy efficient routing algorithm is selected.

2.3 Energy efficient (PEC-MBCR) routing algorithm based on partial energy level

Through the above analysis, we can find that the minimum energy efficient routing algorithm, the energy balanced routing algorithm and the conditional minimum energy efficient routing algorithm cannot make the network energy effectively utilized to achieve the best state.

However, the minimum energy efficient routing algorithm (CMMBCR) based on condition provides a good inspiration for us. Different routing algorithms are used under different network residual energy. However, the threshold value introduced in the CMMBCR routing algorithm is too rigid. It cannot change with the remaining energy level of the whole network, and cannot solve the problem of effective utilization of energy. In order to solve the above problems, the energy efficient routing algorithm based on partial energy level is proposed in this paper. Because of its grouping, it can also be called an energy efficient routing algorithm based on packet.

The residual energy level in the path is used as the path grouping in this algorithm. In addition, the certain value is needed to measure the residual energy level of the nodes in the path. Moreover, the value must be reduced as the energy of the entire network decreases. As a result, the average residual energy level in the entire network is a good choice. Assuming that the undirected connected network model is \( G = \{ V,d\} \) (V: node set; d: distance or weight). In the formula, \( V = \{ 1,2,3, \ldots ,n\} \). n is the number of nodes in the network. The average energy level of all network nodes is:

$$ E^{r}_{{left - {\text{aver}}}} = \frac{1}{n} \times \sum_{{{\text{i}} \in V}}^{\text{n}} {e_{t}^{l} } $$
(11)

In the formula (11), ei is the residual energy of the node. However, for wireless sensor networks based on partial network topology, the solution of \( E_{{left - {\text{aver}}}} \) is not easy. Therefore, the definition of partial average energy level is proposed in this paper. The definition of partial average energy level is that, for a node i, the partial average energy level is the average energy level of all its neighbour nodes. Assuming that NBt = {1, 2, 3, …, n0} is the set of the node/neighbour node. As shown in Fig. 1, the calculation formula of the partial average energy level of the node i is:

Fig. 1
figure 1

Node/neighbour node schematic diagram

$$ E^{r}_{{left - {\text{aver}}}} = \frac{1}{{n_{0} }} \times \sum_{{{\text{i}} \in NB{\text{t}}}}^{{{\text{n}}_{ 0} }} {e_{l}^{t} } $$
(12)

In order to better measure the residual energy level of a specific node, or when the residual energy level of a node is below a certain level of partial energy level, it is considered that the node has been overused. In order to quantify this degree, the algorithm introduces the threshold value a. By adjusting the size of the a, the residual energy of the node is controlled at a degree below the level of energy. Furthermore, this algorithm is more flexible to adapt to different networks.

The routing packet mode in the energy efficient routing algorithm based on the partial energy level and the application of the threshold a are as follows: The packet of one path r from the source node to the destination node is as follows:

If \( \forall i \in r \), then \( e_{i}^{t} \ge a \times E_{left - aver}^{i} (0 < a < 1) \). The group of this path is 0. The analysis shows that the residual energy level of all nodes of the path is at a higher level. Therefore, the path adopts the minimum total energy efficient algorithm.

If \( \exists i \in r \), then \( e_{i}^{t} < a \times E_{left - aver}^{i} (0 < a < 1) \). The group of this path is 1. Because the residual energy level of this path exists in a lower state, it should be avoided as far as possible. Therefore, a balanced energy algorithm, such as the MMBCR algorithm, should be used.

3 Implementation of energy efficient PEC-AODV routing protocol based on partial energy level

3.1 Routing discovery and routing selection of AODV routing protocol

In the network using AODV routing protocol, if a source node and a destination node have mutual arrival routes, the AODV routing protocol will not work. Only when a source node needs to send information to a new destination node, and the routing information to the destination node is unknown, the AODV routing protocol will work.

As shown in Fig. 2, the routing discovery and selection process are explained. In order to find the routing information to reach the destination node 8, the source node 1 broadcasts the RREQ message to its neighbour nodes 1 and 2. Because the neighbour nodes do not reach the routing information of the destination node as well, the neighbour nodes 1 and 2 also forward the RREQ to their adjacent nodes. The existence of the RREQID (routing request message identification) domain ensures that every node in the network only processes the same RREQ message once, which reduces the degree of broadcast storm.

Fig. 2
figure 2

Route discovery and routing schematic diagram. Note: Some of the RREQ and RREP messages in the graph are not drawn

3.2 The acquisition of partial energy level for PEC-AODV routing protocol

In order to achieve simplicity, the AODV routing protocol is improved on the basis of the existing AODV routing protocol. The energy efficient routing algorithm (PEC-MBCR) based on partial energy level is implemented. We call it the PEC-AODV routing protocol.

In the PEC-AODV routing protocol, in order to enable the network node to get the partial energy level of its own network part, the Hello message is used to transmit the residual energy information. A node provides link information and its own energy information to its neighbour nodes through a periodic broadcast Hello message. At the same time, a node can also monitor the link information of its neighbour nodes by listening to the Hello message of its neighbour nodes. In addition, a part of their energy level can be determined by tracking the energy information of multiple neighbour nodes. In the Hello message type RREP information, the group and the setting of minimum energy field are shown in Table 1.

Table 1 The group and the setting of minimum energy field in the Hello message type RREP information

In message format, the rest of the domain values are set to the same as the standard AODV routing protocol. In order to maintain routing, nodes in the network will send a Hello message to their neighbour nodes in a certain period of time. At the same time, a node periodically receives Hello messages sent by their neighbours with residual energy information. The EC-AODV routing protocol adds an energy domain to each neighbour in the neighbour table, which is used to represent the neighbour’s current residual energy level.

This energy value is derived from the received Hello information from the neighbour. The nodes can get some of their energy level by seeking and obtaining the average value of the remaining energy of all their neighbours according to the formula.

4 Simulation and performance evaluation of PEC-AODV routing protocol

4.1 NS-2 routing protocol simulation platform

In order to evaluate the performance of the PEC-AODV routing protocol well, this simulation experiment uses the NS-2 (Network Simulator Version2) simulation platform.

NS-2 (Network Simulator Version2) is an object-oriented network simulator originally developed by the California University at Berkeley. There is a virtual timer within itself, and all the simulations are driven by discrete events.

The main flow of network simulation using NS-2 is as follows: First, the researchers should determine the simulation protocol, such as whether the protocol is new. If the new protocol is a new protocol, the new protocol module needs to be added to the NS-2. It can also be improved from the existing similar protocols. If the existing protocol is simulated, there is no new source code that need to be added. The script files are used to simulate the NS-2 network components directly. Then, the researchers compile the protocol according to the problems proposed in the first step. If it is a new protocol, the source code of the protocol is written and it is added to NS-2 to compile until the compilation is successful. If NS-2 has an agreement, then the process jumps to the next step directly.

Finally, the researchers use the compiled code and OTcl script to do the simulation, and analyzes the corresponding Trace files generated by NS-2 in the simulation process. The simulation results are obtained. If the simulation result is not satisfied, then the process jumps back to the second step until the desired simulation results are reached.

The PEC-AODV routing protocol is a new protocol that needs to add new protocol code to the NS-2. In order to simplify the operation process, the simulation is carried out from the original protocol of NS-2 to the improvement of the AODV protocol code. The original AODV routing protocol module files involved in NS- 2 are as follows: ~/aodv/aodv.cc, ~/aodv/aodv.h, ~/aodv/aodv_logs.cc, ~/aodv/aodv_packet.h, ~/aodv/aodv_rqueue.cc, ~/aodv/aodv_rqueue.h, ~/aodv/aodv__rtable.cc, ~/aodv/aodv_rtable.h.

The PEC-AODV routing protocol has improved the RREQ control message control process of AODV. It involves ~/aodv/aodv_rtable.cc, ~/aodv/aodv_rtable.h, ~/aodv/aodv_packet.h, ~/aodv/aodv.cc, ~/aodv/aodv.h, ~/aodv/aodv_packet.h. When RREQ routing discovery control information is propagated towards the destination node, it can update paths according to the residual energy level of each node in the path and the average energy level of the network part. The workflow is shown in Fig. 3.

Fig. 3
figure 3

Schematic diagram of the workflow of RREQ messages in the PEC-AODV routing protocol

The PEC-AODV routing protocol has improved the RREP control message workflow of AODV. It mainly involves the file with the RREQ control message. The design function is that routing recovery can group the current recovery path according to the residual energy level of each node in the current road and the partial average energy level of the network. Moreover, it can bring back the remaining energy level in the current path and the remaining energy value of the lowest node, so that the source node can choose the best route based on this information. The detailed workflow is shown in Fig. 4.

Fig. 4
figure 4

Schematic diagram of RREP message workflow in PEC-AODV routing protocol

4.2 PEC-AODV experimental environment and simulation scene

In this chapter, NS-2 simulation platform is used to compare the performance of PEC-AODV and AODV routing protocols under different α values. The scene file is created using the CMU tool setdest, and the simulation scene setting is shown in Table 2.

Table 2 Simulation scenario parameter setting table

Const BitRate (CBR) is created by cbrgen.td in CMU tool. The CBR stream belongs to a fixed rate bit stream, which can compare the performance of the PEC-AODV routing protocol in the case of different a values. CBR parameters setting and simulation sensor node settings are not described here. Simulation protocol and simulation parameters are shown in Table 3.

Table 3 Simulation parameters of PEC-AODV protocol

4.3 Analysis of PEC-AODV simulation results

In the PEC-AODV routing protocol, when the a value is 0, it is the standard AODV routing protocol, that is, the shortest path algorithm. When the a value is 1, the PEC-AODV routing protocol uses the residual energy of the least residual energy nodes in the path as the shortest path algorithm for path overhead. This is the maximum-minimum battery overhead (MMBCR) routing algorithm. Therefore, the AODV routing protocol and the maximum-minimum battery overhead (MMBCR) routing algorithm are analyzed as two special cases of the PEC-AODV routing protocol. In order to intuitively display the performance of PEC-AODV routing protocol under different a parameter, we use the number of remaining nodes in the network at different times to compare the performance of the protocol under all a parameter.

Through the simulation of different a values and the analysis of Tmce.tr files, the number of remaining nodes at each time of each network with different a parameters is counted. Figure 5 shows the number of nodes remaining in the network at different times. As shown in Fig. 5, it shows that in the same time, the number of remaining nodes in network is the largest when a = 0.68. The number of remaining nodes in network is the least when a = 3 (For example, when t = 300 and a = 0.68, the number of remaining nodes in network is 55. When a = 0.3, the number of remaining nodes in network is 51). At the same time, it can be clearly seen that the number of nodes in the network (the right curve in the graph) decreases most slowly when a = 0.68, that is, the survival time of most nodes is longer.

Fig. 5
figure 5

Schematic diagram of the remaining nodes in the PEC-A0DV routing protocol

The comparison between the PEC-AODV routing protocol and the existing AODV routing algorithm is as follows.

As shown in Figs. 6 and 7, under a certain network environment and appropriate a values, the PEC-AODV routing protocol can effectively prolong the network lifetime relative to the existing MMBCR routing algorithms.

Fig. 6
figure 6

Comparison of PEC-AODV routing protocol with residual nodes of AODV protocol

Fig. 7
figure 7

Comparison of PEC-AODV routing protocol with residual nodes of MBCR algorithm

5 Conclusion

The energy efficient routing protocol of wireless sensor network is studied around the bottleneck problem of network layer energy efficient use of wireless sensor network. First, the current research status and advantages and disadvantages of the existing energy efficient routing algorithms for wireless sensor networks are analyzed. On the basis of existing algorithms, an energy efficient (PEC-MBCR) routing algorithm based on partial energy level is proposed. The energy efficient routing algorithm based on partial energy level is a trade-off between energy efficiency and energy equilibrium consumption of each node. In order to maximize the efficiency of energy use, part of the problem is to avoid the existing energy efficient routing algorithm. The algorithm also introduces variable factor a, and the adjustment of different a values can make the PEC-MBCR routing algorithm more suitable for the network under different usage scenarios.

Secondly, based on the PEC-MBCR routing algorithm, the PEC-AODV routing protocol is implemented on the basis of the existing AODV routing protocol. The PEC-AODV routing protocol can avoid the unbalance of the energy consumption among the nodes in the network, which can be avoided by the original AODV routing protocol. At the same time, the problem of high total network energy consumption which is easily caused by the existing minimum maximum battery pin (MMBCR) routing algorithm is also taken into account.

Finally, the PEC-AODV protocol module is added to the NS-2 network simulation platform. The NS-2 is used to simulate and evaluate the performance of the PEC-AODV protocol. The result is that the PEC-AODV routing protocol is more efficient than the existing energy efficient routing protocols and algorithms in the case of proper threshold setting. The purpose of this study is achieved.