Mininet簡單性能測試


建一個簡單的模型,使用一個單交換機,然后鏈接n個主機形成拓撲,然后對每個鏈路設置帶寬,延遲時間,和丟包率。

這里就選擇建一個單交換機和六個主機的作為例子。

創建py腳本生成拓撲:寫一個類生成一個單交換機和六個主機的拓撲,並且給每個主機和交換機之間的連接賦予100m的帶寬,5ms的延遲和1%的丟包率。然后通過pingall函數測試連接,iperf函數測試主機間的帶寬,

 1 from mininet.topo import Topo
 2 from mininet.net import Mininet
 3 from mininet.node import CPULimitedHost
 4 from mininet.link import TCLink
 5 from mininet.util import dumpNodeConnections
 6 from mininet.log import setLogLevel
 7 
 8 
 9 class SingleSwitchTopo(Topo):
10     def __init__(self, n=2, **opts):
11         Topo.__init__(self, **opts)
12         switch = self.addSwitch('s1')
13         for h in range(n):
14             # Each host gets 50%/n of system CPU
15             host = self.addHost('h%s' % (h + 1), cpu=.5/n)
16             # 100 Mbps, 5ms delay, 1% Loss, 1000 packet queue
17             self.addLink(host, switch, bw=100, delay='5ms', loss=1,
18                          max_queue_size=1000, use_htb=True)
19 
20 
21 def perfTest():
22     topo = SingleSwitchTopo(n=6)
23     net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink)
24     net.start()
25     print "Dumping host connections"
26     dumpNodeConnections(net.hosts)
27     print "Testing network connectivity"
28     net.pingAll()
29     print "Testing bandwidth between h1 and h4"
30     h1, h4 = net.get('h1', 'h4')
31     net.iperf((h1, h4))
32     print "Testing bandwidth between h1 and h6"
33     h1, h6 = net.get('h1', 'h6')
34     net.iperf((h1, h6))
35     net.stop()
36 
37 
38 if __name__ == '__main__':
39     setLogLevel('info')
40     perfTest()

 

  

ps:如果直接執行出現錯誤找不到py解釋器的話,在代碼開頭加上#!/usr/bin/python。或者直接使用

1 sudo python 文件名.py

 

 執行

結果如下圖所示:


瞎搞一波,再試試兩個交換機相互連接,然后分別下掛三個主機。link全部賦予10m帶寬,5ms延遲和0%的丟包率。

 1 from mininet.topo import Topo
 2 from mininet.net import Mininet
 3 from mininet.node import CPULimitedHost
 4 from mininet.link import TCLink
 5 from mininet.util import dumpNodeConnections
 6 from mininet.log import setLogLevel
 7 
 8 
 9 class DoubleSwitchTopo(Topo):
10     def __init__(self, n=2, **opts):
11         Topo.__init__(self, **opts)
12         switch1 = self.addSwitch('s1')
13         switch2 = self.addSwitch("s2")
14         self.addLink(switch1, switch2, bw=10, delay='5ms',
15                      loss=0, max_queue_size=1000, use_htb=True)
16         for h in range(n/2):
17             host = self.addHost('h%s' % (h + 1), cpu=.5/n)
18             self.addLink(host, switch1, bw=10, delay='5ms', loss=0,
19                          max_queue_size=1000, use_htb=True)
20         for h in range(n/2, n):
21             host = self.addHost('h%s' % (h + 1), cpu=.5/n)
22             self.addLink(host, switch2, bw=10, delay='5ms', loss=0,
23                          max_queue_size=1000, use_htb=True)
24 
25 
26 def perfTest():
27     topo = DoubleSwitchTopo(n=6)
28     net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink)
29     net.start()
30     print "Dumping host connections"
31     dumpNodeConnections(net.hosts)
32     print "Testing network connectivity"
33     net.pingAll()
34     print "Testing bandwidth between h1 and h3"
35     h1, h3 = net.get('h1', 'h3')
36     net.iperf((h1, h3))
37     print "Testing bandwidth between h4 and h6"
38     h4, h6 = net.get('h4', 'h6')
39     net.iperf((h4, h6))
40     net.stop()
41 
42 
43 if __name__ == '__main__':
44     setLogLevel('info')
45     perfTest()

 

 

結果如下圖:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM