步骤1:命令行创建拓扑
s1
s2 s3
h1 h2 h3 h4
步骤2:交互式界面创建主机、交换机等
步骤3:python搭建拓扑
--topo linear,4
from mininet.net import Mininet
from mininet.topo import LinearTopo
Linear4 = LinearTopo(k=4) #四个交换机,分别下挂一个主机
net = Mininet(topo=Linear4)
net.start()
net.pingAll()
net.stop()
--topo single,3
from mininet.net import Mininet
from mininet.topo import SingleSwitchTopo
Single3 = SingleSwitchTopo(k=3) #一个交换机下挂3个主机
net = Mininet(topo=Single3)
net.start()
net.pingAll()
net.stop()
--topo tree,depth=2,fanout=2
from mininet.net import Mininet
from mininet.topolib import TreeTopo
Tree22 = TreeTopo(depth=2,fanout=2)
net = Mininet(topo=Tree22)
net.start()
net.pingAll()
net.stop()
非以上三种topu
from mininet.net import Mininet
net = Mininet()
# Creating nodes in the network.
c0 = net.addController()
h0 = net.addHost('h0')
s0 = net.addSwitch('s0')
h1 = net.addHost('h1')
# Creating links between nodes in network
net.addLink(h0, s0)
net.addLink(h1, s0)
# Configuration of IP addresses in interfaces
h0.setIP('192.168.1.1', 24)
h1.setIP('192.168.1.2', 24)
net.start()
net.pingAll()
net.stop()
性能限制
from mininet.net import Mininet
from mininet.node import CPULimitedHost
from mininet.link import TCLink
net = Mininet(host=CPULimitedHost, link=TCLink)
c0 = net.addController()
s0 = net.addSwitch('s0')
h0 = net.addHost('h0')
h1 = net.addHost('h1', cpu=0.5)
h2 = net.addHost('h1', cpu=0.5)
net.addLink(s0, h0, bw=10, delay='5ms', max_queue_size=1000, loss=10, use_htb=True)
net.addLink(s0, h1)
net.addLink(s0, h2)
net.start()
net.pingAll()
net.stop()