在Ubuntu系统的home目录下创建一个目录,目录命名为学号
在创建的目录下,完成Mininet的源码安装。
使用Mininet可视化工具,生成下图所示的拓扑,并保存拓扑文件名为学号.py
使用Mininet的命令行生成如下拓扑:
在4 b)的基础上,在Mininet交互界面上新增1台主机并且连接到交换机上,再测试新拓扑的连通性
编辑(一)中第3步保存的Python脚本,添加如下网络性能限制,生成拓扑:
代码如下
# !/usr/bin/python import json from mininet.topo import Topo from mininet.net import Mininet from mininet.node import CPULimitedHost,RemoteController from mininet.link import TCLink from mininet.util import dumpNodeConnections from mininet.log import setLogLevel from mininet.cli import CLI class myTopo(Topo): def __init__(self): Topo.__init__(self) L1=2 L2=4 L3=8 a = [] b = [] c = [] # L1 for i in range(L1): switch = self.addSwitch('s{}'.format(i+1)) a.append(switch) #L2 for i in range(L2): switch = self.addSwitch('s{}'.format(i+1+L1)) b.append(switch) #L3 for i in range(L3): switch = self.addSwitch('s{}'.format(i+1+L2+L1)) c.append(switch) # link l1 and l2 #for i in range(L1): # sw1 = a[i] # for j in range(L2): # sw2 = b[j] # self.addLink(sw1,sw2) for i in range(L1): sw1 = a[i] for sw2 in b[i/2::L1/2]: self.addLink(sw2, sw1) for i in range(L1): sw1=a[i] for j in range(L2): sw2=b[j] self.addLink(sw1,sw2) # link L2 and L3 for i in range(0,L2,2): for sw1 in b[i:i+2]: for sw2 in c[i:i+2]: self.addLink(sw2,sw1) num=1 for sw1 in c: for i in range(2): host = self.addHost( 'h{}'.format(num) ) self.addLink(sw1,host) num+=1 def create_network(): #"Create network and run simple performance test" topo = myTopo() net = Mininet(topo=topo,host=CPULimitedHost, link=TCLink) net.start() CLI(net) net.stop() if __name__ == '__main__': setLogLevel('info') create_network()
实验结果如图所示: