MCPcopy Create free account
hub / github.com/mininet/mininet / Controller

Class Controller

mininet/node.py:1416–1492  ·  view source on GitHub ↗

A Controller is a Node that is running (or has execed?) an OpenFlow controller.

Source from the content-addressed store, hash-verified

1414
1415
1416class Controller( Node ):
1417 """A Controller is a Node that is running (or has execed?) an
1418 OpenFlow controller."""
1419
1420 def __init__( self, name, inNamespace=False, command='controller',
1421 cargs='ptcp:%d', cdir=None, ip="127.0.0.1",
1422 port=6653, protocol='tcp', verbose=False, **params ):
1423 self.command = command
1424 self.cargs = cargs
1425 if verbose:
1426 cargs = '-v ' + cargs
1427 self.cdir = cdir
1428 # Accept 'ip:port' syntax as shorthand
1429 if ':' in ip:
1430 ip, port = ip.split( ':' )
1431 port = int( port )
1432 self.ip = ip
1433 self.port = port
1434 self.protocol = protocol
1435 Node.__init__( self, name, inNamespace=inNamespace,
1436 ip=ip, **params )
1437 self.checkListening()
1438
1439 def checkListening( self ):
1440 "Make sure no controllers are running on our port"
1441 # Verify that Telnet is installed first:
1442 out, _err, returnCode = errRun( "which telnet" )
1443 if 'telnet' not in out or returnCode != 0:
1444 raise Exception( "Error running telnet to check for listening "
1445 "controllers; please check that it is "
1446 "installed." )
1447 listening = self.cmd( "echo A | telnet -e A %s %d" %
1448 ( self.ip, self.port ) )
1449 if 'Connected' in listening:
1450 servers = self.cmd( 'netstat -natp' ).split( '\n' )
1451 pstr = ':%d ' % self.port
1452 clist = servers[ 0:1 ] + [ s for s in servers if pstr in s ]
1453 raise Exception( "Please shut down the controller which is"
1454 " running on port %d:\n" % self.port +
1455 '\n'.join( clist ) )
1456
1457 def start( self ):
1458 """Start <controller> <args> on controller.
1459 Log to /tmp/cN.log"""
1460 pathCheck( self.command )
1461 cout = '/tmp/' + self.name + '.log'
1462 if self.cdir is not None:
1463 self.cmd( 'cd ' + self.cdir )
1464 self.cmd( self.command + ' ' + self.cargs % self.port +
1465 ' 1>' + cout + ' 2>' + cout + ' &' )
1466 self.execed = False
1467
1468 # pylint: disable=arguments-differ,signature-differs
1469 def stop( self, *args, **kwargs ):
1470 "Stop controller."
1471 self.cmd( 'kill %' + self.command )
1472 self.cmd( 'wait %' + self.command )
1473 super( Controller, self ).stop( *args, **kwargs )

Callers 2

ClusterControllerFunction · 0.90
controllers.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected