Statistics
| Branch: | Tag: | Revision:

mininet / examples / linearbandwidth.py @ be963554

History | View | Annotate | Download (3.16 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 Host, 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 id in hosts:
46
            self._add_node( id, Node( is_switch=False ) )
47
        for id in switches:
48
            self._add_node( id, 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 ; flush()
85
            results[ datapath ] += [ ( n, bandwidth ) ]
86
        net.stop()
87
      
88
    for datapath in datapaths:
89
        print
90
        print "*** Linear network results for", datapath, "datapath:"
91
        print
92
        result = results[ datapath ]  
93
        print "SwitchCount\tiperf Results"
94
        for switchCount, bandwidth in result:
95
            print switchCount, '\t\t', 
96
            print bandwidth[ 0 ], 'server, ', bandwidth[ 1 ], 'client'
97
        print
98
    print
99
      
100
if __name__ == '__main__':
101
    lg.setLogLevel( 'info' )
102
    init()
103
    print "*** Running linearBandwidthTest"
104
    linearBandwidthTest( [ 1, 10, 20  ]  )
105

    
106