Skip to content
Snippets Groups Projects
Commit 5ac3cde2 authored by Cody Burkard's avatar Cody Burkard
Browse files

restructured defaultController into a function

parent a19cc915
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ from mininet.cli import CLI ...@@ -25,7 +25,7 @@ from mininet.cli import CLI
from mininet.log import lg, LEVELS, info, debug, error from mininet.log import lg, LEVELS, info, debug, error
from mininet.net import Mininet, MininetWithControlNet, VERSION from mininet.net import Mininet, MininetWithControlNet, VERSION
from mininet.node import ( Host, CPULimitedHost, Controller, OVSController, from mininet.node import ( Host, CPULimitedHost, Controller, OVSController,
NOX, RemoteController, DefaultController, UserSwitch, OVSKernelSwitch, NOX, DefaultController, RemoteController, UserSwitch, OVSKernelSwitch,
OVSLegacyKernelSwitch, IVSSwitch ) OVSLegacyKernelSwitch, IVSSwitch )
from mininet.link import Link, TCLink from mininet.link import Link, TCLink
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
......
...@@ -1277,23 +1277,19 @@ def __repr__( self ): ...@@ -1277,23 +1277,19 @@ def __repr__( self ):
return '<%s %s: %s:%s pid=%s> ' % ( return '<%s %s: %s:%s pid=%s> ' % (
self.__class__.__name__, self.name, self.__class__.__name__, self.name,
self.IP(), self.port, self.pid ) self.IP(), self.port, self.pid )
@classmethod
class DefaultController( Controller ): def isAvailable( self ):
"find any controller that is available and run it" return quietRun( 'which controller' )
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
class OVSController( Controller ): class OVSController( Controller ):
"Open vSwitch controller" "Open vSwitch controller"
def __init__( self, name, command='ovs-controller', **kwargs ): def __init__( self, name, command='ovs-controller', **kwargs ):
if quietRun( 'which test-controller' ):
command = 'test-controller'
Controller.__init__( self, name, command=command, **kwargs ) Controller.__init__( self, name, command=command, **kwargs )
@classmethod
def isAvailable( self ):
return quietRun( 'which ovs-controller' ) or quietRun( 'which test-controller' )
class NOX( Controller ): class NOX( Controller ):
"Controller to run a NOX application." "Controller to run a NOX application."
...@@ -1348,3 +1344,10 @@ def checkListening( self ): ...@@ -1348,3 +1344,10 @@ def checkListening( self ):
if 'Connected' not in listening: if 'Connected' not in listening:
warn( "Unable to contact the remote controller" warn( "Unable to contact the remote controller"
" at %s:%d\n" % ( self.ip, self.port ) ) " 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 )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment