iperfmulti命令添加
通常在我们使用mininet做数据中心带宽实验时需要用到iperfmulti命令实现多对多的流量测试,由于mininet的iperf只支持做一对一流量测试,因此我们需要自己自定义命令来实现。
在添加自定义命令时也看到了各位博主的操作方法,因为安装mininet有源码安装和使用pip安装两种方法,因此对于需要修改文件位置不一定相同,需要自行查找文件的具体位置,我总结了一下两种安装方式的配置文件位置分享给大家,方便大家找到。
第一种:源码安装
修改mininet/net.py #添加我们要实现自定义命令的代码
修改mininet/cli.py #注册命令
修改bin/mn #加入到可执行文件中
重新安装Mininet核心文件: ~/mininet/util/install.sh -n
第二种:pip安装
修改/usr/local/lib/python2.7/dist-packages/mininet/net.py #添加我们要实现自定义命令的代码
修改/usr/local/lib/python2.7/dist-packages/mininet/cli.py #注册命令
修改/usr/local/bin/mn #加入到可执行文件中
本人测试貌似不需要重新安装啥的,直接可用
如何添加
接下来详细说明一下需要修改的内容:(以pip安装的mininet为例)
打开net.py,找个位置添加以下代码
#注意添加代码后自行检查缩进是否正确,python代码对代码格式严格要求,否则会报错
def iperf_single( self,hosts=None, udpBw='10M', period=60, port=5001):
"""Run iperf between two hosts using UDP.
hosts: list of hosts; if None, uses opposite hosts
returns: results two-element array of server and client speeds
"""
if not hosts:
return
else:
assert len( hosts ) == 2
client, server = hosts
filename = client.name[1:] + '.out'
output( '*** Iperf: testing bandwidth between ' )
output( "%s and %s\n" % ( client.name, server.name ) )
iperfArgs = 'iperf -u '
bwArgs = '-b ' + udpBw + ' '
print "***start server***"
server.cmd( iperfArgs + '-s -i 1' + ' > /home/smyyy/temp_log/' + filename + '&')
print "***start client***"
client.cmd(
iperfArgs + '-t '+ str(period) + ' -c ' + server.IP() + ' ' + bwArgs
+' > /home/smyyy/temp_log/' + 'client' + filename +'&')
def iperfMulti(self, bw, period=60):
base_port = 5001
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)
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=bw, period= period, port=base_port)
sleep(.05)
base_port += 1
sleep(period)
print("test has done")
打开cli.py,添加以下代码
def do_iperfmulti( self, line ):
"""
Multi iperf UDP test between nodes
"""
args = line.split()
if len(args) == 1:
udpBw = args[0]
self.mn.iperfMulti(udpBw)
elif len(args) == 2:
udpBw = args[0]
period = args[1]
self.mn.iperfMulti(udpBw,float(period))
else:
error( 'invalid number of args: iperfMulti udpBw period\n '+
'udpBw examples:1M 120\n' )
修改bin/mn,添加下面红色框起来的命令
添加好之后就可以使用啦!!!亲测没问题的
使用源码安装的方法比这个多了一步,笔者因为还没有使源码过,也是看别的大神的操作,后期再做测试