Statistics
| Branch: | Tag: | Revision:

mininet / examples / ripcordtest.py @ 51270ce4

History | View | Annotate | Download (2.07 KB)

1
#!/usr/bin/python
2

    
3
"A FatTree network, using Brandon Heller's ripcord system."
4

    
5
import ripcord
6
from ripcord.topo import FatTreeTopo
7

    
8
from mininet.mininet import init, Controller, Network, Host, nameGen, Cli
9
from mininet.mininet import createLink, flush
10

    
11
class NoxController( Controller ):
12
   def __init__( self, name, kernel=False, **kwargs ):
13
      Controller.__init__( self, name, kernel=kernel,
14
         controller='nox_core', 
15
         cargs='-v --libdir=/usr/local/lib -i ptcp:', 
16
         cdir='/usr/local/bin', **kwargs)
17
   
18
class FatTree( Network ):
19
   "A customized Network that uses ripcord's FatTree."
20
   def __init__( self, depth, **kwargs ):
21
      self.depth = depth
22
      Network.__init__( self, **kwargs )
23
   def makeNet( self, controller ):
24
      ft = FatTreeTopo( self.depth )
25
      graph = ft.g
26
      switches = []
27
      hosts = []
28
      hostnames = nameGen( 'h' )
29
      switchnames = nameGen( 's' )
30
      dpnames = nameGen( 'nl:')
31
      graphToMini = {}
32
      miniToGraph = {}
33
      # Create nodes
34
      for graphNode in graph.nodes():
35
         isLeaf = len( graph.neighbors( graphNode ) ) == 1
36
         if isLeaf:
37
            mininetNode = Host( hostnames.next() )
38
            hosts += [ mininetNode ]
39
         else:
40
            mininetNode = self.Switch( switchnames.next(), dpnames.next() )
41
            switches += [ mininetNode ]
42
         print mininetNode.name, ; flush()
43
         miniToGraph[ mininetNode ] = graphNode
44
         graphToMini[ graphNode ] = mininetNode
45
      print
46
      print "*** Creating links"
47
      for switch in switches:
48
         currentNeighbors = [ switch.connection[ intf ][ 0 ] 
49
            for intf in switch.intfs ]
50
         for neighbor in graph.neighbors( miniToGraph[ switch ] ):
51
            miniNeighbor = graphToMini[ neighbor ]
52
            if miniNeighbor not in currentNeighbors:
53
               print '.', ; flush()
54
               createLink( switch, graphToMini[ neighbor ] )
55
      print
56
      return switches, hosts
57
      
58
if __name__ == '__main__':
59
   init()   
60
   network = FatTree( depth=4, kernel=True, Controller=NoxController)
61
   network.run( Cli )