Statistics
| Branch: | Tag: | Revision:

mininet / examples / linearbandwidth.py @ 35341142

History | View | Annotate | Download (3.29 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 <-> sN+1 <-> sN+2 .. sN+N-1
10
       |        |       |
11
       h2       h3      hN
12

13
Note: 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
import sys
27
flush = sys.stdout.flush
28

    
29
from mininet.net import init, Mininet
30
from mininet.node import KernelSwitch, UserSwitch, OVSKernelSwitch
31
from mininet.topo import Topo, Node
32
from mininet.log import lg
33

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

    
37
    def __init__( self, N ):
38

    
39
        # Add default members to class.
40
        super( LinearTestTopo, self ).__init__()
41

    
42
        # Create switch and host nodes
43
        hosts = range( 1, N + 1 )
44
        switches = range( N + 1 , N + N )
45
        for h in hosts:
46
            self.add_node( h, Node( is_switch=False ) )
47
        for s in switches:
48
            self.add_node( s, Node( is_switch=True ) )
49

    
50
        # Wire up switches
51
        for s in switches[ :-1 ]:
52
            self.add_edge( s, s + 1 )
53

    
54
        # Wire up hosts
55
        self.add_edge( hosts[ 0 ], switches[ 0 ] )
56
        for h in hosts[ 1: ]:
57
            self.add_edge( h, h + N - 1 )
58

    
59
        # Consider all switches and hosts 'on'
60
        self.enable_all()
61

    
62

    
63
def linearBandwidthTest( lengths ):
64

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

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

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

    
75
    for datapath in switches.keys():
76
        print "*** testing", datapath, "datapath"
77
        Switch = switches[ datapath ]
78
        results[ datapath ] = []
79
        net = Mininet( topo=LinearTestTopo( hostCount ), 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( 'warning' )
108
    init()
109
    sizes = [ 1, 10, 20 ]
110
    print "*** Running linearBandwidthTest", sizes
111
    linearBandwidthTest( sizes  )