We first need to start the ONOS controller, and then initiate the Python program consisting of Mininet emulation of the network.
Listing 10.3 gives a Software-Defined Network with ONOS controller:
#!/usr/bin/env python # Python Network Programming Cookbook, Second Edition -- Chapter - 10 # This program is optimized for Python 2.7.12. # It may run on any other version with/without modifications. 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.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 ' ) c0=net.addController(name='c0', controller=RemoteController, ip='127.0.0.1', protocol='tcp', port=6653) info( '*** Add switches ') s2 = net.addSwitch('s2', cls=OVSKernelSwitch) s1 = net.addSwitch('s1', cls=OVSKernelSwitch) s5 = net.addSwitch('s5', cls=OVSKernelSwitch, failMode='standalone') info( '*** Add hosts ') h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None) h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None) h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None) h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None) info( '*** Add links ') s1s2 = {'bw':400,'loss':0} net.addLink(s1, s2, cls=TCLink , **s1s2) s2h1 = {'bw':1000,'loss':10,'max_queue_size':10,'speedup':40} net.addLink(s2, h1, cls=TCLink , **s2h1) s2h2 = {'bw':120,'loss':0} net.addLink(s2, h2, cls=TCLink , **s2h2) s2h3 = {'bw':400,'loss':20} net.addLink(s2, h3, cls=TCLink , **s2h3) s1s5 = {'bw':200,'delay':'12','loss':10} net.addLink(s1, s5, cls=TCLink , **s1s5) s5h4 = {'bw':100,'loss':50} net.addLink(s5, h4, cls=TCLink , **s5h4) info( '*** Starting network ') net.build() info( '*** Starting controllers ') for controller in net.controllers: controller.start() info( '*** Starting switches ') net.get('s2').start([c0]) net.get('s1').start([c0]) net.get('s5').start([]) info( '*** Post configure switches and hosts ') CLI(net) net.stop() if __name__ == '__main__': setLogLevel( 'info' ) myNetwork()
Start the ONOS controller first, and then execute this recipe as follows:
$ sudo python 10_3_sdn_onos.py *** Adding controller *** Add switches *** Add hosts *** Add links (400.00Mbit 0.00000% loss) (400.00Mbit 0.00000% loss) (1000.00Mbit 10.00000% loss) (1000.00Mbit 10.00000% loss) (120.00Mbit 0.00000% loss) (120.00Mbit 0.00000% loss) (400.00Mbit 20.00000% loss) (400.00Mbit 20.00000% loss) (200.00Mbit 12 delay 10.00000% loss) (200.00Mbit 12 delay 10.00000% loss) (100.00Mbit 50.00000% loss) (100.00Mbit 50.00000% loss) *** Starting network *** Configuring hosts *** Starting controllers *** Starting switches (400.00Mbit 0.00000% loss) (1000.00Mbit 10.00000% loss) (120.00Mbit 0.00000% loss) (400.00Mbit 20.00000% loss) (400.00Mbit 0.00000% loss) (200.00Mbit 12 delay 10.00000% loss) (200.00Mbit 12 delay 10.00000% loss) (100.00Mbit 50.00000% loss) *** Post configure switches and hosts *** Starting CLI: