Statistics
| Branch: | Tag: | Revision:

mininet / examples / linearbandwidth.py @ edf60032

History | View | Annotate | Download (3.22 KB)

1
#!/usr/bin/python
2

    
3
"""
4
Test bandwidth (using iperf) on linear networks of varying size,
5
using both kernel and user datapaths.
6

7
We construct a network of N hosts and N-1 switches, connected as follows:
8

9
h1 <-> s1 <-> s2 .. sN-1
10
       |       |    |
11
       h2      h3   hN
12

13
WARNING: by default, the reference controller only supports 16
14
switches, so this test WILL NOT WORK unless you have recompiled
15
your controller to support 100 switches (or more.)
16

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

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

24
"""
25

    
26
from mininet.net import Mininet
27
from mininet.node import UserSwitch, OVSKernelSwitch
28
from mininet.topo import Topo
29
from mininet.log import lg
30
from mininet.util import irange
31

    
32
import sys
33
flush = sys.stdout.flush
34

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

    
38
    def __init__( self, N, **params ):
39

    
40
        # Initialize topology
41
        Topo.__init__( self, **params )
42

    
43
        # Create switches and hosts
44
        hosts = [ self.addHost( 'h%s' % h )
45
                  for h in irange( 1, N ) ]
46
        switches = [ self.addSwitch( 's%s' % s )
47
                     for s in irange( 1, N - 1 ) ]
48

    
49
        # Wire up switches
50
        last = None
51
        for switch in switches:
52
            if last:
53
                self.addLink( last, switch )
54
            last = switch
55

    
56
        # Wire up hosts
57
        self.addLink( hosts[ 0 ], switches[ 0 ] )
58
        for host, switch in zip( hosts[ 1: ], switches ):
59
            self.addLink( host, switch )
60

    
61

    
62
def linearBandwidthTest( lengths ):
63

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

    
66
    results = {}
67
    switchCount = max( lengths )
68
    hostCount = switchCount + 1
69

    
70
    switches = { 'reference user': UserSwitch,
71
                 'Open vSwitch kernel': OVSKernelSwitch }
72

    
73
    topo = LinearTestTopo( hostCount )
74

    
75
    for datapath in switches.keys():
76
        print "*** testing", datapath, "datapath"
77
        Switch = switches[ datapath ]
78
        results[ datapath ] = []
79
        net = Mininet( topo=topo, switch=Switch )
80
        net.start()
81
        print "*** testing basic connectivity"
82
        for n in lengths:
83
            net.ping( [ net.hosts[ 0 ], net.hosts[ n ] ] )
84
        print "*** testing bandwidth"
85
        for n in lengths:
86
            src, dst = net.hosts[ 0 ], net.hosts[ n ]
87
            print "testing", src.name, "<->", dst.name,
88
            bandwidth = net.iperf( [ src, dst ] )
89
            print bandwidth
90
            flush()
91
            results[ datapath ] += [ ( n, bandwidth ) ]
92
        net.stop()
93

    
94
    for datapath in switches.keys():
95
        print
96
        print "*** Linear network results for", datapath, "datapath:"
97
        print
98
        result = results[ datapath ]
99
        print "SwitchCount\tiperf Results"
100
        for switchCount, bandwidth in result:
101
            print switchCount, '\t\t',
102
            print bandwidth[ 0 ], 'server, ', bandwidth[ 1 ], 'client'
103
        print
104
    print
105

    
106
if __name__ == '__main__':
107
    lg.setLogLevel( 'info' )
108
    sizes = [ 1, 10, 20, 40, 60, 80, 100 ]
109
    print "*** Running linearBandwidthTest", sizes
110
    linearBandwidthTest( sizes  )