# Routing in Mobile Wireless Sensor Networks: A Leader-Based Approach+
## 3 A Leader-Based Routing Approach (LBR)
### Building the Communication Tree
#### 3.2.2 Protocol LBR2  
Observe than in our second protocol version, LBR2 (Algorithm 3), the broadcast at Line 6 of LBR1 in Figure 1 has been removed. Instead, in LBR2, we introduce a task executed in every node \(p_{i}\) to broadcast every \(\alpha\) time the current routing information of \(p_{i}\) when \(p_{i}\) considers itself as connected (see Lines 30-34 in Algorithm 3). This allows us to adopt a windowed mechanism at the MAC layer and reduce the probability of collision in communications.  
```
1\(||\)Task 1-b: when\((j,\text{leader},\text{sender},\text{round},\text{distance},\text{msgList})\)is received at time \(t\)such that\(j\in\mathbb{N}_{i}(t)\)and\(W_{i\gets j}(t)>\xi(tech)\){When receiving a leader message} if\(round\
eq\text{prev}Round_{i}\)then
2 if\(round>currentRound_{i}\)then
3 prev\(Round\gets 0\);
4\(sinkBy_{i}\gets sender\);
5\(sinkDistance_{i}\gets distance\);
6\(currentRound\gets round\);
7 set\(timer\_connectivity_{i}\)totimeout;
8\(connected_{i}\gets True\);
9
10 elseif\(round=currentRound_{i}\)then
11 if\(sinkDistance_{i}>distance\)then
12\(sinkBy_{i}\gets sender\);
13\(sinkDistance_{i}\gets distance\);
14\(active\_timer\_neighbour_{i}\gets True\);
15 set\(timer\_neighbour_{i}\)to timeout;
16
17 elseif\(sinkDistance_{i}=distance\)and\(sinkBy_{i}\
eq sender\)andnot\(active\_timer\_neighbour_{i}\)and\(sender>sinkBy_{i}\)then
18\(sinkBy_{i}\gets sender\);
19\(active\_timer\_neighbour_{i}\gets True\);
20\(active\_timer\_neighbour_{i}\gets True\);
21 set\(timer\_neighbour_{i}\)to timeout;
22
23
24 end if
25
26 end if
27
28 end if
29
30 end if
310
32 end if
33
34 end if
35
36 end if
37
38 end if
39
```  
**Algorithm 3**The modifications required by LBR2 to the previous algorithm to be executed by any sensing node \(p_{i}\).  
Additionally, in this second protocol, we modify the leadership criteria as follows. The \(sinkBy_{i}\) node will be the one with the lowest distance to \(s\) that firstly communicates with \(p_{i}\). This mechanism is a novel strategy that allows balancing the energy consumption in intermediate nodes at routing time. If many of the nodes share the same \(sinkBy_{i}\), this leader will eventually saturate and the system performance will decrease in terms of battery. To correctly load balance the spanning tree, in LBR2, we introduce an extra timer to monitor the current parent node. This \(timer\_neighbour_{i}\) is set when a new \(sinkBy_{i}\) node is adopted by \(p_{i}\) (Line 15 in Algorithm 3). Since every node \(p_{i}\) sends its information periodically by Line 32, \(sinkBy_{i}\), it will also send a leader message resetting again the \(timer\_neighbour\) by Line 22. On the other hand, if \(timer\_neighbour_{i}\) expires (Lines 27-29), \(p_{i}\) is allowed to re-elect another \(sinkBy_{i}\) among those that have the same distance to \(s\), i.e., the condition in Line 16 is satisfied since \(active\_timer\_neighbour_{i}\) has been previously set to false by Line 28.  
Note that the higher \(\beta\) and \(timeout\) values are, the slower the graph connectivity change detection is. This introduces a trade-off between the reaction time and the number of messages sent by the system in order to provide good QoS and energy-efficiency at the same time.  
Observe also that the global number of messages sent is linear with the number of nodes in the system, which makes LBR2 scalable regarding communication cost.