Revision 07aad110

View differences:

mininet/cli.py
157 157
        else:
158 158
            self.mn.link( *args )
159 159

  
160
    def do_pause( self, args ):
161
        "Temporarily bring a node down."
162
        args = args.split()
163
        if len(args) != 1:
164
            error( 'invalid number of args: pause [node]\n' )
165
        elif args[0] not in self.nodemap:
166
            error( 'invalid node: %s\n' % args[0] )
167
        else:
168
            self.nodemap[ args[ 0 ] ].pause()
169

  
170
    def do_resume( self, args ):
171
        "Temporarily bring a node up."
172
        args = args.split()
173
        if len(args) != 1:
174
            error( 'invalid number of args: resume [node]\n' )
175
        elif args[0] not in self.nodemap:
176
            error( 'invalid node: %s\n' % args[0] )
177
        else:
178
            self.nodemap[ args[ 0 ] ].resume()
179

  
160 180
    def do_exit( self, args ):
161 181
        "Exit"
162 182
        return 'exited by user command'
mininet/node.py
337 337
        "Check if an interface is up."
338 338
        return 'UP' in self.cmd( 'ifconfig ' + intf )
339 339

  
340
    def modIntfs( self, action ):
341
        """Bring all interfaces up or down.
342
           action: string to pass to ifconfig"""
343
        for intf in self.intfs.values():
344
            result = self.cmd( [ 'ifconfig', intf, action ] )
345

  
340 346
    # Other methods
341 347
    def __str__( self ):
342 348
        result = self.name + ':'
......
351 357
    "A host is simply a Node."
352 358
    pass
353 359

  
360
    # Ideally, pausing a host would pause the process.  However, when one
361
    # tries to run a command on a paused host, it leads to an exception later.
362
    # For now, disable interfaces to "pause" the host.
363
    def pause( self ):
364
        "Disable interfaces."
365
        self.modIntfs('down')
366

  
367
    def resume( self ):
368
        "Re-enable interfaces"
369
        self.modIntfs('up')
354 370

  
355 371
class Switch( Node ):
356 372
    """A Switch is a Node that is running (or has execed?)
......
405 421
        self.cmd( 'kill %ofprotocol' )
406 422
        self.deleteIntfs()
407 423

  
424
    def pause( self ):
425
        "Pause ofprotocol and ofdatapath."
426
        self.cmd( 'kill -STOP %ofdatapath' )
427
        self.cmd( 'kill -STOP %ofprotocol' )
428

  
429
    def resume( self ):
430
        "Resume ofprotocol and datapath."
431
        self.cmd( 'kill -CONT %ofdatapath' )
432
        self.cmd( 'kill -CONT %ofprotocol' )
433

  
434

  
408 435
class KernelSwitch( Switch ):
409 436
    """Kernel-space switch.
410 437
       Currently only works in root namespace."""
......
452 479
        self.cmd( 'kill %ofprotocol' )
453 480
        self.deleteIntfs()
454 481

  
482
    # Since kernel threads cannot receive signals like user-space processes,
483
    # disabling the interfaces and ofdatapath is our workaround.
484
    def pause( self ):
485
        "Disable interfaces and pause ofprotocol."
486
        self.cmd( 'kill -STOP %ofprotocol' )
487
        self.modIntfs('down')
488

  
489
    def resume( self ):
490
        "Re-enable interfaces and resume ofprotocol."
491
        self.cmd( 'kill -CONT %ofprotocol' )
492
        self.modIntfs('up')
493

  
455 494
class OVSKernelSwitch( Switch ):
456 495
    """Open VSwitch kernel-space switch.
457 496
       Currently only works in the root namespace."""
......
500 539
        self.cmd( 'kill %ovs-openflowd' )
501 540
        self.deleteIntfs()
502 541

  
542
    # Since kernel threads cannot receive signals like user-space processes,
543
    # disabling the interfaces and ofdatapath is our workaround.
544
    def pause( self ):
545
        "Disable interfaces and pause ovs-openflowd."
546
        self.cmd( 'kill -STOP %ovs-openflowd' )
547
        self.modIntfs('down')
548

  
549
    def resume( self ):
550
        "Re-enable interfaces and resume ovs-openflowd."
551
        self.cmd( 'kill -CONT %ovs-openflowd' )
552
        self.modIntfs('up')
553

  
503 554

  
504 555
class Controller( Node ):
505 556
    """A Controller is a Node that is running (or has execed?) an
......
530 581
        self.cmd( 'kill %' + self.controller )
531 582
        self.terminate()
532 583

  
584
    def pause( self ):
585
        "Pause controller."
586
        self.cmd( 'kill -STOP %' + self.controller )
587

  
588
    def resume( self ):
589
        "Resume controller."
590
        self.cmd( 'kill -CONT %' + self.controller )
591

  
533 592
    def IP( self, intf=None ):
534 593
        "Return IP address of the Controller"
535 594
        ip = Node.IP( self, intf=intf )
......
537 596
            ip = self.defaultIP
538 597
        return ip
539 598

  
599

  
540 600
class ControllerParams( object ):
541 601
    "Container for controller IP parameters."
542 602

  

Also available in: Unified diff