辍耕录 2018-05-18
本实验是基于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()函数所定义的基本一致。