Statistics
| Branch: | Tag: | Revision:

mininet / examples / linearbandwidth.py @ 51270ce4

History | View | Annotate | Download (2.79 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
Each network has N switches and N+1 hosts, connected as follows:
8

9
h0 <-> s0 <-> s1 .. sN-1
10
        |      |     |
11
        h1     h2    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
   
18
from mininet.mininet import init, Network, defaultNames, Host, Switch
19
from mininet.mininet import createLink, flush, iperf, pingTestVerbose, Cli
20

    
21
class LinearNet( Network ):
22
   def __init__( self, switchCount, **kwargs ):
23
      self.switchCount = switchCount
24
      Network.__init__( self, **kwargs )
25
   def makeNet( self, controller ):
26
      snames, hnames, dpnames = defaultNames()
27
      previous = None
28
      hosts = []
29
      switches = []
30
      def newHost( switch ):
31
         host = Host( hnames.next() )
32
         createLink( host, switch )
33
         print host.name, ; flush()
34
         return [ host ]
35
      print "*** Creating linear network of size", self.switchCount
36
      for s in range( 0, self.switchCount ):
37
         dp = dpnames.next() if self.kernel else None
38
         switch = Switch( snames.next(), dp )
39
         switches += [ switch ]
40
         print switch.name, ; flush()
41
         if not self.kernel: createLink( controller, switch )
42
         if s == 0: hosts += newHost( switch )
43
         hosts += newHost( switch)
44
         if previous is not None: createLink( previous, switch)
45
         previous = switch
46
      return switches, hosts
47
   
48
def linearBandwidthTest( lengths ):
49

    
50
   "Check bandwidth at various lengths along a switch chain."
51
   
52
   datapaths = [ 'kernel', 'user' ]
53
   results = {}
54
   switchCount = max( lengths )
55
   
56
   for datapath in datapaths:
57
      k = datapath == 'kernel'
58
      results[ datapath ] = []
59
      network = LinearNet( switchCount, kernel=k)
60
      network.start()
61
      for n in lengths:
62
         def test( controllers, switches, hosts ):
63
            print "testing h0 <-> h" + `n`, ; flush()
64
            result = iperf( [ hosts[ 0 ], hosts[ n ] ] )
65
            print result ; flush()
66
            return result
67
         bandwidth = network.runTest( test )
68
         results[ datapath ] += [ ( n, bandwidth ) ]
69
      network.stop()
70
      
71
   for datapath in datapaths:
72
      print
73
      print "*** Linear network results for", datapath, "datapath:"
74
      print
75
      result = results[ datapath ]  
76
      print "SwitchCount\tiperf Results"
77
      for switchCount, bandwidth in result:
78
         print switchCount, '\t\t', 
79
         print bandwidth[ 0 ], 'server, ', bandwidth[ 1 ], 'client'
80
      print
81
   print
82
      
83
if __name__ == '__main__':
84
   init()
85
   print "*** Running linearBandwidthTest"
86
   linearBandwidthTest( [ 1, 10, 20, 40, 60, 80, 100 ] )
87

    
88