-
Notifications
You must be signed in to change notification settings - Fork 22
/
run_wifi_dynamic.py
145 lines (134 loc) · 4.55 KB
/
run_wifi_dynamic.py
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
#####################################
# Author: Matteo Nerini #
# Email: [email protected] #
# Date: June 2020 #
#####################################
# Import
from datetime import datetime
import subprocess
import csv
# Options
num_scenarios = 1 # how many scenarios are simulated
num_seeds = 20 # how many times each scenario is simulated
notes = "6-100-2" # notes to be written in the .csv file
ns3_script = "wifi_dynamic" # ns3 script to be launched
timestamp = datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
filebase = "/testfile_" + timestamp
csv_file_py = "." + filebase + '.csv'
csv_file_ns3 = "./scratch" + filebase + '.csv'
def main():
print "Creating file ", csv_file_py
print "Simulating", num_scenarios, "scenario(s) with", num_seeds, "seed(s) each"
print
arg_list = []
for i in range(num_scenarios):
for j in range(num_seeds):
args = {}
args["simulationTime"] = 15
args["seed"] = j + 1
args["csvFileName"] = csv_file_ns3
args["band"] = "AX_5"
args["phyModel"] = "spectrum"
args["constantMcs"] = 1
args["channelNumberA"] = 42 # Network A
args["channelWidthA"] = 80
args["mcsA"] = 5
args["giA"] = 800
args["txPowerA"] = 20
#args["dataRateA"] = "xMb/s" to be set in the ns3 script
args["channelNumberB"] = 100 # Network B
args["channelWidthB"] = 20
args["mcsB"] = 1
args["giB"] = 1600
args["txPowerB"] = 3
#args["dataRateB"] = "xKb/s" to be set in the ns3 script
args["channelNumberC"] = 159 # Network C
args["channelWidthC"] = 40
args["mcsC"] = 5
args["giC"] = 800
args["txPowerC"] = 20
#args["dataRateC"] = "xMb/s" to be set in the ns3 script
#args["nStaA"] = x to be set in the ns3 script
#args["nStaB"] = x to be set in the ns3 script
#args["nStaC"] = x to be set in the ns3 script
arg_list.append(args)
with open(csv_file_py, 'w') as file:
writer = csv.writer(file)
writer.writerow(["scenarios", num_scenarios])
writer.writerow(["seeds per scenario", num_seeds])
writer.writerow(["notes", ns3ScriptName + ". " + notes])
writer.writerow(["arg_list[0]", arg_list[0]])
writer.writerow(["arg_list[" + str(len(arg_list)-1) + "]", arg_list[len(arg_list)-1]])
for i in range(0, len(arg_list)):
simulate(arg_list[i])
print
def get_arguments(arg):
atribute_names = [
" --simulationTime=",
" --seed=",
" --csvFileName=",
" --band=",
" --phyModel=",
" --constantMcs=",
" --channelNumberA=", # Network A
" --channelWidthA=",
" --mcsA=",
" --giA=",
" --txPowerA=",
#" --dataRateA=",
" --channelNumberB=", # Network B
" --channelWidthB=",
" --mcsB=",
" --giB=",
" --txPowerB=",
#" --dataRateB=",
" --channelNumberC=", # Network C
" --channelWidthC=",
" --mcsC=",
" --giC=",
" --txPowerC=",
#" --dataRateC=",
#" --nStaA=",
#" --nStaB=",
#" --nStaC="
]
atribute_values = [
str(arg["simulationTime"]),
str(arg["seed"]),
str(arg["csvFileName"]),
str(arg["band"]),
str(arg["phyModel"]),
str(arg["constantMcs"]),
str(arg["channelNumberA"]), # Network A
str(arg["channelWidthA"]),
str(arg["mcsA"]),
str(arg["giA"]),
str(arg["txPowerA"]),
#str(arg["dataRateA"]),
str(arg["channelNumberB"]), # Network B
str(arg["channelWidthB"]),
str(arg["mcsB"]),
str(arg["giB"]),
str(arg["txPowerB"]),
#str(arg["dataRateB"]),
str(arg["channelNumberC"]), # Network C
str(arg["channelWidthC"]),
str(arg["mcsC"]),
str(arg["giC"]),
str(arg["txPowerC"]),
#str(arg["dataRateC"]),
#str(arg["nStaA"]),
#str(arg["nStaB"]),
#str(arg["nStaC"])
]
arguments = ""
for s in range(0, len(atribute_names)):
arguments += atribute_names[s]
arguments += atribute_values[s]
return arguments
def simulate(arg):
arguments = get_arguments(arg)
print "Calling the ns3 script '" + ns3_script + ".cc'"
subprocess.call('(cd ..; ./waf --run "' + ns3_script + arguments+ '")', shell=True)
if __name__ == "__main__":
main()