#!/usr/bin/env python

"""
Copyright 2014 Open Networking Foundation (ONF)

This driver interacts with ONOS bench, the OSGi platform
that configures the ONOS nodes. ( aka ONOS-next )

Please follow the coding style demonstrated by existing
functions and document properly.

If you are a contributor to the driver, please
list your email here for future contact:

jhall@onlab.us
andrew@onlab.us

OCT 9 2014
Modified 2016 by ON.Lab

Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>

"""
import time
import types
import pexpect
import os
import re
import subprocess
from drivers.common.clidriver import CLI

class OnosDriver( CLI ):

    def __init__( self ):
        """
        Initialize client
        """
        self.name = None
        self.home = None
        self.handle = None
        self.nicAddr = None
        super( OnosDriver, self ).__init__()

    def connect( self, **connectargs ):
        """
        Creates ssh handle for ONOS "bench".
        NOTE:
        The ip_address would come from the topo file using the host tag, the
        value can be an environment variable as well as a "localhost" to get
        the ip address needed to ssh to the "bench"
        """
        try:

            for key in connectargs:
                vars( self )[ key ] = connectargs[ key ]
            self.home = "~/onos"
            for key in self.options:
                if key == "home":
                    self.home = self.options[ 'home' ]
                    break
            if self.home is None or self.home == "":
                self.home = "~/onos"

            self.name = self.options[ 'name' ]

            # The 'nodes' tag is optional and it is not required in .topo file
            for key in self.options:
                if key == "nodes":
                    # Maximum number of ONOS nodes to run, if there is any
                    self.maxNodes = int( self.options[ 'nodes' ] )
                    break
                self.maxNodes = None

            if self.maxNodes is None or self.maxNodes == "":
                self.maxNodes = 100

            # Grabs all OC environment variables based on max number of nodes
            self.onosIps = {}  # Dictionary of all possible ONOS ip

            try:
                if self.maxNodes:
                    for i in range( self.maxNodes ):
                        envString = "OC" + str( i + 1 )
                        # If there is no more OC# then break the loop
                        if os.getenv( envString ):
                            self.onosIps[ envString ] = os.getenv( envString )
                        else:
                            self.maxNodes = len( self.onosIps )
                            main.log.info( self.name +
                                           ": Created cluster data with " +
                                           str( self.maxNodes ) +
                                           " maximum number" +
                                           " of nodes" )
                            break

                    if not self.onosIps:
                        main.log.info( "Could not read any environment variable"
                                       + " please load a cell file with all" +
                                        " onos IP" )
                        self.maxNodes = None
                    else:
                        main.log.info( self.name + ": Found " +
                                       str( self.onosIps.values() ) +
                                       " ONOS IPs" )
            except KeyError:
                main.log.info( "Invalid environment variable" )
            except Exception as inst:
                main.log.error( "Uncaught exception: " + str( inst ) )

            try:
                if os.getenv( str( self.ip_address ) ) is not None:
                    self.ip_address = os.getenv( str( self.ip_address ) )
                else:
                    main.log.info( self.name +
                                   ": Trying to connect to " +
                                   self.ip_address )
            except KeyError:
                main.log.info( "Invalid host name," +
                               " connecting to local host instead" )
                self.ip_address = 'localhost'
            except Exception as inst:
                main.log.error( "Uncaught exception: " + str( inst ) )

            self.handle = super( OnosDriver, self ).connect(
                user_name=self.user_name,
                ip_address=self.ip_address,
                port=self.port,
                pwd=self.pwd,
                home=self.home )

            if self.handle:
                self.handle.sendline( "cd " + self.home )
                self.handle.expect( self.prompt )
                return self.handle
            else:
                main.log.info( "Failed to create ONOS handle" )
                return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def disconnect( self ):
        """
        Called when Test is complete to disconnect the ONOS handle.
        """
        response = main.TRUE
        try:
            if self.handle:
                self.handle.sendline( "" )
                self.handle.expect( self.prompt )
                self.handle.sendline( "exit" )
                self.handle.expect( "closed" )
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
        except ValueError:
            main.log.exception( "Exception in disconnect of " + self.name )
            response = main.TRUE
        except Exception:
            main.log.exception( self.name + ": Connection failed to the host" )
            response = main.FALSE
        return response

    def getEpochMs( self ):
        """
        Returns milliseconds since epoch

        When checking multiple nodes in a for loop,
        around a hundred milliseconds of difference (ascending) is
        generally acceptable due to calltime of the function.
        Few seconds, however, is not and it means clocks
        are off sync.
        """
        try:
            self.handle.sendline( 'date +%s.%N' )
            self.handle.expect( 'date \+\%s\.\%N' )
            self.handle.expect( self.prompt )
            epochMs = self.handle.before
            return epochMs
        except Exception:
            main.log.exception( 'Uncaught exception getting epoch time' )
            main.cleanAndExit()

    def onosPackage( self, opTimeout=180 ):
        """
        Produce a self-contained tar.gz file that can be deployed
        and executed on any platform with Java 8 JRE.
        """
        try:
            ret = main.TRUE
            self.handle.sendline( "onos-package" )
            self.handle.expect( "onos-package" )
            while True:
                i = self.handle.expect( [ "Downloading",
                                          "Unknown options",
                                          "No such file or directory",
                                          "tar.gz",
                                          self.prompt ],
                                        opTimeout )
                handle = str( self.handle.before + self.handle.after )
                if i == 0:
                    # Give more time to download the file
                    continue  # expect again
                elif i == 1:
                    # Incorrect usage
                    main.log.error( "onos-package does not recognize the given options" )
                    ret = main.FALSE
                    continue  # expect again
                elif i == 2:
                    # File(s) not found
                    main.log.error( "onos-package could not find a file or directory" )
                    ret = main.FALSE
                    continue  # expect again
                elif i == 3:
                    # tar.gz
                    continue  # expect again
                elif i == 4:
                    # Prompt returned
                    break
            main.log.info( "onos-package command returned: " + handle )
            # As long as the sendline does not time out,
            # return true. However, be careful to interpret
            # the results of the onos-package command return
            return ret
        except pexpect.TIMEOUT:
            main.log.exception( self.name + ": TIMEOUT exception found in onosPackage" )
            main.log.error( self.name + ":    " + self.handle.before )
            self.handle.send( "\x03" )  # Control-C
            self.handle.expect( self.prompt )
            return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( "Failed to package ONOS" )
            main.cleanAndExit()

    def onosBuild( self ):
        """
        Use the pre defined script to build onos via mvn
        """
        try:
            self.handle.sendline( "onos-build" )
            self.handle.expect( "onos-build" )
            i = self.handle.expect( [
                "BUILD SUCCESS",
                "ERROR",
                "BUILD FAILED" ],
                timeout=120 )
            handle = str( self.handle.before )
            self.handle.expect( self.prompt )

            main.log.info( "onos-build command returned: " +
                           handle )

            if i == 0:
                return main.TRUE
            else:
                return handle

        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
        except Exception:
            main.log.exception( "Failed to build ONOS" )
            main.cleanAndExit()

    def cleanInstall( self, skipTest=False, mciTimeout=600 ):
        """
        Runs mvn clean install in the root of the ONOS directory.
        This will clean all ONOS artifacts then compile each module
        Optional:
            skipTest - Does "-DskipTests -Dcheckstyle.skip -U -T 1C" which
                       skip the test. This will make the building faster.
                       Disregarding the credibility of the build
        Returns: main.TRUE on success
        On Failure, exits the test
        """
        try:
            main.log.info( "Running 'mvn clean install' on " +
                           str( self.name ) +
                           ". This may take some time." )
            self.handle.sendline( "cd " + self.home )
            self.handle.expect( self.prompt )

            self.handle.sendline( "" )
            self.handle.expect( self.prompt )

            if not skipTest:
                self.handle.sendline( "mvn clean install" )
                self.handle.expect( "mvn clean install" )
            else:
                self.handle.sendline( "mvn clean install -DskipTests" +
                                      " -Dcheckstyle.skip -U -T 1C" )
                self.handle.expect( "mvn clean install -DskipTests" +
                                      " -Dcheckstyle.skip -U -T 1C" )
            while True:
                i = self.handle.expect( [
                    'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s' +
                    'Runtime\sEnvironment\sto\scontinue',
                    'BUILD\sFAILURE',
                    'BUILD\sSUCCESS',
                    'onos' + self.prompt,  # TODO: fix this to be more generic?
                    'ONOS' + self.prompt,
                    pexpect.TIMEOUT ], mciTimeout )
                if i == 0:
                    main.log.error( self.name + ":There is insufficient memory \
                            for the Java Runtime Environment to continue." )
                    # return main.FALSE

                    main.cleanAndExit()
                if i == 1:
                    main.log.error( self.name + ": Build failure!" )
                    # return main.FALSE

                    main.cleanAndExit()
                elif i == 2:
                    main.log.info( self.name + ": Build success!" )
                elif i == 3 or i == 4:
                    main.log.info( self.name + ": Build complete" )
                    # Print the build time
                    for line in self.handle.before.splitlines():
                        if "Total time:" in line:
                            main.log.info( line )
                    self.handle.sendline( "" )
                    self.handle.expect( self.prompt, timeout=60 )
                    return main.TRUE
                elif i == 5:
                    main.log.error(
                        self.name +
                        ": mvn clean install TIMEOUT!" )
                    # return main.FALSE

                    main.cleanAndExit()
                else:
                    main.log.error( self.name + ": unexpected response from " +
                                    "mvn clean install" )
                    # return main.FALSE

                    main.cleanAndExit()
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def buckBuild( self, timeout=180 ):
        """
        Build onos using buck.
        """
        try:
            ret = main.TRUE
            self.handle.sendline( "buck build onos" )
            self.handle.expect( "buck build onos" )
            output = ""
            while True:
                i = self.handle.expect( [ "This does not appear to be the root of a Buck project.",
                                          "\n",
                                          "BUILD FAILED",
                                          "no buck in",
                                          self.prompt ],
                                        timeout=timeout )
                output += str( self.handle.before + self.handle.after )
                if i == 0:
                    main.log.error( "Wrong location" )
                    ret = main.FALSE
                elif i == 1:
                    # end of a line, buck is still printing output
                    pass
                elif i == 2:
                    # Build failed
                    main.log.error( "Build failed" )
                    ret = main.FALSE
                elif i == 3:
                    main.log.error( "Could not find buck in your PATH." )
                    ret = main.FALSE
                elif i == 4:
                    # Prompt returned
                    break
            main.log.debug( output )
            return ret
        except pexpect.TIMEOUT:
            main.log.exception( self.name + ": TIMEOUT exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            self.handle.send( "\x03" )  # Control-C
            self.handle.expect( self.prompt )
            return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( "Failed to build and package ONOS" )
            main.cleanAndExit()

    def bazelBuild( self, timeout=180 ):
        """
        Build onos using bazel.
        """
        try:
            ret = main.TRUE
            self.handle.sendline( "bazel build onos" )
            self.handle.expect( "bazel build onos" )
            output = ""
            while True:
                i = self.handle.expect( [ "command is only supported from within a workspace",
                                          "\n",
                                          "FAILED",
                                          "ERROR",
                                          "command not found",
                                          self.prompt ],
                                        timeout=timeout )
                output += str( self.handle.before + self.handle.after )
                if i == 0:
                    main.log.error( "Please run the build from root of ONOS project" )
                    ret = main.FALSE
                elif i == 1:
                    # end of a line, buck is still printing output
                    pass
                elif i == 2:
                    # Build failed
                    main.log.error( "Build failed" )
                    ret = main.FALSE
                elif i == 3:
                    # Build failed
                    main.log.error( "Build failed" )
                    ret = main.FALSE
                elif i == 4:
                    main.log.error( "Command not found" )
                    ret = main.FALSE
                elif i == 5:
                    # Prompt returned
                    break
            main.log.debug( output )
            return ret
        except pexpect.TIMEOUT:
            main.log.exception( self.name + ": TIMEOUT exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            self.handle.send( "\x03" )  # Control-C
            self.handle.expect( self.prompt )
            return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( "Failed to build and package ONOS" )
            main.cleanAndExit()

    def gitPull( self, comp1="", fastForward=True ):
        """
        Assumes that "git pull" works without login

        If the fastForward boolean is set to true, only git pulls that can
        be fast forwarded will be performed. IE if you have not local commits
        in your branch.

        This function will perform a git pull on the ONOS instance.
        If used as gitPull( "NODE" ) it will do git pull + NODE. This is
        for the purpose of pulling from other nodes if necessary.

        Otherwise, this function will perform a git pull in the
        ONOS repository. If it has any problems, it will return main.ERROR
        If it successfully does a gitPull, it will return a 1 ( main.TRUE )
        If it has no updates, it will return 3.

        """
        try:
            self.handle.sendline( "cd " + self.home )
            self.handle.expect( self.prompt )
            cmd = "git pull"
            if comp1 != "":
                cmd += ' ' + comp1
            if fastForward:
                cmd += ' ' + " --ff-only"
            self.handle.sendline( cmd )
            i = self.handle.expect(
                [
                    'fatal',
                    'Username\sfor\s(.*):\s',
                    '\sfile(s*) changed,\s',
                    'Already up-to-date',
                    'Aborting',
                    'You\sare\snot\scurrently\son\sa\sbranch',
                    'You asked me to pull without telling me which branch you',
                    'Pull is not possible because you have unmerged files',
                    'Please enter a commit message to explain why this merge',
                    'Found a swap file by the name',
                    'Please, commit your changes before you can merge.',
                    pexpect.TIMEOUT ],
                timeout=300 )
            if i == 0:
                main.log.error( self.name + ": Git pull had some issue" )
                output = self.handle.after
                self.handle.expect( self.prompt )
                output += self.handle.before
                main.log.warn( output )
                return main.ERROR
            elif i == 1:
                main.log.error(
                    self.name +
                    ": Git Pull Asking for username. " )
                return main.ERROR
            elif i == 2:
                main.log.info(
                    self.name +
                    ": Git Pull - pulling repository now" )
                self.handle.expect( self.prompt, 120 )
            # So that only when git pull is done, we do mvn clean compile
                return main.TRUE
            elif i == 3:
                main.log.info( self.name + ": Git Pull - Already up to date" )
                return main.TRUE
            elif i == 4:
                main.log.info(
                    self.name +
                    ": Git Pull - Aborting..." +
                    "Are there conflicting git files?" )
                return main.ERROR
            elif i == 5:
                main.log.info(
                    self.name +
                    ": Git Pull - You are not currently " +
                    "on a branch so git pull failed!" )
                return main.ERROR
            elif i == 6:
                main.log.info(
                    self.name +
                    ": Git Pull - You have not configured an upstream " +
                    "branch to pull from. Git pull failed!" )
                return main.ERROR
            elif i == 7:
                main.log.info(
                    self.name +
                    ": Git Pull - Pull is not possible because " +
                    "you have unmerged files." )
                return main.ERROR
            elif i == 8:
                # NOTE: abandoning test since we can't reliably handle this
                #       there could be different default text editors and we
                #       also don't know if we actually want to make the commit
                main.log.error( "Git pull resulted in a merge commit message" +
                                ". Exiting test!" )

                main.cleanAndExit()
            elif i == 9:  # Merge commit message but swap file exists
                main.log.error( "Git pull resulted in a merge commit message" +
                                " but a swap file exists." )
                try:
                    self.handle.send( 'A' )  # Abort
                    self.handle.expect( self.prompt )
                    return main.ERROR
                except Exception:
                    main.log.exception( "Couldn't exit editor prompt!" )

                    main.cleanAndExit()
            elif i == 10:  # In the middle of a merge commit
                main.log.error( "Git branch is in the middle of a merge. " )
                main.log.warn( self.handle.before + self.handle.after )
                return main.ERROR
            elif i == 11:
                main.log.error( self.name + ": Git Pull - TIMEOUT" )
                main.log.error(
                    self.name + " Response was: " + str(
                        self.handle.before ) )
                self.handle.send( "\x03" )  # Control-C
                self.handle.expect( self.prompt )
                return main.ERROR
            else:
                main.log.error(
                    self.name +
                    ": Git Pull - Unexpected response, check for pull errors" )
                return main.ERROR
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def gitCheckout( self, branch="master" ):
        """
        Assumes that "git pull" works without login

        This function will perform a git git checkout on the ONOS instance.
        If used as gitCheckout( "branch" ) it will do git checkout
        of the "branch".

        Otherwise, this function will perform a git checkout of the master
        branch of the ONOS repository. If it has any problems, it will return
        main.ERROR.
        If the branch was already the specified branch, or the git checkout was
        successful then the function will return main.TRUE.

        """
        try:
            self.handle.sendline( "cd " + self.home )
            self.handle.expect( self.prompt )
            main.log.info( self.name +
                           ": Checking out git branch/ref: " + branch + "..." )
            cmd = "git checkout " + branch
            self.handle.sendline( cmd )
            self.handle.expect( cmd )
            i = self.handle.expect(
                [ 'fatal',
                  'Username for (.*): ',
                  'Already on \'',
                  'Switched to (a new )?branch \'' + str( branch ),
                  pexpect.TIMEOUT,
                  'error: Your local changes to the following files' +
                  'would be overwritten by checkout:',
                  'error: you need to resolve your current index first',
                  "You are in 'detached HEAD' state.",
                  "HEAD is now at " ],
                timeout=60 )
            if i == 0:
                main.log.error(
                    self.name +
                    ": Git checkout had some issue..." )
                main.log.error( self.name + ":     " + self.handle.before )
                return main.ERROR
            elif i == 1:
                main.log.error(
                    self.name +
                    ": Git checkout asking for username." +
                    " Please configure your local git repository to be able " +
                    "to access your remote repository passwordlessly" )
                # TODO add support for authenticating
                return main.ERROR
            elif i == 2:
                main.log.info(
                    self.name +
                    ": Git Checkout %s : Already on this branch" % branch )
                self.handle.expect( self.prompt )
                # main.log.info( "DEBUG: after checkout cmd = "+
                # self.handle.before )
                return main.TRUE
            elif i == 3:
                main.log.info(
                    self.name +
                    ": Git checkout %s - Switched to this branch" % branch )
                self.handle.expect( self.prompt )
                # main.log.info( "DEBUG: after checkout cmd = "+
                # self.handle.before )
                return main.TRUE
            elif i == 4:
                main.log.error( self.name + ": Git Checkout- TIMEOUT" )
                main.log.error(
                    self.name + " Response was: " + str( self.handle.before ) )
                self.handle.send( "\x03" )  # Control-C
                self.handle.expect( self.prompt )
                return main.ERROR
            elif i == 5:
                self.handle.expect( "Aborting" )
                main.log.error(
                    self.name +
                    ": Git checkout error: \n" +
                    "Your local changes to the following files would" +
                    " be overwritten by checkout:" +
                    str( self.handle.before ) )
                self.handle.expect( self.prompt )
                return main.ERROR
            elif i == 6:
                main.log.error(
                    self.name +
                    ": Git checkout error: \n" +
                    "You need to resolve your current index first:" +
                    str( self.handle.before ) )
                self.handle.expect( self.prompt )
                return main.ERROR
            elif i == 7:
                main.log.info(
                    self.name +
                    ": Git checkout " + str( branch ) +
                    " - You are in 'detached HEAD' state. HEAD is now at " +
                    str( branch ) )
                self.handle.expect( self.prompt )
                return main.TRUE
            elif i == 8:  # Already in detached HEAD on the specified commit
                main.log.info(
                    self.name +
                    ": Git Checkout %s : Already on commit" % branch )
                self.handle.expect( self.prompt )
                return main.TRUE
            else:
                main.log.error(
                    self.name +
                    ": Git Checkout - Unexpected response, " +
                    "check for pull errors" )
                main.log.error( self.name + ":     " + self.handle.before )
                return main.ERROR

        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def getBranchName( self ):
        import re
        try:
            main.log.info( self.name + " home is " + self.home )
            self.handle.sendline( "cd " + self.home )
            self.handle.expect( self.prompt )
            self.handle.sendline( "git name-rev --name-only HEAD" )
            self.handle.expect( "git name-rev --name-only HEAD" )
            self.handle.expect( self.prompt )
            lines = self.handle.before.splitlines()
            if lines[ 1 ] == "master" or re.search( "^onos-\d+(\.\d+)+$", lines[ 1 ] ):
                return lines[ 1 ]
            else:
                main.log.info( lines[ 1 ] )
                return "unexpected ONOS branch"
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except pexpect.TIMEOUT:
            main.log.error( self.name + ": TIMEOUT exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def getVersion( self, report=False ):
        """
        Writes the COMMIT number to the report to be parsed
                by Jenkins data collector.
        """
        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            self.handle.sendline(
                "cd " +
                self.home +
                "; git log -1 --pretty=fuller --decorate=short | grep -A 6 " +
                " \"commit\" --color=never" )
            # NOTE: for some reason there are backspaces inserted in this
            # phrase when run from Jenkins on some tests
            self.handle.expect( "never" )
            self.handle.expect( self.prompt )
            response = ( self.name + ": \n" + str(
                self.handle.before + self.handle.after ) )
            self.handle.sendline( "cd " + self.home )
            self.handle.expect( self.prompt )
            lines = response.splitlines()
            for line in lines:
                print line
            if report:
                main.log.wiki( "<blockquote>" )
                for line in lines[ 2:-1 ]:
                    # Bracket replacement is for Wiki-compliant
                    # formatting. '<' or '>' are interpreted
                    # as xml specific tags that cause errors
                    line = line.replace( "<", "[" )
                    line = line.replace( ">", "]" )
                    # main.log.wiki( "\t" + line )
                    main.log.wiki( line + "<br /> " )
                    main.log.summary( line )
                main.log.wiki( "</blockquote>" )
                main.log.summary( "\n" )
            return lines[ 2 ]
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except pexpect.TIMEOUT:
            main.log.error( self.name + ": TIMEOUT exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def createCellFile( self, benchIp, fileName, mnIpAddrs,
                        appString, onosIpAddrs, atomixIps,
                        onosUser="sdn", useSSH=True ):
        """
        Creates a cell file based on arguments
        Required:
            * Bench IP address ( benchIp )
                - Needed to copy the cell file over
            * File name of the cell file ( fileName )
            * Mininet IP address ( mnIpAddrs )
                - Note that only 1 ip address is
                  supported currently
            * ONOS IP addresses ( onosIpAddrs )
                - Must be passed in as last arguments
            * ONOS USER (onosUser)
                - optional argument to set ONOS_USER environment variable

        NOTE: Assumes cells are located at:
            ~/<self.home>/tools/test/cells/
        """
        try:

            # Variable initialization
            cellDirectory = self.home + "/tools/test/cells/"
            # We want to create the cell file in the dependencies directory
            # of TestON first, then copy over to ONOS bench
            tempDirectory = "/tmp/"
            # Create the cell file in the directory for writing ( w+ )
            cellFile = open( tempDirectory + fileName, 'w+' )
            if isinstance( onosIpAddrs, types.StringType ):
                onosIpAddrs = [ onosIpAddrs ]
            if isinstance( atomixIps, types.StringType ):
                atomixIps = [ atomixIps ]

            # App string is hardcoded environment variables
            # That you may wish to use by default on startup.
            # Note that you  may not want certain apps listed
            # on here.
            appString = "export ONOS_APPS=" + appString
            onosGroup = "export ONOS_GROUP=" + onosUser
            onosUser = "export ONOS_USER=" + onosUser
            if useSSH:
                onosUseSSH = "export ONOS_USE_SSH=true"
            mnString = "export OCN="
            if mnIpAddrs == "":
                mnString = ""
            onosString = "export OC"
            atomixString = "export OCC"

            # Create ONOSNIC ip address prefix
            tempOnosIp = str( onosIpAddrs[ 0 ] )
            tempList = []
            tempList = tempOnosIp.split( "." )
            # Omit last element of list to format for NIC
            tempList = tempList[ :-1 ]
            # Structure the nic string ip
            nicAddr = ".".join( tempList ) + ".*"
            self.nicAddr = nicAddr
            onosNicString = "export ONOS_NIC=" + nicAddr

            # Start writing to file
            cellFile.write( onosNicString + "\n" )

            onosIndex = 1
            for arg in onosIpAddrs:
                # For each argument in onosIpAddrs, write to file
                # Output should look like the following:
                #   export OC1="10.128.20.11"
                #   export OC2="10.128.20.12"
                cellFile.write( onosString + str( onosIndex ) +
                                "=\"" + arg + "\"\n" )
                onosIndex = onosIndex + 1

            atomixIndex = 1
            for ip in atomixIps:
                cellFile.write( atomixString + str( atomixIndex ) +
                                    "=\"" + ip + "\"\n" )
                atomixIndex += 1

            cellFile.write( "export OCI=$OC1\n" )
            if mnString:
                cellFile.write( mnString + "\"" + str( mnIpAddrs ) + "\"\n" )
            cellFile.write( appString + "\n" )
            cellFile.write( onosGroup + "\n" )
            cellFile.write( onosUser + "\n" )
            if useSSH:
                cellFile.write( onosUseSSH + "\n" )
            cellFile.close()

            # We use os.system to send the command to TestON cluster
            # to account for the case in which TestON is not located
            # on the same cluster as the ONOS bench
            # Note that even if TestON is located on the same cluster
            # as ONOS bench, you must setup passwordless ssh
            # between TestON and ONOS bench in order to automate the test.
            os.system( "scp " + tempDirectory + fileName + " " +
                       self.user_name + "@" + self.ip_address + ":" + cellDirectory )

            return main.TRUE

        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def setCell( self, cellname ):
        """
        Calls 'cell <name>' to set the environment variables on ONOSbench
        """
        try:
            if not cellname:
                main.log.error( self.name + ": Must define cellname" )
                main.cleanAndExit()
            else:
                self.handle.sendline( "cell " + str( cellname ) )
                # Expect the cellname in the ONOSCELL variable.
                # Note that this variable name is subject to change
                #   and that this driver will have to change accordingly
                self.handle.expect( str( cellname ) )
                response = self.handle.before + self.handle.after
                i = self.handle.expect( [ "No such cell",
                                          "command not found",
                                          self.prompt ], timeout=10 )
                response += self.handle.before + self.handle.after
                if i == 0:
                    main.log.error( self.name + ": No such cell. Response: " + str( response ) )
                    main.cleanAndExit()
                elif i == 1:
                    main.log.error( self.name + ": Error setting cell. Response: " + str( response ) )
                    main.cleanAndExit()
                elif i == 2:
                    main.log.info( self.name + ": Successfully set cell: " + str( response ) )
                return main.TRUE
        except pexpect.TIMEOUT:
            main.log.error( self.name + ": TIMEOUT exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def verifyCell( self ):
        """
        Calls 'onos-verify-cell' to check for cell installation
        """
        # TODO: Add meaningful expect value

        try:
            # Clean handle by sending empty and expecting $
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            self.handle.sendline( "onos-verify-cell" )
            self.handle.expect( self.prompt )
            handleBefore = self.handle.before
            handleAfter = self.handle.after
            main.log.info( "Verify cell returned: " + handleBefore +
                           handleAfter )
            return main.TRUE
        except pexpect.ExceptionPexpect:
            main.log.exception( self.name + ": Pexpect exception found: " )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosCfgSet( self, ONOSIp, configName, configParam ):
        """
        Uses 'onos <node-ip> cfg set' to change a parameter value of an
        application.

        ex)
            onos 10.0.0.1 cfg set org.onosproject.myapp appSetting 1
        ONOSIp = '10.0.0.1'
        configName = 'org.onosproject.myapp'
        configParam = 'appSetting 1'
        """
        try:
            cfgStr = "onos {} cfg set {} {}".format( ONOSIp,
                                                     configName,
                                                     configParam )
            self.handle.sendline( "" )
            self.handle.expect( ":~" )
            self.handle.sendline( cfgStr )
            self.handle.expect( "cfg set" )
            self.handle.expect( ":~" )

            paramValue = configParam.split( " " )[ 1 ]
            paramName = configParam.split( " " )[ 0 ]

            checkStr = 'onos {} cfg get " {} {} " '.format( ONOSIp, configName, paramName )

            self.handle.sendline( checkStr )
            self.handle.expect( ":~" )

            if "value=" + paramValue + "," in self.handle.before:
                main.log.info( "cfg " + configName + " successfully set to " + configParam )
                return main.TRUE
        except pexpect.ExceptionPexpect:
            main.log.exception( self.name + ": Pexpect exception found: " )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosCli( self, ONOSIp, cmdstr, timeout=60 ):
        """
        Uses 'onos' command to send various ONOS CLI arguments.
        Required:
            * ONOSIp: specify the ip of the cell machine
            * cmdstr: specify the command string to send
        Optional:
            * timeout: pexpect timeout for running the command

        This function is intended to expose the entire karaf
        CLI commands for ONOS. Try to use this function first
        before attempting to write a ONOS CLI specific driver
        function.
        You can see a list of available 'cmdstr' arguments
        by starting onos, and typing in 'onos' to enter the
        onos> CLI. Then, type 'help' to see the list of
        available commands.
        """
        try:
            if not ONOSIp:
                main.log.error( "You must specify the IP address" )
                return main.FALSE
            if not cmdstr:
                main.log.error( "You must specify the command string" )
                return main.FALSE

            cmdstr = str( cmdstr )
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )

            self.handle.sendline( "onos-wait-for-start " + ONOSIp )
            self.handle.expect( self.prompt )

            self.handle.sendline( "onos " + ONOSIp + " " + cmdstr )
            i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ], timeout=timeout )
            if i == 0:
                handleBefore = self.handle.before
                main.log.info( "Command sent successfully" )
                # Obtain return handle that consists of result from
                # the onos command. The string may need to be
                # configured further.
                returnString = handleBefore
                return returnString
            elif i == 1:
                main.log.error( self.name + ": Timeout when sending " + cmdstr )
                self.handle.send( "\x03" )  # Control-C
                self.handle.expect( self.prompt )
                return main.FALSE
        except pexpect.TIMEOUT:
            main.log.exception( self.name + ": Timeout when sending " + cmdstr )
            return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosSecureSSH( self, userName="onos", userPWD="rocks", node="" ):
        """
        Enables secure access to ONOS console
        by removing default users & keys.

        onos-secure-ssh -u onos -p rocks node

        Returns: main.TRUE on success and main.FALSE on failure
        """

        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            self.handle.sendline( " onos-secure-ssh -u " + userName + " -p " + userPWD + " " + node )

            # NOTE: this timeout may need to change depending on the network
            # and size of ONOS
            # TODO: Handle the other possible error
            i = self.handle.expect( [ "Network\sis\sunreachable",
                                      self.prompt,
                                      pexpect.TIMEOUT ], timeout=180 )
            if i == 0:
                # can't reach ONOS node
                main.log.warn( self.name + ": Network is unreachable" )
                self.handle.expect( self.prompt )
                return main.FALSE
            elif i == 1:
                # Process started
                main.log.info( self.name + ": Secure SSH performed on " + node )
                return main.TRUE
            elif i == 2:
                # timeout
                main.log.error( self.name + ": Failed to secure ssh on " + node )
                main.log.debug( self.handle.before )
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosInstall( self, options="-f", node="" ):
        """
        Installs ONOS bits on the designated cell machine.
        If -f option is provided, it also forces an uninstall.
        Presently, install also includes onos-push-bits and
        onos-config within.
        The node option allows you to selectively only push the jar
        files to certain onos nodes

        Returns: main.TRUE on success and main.FALSE on failure
        """
        try:
            if options:
                self.handle.sendline( "onos-install " + options + " " + node )
            else:
                self.handle.sendline( "onos-install " + node )
            self.handle.expect( "onos-install " )
            # NOTE: this timeout may need to change depending on the network
            # and size of ONOS
            i = self.handle.expect( [ "Network\sis\sunreachable",
                                      "onos\sstart/running,\sprocess",
                                      "ONOS\sis\salready\sinstalled",
                                      "does not exist",
                                      self.prompt,
                                      pexpect.TIMEOUT ], timeout=180 )
            if i == 0:
                # can't reach ONOS node
                main.log.warn( "Network is unreachable" )
                self.handle.expect( self.prompt )
                return main.FALSE
            elif i == 1:
                # Process started
                main.log.info(
                    "ONOS was installed on " +
                    node +
                    " and started" )
                self.handle.expect( self.prompt )
                return main.TRUE
            elif i == 2:
                # same bits are already on ONOS node
                main.log.info( "ONOS is already installed on " + node )
                self.handle.expect( self.prompt )
                return main.TRUE
            elif i == 3:
                # onos not packaged
                main.log.error( "ONOS package not found." )
                self.handle.expect( self.prompt )
                return main.FALSE
            elif i == 4:
                # prompt
                main.log.info( "ONOS was installed on {} {}.".format(  node,
                               "but not started" if 'n' in options else "and started" ) )
                return main.TRUE
            elif i == 5:
                # timeout
                main.log.info(
                    "Installation of ONOS on " +
                    node +
                    " timed out" )
                self.handle.expect( self.prompt )
                main.log.warn( self.handle.before )
                self.handle.send( "\x03" )  # Control-C
                self.handle.expect( self.prompt )
                return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosStart( self, nodeIp ):
        """
        Calls onos command: 'onos-service [<node-ip>] start'
        This command is a remote management of the ONOS upstart daemon
        """
        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            self.handle.sendline( "onos-service " + str( nodeIp ) +
                                  " start" )
            i = self.handle.expect( [
                "Job\sis\salready\srunning",
                "start/running",
                self.prompt,
                "Unknown\sinstance",
                pexpect.TIMEOUT ], timeout=180 )
            if i == 0:
                self.handle.expect( self.prompt )
                main.log.info( "Service is already running" )
                return main.TRUE
            elif i == 1:
                self.handle.expect( self.prompt )
                main.log.info( "ONOS service started" )
                return main.TRUE
            elif i == 2:
                main.log.info( "ONOS service started" )
                return main.TRUE
            else:
                self.handle.expect( self.prompt )
                main.log.error( "ONOS service failed to start" )

                main.cleanAndExit()
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosStop( self, nodeIp ):
        """
        Calls onos command: 'onos-service [<node-ip>] stop'
        This command is a remote management of the ONOS upstart daemon
        """
        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            self.handle.sendline( "onos-service " + str( nodeIp ) +
                                  " stop" )
            i = self.handle.expect( [
                "stop/waiting",
                "Could not resolve hostname",
                "Unknown\sinstance",
                self.prompt,
                pexpect.TIMEOUT ], timeout=180 )
            if i == 0:
                self.handle.expect( self.prompt )
                main.log.info( "ONOS service stopped" )
                return main.TRUE
            elif i == 1:
                self.handle.expect( self.prompt )
                main.log.info( "onosStop() Unknown ONOS instance specified: " +
                               str( nodeIp ) )
                return main.FALSE
            elif i == 2:
                self.handle.expect( self.prompt )
                main.log.warn( "ONOS wasn't running" )
                return main.TRUE
            elif i == 3:
                main.log.info( "ONOS service stopped" )
                return main.TRUE
            else:
                main.log.error( "ONOS service failed to stop" )
                return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosUninstall( self, nodeIp="" ):
        """
        Calls the command: 'onos-uninstall'
        Uninstalls ONOS from the designated cell machine, stopping
        if needed
        """
        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt, timeout=180 )
            self.handle.sendline( "onos-uninstall " + str( nodeIp ) )
            self.handle.expect( self.prompt, timeout=180 )
            main.log.info( "ONOS " + nodeIp + " was uninstalled" )
            # onos-uninstall command does not return any text
            return main.TRUE
        except pexpect.TIMEOUT:
            main.log.exception( self.name + ": Timeout in onosUninstall" )
            self.handle.send( "\x03" )  # Control-C
            self.handle.expect( self.prompt )
            return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosDie( self, nodeIp ):
        """
        Issues the command 'onos-die <node-ip>'
        This command calls onos-kill and also stops the node
        """
        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            cmdStr = "onos-die " + str( nodeIp )
            self.handle.sendline( cmdStr )
            i = self.handle.expect( [
                "Killing\sONOS",
                "ONOS\sprocess\sis\snot\srunning",
                pexpect.TIMEOUT ], timeout=60 )
            if i == 0:
                main.log.info( "ONOS instance " + str( nodeIp ) +
                               " was killed and stopped" )
                self.handle.sendline( "" )
                self.handle.expect( self.prompt )
                return main.TRUE
            elif i == 1:
                main.log.info( "ONOS process was not running" )
                self.handle.sendline( "" )
                self.handle.expect( self.prompt )
                return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosKill( self, nodeIp ):
        """
        Calls the command: 'onos-kill [<node-ip>]'
        "Remotely, and unceremoniously kills the ONOS instance running on
        the specified cell machine" - Tom V
        """
        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            self.handle.sendline( "onos-kill " + str( nodeIp ) )
            i = self.handle.expect( [
                self.prompt,
                "No\sroute\sto\shost",
                "password:",
                pexpect.TIMEOUT ], timeout=60 )

            if i == 0:
                main.log.info(
                    "ONOS instance " + str(
                        nodeIp ) + " was killed" )
                return main.TRUE
            elif i == 1:
                main.log.info( "No route to host" )
                return main.FALSE
            elif i == 2:
                main.log.info(
                    "Passwordless login for host: " +
                    str( nodeIp ) +
                    " not configured" )
                return main.FALSE
            else:
                main.log.info( "ONOS instance was not killed" )
                return main.FALSE

        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosRemoveRaftLogs( self ):
        """
        Removes Raft / Copy cat files from ONOS to ensure
        a cleaner environment.

        Description:
            Stops all ONOS defined in the cell,
            wipes the raft / copycat log files
        """
        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            self.handle.sendline( "onos-remove-raft-logs" )
            # Sometimes this command hangs
            i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
                                    timeout=120 )
            if i == 1:
                i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
                                        timeout=120 )
                if i == 1:
                    return main.FALSE
            return main.TRUE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosStartNetwork( self, mntopo ):
        """
        Calls the command 'onos-start-network [ <mininet-topo> ]
        "remotely starts the specified topology on the cell's
        mininet machine against all controllers configured in the
        cell."
        * Specify mininet topology file name for mntopo
        * Topo files should be placed at:
          ~/<your-onos-directory>/tools/test/topos

        NOTE: This function will take you to the mininet prompt
        """
        try:
            if not mntopo:
                main.log.error( "You must specify a topo file to execute" )
                return main.FALSE

            mntopo = str( mntopo )
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )

            self.handle.sendline( "onos-start-network " + mntopo )
            self.handle.expect( "mininet>" )
            main.log.info( "Network started, entered mininet prompt" )

            # TODO: Think about whether return is necessary or not

        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def isup( self, node="", timeout=240 ):
        """
        Run's onos-wait-for-start which only returns once ONOS is at run
        level 100(ready for use)

        Returns: main.TRUE if ONOS is running and main.FALSE on timeout
        """
        try:
            self.handle.sendline( "onos-wait-for-start " + node )
            self.handle.expect( "onos-wait-for-start" )
            # NOTE: this timeout is arbitrary"
            i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT, "Password:" ], timeout )
            if i == 0:
                main.log.info( self.name + ": " + node + " is up" )
                return main.TRUE
            elif i == 1 or i == 2:
                # NOTE: since this function won't return until ONOS is ready,
                #   we will kill it on timeout
                if i == 1:
                    main.log.error( "{}: ONOS {} has not started yet".format( self.name, node ) )
                elif i == 2:
                    main.log.error( "{}: Cannot login to ONOS CLI {}, try using onos-secure-ssh".format( self.name, node ) )
                self.handle.send( "\x03" )  # Control-C
                self.handle.expect( self.prompt )
                return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def preventAutoRespawn( self ):
        """
        Description:
            This will prevent ONOSservice to automatically
            respawn.
        """
        try:
            self.handle.sendline( "sed -i -e 's/^respawn$/#respawn/g' tools/package/init/onos.conf" )
            self.handle.expect( "\$" )  # $ from the command
            self.handle.sendline( "sed -i -e 's/^Restart=always/Restart=no/g' tools/package/init/onos.service" )
            self.handle.expect( "\$" )  # $ from the command
            self.handle.expect( "\$" )  # $ from the prompt
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def pushTestIntentsShell(
            self,
            dpidSrc,
            dpidDst,
            numIntents,
            dirFile,
            onosIp,
            numMult="",
            appId="",
            report=True,
            options="" ):
        """
        Description:
            Use the linux prompt to push test intents to
            better parallelize the results than the CLI
        Required:
            * dpidSrc: specify source dpid
            * dpidDst: specify destination dpid
            * numIntents: specify number of intents to push
            * dirFile: specify directory and file name to save
              results
            * onosIp: specify the IP of ONOS to install on
        NOTE:
            You must invoke this command at linux shell prompt
        """
        try:
            # Create the string to sendline
            if options:
                baseCmd = "onos " + str( onosIp ) + " push-test-intents " +\
                    options + " "
            else:
                baseCmd = "onos " + str( onosIp ) + " push-test-intents "

            addDpid = baseCmd + str( dpidSrc ) + " " + str( dpidDst )
            if not numMult:
                addIntents = addDpid + " " + str( numIntents )
            elif numMult:
                addIntents = addDpid + " " + str( numIntents ) + " " +\
                    str( numMult )
                if appId:
                    addApp = addIntents + " " + str( appId )
                else:
                    addApp = addIntents

            if report:
                sendCmd = addApp + " > " + str( dirFile ) + " &"
            else:
                sendCmd = addApp + " &"
            main.log.info( "Send cmd: " + sendCmd )

            self.handle.sendline( sendCmd )

        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def tsharkPcap( self, interface, dirFile ):
        """
        Capture all packet activity and store in specified
        directory/file

        Required:
            * interface: interface to capture
            * dir: directory/filename to store pcap
        """
        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )

            self.handle.sendline( "tshark -i " + str( interface ) + " -t e -w " + str( dirFile ) + " &" )
            self.handle.sendline( "\n" )
            self.handle.expect( "Capturing on" )
            self.handle.sendline( "\n" )
            self.handle.expect( self.prompt )

            main.log.info( "Tshark started capturing files on " +
                           str( interface ) + " and saving to directory: " +
                           str( dirFile ) )
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosTopoCfg( self, onosIp, jsonFile ):
        """
            Description:
                Execute onos-topo-cfg command
            Required:
                onosIp - IP of the onos node you want to send the json to
                jsonFile - File path of the json file
            Return:
                Returns main.TRUE if the command is successfull; Returns
                main.FALSE if there was an error
        """
        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            cmd = "onos-topo-cfg "
            self.handle.sendline( cmd + str( onosIp ) + " " + jsonFile )
            handle = self.handle.before
            print handle
            if "Error" in handle:
                main.log.error( self.name + ":    " + self.handle.before )
                return main.FALSE
            else:
                self.handle.expect( self.prompt )
                return main.TRUE

        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def tsharkGrep( self, grep, directory, interface='eth0', grepOptions='' ):
        """
        Required:
            * grep string
            * directory to store results
        Optional:
            * interface - default: eth0
            * grepOptions - options for grep
        Description:
            Uses tshark command to grep specific group of packets
            and stores the results to specified directory.
            The timestamp is hardcoded to be in epoch
        """
        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            self.handle.sendline( "" )
            if grepOptions:
                grepStr = "grep " + str( grepOptions )
            else:
                grepStr = "grep"

            cmd = (
                "sudo tshark -i " +
                str( interface ) +
                " -t e | " +
                grepStr + " --line-buffered \"" +
                str( grep ) +
                "\" >" +
                directory +
                " &" )
            self.handle.sendline( cmd )
            main.log.info( cmd )
            self.handle.expect( "Capturing on" )
            self.handle.sendline( "\n" )
            self.handle.expect( self.prompt )
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def tsharkStop( self ):
        """
        Removes wireshark files from /tmp and kills all tshark processes
        """
        # Remove all pcap from previous captures
        try:
            self.execute( cmd="sudo rm /tmp/wireshark*" )
            self.handle.sendline( "" )
            self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\"" +
                                  " | grep -v grep | awk '{print $2}'`" )
            self.handle.sendline( "" )
            main.log.info( "Tshark stopped" )
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def ptpd( self, args ):
        """
        Initiate ptp with user-specified args.
        Required:
            * args: specify string of args after command
              'sudo ptpd'
        """
        try:
            self.handle.sendline( "sudo ptpd " + str( args ) )
            i = self.handle.expect( [
                "Multiple",
                "Error",
                self.prompt ] )
            self.handle.expect( self.prompt )

            if i == 0:
                handle = self.handle.before
                main.log.info( "ptpd returned an error: " +
                               str( handle ) )
                return handle
            elif i == 1:
                handle = self.handle.before
                main.log.error( "ptpd returned an error: " +
                                str( handle ) )
                return handle
            else:
                return main.TRUE

        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def dumpONOSCmd( self, ONOSIp, CMD, destDir, filename, options="", timeout=60 ):
        """
        Dump Cmd to a desired directory.
        For debugging purposes, you may want to use
        this function to capture Cmd at a given point in time.
        Localtime will be attached to the filename

        Required:
            * ONOSIp: the IP of the target ONOS instance
            * CMD: the command to dump;
            * destDir: specify directory to copy to.
              ex ) /tmp/
            * fileName: Name of the file
        Optional:
            * options: Options for ONOS command
            * timeout: pexpect timeout for running the ONOS command
        """

        localtime = time.strftime( '%x %X' )
        localtime = localtime.replace( "/", "" )
        localtime = localtime.replace( " ", "_" )
        localtime = localtime.replace( ":", "" )
        if destDir[ -1: ] != "/":
            destDir += "/"
        cmd = CMD + " " + options + " > " + str( destDir ) + str( filename ) + localtime
        return self.onosCli( ONOSIp, cmd, timeout=timeout )

    def cpLogsToDir( self, logToCopy,
                     destDir, copyFileName="" ):
        """
        Copies logs to a desired directory.
        Current implementation of ONOS deletes its karaf
        logs on every iteration. For debugging purposes,
        you may want to use this function to capture
        certain karaf logs. ( or any other logs if needed )
        Localtime will be attached to the filename

        Required:
            * logToCopy: specify directory and log name to
              copy.
              ex ) /opt/onos/log/karaf.log.1
              For copying multiple files, leave copyFileName
              empty and only specify destDir -
              ex ) /opt/onos/log/karaf*
            * destDir: specify directory to copy to.
              ex ) /tmp/
        Optional:
            * copyFileName: If you want to rename the log
              file, specify copyFileName. This will not work
              with multiple file copying
        """
        try:
            localtime = time.strftime( '%H %M' )
            localtime = localtime.replace( "/", "" )
            localtime = localtime.replace( " ", "_" )
            localtime = localtime.replace( ":", "" )
            if destDir[ -1: ] != "/":
                destDir += "/"

            if copyFileName:
                self.handle.sendline( "cp " + str( logToCopy ) + " " +
                                      str( destDir ) + str( copyFileName ) +
                                      localtime )
                self.handle.expect( "cp" )
                self.handle.expect( self.prompt )
            else:
                self.handle.sendline( "cp " + str( logToCopy ) +
                                      " " + str( destDir ) )
                self.handle.expect( "cp" )
                self.handle.expect( self.prompt )

            return self.handle.before

        except pexpect.EOF:
            main.log.error( "Copying files failed" )
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
        except Exception:
            main.log.exception( "Copying files failed" )

    def checkLogs( self, onosIp, restart=False ):
        """
        runs onos-check-logs on the given onos node
        If restart is True, use the old version of onos-check-logs which
            does not print the full stacktrace, but shows the entire log file,
            including across restarts
        returns the response
        """
        try:
            cmd = "onos-check-logs " + str( onosIp )
            if restart:
                cmd += " old"
            self.handle.sendline( cmd )
            self.handle.expect( cmd )
            self.handle.expect( self.prompt + " " )
            response = self.handle.before
            return response
        except pexpect.EOF:
            main.log.error( "Lost ssh connection" )
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosStatus( self, node="" ):
        """
        Calls onos command: 'onos-service [<node-ip>] status'
        """
        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            self.handle.sendline( "onos-service " + str( node ) +
                                  " status" )
            i = self.handle.expect( [
                "start/running",
                "Running ...",
                "stop/waiting",
                "Not Running ...",
                pexpect.TIMEOUT ], timeout=120 )
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )

            if i == 0 or i == 1:
                main.log.info( "ONOS is running" )
                return main.TRUE
            elif i == 2 or i == 3:
                main.log.info( "ONOS is stopped" )
                main.log.error( "ONOS service failed to check the status" )

                main.cleanAndExit()
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def setIpTables( self, ip, port='', action='add', packet_type='',
                     direction='INPUT', rule='DROP', states=True ):
        """
        Description:
            add or remove iptables rule to DROP (default) packets from
            specific IP and PORT
        Usage:
        * specify action ('add' or 'remove')
          when removing, pass in the same argument as you would add. It will
          delete that specific rule.
        * specify the ip to block
        * specify the destination port to block (defaults to all ports)
        * optional packet type to block (default tcp)
        * optional iptables rule (default DROP)
        * optional direction to block (default 'INPUT')
        * States boolean toggles adding all supported tcp states to the
          firewall rule
        Returns:
            main.TRUE on success or
            main.FALSE if given invalid input or
            main.ERROR if there is an error in response from iptables
        WARNING:
        * This function uses root privilege iptables command which may result
          in unwanted network errors. USE WITH CAUTION
        """

        # NOTE*********
        #   The strict checking methods of this driver function is intentional
        #   to discourage any misuse or error of iptables, which can cause
        #   severe network errors
        # *************

        # NOTE: Sleep needed to give some time for rule to be added and
        #       registered to the instance. If you are calling this function
        #       multiple times this sleep will prevent any errors.
        #       DO NOT REMOVE
        # time.sleep( 5 )
        try:
            # input validation
            action_type = action.lower()
            rule = rule.upper()
            direction = direction.upper()
            if action_type != 'add' and action_type != 'remove':
                main.log.error( "Invalid action type. Use 'add' or "
                                "'remove' table rule" )
                if rule != 'DROP' and rule != 'ACCEPT' and rule != 'LOG':
                    # NOTE Currently only supports rules DROP, ACCEPT, and LOG
                    main.log.error( "Invalid rule. Valid rules are 'DROP' or "
                                    "'ACCEPT' or 'LOG' only." )
                    if direction != 'INPUT' and direction != 'OUTPUT':
                        # NOTE currently only supports rules INPUT and OUPTUT
                        main.log.error( "Invalid rule. Valid directions are"
                                        " 'OUTPUT' or 'INPUT'" )
                        return main.FALSE
                    return main.FALSE
                return main.FALSE
            if action_type == 'add':
                # -A is the 'append' action of iptables
                actionFlag = '-A'
            elif action_type == 'remove':
                # -D is the 'delete' rule of iptables
                actionFlag = '-D'
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            cmd = "sudo iptables " + actionFlag + " " +\
                  direction +\
                  " -s " + str( ip )
            # " -p " + str( packet_type ) +\
            if packet_type:
                cmd += " -p " + str( packet_type )
            if port:
                cmd += " --dport " + str( port )
            if states:
                cmd += " -m state --state="
                # FIXME- Allow user to configure which states to block
                cmd += "INVALID,ESTABLISHED,NEW,RELATED,UNTRACKED"
            cmd += " -j " + str( rule )

            self.handle.sendline( cmd )
            self.handle.expect( self.prompt )
            main.log.warn( self.handle.before )

            info_string = "On " + str( self.name )
            info_string += " " + str( action_type )
            info_string += " iptable rule [ "
            info_string += " IP: " + str( ip )
            info_string += " Port: " + str( port )
            info_string += " Rule: " + str( rule )
            info_string += " Direction: " + str( direction ) + " ]"
            main.log.info( info_string )
            return main.TRUE
        except pexpect.TIMEOUT:
            main.log.exception( self.name + ": Timeout exception in "
                                "setIpTables function" )
            self.handle.send( "\x03" )  # Control-C
            self.handle.expect( self.prompt )
            return main.ERROR
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def detailed_status( self, log_filename ):
        """
        This method is used by STS to check the status of the controller
        Reports RUNNING, STARTING, STOPPED, FROZEN, ERROR (and reason)
        """
        import re
        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            self.handle.sendline( "cd " + self.home )
            self.handle.expect( self.prompt )
            self.handle.sendline( "service onos status" )
            self.handle.expect( self.prompt )
            response = self.handle.before
            if re.search( "onos start/running", response ):
                # onos start/running, process 10457
                return 'RUNNING'
            # FIXME: Implement this case
            # elif re.search( pattern, response ):
            #      return 'STARTING'
            elif re.search( "onos stop/", response ):
                # onos stop/waiting
                # FIXME handle this differently?:  onos stop/pre-stop
                return 'STOPPED'
            # FIXME: Implement this case
            # elif re.search( pattern, response ):
            #      return 'FROZEN'
            else:
                main.log.warn( self.name +
                               " WARNING: status received unknown response" )
                main.log.warn( response )
                return 'ERROR', "Unknown response: %s" % response
        except pexpect.TIMEOUT:
            main.log.exception( self.name + ": Timeout exception in "
                                "setIpTables function" )
            self.handle.send( "\x03" )  # Control-C
            self.handle.expect( self.prompt )
            return 'ERROR', "Pexpect Timeout"
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def createLinkGraphFile( self, benchIp, ONOSIpList, deviceCount ):
        '''
            Create/formats the LinkGraph.cfg file based on arguments
                -only creates a linear topology and connects islands
                -evenly distributes devices
                -must be called by ONOSbench

                ONOSIpList - list of all of the node IPs to be used

                deviceCount - number of switches to be assigned
        '''
        main.log.info( "Creating link graph configuration file." )
        linkGraphPath = self.home + "/tools/package/etc/linkGraph.cfg"
        tempFile = "/tmp/linkGraph.cfg"

        linkGraph = open( tempFile, 'w+' )
        linkGraph.write( "# NullLinkProvider topology description (config file).\n" )
        linkGraph.write( "# The NodeId is only added if the destination is another node's device.\n" )
        linkGraph.write( "# Bugs: Comments cannot be appended to a line to be read.\n" )

        clusterCount = len( ONOSIpList )

        if isinstance( deviceCount, int ) or isinstance( deviceCount, str ):
            deviceCount = int( deviceCount )
            switchList = [ 0 ]*( clusterCount+1 )
            baselineSwitchCount = deviceCount/clusterCount

            for node in range( 1, clusterCount + 1 ):
                switchList[ node ] = baselineSwitchCount

            for node in range( 1, ( deviceCount % clusterCount )+1 ):
                switchList[ node ] += 1

        if isinstance( deviceCount, list ):
            main.log.info( "Using provided device distribution" )
            switchList = [ 0 ]
            for i in deviceCount:
                switchList.append( int( i ) )

        tempList = [ '0' ]
        tempList.extend( ONOSIpList )
        ONOSIpList = tempList

        myPort = 6
        lastSwitch = 0
        for node in range( 1, clusterCount+1 ):
            if switchList[ node ] == 0:
                continue

            linkGraph.write( "graph " + ONOSIpList[ node ] + " {\n" )

            if node > 1:
                # connect to last device on previous node
                line = ( "\t0:5 -> " + str( lastSwitch ) + ":6:" + lastIp + "\n" )  # ONOSIpList[node-1]
                linkGraph.write( line )

            lastSwitch = 0
            for switch in range( 0, switchList[ node ]-1 ):
                line = ""
                line = ( "\t" + str( switch ) + ":" + str( myPort ) )
                line += " -- "
                line += ( str( switch+1 ) + ":" + str( myPort-1 ) + "\n" )
                linkGraph.write( line )
                lastSwitch = switch+1
            lastIp = ONOSIpList[ node ]

            # lastSwitch += 1
            if node < ( clusterCount ):
                # connect to first device on the next node
                line = ( "\t" + str( lastSwitch ) + ":6 -> 0:5:" + ONOSIpList[ node+1 ] + "\n" )
                linkGraph.write( line )

            linkGraph.write( "}\n" )
        linkGraph.close()

        # SCP
        os.system( "scp " + tempFile + " " + self.user_name + "@" + benchIp + ":" + linkGraphPath )
        main.log.info( "linkGraph.cfg creation complete" )

    def configNullDev( self, ONOSIpList, deviceCount, numPorts=10 ):
        '''
            ONOSIpList = list of Ip addresses of nodes switches will be devided amongst
            deviceCount = number of switches to distribute, or list of values to use as custom distribution
            numPorts = number of ports per device. Defaults to 10 both in this function and in ONOS. Optional arg
        '''

        main.log.info( "Configuring Null Device Provider" )
        clusterCount = len( ONOSIpList )

        try:

            if isinstance( deviceCount, int ) or isinstance( deviceCount, str ):
                main.log.info( "Creating device distribution" )
                deviceCount = int( deviceCount )
                switchList = [ 0 ]*( clusterCount+1 )
                baselineSwitchCount = deviceCount/clusterCount

                for node in range( 1, clusterCount + 1 ):
                    switchList[ node ] = baselineSwitchCount

                for node in range( 1, ( deviceCount % clusterCount )+1 ):
                    switchList[ node ] += 1

            if isinstance( deviceCount, list ):
                main.log.info( "Using provided device distribution" )

                if len( deviceCount ) == clusterCount:
                    switchList = [ '0' ]
                    switchList.extend( deviceCount )

                if len( deviceCount ) == ( clusterCount + 1 ):
                    if deviceCount[ 0 ] == '0' or deviceCount[ 0 ] == 0:
                        switchList = deviceCount

                assert len( switchList ) == ( clusterCount + 1 )

        except AssertionError:
            main.log.error( "Bad device/Ip list match" )
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

        ONOSIp = [ 0 ]
        ONOSIp.extend( ONOSIpList )

        devicesString = "devConfigs = "
        for node in range( 1, len( ONOSIp ) ):
            devicesString += ( ONOSIp[ node ] + ":" + str( switchList[ node ] ) )
            if node < clusterCount:
                devicesString += ( "," )

        try:
            self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider devConfigs " + devicesString )
            self.handle.expect( ":~" )
            self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider numPorts " + str( numPorts ) )
            self.handle.expect( ":~" )

            for i in range( 10 ):
                self.handle.sendline( "onos $OC1 cfg get org.onosproject.provider.nil.device.impl.NullDeviceProvider" )
                self.handle.expect( ":~" )
                verification = self.handle.before
                if ( " value=" + str( numPorts ) ) in verification and ( " value=" + devicesString ) in verification:
                    break
                else:
                    time.sleep( 1 )

            assert ( "value=" + str( numPorts ) ) in verification and ( " value=" + devicesString ) in verification

        except AssertionError:
            main.log.error( "Incorrect Config settings: " + verification )
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def configNullLink( self, fileName="/opt/onos/apache-karaf-3.0.3/etc/linkGraph.cfg", eventRate=0 ):
        '''
                fileName default is currently the same as the default on ONOS, specify alternate file if
                you want to use a different topology file than linkGraph.cfg
        '''

        try:
            self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider eventRate " + str( eventRate ) )
            self.handle.expect( ":~" )
            self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider cfgFile " + fileName )
            self.handle.expect( ":~" )

            for i in range( 10 ):
                self.handle.sendline( "onos $OC1 cfg get org.onosproject.provider.nil.link.impl.NullLinkProvider" )
                self.handle.expect( ":~" )
                verification = self.handle.before
                if ( " value=" + str( eventRate ) ) in verification and ( " value=" + fileName ) in verification:
                    break
                else:
                    time.sleep( 1 )

            assert ( "value=" + str( eventRate ) ) in verification and ( " value=" + fileName ) in verification

        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except AssertionError:
            main.log.info( "Settings did not post to ONOS" )
            main.log.error( verification )
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.log.error( verification )
            main.cleanAndExit()

    def getOnosIps( self ):
        """
            Get all onos IPs stored in
        """

        return sorted( self.onosIps.values() )

    def listLog( self, nodeIp ):
        """
            Get a list of all the karaf log names
        """
        try:
            cmd = "onos-ssh " + nodeIp + " ls -tr /opt/onos/log"
            self.handle.sendline( cmd )
            self.handle.expect( ":~" )
            before = self.handle.before.splitlines()
            logNames = []
            for word in before:
                if 'karaf.log' in word:
                    logNames.append( word )
            return logNames
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except pexpect.TIMEOUT:
            main.log.error( self.name + ": TIMEOUT exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def logReport( self, nodeIp, searchTerms, outputMode="s", startStr=None, endStr=None ):
        """
        Searches the latest ONOS log file for the given search terms and
        prints the total occurances of each term. Returns to combined total of
        all occurances.

        Arguments:
            * nodeIp - The ip of the ONOS node where the log is located
            * searchTerms - A string to grep for or a list of strings to grep
                            for in the ONOS log. Will print out the number of
                            occurances for each term.
        Optional Arguments:
            * outputMode - 's' or 'd'. If 'd' will print the last 5 lines
                           containing each search term as well as the total
                           number of occurances of each term. Defaults to 's',
                           which prints the simple output of just the number
                           of occurances for each term.
            * startStr - the start string to be given to stream editor command
                         as the start point for extraction of data
            * endStr -  the end string to be given to stream editor command as
                        the end point for extraction of data
        """
        try:
            main.log.info( " Log Report for {} ".format( nodeIp ).center( 70, '=' ) )
            if isinstance( searchTerms, str ):
                searchTerms = [ searchTerms ]
            numTerms = len( searchTerms )
            outputMode = outputMode.lower()

            totalHits = 0
            logLines = []
            for termIndex in range( numTerms ):
                term = searchTerms[ termIndex ]
                logLines.append( [ term ] )
                if startStr and endStr:
                    cmd = "onos-ssh {} \"sed -n '/{}/,/{}/p' /opt/onos/log/karaf.log | grep {}\"".format( nodeIp,
                                                                                                          startStr,
                                                                                                          endStr,
                                                                                                          term )
                else:
                    cmd = "onos-ssh {} cat /opt/onos/log/karaf.log | grep {}".format( nodeIp,
                                                                                      term )
                self.handle.sendline( cmd )
                self.handle.expect( ":~" )
                before = self.handle.before.splitlines()
                count = 0
                for line in before:
                    if term in line and "grep" not in line:
                        count += 1
                        if before.index( line ) > ( len( before ) - 7 ):
                            logLines[ termIndex ].append( line )
                main.log.info( "{}: {}".format( term, count ) )
                totalHits += count
                if termIndex == numTerms - 1:
                    print "\n"
            if outputMode != "s":
                outputString = ""
                for term in logLines:
                    outputString = term[ 0 ] + ": \n"
                    for line in range( 1, len( term ) ):
                        outputString += ( "\t" + term[ line ] + "\n" )
                    if outputString != ( term[ 0 ] + ": \n" ):
                        main.log.info( outputString )
            main.log.info( "=" * 70 )
            return totalHits
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except pexpect.TIMEOUT:
            main.log.error( self.name + ": TIMEOUT exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def copyMininetFile( self, fileName, localPath, userName, ip,
                         mnPath='~/mininet/custom/', timeout = 60 ):
        """
        Description:
            Copy mininet topology file from dependency folder in the test folder
            and paste it to the mininet machine's mininet/custom folder
        Required:
            fileName - Name of the topology file to copy
            localPath - File path of the mininet topology file
            userName - User name of the mininet machine to send the file to
            ip - Ip address of the mininet machine
        Optional:
            mnPath - of the mininet directory to send the file to
        Return:
            Return main.TRUE if successfully copied the file otherwise
            return main.FALSE
        """

        try:
            cmd = "scp " + localPath + fileName + " " + userName + "@" + \
                  str( ip ) + ":" + mnPath + fileName

            self.handle.sendline( "" )
            self.handle.expect( self.prompt )

            main.log.info( self.name + ": Execute: " + cmd )

            self.handle.sendline( cmd )

            i = self.handle.expect( [ 'No such file',
                                      "100%",
                                      pexpect.TIMEOUT ] )

            if i == 0:
                main.log.error( self.name + ": File " + fileName +
                                " does not exist!" )
                return main.FALSE

            if i == 1:
                main.log.info( self.name + ": File " + fileName +
                                " has been copied!" )
                self.handle.sendline( "" )
                self.handle.expect( self.prompt )
                return main.TRUE

        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except pexpect.TIMEOUT:
            main.log.error( self.name + ": TIMEOUT exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()

    def jvmSet( self, memory=8 ):

        import os

        homeDir = os.path.expanduser( '~' )
        filename = "/onos/tools/package/bin/onos-service"

        serviceConfig = open( homeDir + filename, 'w+' )
        serviceConfig.write( "#!/bin/bash\n " )
        serviceConfig.write( "#------------------------------------- \n " )
        serviceConfig.write( "# Starts ONOS Apache Karaf container\n " )
        serviceConfig.write( "#------------------------------------- \n " )
        serviceConfig.write( "#export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-7-openjdk-amd64/}\n " )
        serviceConfig.write( """export JAVA_OPTS="${JAVA_OPTS:--Xms""" + str( memory ) + "G -Xmx" + str( memory ) + """G}" \n """ )
        serviceConfig.write( "[ -d $ONOS_HOME ] && cd $ONOS_HOME || ONOS_HOME=$(dirname $0)/..\n" )
        serviceConfig.write( """${ONOS_HOME}/apache-karaf-$KARAF_VERSION/bin/karaf "$@" \n """ )
        serviceConfig.close()

    def createDBFile( self, testData ):

        filename = main.TEST + "DB"
        DBString = ""

        for item in testData:
            if isinstance( item, str ):
                item = "'" + item + "'"
            if testData.index( item ) < len( testData - 1 ):
                item += ","
            DBString += str( item )

        DBFile = open( filename, "a" )
        DBFile.write( DBString )
        DBFile.close()

    def verifySummary( self, ONOSIp, *deviceCount ):

        self.handle.sendline( "onos " + ONOSIp + " summary" )
        self.handle.expect( ":~" )

        summaryStr = self.handle.before
        print "\nSummary\n==============\n" + summaryStr + "\n\n"

        # passed = "SCC(s)=1" in summaryStr
        # if deviceCount:
        #    passed = "devices=" + str(deviceCount) + "," not in summaryStr

        passed = False
        if "SCC(s)=1," in summaryStr:
            passed = True
            print "Summary is verifed"
        else:
            print "Summary failed"

        if deviceCount:
            print" ============================="
            checkStr = "devices=" + str( deviceCount[ 0 ] ) + ","
            print "Checkstr: " + checkStr
            if checkStr not in summaryStr:
                passed = False
                print "Device count failed"
            else:
                print "device count verified"

        return passed

    def getIpAddr( self, iface=None ):
        """
        Update self.ip_address with numerical ip address. If multiple IP's are
        located on the device, will attempt to use self.nicAddr to choose the
        right one. Defaults to 127.0.0.1 if no other address is found or cannot
        determine the correct address.

        ONLY WORKS WITH IPV4 ADDRESSES
        """
        try:
            LOCALHOST = "127.0.0.1"
            ipPat = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
            pattern = re.compile( ipPat )
            match = re.search( pattern, self.ip_address )
            if self.nicAddr:
                nicPat = self.nicAddr.replace( ".", "\." ).replace( "\*", r"\d{1,3}" )
                nicPat = re.compile( nicPat )
            else:
                nicPat = None
            # IF self.ip_address is an ip address and matches
            #    self.nicAddr: return self.ip_address
            if match:
                curIp = match.group( 0 )
                if nicPat:
                    nicMatch = re.search( nicPat, curIp )
                    if nicMatch:
                        return self.ip_address
            # ELSE: IF iface, return ip of interface
            cmd = "ifconfig"
            ifPat = re.compile( "inet addr:({})".format( ipPat ) )
            if iface:
                cmd += " " + str( iface )
            raw = subprocess.check_output( cmd.split() )
            ifPat = re.compile( "inet addr:({})".format( ipPat ) )
            ips = re.findall( ifPat, raw )
            if iface:
                if ips:
                    ip = ips[ 0 ]
                    self.ip_address = ip
                    return ip
                else:
                    main.log.error( "Error finding ip, ifconfig output:".format( raw ) )
            # ELSE: attempt to get address matching nicPat.
            if nicPat:
                for ip in ips:
                    curMatch = re.search( nicPat, ip )
                    if curMatch:
                        self.ip_address = ip
                        return ip
            else:  # If only one non-localhost ip, return that
                tmpList = [ ip for ip in ips if ip is not LOCALHOST ]
                if len( tmpList ) == 1:
                    curIp = tmpList[ 0 ]
                    self.ip_address = curIp
                    return curIp
            # Either no non-localhost IPs, or more than 1
            main.log.warn( "getIpAddr failed to find a public IP address" )
            return LOCALHOST
        except subprocess.CalledProcessError:
            main.log.exception( "Error executing ifconfig" )
        except IndexError:
            main.log.exception( "Error getting IP Address" )
        except Exception:
            main.log.exception( "Uncaught exception" )

    def startBasicONOS( self, nodeList, opSleep=60, onosStartupSleep=30, onosUser="sdn" ):
        '''
        Start onos cluster with defined nodes, but only with drivers app
        '''
        import time

        self.createCellFile( self.ip_address,
                             "temp",
                             self.ip_address,
                             "drivers",
                             nodeList,
                             nodeList,
                             onosUser=onosUser )

        main.log.info( self.name + ": Apply cell to environment" )
        cellResult = self.setCell( "temp" )
        verifyResult = self.verifyCell()

        main.log.info( self.name + ": Creating ONOS package" )
        packageResult = self.buckBuild( timeout=opSleep )

        main.log.info( self.name + ": Uninstalling ONOS" )
        for nd in nodeList:
            self.onosUninstall( nodeIp=nd )

        main.log.info( self.name + ": Installing ONOS package" )
        for nd in nodeList:
            self.onosInstall( node=nd )

        main.log.info( self.name + ": Set up ONOS secure SSH" )
        for nd in nodeList:
            self.onosSecureSSH( node=nd )

        main.log.info( self.name + ": Starting ONOS service" )
        time.sleep( onosStartupSleep )

        onosStatus = True
        for nd in nodeList:
            onosStatus = onosStatus & self.isup( node = nd )
            # print "onosStatus is: " + str( onosStatus )

        return main.TRUE if onosStatus else main.FALSE

    def onosNetCfg( self, controllerIp, path, fileName ):
        """
        Push a specified json file to ONOS through the onos-netcfg service

        Required:
        controllerIp - the Ip of the ONOS node in the cluster
        path - the location of the file to be sent
        fileName - name of the json file to be sent

        Returns main.TRUE on successfully sending json file, and main.FALSE if
        there is an error.
        """
        try:
            cmd = "onos-netcfg {0} {1}{2}".format( controllerIp, path, fileName )
            main.log.info( "Sending: " + cmd )
            main.ONOSbench.handle.sendline( cmd )
            main.ONOSbench.handle.expect( self.prompt )
            handle = self.handle.before
            if "Error" in handle or "No such file or directory" in handle or "curl: " in handle:
                main.log.error( self.name + ":    " + handle + self.handle.after )
                return main.FALSE
            return main.TRUE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def formCluster( self, onosIPs ):
        """
            From ONOS cluster for IP addresses in onosIPs list
        """
        try:
            onosIPs = " ".join( onosIPs )
            command = "onos-form-cluster {}".format(  onosIPs )
            main.log.info( "Sending: " + command )
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            self.handle.sendline( command )
            self.handle.expect( self.prompt )
            handle = self.handle.before
            main.log.debug( handle )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Error" not in handle, handle
            assert "Exception:" not in handle, handle
            assert "curl:" not in handle, handle
            return main.TRUE
        except AssertionError:
            main.log.exception( "{} Error in onos-form-cluster output:".format( self.name ) )
            return main.FALSE
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def backupData( self, location ):
        """
            Backs up ONOS data and logs to a given location. Returns main.FALSE
            if there is an error executing the command, and main.TRUE otherwise.
            required arguments:
            loaction - The file path to save the backup to
        """
        try:
            cmd = "/opt/onos/bin/onos-backup " + str( location )
            self.handle.sendline( cmd )
            self.handle.expect( self.prompt )
            handle = self.handle.before
            main.log.debug( handle )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Error" not in handle, handle
            assert "Exception:" not in handle, handle
            return main.TRUE
        except AssertionError:
            main.log.exception( "{} Error in onos-backup output:".format( self.name ) )
            return main.FALSE
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def restoreData( self, location ):
        """
            Restores ONOS data and logs from a given location. Returns main.FALSE
            if there is an error executing the command, and main.TRUE otherwise.
            required arguments:
            loaction - The file path of a backup file
        """
        try:
            cmd = "/opt/onos/bin/onos-restore " + str( location )
            self.handle.sendline( cmd )
            self.handle.expect( self.prompt )
            handle = self.handle.before
            main.log.debug( handle )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Error" not in handle, handle
            assert "Exception:" not in handle, handle
            return main.TRUE
        except AssertionError:
            main.log.exception( "{} Error in onos-restore output:".format( self.name ) )
            return main.FALSE
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosDiagnostics( self, onosIPs, dstDir, suffix, timeout=300 ):
        """
            Run onos-diagnostics with given ONOS instance IPs and save output to dstDir
            with suffix specified E.g. onos-diags-suffix.tar.gz
            required arguments:
                onosIPs - list of ONOS IPs for collecting diags
                dstDir - diags file will be saved under the directory specified
                suffix - diags file will be named with the suffix specified
            returns:
                main.FALSE if there's an error executing the command, and main.TRUE otherwise
        """
        try:
            cmd = "onos-diagnostics"
            assert isinstance( onosIPs, list )
            for ip in onosIPs:
                cmd += " " + str( ip )
            self.handle.sendline( cmd )
            self.handle.expect( self.prompt, timeout=timeout )
            handle = self.handle.before
            main.log.debug( handle )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Exception:" not in handle, handle
            # Rename and move diags file to dstDir from /tmp
            if dstDir[ -1: ] != "/":
                dstDir += "/"
            self.handle.sendline( "mv /tmp/onos-diags.tar.gz " + str( dstDir ) + "onos-diags" + str( suffix ) + ".tar.gz" )
            self.handle.expect( self.prompt )
            handle = self.handle.before
            main.log.debug( handle )
            assert handle is not None, "Error in sendline"
            assert "No such file or directory" not in handle, handle
            return main.TRUE
        except AssertionError:
            main.log.exception( "{} Error in onos-diagnostics output:".format( self.name ) )
            return main.FALSE
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.FALSE
        except pexpect.TIMEOUT:
            main.log.exception( self.name + ": TIMEOUT exception found in onosDiagnostics" )
            main.log.error( self.name + ":    " + self.handle.before )
            self.exitFromCmd( self.prompt, 100 )
            return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def onosPower( self, onosIP, toggle, userName=None ):
        """
            Run onos-power script to tell the cell warden to simulate a power faulure
            for the given container.
            required :
                onosIP - ONOS node IP
                toggle - either "off" or "on", used to indicate whether
                      the node should be powered off or on
            returns:
                main.FALSE if there's an error executing the command, and main.TRUE otherwise
        """
        try:
            cmd = "onos-power {} {}".format( onosIP, toggle )
            if userName:
                cmd += " {}".format( userName )
            self.handle.sendline( cmd )
            self.handle.expect( self.prompt )
            handle = self.handle.before
            main.log.debug( handle )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Exception:" not in handle, handle
            assert "usage:" not in handle, handle
            return main.TRUE
        except AssertionError:
            main.log.exception( "{} Error in onos-power output:".format( self.name ) )
            return main.FALSE
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def atomixKill( self, nodeIp ):
        """
        Calls the command: 'atomix-kill [<node-ip>]'
        Kills the Atomix instance running on the specified node
        """
        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            self.handle.sendline( "atomix-kill " + str( nodeIp ) )
            i = self.handle.expect( [
                self.prompt,
                "No\sroute\sto\shost",
                "password:",
                pexpect.TIMEOUT ], timeout=60 )

            if i == 0:
                main.log.info( "Atomix instance " + str( nodeIp ) + " was killed" )
                return main.TRUE
            elif i == 1:
                main.log.info( "No route to host" )
                return main.FALSE
            elif i == 2:
                main.log.info( "Passwordless login for host: " + str( nodeIp ) + " not configured" )
                return main.FALSE
            else:
                main.log.info( "Atomix instance was not killed" )
                return main.FALSE

        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def atomixUninstall( self, nodeIp="" ):
        """
        Calls the command: 'atomix-uninstall'
        Uninstalls Atomix from the designated node, stopping if needed
        """
        try:
            self.handle.sendline( "" )
            self.handle.expect( self.prompt, timeout=180 )
            self.handle.sendline( "atomix-uninstall " + str( nodeIp ) )
            self.handle.expect( self.prompt, timeout=180 )
            main.log.info( "Atomix " + nodeIp + " was uninstalled" )
            # onos-uninstall command does not return any text
            return main.TRUE
        except pexpect.TIMEOUT:
            main.log.exception( self.name + ": Timeout in atomixUninstall" )
            self.handle.send( "\x03" )  # Control-C
            self.handle.expect( self.prompt )
            return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def atomixInstall( self, options="", node="" ):
        """
        Installs Atomix on the designated nodes.
        Returns: main.TRUE on success and main.FALSE on failure
        """
        try:
            if options:
                self.handle.sendline( "atomix-install " + options + " " + node )
            else:
                self.handle.sendline( "atomix-install " + node )
            self.handle.expect( "atomix-install " )
            i = self.handle.expect( [ "Network\sis\sunreachable",
                                      "is already installed",
                                      "saved",
                                      self.prompt,
                                      pexpect.TIMEOUT ], timeout=180 )
            if i == 0:
                # can't reach ONOS node
                main.log.warn( self.name + ": Network is unreachable" )
                self.handle.expect( self.prompt )
                return main.FALSE
            elif i == 1:
                # same bits are already on Atomix node
                main.log.info( self.name + ": Atomix is already installed on " + node )
                self.handle.expect( self.prompt )
                return main.TRUE
            elif i == 2:
                main.log.info( self.name + ": Atomix was installed on " + node )
                self.handle.expect( self.prompt )
                return main.TRUE
            elif i == 3:
                self.handle.sendline( "echo Return code: $?" )
                self.handle.expect( "\$\?" )
                self.handle.expect( self.prompt )
                match = re.search( "Return code: (\d+)", self.handle.before )
                if match:
                    exitCode = int( match.group( 1 ) )
                else:
                    # Didn't match pattern
                    main.log.error( "Could not parse exit code of atomix-install" )
                    main.log.debug( self.handle.before + self.handle.before )
                    return main.FALSE
                if exitCode == 0:
                    return main.TRUE
                else:
                    main.log.error( "Unsuccessful exit code of atomix-install" )
                    main.log.debug( self.handle.before + self.handle.before )
                    return main.FALSE
            elif i == 4:
                # timeout
                main.log.info( self.name + ": Installation of Atomix on " + node + " timed out" )
                self.handle.expect( self.prompt )
                main.log.warn( self.handle.before )
                self.handle.send( "\x03" )  # Control-C
                self.handle.expect( self.prompt )
                return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ": " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()
