Algorithm 1: REBORN |
|
▷ Variables:
|
|
1: ; |
{Time spent in activity state} |
2: ; |
{Time spent in energy-saving state} |
3: ; |
{Time spent in the discovery state} |
4: ; |
{Remaining time for the node to exit the active state} |
5: state := discovery; |
{Current node state} |
6: := false; |
{Routing message received} |
7: ; |
{Distance to the sink} |
8: ; |
{Identification of the cell} |
9: ; |
{Identifier of incoming data messages} |
▷ Input:
|
|
10: Sink node sends routing message |
|
Action:
|
|
11: |
{Sink initiates a controlled flooding} |
▷ Input:
|
|
12: Regular nodes receive routing message (msg) |
|
Action:
|
|
13: if !routeConf then
|
{Was message received?} |
14: routeConf := true; |
{Confirmed message} |
15: sinkDist := getDist(msg.sinkPos); |
{Compute distance of sink} |
16: ; |
{Forward the message} |
17: gridID := getGrid(nodePos); |
{Compute the grid ID} |
18: end if
|
|
▷ Input:
|
|
19: Regular nodes enter in discovery state |
|
Action
|
|
20: discTimer := Constant
|
{Update discTimer value} |
21: aTimer := remTimerAct := getTimeToSend(); |
{Compute the send time} |
22: timer.trigger() |
{Time to node change the state} |
23: sendDiscMessage(nodeID, gridID, remTimeAct, state, energyBat); |
|
▷ Input:
|
|
24: Regular nodes receive discovery message (msg) |
|
Action
|
|
25: if state == discovery and msg.state == active then
|
{High priority?} |
26: eTimer := msg.remTimeAct; state := sleep; |
|
27: else if state == msg.state then {Are nodes in same state ?} |
|
28: if energyBat < msg.energyBat then
|
{Is my energy bigger ?} |
29: eTimer := msg.remTimeAct; state := sleep; |
|
30: end if
|
|
31: end if
|
|
▷ Input:
|
|
32: Timer fire |
|
Action
|
|
33: state := active |
{The elected node changes to active state} |
▷ Input:
|
|
34: Elected nodes enter in active state |
|
Action
|
|
35: discTimer := aTimer/6; |
{Update discTimer value} |
36: Timer.trigger(); |
{Time to node change state} |
37: Timer.trigger(); |
{Time to node send the data message} |
38: Timer.trigger(); |
{Time for node to send the discovery message} |
▷ Input:
|
|
39: Timer fire |
|
Action:
|
|
40: remTimeAct := timer.remainingTime(); |
{Update remTimeAct with rest time of aTimer} |
41: sendDiscMessage(nodeID, gridID, remTimeAct, state, energyBat); |
|
▷ Input:
|
|
42: Timer fire |
|
Action:
|
|
43: sendDataMessage(data, msg, sinkDist); |
|
▷ Input:
|
|
44: Nodes in active state receive data message (msg) |
|
Action:
|
|
45: if sinkDist < msgand !checkID() then
|
|
46: sendDataMessage(msg.date, msg..msg, distSink); |
|
47: msg.add(msg..); |
{Storage msg} |
48: end if
|
|
▷ Input:
|
|
49: Nodes not elected enter in the sleep state |
|
Action:
|
|
50: timer.trigger(); |
{Time to node change state} |
▷ Input:
|
|
51: Timer or Timer fire |
|
Action:
|
|
52: state := discovery; |
{Restart the process} |