使用Mininet建立Topo
Python腳本實作建立拓撲
#coding:utf-
from mininet.net import Mininet
from mininet.topo import LinearTopo
# 四個交換機每個下邊挂載一個主機
Linear4 = LinearTopo(k=)
net = Mininet(topo=Linear4)
net.start()
net.pingAll()
net.stop()
# single,
from mininet.topo import SingleSwitchTopo
Single3 = SingleSwitchTopo(k=)
net = Mininet(topo=Single3)
net.start()
net.pingAll()
net.stop()
# tree,depth=,fanout=
from mininet.topolib import TreeTopo
Tree22 = TreeTopo(depth=, fanout=)
net = Mininet(topo=Tree22)
net.start()
net.pingAll()
net.stop()
# create switch, host,set hosts IP
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 address in interfaces
h0.setIP('...', )
h1.setIP('...', )
net.start()
net.pingAll()
net.stop()
# add more limits to the host
from mininet.net import Mininet
from mininet.node import CPULimitedHost
from mininet.link import TCLink
net = Mininet(host=CPULimitedHost, link=TCLink)
# Creating nodes in the network
c0 = net.addController()
s0 = net.addSwitch('s0')
h0 = net.addHost('h0')
h1 = net.addHost('h1', cpu=.)
h2 = net.addHost('h2', cpu=.)
net.addLink(s0, h0, bw=, delay='ms',max_queue_size=, loss=, use_htb=True)
net.addLink(s0, h1)
net.addLink(s0, h2)
net.start()
net.pingAll()
net.stop()
指令行建立topo
互動模式
# sudo mn
mininet>py net.addHost('h3')
mininet>py net.addLink(s1, net.get('h3'))
mininet>py s1.attach('s1-eth3')
mininet>py net.get('h3').cmd('ifconfig h3-eth0 10.3')
mininet>h1 ping -c1
mininet>px from mininet.util import dumpNodeConnections
mininet>py dumpNodeConnections(net.hosts)
mininet>py net.pingAll()