Revision 538a856c mininet/node.py

View differences:

mininet/node.py
49 49
import signal
50 50
import select
51 51
from subprocess import Popen, PIPE, STDOUT
52
from operator import or_
52 53

  
53 54
from mininet.log import info, error, warn, debug
54 55
from mininet.util import ( quietRun, errRun, errFail, moveIntf, isShellBuiltin,
......
784 785
            error( '*** Error: %s has execed and cannot accept commands' %
785 786
                   self.name )
786 787

  
788
    def connected( self ):
789
        "Is the switch connected to a controller? (override this method)"
790
        return False
791

  
787 792
    def __repr__( self ):
788 793
        "More informative string representation"
789 794
        intfs = ( ','.join( [ '%s:%s' % ( i.name, i.IP() )
......
819 824
        return self.cmd( 'dpctl ' + ' '.join( args ) +
820 825
                         ' tcp:127.0.0.1:%i' % self.listenPort )
821 826

  
827
    def connected( self ):
828
        "Is the switch connected to a controller?"
829
        return 'remote.is-connected=true' in self.dpctl( 'status' )
830

  
822 831
    def start( self, controllers ):
823 832
        """Start OpenFlow reference user datapath.
824 833
           Log to /tmp/sN-{ofd,ofp}.log.
......
950 959
        "Disconnect a data port"
951 960
        self.cmd( 'ovs-vsctl del-port', self, intf )
952 961

  
962
    def controllerUUIDs( self ):
963
        "Return ovsdb UUIDs for our controllers"
964
        uuids = []
965
        controllers = self.cmd( 'ovs-vsctl -- get Bridge', self,
966
                               'Controller' ).strip()
967
        if controllers.startswith( '[' ) and controllers.endswith( ']' ):
968
            controllers = controllers[ 1 : -1 ]
969
            uuids = [ c.strip() for c in controllers.split( ',' ) ]
970
        return uuids
971

  
972
    def connected( self ):
973
        "Are we connected to at least one of our controllers?"
974
        results = [ 'true' in self.cmd( 'ovs-vsctl -- get Controller',
975
                                         uuid, 'is_connected' )
976
                    for uuid in self.controllerUUIDs() ]
977
        return reduce( or_, results, False )
978

  
953 979
    def start( self, controllers ):
954 980
        "Start up a new OVS OpenFlow switch using ovs-vsctl"
955 981
        if self.inNamespace:
......
976 1002
            clist += ' ptcp:%s' % self.listenPort
977 1003
        self.cmd( 'ovs-vsctl set-controller', self, clist )
978 1004
        # Reconnect quickly to controllers (1s vs. 15s max_backoff)
979
        controllers = self.cmd( 'ovs-vsctl -- get Bridge', self,
980
                               'Controller' ).strip()
981
        if controllers.startswith( '[' ) and controllers.endswith( ']' ):
982
            controllers = controllers[ 1 : -1 ]
983
            uuids = [ c.strip() for c in controllers.split( ',' ) ]
984
            for uuid in uuids:
985
                if uuid.count( '-' ) != 4:
986
                    # Doesn't look like a UUID
987
                    continue
988
                uuid = uuid.strip()
989
                self.cmd( 'ovs-vsctl set Controller', uuid,
990
                          'max_backoff=1000' )
1005
        for uuid in self.controllerUUIDs():
1006
            if uuid.count( '-' ) != 4:
1007
                # Doesn't look like a UUID
1008
                continue
1009
            uuid = uuid.strip()
1010
            self.cmd( 'ovs-vsctl set Controller', uuid,
1011
                      'max_backoff=1000' )
991 1012

  
992 1013
    def stop( self ):
993 1014
        "Terminate OVS switch."

Also available in: Unified diff