Mininet + NS3 for SDN and WIFI simulations


Example 2:

h1( link--h0 (wireless router: and 10.0.01)-- s0(OVS)--h3(

h2 ( link—



1.      Open the vm.

2.      Login with name: mininet and password: mininet

3.      Change to graphical mode: startx

4.      Open a terminal

5.     Go to the directory containing ns3: cd ns-allinone-3.17/ns-3.17

6.      Run sudo ./waf shell in order to let the ns3 set appropriate environment variables.

7.     Run the




This example shows how to create an empty Mininet object

(without a topology object) and add nodes to it manually.



from import Mininet

from mininet.node import OVSController

from mininet.cli import CLI

from mininet.log import setLogLevel, info


import mininet.ns3                          # line added

from mininet.ns3 import WIFISegment

from import TCLink

import ns.wifi


def emptyNet():


    net = Mininet( controller=OVSController )


    info( '*** Adding controller\n' )

    net.addController( 'c0' )


    info( '*** Adding switch\n' )

    s0 = net.addSwitch( 's0' )

    s0.listenPort = 6634


    h0 = net.addHost( 'h0' )

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

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

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

    linkopts=dict( bw=100, delay='1ms', loss=0 )

    TCLink( s0, h3, **linkopts )

    TCLink( h0, s0, **linkopts )


    wifi = WIFISegment()


    wifi.addAp( h0 )

    wifi.addSta( h1 )

    wifi.addSta( h2 )


    info( '*** Starting network\n')




    h0.cmdPrint ( "ifconfig h0-eth0 netmask" )

    h0.cmdPrint ( "ifconfig h0-eth1 netmask" )

    h0.cmdPrint ( "sudo echo 1 > /proc/sys/net/ipv4/ip_forward" )

    h1.cmdPrint ( "route add default gw" )

    h2.cmdPrint ( "route add default gw" )

    h3.cmdPrint ( "route add default gw" )


    info( '*** Testing network connectivity\n' )



    info( '*** Running CLI\n' )

    CLI( net )


    info( '*** Stopping network' )


    mininet.ns3.clear()                     # line added



if __name__ == '__main__':

setLogLevel( 'info' )






























8.      Show the network topoplogy.


9.      Use the dpctl to show switch s0


10.  Use the dpctl to dump-flows for switch s0


11.   We can change the default ovs-controller to another controller (Here we use pox as an example.)

11.1  open another terminal and kill the ovs-controller process


11.2  use dpctl to del-flows for switch s0

11.3  use dpctl to dump-flows for switch s0. To check that there are no rules for switch s0 now. So h1 and h2 can not ping h3.



12.  Use pox controller.

(above figure: the second terminal)

(above figure: the first terminal)


(above figure: the second terminal)


Dr. Chih-Heng Ke

Department of Computer Science and Information Engineering, National Quemoy University, Kinmen, Taiwan