Statistics
| Branch: | Tag: | Revision:

mininet / examples / linearbandwidth.py @ 9cbf4688

History | View | Annotate | Download (3.64 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, Controller
28
from mininet.topo import Topo
29
from mininet.log import lg
30
from mininet.util import irange
31
from mininet.link import TCLink
32
from functools import partial
33

    
34
import sys
35
flush = sys.stdout.flush
36

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

    
40
    def __init__( self, N, **params ):
41

    
42
        # Initialize topology
43
        Topo.__init__( self, **params )
44

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

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

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

    
63

    
64
def linearBandwidthTest( lengths ):
65

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

    
68
    results = {}
69
    switchCount = max( lengths )
70
    hostCount = switchCount + 1
71

    
72
    switches = { 'reference user': UserSwitch,
73
                 'Open vSwitch kernel': OVSKernelSwitch }
74

    
75
    topo = LinearTestTopo( hostCount )
76

    
77
    for datapath in switches.keys():
78
        # we can remove this later when/if the userswitch is fixed
79
        if switches[ datapath ] is UserSwitch:
80
            print "*** Skipping User Switch due to poor performance"
81
            continue
82
        print "*** testing", datapath, "datapath"
83
        Switch = switches[ datapath ]
84
        results[ datapath ] = []
85
        link = partial( TCLink, delay='1ms' )
86
        net = Mininet( topo=topo, switch=Switch,
87
                       controller=Controller, waitConnected=True,
88
                       link=link )
89
        net.start()
90
        print "*** testing basic connectivity"
91
        for n in lengths:
92
            net.ping( [ net.hosts[ 0 ], net.hosts[ n ] ] )
93
        print "*** testing bandwidth"
94
        for n in lengths:
95
            src, dst = net.hosts[ 0 ], net.hosts[ n ]
96
            print "testing", src.name, "<->", dst.name,
97
            bandwidth = net.iperf( [ src, dst ] )
98
            print bandwidth
99
            flush()
100
            results[ datapath ] += [ ( n, bandwidth ) ]
101
        net.stop()
102

    
103
    for datapath in switches.keys():
104
        print
105
        print "*** Linear network results for", datapath, "datapath:"
106
        print
107
        result = results[ datapath ]
108
        print "SwitchCount\tiperf Results"
109
        for switchCount, bandwidth in result:
110
            print switchCount, '\t\t',
111
            print bandwidth[ 0 ], 'server, ', bandwidth[ 1 ], 'client'
112
        print
113
    print
114

    
115
if __name__ == '__main__':
116
    lg.setLogLevel( 'info' )
117
    sizes = [ 1, 10, 20, 40, 60, 80, 100 ]
118
    print "*** Running linearBandwidthTest", sizes
119
    linearBandwidthTest( sizes  )