Revision 723d068c mininet/node.py

View differences:

mininet/node.py
2 2
'''Node objects for Mininet.'''
3 3

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

  
7 10
flush = sys.stdout.flush
8 11

  
9 12
from mininet.logging_mod import lg
10 13
from mininet.util import quietRun, macColonHex, ipStr
11 14

  
15

  
12 16
class Node(object):
13 17
    '''A virtual network node is simply a shell in a network namespace.
14 18
       We communicate with it using pipes.'''
......
116 120

  
117 121
    def waitOutput(self):
118 122
        '''Wait for a command to complete.
119
        
123

  
120 124
        Completion is signaled by a sentinel character, ASCII(127) appearing in
121 125
        the output stream.  Wait for the sentinel and return the output,
122 126
        including trailing newline.
......
129 133
            if len(data) > 0  and data[-1] == chr(0177):
130 134
                output += data[:-1]
131 135
                break
132
            else: output += data
136
            else:
137
                output += data
133 138
        self.waiting = False
134 139
        return output
135 140

  
......
143 148

  
144 149
    def cmdPrint(self, cmd):
145 150
        '''Call cmd and printing its output
146
        
151

  
147 152
        @param cmd string
148 153
        '''
149 154
        #lg.info('*** %s : %s', self.name, cmd)
......
215 220
    def IP(self):
216 221
        '''Return IP address of first interface'''
217 222
        if len(self.intfs) > 0:
218
            return self.ips.get(self.intfs[ 0 ], None)
223
            return self.ips.get(self.intfs[0], None)
219 224

  
220 225
    def intfIsUp(self):
221 226
        '''Check if one of our interfaces is up.'''
......
258 263
        else:
259 264
            return True, ''
260 265

  
266

  
261 267
class UserSwitch(Switch):
262 268
    '''User-space switch.
263 269

  
......
269 275

  
270 276
        @param name
271 277
        '''
272
        Node.__init__(self, name, inNamespace = False)
278
        Switch.__init__(self, name, inNamespace = False)
273 279

  
274 280
    def start(self, controllers):
275 281
        '''Start OpenFlow reference user datapath.
......
298 304

  
299 305

  
300 306
class KernelSwitch(Switch):
307
    '''Kernel-space switch.
308

  
309
    Much faster than user-space!
310

  
311
    Currently only works in the root namespace.
312
    '''
301 313

  
302 314
    def __init__(self, name, dp = None, dpid = None):
303 315
        '''Init.
......
306 318
        @param dp netlink id (0, 1, 2, ...)
307 319
        @param dpid datapath ID as unsigned int; random value if None
308 320
        '''
309
        Node.__init__(self, name, inNamespace = False)
321
        Switch.__init__(self, name, inNamespace = False)
310 322
        self.dp = dp
311 323
        self.dpid = dpid
312 324

  
......
333 345
                      controllers['c0'].IP() + ':' +
334 346
                      str(controllers['c0'].port) +
335 347
                      ' --fail=closed 1> ' + ofplog + ' 2>' + ofplog + ' &')
336
        self.execed = False # XXX until I fix it
348
        self.execed = False
337 349

  
338 350
    def stop(self):
339 351
        '''Terminate reference kernel datapath.'''
......
372 384
            self.cmdPrint('cd ' + self.cdir)
373 385
        self.cmdPrint(self.controller + ' ' + self.cargs +
374 386
            ' 1> ' + cout + ' 2> ' + cout + ' &')
375
        self.execed = False # XXX Until I fix it
387
        self.execed = False
376 388

  
377 389
    def stop(self):
378 390
        '''Stop controller.'''
......
386 398

  
387 399
class ControllerParams(object):
388 400
    '''Container for controller IP parameters.'''
401

  
389 402
    def __init__(self, ip, subnet_size):
390 403
        '''Init.
391 404

  
......
398 411

  
399 412
class NOX(Controller):
400 413
    '''Controller to run a NOX application.'''
414

  
401 415
    def __init__(self, name, inNamespace = False, nox_args = None, **kwargs):
402 416
        '''Init.
403 417

  
......
420 434

  
421 435
class RemoteController(Controller):
422 436
    '''Controller running outside of Mininet's control.'''
437

  
423 438
    def __init__(self, name, inNamespace = False, ip_address = '127.0.0.1',
424 439
                 port = 6633):
425 440
        '''Init.

Also available in: Unified diff