-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_simulation_2.py
More file actions
231 lines (191 loc) · 10 KB
/
run_simulation_2.py
File metadata and controls
231 lines (191 loc) · 10 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
from create_constants import *
from constants import *
from misc_sim_funcs import *
import os
def run_simulation(DataSet, Day_Or_NumMules, Round, Protocol, Band, t, ts, v, Gen_LE, Max_Nodes, pkl_fold_num, perfect_knowledge,src_dst,speed, num_mes, num_chan, num_puser, smart_setting, num_fwd, msg_round, puser_round, msg_mean, ttl, max_mem):
dir = "DataMules/" #Starting Directory
num_messages = num_mes
debug_message = -1
debug_mode = -1
metric_interval = 30
is_queuing_active = True
restrict_band_access = True
restrict_channel_access = True
priority_queue_active = True
if num_fwd == 0:
broadcast = True
geo_routing = False
else:
broadcast = False
geo_routing = True
num_nodes_to_fwd = num_fwd
generate_new_primary_users = False
generate_messages = True if pkl_fold_num == 1 else False
fwd_strat = "broadcast" if broadcast == True else "geo_" + str(num_nodes_to_fwd)
dataset = DataSet #UMass or Lexington
day_or_numMules = Day_Or_NumMules#date (UMass) or number of mules (Lexington)
round = Round #Round number (Always 1 for UMass)
if Protocol == "Epidemic_Smart":
protocol = Protocol + "_" + smart_setting #Protocol in set of [XChant, Epidemic, SprayNWait, HotPotato]
else:
protocol = Protocol
if priority_queue_active == True:
buffer = "PQ"
else:
buffer = "FIFO"
band = Band #bands to use in set of [ALL, TV, LTE, ISM, CBRS]
generate_link_exists = Gen_LE
T = t #Length of Simulation
V = v #Number of dataMules
NoOfSources = src_dst[0]
NoOfDataCenters = src_dst[1]
start_time = ts
max_nodes = Max_Nodes #All nodes include src and des
if dataset == "UMass":
dataMule_path = dir + dataset + "/" + day_or_numMules + "/" + str(round) + "/"
link_exists_path = dataMule_path + "Link_Exists/" + "LE_" + str(start_time) + "_" + str(T) + "/"
metrics_path = link_exists_path + protocol + "/" + buffer + "/" + fwd_strat +"/mules_" + str(V) + "/channels_" + str(num_chan) + "/P_users_" + str(num_puser) + "/"
path_to_save_LLC = link_exists_path + protocol + "/" + buffer + "/mules_" + str(V) + "/"
if pkl_fold_num == 1:
path_to_day1_LLC = link_exists_path + protocol + "/" + buffer + "/mules_" + str(V) + "/"
else:
path_to_day1_LLC = dataMule_path + "Link_Exists/LE_" + str(start_time - T) + "_" + str(T) + "/" + protocol + "/" + buffer + "/mules_" + str(V) + "/"
elif dataset == "Lexington":
dataMule_path = dir + dataset + "/" + day_or_numMules + "/" + str(round) + "/"
if pkl_fold_num == 1:
link_exists_path = dataMule_path + "Link_Exists/" + "LE_1_" + str(T) + "/"
metrics_path = link_exists_path + protocol + "/" + buffer + "/" + fwd_strat + "/mules_" + str(
V) + "/channels_" + str(num_chan) + "/P_users_" + str(num_puser) + "/"
path_to_day1_LLC = link_exists_path
else:
link_exists_path = dataMule_path + "Link_Exists/" + "LE_2_" + str(T) + "/"
metrics_path = link_exists_path + protocol + "/" + buffer + "/" + fwd_strat + "/mules_" + str(
V) + "/channels_" + str(num_chan) + "/P_users_" + str(num_puser) + "/"
path_to_day1_LLC = dataMule_path + "Link_Exists/LE_2_" + str(
T) + "/" + protocol + "/" + buffer + "/mules_" + str(V) + "/"
path_to_save_LLC = link_exists_path
else:
print("Invalid Dataset")
return -1
if band == "ALL":
S = get_suitable_spectrum_list(smart_setting)
elif band == "TV":
S = [0, 0, 0, 0]
elif band == "ISM":
S = [1, 1, 1, 1]
elif band == "LTE":
S = [2, 2, 2, 2]
elif band == "CBRS":
S = [3, 3, 3, 3]
else:
S = []
print("Invalid Band Type")
create_constants(T, V, S, start_time, dataset, max_nodes, dataMule_path, metrics_path, link_exists_path,
debug_message, \
protocol, NoOfDataCenters, NoOfSources, generate_link_exists, generate_messages, num_messages,
pkl_fold_num, \
path_to_day1_LLC, perfect_knowledge, speed, is_queuing_active, restrict_band_access,
restrict_channel_access, \
generate_new_primary_users, num_chan, num_puser, path_to_save_LLC, smart_setting,
priority_queue_active, \
broadcast, geo_routing, num_nodes_to_fwd, msg_round, puser_round, debug_mode, metric_interval,
msg_mean, ttl, max_mem)
if generate_new_primary_users == True:
os.system("python3 generate_primary_users.py")
if generate_link_exists == True and max_nodes == V + NoOfSources + NoOfDataCenters:
if dataset == "UMass":
os.system("python3 create_pickles.py")
os.system("python3 computeLINKEXISTS_UMass.py")
elif dataset == "Lexington":
os.system("python3 readLexingtonData_Fixed.py")
os.system("python3 create_pickles_Lex.py")
os.system("python3 computeLINKEXISTS_Lex.py")
if protocol == "XChant":
if not os.path.exists(path_to_metrics):
os.makedirs(path_to_metrics)
if generate_LE == True:
os.system("python3 STB_main_path.py")
#
# if generate_messages == True and pkl_fold_num == 1 and V + NoOfDataCenters + NoOfSources == Max_Nodes:
# os.system("python3 generateMessage_new.py")
if generate_LE == False:
os.system("python3 main.py")
os.system("python3 metrics.py")
def run_various_sims(num_mules, num_channels, num_Pusers, msg_round, msg_mean, ttl, mem_size):
for band in ["ALL", "TV", "CBRS", "LTE", "ISM"]:
# print("Band:", band, "MSG round:", msg_round, "MSG mean:", msg_mean)
if band == "ALL":
for nodes_tofwd in [1, 0]:
print("K:", nodes_tofwd)
print("Optimistic")
run_simulation(data, day, 3, proto, band, len_T, start_time, num_mules, generate_LE, max_v,
pkl_ID, perfect_knowledge, src_dst, speed, num_messages, num_channels, num_Pusers,
"optimistic", nodes_tofwd, msg_round, puser_round, msg_mean, ttl, mem_size)
print()
print("Pessimistic")
run_simulation(data, day, 3, proto, band, len_T, start_time, num_mules, generate_LE, max_v,
pkl_ID, perfect_knowledge, src_dst, speed, num_messages, num_channels, num_Pusers,
"pessimistic", nodes_tofwd, msg_round, puser_round, msg_mean, ttl, mem_size)
else:
for nodes_tofwd in [0]:
print("Band:", band, "K:", nodes_tofwd)
run_simulation(data, day, 3, proto, band, len_T, start_time, num_mules, generate_LE, max_v,
pkl_ID, perfect_knowledge, src_dst, speed, num_messages, num_channels, num_Pusers,
band, nodes_tofwd, msg_round, puser_round, msg_mean, ttl, mem_size)
# (DataSet, Day_Or_NumMules, Round, Protocol, Band, t, ts, v, Gen_LE, Max_Nodes, pkl_fold_num, perfect_knowledge,
# src_dst_arr, speed_arr, num messages, num channels, num primary users, smart setting (optional))
data = "Lexington"
day = "50"
len_T = 360 #length of simulation
start_time = 0 #start time (to find Link Exists)
bands = ["ALL", "LTE", "TV", "CBRS", "ISM"] #which bands to use
num_mules = 96 #number of data mules to use
generate_LE = False #generate Link Exists
pkl_ID = 1 #pkl folder ID if Link Exists is being generated
perfect_knowledge = False #Xchant only
src_dst = [6, 6] #num src and dst
max_v = num_mules + src_dst[0] + src_dst[1] #max number of datamules + src + dst
speed = [135, 400] #Lex data only
proto = "Epidemic_Smart" #[Epidemic_Smart, XChant, SprayNWait (in progress)]
num_messages = 206
num_Pusers = 150
num_channels = 6
nodes_tofwd = 0
msg_round = 0
puser_round = 0
msg_mean = 15
ttl = 180
mem_size = 150
if generate_LE == False:
for msg_round in range(9, 0, -1):
#print("Round : ", msg_round)
# for msg_mean in [5, 10, 20, 25]:
# run_various_sims()
for mem_size in [25, 50, 100, 150, 300, -1]:
print("Round: ", msg_round, "msg size: ", mem_size)
run_various_sims(num_mules, num_channels, num_Pusers, msg_round, msg_mean, ttl, mem_size)
mem_size = 150
for ttl in [15, 30, 90, 180, 240, 360]:
print("Round ", msg_round, "TTL", ttl)
run_various_sims(num_mules, num_channels, num_Pusers, msg_round, msg_mean, ttl, mem_size)
#varying num of mules
#print("Testing num mules")
ttl = 180
for num_mules in [8, 24, 32, 64, 96, 128]:
print("Round", msg_round, "No. of Mules", num_mules)
run_various_sims(num_mules, num_channels, num_Pusers, msg_round, msg_mean, ttl, mem_size)
num_mules = 96
# varying num of channels
for num_channels in [1, 2, 4, 6, 8, 10]:
print("Round", msg_round, "No. of Channels", num_channels)
run_various_sims(num_mules, num_channels, num_Pusers, msg_round, msg_mean, ttl, mem_size)
num_channels = 6
# varying num primary users
for num_Pusers in [0, 50, 100, 150, 300, 450]:
print("Round", msg_round, "No. of PUs", num_Pusers)
run_various_sims(num_mules, num_channels, num_Pusers, msg_round, msg_mean, ttl, mem_size)
#Generate Link exists
else:
run_simulation(data, day, 3, proto, "ALL", len_T, start_time, num_mules, generate_LE, max_v,
pkl_ID, perfect_knowledge, src_dst, speed, num_messages, num_channels, num_Pusers,
"optimistic", nodes_tofwd, msg_round, puser_round, msg_mean, ttl, mem_size)