Added a RemoteController object

Now you can run a controller on a remote PC that is
not on the same pc as Mininet.
This commit is contained in:
David Erickson
2010-01-01 03:26:58 -08:00
committed by Brandon Heller
parent 540379957b
commit 60d9ead65a
2 changed files with 49 additions and 6 deletions
+12
View File
@@ -16,6 +16,7 @@ except ImportError:
from mininet.logging_mod import lg, set_loglevel, LEVELS from mininet.logging_mod import lg, set_loglevel, LEVELS
from mininet.net import Mininet, init from mininet.net import Mininet, init
from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX
from mininet.node import RemoteController
from mininet.topo import SingleSwitchTopo, LinearTopo from mininet.topo import SingleSwitchTopo, LinearTopo
# built in topologies, created only when run # built in topologies, created only when run
@@ -46,6 +47,7 @@ CONTROLLER_DEF = 'ref'
CONTROLLERS = {'ref' : Controller, CONTROLLERS = {'ref' : Controller,
'nox_dump' : lambda a, b: NOX(a, b, 'packetdump'), 'nox_dump' : lambda a, b: NOX(a, b, 'packetdump'),
'nox_pysw' : lambda a, b: NOX(a, b, 'pyswitch'), 'nox_pysw' : lambda a, b: NOX(a, b, 'pyswitch'),
'remote' : lambda a, b: None,
'none' : lambda a, b: None} 'none' : lambda a, b: None}
# optional tests to run # optional tests to run
@@ -106,6 +108,12 @@ class MininetRunner(object):
opts.add_option('--verbosity', '-v', type = 'choice', opts.add_option('--verbosity', '-v', type = 'choice',
choices = LEVELS.keys(), default = 'info', choices = LEVELS.keys(), default = 'info',
help = '[' + ' '.join(LEVELS.keys()) + ']') help = '[' + ' '.join(LEVELS.keys()) + ']')
opts.add_option('--ip', type = 'string',
help = '[ip address as a dotted decimal string for a'
'remote controller]')
opts.add_option('--port', type = 'string',
help = '[port integer for a listening remote'
' controller]')
self.options = opts.parse_args()[0] self.options = opts.parse_args()[0]
def setup(self): def setup(self):
@@ -132,6 +140,10 @@ class MininetRunner(object):
switch = SWITCHES[self.options.switch] switch = SWITCHES[self.options.switch]
host = HOSTS[self.options.host] host = HOSTS[self.options.host]
controller = CONTROLLERS[self.options.controller] controller = CONTROLLERS[self.options.controller]
if self.options.controller == 'remote':
controller = lambda a, b: RemoteController(a, b,
ip_address = self.options.ip,
port = self.options.port)
controller_params = ControllerParams(0x0a000000, 8) # 10.0.0.0/8 controller_params = ControllerParams(0x0a000000, 8) # 10.0.0.0/8
xterms = self.options.xterms xterms = self.options.xterms
+37 -6
View File
@@ -3,6 +3,7 @@
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
import os, signal, sys, select import os, signal, sys, select
flush = sys.stdout.flush flush = sys.stdout.flush
from mininet.logging_mod import lg from mininet.logging_mod import lg
@@ -36,7 +37,7 @@ class Node(object):
self.pid = self.shell.pid self.pid = self.shell.pid
self.intfCount = 0 self.intfCount = 0
self.intfs = [] # list of interface names, as strings self.intfs = [] # list of interface names, as strings
self.ips = {} self.ips = {} # dict of interfaces to ip addresses as strings
self.connection = {} self.connection = {}
self.waiting = False self.waiting = False
self.execed = False self.execed = False
@@ -186,7 +187,7 @@ class Node(object):
'''Set the IP address for an interface. '''Set the IP address for an interface.
@param intf string, interface name @param intf string, interface name
@param ip IP address as integer @param ip IP address as a string
@param bits @param bits
''' '''
result = self.cmd(['ifconfig', intf, ip + bits, 'up']) result = self.cmd(['ifconfig', intf, ip + bits, 'up'])
@@ -303,7 +304,7 @@ class KernelSwitch(Switch):
self.dp = dp self.dp = dp
self.dpid = dpid self.dpid = dpid
def start(self, ignore): def start(self, controllers):
'''Start up reference kernel datapath.''' '''Start up reference kernel datapath.'''
ofplog = '/tmp/' + self.name + '-ofp.log' ofplog = '/tmp/' + self.name + '-ofp.log'
quietRun('ifconfig lo up') quietRun('ifconfig lo up')
@@ -318,7 +319,8 @@ class KernelSwitch(Switch):
self.cmdPrint('dpctl addif nl:' + str(self.dp) + ' ' + self.cmdPrint('dpctl addif nl:' + str(self.dp) + ' ' +
' '.join(self.intfs)) ' '.join(self.intfs))
# Run protocol daemon # Run protocol daemon
self.cmdPrint('ofprotocol nl:' + str(self.dp) + ' tcp:127.0.0.1 ' + self.cmdPrint('ofprotocol nl:' + str(self.dp) + ' tcp:' +
controllers['c0'].IP()+':'+str(controllers['c0'].port) +
' --fail=closed 1> ' + ofplog + ' 2>' + ofplog + ' &') ' --fail=closed 1> ' + ofplog + ' 2>' + ofplog + ' &')
self.execed = False # XXX until I fix it self.execed = False # XXX until I fix it
@@ -340,10 +342,13 @@ class Controller(Node):
OpenFlow controller.''' OpenFlow controller.'''
def __init__(self, name, inNamespace = False, controller = 'controller', def __init__(self, name, inNamespace = False, controller = 'controller',
cargs = '-v ptcp:', cdir = None): cargs = '-v ptcp:', cdir = None, ip_address="127.0.0.1",
port = 6633):
self.controller = controller self.controller = controller
self.cargs = cargs self.cargs = cargs
self.cdir = cdir self.cdir = cdir
self.ip_address = ip_address
self.port = port
Node.__init__(self, name, inNamespace = inNamespace) Node.__init__(self, name, inNamespace = inNamespace)
def start(self): def start(self):
@@ -363,6 +368,10 @@ class Controller(Node):
self.cmd('kill %' + self.controller) self.cmd('kill %' + self.controller)
self.terminate() self.terminate()
def IP(self):
'''Return IP address of the Controller'''
return self.ip_address
class ControllerParams(object): class ControllerParams(object):
'''Container for controller IP parameters.''' '''Container for controller IP parameters.'''
@@ -395,4 +404,26 @@ class NOX(Controller):
controller = nox_core_dir + '/nox_core', controller = nox_core_dir + '/nox_core',
cargs = '--libdir=/usr/local/lib -v -i ptcp: ' + \ cargs = '--libdir=/usr/local/lib -v -i ptcp: ' + \
' '.join(nox_args), ' '.join(nox_args),
cdir = nox_core_dir, **kwargs) cdir = nox_core_dir, **kwargs)
class RemoteController(Controller):
'''Controller running remotely.'''
def __init__(self, name, inNamespace = False, ip_address = None, port = 6633):
'''Init.
@param name name to give controller
@param ip_address the IP address where the remote controller is
listening
@param port the port where the remote controller is listening
'''
if not ip_address:
raise Exception('please set ip_address\n')
Controller.__init__(self, name, ip_address = ip_address, port = port)
def start(self):
'''Overridden to do nothing.'''
return
def stop(self):
'''Overridden to do nothing.'''
return