#!/usr/bin/python

from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.node import CPULimitedHost, Host, Node
from mininet.node import OVSKernelSwitch, UserSwitch
from mininet.node import IVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink, Intf
from subprocess import call

def myNetwork():

    net = Mininet( topo=None,
                   build=False,
                   ipBase='10.0.0.0/8')

    info( '*** Adding controller\n' )
    c0=net.addController(name='c0',
                      controller=Controller,
                      protocol='tcp',
                      port=6633)

    info( '*** Add switches\n')
    s6 = net.addSwitch('s6', cls=OVSKernelSwitch)
    s11 = net.addSwitch('s11', cls=OVSKernelSwitch)
    s24 = net.addSwitch('s24', cls=OVSKernelSwitch)
    s30 = net.addSwitch('s30', cls=OVSKernelSwitch)
    s26 = net.addSwitch('s26', cls=OVSKernelSwitch)
    s21 = net.addSwitch('s21', cls=OVSKernelSwitch)
    s15 = net.addSwitch('s15', cls=OVSKernelSwitch)
    s17 = net.addSwitch('s17', cls=OVSKernelSwitch)
    s28 = net.addSwitch('s28', cls=OVSKernelSwitch)
    s12 = net.addSwitch('s12', cls=OVSKernelSwitch)
    s10 = net.addSwitch('s10', cls=OVSKernelSwitch)
    s29 = net.addSwitch('s29', cls=OVSKernelSwitch)
    s27 = net.addSwitch('s27', cls=OVSKernelSwitch)
    s18 = net.addSwitch('s18', cls=OVSKernelSwitch)
    s20 = net.addSwitch('s20', cls=OVSKernelSwitch)
    s14 = net.addSwitch('s14', cls=OVSKernelSwitch)
    s23 = net.addSwitch('s23', cls=OVSKernelSwitch)
    s8 = net.addSwitch('s8', cls=OVSKernelSwitch)
    s3 = net.addSwitch('s3', cls=OVSKernelSwitch)
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
    s5 = net.addSwitch('s5', cls=OVSKernelSwitch)
    s19 = net.addSwitch('s19', cls=OVSKernelSwitch)
    s25 = net.addSwitch('s25', cls=OVSKernelSwitch)
    s13 = net.addSwitch('s13', cls=OVSKernelSwitch)
    s7 = net.addSwitch('s7', cls=OVSKernelSwitch)
    s16 = net.addSwitch('s16', cls=OVSKernelSwitch)
    s31 = net.addSwitch('s31', cls=OVSKernelSwitch)
    s22 = net.addSwitch('s22', cls=OVSKernelSwitch)
    s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
    s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
    s9 = net.addSwitch('s9', cls=OVSKernelSwitch)

    info( '*** Add hosts\n')
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
    h9 = net.addHost('h9', cls=Host, ip='10.0.0.9', defaultRoute=None)
    h28 = net.addHost('h28', cls=Host, ip='10.0.0.28', defaultRoute=None)
    h17 = net.addHost('h17', cls=Host, ip='10.0.0.17', defaultRoute=None)
    h31 = net.addHost('h31', cls=Host, ip='10.0.0.31', defaultRoute=None)
    h7 = net.addHost('h7', cls=Host, ip='10.0.0.7', defaultRoute=None)
    h23 = net.addHost('h23', cls=Host, ip='10.0.0.23', defaultRoute=None)
    h12 = net.addHost('h12', cls=Host, ip='10.0.0.12', defaultRoute=None)
    h25 = net.addHost('h25', cls=Host, ip='10.0.0.25', defaultRoute=None)
    h29 = net.addHost('h29', cls=Host, ip='10.0.0.29', defaultRoute=None)
    h13 = net.addHost('h13', cls=Host, ip='10.0.0.13', defaultRoute=None)
    h16 = net.addHost('h16', cls=Host, ip='10.0.0.16', defaultRoute=None)
    h20 = net.addHost('h20', cls=Host, ip='10.0.0.20', defaultRoute=None)
    h27 = net.addHost('h27', cls=Host, ip='10.0.0.27', defaultRoute=None)
    h15 = net.addHost('h15', cls=Host, ip='10.0.0.15', defaultRoute=None)
    h10 = net.addHost('h10', cls=Host, ip='10.0.0.10', defaultRoute=None)
    h18 = net.addHost('h18', cls=Host, ip='10.0.0.18', defaultRoute=None)
    h8 = net.addHost('h8', cls=Host, ip='10.0.0.8', defaultRoute=None)
    h24 = net.addHost('h24', cls=Host, ip='10.0.0.24', defaultRoute=None)
    h5 = net.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None)
    h30 = net.addHost('h30', cls=Host, ip='10.0.0.30', defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
    h14 = net.addHost('h14', cls=Host, ip='10.0.0.14', defaultRoute=None)
    h6 = net.addHost('h6', cls=Host, ip='10.0.0.6', defaultRoute=None)
    h19 = net.addHost('h19', cls=Host, ip='10.0.0.19', defaultRoute=None)
    h33 = net.addHost('h33', cls=Host, ip='10.0.0.33', defaultRoute=None)
    h22 = net.addHost('h22', cls=Host, ip='10.0.0.22', defaultRoute=None)
    h32 = net.addHost('h32', cls=Host, ip='10.0.0.32', defaultRoute=None)
    h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)
    h26 = net.addHost('h26', cls=Host, ip='10.0.0.26', defaultRoute=None)
    h11 = net.addHost('h11', cls=Host, ip='10.0.0.11', defaultRoute=None)
    h21 = net.addHost('h21', cls=Host, ip='10.0.0.21', defaultRoute=None)

    info( '*** Add links\n')
    net.addLink(h1, s1)
    net.addLink(s2, s1)
    net.addLink(s1, s3)
    net.addLink(s2, s4)
    net.addLink(s2, s5)
    net.addLink(s3, s6)
    net.addLink(s3, s7)
    net.addLink(s4, s8)
    net.addLink(s4, s9)
    net.addLink(s5, s10)
    net.addLink(s5, s11)
    net.addLink(s8, s16)
    net.addLink(s8, s17)
    net.addLink(s9, s18)
    net.addLink(s9, s19)
    net.addLink(s10, s20)
    net.addLink(s10, s21)
    net.addLink(s11, s22)
    net.addLink(s11, s23)
    net.addLink(s6, s12)
    net.addLink(s6, s13)
    net.addLink(s7, s14)
    net.addLink(s7, s15)
    net.addLink(s12, s24)
    net.addLink(s12, s25)
    net.addLink(s13, s26)
    net.addLink(s13, s27)
    net.addLink(s14, s28)
    net.addLink(s14, s29)
    net.addLink(s15, s30)
    net.addLink(s15, s31)
    net.addLink(s16, h2)
    net.addLink(s16, h3)
    net.addLink(s17, h4)
    net.addLink(s17, h5)
    net.addLink(s18, h6)
    net.addLink(s18, h7)
    net.addLink(s19, h8)
    net.addLink(s19, h9)
    net.addLink(s20, h10)
    net.addLink(s20, h11)
    net.addLink(s21, h12)
    net.addLink(s21, h13)
    net.addLink(s22, h14)
    net.addLink(s22, h15)
    net.addLink(s23, h16)
    net.addLink(s23, h17)
    net.addLink(s24, h18)
    net.addLink(s24, h19)
    net.addLink(s25, h20)
    net.addLink(s25, h21)
    net.addLink(s26, h22)
    net.addLink(s26, h23)
    net.addLink(s27, h24)
    net.addLink(s27, h25)
    net.addLink(s28, h26)
    net.addLink(s28, h27)
    net.addLink(s29, h28)
    net.addLink(s29, h29)
    net.addLink(s30, h30)
    net.addLink(s30, h31)
    net.addLink(s31, h32)
    net.addLink(s31, h33)

    info( '*** Starting network\n')
    net.build()
    info( '*** Starting controllers\n')
    for controller in net.controllers:
        controller.start()

    info( '*** Starting switches\n')
    net.get('s6').start([c0])
    net.get('s11').start([c0])
    net.get('s24').start([c0])
    net.get('s30').start([c0])
    net.get('s26').start([c0])
    net.get('s21').start([c0])
    net.get('s15').start([c0])
    net.get('s17').start([c0])
    net.get('s28').start([c0])
    net.get('s12').start([c0])
    net.get('s10').start([c0])
    net.get('s29').start([c0])
    net.get('s27').start([c0])
    net.get('s18').start([c0])
    net.get('s20').start([c0])
    net.get('s14').start([c0])
    net.get('s23').start([c0])
    net.get('s8').start([c0])
    net.get('s3').start([c0])
    net.get('s2').start([c0])
    net.get('s5').start([c0])
    net.get('s19').start([c0])
    net.get('s25').start([c0])
    net.get('s13').start([c0])
    net.get('s7').start([c0])
    net.get('s16').start([c0])
    net.get('s31').start([c0])
    net.get('s22').start([c0])
    net.get('s4').start([c0])
    net.get('s1').start([c0])
    net.get('s9').start([c0])

    info( '*** Post configure switches and hosts\n')

    CLI(net)
    net.stop()

if __name__ == '__main__':
    setLogLevel( 'info' )
    myNetwork()

