Example #1
0
 def __init__(self, *args, **kwargs):
     """servers: a list of servers to use (note: include
        localhost or None to use local system as well)
        user: user name for server ssh
        placement: Placer() subclass"""
     params = {
         'host': RemoteHost,
         'switch': RemoteOVSSwitch,
         'link': RemoteLink,
         'precheck': True
     }
     params.update(kwargs)
     servers = params.pop('servers', ['localhost'])
     servers = [s if s else 'localhost' for s in servers]
     self.servers = servers
     self.serverIP = params.pop('serverIP', {})
     if not self.serverIP:
         self.serverIP = {
             server: RemoteMixin.findServerIP(server)
             for server in self.servers
         }
     self.user = params.pop('user', findUser())
     if params.pop('precheck'):
         self.precheck()
     self.connections = {}
     self.placement = params.pop('placement', SwitchBinPlacer)
     # Make sure control directory exists
     self.cdir = os.environ['HOME'] + '/.ssh/mn'
     errRun(['mkdir', '-p', self.cdir])
     Mininet.__init__(self, *args, **params)
Example #2
0
 def __init__( self, *args, **kwargs ):
     """servers: a list of servers to use (note: include
        localhost or None to use local system as well)
        user: user name for server ssh
        placement: Placer() subclass"""
     params = { 'host': RemoteHost,
                'switch': RemoteOVSSwitch,
                'link': RemoteLink,
                'precheck': True }
     params.update( kwargs )
     servers = params.pop( 'servers', [ 'localhost' ] )
     servers = [ s if s else 'localhost' for s in servers ]
     self.servers = servers
     self.serverIP = params.pop( 'serverIP', {} )
     if not self.serverIP:
         self.serverIP = { server: RemoteMixin.findServerIP( server )
                           for server in self.servers }
     self.user = params.pop( 'user', findUser() )
     if params.pop( 'precheck' ):
         self.precheck()
     self.connections = {}
     self.placement = params.pop( 'placement', SwitchBinPlacer )
     # Make sure control directory exists
     self.cdir = os.environ[ 'HOME' ] + '/.ssh/mn'
     errRun( [ 'mkdir', '-p', self.cdir ] )
     Mininet.__init__( self, *args, **params )
Example #3
0
 def precheck( self ):
     """Pre-check to make sure connection works and that
        we can call sudo without a password"""
     result = 0
     info( '*** Checking servers\n' )
     for server in self.servers:
         ip = self.serverIP[ server ]
         if not server or server == 'localhost':
             continue
         info( server, '' )
         dest = '%s@%s' % ( self.user, ip )
         cmd = [ 'sudo', '-E', '-u', self.user ]
         cmd += self.sshcmd + [ '-n', dest, 'sudo true' ]
         debug( ' '.join( cmd ), '\n' )
         _out, _err, code = errRun( cmd )
         if code != 0:
             error( '\nstartConnection: server connection check failed '
                    'to %s using command:\n%s\n'
                     % ( server, ' '.join( cmd ) ) )
         result |= code
     if result:
         error( '*** Server precheck failed.\n'
                '*** Make sure that the above ssh command works'
                ' correctly.\n'
                '*** You may also need to run mn -c on all nodes, and/or\n'
                '*** use sudo -E.\n' )
         sys.exit( 1 )
     info( '\n' )
Example #4
0
 def cmd(self, *args, **kwargs):
     "Run a command in our owning node namespace or in the root namespace when not yet inRightNamespace."
     if self.inRightNamespace:
         return self.node.cmd(*args, **kwargs)
     else:
         cmd = ' '.join([str(c) for c in args])
         return errRun(cmd)[0]
Example #5
0
 def precheck(self):
     """Pre-check to make sure connection works and that
        we can call sudo without a password"""
     result = 0
     info('*** Checking servers\n')
     for server in self.servers:
         ip = self.serverIP[server]
         if not server or server == 'localhost':
             continue
         info(server, '')
         dest = '%s@%s' % (self.user, ip)
         cmd = ['sudo', '-E', '-u', self.user]
         cmd += self.sshcmd + ['-n', dest, 'sudo true']
         debug(' '.join(cmd), '\n')
         _out, _err, code = errRun(cmd)
         if code != 0:
             error('\nstartConnection: server connection check failed '
                   'to %s using command:\n%s\n' % (server, ' '.join(cmd)))
         result |= code
     if result:
         error('*** Server precheck failed.\n'
               '*** Make sure that the above ssh command works'
               ' correctly.\n'
               '*** You may also need to run mn -c on all nodes, and/or\n'
               '*** use sudo -E.\n')
         sys.exit(1)
     info('\n')
Example #6
0
 def setup(cls):
     "Make sure POFSwitch is installed"
     pathCheck('pofswitch', moduleName='POF Switch (poforwarding.org)')
     out, err, exitcode = errRun('pofswitch -h')
     if exitcode:
         error(out + err + 'pofswitch exited with code %d\n' % exitcode)
         exit(1)
