-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtopology-evaluator.py
executable file
·89 lines (71 loc) · 2.65 KB
/
topology-evaluator.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import os
import sys
import argparse
import networkx as nx
import interruptingcow as ic
from topology import *
from traffic import *
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--csv', action='store_true',
help='full CSV output', default=False)
parser.add_argument('-a', '--allcycles', action='store_true',
help='use all cycles generator', default=False)
parser.add_argument('-H', '--hosts', action='store_true',
help='create hosts in the topology', default=False)
parser.add_argument('-P', '--pathbased', action='store_true',
help='use path-based loops', default=False)
parser.add_argument('-d', '--directed', action='store_true',
help='use directed based cycles', default=False)
parser.add_argument('-v', '--verbose', action='store_true',
help='verbose', default=False)
parser.add_argument('-s', '--seed', type=int, default=None,
help='seed for PRNG to have consistend results')
parser.add_argument('-p', '--parser', type=str, default='zoo',
choices=['zoo', 'rocket', 'stanford', 'fattree'],
help='topology file / arguments parser')
parser.add_argument('-l', '--loops', type=int, default=1000,
help='number of iterations')
parser.add_argument('-t', '--timeout', type=int, default=60,
help='timeout in seconds for processing one file')
parser.add_argument('files', metavar='FILEorARG', type=str, nargs='+',
help='topology file / argument')
args = parser.parse_args()
if len(args.files) == 0:
parser.print_help()
sys.exit(1)
print "File", "AVG-B", "AVG-L", "AVG-X", "MIN-B", "MIN-L", "MIN-X", "MAX-B", "MAX-L", "MAX-X", "Nodes", "Diameter", "Basis"
if args.verbose:
print
while len(args.files) > 0:
topo = None
# Test if file exists, otherwise skip it
topo_file = args.files.pop(0)
if args.parser != 'fattree' and not os.path.exists(topo_file):
print "No file", topo_file
continue
try:
# Setup a timeout for the analysis operation
with ic.timeout(args.timeout, exception=RuntimeError):
if args.parser == 'stanford':
topo_file = (topo_file, args.files.pop(0))
# Load topology from file
topo = Topology.load(topo_file, parser=args.parser, seed=args.seed, create_hosts=args.hosts,
verbose=args.verbose, allcycles=args.allcycles, directed=args.directed)
if args.parser == 'stanford':
topo_file = topo_file[-1]
# Analyze loops
topo.analyze_loops(args.loops, prefix=topo_file, csv=args.csv, pathbased=args.pathbased)
if args.verbose:
print
except nx.exception.NetworkXError as err:
if args.verbose:
print err
print "Failed to load", topo_file
continue
except RuntimeError as err:
if args.verbose:
print err
print "Timeouted", topo_file
continue