以下是mininet多控制器網(wǎng)絡(luò)運行腳本,是根據(jù)mininet提供的example中controllers.py改寫的。


from mininet.net import Mininet
from mininet.node import OVSSwitch, Controller, RemoteController
from mininet.topolib import TreeTopo
from mininet.log import setLogLevel
from mininet.cli import CLI????????
setLogLevel( 'info' )
# Two local and one "external" controller (which is actually c0)
# Ignore the warning message that the remote isn't (yet) running
c0 = RemoteController( 'c0', ip='10.108.48.160')
c1 = RemoteController( 'c1', ip='10.108.50.78')
c2 = RemoteController( 'c2', ip='10.108.48.240' )
cmap = { 's1': c0, 's2': c1, 's1': c2, 's3':c1 }
class MultiSwitch( OVSSwitch ):
? ? "Custom Switch() subclass that connects to different controllers"
? ? def start( self, controllers ):
? ? ? ? return OVSSwitch.start( self, [ cmap[ self.name ] ] )
topo = TreeTopo( depth=2, fanout=2 )
net = Mininet( topo=topo, switch=MultiSwitch, build=False )
for c in [ c1, c2? ]:
? ? net.addController(c)
net.build()
net.start()
CLI( net )
net.stop()