簡介
本實驗是基于pox搭建簡單的網絡并測試網絡的連通性,利用mininet代碼創建一個交換機四個主機的拓撲,測試各主機之間的連通性以及h1、h4之間的帶寬。
代碼
實驗代碼如下所示,SingleSwitchTopo類負責創建拓撲,n個主機連接一個交換機,每個主機的CPU占50%/n,鏈路性能參數分別是“bw=10、delay='5ms'、loss=0、max_queue_size=1000”。
perfTest函數實現了主要功能,首先創建4個主機1個交換機的拓撲,啟動控制器、交換機后用pingall測試鏈路連通性,用iperf測試h1、h4之間的帶寬,最后關閉控制器交換機和主機。
具體代碼如下所示:
#!/usr/bin/python
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()
實驗結果
實驗結果如下所示,本實驗利用mininet的代碼實現一些基本操作。實驗結果與perfTest()函數所定義的基本一致。
實驗結果