在mininet API中使用iperf生成连续流量

时间:2019-03-04 01:21:34

标签: python-2.7 mininet iperf

我已经创建了一个小型网络拓扑,我想使用iperf在仿真主机内发送恒定流量。由于此环境设置用于实验,因此我希望连续至少产生一分钟的流量。目前,它运行了整整一轮,但我希望它可以迭代一分钟。

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.log import setLogLevel
from mininet.topo import Topo
from mininet import cli
from mininet.clean import Cleanup
from mininet.node import CPULimitedHost
from mininet.node import OVSKernelSwitch, Controller, RemoteController, OVSSwitch
from mininet.link import TCLink
from mininet.util import irange,dumpNodeConnections
from mininet.topolib import TreeTopo
from datetime import datetime
import subprocess
import os
import thread
import threading
import time


class LinearTopo(Topo):
   "Linear topology of k switches, with one host per switch."

   def __init__(self, k=3, **opts):
       """Init.
           k: number of switches (and hosts)
           hconf: host configuration options
           lconf: link configuration options"""

       super(LinearTopo, self).__init__(**opts)

       self.k = k

       lastSwitch = None
       for i in irange(1, k):
           host = self.addHost('h%s' % i)
           switch = self.addSwitch('s%s' % i)
           self.addLink( host, switch)
           if lastSwitch:
               self.addLink( switch, lastSwitch,delay='10ms')
           lastSwitch = switch

#creates traffic between switches

def iperf_thread( threadName, net ):

 for i in range(0,3):

     for j in range(0,3):
         if(i == j):
             continue
         else:
             result = net.iperf([net.switches[i],net.switches[j]],seconds=2)


def simpleTest():
   "Create and test a simple network"
   topo = LinearTopo(k=3)
   net = Mininet(topo, controller=RemoteController,link=TCLink,switch=OVSSwitch)
   c1 = net.addController(name = 'Floodlight', controller = RemoteController, defaultIP='10.0.2.15', port=6653)
   net.start()
   time.sleep(10)


   print "Dumping host connections"
   dumpNodeConnections(net.hosts)
   print "Testing network connectivity"
   net.pingAll()
   t = threading.Thread(target=iperf_thread, args=(iperf_thread, net,))
   t.start()
   t.setDaemon = True
   t.join()
   net.pingAll()





if __name__ == '__main__':
   # Tell mininet to print useful information
   setLogLevel('info')
   simpleTest()

result of this code

0 个答案:

没有答案