Statistics
| Branch: | Revision:

iof-tools / BGPpysim / topos / genFABREXfig1.py @ de0e8e06

History | View | Annotate | Download (1.57 KB)

1
#!/usr/bin/python
2

    
3
import code
4
import networkx as nx
5
from collections import defaultdict
6

    
7

    
8
def edge(e1, e2, etype, mrai1=30, mrai2=30, customer=None):
9
    if etype == 'peer':
10
        assert customer == None
11
    elif etype == 'transit':
12
        assert customer == e1 or customer == e2
13
    redge = (e1, e2, {'type': etype, 'termination1': e1, 'termination2': e2,
14
                      'mrai1': mrai1, 'mrai2': mrai2, 'customer': customer})
15
    return redge
16

    
17

    
18
G = nx.DiGraph()
19

    
20
etype = 'transit'
21
myedges = []
22
myedges.append(edge('X4', 'Y3', etype, customer='X4', mrai1=7.5, mrai2=7.5))
23
myedges.append(edge('X4', 'X3', etype, customer='X4', mrai1=7.5, mrai2=7.5))
24
myedges.append(edge('Y3', 'X3', etype, customer='Y3', mrai1=7.5, mrai2=7.5))
25

    
26
myedges.append(edge('X3', 'Y2', etype, customer='X3', mrai1=15.0, mrai2=15.0))
27
myedges.append(edge('X3', 'X2', etype, customer='X3', mrai1=15.0, mrai2=15.0))
28
myedges.append(edge('Y2', 'X2', etype, customer='Y2', mrai1=15.0, mrai2=15.0))
29

    
30
myedges.append(edge('X2', 'Y1', etype, customer='X2', mrai1=30.0, mrai2=30.0))
31
myedges.append(edge('X2', 'X1', etype, customer='X2', mrai1=30.0, mrai2=30.0))
32
myedges.append(edge('Y1', 'X1', etype, customer='Y1', mrai1=30.0, mrai2=30.0))
33

    
34

    
35
G.add_edges_from(myedges)
36

    
37
attrs = defaultdict(dict)
38
# Source export dest d
39
ntype = 'C'
40
for n in G.nodes():
41
    destinations = []
42
    if n == 'X1':
43
        destinations = ['100.0.0.0/24']
44
    attrs[n]['destinations'] = ','.join(destinations)
45
    attrs[n]['type'] = ntype
46

    
47
nx.set_node_attributes(G, attrs)
48

    
49
nx.write_graphml(G, 'test.graphml')
50
#code.interact(local=dict(globals(), **locals()))