How to do it...

In this recipe, we will run a simple network emulation with two switches - one OVSKernelSwitch and the other, Indigo Virtual Switch (IVSSwitch). First let's install IVSSwitch (https://github.com/floodlight/ivs), which is Floodlight's own implementation of a virtual switch. We start with installing the dependencies:

$ sudo apt-get install libnl-3-dev libnl-genl-3-dev libnl-route-3-dev pkg-config python-tz libpcap-dev libcap2-dev

Clone the IVS repository:

$ git clone --recurse-submodules https://github.com/floodlight/ivs.git

Compile it:

$ cd ivs
$ make
$ sudo make install

Make sure to execute Floodlight before running this recipe. Now, IVS is ready to run:

$ sudo ivs -c 127.0.0.1

Now you may run the listing 10.4, which constructs the network with the switches, hosts, and links:

#!/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.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
' ) 
    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=IVSSwitch) 
 
    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) 
    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) 
 
    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]) 
 
    info( '*** Post configure switches and hosts
') 
 
    CLI(net) 
    net.stop() 
 
if __name__ == '__main__': 
    setLogLevel( 'info' ) 
    myNetwork() 

The virtual switches communicate with the controller. The network is managed by Floodlight controller centrally. Here you may see the output of the execution of this recipe:

$ sudo python 10_4_sdn_floodlight.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) *** 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) *** Post configure switches and hosts
*** Starting CLI:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.71.28