Skip to content

Using NetASM Switch with Mininet Python API

Muhammad Shahbaz edited this page Jun 19, 2015 · 7 revisions

The NetASM Switch can also be used with Mininet. For this, we provided a new node class for Mininet called NetASMSwitch. When using Mininet Python APIs, you can use this to specify the switch type.

Here's an example of a single switch topology in Mininet using NetASMSwitch.

from mininet.node import RemoteController
from mininet.net import Mininet, CLI
from mininet.topo import SingleSwitchTopo
from mininet.log import setLogLevel
from netasm.back_ends.soft_switch.mininet.node import NetASMSwitch


def test():
    topo = SingleSwitchTopo(2)

    NetASMSwitch.CTL_ADDRESS = "127.0.0.1"
    NetASMSwitch.CTL_PORT = 7791

    net = Mininet(topo, switch=NetASMSwitch, autoSetMacs=True, controller=lambda name: RemoteController(name))

    for switch in net.switches:
        switch.policy = 'netasm.examples.netasm.standalone.hub'

    NetASMSwitch.start_datapath(net.switches, address="127.0.0.1", port=6633, standalone=True)
    net.start()

    net.pingAll()

    net.stop()
    NetASMSwitch.stop_datapath()


if __name__ == '__main__':
    # Tell mininet to print useful information
    setLogLevel('info')
    test()

You can find the actual code, here.

Let's run this program.

$ cd ~/netasm/netasm/examples/back_ends/soft_switch/mininet
$ sudopy python standalone_single_switch.py

This will start Mininet.

*** Creating network
*** Adding controller
Unable to contact the remote controller at 127.0.0.1:6633
*** Adding hosts:
h1 h2 
*** Adding switches:
s1 
*** Adding links:
(h1, s1) (h2, s1) 
*** Configuring hosts
h1 h2 
*** Run this command in a separate terminal then press Enter!
sudopy python /home/vagrant/pox/pox.py --no-openflow netasm.back_ends.soft_switch.datapath --standalone --address=127.0.0.1 --port=6633 --dpid=0000000000000001 --policy=netasm.examples.netasm.standalone.hub --ports=s1-eth1,s1-eth2 --ctl_port=7791

However, it will halt at one point asking you to run a python script for launching NetASM datapath in another terminal, as shown above.

$ sudopy python /home/vagrant/pox/pox.py --no-openflow netasm.back_ends.soft_switch.datapath --standalone --address=127.0.0.1 --port=6633 --dpid=0000000000000001 --policy=netasm.examples.netasm.standalone.hub --ports=s1-eth1,s1-eth2 --ctl_port=7791

After running this, go back to the previous terminal where Mininet was running and press Enter. This will resume Mininet which, after setting up the virtual network, will run net.pingAll() and terminate.

*** Starting controller
c0 
*** Starting 1 switches
s1 
*** Ping: testing ping reachability
h1 -> h2 
h2 -> h1 
*** Results: 0% dropped (2/2 received)
*** Stopping 1 controllers
c0 
*** Stopping 2 links
..
*** Stopping 1 switches
s1 
*** Stopping 2 hosts
h1 h2 
*** Done

Clone this wiki locally