3.2 SPF construction
3.2.1 Distributed SPF algorithm
SPF construction
G= (V, E, w) and Z ⊆ V. We assume that at the beginning of the algorithm there exists a breadth first search (BFS) tree ofG rooted at a terminal r. Note that a BFS tree can be computed using O(D) rounds and O(m) messages in the CONGEST model [114].
We also assume that r, the root node, knows the height (denoted as h) of the BFS tree.
Note that the height of a node is the number of edges on the longest path between that node and a leaf, and the height of a tree is the height of the root node. Intuitivelyrcan compute husing a broadcast and convergecast procedure as follows. Initiallyrsends a message called hcompute heightito all of its child nodes in the BFS tree. Upon receivinghcompute heighti, each node forwards it to all of its child nodes. Whenever a leaf nodevin the BFS tree receives hcompute heighti, it sets its h(v) to 0 and sends a message called hmy height(h(v))i to its parent. Upon receiving hmy height(h(vi))i from each of its child nodes vi ∈child(u), an internal nodeusets h(u) to max{h(vi)|vi ∈child(u) and 1≤i≤ |child(u)|}+ 1 and sends the resulted h(u) to its parent.1 In this way eventually r receives the heights of all of its child nodes. Then it computesh(r) = max{h(vi)|vi ∈child(r) and 1≤i≤ |child(r)|}+ 1, which is the required height of the BFS tree. It is obvious thatr can computehof the BFS tree using O(h) rounds andO(n) messages. Since the height of the BFS tree (h(r)) can be at mostD, the round complexity of computing h(r) in the worst-case is O(D).
Input. Each node knows whether it is a terminal or not, and the set of edges incident on it. Let bfs π(v) denotes the parent of a node v in the BFS tree rooted at r. Except r, all other nodes in the BFS tree know their parents; forr we assume thatbfs π(r) = r. Initially, tπ(v) =nill,ts(v) = nill, andtd(v) = ∞for each nodev ∈V. Note here that the notations tπ,ts, and td are used to describe the tentative SPF. Furthermore r uses two additional local variables calledheight andstart flag which are initially set toh andfalse respectively.
Output. Whenever the algorithm terminates, d(v) = td(v),π(v) =tπ(v), and s(v) = ts(v) for each node v ∈V.
Outline of the algorithm. The special noder initiates the algorithm by settingstart flag
=true,td(r) =0,tπ(r) = r,ts(r) = r, and sendinghupdate(r, ts(r), td(r))imessages on all of its incident edges. After that if r does not receive any message in a round, it sets height to height −1. Whenever height beomes −1, r sets start flag to false and the algorithm terminates.
Let U and Y denote the set of hupdatei and the set of hechoi messages respectively
1Here |child(u)|denotes the number of child nodes ofuin the BFS tree.
SPF algorithm at node v upon receiving a set of messages or no message.
1: upon receiving no message
2: if v =r and v ∈Z then . we assume thatr ∈Z
3: if start flag =false then
4: start flag ←true; .spontaneous awaken of the root node
5: ts ←v;tπ←v;td ←0;height ←h;update flag ←false; .update flag(v) denotes a boolean variable at node v.
6: for each e ∈δ(v) do
7: send hupdate(v, ts, td)i one
8: end for
9: else
10: height ←height −1;
11: if height =−1 then
12: start flag ←false; . Algorithm terminates
13: end if
14: end if
15: end if
16: upon receiving a set of hupdatei or hechoi messages .U 6=φ orY 6=φ
17: if v ∈Z and td =∞ then . for the first time v receives some messages
18: ts ←v;tπ←v;td ←0;
19: if update flag =false then
20: update flag ←true;
21: end if
22: else if v ∈V \Z then
23: for eachhupdate(idn(e),tsn(e),tdn(e))i ∈U such that e ∈δ(v) do
24: if tdn(e) +we <td then
25: td ←tdn(e) +we;tπ ←idn(e);ts ←tsn(e);
26: if update flag =false then
27: update flag ←true;
28: end if
29: end if
30: end for
31: end if
32: if update flag =true then
33: for eache ∈δ(v) do
34: send hupdate(v,ts,td)i one
35: end for
SPF construction
SPF algorithm(continued).
36: send hechoi tobfs π;
37: update flag ←false;
38: else
39: if v =r then
40: height ←h;
41: else if Y 6=φ then
42: sendhechoi to bfs π;
43: end if
44: end if
received by a node in a round. Upon receiving a set ofhupdatei orhechoimessages (U 6=φ orY 6=φ) a nodev acts as per the following rules.
R1. ifv =r then it resets height to h.
R2. if v ∈Z and td(v) =∞ and for the first time it receives some messages then it sets ts(v) =v, td(v) = 0, and tπ(v) = v.
R3. ifv ∈V \Z and U 6=φ then it computes we+tdn(e) for each hupdate(idn(e), tsn(e), tdn(e))i ∈Uand chooses the minimum one, saywe0+tdn(e0) resulted byhupdate(idn(e0), tsn(e0), tdn(e0))i ∈ U. If td(v) > we0 +tdn(e0) then it updates td(v) = we0 +tdn(e0), ts(v) = tsn(e0), and tπ(v) = idn(e0). Otherwise, td(v), ts(v) and tπ(v) remain un- changed.
R4. iftd(v) is updated then
(a) sends hupdate(v, ts(v), td(v))ion all of its incident edges.
(b) sends hechoi tobfs π(v).
R5. iftd(v) is not updated andY 6=φ then v sends hechoi tobfs π(v).
Termination detection. Termination of an algorithm is a state in which no message is in transit or sent by any node in the network. The root r of the BFS tree detects the termination of the SPF algorithm. Wheneverr finds that the local variable height becomes
−1, it terminates the algorithm. At the beginning of the algorithm,r sets height toh. If r does not receive any message in a round, it sets height to height −1. During the execution
of the algorithm a node v sends an hechoi message to bfs π(v) in any one of the following cases.
1. it updates its local state
2. receives hechoi message from at least one of its child nodes
Above two cases guarantee that anhechoimessage generated at any node in the network eventually reachesr. If r receives some messages, it resetsheight toh. Since h is the height of the BFS tree, it is guaranteed that from the time of any change of local state in a node (which generates an hechoi message), r receives this information (by receiving an hechoi message) after at most h rounds. This ensures that r resets height to h before it becomes
−1 in at most h rounds from the time of any changes occur in the network. In case r does not receive any message for h + 1 consecutive rounds, this ensures that no changes have been occurred at any node in the network in last h+ 1 rounds. In this caseheight becomes
−1 and r terminates the algorithm by setting start flag to false.