a) h1的cpu最高不超过50%;
b) h1和s1之间的链路带宽为10,延迟为5ms,最大队列大小为1000,损耗率50。
代码详情:
#!/usr/bin/env python from mininet.net import Mininet from mininet.node import Controller, RemoteController, OVSController from mininet.node import CPULimitedHost, Host, Node from mininet.node import OVSKernelSwitch, UserSwitch from mininet.node import IVSSwitch from mininet.cli import CLI from mininet.log import setLogLevel, info from mininet.link import TCLink, Intf from subprocess import call def myNetwork(): net = Mininet( topo=None, build=False, ipBase='10.0.0.0/8') info( '*** Adding controller\n' ) c0=net.addController(name='c0', controller=Controller, protocol='tcp', port=6633) info( '*** Add switches\n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch) s2 = net.addSwitch('s2', cls=OVSKernelSwitch) info( '*** Add hosts\n') h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None, cpu=0.5) h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None) h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None) h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None) info( '*** Add links\n') net.addLink(s1, s2) net.addLink(h1, s1, bw=10, delay='5ms', max_queue_size=1000, loss=50, use_htb=True) net.addLink(h2, s1) net.addLink(h3, s2) net.addLink(s2, h4) info( '*** Starting network\n') net.build() info( '*** Starting controllers\n') for controller in net.controllers: controller.start() info( '*** Starting switches\n') net.get('s1').start([c0]) net.get('s2').start([c0]) info( '*** Post configure switches and hosts\n') CLI(net) net.stop() if __name__ == '__main__': setLogLevel( 'info' ) myNetwork()
运行结果:
编写Python脚本,生成数据中心网络拓扑
代码详情:
#!/usr/bin/python from mininet.topo import Topo from mininet.net import Mininet from mininet.node import RemoteController,CPULimitedHost from mininet.link import TCLink from mininet.util import dumpNodeConnections class MyTopo( Topo ): def __init__( self ): Topo.__init__( self ) L1 = 2 L2 = L1 * 2 L3 = L2 * 2 c = [] a = [] e = [] for i in range( L1 ): sw = self.addSwitch( 'c{}'.format( i + 1 ) ) c.append( sw ) for i in range( L2 ): sw = self.addSwitch( 'a{}'.format( L1 + i + 1 ) ) a.append( sw ) for i in range( L3 ): sw = self.addSwitch( 'e{}'.format( L1 + L2 + i + 1 ) ) e.append( sw ) for i in range( L1 ): sw1 = c[i] for sw2 in a[i//2::L1//2]: self.addLink( sw2, sw1 ) for i in range( 0, L2, 2 ): for sw1 in a[i:i+2]: for sw2 in e[i:i+2]: self.addLink( sw2, sw1 ) count = 1 for sw1 in e: for i in range(2): host = self.addHost( 'h{}'.format( count ) ) self.addLink( sw1, host ) count += 1 topos = { 'mytopo': ( lambda: MyTopo() ) }
运行结果:
1.本次实验难度体感一般,在对于拓扑有基本了解的情况下实验进行较为容易。整个实验内容理解难度较小且循序渐进,相关代码的应用简单,较废心力倒在于为相关环境不兼容等问题需求合适的解决方法。
2.在实验一开始无法使用可视化工具生成拓扑,发现是python的链接出现问题,通过ls python*查找,再删除原链接后再建新链接后问题得到解决。
3.在进阶要求中,一开始是复制并修改代码,其中一行代码报错是因为python版本不同,后将‘/’改为‘//’则代码得以实现。