Statistics
| Branch: | Tag: | Revision:

mininet / examples / linearbandwidth.py @ 33695835

History | View | Annotate | Download (3.89 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, quietRun
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
    # UserSwitch is horribly slow with recent kernels.
76
    # We can reinstate it once its performance is fixed
77
    del switches[ 'reference user' ]
78

    
79
    topo = LinearTestTopo( hostCount )
80

    
81
    # Select TCP Reno
82
    output = quietRun( 'sysctl -w net.ipv4.tcp_congestion_control=reno' )
83
    assert 'reno' in output
84

    
85
    for datapath in switches.keys():
86
        print "*** testing", datapath, "datapath"
87
        Switch = switches[ datapath ]
88
        results[ datapath ] = []
89
        link = partial( TCLink, delay='1ms' )
90
        net = Mininet( topo=topo, switch=Switch,
91
                       controller=Controller, waitConnected=True,
92
                       link=link )
93
        net.start()
94
        print "*** testing basic connectivity"
95
        for n in lengths:
96
            net.ping( [ net.hosts[ 0 ], net.hosts[ n ] ] )
97
        print "*** testing bandwidth"
98
        for n in lengths:
99
            src, dst = net.hosts[ 0 ], net.hosts[ n ]
100
            # Try to prime the pump to reduce PACKET_INs during test
101
            # since the reference controller is reactive
102
            src.cmd( 'telnet', dst.IP(), '5001' )
103
            print "testing", src.name, "<->", dst.name,
104
            bandwidth = net.iperf( [ src, dst ], seconds=10 )
105
            print bandwidth
106
            flush()
107
            results[ datapath ] += [ ( n, bandwidth ) ]
108
        net.stop()
109

    
110
    for datapath in switches.keys():
111
        print
112
        print "*** Linear network results for", datapath, "datapath:"
113
        print
114
        result = results[ datapath ]
115
        print "SwitchCount\tiperf Results"
116
        for switchCount, bandwidth in result:
117
            print switchCount, '\t\t',
118
            print bandwidth[ 0 ], 'server, ', bandwidth[ 1 ], 'client'
119
        print
120
    print
121

    
122
if __name__ == '__main__':
123
    lg.setLogLevel( 'info' )
124
    sizes = [ 1, 10, 20, 40, 60, 80 ]
125
    print "*** Running linearBandwidthTest", sizes
126
    linearBandwidthTest( sizes  )