-
Notifications
You must be signed in to change notification settings - Fork 2
/
SCALE_mesh_network_simulator.m
157 lines (115 loc) · 5.03 KB
/
SCALE_mesh_network_simulator.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
% Simulation for SCALE Wireless Sensor Box
clear;
close all;
scale_parameter;
global numNodes;
global initial_power;
global maxx;
global maxy;
global maxEvents;
global eventsPeriod;
global APs_list;
global sentEvents;
global forwardedEvents;
global totalReceived;
global timeInterval;
global powerWeight;
global neighborWeight;
global distanceWeight;
timeInterval= 1; %record power of each node every time interval
powerWeight = 0.02;
neighborWeight = 0.06;
distanceWeight = 0.05;
prob_sleeping = 0.6;
sentStatistics = [];
APs_list = [];
sentEvents = 0;
forwardedEvents = 0;
totalReceived = 0;
Nodes_list = [];
Events_list = [];
Nodes_coordinates = zeros(numNodes, 2);
% Initialize sensor direct connection to a nearest Access Point AP
% Initialize sensor status
issid = 0;
for k=1:numNodes
Nodes_list(k).id = k;
Nodes_list(k).x_coordinate = rand()*maxx; % 250 feets
Nodes_list(k).y_coordinate = rand()*maxy; % 250 feets
Nodes_list(k).generated_events = 0;
Nodes_list(k).sent_events = 0;
Nodes_list(k).relayed_events = 0;
Nodes_list(k).received_events = 0;
Nodes_list(k).duplicated_events = 0;
Nodes_list(k).recieved_events_queue = [];
% For FaNet
Nodes_list(k).parents = [];
Nodes_list(k).children = [];
Nodes_list(k).level = -9999;
Nodes_list(k).offers = [];
Nodes_list(k).offerings = [];
Nodes_list(k).primary_tree_id = 0;
Nodes_list(k).primary_parent_id = 0;
Nodes_list(k).buffer = [];
Nodes_list(k).neighbors = [];
Nodes_list(k).status = 0; % get_status(node_id, neighors), 0 = sleep, 1 = active
Nodes_list(k).on_duty = 0; % 0 is not fowarding neighbors' traffic, 1 is
Nodes_list(k).power = initial_power;
Nodes_list(k).active_time_left = 0; % initial value
Nodes_list(k).sleeping_time_left = 0; % 0 initial value
Nodes_list(k).beacon_broadcasted = 0; % 0 initial value
Nodes_list(k).AP_Connections = [];
AP_Connections = [];
random_AP = mod(round(rand(1)*100), k);
if(random_AP == 0 || random_AP == 1)
issid = issid + 1;
% Add new Access Point into APs_list
AP = [];
AP.issid = issid;
AP.connect_node_id = k; %direct connection node id
AP.x_coordinate = Nodes_list(k).x_coordinate + 5;
AP.y_coordinate = Nodes_list(k).y_coordinate + 5;
AP.arrived_events = 0;
APs_list = [APs_list; AP];
Connection.through_neighbor = k; % need a function for this
Connection.num_hops = 1; % need a function for this
Connection.AP_issid = AP.issid;
AP_Connections = [AP_Connections; Connection];
Nodes_list(k).AP_Connections = AP_Connections;
clear Connection;
clear AP_Connections;
clear AP;
end
end
% Clone Nodes_list to Nodes_list_Fanet for later use
Nodes_list_FaNet = Nodes_list;
% Display initial network topology
%disp(sprintf('\n Network Initial Tepology\n'));
%scale_display_nodes_info(Nodes_list);
% Initial broadcast join messages
Nodes_list = scale_initial_broadcast_join(Nodes_list);
scale_draw_network_topology(Nodes_list, APs_list, maxx, maxy); % draw network with neighbor connections
%Generate initial events which could occur within the SCALE network
% within 1 hour
Events_list = scale_generate_initial_events(Events_list, numNodes, maxEvents, eventsPeriod);
% Now, it is time to run network topology and generate events to
% be sent to its access points, every while loop will count as
% 1 second of sensors' clock.
max_run_time = 45;
% ################### Begin of all active schema ####################
% First sleeping schema: every node stay awake
[Nodes_list, ActPower, events_graph_height] = scale_run_all_active(Nodes_list, Events_list, max_run_time);
broadcast_AP_total_received_events = scale_get_events_arrived_at_APs(APs_list);
Nodes_list_FaNet = scale_FaNet_build_topology(Nodes_list_FaNet);
scale_draw_FaNet_topology(Nodes_list_FaNet, APs_list, maxx, maxy);
% Run the FaNet data dissemination schema here
[Nodes_list_FaNet, FaNetPower, events_graph_height] = scale_run_FaNet(Nodes_list_FaNet, Events_list, max_run_time, events_graph_height);
FaNet_AP_total_received_events = scale_get_events_arrived_at_APs(APs_list);
% Display simulation data
scale_events_comparison_graph(Nodes_list, Nodes_list_FaNet, 'duplicated', 'Multi Hops Broadcast and FatNet Disseminated Duplicated Messages Comparison');
scale_total_events_comparison_graph(Nodes_list, Nodes_list_FaNet, ...
broadcast_AP_total_received_events, FaNet_AP_total_received_events);
% ############### Begin of random sleeping schema ##################
scale_total_power_graph(numel(Nodes_list),'Multi Hops Broadcast', 'FaNet Dissemination', ActPower, FaNetPower);
scale_draw_event_spreading(Nodes_list, maxx, maxy, 'Multi Hops Dissemination');
scale_draw_event_spreading(Nodes_list_FaNet, maxx, maxy, 'FaNet Dissemination');