這個實驗主要仍是說明經過python程序來設定Mininet中的鏈路帶寬。html
目的:node
實現一個單個交換機的拓撲,添加一個交換機,和N個主機到網絡中。交換機和主機之間的每一個鏈路可以設置帶寬、延遲時間、以及丟包率。建立一個包含一個交換機和四個主機的網絡,使用iperf測試主機之間的帶寬。
拓撲圖以下所示:
python
原文說實驗須要兩臺虛擬機,其實一臺裝好Mininet的虛擬機便可,實驗也很簡單。
cd 進mininet目錄下(原文是說到/mininet/custom),執行如下命令:vim
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 //均可以
結果:
.net
主要仍是說明下能夠用python文件來設置mininet鏈路的帶寬以及丟包率等性能,還有用iperf測試性能。code
2016/9/29orm