Revision 60d9ead6

View differences:

bin/mn_run.py
16 16
from mininet.logging_mod import lg, set_loglevel, LEVELS
17 17
from mininet.net import Mininet, init
18 18
from mininet.node import KernelSwitch, Host, Controller, ControllerParams, NOX
19
from mininet.node import RemoteController
19 20
from mininet.topo import SingleSwitchTopo, LinearTopo
20 21

  
21 22
# built in topologies, created only when run
......
46 47
CONTROLLERS = {'ref' : Controller,
47 48
               'nox_dump' : lambda a, b: NOX(a, b, 'packetdump'),
48 49
               'nox_pysw' : lambda a, b: NOX(a, b, 'pyswitch'),
50
               'remote' : lambda a, b: None,
49 51
               'none' :     lambda a, b: None}
50 52

  
51 53
# optional tests to run
......
106 108
        opts.add_option('--verbosity', '-v', type = 'choice',
107 109
                        choices = LEVELS.keys(), default = 'info',
108 110
                        help = '[' + ' '.join(LEVELS.keys()) + ']')
111
        opts.add_option('--ip', type = 'string',
112
                        help = '[ip address as a dotted decimal string for a'
113
                        'remote controller]')
114
        opts.add_option('--port', type = 'string',
115
                        help = '[port integer for a listening remote'
116
                        ' controller]')
109 117
        self.options = opts.parse_args()[0]
110 118

  
111 119
    def setup(self):
......
132 140
        switch = SWITCHES[self.options.switch]
133 141
        host = HOSTS[self.options.host]
134 142
        controller = CONTROLLERS[self.options.controller]
143
        if self.options.controller == 'remote':
144
            controller = lambda a, b: RemoteController(a, b,
145
                             ip_address = self.options.ip,
146
                             port = self.options.port)
135 147

  
136 148
        controller_params = ControllerParams(0x0a000000, 8) # 10.0.0.0/8
137 149
        xterms = self.options.xterms
mininet/node.py
3 3

  
4 4
from subprocess import Popen, PIPE, STDOUT
5 5
import os, signal, sys, select
6

  
6 7
flush = sys.stdout.flush
7 8

  
8 9
from mininet.logging_mod import lg
......
36 37
        self.pid = self.shell.pid
37 38
        self.intfCount = 0
38 39
        self.intfs = [] # list of interface names, as strings
39
        self.ips = {}
40
        self.ips = {} # dict of interfaces to ip addresses as strings
40 41
        self.connection = {}
41 42
        self.waiting = False
42 43
        self.execed = False
......
186 187
        '''Set the IP address for an interface.
187 188

  
188 189
        @param intf string, interface name
189
        @param ip IP address as integer
190
        @param ip IP address as a string
190 191
        @param bits
191 192
        '''
192 193
        result = self.cmd(['ifconfig', intf, ip + bits, 'up'])
......
303 304
        self.dp = dp
304 305
        self.dpid = dpid
305 306

  
306
    def start(self, ignore):
307
    def start(self, controllers):
307 308
        '''Start up reference kernel datapath.'''
308 309
        ofplog = '/tmp/' + self.name + '-ofp.log'
309 310
        quietRun('ifconfig lo up')
......
318 319
        self.cmdPrint('dpctl addif nl:' + str(self.dp) + ' ' +
319 320
                      ' '.join(self.intfs))
320 321
        # Run protocol daemon
321
        self.cmdPrint('ofprotocol nl:' + str(self.dp) + ' tcp:127.0.0.1 ' +
322
        self.cmdPrint('ofprotocol nl:' + str(self.dp) + ' tcp:' +
323
                      controllers['c0'].IP()+':'+str(controllers['c0'].port) +
322 324
                      ' --fail=closed 1> ' + ofplog + ' 2>' + ofplog + ' &')
323 325
        self.execed = False # XXX until I fix it
324 326

  
......
340 342
      OpenFlow controller.'''
341 343

  
342 344
    def __init__(self, name, inNamespace = False, controller = 'controller',
343
                 cargs = '-v ptcp:', cdir = None):
345
                 cargs = '-v ptcp:', cdir = None, ip_address="127.0.0.1",
346
                 port = 6633):
344 347
        self.controller = controller
345 348
        self.cargs = cargs
346 349
        self.cdir = cdir
350
        self.ip_address = ip_address
351
        self.port = port
347 352
        Node.__init__(self, name, inNamespace = inNamespace)
348 353

  
349 354
    def start(self):
......
363 368
        self.cmd('kill %' + self.controller)
364 369
        self.terminate()
365 370

  
371
    def IP(self):
372
        '''Return IP address of the Controller'''
373
        return self.ip_address
374

  
366 375

  
367 376
class ControllerParams(object):
368 377
    '''Container for controller IP parameters.'''
......
395 404
            controller = nox_core_dir + '/nox_core',
396 405
            cargs = '--libdir=/usr/local/lib -v -i ptcp: ' + \
397 406
                    ' '.join(nox_args),
398
            cdir = nox_core_dir, **kwargs)
407
            cdir = nox_core_dir, **kwargs)
408

  
409
class RemoteController(Controller):
410
    '''Controller running remotely.'''
411
    def __init__(self, name, inNamespace = False, ip_address = None, port = 6633):
412
        '''Init.
413

  
414
        @param name name to give controller
415
        @param ip_address the IP address where the remote controller is
416
            listening
417
        @param port the port where the remote controller is listening
418
        '''
419
        if not ip_address:
420
            raise Exception('please set ip_address\n')
421
        Controller.__init__(self, name, ip_address = ip_address, port = port)
422

  
423
    def start(self):
424
        '''Overridden to do nothing.'''
425
        return
426

  
427
    def stop(self):
428
        '''Overridden to do nothing.'''
429
        return

Also available in: Unified diff