Revision 60d9ead6 mininet/node.py

View differences:

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