Example #7
0
 def cmd( self, *args, **kwargs ):
     "Run a command in our owning node or in root namespace when not yet inRightNamespace"
     if self.inRightNamespace:
         return self.node.cmd( *args, **kwargs )
     else:
         cmd = ' '.join( [ str( c ) for c in args ] )
         return errRun( cmd )[ 0 ]
Example #8
0
 def test_dhcp(self):
     (out, err, returncode) = errRun('dhcpd')
     if returncode:
         error('\n##### dhcpd error! #####\n')
         error(err)
         return 1
     return 0
Example #9
0
 def pullImage(self):  # pylint: disable=invalid-name
     "Pull docker image if necessary"
     if self.image not in quietRun('docker images'):
         error('%s: docker image' % self.name, self.image,
               'not available locally - pulling\n')
         _out, err, code = errRun('docker', 'pull', self.image)
         if err or code:
             error('docker pull failed with error', code, err, '\n')
Example #10
0
def serviceCheck( *args, **kwargs ):
    "Make sure each service in *args can be found in /etc/init.d/."
    moduleName = kwargs.get( 'moduleName', 'it' )
    for arg in args:
        _, _, ret = errRun( 'test -x /etc/init.d/' + arg )
        if ret != 0:
            error( 'Cannot find required service %s in /etc/init.d/.\n' % arg +
                   'Please make sure that %s is installed ' % moduleName )
            exit( 1 )
Example #11
0
def makeIntfPairFixed(
    intf1,
    intf2,
    addr1=None,
    addr2=None,
    node1=None,
    node2=None,
    deleteIntfs=True,
    runCmd=None,
):
    """Make a veth pair connnecting new interfaces intf1 and intf2
       intf1: name for interface 1
       intf2: name for interface 2
       addr1: MAC address for interface 1 (optional)
       addr2: MAC address for interface 2 (optional)
       node1: home node for interface 1 (optional)
       node2: home node for interface 2 (optional)
       deleteIntfs: delete intfs before creating them
       runCmd: function to run shell commands (quietRun)
       raises Exception on failure"""
    if not runCmd:
        runCmd = quietRun if not node1 else node1.cmd
        runCmd2 = quietRun if not node2 else node2.cmd
    if deleteIntfs:
        # Delete any old interfaces with the same names
        runCmd("ip link del " + intf1)
        runCmd2("ip link del " + intf2)
    # Create new pair
    netns1 = node1.pid
    netns2 = 1 if not node2 else node2.pid
    if addr1 is None and addr2 is None:
        cmd = "ip link add name %s netns %s " "type veth peer name %s netns %s" % (
            intf1,
            netns1,
            intf2,
            netns2,
        )
    else:
        cmd = ("ip link add name %s address %s netns %s "
               "type veth peer name %s address %s netns %s" %
               (intf1, addr1, netns1, intf2, addr2, netns2))

    _, cmdOutput, _ = errRun(cmd)

    # iproute2 changes behaviour in release 5.1
    # the following workaround should be removed when
    # issue in iproute2 was fixed
    # [1] https://github.com/mininet/mininet/issues/884
    # [2] https://lwn.net/Articles/783494/
    if "No such device" in cmdOutput:
        debug("Ignored error creating interface pair (%s,%s): %s " %
              (intf1, intf2, cmdOutput))
        cmdOutput = ""

    if cmdOutput:
        raise Exception("Error creating interface pair (%s,%s): %s " %
                        (intf1, intf2, cmdOutput))
Example #12
0
def serviceCheck(*args, **kwargs):
    "Make sure each service in *args can be found in /etc/init.d/."
    moduleName = kwargs.get('moduleName', 'it')
    for arg in args:
        _, _, ret = errRun('test -x /etc/init.d/' + arg)
        if ret != 0:
            error('Cannot find required service %s in /etc/init.d/.\n' % arg +
                  'Please make sure that %s is installed ' % moduleName)
            exit(1)
Example #13
0
 def setup( cls ):
     "Make sure IVS is installed"
     pathCheck( 'ivs-ctl', 'ivs',
                moduleName="Indigo Virtual Switch (projectfloodlight.org)" )
     out, err, exitcode = errRun( 'ivs-ctl show' )
     if exitcode:
         error( out + err +
                'ivs-ctl exited with code %d\n' % exitcode +
                '*** The openvswitch kernel module might '
                'not be loaded. Try modprobe openvswitch.\n' )
         exit( 1 )
Example #14
0
 def setup( cls ):
     "Make sure IVS is installed"
     pathCheck( 'ivs-ctl', 'ivs',
                moduleName="Indigo Virtual Switch (projectfloodlight.org)" )
     out, err, exitcode = errRun( 'ivs-ctl show' )
     if exitcode:
         error( out + err +
                'ivs-ctl exited with code %d\n' % exitcode +
                '*** The openvswitch kernel module might '
                'not be loaded. Try modprobe openvswitch.\n' )
         exit( 1 )
