blob: b75bfe407e62f590a94b1abdf0ad8c96f366f7f2 [file] [log] [blame]
tombd8e9c82014-10-07 11:46:15 -07001#!/usr/bin/env python
Brian O'Connor580163d2014-10-30 21:03:43 -07002
3from mininet.topo import Topo
tombd8e9c82014-10-07 11:46:15 -07004from mininet.cli import CLI
5from mininet.net import Mininet
6from mininet.node import RemoteController, OVSKernelSwitch
Brian O'Connor580163d2014-10-30 21:03:43 -07007from mininet.log import setLogLevel
tombd8e9c82014-10-07 11:46:15 -07008
tombd8e9c82014-10-07 11:46:15 -07009
Brian O'Connor580163d2014-10-30 21:03:43 -070010class TowerTopo( Topo ):
11 """Create a tower topology"""
tombd8e9c82014-10-07 11:46:15 -070012
Brian O'Connor580163d2014-10-30 21:03:43 -070013 def build( self, k=4, h=6 ):
14 spines = []
15 leaves = []
16 hosts = []
tombd8e9c82014-10-07 11:46:15 -070017
18 # Create the two spine switches
Brian O'Connor580163d2014-10-30 21:03:43 -070019 spines.append(self.addSwitch('s1'))
20 spines.append(self.addSwitch('s2'))
tombd8e9c82014-10-07 11:46:15 -070021
22 # Create two links between the spine switches
Brian O'Connor580163d2014-10-30 21:03:43 -070023 self.addLink(spines[0], spines[1])
24 #TODO add second link between spines when multi-link topos are supported
25 #self.addLink(spines[0], spines[1])
tombd8e9c82014-10-07 11:46:15 -070026
27 # Now create the leaf switches, their hosts and connect them together
28 i = 1
29 c = 0
30 while i <= k:
Brian O'Connor580163d2014-10-30 21:03:43 -070031 leaves.append(self.addSwitch('s1%d' % i))
32 for spine in spines:
33 self.addLink(leaves[i-1], spine)
tombd8e9c82014-10-07 11:46:15 -070034
35 j = 1
36 while j <= h:
Brian O'Connor580163d2014-10-30 21:03:43 -070037 hosts.append(self.addHost('h%d%d' % (i, j)))
38 self.addLink(hosts[c], leaves[i-1])
tombd8e9c82014-10-07 11:46:15 -070039 j+=1
40 c+=1
41
42 i+=1
43
Brian O'Connor580163d2014-10-30 21:03:43 -070044topos = { 'tower': TowerTopo }
tombd8e9c82014-10-07 11:46:15 -070045
Brian O'Connor580163d2014-10-30 21:03:43 -070046def run():
47 topo = TowerTopo()
48 net = Mininet( topo=topo, controller=RemoteController, autoSetMacs=True )
49 net.start()
50 CLI( net )
51 net.stop()
tombd8e9c82014-10-07 11:46:15 -070052
Brian O'Connor580163d2014-10-30 21:03:43 -070053if __name__ == '__main__':
54 setLogLevel( 'info' )
55 run()