Revision edf60032 mininet/node.py

View differences:

mininet/node.py
52 52

  
53 53
from mininet.log import info, error, warn, debug
54 54
from mininet.util import ( quietRun, errRun, errFail, moveIntf, isShellBuiltin,
55
                          numCores, retry, mountCgroups )
55
                           numCores, retry, mountCgroups )
56 56
from mininet.moduledeps import moduleDeps, pathCheck, OVS_KMOD, OF_KMOD, TUN
57 57
from mininet.link import Link, Intf, TCIntf
58 58

  
......
120 120
        # bash -m: enable job control
121 121
        cmd = [ 'mnexec', opts, 'bash', '-m' ]
122 122
        self.shell = Popen( cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT,
123
            close_fds=True )
123
                            close_fds=True )
124 124
        self.stdin = self.shell.stdin
125 125
        self.stdout = self.shell.stdout
126 126
        self.pid = self.shell.pid
......
355 355
            return self.intfs[ min( ports ) ]
356 356
        else:
357 357
            warn( '*** defaultIntf: warning:', self.name,
358
                 'has no interfaces\n' )
358
                  'has no interfaces\n' )
359 359

  
360 360
    def intf( self, intf='' ):
361 361
        """Return our interface object with given name,
......
513 513
    def __repr__( self ):
514 514
        "More informative string representation"
515 515
        intfs = ( ','.join( [ '%s:%s' % ( i.name, i.IP() )
516
                        for i in self.intfList() ] ) )
516
                              for i in self.intfList() ] ) )
517 517
        return '<%s %s: %s pid=%s> ' % (
518 518
            self.__class__.__name__, self.name, intfs, self.pid )
519 519

  
......
775 775
    def __repr__( self ):
776 776
        "More informative string representation"
777 777
        intfs = ( ','.join( [ '%s:%s' % ( i.name, i.IP() )
778
                        for i in self.intfList() ] ) )
778
                              for i in self.intfList() ] ) )
779 779
        return '<%s %s: %s pid=%s> ' % (
780 780
            self.__class__.__name__, self.name, intfs, self.pid )
781 781

  
......
789 789
           name: name for the switch"""
790 790
        Switch.__init__( self, name, **kwargs )
791 791
        pathCheck( 'ofdatapath', 'ofprotocol',
792
            moduleName='the OpenFlow reference user switch (openflow.org)' )
792
                   moduleName='the OpenFlow reference user switch' +
793
                              '(openflow.org)' )
793 794
        if self.listenPort:
794 795
            self.opts += ' --listen=ptcp:%i ' % self.listenPort
795 796

  
......
812 813
           controllers: list of controller objects"""
813 814
        # Add controllers
814 815
        clist = ','.join( [ 'tcp:%s:%d' % ( c.IP(), c.port )
815
                           for c in controllers ] )
816
                            for c in controllers ] )
816 817
        ofdlog = '/tmp/' + self.name + '-ofd.log'
817 818
        ofplog = '/tmp/' + self.name + '-ofp.log'
818 819
        self.cmd( 'ifconfig lo up' )
819 820
        intfs = [ str( i ) for i in self.intfList() if not i.IP() ]
820 821
        self.cmd( 'ofdatapath -i ' + ','.join( intfs ) +
821
            ' punix:/tmp/' + self.name + ' -d ' + self.dpid +
822
            ' 1> ' + ofdlog + ' 2> ' + ofdlog + ' &' )
822
                  ' punix:/tmp/' + self.name + ' -d ' + self.dpid +
823
                  ' 1> ' + ofdlog + ' 2> ' + ofdlog + ' &' )
823 824
        self.cmd( 'ofprotocol unix:/tmp/' + self.name +
824
            ' ' + clist +
825
            ' --fail=closed ' + self.opts +
826
            ' 1> ' + ofplog + ' 2>' + ofplog + ' &' )
825
                  ' ' + clist +
826
                  ' --fail=closed ' + self.opts +
827
                  ' 1> ' + ofplog + ' 2>' + ofplog + ' &' )
827 828

  
828 829
    def stop( self ):
829 830
        "Stop OpenFlow reference user datapath."
......
846 847
        self.intf = self.dp
847 848
        if self.inNamespace:
848 849
            error( "OVSKernelSwitch currently only works"
849
                " in the root namespace.\n" )
850
                   " in the root namespace.\n" )
850 851
            exit( 1 )
851 852

  
852 853
    @classmethod
853 854
    def setup( cls ):
854 855
        "Ensure any dependencies are loaded; if not, try to load them."
855 856
        pathCheck( 'ovs-dpctl', 'ovs-openflowd',
856
            moduleName='Open vSwitch (openvswitch.org)')
857
                   moduleName='Open vSwitch (openvswitch.org)')
857 858
        moduleDeps( subtract=OF_KMOD, add=OVS_KMOD )
858 859

  
859 860
    def start( self, controllers ):
......
868 869
        self.cmd( 'ovs-dpctl', 'add-if', self.dp, ' '.join( intfs ) )
869 870
        # Run protocol daemon
870 871
        clist = ','.join( [ 'tcp:%s:%d' % ( c.IP(), c.port )
871
                           for c in controllers ] )
872
                            for c in controllers ] )
872 873
        self.cmd( 'ovs-openflowd ' + self.dp +
873
            ' ' + clist +
874
            ' --fail=secure ' + self.opts +
875
            ' --datapath-id=' + self.dpid +
876
            ' 1>' + ofplog + ' 2>' + ofplog + '&' )
874
                  ' ' + clist +
875
                  ' --fail=secure ' + self.opts +
876
                  ' --datapath-id=' + self.dpid +
877
                  ' 1>' + ofplog + ' 2>' + ofplog + '&' )
877 878
        self.execed = False
878 879

  
879 880
    def stop( self ):
......
897 898
    def setup( cls ):
898 899
        "Make sure Open vSwitch is installed and working"
899 900
        pathCheck( 'ovs-vsctl',
900
            moduleName='Open vSwitch (openvswitch.org)')
901
                   moduleName='Open vSwitch (openvswitch.org)')
901 902
        # This should no longer be needed, and it breaks
902 903
        # with OVS 1.7 which has renamed the kernel module:
903 904
        #  moduleDeps( subtract=OF_KMOD, add=OVS_KMOD )
......
970 971
       OpenFlow controller."""
