In-band Controller with Mininet

Update: See my followup post on an improvement to the script so that you don’t need to modify and MiniNet classes. But first read through this post to see how it works.


There have been a few threads in the Mininet mailing list about people trying to connect a controller to a specific switch by creating a link between a switch and ‘c0’.  As people have discovered, this isn’t going to work.  But this got me thinking about how to test in-band management.  I found that Open vSwitch by default uses in-band.  So after some testing and changing in mininet, I managed to actually build a working scenario of in-band management.

So what I did, which should work, but mininet had a bug/deficiency, is that first create a network script like this.

    net = Mininet( topo=None,  build=False)

    h1 = net.addHost( 'h1', ip='' )
    h2 = net.addHost( 'h2', ip='' )
    h3 = net.addHost( 'h3', ip='' )

    s1 = net.addSwitch( 's1', cls=OVSSwitch )

    net.addLink( h1, s1 )
    net.addLink( h2, s1 )
    net.addLink( h3, s1 )

    CLI( net )

Now here is the trick.  Since you can’t create a link to a controller, we are actually going to run a controller inside one of the hosts.  So for our test, we are going to run our controller inside h1.  So first, add this line into your script.

    net.addController( 'c0',
                       ip=''  )

The other important thing to remember is that the switch itself needs an IP address.  So we add a command to the script to set the IP address on the switch to something in the same subnet.  We will insert a new line after the net.start() to set the s1 switch IP address to

    s1.cmd('ifconfig s1 inet')

Once that is done, you should have been able to start up the script.  But when I did, the mininet hung.  I tracked it down to mininet calling a method checkListening().  Unfortunately, it hangs in here because the test is trying to see if the IP and port are there, but we gave it an address that wasn’t even routable.  So the test hangs.  So my quick hack was to remove the listen check.  The path to your python might be different depending on how you installed it and all this must be done as root/sudo.

First, remove the binary of, called node.pyc.

cd /usr/local/lib/python2.7/dist-packages/mininet-2.1.0-py2.7.egg/mininet
rm node.pyc

Then modify the  Since I am running the Mininet 2.1.0 VM, go to line 1135.  It will be in the __init__() method.  Just comment out the line calling self.checkListening().

    def __init__( self, name, inNamespace=False, command='controller',
                  cargs='-v ptcp:%d', cdir=None, ip="",
                  port=6633, **params ):
        self.command = command
        self.cargs = cargs
        self.cdir = cdir
        self.ip = ip
        self.port = port
        Node.__init__( self, name, inNamespace=inNamespace,
                       ip=ip, **params  )
        self.cmd( 'ifconfig lo up' )  # Shouldn't be necessary

Now that you modified the file and saved it, go ahead and start your script.  But at this point, if you try and run pingall, it will all fail.  That is because you didn’t start the controller yet.

mininet> pingall
*** Ping: testing ping reachability
h1 -> X X
h2 -> X X
h3 -> X X
*** Results: 100% dropped (0/6 received)

So start the controller.  First open an xterm to h1, which is where we said the controller would be.

mininet> xterm h1

When the xterm opens, start the controller. For this quick test, we will just start the OpenFlow Reference controller.

root@mininet-vm:~# controller -v ptcp:6633

At this point, you should see output from the controller like.


This means that the controller and switch are successfully talking to each other.  And if you do a pingall now.

mininet> pingall
*** Ping: testing ping reachability
h1 -> h2 h3
h2 -> h1 h3
h3 -> h1 h2
*** Results: 0% dropped (6/6 received)

Congratulations, you now have in-band testing.  There are certain cases where you would want to test this scenario.  So it is a good option to have.

This will also now allow you to add link bandwidth management parameters on the link between the switch and the node hosting the controller, such as delay and jitter, if you really want to do that.  For this example, we just used the OpenFlow reference controller.  You should be able to start any controller that you have installed on your Mininet VM.

Hope people find this useful.  My full script looks like this.


from import Mininet
from mininet.node import RemoteController, OVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info

def emptyNet():

    "Create an empty network and add nodes to it."

    net = Mininet( topo=None,

    net.addController( 'c0',
                       ip=''  )

    h1 = net.addHost( 'h1', ip='' )
    h2 = net.addHost( 'h2', ip='' )
    h3 = net.addHost( 'h3', ip='' )

    s1 = net.addSwitch( 's1', cls=OVSSwitch )

    net.addLink( h1, s1 )
    net.addLink( h2, s1 )
    net.addLink( h3, s1 )

    s1.cmd('ifconfig s1 inet')

    CLI( net )

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

This post ‘In-band Controller with Mininet’ first appeared on


4 Responses to In-band Controller with Mininet

  1. Fantastic post Gregory! Thanks so much!

  2. Amina Bibi says:

    i’m trying to ping h1 to h2 or h3 but it doesn’t work !! So, how can I test the in band controller ?
    Help please !!

  3. Gustavo says:

    When I try to start the controller in the host h1, the command ˜controller -v ptcp:6633˜ do nothing. What is possibly going wrong?
    I`m using the mininet 2.0.0 in an Apple OS X

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: