Revision a395aaa8 BGPpysim/topos/genFABREXfig1.py

View differences:

BGPpysim/topos/genFABREXfig1.py
1 1
#!/usr/bin/python
2 2

  
3
import code
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
#
16
# Copyright (C) 2019  Mattia Milani <mattia.milani@studenti.unitn.it> & Lorenzo Ghiro <lorenzo.ghiro@unitn.it>
17

  
18

  
4 19
import networkx as nx
5 20
from collections import defaultdict
6 21

  
7 22

  
8
def edge(e1, e2, etype, mrai1=30, mrai2=30, customer=None):
23
def edge(e1, e2, etype, mrai1=30.0, mrai2=30.0, customer=None):
24
    """
25
    Function to set the edge information
26
    :param e1: first part of the edge
27
    :param e2: second node of the edge
28
    :param etype: Type of the edge
29
    :param mrai1: MRAI that controls the connection e1->e2
30
    :param mrai2: MRAI that controls the connection e2->e1
31
    :param customer: Parameter that identifies which node is the customer in the relation
32
    :return: the edge with all the parameters configured
33
    """
9 34
    if etype == 'peer':
10
        assert customer == None
35
        assert customer is None
11 36
    elif etype == 'transit':
12 37
        assert customer == e1 or customer == e2
13 38
    redge = (e1, e2, {'type': etype, 'termination1': e1, 'termination2': e2,
......
18 43
G = nx.DiGraph()
19 44

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

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

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

  
46
myedges = [edge('X4', 'Y3', etype, customer='Y3', mrai1=8.0, mrai2=8.0),
47
           edge('X4', 'X3', etype, customer='X3', mrai1=8.0, mrai2=8.0),
48
           edge('Y3', 'X3', etype, customer='X3', mrai1=8.0, mrai2=8.0),
49
           edge('X3', 'Y2', etype, customer='Y2', mrai1=4.0, mrai2=4.0),
50
           edge('X3', 'X2', etype, customer='X2', mrai1=4.0, mrai2=4.0),
51
           edge('Y2', 'X2', etype, customer='X2', mrai1=4.0, mrai2=4.0),
52
           edge('X2', 'Y1', etype, customer='Y1', mrai1=2.0, mrai2=2.0),
53
           edge('X2', 'X1', etype, customer='X1', mrai1=2.0, mrai2=2.0),
54
           edge('Y1', 'X1', etype, customer='X1', mrai1=2.0, mrai2=2.0)]
34 55

  
35 56
G.add_edges_from(myedges)
36 57

  
......
47 68
nx.set_node_attributes(G, attrs)
48 69

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

Also available in: Unified diff