from mininet.net import Mininet
from mininet.node import CPULimitedHost
from mininet.link import TCLink
net = Mininet(host=CPULimitedHost, link=TCLink)
c0 = net.addController()
h1 = net.addHost(‘h1‘, cpu=0.5)
h2 = net.addHost(‘h2‘, cpu=0.5)
h3 = net.addHost(‘h3‘)
h4 = net.addHost(‘h4‘)
s1 = net.addSwitch(‘s1‘)
s2 = net.addSwitch(‘s2‘)
net.addLink(h1, s1, bw=10, delay=‘5ms‘,max_queue_size=1000, loss=10, use_htb=True)
net.addLink(h3, s1)
net.addLink(h2, s2, bw=10, delay=‘5ms‘,max_queue_size=1000, loss=10, use_htb=True)
net.addLink(h4, s2)
net.addLink(s1, s2)
h1.setIP(‘10.0.0.1‘, 24)
h2.setIP(‘10.0.0.2‘, 24)
h3.setIP(‘10.0.0.3‘, 24)
h4.setIP(‘10.0.0.4‘, 24)
net.start()
net.pingAll()
net.stop()
$ nano mytopo.py // 复制 Python 代码到 py 文件中
$ sudo python mytopo.py // 执行 py 文件
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
def IperfTest():
net = Mininet(host=CPULimitedHost, link=TCLink)
c0 = net.addController()
h1 = net.addHost(‘h1‘, cpu=0.5)
h2 = net.addHost(‘h2‘, cpu=0.5)
h3 = net.addHost(‘h3‘)
s1 = net.addSwitch(‘s1‘)
s2 = net.addSwitch(‘s2‘)
s3 = net.addSwitch(‘s3‘)
net.addLink(s1, s2, bw=10, delay=‘5ms‘,max_queue_size=1000, loss=0, use_htb=True)
net.addLink(s2, s3)
net.addLink(s1, h1, bw=10, delay=‘5ms‘,max_queue_size=1000, loss=0, use_htb=True)
net.addLink(s2, h2)
net.addLink(s3, h3)
h1.setIP(‘10.0.0.1‘, 24)
h2.setIP(‘10.0.0.2‘, 24)
h3.setIP(‘10.0.0.3‘, 24)
net.start()
print "Dumping host connections"
dumpNodeConnections(net.hosts)
print "Testing network connectivity"
net.pingAll()
print "Testing bandwidth"
h1, h2, h3 = net.get(‘h1‘, ‘h2‘, ‘h3‘)
net.iperf((h1, h3))
net.iperf((h2, h1))
net.iperf((h2, h3))
net.stop()
if name==‘main‘:
setLogLevel(‘info‘)
IperfTest()
原文:https://www.cnblogs.com/liujiarun/p/13661287.html