在mininet中增加新功能主要分为3步:
1. 修改net.py增加函数实体;
2. 修改cli.py,增加对应do_function函数,用于命令解析;
3. 修改mn函数,用于声明命令。
net.py和cli.py文件均在mininet/mininet目录,mn文件在在mininet/bin目录下.
修改cli.py
def do_iperfmulti( self, line ): args=line.split() if len(args) == 1: udpBw = args[ 0 ] self.mn.iperfMulti(udpBw) elif len(args)== 2: udpBw = args[ 0 ] period = args[ 1 ] err = False self.mn.iperfMulti(udpBw,int(period)) else: error('invalid number of args: iperfmulti udpBw \n' +'udpBw examples: 1M\n')
修改net.py
def iperfMulti( self, load, period=5): ""Multi iperf UDP test between nodes""" base_port = 5001 #output(load) server_list = [] client_list = [h for h in self.hosts] host_list = [] host_list = [h for h in self.hosts] cli_outs = [] ser_outs = [] _len = len(host_list) #output(_len) for i in xrange(0, _len): client = host_list[i] server = client while( server == client ): server = random.choice(host_list) server_list.append(server) self.iperf_single(hosts = [client, server], udpBw=load, period=period, port=base_port) sleep(.05) base_port += 1 sleep(period)
def iperf_single( self,hosts=None, udpBw=5, period=5, port=5001): """""" if not hosts: return else: assert len( hosts ) == 2 client, server = hosts filename = client.name+'.out' filenameserver = server.name+'.out' delayname = client.name+'-'+server.name+'.delay' output( '***testing bandwidth between ' ) output( "%s and %s\n" % ( client.name, server.name ) ) iperfArgs = 'iperf -u' print "****start server******" server.cmd( iperfArgs + '-s' + ' >> /home/zhao/log/' + 'server-'+filenameserver + '&') print "****start client******" client.cmd(iperfArgs + '-t ' + str(period) + ' -c ' + server.IP() + ' -b '+str(udpBw)+'M'+ ' >> /home/zhao/log/'+ 'client-' + filename +'&')
修改mn
TESTS = [ 'cli', 'build', 'pingall', 'pingpair', 'iperf', 'all', 'iperfudp', 'none', 'iperfmulti' ]ALTSPELLING = { 'pingall': 'pingAll', 'pingpair': 'pingPair', 'iperfudp': 'iperfUdp', 'iperfUDP': 'iperfUdp', 'iperfmulti': 'iperfmulti' }
输入以下命令重新编译安装mininet core
sudo ./mininet/util/install.sh -n
重启mininet,输入iperf,可使用table补全iperfmulti,从而可使用iperfmulti进行测试