Mininet实验 设置带宽之简单性能测试
原文:设置带宽之简单性能测试
这个实验主要还是说明通过python程序来设定Mininet中的链路带宽。
目的:
- Python脚本实现自定义拓扑
- 设置链路的带宽、延迟及丢包率
- iperf测试主机间的带宽性能
实验:
实现一个单个交换机的拓扑,添加一个交换机,和N个主机到网络中。交换机和主机之间的每个链路能够设置带宽、延迟时间、以及丢包率。创建一个包含一个交换机和四个主机的网络,使用iperf测试主机之间的带宽。
拓扑图如下所示:
原文说实验需要两台虚拟机,其实一台装好Mininet的虚拟机即可,实验也很简单。
cd 进mininet目录下(原文是说到/mininet/custom),执行以下命令:
touch mymininet1.py //注意:原文前后python程序名称不一致
vim mymininet.py
修改python文件内容:
#2016/9/29 Created by Wasdns, FZU, SDNLab
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import CPULimitedHost
from mininet.link import TCLink
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel
class SingleSwitchTopo(Topo):
"Single switch connected to n hosts."
def __init__(self, n=2, **opts):
Topo.__init__(self, **opts)
switch = self.addSwitch('s1')
for h in range(n):
#Each host gets 50%/n of system CPU
host = self.addHost('h%s' % (h + 1), cpu=.5/n)
#10 Mbps, 5ms delay, 0% Loss, 1000 packet queue
self.addLink(host, switch, bw=10, delay='5ms', loss=0, max_queue_size=1000, use_htb=True)
def perfTest():
"Create network and run simple performance test"
topo = SingleSwitchTopo(n=4)
net = Mininet(topo=topo,host=CPULimitedHost, link=TCLink)
net.start()
print "Dumping host connections"
dumpNodeConnections(net.hosts)
print "Testing network connectivity"
net.pingAll()
print "Testing bandwidth between h1 and h4"
h1, h4 = net.get('h1', 'h4')
net.iperf((h1, h4))
net.stop()
if __name__=='__main__':
setLogLevel('info')
perfTest()
添加权限:
chmod +x mymininet1.py //这步其实没有那么必要
执行
./mymininet1.py
//或者
python mymininet.py
//都可以
结果:
结论:
主要还是说明下可以用python文件来设置mininet链路的带宽以及丢包率等性能,还有用iperf测试性能。
2016/9/29
To improve is to change, to be perfect is to change often.