forked from fg-inet/panoptisim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
panoptisim.py
executable file
·268 lines (241 loc) · 12.1 KB
/
panoptisim.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
#!/usr/bin/env python2.7
#
# Dan Levin <[email protected]>
import argparse
import gzip
import logging
import logging.config
import os
import pickle
import random
import subprocess
import time
from os import getpid
from socket import gethostname
from sim.simulator import Simulator
from sim.topology import EnterpriseTopology
def get_parser():
"""Returns the parser for Panoptisim"""
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(help='sub-command help')
parser_1 = subparsers.add_parser('new',
help="start a new simulation run using \
cmdline specified paramters")
parser_2 = subparsers.add_parser('resume',
help="resume a partially-run simulation \
using paramters obtained from a json \
results file")
################################################################################
# Following paramters must be determined by json when using file-recovery
################################################################################
for myparser in [parser_1, parser_2]:
# Only require the following args if we're running "new"
isrequired = (myparser == parser_1)
myparser.add_argument("--seedmapping",
help="random seed for endpoint mapping",
required=isrequired,
type=int)
myparser.add_argument("--seednextswitch",
help="random seed for RAND nextswitch",
required=isrequired,
type=int)
myparser.add_argument("--tmsf",
help="TM scaling factor",
#choices=['1.0', 'max-50', '1-50', '0.5-50'],
# Ony 1.0 and max-50 are sensible options, see
# EnterpriseTopology.__calculate_traffic_scaling_factor
choices=['1.0', 'max-50'],
required=isrequired,
type=str)
myparser.add_argument("--epsf",
help="end-point scaling factor",
required=isrequired,
type=int)
myparser.add_argument("--epp",
help="entries-per-port: number of 'policy' flow-table \
entries to consume per communicating src-dst pair",
required=isrequired,
type=int)
myparser.add_argument("--tm",
help="lbnl traffic matrix year",
required=isrequired,
choices=['2004', '2005'],
type=str)
myparser.add_argument("--pattern",
# Now deprecated and not used anymore
help="which communication pattern to consider, \
deprecated and not used anymore",
#required=isrequired,
choices=['all-to-all', 'only-tm'],
default='only-tm',
type=str)
myparser.add_argument("--switchstrategy",
help="heuristic for which switch to consider next",
required=isrequired,
choices=['VOL', 'DEG', 'RAND', 'ROUTERS', 'VOLI', 'EVOLF' , 'IVOLT', 'TVOL'],
type=str)
myparser.add_argument("--portstrategy",
help="in what order to try to accommodate sdn ports",
required=isrequired,
choices=['default', 'sdn-switches-first'],
type=str)
myparser.add_argument("--maxvlans",
help="max vlans limit",
required=isrequired,
type=int)
myparser.add_argument("--maxft",
help="max flow table limit",
required=isrequired,
type=int)
myparser.add_argument("--activefrontiersize",
help="limit the max size of the active frontier",
default=None,
type=int)
################################################################################
isrequired = (myparser == parser_2)
myparser.add_argument("--resumefromfile",
help="resume a simulation run using the paramters \
obtained from a json results file",
required=isrequired,
type=str)
################################################################################
# Always Required
################################################################################
myparser.add_argument("--toupgrade",
help="how many switches to upgrade",
required=True,
type=int)
myparser.add_argument("--numprioports",
help="number of ports that must be SDN",
default=0,
type=int)
myparser.add_argument("--exclude", "-e",
help="exclude switches from upgrade",
nargs='+',
default=['config1515', 'config775', 'config842'],
type=str)
myparser.add_argument("--upgraded",
help="consider the switches in this list as \
already upgraded",
nargs='+',
default=[],
type=str)
myparser.add_argument("--onlyupgrade",
help="only upgrade the following switches in the \
given order",
nargs='+',
default=[],
type=str)
myparser.add_argument("--linkutilthresh",
help="max link util before rejecting an SDN port's \
traffic",
default=1,
type=float)
myparser.add_argument("--magicswitches",
help="just upgrade n of the magic switches in \
random (seednextswitch) order",
default=0,
type=int)
################################################################################
# Following paramters should be taken from json during file recovery, but may be
# overridden from json when using file-recovery.
################################################################################
parser.add_argument("--stop",
help="stop after all ports are made SDN",
action='store_true',
default=False)
parser.add_argument("--outputdir",
help="Directory where json output is written",
type=str,
default=os.getcwd())
# parser.add_argument("--gitid",
# help="git commit id of the running experiment",
# default=subprocess.check_output(
# ["git log | head -1"],shell=True
# ).strip().replace("commit ",""),
# type=str)
parser.add_argument("--starttime",
help="the time at which the simulation begins execution",
default=str(time.time()),
type=str)
parser.add_argument("--hostname",
help="the hostname on which the simulation is run: \
This only documents the hostname in the filename.",
default=gethostname(),
type=str)
parser.add_argument("--pid",
help="the simulatoin process id",
default=str(getpid()),
type=str)
################################################################################
# Following paramters are optional and may be specified regardless of subcommand
################################################################################
parser.add_argument("--pickletopo",
help="use a pickeled topo to speed up reading topology",
default=False,
action='store_true')
parser.add_argument("--verbosity", "-v",
help="set the logging level",
choices=['DEBUG', 'INFO', 'WARN', 'ERROR'],
default='INFO',
type=str)
return parser
def main():
FORMAT="%(asctime)s %(process)d %(levelname)s %(message)s"
logging.basicConfig(format=FORMAT)
logger = logging.getLogger('panoptisim')
parser = get_parser()
args = parser.parse_args()
logger.setLevel(args.verbosity)
for module in ['sim.topology', 'sim.simulator']:
lg = logging.getLogger(module)
lg.setLevel(logger.getEffectiveLevel())
logger.info("Starting on host [{}]".format(args.hostname))
logger.info("Starting with args: {args}".format(
args="\n\t".join(sorted([str(k)+": "+str(v) for k,v in
args.__dict__.iteritems()]))
)
)
logger.debug("Excluding Devices: %s" % str(args.exclude))
random.seed(args.seedmapping)
logger.debug("Mapping Randomseed is: %s" % str(args.seedmapping))
EPscalingFactor = int(args.epsf)
topo = None
if args.pickletopo:
topo = EnterpriseTopology.load_from_pickle(args.tm, args.tmsf,
args.seedmapping,
EPscalingFactor)
else:
logger.info("Creating New EnterpriseTopology")
topo = EnterpriseTopology(tm=args.tm, tm_factor_name=args.tmsf,
EPscalingFactor=EPscalingFactor)
random.seed(args.seednextswitch)
logger.debug("Nextswitch Randomseed: %s" % str(args.seednextswitch))
# Magic switches are switches that can accommmodate all 1296 SDN ports with
# traffic under epp=2 maxvlan=1024 maxft=100000
if args.magicswitches > 0:
magic_switches = ['config451', 'config1520', 'config333', 'config424',
'config426', 'config427', 'config428', 'config429', 'config431',
'config433', 'config434', 'config435', 'config436', 'config437',
'config439', 'config441', 'config442', 'config444', 'config445',
'config446', 'config447', 'config449', 'config450', 'config452',
'config453', 'config457', 'config458', 'config459', 'config460',
'config461', 'config462', 'config463', 'config465', 'config468',
'config469', 'config471', 'config474', 'config567', 'config714',
'config775', 'config823', 'config842', 'config962', 'config1515',
'config455', 'config473', 'config470', 'config418', 'config467',
'config472', 'config713']
random.shuffle(magic_switches)
args.onlyupgrade = magic_switches[:args.magicswitches]
logger.info("Starting with magic switches: {args}".format(
args="\n\t".join(sorted([str(k)+": "+str(v) for k,v in
args.__dict__.iteritems()]))
)
)
print ("HASAN " + str(len(topo.graph.nodes())))
simulation = Simulator(topo, args)
simulation.run()
#topo.draw()
logger.info("Finished Simulation")
if __name__ == '__main__':
main()