blob: bc5c6899b025207b01b45abeae89d3fc35b5f3d7 [file] [log] [blame]
Brian O'Connor75dc8892015-07-30 19:07:55 -07001#!/usr/bin/env python
2
3from mininet.topo import Topo
4
5class FractalTopo( Topo ):
6 def build( self, n=3, h=2 ):
7
8 clusters = []
9 for i in range( 1, n+1 ):
10 clusterSws = []
11 # create switches in cluster
12 for j in range( 1, n+1 ):
13 id = i * 1000 + j
14 sw = self.addSwitch('s%d' % id, dpid=str(id).zfill(16))
15 [ self.addLink(s, sw) for s in clusterSws ]
16 clusterSws.append(sw)
17 clusters.append(clusterSws)
18
19 for i in range( 1, n+1 ):
20 # create the edge switch
21 id = i * 10000
22 sw = self.addSwitch('s%d' % id, dpid=str(id).zfill(16))
23 self.addLink(clusters[i-1].pop(0), sw)
24 for j in range( 1, h+1 ):
25 id = i * 1000 + j
26 host = self.addHost( 'h%d' % id )
27 self.addLink( host, sw )
28
29 for i in range( 1, n+1 ):
30 # connect the clusters
31 if i == n:
32 id = n * 1000000 + 10000
33 sw = self.addSwitch('s%d' % id, dpid=str(id).zfill(16))
34 self.addLink(clusters[i-1].pop(0), sw)
35 self.addLink(clusters[0].pop(0), sw)
36
37 else:
38 id = (i+1) * 1000000 + i * 10000
39 sw = self.addSwitch('s%d' % id, dpid=str(id).zfill(16))
40 self.addLink(clusters[i-1].pop(0), sw)
41 self.addLink(clusters[i].pop(0), sw)
42
43
44topos = { 'fractal': FractalTopo }
45
46def run():
47 topo = FractalTopo()
48 net = Mininet( topo=topo, controller=RemoteController, autoSetMacs=True )
49 net.start()
50 CLI( net )
51 net.stop()
52
53if __name__ == '__main__':
54 setLogLevel( 'info' )
55 run()
56