Statistics
| Branch: | Tag: | Revision:

mininet / examples / linearbandwidth.py @ 80be5642

History | View | Annotate | Download (3.1 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
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
def linearBandwidthTest( lengths ):
63

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

    
66
    datapaths = [ 'kernel', 'user' ]
67
    results = {}
68
    switchCount = max( lengths )
69
    hostCount = switchCount + 1
70

    
71
    for datapath in datapaths:
72
        Switch = KernelSwitch if datapath == 'kernel' else UserSwitch
73
        results[ datapath ] = []
74
        net = Mininet( topo=LinearTestTopo( hostCount ), switch=Switch )
75
        net.start()
76
        print "*** testing basic connectivity"
77
        for n in lengths:
78
            net.ping( [ net.hosts[ 0 ], net.hosts[ n ] ] )
79
        print "*** testing bandwidth"
80
        for n in lengths:
81
            src, dst = net.hosts[ 0 ], net.hosts[ n ]
82
            print "testing", src.name, "<->", dst.name
83
            bandwidth = net.iperf( [ src, dst ] )
84
            print bandwidth
85
            flush()
86
            results[ datapath ] += [ ( n, bandwidth ) ]
87
        net.stop()
88

    
89
    for datapath in datapaths:
90
        print
91
        print "*** Linear network results for", datapath, "datapath:"
92
        print
93
        result = results[ datapath ]
94
        print "SwitchCount\tiperf Results"
95
        for switchCount, bandwidth in result:
96
            print switchCount, '\t\t',
97
            print bandwidth[ 0 ], 'server, ', bandwidth[ 1 ], 'client'
98
        print
99
    print
100

    
101
if __name__ == '__main__':
102
    lg.setLogLevel( 'info' )
103
    init()
104
    print "*** Running linearBandwidthTest"
105
    linearBandwidthTest( [ 1, 10, 20  ]  )