-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
373 lines (315 loc) · 15.8 KB
/
run.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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#!/usr/bin/env python
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
from subprocess import call
from sys import argv
import os
import subprocess
import workerpool
import multiprocessing
import argparse
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#Copyright (c) 2019, Algorithmi Research Centree, University of Minho, Portugal
# * Authors: Ertugrul Dogruluk <[email protected]>, Department of #Informatics
######################################################################
######################################################################
################################################### ###################
parser = argparse.ArgumentParser(description='Simulation runner')
parser.add_argument('scenarios', metavar='scenario', type=str, nargs='*',
help='Scenario to run')
parser.add_argument('-l', '--list', dest="list", action='store_true', default=False,
help='Get list of available scenarios')
parser.add_argument('-s', '--simulate', dest="simulate", action='store_true', default=False,
help='Run simulation and postprocessing (false by default)')
parser.add_argument('-p', '--postprocess', dest="postprocess", action='store_true', default=False,
help='Run postprocessing (false by default, always true if simulate is enabled)')
parser.add_argument('-g', '--no-graph', dest="graph", action='store_false', default=True,
help='Do not build a graph for the scenario (builds a graph by default)')
args = parser.parse_args()
if not args.list and len(args.scenarios)==0:
print "ERROR: at least one scenario need to be specified"
parser.print_help()
exit (1)
if args.list:
print "Available scenarios: "
else:
if args.simulate:
print "Simulating the side-channel attack for following scenario application: " + ",".join (args.scenarios)
if args.graph:
print "When simulation finished, will be building graphs for the following scenarios: " + ",".join (args.scenarios)
######################################################################
######################################################################
######################################################################
class SimulationJob (workerpool.Job):
"Job to simulate things"
def __init__ (self, cmdline):
self.cmdline = cmdline
def run (self):
print (" ".join (self.cmdline))
subprocess.call (self.cmdline)
pool = workerpool.WorkerPool(size = multiprocessing.cpu_count())
class Processor:
def run (self):
if args.list:
print " " + self.name
return
if "all" not in args.scenarios and self.name not in args.scenarios:
return
if args.list:
pass
else:
if args.simulate:
self.simulate ()
pool.join ()
if args.simulate or args.postprocess:
self.postprocess ()
pool.join ()
if args.graph:
self.graph ()
def graph (self):
subprocess.call ("./graphs/%s.R" % self.name, shell=True)
class ConvertTopologies (Processor):
def __init__ (self, name, runs, topology, buildGraph = False):
self.name = name
self.runs = runs
self.topology = topology
self.buildGraph = buildGraph
for run in runs:
try:
os.mkdir ("topology/bw-delay-rand-%d" % run)
except:
pass # ignore the error
def simulate (self):
for topology in self.topology:
for run in self.runs:
cmdline = ["./build/rocketfuel-maps-cch-to-annotaded",
"--topology=topology/rocketfuel_maps_cch/%s.cch" % topology,
"--run=%d" % run,
"--output=topology/bw-delay-rand-%d/%s" % (run, topology),
"--buildGraph=%d" % self.buildGraph,
"--keepLargestComponent=1",
"--connectBackbones=1",
"--clients=3",
]
job = SimulationJob (cmdline)
pool.put (job)
def postprocess (self):
# any postprocessing, if any
pass
def graph (self):
pass
class SideChannelAttack (Processor):
def __init__ (self, name, algorithms, topology, evils, good, runs, folder, producer="gw", defaultRtt="250ms"):
self.name = name
self.algorithms = algorithms
self.topology = topology
self.evils = evils
self.good = good
self.runs = runs
self.folder = folder
self.producer = producer
self.defaultRtt = defaultRtt
def simulate (self):
for algorithm in self.algorithms:
for topology in self.topology:
for evil in self.evils:
for run in self.runs:
cmdline = ["./build/vondn", #here is reading build form for vondn.cpp complied project
#"./waf --run=tesbed --vis",
"--algorithm=%s" % algorithm,
"--run=%d" % run,
"--topology=%s" % topology,
"--badCount=%d" % evil,
"--goodCount=%d" % self.good,
"--folder=%s" % self.folder,
"--producer=%s" % self.producer,
"--defaultRtt=%s" % self.defaultRtt,
]
job = SimulationJob (cmdline)
pool.put (job)
def postprocess (self):
print "Convert data to sqlite and reduce data size"
for algorithm in self.algorithms:
for topology in self.topology:
for evil in self.evils:
for run in self.runs:
name = "results/%s/%s-topo-%s-evil-%d-good-%d-producer-%s-run-%d" % (
self.folder,
algorithm,
topology,
evil,
self.good,
self.producer,
run)
print "Converting %s" % name
bzip = "%s.txt.bz2" % name
sqlite = "%s.db" % name
subprocess.call ("rm -f \"%s\"" % sqlite, shell=True)
#cmd = "bzcat \"%s\" | tail -n +2 | awk -F\"\t\" '{if (NF == 4) {print $1\"|\"$2\"|\"$3\"|\"$4}}' | sqlite3 -cmd \"create table data_tmp (Time int, Node text, Type text, Packets real)\" -cmd \".import /dev/stdin data_tmp\" \"%s\"" % (bzip, sqlite)
cmd = "bzcat \"%s\" | tail -n +2 | awk -F\"\t\" '{if (NF == 9) {print $1\"|\"$2\"|\"$5\"|\"$6\"|\"$9}}' | sqlite3 -cmd \"create table data_tmp (Time int, Node text, Type text, DelayS int, HopCount real)\" -cmd \".import /dev/stdin data_tmp\" \"%s\"" % (bzip, sqlite)
subprocess.call (cmd, shell=True)
#cmd = "sqlite3 -cmd \"create table data as select Time,Node,Type,sum(Packets) as Packets from data_tmp where Type in ('CacheHits', 'CacheMisses') group by Time,Node,Type\" -cmd \"drop table data_tmp\" -cmd \"vacuum\" \"%s\" </dev/null" % sqlite
cmd = "sqlite3 -cmd \"create table data as select Time,Node,Type,DelayS,avg(HopCount) as HopCount from data_tmp where HopCount group by Time,Node,Type,DelayS,HopCount\" -cmd \"drop table data_tmp\" -cmd \"vacuum\" \"%s\" </dev/null" % sqlite
# print cmd
subprocess.call (cmd, shell=True)
def graph (self):
print "graph_rate_verification"
for algorithm in self.algorithms:
for topology in self.topology:
for evil in self.evils:
# print "Scenario [%s], topology [%s], evils [%d], run [%d]" % (prefix, topology, evil, run)
cmdline = ["./graphs/rates.R",
algorithm,
topology,
str(evil),
",".join([str(run) for run in self.runs]),
self.folder,
str(self.good),
self.producer,
]
job = SimulationJob (cmdline)
pool.put (job)
class CachehitRatioAlgorithms (SideChannelAttack):
def __init__ (self, name, scenario):
self.name = name
self.algorithms = scenario.algorithms
self.topology = scenario.topology
self.evils = scenario.evils
self.good = scenario.good
self.runs = scenario.runs
self.folder = scenario.folder
self.producer = scenario.producer
self.defaultRtt = scenario.defaultRtt
def simulate (self):
# Here we just assume that the relevant simulation data is already exists
pass
def postprocess (self):
print "Aggregate data"
for algorithm in self.algorithms:
for topology in self.topology:
for evil in self.evils:
cmdline = ["./graphs/preprocess.R",
algorithm,
topology,
str(evil),
",".join([str(run) for run in self.runs]),
self.folder,
str(self.good),
self.producer,
]
job = SimulationJob (cmdline)
print ">>> "+" ".join (cmdline)+"<<< \n";
pool.put (job)
def graph (self):
print "CachehitRatioAlgorithms"
for topology in self.topology:
cmdline = ["./graphs/cachehitratio-min-max-vs-time.R",
",".join(self.algorithms),
topology,
",".join([str(evil) for evil in self.evils]),
",".join([str(run) for run in self.runs]),
self.folder,
str(self.good),
self.producer
]
job = SimulationJob (cmdline)
pool.put (job)
class AttackersFigures (CachehitRatioAlgorithms):
def simulate (self):
# Here we just assume that the relevant simulation data is already exists
pass
def postprocess (self):
pass
def graph (self):
print "AttackersFigures"
for topology in self.topology:
cmdline = ["./graphs/cachehitratio-vs-number-of-attackers.R",
",".join(self.algorithms),
topology,
",".join([str(evil) for evil in self.evils]),
",".join([str(run) for run in self.runs]),
self.folder,
str(self.good),
self.producer
]
job = SimulationJob (cmdline)
pool.put (job)
try:
conversion = ConvertTopologies (name="convert-topologies",
runs=[1],
topology=["1221.r0",
"1239.r0",
"1755.r0",
"2914.r0",
"3257.r0",
"3356.r0",
"3967.r0",
"4755.r0",
"6461.r0",
"7018.r0",],
buildGraph = True)
# conversion.run ()
smallTree = SideChannelAttack (name="attack-small-tree",
algorithms = ["Lru", "Fifo","Lfu","Probability", "Random", "dad"],
topology = ["small-tree"],
evils = [2],
#evils = [1,2],
good = 0, # number of client nodes minus number of evil nodes
runs = range(1,11),
folder = "attackSmallTree",
producer = "bb",
defaultRtt = "80ms")
smallTree.run ()
tree = SideChannelAttack (name="attack-tree",
algorithms = ["dad"],
topology = ["tree"],
evils = [4],
#evils = range(1,10,2),
good = 0, # number of client nodes minus number of evil nodes
runs = range(1,11),
folder = "attackTree",
producer = "bb",
defaultRtt = "80ms")
tree.run ()
isp = SideChannelAttack (name="attack-isp",
algorithms = ["Lru1", "Lfu", "Fifo"],
topology = ["7018.r0"],
evils = [int(296*0.5)],#50% of consumer candidates.
good = 0, # number of client nodes minus number of evil nodes
runs=[1],
# runs = range(1,11),
folder = "attackISP",
producer = "bb",
defaultRtt = "330ms")
isp.run ()
testbed = SideChannelAttack (name="attack-vondn",
#algorithms = ["Lru1","Lru2","Probability1","Probability2", "dad1","dad2"],
algorithms = ["dad2"],
topology = ["testbed"],
evils = [int(420*0.4)],#40% of consumer candidates.
good = 0, # number of client nodes minus number of evil nodes
runs=[1],
#runs = range(1,11),
folder = "attack_vondn",
producer = "bb",
defaultRtt = "330ms")
testbed.run ()
CachehitRatioAlgorithms (name="ratios-small-tree", scenario=smallTree).run ()
CachehitRatioAlgorithms (name="ratios-tree", scenario=tree).run ()
CachehitRatioAlgorithms (name="ratios-isp", scenario=isp).run ()
CachehitRatioAlgorithms (name="ratios-vondn", scenario=testbed).run ()
AttackersFigures (name="attacker-small-tree", scenario=smallTree).run ()
AttackersFigures (name="attacker-tree", scenario=tree).run ()
AttackersFigures (name="attacker-isp", scenario=isp).run ()
AttackersFigures (name="attacker-vondn", scenario=testbed).run ()
finally:
pool.join ()
pool.shutdown ()