Revision 8a7d42db mininet/node.py

View differences:

mininet/node.py
49 49
from time import sleep
50 50

  
51 51
from mininet.log import info, error, debug
52
from mininet.util import quietRun, makeIntfPair, moveIntf, isShellBuiltin
52
from mininet.util import quietRun, errRun, makeIntfPair, moveIntf, isShellBuiltin
53 53
from mininet.moduledeps import moduleDeps, pathCheck, OVS_KMOD, OF_KMOD, TUN
54 54

  
55 55
SWITCH_PORT_BASE = 1  # For OF > 0.9, switch ports start at 1 rather than zero
......
558 558
        self.deleteIntfs()
559 559

  
560 560

  
561
class OVSKernelSwitch( Switch ):
562
    """Open VSwitch kernel-space switch.
561
class OVSLegacyKernelSwitch( Switch ):
562
    """Open VSwitch legacy kernel-space switch using ovs-openflowd.
563 563
       Currently only works in the root namespace."""
564 564

  
565 565
    def __init__( self, name, dp=None, **kwargs ):
......
617 617
        self.deleteIntfs()
618 618

  
619 619

  
620
class OVSSwitch( Switch ):
621
    "Open vSwitch switch. Depends on ovs-vsctl."
622

  
623
    def __init__( self, name, dp=None, **kwargs ):
624
        """Init.
625
           name: name for switch
626
           dp: netlink id (0, 1, 2, ...)
627
           defaultMAC: default MAC as unsigned int; random value if None"""
628
        Switch.__init__( self, name, **kwargs )
629
        self.dp = 'dp%i' % dp
630

  
631
    @staticmethod
632
    def setup():
633
        "Make sure Open vSwitch is installed and working"
634
        pathCheck( 'ovs-vsctl', 
635
            moduleName='Open vSwitch (openvswitch.org)')
636
        moduleDeps( subtract=OF_KMOD, add=OVS_KMOD )
637
        out, err, exitcode = errRun( 'ovs-vsctl -t 1 show' )
638
        if exitcode:
639
            error( out + err + 
640
                   'ovs-vsctl exited with code %d\n' % exitcode +
641
                   '*** Error connecting to ovs-db with ovs-vsctl\n'
642
                   'Make sure that Open vSwitch is installed, '
643
                   'that ovsdb-server is running, and that\n'
644
                   '"ovs-vsctl show" works correctly.\n'
645
                   'You may wish to try "service openvswitch-switch start".\n' )
646
            exit( 1 )
647

  
648
    def start( self, controllers ):
649
        "Start up a new OVS OpenFlow switch using ovs-vsctl"
650
        # Annoyingly, --if-exists option seems not to work
651
        self.cmd( 'ovs-vsctl del-br ', self.dp )
652
        self.cmd( 'ovs-vsctl add-br', self.dp )
653
        self.cmd( 'ovs-vsctl set-fail-mode', self.dp, 'secure' )
654
        # Add ports
655
        ports = sorted( self.ports.values() )
656
        intfs = [ self.intfs[ port ] for port in ports ]
657
        # XXX: Ugly check - we should probably fix this!
658
        if ports and ( len( ports ) != ports[ -1 ] + 1 - self.portBase ):
659
            raise Exception( 'only contiguous, one-indexed port ranges '
660
                            'supported: %s' % self.intfs )
661
        for intf in intfs:
662
            self.cmd( 'ovs-vsctl add-port', self.dp, intf )
663
            self.cmd( 'ifconfig', intf, 'up' )
664
        # Add controllers
665
        clist = ','.join( [ 'tcp:%s:%d' % ( c.IP(), c.port ) for c in controllers ] )
666
        self.cmd( 'ovs-vsctl set-controller', self.dp, clist )
667

  
668
    def stop( self ):
669
        "Terminate OVS switch."
670
        self.cmd( 'ovs-vsctl del-br', self.dp )
671

  
672
OVSKernelSwitch = OVSSwitch
673

  
674

  
620 675
class Controller( Node ):
621 676
    """A Controller is a Node that is running (or has execed?) an
622 677
       OpenFlow controller."""

Also available in: Unified diff