Mininet + NS3 for SDN and WIFI simulations

 

Example 2:

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

h2 (192.168.0.3)--wireless link—

 

Usage:

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 test-wifi2.py

#!/usr/bin/python

 

"""

This example shows how to create an empty Mininet object

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

"""

 

from mininet.net 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 mininet.link 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='192.168.0.2' )

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

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

    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')

    net.start()

    mininet.ns3.start()               

 

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

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

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

    h1.cmdPrint ( "route add default gw 192.168.0.1" )

    h2.cmdPrint ( "route add default gw 192.168.0.1" )

    h3.cmdPrint ( "route add default gw 10.0.0.1" )

 

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

    net.pingAll()

 

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

    CLI( net )

 

    info( '*** Stopping network' )

    mininet.ns3.stop()

    mininet.ns3.clear()                     # line added

    net.stop()

 

if __name__ == '__main__':

setLogLevel( 'info' )

emptyNet()

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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

Email: smallko@gmail.com