Skip to content
Snippets Groups Projects
linearbandwidth.py 3.33 KiB
Newer Older
#!/usr/bin/python

Bob Lantz's avatar
Bob Lantz committed
"""
Test bandwidth (using iperf) on linear networks of varying size,
Bob Lantz's avatar
Bob Lantz committed
using both kernel and user datapaths.
Bob Lantz's avatar
Bob Lantz committed

We construct a network of N hosts and N-1 switches, connected as follows:
Bob Lantz's avatar
Bob Lantz committed

h1 <-> sN+1 <-> sN+2 .. sN+N-1
       |        |       |
       h2       h3      hN
WARNING: by default, the reference controller only supports 16
Bob Lantz's avatar
Bob Lantz committed
switches, so this test WILL NOT WORK unless you have recompiled
your controller to support 100 switches (or more.)

In addition to testing the bandwidth across varying numbers
of switches, this example demonstrates:

- creating a custom topology, LinearTestTopo
- using the ping() and iperf() tests from Mininet()
- testing both the kernel and user switches

Bob Lantz's avatar
Bob Lantz committed
"""
import sys
flush = sys.stdout.flush
from mininet.net import init, Mininet
# from mininet.node import KernelSwitch
from mininet.node import UserSwitch, OVSKernelSwitch
from mininet.topo import Topo, Node
from mininet.log import lg

class LinearTestTopo( Topo ):
    "Topology for a string of N hosts and N-1 switches."

    def __init__( self, N ):
        # Add default members to class.
        super( LinearTestTopo, self ).__init__()
        # Create switch and host nodes
        hosts = range( 1, N + 1 )
        switches = range( N + 1 , N + N )
        for h in hosts:
            self.add_node( h, Node( is_switch=False ) )
        for s in switches:
            self.add_node( s, Node( is_switch=True ) )

        # Wire up switches
        for s in switches[ :-1 ]:
        # Wire up hosts
        self.add_edge( hosts[ 0 ], switches[ 0 ] )
        for h in hosts[ 1: ]:
        # Consider all switches and hosts 'on'
        self.enable_all()

Bob Lantz's avatar
Bob Lantz committed

    "Check bandwidth at various lengths along a switch chain."

    results = {}
    switchCount = max( lengths )
    hostCount = switchCount + 1
    switches = {  # 'reference kernel': KernelSwitch,
            'reference user': UserSwitch,
            'Open vSwitch kernel': OVSKernelSwitch }
    for datapath in switches.keys():
        print "*** testing", datapath, "datapath"
        Switch = switches[ datapath ]
        results[ datapath ] = []
        net = Mininet( topo=LinearTestTopo( hostCount ), switch=Switch )
        net.start()
        print "*** testing basic connectivity"
        for n in lengths:
            net.ping( [ net.hosts[ 0 ], net.hosts[ n ] ] )
        print "*** testing bandwidth"
        for n in lengths:
            src, dst = net.hosts[ 0 ], net.hosts[ n ]
            print "testing", src.name, "<->", dst.name,
            bandwidth = net.iperf( [ src, dst ] )
            results[ datapath ] += [ ( n, bandwidth ) ]
        net.stop()
    for datapath in switches.keys():
        print
        print "*** Linear network results for", datapath, "datapath:"
        print
        print "SwitchCount\tiperf Results"
        for switchCount, bandwidth in result:
            print bandwidth[ 0 ], 'server, ', bandwidth[ 1 ], 'client'
        print
    print
if __name__ == '__main__':
    lg.setLogLevel( 'info' )
    sizes = [ 1, 10, 20, 40, 60, 80, 100 ]
    print "*** Running linearBandwidthTest", sizes
    linearBandwidthTest( sizes  )