簡(jiǎn)介
本實(shí)驗(yàn)是基于pox搭建簡(jiǎn)單的網(wǎng)絡(luò)并測(cè)試網(wǎng)絡(luò)的連通性碱璃,利用mininet代碼創(chuàng)建一個(gè)交換機(jī)四個(gè)主機(jī)的拓?fù)浣俨啵瑴y(cè)試各主機(jī)之間的連通性以及h1惭蹂、h4之間的帶寬挪捕。
代碼
實(shí)驗(yàn)代碼如下所示,SingleSwitchTopo類負(fù)責(zé)創(chuàng)建拓?fù)淦纯玻琻個(gè)主機(jī)連接一個(gè)交換機(jī)浮毯,每個(gè)主機(jī)的CPU占50%/n,鏈路性能參數(shù)分別是“bw=10泰鸡、delay='5ms'债蓝、loss=0、max_queue_size=1000”盛龄。
perfTest函數(shù)實(shí)現(xiàn)了主要功能饰迹,首先創(chuàng)建4個(gè)主機(jī)1個(gè)交換機(jī)的拓?fù)洌瑔?dòng)控制器余舶、交換機(jī)后用pingall測(cè)試鏈路連通性啊鸭,用iperf測(cè)試h1、h4之間的帶寬匿值,最后關(guān)閉控制器交換機(jī)和主機(jī)赠制。
具體代碼如下所示:
#!/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()
實(shí)驗(yàn)結(jié)果
實(shí)驗(yàn)結(jié)果如下所示,本實(shí)驗(yàn)利用mininet的代碼實(shí)現(xiàn)一些基本操作挟憔。實(shí)驗(yàn)結(jié)果與perfTest()函數(shù)所定義的基本一致钟些。