Example #15
0
def unmountAll(dir=MNRUNDIR):
    "Unmount all mounts under a directory tree"
    dir = realpath(dir)
    # Find all mounts below dir
    # This is subtle because /foo is not
    # a parent of /foot
    dirslash = dir + '/'
    mounts = [m for m in mountPoints() if m == dir or m.find(dirslash) == 0]
    # Unmount them from bottom to top
    mounts.sort(reverse=True)
    for mount in mounts:
        debug('Unmounting', mount, '\n')
        out, err, code = errRun('umount', mount)
        if code != 0:
            info('*** Warning: failed to umount', mount, '\n')
            info(err)
Example #16
0
File: node.py Project: sjas/mininet
 def checkListening(self):
     "Make sure no controllers are running on our port"
     # Verify that Telnet is installed first:
     out, _err, returnCode = errRun("which telnet")
     if "telnet" not in out or returnCode != 0:
         raise Exception(
             "Error running telnet to check for listening " "controllers; please check that it is " "installed."
         )
     listening = self.cmd("echo A | telnet -e A %s %d" % (self.ip, self.port))
     if "Unable" not in listening:
         servers = self.cmd("netstat -atp").split("\n")
         pstr = ":%d " % self.port
         clist = servers[0:1] + [s for s in servers if pstr in s]
         raise Exception(
             "Please shut down the controller which is" " running on port %d:\n" % self.port + "\n".join(clist)
         )
Example #17
0
 def setup(cls):
     "Make sure Open vSwitch is installed and working"
     pathCheck('ovs-vsctl', moduleName='Open vSwitch (openvswitch.org)')
     # This should no longer be needed, and it breaks
     # with OVS 1.7 which has renamed the kernel module:
     #  moduleDeps( subtract=OF_KMOD, add=OVS_KMOD )
     out, err, exitcode = errRun('ovs-vsctl -t 1 show')
     if exitcode:
         error(out + err + 'ovs-vsctl exited with code %d\n' % exitcode +
               '*** Error connecting to ovs-db with ovs-vsctl\n'
               'Make sure that Open vSwitch is installed, '
               'that ovsdb-server is running, and that\n'
               '"ovs-vsctl show" works correctly.\n'
               'You may wish to try '
               '"service openvswitch-switch start".\n')
         exit(1)
Example #18
0
 def checkListening( self ):
     "Make sure no controllers are running on our port"
     # Verify that Telnet is installed first:
     out, _err, returnCode = errRun( "which telnet" )
     if 'telnet' not in out or returnCode != 0:
         raise Exception( "Error running telnet to check for listening "
                          "controllers; please check that it is "
                          "installed." )
     listening = self.cmd( "echo A | telnet -e A %s %d" %
                           ( self.ip, self.port ) )
     if 'Unable' not in listening:
         servers = self.cmd( 'netstat -atp' ).split( '\n' )
         pstr = ':%d ' % self.port
         clist = servers[ 0:1 ] + [ s for s in servers if pstr in s ]
         raise Exception( "Please shut down the controller which is"
                          " running on port %d:\n" % self.port +
                          '\n'.join( clist ) )
def unmountAll( rootdir=MNRUNDIR ):
    "Unmount all mounts under a directory tree"
    rootdir = realpath( rootdir )
    # Find all mounts below rootdir
    # This is subtle because /foo is not
    # a parent of /foot
    dirslash = rootdir + '/'
    mounts = [ m for m in mountPoints()
              if m == dir or m.find( dirslash ) == 0 ]
    # Unmount them from bottom to top
    mounts.sort( reverse=True )
    for mount in mounts:
        debug( 'Unmounting', mount, '\n' )
        _out, err, code = errRun( 'umount', mount )
        if code != 0:
            info( '*** Warning: failed to umount', mount, '\n' )
            info( err )
Example #20
0
 def setup( cls ):
     "Make sure Open vSwitch is installed and working"
     pathCheck( 'ovs-vsctl',
                moduleName='Open vSwitch (openvswitch.org)')
     # This should no longer be needed, and it breaks
     # with OVS 1.7 which has renamed the kernel module:
     #  moduleDeps( subtract=OF_KMOD, add=OVS_KMOD )
     out, err, exitcode = errRun( 'ovs-vsctl -t 1 show' )
     if exitcode:
         error( out + err +
                'ovs-vsctl exited with code %d\n' % exitcode +
                '*** Error connecting to ovs-db with ovs-vsctl\n'
                'Make sure that Open vSwitch is installed, '
                'that ovsdb-server is running, and that\n'
                '"ovs-vsctl show" works correctly.\n'
                'You may wish to try '
                '"service openvswitch-switch start".\n' )
         exit( 1 )
Example #21
0
def cleanUpScreens():
    "Remove moldy socat X11 tunnels."
    errRun( "pkill -9 -f mnexec.*socat" )
Example #22
0
 def cgroupDel( self ):
     "Clean up our cgroup"
     # info( '*** deleting cgroup', self.cgroup, '\n' )
     _out, _err, exitcode = errRun( 'cgdelete -r ' + self.cgroup )
     return exitcode != 0
Example #23
0
def cleanUpScreens():
    "Remove moldy socat X11 tunnels."
    errRun( "pkill -9 -f mnexec.*socat" )