Algorithm 1 Clustering and routing algorithm in . |
-
1:
Node i receives from the sink;
-
2:
if
then
-
3:
;
-
4:
else
-
5:
;
-
6:
end if
-
7:
Sets up random backoff timer (Equation (5));
-
8:
repeat
-
9:
if Receives AC message from CH j
then
-
10:
Records CH j to JOIN list;
-
11:
end
if
-
12:
if Receives AR message from CH j AND
then
-
13:
if
then
-
14:
Records CH j to SERV list;
-
15:
else
if
AND CH j is in SERV list then
-
16:
Deletes CH j from SERV list;
-
17:
end
if
-
18:
else
if Receives AR message from CH j AND
then
-
19:
if
AND
then
-
20:
Records CH j to RELAY list;
-
21:
end
if
-
22:
end
if
-
23:
until
terminates
-
24:
if
then
-
25:
;
-
26:
Forwards the data to the sink directly;
-
27:
Broadcasts AC and AR message;
-
28:
else
if SERV is not empty or JOIN is empty then
-
29:
;
-
30:
if RELAY is empty then
-
31:
Forwards the data to the sink directly;
-
32:
else
-
33:
Selects the relay with minimum from RELAY list (Equation (7));
-
34:
end
if
-
35:
Broadcasts AC and AR message;
-
36:
else
-
37:
;
-
38:
Selects its CH with minimum from JOIN list (Equation (8));
-
39:
end
if
|