Revision 80be5642 examples/linearbandwidth.py

View differences:

examples/linearbandwidth.py
1 1
#!/usr/bin/python
2 2

  
3 3
"""
4
Test bandwidth (using iperf) on linear networks of varying size, 
4
Test bandwidth (using iperf) on linear networks of varying size,
5 5
using both kernel and user datapaths.
6 6

  
7 7
We construct a network of N hosts and N-1 switches, connected as follows:
......
9 9
h1 <-> sN+1 <-> sN+2 .. sN+N-1
10 10
       |        |       |
11 11
       h2       h3      hN
12
        
12

  
13 13
Note: by default, the reference controller only supports 16
14 14
switches, so this test WILL NOT WORK unless you have recompiled
15 15
your controller to support 100 switches (or more.)
......
25 25

  
26 26
import sys
27 27
flush = sys.stdout.flush
28
   
28

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

  
......
35 35
    "Topology for a string of N hosts and N-1 switches."
36 36

  
37 37
    def __init__( self, N ):
38
    
38

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

  
42 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
        
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 50
        # Wire up switches
51 51
        for s in switches[ :-1 ]:
52
            self._add_edge( s, s + 1 )
53
        
52
            self.add_edge( s, s + 1 )
53

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

  
59 59
        # Consider all switches and hosts 'on'
60 60
        self.enable_all()
......
81 81
            src, dst = net.hosts[ 0 ], net.hosts[ n ]
82 82
            print "testing", src.name, "<->", dst.name
83 83
            bandwidth = net.iperf( [ src, dst ] )
84
            print bandwidth ; flush()
84
            print bandwidth
85
            flush()
85 86
            results[ datapath ] += [ ( n, bandwidth ) ]
86 87
        net.stop()
87
      
88

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

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

  
106
   

Also available in: Unified diff