Statistics
| Branch: | Tag: | Revision:

mininet / examples / linearbandwidth.py @ 8a130dea

History | View | Annotate | Download (3.33 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
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
import sys
27
flush = sys.stdout.flush
28

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

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

    
38
    def __init__( self, N ):
39

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

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

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

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

    
60
        # Consider all switches and hosts 'on'
61
        self.enable_all()
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 kernel': KernelSwitch,
73
            'reference user': UserSwitch,
74
            'Open vSwitch kernel': OVSKernelSwitch }
75

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

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

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