Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from mininet.net import Mininet
- from mininet.link import TCLink
- 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, link=TCLink, build=False)
- info( '*** Adding controller\n' )
- c1 = net.addController(name='c1', controller=RemoteController, ip='10.12.99.3', protocol='tcp', port=6633)
- info( '*** Add switches\n')
- for i in range(0, 10) :
- net.addSwitch('s' + str(i+1), cls=OVSKernelSwitch, protocols='OpenFlow13');
- info( '*** Add hosts\n')
- net.addHost('h1', cls=Host, ip='10.0.1.1', defaultRoute=None);
- net.addHost('h2', cls=Host, ip='10.0.1.2', defaultRoute=None);
- net.addHost('h3', cls=Host, ip='10.0.1.3', defaultRoute=None);
- net.addHost('h4', cls=Host, ip='10.0.1.4', defaultRoute=None);
- net.addHost('h5', cls=Host, ip='10.0.2.1', defaultRoute=None);
- net.addHost('h6', cls=Host, ip='10.0.2.2', defaultRoute=None);
- net.addHost('h7', cls=Host, ip='10.0.2.3', defaultRoute=None);
- net.addHost('h8', cls=Host, ip='10.0.2.4', defaultRoute=None);
- info( '*** Add links\n')
- # 3-LAYER TOPOLOGY
- linkopts = dict(bw=10, delay='5ms', jitter='2ms');
- # < H > <-- external hosts
- # G <-- Pseudo gateway switch
- # |
- # L-B <-- load balancer
- # / / \ \
- # / / \ \
- # O O O O <-- out switches
- # <full-mesh>
- # E E E E <-- exterior-facing switches
- # | | | |
- # H H H H <-- internal hosts
- # External hosts & the pseudo gateway
- net.addLink(net.switches[0], net.hosts[0], **linkopts);
- net.addLink(net.switches[0], net.hosts[1], **linkopts);
- net.addLink(net.switches[0], net.hosts[2], **linkopts);
- net.addLink(net.switches[0], net.hosts[3], **linkopts);
- # Pseudo gateway and the hash load balancer
- net.addLink(net.switches[1], net.switches[0], **linkopts);
- # The load balancer & the out switches
- net.addLink(net.switches[1], net.switches[2], **linkopts);
- net.addLink(net.switches[1], net.switches[3], **linkopts);
- net.addLink(net.switches[1], net.switches[4], **linkopts);
- net.addLink(net.switches[1], net.switches[5], **linkopts);
- # The out switches & the exterior-facing switches
- net.addLink(net.switches[2], net.switches[6], **linkopts);
- net.addLink(net.switches[2], net.switches[7], **linkopts);
- net.addLink(net.switches[2], net.switches[8], **linkopts);
- net.addLink(net.switches[2], net.switches[9], **linkopts);
- net.addLink(net.switches[3], net.switches[6], **linkopts);
- net.addLink(net.switches[3], net.switches[7], **linkopts);
- net.addLink(net.switches[3], net.switches[8], **linkopts);
- net.addLink(net.switches[3], net.switches[9], **linkopts);
- net.addLink(net.switches[4], net.switches[6], **linkopts);
- net.addLink(net.switches[4], net.switches[7], **linkopts);
- net.addLink(net.switches[4], net.switches[8], **linkopts);
- net.addLink(net.switches[4], net.switches[9], **linkopts);
- net.addLink(net.switches[5], net.switches[6], **linkopts);
- net.addLink(net.switches[5], net.switches[7], **linkopts);
- net.addLink(net.switches[5], net.switches[8], **linkopts);
- net.addLink(net.switches[5], net.switches[9], **linkopts);
- # The hosts
- net.addLink(net.switches[6], net.hosts[4], **linkopts);
- net.addLink(net.switches[7], net.hosts[5], **linkopts);
- net.addLink(net.switches[8], net.hosts[6], **linkopts);
- net.addLink(net.switches[9], net.hosts[7], **linkopts);
- info( '*** Starting network\n')
- net.build()
- info( '*** Starting controllers\n')
- for controller in net.controllers:
- controller.start()
- info( '*** Starting switches\n')
- for switch in net.switches:
- switch.start([c1]);
- net.hosts[0].cmd("ping h2");
- CLI(net)
- net.stop()
- if __name__ == '__main__':
- setLogLevel( 'info' )
- myNetwork()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement