mininet 如何建立有不一样带宽的链路

被问道如何在mininet中建立一个有不一样带宽的链路的时候,因而我就总结了一下我知道的方法:node

在总结的时候,分别参考了以下的网址:python

https://github.com/mininet/mininet/wiki/Introduction-to-Mininetgit

http://stackoverflow.com/questions/30496161/how-to-set-bandwidth-on-mininet-custom-topologygithub


 

 

我总结的方法有如下的三种:网络

第一种,在建立的网络拓扑的时候,使用 --link 这个选项:app

sudo mn --topo linear,10 --link tc,bw=10

这一条命令,就能够建立出一个拓扑是线性的,而且每一条链接都是10m的带宽。ui

这种建立的方法就是很简单,可是不可以模拟一种状况,不一样的链路的带宽不一样。对与作网络均衡负载的同窗,就不可以适用spa

 

第二种,适用 python 脚原本进行建立一个 mininet网络。 使用这种脚本的方法是 python <your_mininet_creation_script.py> 就会建立出一个mininet的拓扑出来了。这种方法,若是要链接外部的控制器的时候,或许也要在里面写,或许也能够在mn的命令行中设置。我那时候在里面进行链接外部控制器的时候,老是出错,就没有继续用这种方式。我没有试过在脚本里面建立拓扑,而后在命令行中链接外部控制器这种状况。.net

下面附上这种脚本的一个范例,取自于 https://github.com/mininet/mininet/wiki/Introduction-to-Mininet命令行

#!/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 build( self, n=2 ):
    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, 2% loss, 1000 packet queue
        self.addLink( host, switch, bw=10, delay='5ms', loss=2,
                          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 walkthrough 中的建立拓扑的方法:脚本的适用方法是

sudo mn --custom <your_mininet_topo_creation_script.py> --topo <topo_class_in_your_script>

可是直接在你的脚本中添加语句

self.addLink( host, switch, bw=10, delay='5ms', loss=2, max_queue_size=1000, use_htb=True )

会致使出现没有 bw 这个参数的错误。这是由于没有适用 TCLink class。解决的方法,是在

http://stackoverflow.com/questions/30496161/how-to-set-bandwidth-on-mininet-custom-topology

中获得的启示。只要运行的时候,加上 --link 选项就能够,完整的运行的命令是

sudo mn --custom <your_mininet_topo_creation_script.py> --topo <topo_class_in_your_script> --link tc

 

OK, That is the end. Happy hacking.

相关文章
相关标签/搜索