Lab 1: Create a network and run a simple performance test



    Prepare a SingleSwitchTopo class that adds a single switch and n hosts into a network. Each link connected from host to switch can be set the bandwidth, delay time, and loss rate. Then create a network that contains one switch and 4 hosts. Finally, use iperf to test the bandwidth between host 1 and host 4.





from mininet.topo import Topo

from import Mininet

from mininet.node import CPULimitedHost

from import TCLink

from mininet.util import dumpNodeConnections

from mininet.log import setLogLevel


class SingleSwitchTopo(Topo):

    "Single switch connected to n hosts."

    def __init__(self, n=2, **opts):

        Topo.__init__(self, **opts)

        switch = self.addSwitch('s1')

        for h in range(n):

            #Each host gets 50%/n of system CPU

            host = self.addHost('h%s' % (h + 1), cpu=.5/n)

            #10 Mbps, 5ms delay, 0% Loss, 1000 packet queue

            self.addLink(host, switch, bw=10, delay='5ms', loss=0, max_queue_size=1000, use_htb=True)


def perfTest():

    "Create network and run simple performance test"

    topo = SingleSwitchTopo(n=4)

    net = Mininet(topo=topo,host=CPULimitedHost, link=TCLink)


    print "Dumping host connections"


    print "Testing network connectivity"


    print "Testing bandwidth between h1 and h4"

    h1, h4 = net.get('h1', 'h4')

    net.iperf((h1, h4))



if __name__=='__main__':






(Need to use chmod +x to add execution property to first. Then use sudo to run the script.)


Dr. Chih-Heng Ke (

Department of Computer Science and Information Engineering,

National Quemoy University, Kinmen, Taiwan.