-
Notifications
You must be signed in to change notification settings - Fork 2
/
scale_send_to_neighbor.m
41 lines (31 loc) · 1.57 KB
/
scale_send_to_neighbor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function [Nodes_list] = scale_send_to_neighbor(Nodes_list, event, neighbor_id)
% Send an event to a neighbor node
if isempty(neighbor_id)
return;
end
%disp(sprintf('EVENT with message id# %d FORWARDED TO Neighbor ID %d', neighbor_id, event.id));
if ~isempty(Nodes_list(neighbor_id))
if Nodes_list(neighbor_id).status == 1
% record total received events
Nodes_list(neighbor_id).received_events = Nodes_list(neighbor_id).received_events + 1;
% Drop the message if the node is its originator
if event.originator == neighbor_id
return
end
% add the event into the neighbor's buffer
event.source = neighbor_id;
action = [];
action.type = 'receiving';
action.packet_size = event.size;
Nodes_list(neighbor_id).power = scale_power_consumption(Nodes_list(neighbor_id).power, action);
disp(sprintf('NEIGHBOR Node ID# %d sending forwarded event with message id# %d', neighbor_id, event.id));
% record total replayed events
Nodes_list(neighbor_id).relayed_events = Nodes_list(neighbor_id).relayed_events + 1;
Nodes_list = scale_send_event(Nodes_list, event);
else
disp(sprintf('NEIGHBOR Node ID# %d BUFFERING forwarded event with message id# %d', neighbor_id, event.id));
Nodes_list(neighbor_id).buffer = [Nodes_list(neighbor_id).buffer, event];
end
end
return;
end