tom | bd8e9c8 | 2014-10-07 11:46:15 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
Brian O'Connor | 580163d | 2014-10-30 21:03:43 -0700 | [diff] [blame] | 2 | |
| 3 | from mininet.topo import Topo |
tom | bd8e9c8 | 2014-10-07 11:46:15 -0700 | [diff] [blame] | 4 | from mininet.cli import CLI |
| 5 | from mininet.net import Mininet |
| 6 | from mininet.node import RemoteController, OVSKernelSwitch |
Brian O'Connor | 580163d | 2014-10-30 21:03:43 -0700 | [diff] [blame] | 7 | from mininet.log import setLogLevel |
tom | bd8e9c8 | 2014-10-07 11:46:15 -0700 | [diff] [blame] | 8 | |
tom | bd8e9c8 | 2014-10-07 11:46:15 -0700 | [diff] [blame] | 9 | |
Brian O'Connor | 580163d | 2014-10-30 21:03:43 -0700 | [diff] [blame] | 10 | class TowerTopo( Topo ): |
| 11 | """Create a tower topology""" |
tom | bd8e9c8 | 2014-10-07 11:46:15 -0700 | [diff] [blame] | 12 | |
Brian O'Connor | 580163d | 2014-10-30 21:03:43 -0700 | [diff] [blame] | 13 | def build( self, k=4, h=6 ): |
| 14 | spines = [] |
| 15 | leaves = [] |
| 16 | hosts = [] |
tom | bd8e9c8 | 2014-10-07 11:46:15 -0700 | [diff] [blame] | 17 | |
| 18 | # Create the two spine switches |
Brian O'Connor | 580163d | 2014-10-30 21:03:43 -0700 | [diff] [blame] | 19 | spines.append(self.addSwitch('s1')) |
| 20 | spines.append(self.addSwitch('s2')) |
tom | bd8e9c8 | 2014-10-07 11:46:15 -0700 | [diff] [blame] | 21 | |
| 22 | # Create two links between the spine switches |
Brian O'Connor | 580163d | 2014-10-30 21:03:43 -0700 | [diff] [blame] | 23 | 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]) |
tom | bd8e9c8 | 2014-10-07 11:46:15 -0700 | [diff] [blame] | 26 | |
| 27 | # Now create the leaf switches, their hosts and connect them together |
| 28 | i = 1 |
| 29 | c = 0 |
| 30 | while i <= k: |
Brian O'Connor | 580163d | 2014-10-30 21:03:43 -0700 | [diff] [blame] | 31 | leaves.append(self.addSwitch('s1%d' % i)) |
| 32 | for spine in spines: |
| 33 | self.addLink(leaves[i-1], spine) |
tom | bd8e9c8 | 2014-10-07 11:46:15 -0700 | [diff] [blame] | 34 | |
| 35 | j = 1 |
| 36 | while j <= h: |
Brian O'Connor | 580163d | 2014-10-30 21:03:43 -0700 | [diff] [blame] | 37 | hosts.append(self.addHost('h%d%d' % (i, j))) |
| 38 | self.addLink(hosts[c], leaves[i-1]) |
tom | bd8e9c8 | 2014-10-07 11:46:15 -0700 | [diff] [blame] | 39 | j+=1 |
| 40 | c+=1 |
| 41 | |
| 42 | i+=1 |
| 43 | |
Brian O'Connor | 580163d | 2014-10-30 21:03:43 -0700 | [diff] [blame] | 44 | topos = { 'tower': TowerTopo } |
tom | bd8e9c8 | 2014-10-07 11:46:15 -0700 | [diff] [blame] | 45 | |
Brian O'Connor | 580163d | 2014-10-30 21:03:43 -0700 | [diff] [blame] | 46 | def run(): |
| 47 | topo = TowerTopo() |
| 48 | net = Mininet( topo=topo, controller=RemoteController, autoSetMacs=True ) |
| 49 | net.start() |
| 50 | CLI( net ) |
| 51 | net.stop() |
tom | bd8e9c8 | 2014-10-07 11:46:15 -0700 | [diff] [blame] | 52 | |
Brian O'Connor | 580163d | 2014-10-30 21:03:43 -0700 | [diff] [blame] | 53 | if __name__ == '__main__': |
| 54 | setLogLevel( 'info' ) |
| 55 | run() |