Revision 65c35b65 mininet/topo.py

View differences:

mininet/topo.py
11 11
setup for testing, and can even be emulated with the Mininet package.
12 12
'''
13 13

  
14
# BL: we may have to fix compatibility here.
15
# networkx is also a fairly heavyweight dependency
16
# from networkx.classes.graph import Graph
17

  
18
from networkx import Graph
19 14
from mininet.util import irange, natural, naturalSeq
20 15

  
16
class Graph(object):
17
    "Utility class to track nodes and edges "
18

  
19
    def __init__(self):
20
        self.data = {}
21

  
22
    def add_node(self,node):
23
        if node not in self.data.keys():
24
            self.data[node] = []
25

  
26
    def add_edge(self,src,dest):
27
        self.add_node(src)
28
        self.add_node(dest)
29
        self.data[src].append(dest)
30

  
31
    def nodes(self):
32
        return self.data.keys()
33

  
34
    def edges(self):
35
        for src in self.data.keys():
36
            for dest in self.data[src]:
37
                yield (src,dest)
38

  
21 39
class Topo(object):
22 40
    "Data center network representation for structured multi-trees."
23 41

  

Also available in: Unified diff