我想使用 Mininet 测试数据中心路由算法。流量需要符合某些参数:
- 它应该由各种大小的“文件”组成(请注意,这些文件实际上不一定是文件;在例如 iperf 中生成的流量是可以的,只要大小是可控的);
- 文件大小应取自特定分布;
- 应为给定文件随机选择发送数据的源/目标主机对;
- 文件发送到其后继文件发送的时间间隔应该是随机的;和
- 如果在两台主机之间发送了一个巨大的文件,需要很长时间才能传输,那么它应该仍然可以在网络中的其他主机之间发送数据。
第 1-4 点已处理完毕。几天来我一直在为#5 苦苦挣扎,但我无法让它正常工作。我最初的想法是产生子进程/线程来向主机发送 iperf 命令:
while count < 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))
命令 test_custom_iperf 以 Python Mininet API 的 iperf 版本为模型,包含-n
传输大小参数:
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 )
使这种非阻塞变得非常困难。出于某种原因,我需要能够发送server.sendInt()
命令,为此我需要等待客户端的命令完成。
我会很感激任何关于我可以尝试做什么的建议!