971 972

  
972 973
    def __init__( self, name, inNamespace=False, command='controller',
973
                 cargs='-v ptcp:%d', cdir=None, ip="127.0.0.1",
974
                 port=6633, **params ):
974
                  cargs='-v ptcp:%d', cdir=None, ip="127.0.0.1",
975
                  port=6633, **params ):
975 976
        self.command = command
976 977
        self.cargs = cargs
977 978
        self.cdir = cdir
978 979
        self.ip = ip
979 980
        self.port = port
980 981
        Node.__init__( self, name, inNamespace=inNamespace,
981
            ip=ip, **params  )
982
                       ip=ip, **params  )
982 983
        self.cmd( 'ifconfig lo up' )  # Shouldn't be necessary
983 984
        self.checkListening()
984 985

  
......
1002 1003
        if self.cdir is not None:
1003 1004
            self.cmd( 'cd ' + self.cdir )
1004 1005
        self.cmd( self.command + ' ' + self.cargs % self.port +
1005
            ' 1>' + cout + ' 2>' + cout + '&' )
1006
                  ' 1>' + cout + ' 2>' + cout + '&' )
1006 1007
        self.execed = False
1007 1008

  
1008 1009
    def stop( self ):
......
1050 1051
        noxCoreDir = os.environ[ 'NOX_CORE_DIR' ]
1051 1052

  
1052 1053
        Controller.__init__( self, name,
1053
            command=noxCoreDir + '/nox_core',
1054
            cargs='--libdir=/usr/local/lib -v -i ptcp:%s ' +
1055
                    ' '.join( noxArgs ),
1056
            cdir=noxCoreDir, **kwargs )
1054
                             command=noxCoreDir + '/nox_core',
1055
                             cargs='--libdir=/usr/local/lib -v -i ptcp:%s ' +
1056
                                   ' '.join( noxArgs ),
1057
                             cdir=noxCoreDir,
1058
                             **kwargs )
1057 1059

  
1058 1060

  
1059 1061
class RemoteController( Controller ):
1060 1062
    "Controller running outside of Mininet's control."
1061 1063

  
1062 1064
    def __init__( self, name, ip='127.0.0.1',
1063
                 port=6633, **kwargs):
1065
                  port=6633, **kwargs):
1064 1066
        """Init.
1065 1067
           name: name to give controller
1066 1068
           ip: the IP address where the remote controller is
1067 1069
           listening
1068 1070
           port: the port where the remote controller is listening"""
1069
        Controller.__init__( self, name, ip=ip, port=port,
1070
            **kwargs )
1071
        Controller.__init__( self, name, ip=ip, port=port, **kwargs )
1071 1072

  
1072 1073
    def start( self ):
1073 1074
        "Overridden to do nothing."

Also available in: Unified diff