How to do it...

The following line adds a controller as RemoteController to the network emulated:

    c1 = net.addController(name='c1', 
controller=RemoteController, ip='127.0.0.1')

If a RemoteController does not exist in the given IP (since the port is not mentioned, default OpenFlow controller port 6653 is assumed), it will start Mininet's controller. Thus, make sure to start OpenDaylight (or any other SDN controller of your choice) first.

Listing 10.2 gives an execution of a Software-Defined Network with a controller, a few nodes (switches and hosts), and links as follows:

#!/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 OVSSwitch, Controller, RemoteController            
from mininet.cli import CLI 
from mininet.log import setLogLevel 
 
def execute(): 
 
    # Create Mininet instance. 
    net = Mininet() 
 
    # Add the SDN controller to the network. 
    c1 = net.addController(name='c1', 
controller=RemoteController, ip='127.0.0.1') # Add hosts to the network. h0=net.addHost('h0') h1=net.addHost('h1') # Add switches to the network. s0=net.addSwitch('s0') s1=net.addSwitch('s1') s2=net.addSwitch('s2') # Creating links between the switches in the network net.addLink(s0, s1) net.addLink(s1, s2) net.addLink(s0, s2) # Connect hosts to the relevant switches in the network. net.addLink(h0, s0) net.addLink(h1, s1) # Start execution. net.start() CLI( net ) if __name__ == '__main__': setLogLevel( 'info' ) # for CLI output execute()

This is a simple Python program that uses Open vSwitch for virtual emulated switches, and remote SDN Controller module of Mininet to connect to an executing controller (or if none exists, start its own).

First, we start the OpenDaylight controller from the bin directory:

$ ./karaf
karaf: Ignoring predefined value for KARAF_HOME
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
    
________                       ________                .__  .__  .__     __       
    \_____   ______   ____   ____ \______  _____  ___.__.|  | |__| ____ |  |___/  |_     
     /   |   \____ \_/ __  /     |    |  \__  <   |  ||  | |  |/ ___|  |     __    
    /    |      |_> >  ___/|   |  |    `   / __ \___  ||  |_|  / /_/  >   Y    |      
   \_______  /   __/ \___  >___|  /_______  (____  / ____||____/__\___  /|___|  /__|      
            /|__|        /     /        /     //            /_____/      /          
    
    
Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown OpenDaylight.
  

Then we execute our program:

$ sudo python 10_2_sdn_opendaylight.py
[sudo] password for pradeeban: 
Connecting to remote controller at 127.0.0.1:6653
*** Configuring hosts
*** Starting controller(s)
c1 
*** Starting switches and/or access points
s0 s1 s2 ...
*** Starting CLI:
mininet-wifi> 

We can also access the controller GUI (DLUX) through a browser, at http://localhost:8181/index.html# as we did before. The following screenshot indicates the output from the console and the browser:

SDN with OpenDaylight
..................Content has been hidden....................

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