Skip to content
Snippets Groups Projects
Commit 60d9ead6 authored by David Erickson's avatar David Erickson Committed by Brandon Heller
Browse files

Added a RemoteController object

Now you can run a controller on a remote PC that is
not on the same pc as Mininet.
parent 54037995
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@
from mininet.logging_mod import lg, set_loglevel, LEVELS
from mininet.net import Mininet, init
from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX
from mininet.node import RemoteController
from mininet.topo import SingleSwitchTopo, LinearTopo
# built in topologies, created only when run
......@@ -46,6 +47,7 @@
CONTROLLERS = {'ref' : Controller,
'nox_dump' : lambda a, b: NOX(a, b, 'packetdump'),
'nox_pysw' : lambda a, b: NOX(a, b, 'pyswitch'),
'remote' : lambda a, b: None,
'none' : lambda a, b: None}
# optional tests to run
......@@ -106,6 +108,12 @@ def parse_args(self):
opts.add_option('--verbosity', '-v', type = 'choice',
choices = LEVELS.keys(), default = 'info',
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]
def setup(self):
......@@ -132,6 +140,10 @@ def begin(self):
switch = SWITCHES[self.options.switch]
host = HOSTS[self.options.host]
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
xterms = self.options.xterms
......
......@@ -3,6 +3,7 @@
from subprocess import Popen, PIPE, STDOUT
import os, signal, sys, select
flush = sys.stdout.flush
from mininet.logging_mod import lg
......@@ -36,7 +37,7 @@ def __init__(self, name, inNamespace = True):
self.pid = self.shell.pid
self.intfCount = 0
self.intfs = [] # list of interface names, as strings
self.ips = {}
self.ips = {} # dict of interfaces to ip addresses as strings
self.connection = {}
self.waiting = False
self.execed = False
......@@ -186,7 +187,7 @@ def setIP(self, intf, ip, bits):
'''Set the IP address for an interface.
@param intf string, interface name
@param ip IP address as integer
@param ip IP address as a string
@param bits
'''
result = self.cmd(['ifconfig', intf, ip + bits, 'up'])
......@@ -303,7 +304,7 @@ def __init__(self, name, dp = None, dpid = None):
self.dp = dp
self.dpid = dpid
def start(self, ignore):
def start(self, controllers):
'''Start up reference kernel datapath.'''
ofplog = '/tmp/' + self.name + '-ofp.log'
quietRun('ifconfig lo up')
......@@ -318,7 +319,8 @@ def start(self, ignore):
self.cmdPrint('dpctl addif nl:' + str(self.dp) + ' ' +
' '.join(self.intfs))
# 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 + ' &')
self.execed = False # XXX until I fix it
......@@ -340,10 +342,13 @@ class Controller(Node):
OpenFlow 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.cargs = cargs
self.cdir = cdir
self.ip_address = ip_address
self.port = port
Node.__init__(self, name, inNamespace = inNamespace)
def start(self):
......@@ -363,6 +368,10 @@ def stop(self):
self.cmd('kill %' + self.controller)
self.terminate()
def IP(self):
'''Return IP address of the Controller'''
return self.ip_address
class ControllerParams(object):
'''Container for controller IP parameters.'''
......@@ -395,4 +404,26 @@ def __init__(self, name, inNamespace = False, nox_args = None, **kwargs):
controller = nox_core_dir + '/nox_core',
cargs = '--libdir=/usr/local/lib -v -i ptcp: ' + \
' '.join(nox_args),
cdir = nox_core_dir, **kwargs)
\ No newline at end of file
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
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