-
Notifications
You must be signed in to change notification settings - Fork 27
/
run.py
executable file
·333 lines (283 loc) · 13.5 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
#!/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
######################################################################
######################################################################
######################################################################
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 following scenarios: " + ",".join (args.scenarios)
if args.graph:
print "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, topologies, buildGraph = False):
self.name = name
self.runs = runs
self.topologies = topologies
self.buildGraph = buildGraph
for run in runs:
try:
os.mkdir ("topologies/bw-delay-rand-%d" % run)
except:
pass # ignore the error
def simulate (self):
for topology in self.topologies:
for run in self.runs:
cmdline = ["./build/rocketfuel-maps-cch-to-annotaded",
"--topology=topologies/rocketfuel_maps_cch/%s.cch" % topology,
"--run=%d" % run,
"--output=topologies/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 InterestDdosAttack (Processor):
def __init__ (self, name, algorithms, topologies, evils, good, runs, folder, producer="gw", defaultRtt="250ms"):
self.name = name
self.algorithms = algorithms
self.topologies = topologies
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.topologies:
for evil in self.evils:
for run in self.runs:
cmdline = ["./build/interest-ddos-attack-and-mitigation-scenario",
"--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.topologies:
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 == 9) {print $1\"|\"$2\"|\"$3\"|\"$5\"|\"$6\"|\"$7}}' | sqlite3 -cmd \"create table data_tmp (Time int, Node text, FaceId int, Type text, Packets real, Kilobytes 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, sum(Kilobytes) as Kilobytes from data_tmp where Type in ('InData', 'OutInterests') group by Time,Node,Type\" -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.topologies:
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 SatisfactionMinManFigures (InterestDdosAttack):
def __init__ (self, name, scenario):
self.name = name
self.algorithms = scenario.algorithms
self.topologies = scenario.topologies
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.topologies:
for evil in self.evils:
cmdline = ["./graphs/preprocess-satisfaction.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 "SatisfactionMinManFigures"
for topology in self.topologies:
cmdline = ["./graphs/satisfaction-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 SatisfactionNumberOfAttackersFigures (SatisfactionMinManFigures):
def simulate (self):
# Here we just assume that the relevant simulation data is already exists
pass
def postprocess (self):
pass
def graph (self):
print "SatisfactionNumberOfAttackersFigures"
for topology in self.topologies:
cmdline = ["./graphs/satisfaction-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],
topologies=["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 = InterestDdosAttack (name="attack-small-tree",
algorithms = ["fairness", "satisfaction-accept", "satisfaction-pushback"],
topologies = ["small-tree"],
evils = [1,2],
good = 0, # number of client nodes minus number of evil nodes
runs = range(1,11),
folder = "attackSmallTree",
producer = "gw",
defaultRtt = "80ms")
smallTree.run ()
tree = InterestDdosAttack (name="attack-tree",
algorithms = ["fairness", "satisfaction-accept", "satisfaction-pushback"],
topologies = ["tree"],
evils = range(1,10,2),
good = 0, # number of client nodes minus number of evil nodes
runs = range(1,11),
folder = "attackTree",
producer = "gw",
defaultRtt = "80ms")
tree.run ()
isp = InterestDdosAttack (name="attack-isp",
algorithms = ["fairness", "satisfaction-accept", "satisfaction-pushback"],
topologies = ["7018.r0"],
evils = [140],
good = 0, # number of client nodes minus number of evil nodes
runs = range(1,11),
folder = "attackISP",
producer = "gw",
defaultRtt = "330ms")
isp.run ()
SatisfactionMinManFigures (name="figureX", scenario=smallTree).run ()
SatisfactionMinManFigures (name="figure6", scenario=tree).run ()
SatisfactionMinManFigures (name="figure9", scenario=isp).run ()
SatisfactionNumberOfAttackersFigures (name="figureXX", scenario=smallTree).run ()
SatisfactionNumberOfAttackersFigures (name="figure7", scenario=tree).run ()
# SatisfactionNumberOfAttackersFigures (name="figureYY", scenario=isp).run ()
finally:
pool.join ()
pool.shutdown ()