-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtopogen.py
62 lines (51 loc) · 2.34 KB
/
topogen.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
#!/usr/bin/env python
"""
Read GraphML topology files from topozoo and generate SyNET inputs
for the topology and the requirements.
"""
import glob
import os
import networkx as nx
from synet.graph_util import read_topology_zoo
from synet.graph_util import topozoo_to_datalog
from synet.graph_util import gen_ospf_reqs
from synet.graph_util import gen_bgp_reqs
from synet.graph_util import gen_static_reqs
__author__ = "Ahmed El-Hassany"
__email__ = "[email protected]"
def main():
for file in glob.glob('examples/topozoo_original/*.graphml'):
basename = os.path.basename(file)
toponame = basename.split('.')[0]
graph = read_topology_zoo(file)
num_nodes = len(graph.nodes())
num_edges = len(graph.edges())
if num_nodes <= 70:
if not nx.is_strongly_connected(graph):
# Skip not connected graphs
continue
print toponame, num_nodes, num_edges
for traffic_classes in [1, 5, 10, 15, 20]:
if traffic_classes >= len(graph.nodes()):
continue
spec = topozoo_to_datalog(graph)
spec_ospf, reqs_ospf = gen_ospf_reqs(graph, traffic_classes)
with open('examples/topozoo/%s-ospf-%d.logic' % (toponame, traffic_classes), 'w') as f:
f.write(spec)
f.write(spec_ospf)
with open('examples/topozoo/%s-ospf-%d-req.logic' % (toponame, traffic_classes), 'w') as f:
f.write(reqs_ospf)
spec_bgp, reqs_bgp = gen_bgp_reqs(graph, traffic_classes)
with open('examples/topozoo/%s-bgp-%d.logic' % (toponame, traffic_classes), 'w') as f:
f.write(spec)
f.write(spec_bgp)
with open('examples/topozoo/%s-bgp-%d-req.logic' % (toponame, traffic_classes), 'w') as f:
f.write(reqs_bgp)
spec_static, reqs_static = gen_static_reqs(graph, traffic_classes)
with open('examples/topozoo/%s-static-%d.logic' % (toponame, traffic_classes), 'w') as f:
f.write(spec)
f.write(spec_static)
with open('examples/topozoo/%s-static-%d-req.logic' % (toponame, traffic_classes), 'w') as f:
f.write(reqs_static)
if __name__ == '__main__':
main()