title: Sending "random" traffic through Mininet network
body: <p>I want to test a data center routing algorithm using Mininet. The traffic needs to conform to certain parameters: </p>
  
  <ol>
  <li>It should consist of "files" of various sizes (note that these don't actually have to be files; traffic generated in, e.g., iperf is OK, as long as the size is controllable); </li>
  <li>The file sizes should be drawn from a particular distribution; </li>
  <li>The source/destination host pairs between which data is sent should be selected randomly for a given file; </li>
  <li>The interval between when a file is sent and its successor is sent should be random; and </li>
  <li>If a huge file gets sent between two hosts that takes a long time to transfer, it should still be possible to send data between other hosts in the network. </li>
  </ol>
  
  <p>Points 1-4 are taken care of. I've been struggling with #5 for days and I can't get it working properly. My initial thought was to spawn subprocesses/threads to send iperf commands to the hosts: </p>
  
  <pre><code>while count &lt; 10:
      if (count % 2) == 0:
          host_pair = net.get("h1", "h2")
      else:
          host_pair = net.get("h3", "h4")
  
      p = multiprocessing.Process(target=test_custom_iperf, args=(net, host_pair, nbytes))
      p.daemon = True
      p.start()
  
      time.sleep(random.uniform(0, 1))
  </code></pre>
  
  <p>The command test_custom_iperf is modeled after the Python Mininet API's version of iperf to include the <code>-n</code> transfer size parameter: </p>
  
  <pre><code>client, server = host_pair
  print client, server
  
  output( '*** Iperf: testing TCP bandwidth between',
          client, 'and', server, '\n' )
  
  server.sendCmd( 'iperf -s' )
  
  if not waitListening( client, server.IP(), 5001 ):
      raise Exception( 'Could not connect to iperf on port 5001' )
  
  cliout = client.cmd( 'iperf -c ' + server.IP() + ' -n %d' % nbytes )
  print cliout
  
  server.sendInt()
  servout = server.waitOutput()
  
  debug( 'Server output: %s\n' % servout)
  result = [ net._parseIperf( servout ), net._parseIperf( cliout ) ]
  output( '*** Results: %s\n' % result )
  </code></pre>
  
  <p>Making this non-blocking has been extremely difficult. I need to be able to send the <code>server.sendInt()</code> command, for some reason, and to do this I need to wait for the client's command to finish. </p>
  
  <p>I'd appreciate any advice on what I can try to make this work!</p>