restructured defaultController into a function

This commit is contained in:
Cody Burkard
2014-07-15 15:48:18 -07:00
parent a19cc91537
commit 5ac3cde2bd
2 changed files with 16 additions and 13 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ from mininet.cli import CLI
from mininet.log import lg, LEVELS, info, debug, error
from mininet.net import Mininet, MininetWithControlNet, VERSION
from mininet.node import ( Host, CPULimitedHost, Controller, OVSController,
NOX, RemoteController, DefaultController, UserSwitch, OVSKernelSwitch,
NOX, DefaultController, RemoteController, UserSwitch, OVSKernelSwitch,
OVSLegacyKernelSwitch, IVSSwitch )
from mininet.link import Link, TCLink
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
+15 -12
View File
@@ -1277,23 +1277,19 @@ class Controller( Node ):
return '<%s %s: %s:%s pid=%s> ' % (
self.__class__.__name__, self.name,
self.IP(), self.port, self.pid )
class DefaultController( Controller ):
"find any controller that is available and run it"
def __init__( self, name, **kwargs ):
"search for any installed controller"
controllers = [ 'controller', 'ovs-controller',
'test-controller' ]
for c in controllers:
if quietRun( "which " + c ):
Controller.__init__( self, name, command=c, **kwargs )
break
@classmethod
def isAvailable( self ):
return quietRun( 'which controller' )
class OVSController( Controller ):
"Open vSwitch controller"
def __init__( self, name, command='ovs-controller', **kwargs ):
if quietRun( 'which test-controller' ):
command = 'test-controller'
Controller.__init__( self, name, command=command, **kwargs )
@classmethod
def isAvailable( self ):
return quietRun( 'which ovs-controller' ) or quietRun( 'which test-controller' )
class NOX( Controller ):
"Controller to run a NOX application."
@@ -1348,3 +1344,10 @@ class RemoteController( Controller ):
if 'Connected' not in listening:
warn( "Unable to contact the remote controller"
" at %s:%d\n" % ( self.ip, self.port ) )
def DefaultController( name, order=[ Controller, OVSController ], **kwargs ):
"find a default controller for mininet"
for controller in order:
if controller.isAvailable():
return controller( name, **kwargs )