# La-CTP: Loop-Aware Routing for Energy-Harvesting Wireless Sensor Networks
## 5 Design of La-CTP
### Handling Loops and Invalid Routes
Different from La-CTP, however, CTP identifies the local network status only by the traffic coming from children nodes, which easily lets the parent node mistaken in thinking \"all the upstream network is working smoothly and then I do not need to change anything.\" La-CTP uses a threshold, which is denoted by NO_TRAFFIC and set to 2560 ms in implementation. If the node has not received any passing-by packets within \(\Delta t\) and \(\Delta t\geq\)NO_TRAFFIC, it will stop its current beacon timer, immediately followed by resetting \(T_{b}\) with MIN_INTERVAL and starting a new beacon timer of \(T_{b}\). Second, if a parent node \(u\) receives one packet from its child node \(v\) and \(\Delta t<\)NO_TRAFFIC, then \(u\) will extend its beacon timer SCALE_RATIO times, assuming that the local network runs properly with high probability. Here parameter SCALE_RATIO is a constant empirically set to 2 in the implementation of La-CTP. The exponentially prolonged beacon timer saves the energy of \(u\) and reduces the possible co-channel conflicts in the vicinity of \(u\). Third, La-CTP shortens its beacon timer, based on the routing messages received. If a parent node \(u\) receives a beaconing message from child \(v\), \(u\) will first check the current status of \(v\) encapsulated in this message, and then determine its beacon timer adjustment, depending on the current status of \(v\). If \(v\) broadcasts the beaconing message for seeking new route, \(u\) will shorten its beacon timer down to the minimum. If the message of \(v\) tells that it has detected a loop, \(u\) will shorten its beacon timer by SCALE_RATIO fold. We deal with the new route request and the loop-detection event with different timer adjustment policies because sometimes, the loop-detection event does not always indicate that a loop really happens to the child node. For example, the occasional dramatic link variation in short term affects the link quality evaluation that is made by the ETX component in real time, and then gives rise to a spike of link ETX value, which is possibly followed by a false loop detection. Therefore, La-CTP can wait to see whether loops actually occur at the upstreaming nodes, while shortening its beacon timer step by step. In the case with true loop detection, of course, La-CTP trades off some certain loop-response speed for better energy efficiency. Parameter NO_TRAFFIC lets a node re-connect with its in-loop child nodes in a proactive way, while parameter SCALE_RATIO passively tunes the beacon timer in a packet-driven way, making the node propoerly react to its local network status--continuously prolonging the beacon timer to save energy or shortening the beacon timer to rescue its child nodes from loops. In fact, it is hard to obtain theoretically optimal configurations of NO_TRAFFIC and SCALE_RATIO. Their configurations, open to future developers, depend on the data traffic intensity and the network scale in reality. In experiments, however, we found that the values of NO_TRAFFIC only have insignificant effect on the overall network performance, because inherently, EH-WSNs will not well support traffic-intensive applications. Larger SCALE_RATIO will surely benefit fast loop handling when loops are continually detected at the child nodes, because it can make parent's beacon timer drop to the minimum more quickly (i.e., less exponential decreases are needed before the minium is hit). However, a larger SCALE_RATIO will make the parent node aggressively react to the false or the sparse loop-detection event by broadcasting periodic messages with the time interval of length MIN_INTERVAL, and then will waste the network resource. In the future we will examine the effect of SCALE_RATIO under certain scenarios and investigate traffic-adaptive and resource-aware update policy of SCALE_RATIO. It is worth noting that Algorithm 2 uses a _task_, named adjustBeaconTimer, to carry out the beacon timer adjustment.