#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
OCT 13 2014
Copyright 2014 Open Networking Foundation (ONF)

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>

    TestON is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    TestON is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with TestON.  If not, see <http://www.gnu.org/licenses/>.
"""

"""
This driver enters the onos> prompt to issue commands.

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
shreya@onlab.us
jeremyr@opennetworking.org
"""
import ipaddress
import pexpect
import re
import json
import types
import time
import os
from drivers.common.clidriver import CLI
from core.graph import Graph
from cStringIO import StringIO
from itertools import izip

class OnosCliDriver( CLI ):

    def __init__( self ):
        """
        Initialize client
        """
        self.name = None
        self.home = None
        self.handle = None
        self.karafUser = None
        self.karafPass = None
        self.karafPort = None
        self.karafTimeout = None
        self.address = None
        self.karafPromptUser = None
        self.dockerPrompt = None
        self.graph = Graph()
        super( OnosCliDriver, self ).__init__()

    def connect( self, **connectargs ):
        """
        Creates ssh handle for ONOS cli.
        """
        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[ key ]
                elif key == "karaf_username":
                    self.karafUser = self.options[ key ]
                elif key == "karaf_password":
                    self.karafPass = self.options[ key ]
                elif key == "docker_prompt":
                    self.dockerPrompt = self.options[ key ]
                elif key == "karaf_timeout":
                    self.karafTimeout = self.options[ key ]
                elif key == "karaf_port":
                    self.karafPort = self.options[ key ]
                elif key == "karafPromptUser":
                    self.karafPromptUser = self.options[ key ]
            self.home = self.checkOptions( self.home, "~/onos" )
            self.karafUser = self.checkOptions( self.karafUser, self.user_name )
            self.karafPass = self.checkOptions( self.karafPass, self.pwd )
            self.karafPort = self.checkOptions( self.karafPort, 8101 )
            self.dockerPrompt = self.checkOptions( self.dockerPrompt, "~/onos#" )
            self.karafTimeout = self.checkOptions( self.karafTimeout, 7200000  )

            self.karafPrompt = self.karafPromptUser + "@root >"
            for key in self.options:
                if key == 'onosIp':
                    self.onosIp = self.options[ 'onosIp' ]
                    break

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

            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( OnosCliDriver, self ).connect(
                user_name=self.user_name,
                ip_address=self.ip_address,
                port=self.port,
                pwd=self.pwd,
                home=self.home )

            self.handle.sendline( "cd " + self.home )
            self.handle.expect( self.prompt )
            if self.handle:
                self.address = self.ip_address
                return self.handle
            else:
                main.log.info( "NO ONOS HANDLE" )
                return main.FALSE
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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:
                i = self.logout()
                if i == main.TRUE:
                    self.handle.sendline( "" )
                    for l in range( 3 ):
                        p = self.handle.expect( [ self.prompt, self.dockerPrompt ] )
                        if p == 1:
                            self.inDocker = False
                        self.handle.sendline( "exit" )
                        j = self.handle.expect( [ "closed", pexpect.TIMEOUT ], timeout=3 )
                        if j == 0:
                            return response
                    response = main.FALSE
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            response = main.FALSE
        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 + ": disconnection failed from the host" )
            response = main.FALSE
        return response

    def logout( self ):
        """
        Sends 'logout' command to ONOS cli
        Returns main.TRUE if exited CLI and
                main.FALSE on timeout (not guranteed you are disconnected)
                None on TypeError
                Exits test on unknown error or pexpect exits unexpectedly
        """
        try:
            if self.handle:
                self.handle.sendline( "" )
                i = self.handle.expect( [ self.karafPrompt,
                                          self.Prompt(),
                                          pexpect.TIMEOUT ],

                                        timeout=10 )
                if i == 0:  # In ONOS CLI
                    self.handle.sendline( "logout" )
                    j = self.handle.expect( [ self.Prompt(),
                                              "Command not found:",
                                              pexpect.TIMEOUT ] )
                    if j == 0:  # Successfully logged out
                        return main.TRUE
                    elif j == 1 or j == 2:
                        # ONOS didn't fully load, and logout command isn't working
                        # or the command timed out
                        self.handle.send( "\x04" )  # send ctrl-d
                        try:
                            self.handle.expect( self.Prompt() )
                        except pexpect.TIMEOUT:
                            main.log.error( "ONOS did not respond to 'logout' or CTRL-d" )
                        return main.TRUE
                    else:  # some other output
                        main.log.warn( "Unknown repsonse to logout command: '{}'",
                                       repr( self.handle.before ) )
                        return main.FALSE
                elif i == 1:  # not in CLI
                    return main.TRUE
                elif i == 2:  # Timeout
                    return main.FALSE
            else:
                return main.TRUE
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except pexpect.EOF:
            main.log.error( self.name + ": eof exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except ValueError:
            main.log.error( self.name +
                            "ValueError exception in logout method" )
        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

        Before issuing any cli commands, set the environment variable first.
        """
        try:
            if not cellname:
                main.log.error( "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 ) )
                handleBefore = self.handle.before
                handleAfter = self.handle.after
                # Get the rest of the handle
                self.handle.sendline( "" )
                self.handle.expect( self.prompt )
                handleMore = self.handle.before

                main.log.info( "Cell call returned: " + handleBefore +
                               handleAfter + handleMore )

                return main.TRUE

        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 startOnosCli( self, ONOSIp, karafTimeout="",
                      commandlineTimeout=10, onosStartTimeout=60, waitForStart=False ):
        """
        karafTimeout is an optional argument. karafTimeout value passed
        by user would be used to set the current karaf shell idle timeout.
        Note that when ever this property is modified the shell will exit and
        the subsequent login would reflect new idle timeout.
        Below is an example to start a session with 60 seconds idle timeout
        ( input value is in milliseconds ):

        tValue = "60000"
        main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue )

        Note: karafTimeout is left as str so that this could be read
        and passed to startOnosCli from PARAMS file as str.
        """
        self.onosIp = ONOSIp
        self.address = self.onosIp
        try:
            # Check if we are already in the cli
            self.handle.sendline( "" )
            x = self.handle.expect( [ self.Prompt(), self.karafPrompt ], commandlineTimeout )
            if x == 1:
                main.log.info( "ONOS cli is already running" )
                return main.TRUE

            # Not in CLI so login
            if self.inDocker:
                # The Docker does not have all the wrapper scripts
                startCliCommand = "ssh -p %s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null %s@localhost" % ( self.karafPort, self.karafUser )
            elif waitForStart:
                # Wait for onos start ( onos-wait-for-start ) and enter onos cli
                startCliCommand = "onos-wait-for-start " + str( ONOSIp )
            else:
                startCliCommand = "onos " + str( ONOSIp )
            self.handle.sendline( startCliCommand )
            tries = 0
            timeoutSet = False
            while tries < 5:
                i = self.handle.expect( [
                    self.karafPrompt,
                    "Password:",
                    pexpect.TIMEOUT ], onosStartTimeout )

                if i == 0:
                    if not karafTimeout or timeoutSet:
                        main.log.info( str( ONOSIp ) + " CLI Started successfully" )
                        return main.TRUE
                    if karafTimeout:
                        self.handle.sendline(
                            "config:property-set -p org.apache.karaf.shell\
                                     sshIdleTimeout " +
                            str( karafTimeout ) )
                        self.handle.expect( "closed by remote host" )
                        self.handle.expect( self.Prompt() )
                        self.handle.sendline( startCliCommand )
                        timeoutSet = True
                elif i == 1:
                    main.log.info( str( ONOSIp ) + " CLI asking for password" )
                    main.log.debug( "Sending %s" % self.karafPass )
                    self.handle.sendline( self.karafPass )
                else:
                    # If failed, send ctrl+c to process and try again
                    main.log.info( "Starting CLI failed. Retrying..." )
                    time.sleep( 5 )
                    self.handle.send( "\x03" )
                    self.handle.sendline( startCliCommand )
                tries += 1
            main.log.error( "Connection to CLI " + str( ONOSIp ) + " timeout" )
            return main.FALSE
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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.debug( self.handle.before + str( self.handle.after ) )
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def startCellCli( self, karafTimeout="",
                      commandlineTimeout=10, onosStartTimeout=60 ):
        """
        Start CLI on onos cell handle.

        karafTimeout is an optional argument. karafTimeout value passed
        by user would be used to set the current karaf shell idle timeout.
        Note that when ever this property is modified the shell will exit and
        the subsequent login would reflect new idle timeout.
        Below is an example to start a session with 60 seconds idle timeout
        ( input value is in milliseconds ):

        tValue = "60000"

        Note: karafTimeout is left as str so that this could be read
        and passed to startOnosCli from PARAMS file as str.
        """

        try:
            self.handle.sendline( "" )
            x = self.handle.expect( [
                self.Prompt(), self.karafPrompt ], commandlineTimeout )

            if x == 1:
                main.log.info( "ONOS cli is already running" )
                return main.TRUE

            # Wait for onos start ( onos-wait-for-start ) and enter onos cli
            self.handle.sendline( "/opt/onos/bin/onos" )
            i = self.handle.expect( [
                self.karafPrompt,
                pexpect.TIMEOUT ], onosStartTimeout )

            if i == 0:
                main.log.info( self.name + " CLI Started successfully" )
                if karafTimeout:  # FIXME: This doesn't look right
                    self.handle.sendline(
                        "config:property-set -p org.apache.karaf.shell\
                                 sshIdleTimeout " +
                        karafTimeout )
                    self.handle.expect( self.Prompt() )
                    self.handle.sendline( "/opt/onos/bin/onos" )
                    self.handle.expect( self.karafPrompt )
                return main.TRUE
            else:
                # If failed, send ctrl+c to process and try again
                main.log.info( "Starting CLI failed. Retrying..." )
                self.handle.send( "\x03" )
                self.handle.sendline( "/opt/onos/bin/onos" )
                i = self.handle.expect( [ self.karafPrompt, pexpect.TIMEOUT ],
                                        timeout=30 )
                if i == 0:
                    main.log.info( self.name + " CLI Started " +
                                   "successfully after retry attempt" )
                    if karafTimeout:
                        self.handle.sendline(
                            "config:property-set -p org.apache.karaf.shell\
                                    sshIdleTimeout " +
                            karafTimeout )
                        self.handle.expect( self.Prompt() )
                        self.handle.sendline( "/opt/onos/bin/onos" )
                        self.handle.expect( self.karafPrompt )
                    return main.TRUE
                else:
                    main.log.error( "Connection to CLI " +
                                    self.name + " timeout" )
                    return main.FALSE

        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 log( self, cmdStr, level="", noExit=False ):
        """
            log the commands in the onos CLI.
            returns main.TRUE on success
            returns main.FALSE if Error occurred
            if noExit is True, TestON will not exit, but clean up
            Available level: DEBUG, TRACE, INFO, WARN, ERROR
            Level defaults to INFO
            if cmdStr has spaces then put quotes in the passed string
        """
        try:
            lvlStr = ""
            if level:
                lvlStr = "--level=" + level
            handle = self.sendline( "log:log " + lvlStr + " " + cmdStr, noExit=noExit )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in logging message" )
                main.log.error( handle )
                return main.FALSE
            else:
                return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            if noExit:
                main.cleanup()
                return None
            else:
                main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            if noExit:
                main.cleanup()
                return None
            else:
                main.cleanAndExit()

    def clearBuffer( self, debug=False, timeout=10, noExit=False ):
        """
        Test cli connection and clear any left over output in the buffer
        Optional Arguments:
        debug - Defaults to False. If True, will enable debug logging.
        timeout - Defaults to 10. Amount of time in seconds for a command to return
                  before a timeout.
        noExit - Defaults to False. If True, will not exit TestON in the event of a
        """
        try:
            # Try to reconnect if disconnected from cli
            self.handle.sendline( "" )
            i = self.handle.expect( [ self.karafPrompt,
                                      self.Prompt(),
                                      pexpect.TIMEOUT ] )
            response = self.handle.before
            if i == 1:  # Not in ONOS CLI
                # FIXME: This isn't really the correct place for this, but it works for now
                # Check if port-forward session is still up first
                if hasattr( main, "Cluster"):
                    ctrl = None
                    for c in main.Cluster.controllers:
                        if c.CLI is self:
                            ctrl = c
                            break
                    if not ctrl:
                        main.log.warn( self.name + ": Could not find this node in Cluster. Can't check port-forward status" )
                    elif ctrl.k8s:
                        ctrl.k8s.checkPortForward( ctrl.k8s.podName,
                                                   kubeconfig=ctrl.k8s.kubeConfig,
                                                   namespace=main.params[ 'kubernetes' ][ 'namespace' ] )
                main.log.error( self.name + ": onos cli session closed. " )
                if self.onosIp:
                    main.log.warn( "Trying to reconnect " + self.onosIp )
                    reconnectResult = self.startOnosCli( self.onosIp )
                    if reconnectResult:
                        main.log.info( self.name + ": onos cli session reconnected." )
                    else:
                        main.log.error( self.name + ": reconnection failed." )
                        if noExit:
                            return None
                        else:
                            main.cleanAndExit()
                else:
                    main.cleanAndExit()
            if i == 2:
                main.log.warn( "Timeout when testing cli responsiveness" )
                main.log.debug( "%s: %s" % ( self.name, self.handle.before ) )
                self.handle.send( "\x03" )  # Send ctrl-c to clear previous output
                self.handle.expect( self.karafPrompt )

            response += self.handle.before
            if debug:
                main.log.debug( self.name + ": Raw output from sending ''" )
                main.log.debug( self.name + ": " + repr( response ) )
        except pexpect.TIMEOUT:
            main.log.error( self.name + ": ONOS timeout" )
            main.log.debug( "%s: %s" % ( self.name, self.handle.before ) )
            self.handle.send( "\x03" )
            self.handle.expect( self.karafPrompt )
            return None
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            if noExit:
                return None
            else:
                main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            if noExit:
                return None
            else:
                main.cleanAndExit()

    def sendline( self, cmdStr, showResponse=False, debug=False, timeout=10, noExit=False, relaxedRegex=True, expectJson=False ):
        """
        A wrapper around pexpect's sendline/expect. Will return all the output from a given command

        Required Arguments:
        cmdStr - String to send to the pexpect session

        Optional Arguments:
        showResponse - Defaults to False. If True will log the response.
        debug - Defaults to False. If True, will enable debug logging.
        timeout - Defaults to 10. Amount of time in seconds for a command to return
                  before a timeout.
        noExit - Defaults to False. If True, will not exit TestON in the event of a
                 closed channel, but instead return None
        relaxedRegex - Defaults to True. If there is a pipe in the command send, will only try to match the last part of the piped command.

        Warning: There are no sanity checking to commands sent using this method.

        """
        try:
            # Try to reconnect if disconnected from cli
            self.clearBuffer( debug=debug, timeout=timeout, noExit=noExit )
            if debug:
                # NOTE: This adds an average of .4 seconds per call
                logStr = "\"Sending CLI command: '" + cmdStr + "'\""
                self.log( logStr, noExit=noExit )
            self.handle.sendline( cmdStr )
            self.handle.expect( self.karafPrompt, timeout )
            response = self.handle.before
            main.log.info( "Command '" + str( cmdStr ) + "' sent to "
                           + self.name + "." )
            if debug:
                main.log.debug( self.name + ": Raw output" )
                main.log.debug( self.name + ": " + repr( response ) )

            response = self.cleanOutput( response, debug=debug )
            # Remove control codes from karaf 4.2.1
            karafEscape = re.compile( r"('(0|1)~\'|\r\r\r\n\x1b\[A\x1b\[79C(x|\s)?|\x1b(>|=~?)|\x1b\[90m~)" )
            response = karafEscape.sub( '', response )
            if debug:
                main.log.debug( self.name + ": karafEscape output" )
                main.log.debug( self.name + ": " + repr( response ) )
            # Remove ANSI color control strings from output
            response = self.cleanOutput( response, debug )

            # Remove ANSI color control strings from output
            # NOTE: karaf is sometimes adding a single character then two
            #       backspaces and sometimes adding 2 characters with 2 backspaces??
            backspaceEscape = re.compile( r'((.|\s)\x08)' )
            unchanged = False
            while not unchanged:
                old = response
                response = backspaceEscape.sub( '', response, count=1 )
                if debug:
                    main.log.debug( self.name + ": backspaceEscape output" )
                    main.log.debug( self.name + ": " + repr( response ) )
                unchanged = old == response

            # Remove extra return chars that get added
            response = re.sub(  r"\s\r", "", response )
            if debug:
                main.log.debug( self.name + ": Removed extra returns " +
                                "from output" )
                main.log.debug( self.name + ": " + repr( response ) )

            # Strip excess whitespace
            response = response.strip()
            if debug:
                main.log.debug( self.name + ": parsed and stripped output" )
                main.log.debug( self.name + ": " + repr( response ) )

            # parse for just the output, remove the cmd from response
            cmdPattern = cmdStr.strip()
            main.log.debug( "REGEX PATTERN SET TO: " + repr( cmdPattern ) +
                            "\nSENT COMMAND STRING WAS: " + repr( cmdStr ) )
            if relaxedRegex:
                cmdPattern = cmdPattern.split( '|' )[ -1 ].strip()
                main.log.debug( "REGEX PATTERN SET TO: " + repr( cmdPattern ) +
                                "\nSENT COMMAND STRING WAS: " + repr( cmdStr ) )
                # This was added because karaf 4.2 is stripping some characters from the command echo
                output = response.split( cmdPattern, 1 )
                if expectJson:
                    main.log.warn( "Relaxed Regex: Searching for a json string amongst the output" )
                    jsonPattern = r'\{.*\}'
                    match = re.search( jsonPattern, output[ 0 ] )
                    if match:
                        output = [ '' , match.group( 0 ) ]  # We expect a list with the second element to be the output
                if len( output ) < 2:
                    main.log.warn( "Relaxing regex match to last 5 characters of the sent command" )
                    cmdPattern = cmdPattern[ -5: ]
                    main.log.debug( "REGEX PATTERN SET TO: " + repr( cmdPattern ) +
                                    "\nSENT COMMAND STRING WAS: " + repr( cmdStr ) )
                    output = response.split( cmdPattern, 1 )
            else:
                output = response.split( cmdPattern, 1 )
                if len( output ) < 2:  # TODO: Should we do this without the relaxedRegex flag?
                    main.log.warn( "Relaxing regex match to last 5 characters of the sent command" )
                    output = response.split( cmdPattern[ -5: ], 1 )
            if output:
                if debug:
                    main.log.debug( self.name + ": split output" )
                    for r in output:
                        main.log.debug( self.name + ": " + repr( r ) )
                if len( output ) == 1:
                    main.log.error( "Could not remove sent command echo from output" )
                    return output
                output = output[ 1 ].strip()
            if showResponse:
                main.log.info( "Response from ONOS: {}".format( output ) )
            self.clearBuffer( debug=debug, timeout=timeout, noExit=noExit )
            return output
        except pexpect.TIMEOUT:
            main.log.error( self.name + ": ONOS timeout" )
            if debug:
                main.log.debug( "%s: %s" % ( self.name, self.handle.before ) )
            self.exitFromCmd( self.karafPrompt, 100 )
            return None
        except IndexError:
            main.log.exception( self.name + ": Object not as expected" )
            main.log.debug( "response: {}".format( repr( response ) ) )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            if noExit:
                return None
            else:
                main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            if noExit:
                return None
            else:
                main.cleanAndExit()

    def lineCount( self, cmdStr, showResponse=False, debug=False, timeout=10, noExit=False, relaxedRegex=True ):
        """
        A wrapper around sendline(). Will return the number of lines returned or None on error

        Required Arguments:
        cmdStr - String to send to the pexpect session

        Optional Arguments:
        showResponse - Defaults to False. If True will log the response.
        debug - Defaults to False. If True, will enable debug logging.
        timeout - Defaults to 10. Amount of time in seconds for a command to return
                  before a timeout.
        noExit - Defaults to False. If True, will not exit TestON in the event of a
                 closed channel, but instead return None
        relaxedRegex - Defaults to True. If there is a pipe in the command send, will only try to match the last part of the piped command.

        Warning: There are no sanity checking to commands sent using this method.

        """
        try:
            numLines = self.sendline( cmdStr, showResponse, debug, timeout, noExit, relaxedRegex )
            parsed = re.search( "(\d+)", numLines )
            if not parsed:
                main.log.error( "Warning, output of karaf's wc may have changed" )
                return None
            return parsed.group( 1 )
        except IndexError:
            main.log.exception( self.name + ": Object not as expected" )
            main.log.debug( "response: {}".format( repr( numLines ) ) )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            if noExit:
                return None
            else:
                main.cleanAndExit()

    # IMPORTANT NOTE:
    # For all cli commands, naming convention should match
    # the cli command changing 'a:b' with 'aB'.
    # Ex ) onos:topology > onosTopology
    #    onos:links    > onosLinks
    #    feature:list  > featureList

    def addNode( self, nodeId, ONOSIp, tcpPort="" ):
        """
        Adds a new cluster node by ID and address information.
        Required:
            * nodeId
            * ONOSIp
        Optional:
            * tcpPort
        """
        try:
            cmdStr = "add-node " + str( nodeId ) + " " +\
                str( ONOSIp ) + " " + str( tcpPort )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in adding node" )
                main.log.error( handle )
                return main.FALSE
            else:
                main.log.info( "Node " + str( ONOSIp ) + " added" )
                return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 removeNode( self, nodeId ):
        """
        Removes a cluster by ID
        Issues command: 'remove-node [<node-id>]'
        Required:
            * nodeId
        """
        try:

            cmdStr = "remove-node " + str( nodeId )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in removing node" )
                main.log.error( handle )
                return main.FALSE
            else:
                return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 nodes( self, jsonFormat=True ):
        """
        List the nodes currently visible
        Issues command: 'nodes'
        Optional argument:
            * jsonFormat - boolean indicating if you want output in json
        """
        try:
            cmdStr = "nodes"
            if jsonFormat:
                cmdStr += " -j"
            output = self.sendline( cmdStr )
            assert output is not None, "Error in sendline"
            # "Command not found" or "Service org.onosproject.security.AuditService not found"
            assert "not found" not in output, output
            return output
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 topology( self ):
        """
        Definition:
            Returns the output of topology command.
        Return:
            topology = current ONOS topology
        """
        try:
            cmdStr = "topology -j"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            main.log.info( cmdStr + " returned: " + str( handle ) )
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 deviceRemove( self, deviceId ):
        """
        Removes particular device from storage

        TODO: refactor this function
        """
        try:
            cmdStr = "device-remove " + str( deviceId )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in removing device" )
                main.log.error( handle )
                return main.FALSE
            else:
                return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 devices( self, jsonFormat=True, timeout=30 ):
        """
        Lists all infrastructure devices or switches
        Optional argument:
            * jsonFormat - boolean indicating if you want output in json
        """
        try:
            cmdStr = "devices"
            if jsonFormat:
                cmdStr += " -j"
            handle = self.sendline( cmdStr, timeout=timeout )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 balanceMasters( self ):
        """
        This balances the devices across all controllers
        by issuing command: 'onos> onos:balance-masters'
        If required this could be extended to return devices balanced output.
        """
        try:
            cmdStr = "onos:balance-masters"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in balancing masters" )
                main.log.error( handle )
                return main.FALSE
            else:
                return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 checkMasters( self, jsonFormat=True  ):
        """
            Returns the output of the masters command.
            Optional argument:
                * jsonFormat - boolean indicating if you want output in json
        """
        try:
            cmdStr = "onos:masters"
            if jsonFormat:
                cmdStr += " -j"
            output = self.sendline( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            return output
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 checkBalanceMasters( self, jsonFormat=True ):
        """
            Uses the master command to check that the devices' leadership
            is evenly divided

            Dependencies: checkMasters() and summary()

            Returns main.TRUE if the devices are balanced
            Returns main.FALSE if the devices are unbalanced
            Exits on Exception
            Returns None on TypeError
        """
        try:
            summaryOutput = self.summary()
            totalDevices = json.loads( summaryOutput )[ "devices" ]
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summaryOutput ) )
            return None
        try:
            totalOwnedDevices = 0
            mastersOutput = self.checkMasters()
            masters = json.loads( mastersOutput )
            first = masters[ 0 ][ "size" ]
            for master in masters:
                totalOwnedDevices += master[ "size" ]
                if master[ "size" ] > first + 1 or master[ "size" ] < first - 1:
                    main.log.error( "Mastership not balanced" )
                    main.log.info( "\n" + self.checkMasters( False ) )
                    return main.FALSE
            main.log.info( "Mastership balanced between " +
                           str( len( masters ) ) + " masters" )
            return main.TRUE
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, mastersOutput ) )
            return None
        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 links( self, jsonFormat=True, timeout=30 ):
        """
        Lists all core links
        Optional argument:
            * jsonFormat - boolean indicating if you want output in json
        """
        try:
            cmdStr = "links"
            if jsonFormat:
                cmdStr += " -j"
            handle = self.sendline( cmdStr, timeout=timeout )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 ports( self, jsonFormat=True, timeout=30 ):
        """
        Lists all ports
        Optional argument:
            * jsonFormat - boolean indicating if you want output in json
        """
        try:
            cmdStr = "ports"
            if jsonFormat:
                cmdStr += " -j"
            handle = self.sendline( cmdStr, timeout=timeout )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 roles( self, jsonFormat=True ):
        """
        Lists all devices and the controllers with roles assigned to them
        Optional argument:
            * jsonFormat - boolean indicating if you want output in json
        """
        try:
            cmdStr = "roles"
            if jsonFormat:
                cmdStr += " -j"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 getRole( self, deviceId ):
        """
        Given the a string containing the json representation of the "roles"
        cli command and a partial or whole device id, returns a json object
        containing the roles output for the first device whose id contains
        "device_id"

        Returns:
        A dict of the role assignments for the given device or
        None if no match
        """
        try:
            if deviceId is None:
                return None
            else:
                rawRoles = self.roles()
                rolesJson = json.loads( rawRoles )
                # search json for the device with id then return the device
                for device in rolesJson:
                    # print device
                    if str( deviceId ) in device[ 'id' ]:
                        return device
            return None
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) )
            return None
        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 rolesNotNull( self ):
        """
        Iterates through each device and checks if there is a master assigned
        Returns: main.TRUE if each device has a master
                 main.FALSE any device has no master
        """
        try:
            rawRoles = self.roles()
            rolesJson = json.loads( rawRoles )
            # search json for the device with id then return the device
            for device in rolesJson:
                # print device
                if device[ 'master' ] == "none":
                    main.log.warn( "Device has no master: " + str( device ) )
                    return main.FALSE
            return main.TRUE
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) )
            return None
        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 paths( self, srcId, dstId ):
        """
        Returns string of paths, and the cost.
        Issues command: onos:paths <src> <dst>
        """
        try:
            cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in getting paths" )
                return ( handle, "Error" )
            else:
                path = handle.split( ";" )[ 0 ]
                cost = handle.split( ";" )[ 1 ]
                return ( path, cost )
        except AssertionError:
            main.log.exception( "" )
            return ( handle, "Error" )
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return ( handle, "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 hosts( self, jsonFormat=True ):
        """
        Lists all discovered hosts
        Optional argument:
            * jsonFormat - boolean indicating if you want output in json
        """
        try:
            cmdStr = "hosts"
            if jsonFormat:
                cmdStr += " -j"
            handle = self.sendline( cmdStr )
            if handle:
                assert "Command not found:" not in handle, handle
                # TODO: Maybe make this less hardcoded
                # ConsistentMap Exceptions
                assert "org.onosproject.store.service" not in handle
                # Node not leader
                assert "java.lang.IllegalStateException" not in handle
            return handle
        except AssertionError:
            main.log.exception( self.name + ": Error in processing '" + cmdStr + "' " +
                                "command: " + str( handle ) )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 getHost( self, mac ):
        """
        Return the first host from the hosts api whose 'id' contains 'mac'

        Note: mac must be a colon separated mac address, but could be a
              partial mac address

        Return None if there is no match
        """
        try:
            if mac is None:
                return None
            else:
                mac = mac
                rawHosts = self.hosts()
                hostsJson = json.loads( rawHosts )
                # search json for the host with mac then return the device
                for host in hostsJson:
                    # print "%s in  %s?" % ( mac, host[ 'id' ] )
                    if not host:
                        pass
                    elif mac in host[ 'id' ]:
                        return host
            return None
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawHosts ) )
            return None
        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 getHostsId( self, hostList ):
        """
        Obtain list of hosts
        Issues command: 'onos> hosts'

        Required:
            * hostList: List of hosts obtained by Mininet
        IMPORTANT:
            This function assumes that you started your
            topology with the option '--mac'.
            Furthermore, it assumes that value of VLAN is '-1'
        Description:
            Converts mininet hosts ( h1, h2, h3... ) into
            ONOS format ( 00:00:00:00:00:01/-1 , ... )
        """
        try:
            onosHostList = []

            for host in hostList:
                host = host.replace( "h", "" )
                hostHex = hex( int( host ) ).zfill( 12 )
                hostHex = str( hostHex ).replace( 'x', '0' )
                i = iter( str( hostHex ) )
                hostHex = ":".join( a + b for a, b in zip( i, i ) )
                hostHex = hostHex + "/-1"
                onosHostList.append( hostHex )

            return onosHostList

        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 verifyHostLocation( self, hostIp, location ):
        """
        Description:
            Verify the host given is discovered in all locations expected
        Required:
            hostIp: IP address of the host
            location: expected location(s) of the given host. ex. "of:0000000000000005/8"
                      Could be a string or list
        Returns:
            main.TRUE if host is discovered on all locations provided
            main.FALSE otherwise
        """
        locations = [ location ] if isinstance( location, str ) else location
        assert isinstance( locations, list ), "Wrong type of location: {}".format( type( location ) )
        try:
            hosts = self.hosts()
            hosts = json.loads( hosts )
            targetHost = None
            for host in hosts:
                if hostIp in host[ "ipAddresses" ]:
                    targetHost = host
            assert targetHost, "Not able to find host with IP {}".format( hostIp )
            result = main.TRUE
            locationsDiscovered = [ loc[ "elementId" ] + "/" + loc[ "port" ] for loc in targetHost[ "locations" ] ]
            for loc in locations:
                discovered = False
                for locDiscovered in locationsDiscovered:
                    locToMatch = locDiscovered if "/" in loc else locDiscovered.split( "/" )[0]
                    if loc == locToMatch:
                        main.log.debug( "Host {} discovered with location {}".format( hostIp, loc ) )
                        discovered = True
                        break
                if discovered:
                    locationsDiscovered.remove( locDiscovered )
                else:
                    main.log.warn( "Host {} not discovered with location {}".format( hostIp, loc ) )
                    result = main.FALSE
            if locationsDiscovered:
                main.log.warn( "Host {} is also discovered with location {}".format( hostIp, locationsDiscovered ) )
                result = main.FALSE
            return result
        except KeyError:
            main.log.exception( self.name + ": host data not as expected: " + hosts )
            return None
        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" )
            return None

    def verifyHostIp( self, hostList=[], prefix="", prefixLength=24 ):
        """
        Description:
            Verify that all hosts have IP address assigned to them
        Optional:
            hostList: If specified, verifications only happen to the hosts
            in hostList
            prefix: at least one of the ip address assigned to the host
            needs to have the specified prefix
        Returns:
            main.TRUE if all hosts have specific IP address assigned;
            main.FALSE otherwise
        """
        try:
            hosts = self.hosts()
            hosts = json.loads( hosts, "utf-8" )
            if not hostList:
                hostList = [ host[ "id" ] for host in hosts ]
            hostList = [ str( h.lower() ) for h in hostList ]
            for host in hosts:
                hostId = host[ "id" ]
                hostId = str( hostId.lower() )
                match = False
                for onosHostId in hostList:
                    if onosHostId == hostId:
                        match = True
                if not match:
                    continue
                ipList = host[ "ipAddresses" ]
                main.log.debug( self.name + ": IP list on host " + str( hostId ) + ": " + str( ipList ) )
                if not ipList:
                    main.log.warn( self.name + ": Failed to discover any IP addresses on host " + str( hostId ) )
                else:
                    # if no hostIp in subnet: Get warning otherwise remove hostId from hostList
                    subnetString = u"%s/%s" % (prefix, prefixLength)
                    subnet =  ipaddress.ip_network( subnetString, strict=False )
                    if not any( ipaddress.ip_address( ip ) in subnet for ip in ipList ):
                        main.log.warn( self.name + ": None of the IPs on host " + str( hostId ) + " has prefix " + str( prefix ) )
                    else:
                        main.log.debug( self.name + ": Found matching IP on host " + str( hostId ) )
                        hostList.remove( hostId )
            if hostList:
                main.log.warn( self.name + ": failed to verify IP on following hosts: " + str( hostList) )
                # Print info for debugging
                main.log.debug( self.name + ": hosts output: " + str( hosts ) )
                return main.FALSE
            else:
                return main.TRUE
        except KeyError:
            main.log.exception( self.name + ": host data not as expected: " + hosts )
            return None
        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" )
            return None

    def addHostIntent( self, hostIdOne, hostIdTwo, vlanId="", setVlan="", encap="", bandwidth="" ):
        """
        Required:
            * hostIdOne: ONOS host id for host1
            * hostIdTwo: ONOS host id for host2
        Optional:
            * vlanId: specify a VLAN id for the intent
            * setVlan: specify a VLAN id treatment
            * encap: specify an encapsulation type
        Description:
            Adds a host-to-host intent ( bidirectional ) by
            specifying the two hosts.
        Returns:
            A string of the intent id or None on Error
        """
        try:
            cmdStr = "add-host-intent "
            if vlanId:
                cmdStr += "-v " + str( vlanId ) + " "
            if setVlan:
                cmdStr += "--setVlan " + str( vlanId ) + " "
            if encap:
                cmdStr += "--encapsulation " + str( encap ) + " "
            if bandwidth:
                cmdStr += "-b " + str( bandwidth ) + " "
            cmdStr += str( hostIdOne ) + " " + str( hostIdTwo )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in adding Host intent" )
                main.log.debug( "Response from ONOS was: " + repr( handle ) )
                return None
            else:
                main.log.info( "Host intent installed between " +
                               str( hostIdOne ) + " and " + str( hostIdTwo ) )
                match = re.search( 'id=0x([\da-f]+),', handle )
                if match:
                    return match.group()[ 3:-1 ]
                else:
                    main.log.error( "Error, intent ID not found" )
                    main.log.debug( "Response from ONOS was: " +
                                    repr( handle ) )
                    return None
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 addOpticalIntent( self, ingressDevice, egressDevice ):
        """
        Required:
            * ingressDevice: device id of ingress device
            * egressDevice: device id of egress device
        Optional:
            TODO: Still needs to be implemented via dev side
        Description:
            Adds an optical intent by specifying an ingress and egress device
        Returns:
            A string of the intent id or None on error
        """
        try:
            cmdStr = "add-optical-intent " + str( ingressDevice ) +\
                " " + str( egressDevice )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            # If error, return error message
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in adding Optical intent" )
                return None
            else:
                main.log.info( "Optical intent installed between " +
                               str( ingressDevice ) + " and " +
                               str( egressDevice ) )
                match = re.search( 'id=0x([\da-f]+),', handle )
                if match:
                    return match.group()[ 3:-1 ]
                else:
                    main.log.error( "Error, intent ID not found" )
                    return None
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 addPointIntent(
            self,
            ingressDevice,
            egressDevice,
            portIngress="",
            portEgress="",
            ethType="",
            ethSrc="",
            ethDst="",
            bandwidth="",
            lambdaAlloc=False,
            protected=False,
            ipProto="",
            ipSrc="",
            ipDst="",
            tcpSrc="",
            tcpDst="",
            vlanId="",
            setVlan="",
            encap="" ):
        """
        Required:
            * ingressDevice: device id of ingress device
            * egressDevice: device id of egress device
        Optional:
            * ethType: specify ethType
            * ethSrc: specify ethSrc ( i.e. src mac addr )
            * ethDst: specify ethDst ( i.e. dst mac addr )
            * bandwidth: specify bandwidth capacity of link
            * lambdaAlloc: if True, intent will allocate lambda
              for the specified intent
            * ipProto: specify ip protocol
            * ipSrc: specify ip source address
            * ipDst: specify ip destination address
            * tcpSrc: specify tcp source port
            * tcpDst: specify tcp destination port
            * vlanId: specify vlan ID
            * setVlan: specify a VLAN id treatment
            * encap: specify an Encapsulation type to use
        Description:
            Adds a point-to-point intent ( uni-directional ) by
            specifying device id's and optional fields
        Returns:
            A string of the intent id or None on error

        NOTE: This function may change depending on the
              options developers provide for point-to-point
              intent via cli
        """
        try:
            cmd = "add-point-intent"

            if ethType:
                cmd += " --ethType " + str( ethType )
            if ethSrc:
                cmd += " --ethSrc " + str( ethSrc )
            if ethDst:
                cmd += " --ethDst " + str( ethDst )
            if bandwidth:
                cmd += " --bandwidth " + str( bandwidth )
            if lambdaAlloc:
                cmd += " --lambda "
            if ipProto:
                cmd += " --ipProto " + str( ipProto )
            if ipSrc:
                cmd += " --ipSrc " + str( ipSrc )
            if ipDst:
                cmd += " --ipDst " + str( ipDst )
            if tcpSrc:
                cmd += " --tcpSrc " + str( tcpSrc )
            if tcpDst:
                cmd += " --tcpDst " + str( tcpDst )
            if vlanId:
                cmd += " -v " + str( vlanId )
            if setVlan:
                cmd += " --setVlan " + str( setVlan )
            if encap:
                cmd += " --encapsulation " + str( encap )
            if protected:
                cmd += " --protect "

            # Check whether the user appended the port
            # or provided it as an input
            if "/" in ingressDevice:
                cmd += " " + str( ingressDevice )
            else:
                if not portIngress:
                    main.log.error( "You must specify the ingress port" )
                    # TODO: perhaps more meaningful return
                    #       Would it make sense to throw an exception and exit
                    #       the test?
                    return None

                cmd += " " + \
                    str( ingressDevice ) + "/" +\
                    str( portIngress ) + " "

            if "/" in egressDevice:
                cmd += " " + str( egressDevice )
            else:
                if not portEgress:
                    main.log.error( "You must specify the egress port" )
                    return None

                cmd += " " +\
                    str( egressDevice ) + "/" +\
                    str( portEgress )

            handle = self.sendline( cmd )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            # If error, return error message
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in adding point-to-point intent" )
                return None
            else:
                # TODO: print out all the options in this message?
                main.log.info( "Point-to-point intent installed between " +
                               str( ingressDevice ) + " and " +
                               str( egressDevice ) )
                match = re.search( 'id=0x([\da-f]+),', handle )
                if match:
                    return match.group()[ 3:-1 ]
                else:
                    main.log.error( "Error, intent ID not found" )
                    return None
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 addMultipointToSinglepointIntent(
            self,
            ingressDeviceList,
            egressDevice,
            portIngressList=None,
            portEgress="",
            ethType="",
            ethSrc="",
            ethDst="",
            bandwidth="",
            lambdaAlloc=False,
            ipProto="",
            ipSrc="",
            ipDst="",
            tcpSrc="",
            tcpDst="",
            setEthSrc="",
            setEthDst="",
            vlanId="",
            setVlan="",
            partial=False,
            encap="" ):
        """
        Note:
            This function assumes the format of all ingress devices
            is same. That is, all ingress devices include port numbers
            with a "/" or all ingress devices could specify device
            ids and port numbers seperately.
        Required:
            * ingressDeviceList: List of device ids of ingress device
                ( Atleast 2 ingress devices required in the list )
            * egressDevice: device id of egress device
        Optional:
            * ethType: specify ethType
            * ethSrc: specify ethSrc ( i.e. src mac addr )
            * ethDst: specify ethDst ( i.e. dst mac addr )
            * bandwidth: specify bandwidth capacity of link
            * lambdaAlloc: if True, intent will allocate lambda
              for the specified intent
            * ipProto: specify ip protocol
            * ipSrc: specify ip source address
            * ipDst: specify ip destination address
            * tcpSrc: specify tcp source port
            * tcpDst: specify tcp destination port
            * setEthSrc: action to Rewrite Source MAC Address
            * setEthDst: action to Rewrite Destination MAC Address
            * vlanId: specify vlan Id
            * setVlan: specify VLAN Id treatment
            * encap: specify a type of encapsulation
        Description:
            Adds a multipoint-to-singlepoint intent ( uni-directional ) by
            specifying device id's and optional fields
        Returns:
            A string of the intent id or None on error

        NOTE: This function may change depending on the
              options developers provide for multipoint-to-singlepoint
              intent via cli
        """
        try:
            cmd = "add-multi-to-single-intent"

            if ethType:
                cmd += " --ethType " + str( ethType )
            if ethSrc:
                cmd += " --ethSrc " + str( ethSrc )
            if ethDst:
                cmd += " --ethDst " + str( ethDst )
            if bandwidth:
                cmd += " --bandwidth " + str( bandwidth )
            if lambdaAlloc:
                cmd += " --lambda "
            if ipProto:
                cmd += " --ipProto " + str( ipProto )
            if ipSrc:
                cmd += " --ipSrc " + str( ipSrc )
            if ipDst:
                cmd += " --ipDst " + str( ipDst )
            if tcpSrc:
                cmd += " --tcpSrc " + str( tcpSrc )
            if tcpDst:
                cmd += " --tcpDst " + str( tcpDst )
            if setEthSrc:
                cmd += " --setEthSrc " + str( setEthSrc )
            if setEthDst:
                cmd += " --setEthDst " + str( setEthDst )
            if vlanId:
                cmd += " -v " + str( vlanId )
            if setVlan:
                cmd += " --setVlan " + str( setVlan )
            if partial:
                cmd += " --partial"
            if encap:
                cmd += " --encapsulation " + str( encap )

            # Check whether the user appended the port
            # or provided it as an input

            if portIngressList is None:
                for ingressDevice in ingressDeviceList:
                    if "/" in ingressDevice:
                        cmd += " " + str( ingressDevice )
                    else:
                        main.log.error( "You must specify " +
                                        "the ingress port" )
                        # TODO: perhaps more meaningful return
                        return main.FALSE
            else:
                if len( ingressDeviceList ) == len( portIngressList ):
                    for ingressDevice, portIngress in zip( ingressDeviceList,
                                                           portIngressList ):
                        cmd += " " + \
                            str( ingressDevice ) + "/" +\
                            str( portIngress ) + " "
                else:
                    main.log.error( "Device list and port list does not " +
                                    "have the same length" )
                    return main.FALSE
            if "/" in egressDevice:
                cmd += " " + str( egressDevice )
            else:
                if not portEgress:
                    main.log.error( "You must specify " +
                                    "the egress port" )
                    return main.FALSE

                cmd += " " +\
                    str( egressDevice ) + "/" +\
                    str( portEgress )
            handle = self.sendline( cmd )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            # If error, return error message
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in adding multipoint-to-singlepoint " +
                                "intent" )
                return None
            else:
                match = re.search( 'id=0x([\da-f]+),', handle )
                if match:
                    return match.group()[ 3:-1 ]
                else:
                    main.log.error( "Error, intent ID not found" )
                    return None
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 addSinglepointToMultipointIntent(
            self,
            ingressDevice,
            egressDeviceList,
            portIngress="",
            portEgressList=None,
            ethType="",
            ethSrc="",
            ethDst="",
            bandwidth="",
            lambdaAlloc=False,
            ipProto="",
            ipSrc="",
            ipDst="",
            tcpSrc="",
            tcpDst="",
            setEthSrc="",
            setEthDst="",
            vlanId="",
            setVlan="",
            partial=False,
            encap="" ):
        """
        Note:
            This function assumes the format of all egress devices
            is same. That is, all egress devices include port numbers
            with a "/" or all egress devices could specify device
            ids and port numbers seperately.
        Required:
            * EgressDeviceList: List of device ids of egress device
                ( Atleast 2 eress devices required in the list )
            * ingressDevice: device id of ingress device
        Optional:
            * ethType: specify ethType
            * ethSrc: specify ethSrc ( i.e. src mac addr )
            * ethDst: specify ethDst ( i.e. dst mac addr )
            * bandwidth: specify bandwidth capacity of link
            * lambdaAlloc: if True, intent will allocate lambda
              for the specified intent
            * ipProto: specify ip protocol
            * ipSrc: specify ip source address
            * ipDst: specify ip destination address
            * tcpSrc: specify tcp source port
            * tcpDst: specify tcp destination port
            * setEthSrc: action to Rewrite Source MAC Address
            * setEthDst: action to Rewrite Destination MAC Address
            * vlanId: specify vlan Id
            * setVlan: specify VLAN ID treatment
            * encap: specify an encapsulation type
        Description:
            Adds a singlepoint-to-multipoint intent ( uni-directional ) by
            specifying device id's and optional fields
        Returns:
            A string of the intent id or None on error

        NOTE: This function may change depending on the
              options developers provide for singlepoint-to-multipoint
              intent via cli
        """
        try:
            cmd = "add-single-to-multi-intent"

            if ethType:
                cmd += " --ethType " + str( ethType )
            if ethSrc:
                cmd += " --ethSrc " + str( ethSrc )
            if ethDst:
                cmd += " --ethDst " + str( ethDst )
            if bandwidth:
                cmd += " --bandwidth " + str( bandwidth )
            if lambdaAlloc:
                cmd += " --lambda "
            if ipProto:
                cmd += " --ipProto " + str( ipProto )
            if ipSrc:
                cmd += " --ipSrc " + str( ipSrc )
            if ipDst:
                cmd += " --ipDst " + str( ipDst )
            if tcpSrc:
                cmd += " --tcpSrc " + str( tcpSrc )
            if tcpDst:
                cmd += " --tcpDst " + str( tcpDst )
            if setEthSrc:
                cmd += " --setEthSrc " + str( setEthSrc )
            if setEthDst:
                cmd += " --setEthDst " + str( setEthDst )
            if vlanId:
                cmd += " -v " + str( vlanId )
            if setVlan:
                cmd += " --setVlan " + str( setVlan )
            if partial:
                cmd += " --partial"
            if encap:
                cmd += " --encapsulation " + str( encap )

            # Check whether the user appended the port
            # or provided it as an input

            if "/" in ingressDevice:
                cmd += " " + str( ingressDevice )
            else:
                if not portIngress:
                    main.log.error( "You must specify " +
                                    "the Ingress port" )
                    return main.FALSE

                cmd += " " +\
                    str( ingressDevice ) + "/" +\
                    str( portIngress )

            if portEgressList is None:
                for egressDevice in egressDeviceList:
                    if "/" in egressDevice:
                        cmd += " " + str( egressDevice )
                    else:
                        main.log.error( "You must specify " +
                                        "the egress port" )
                        # TODO: perhaps more meaningful return
                        return main.FALSE
            else:
                if len( egressDeviceList ) == len( portEgressList ):
                    for egressDevice, portEgress in zip( egressDeviceList,
                                                         portEgressList ):
                        cmd += " " + \
                            str( egressDevice ) + "/" +\
                            str( portEgress )
                else:
                    main.log.error( "Device list and port list does not " +
                                    "have the same length" )
                    return main.FALSE
            handle = self.sendline( cmd )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            # If error, return error message
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in adding singlepoint-to-multipoint " +
                                "intent" )
                return None
            else:
                match = re.search( 'id=0x([\da-f]+),', handle )
                if match:
                    return match.group()[ 3:-1 ]
                else:
                    main.log.error( "Error, intent ID not found" )
                    return None
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 addMplsIntent(
            self,
            ingressDevice,
            egressDevice,
            ingressPort="",
            egressPort="",
            ethType="",
            ethSrc="",
            ethDst="",
            bandwidth="",
            lambdaAlloc=False,
            ipProto="",
            ipSrc="",
            ipDst="",
            tcpSrc="",
            tcpDst="",
            ingressLabel="",
            egressLabel="",
            priority="" ):
        """
        Required:
            * ingressDevice: device id of ingress device
            * egressDevice: device id of egress device
        Optional:
            * ethType: specify ethType
            * ethSrc: specify ethSrc ( i.e. src mac addr )
            * ethDst: specify ethDst ( i.e. dst mac addr )
            * bandwidth: specify bandwidth capacity of link
            * lambdaAlloc: if True, intent will allocate lambda
              for the specified intent
            * ipProto: specify ip protocol
            * ipSrc: specify ip source address
            * ipDst: specify ip destination address
            * tcpSrc: specify tcp source port
            * tcpDst: specify tcp destination port
            * ingressLabel: Ingress MPLS label
            * egressLabel: Egress MPLS label
        Description:
            Adds MPLS intent by
            specifying device id's and optional fields
        Returns:
            A string of the intent id or None on error

        NOTE: This function may change depending on the
              options developers provide for MPLS
              intent via cli
        """
        try:
            cmd = "add-mpls-intent"

            if ethType:
                cmd += " --ethType " + str( ethType )
            if ethSrc:
                cmd += " --ethSrc " + str( ethSrc )
            if ethDst:
                cmd += " --ethDst " + str( ethDst )
            if bandwidth:
                cmd += " --bandwidth " + str( bandwidth )
            if lambdaAlloc:
                cmd += " --lambda "
            if ipProto:
                cmd += " --ipProto " + str( ipProto )
            if ipSrc:
                cmd += " --ipSrc " + str( ipSrc )
            if ipDst:
                cmd += " --ipDst " + str( ipDst )
            if tcpSrc:
                cmd += " --tcpSrc " + str( tcpSrc )
            if tcpDst:
                cmd += " --tcpDst " + str( tcpDst )
            if ingressLabel:
                cmd += " --ingressLabel " + str( ingressLabel )
            if egressLabel:
                cmd += " --egressLabel " + str( egressLabel )
            if priority:
                cmd += " --priority " + str( priority )

            # Check whether the user appended the port
            # or provided it as an input
            if "/" in ingressDevice:
                cmd += " " + str( ingressDevice )
            else:
                if not ingressPort:
                    main.log.error( "You must specify the ingress port" )
                    return None

                cmd += " " + \
                    str( ingressDevice ) + "/" +\
                    str( ingressPort ) + " "

            if "/" in egressDevice:
                cmd += " " + str( egressDevice )
            else:
                if not egressPort:
                    main.log.error( "You must specify the egress port" )
                    return None

                cmd += " " +\
                    str( egressDevice ) + "/" +\
                    str( egressPort )

            handle = self.sendline( cmd )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            # If error, return error message
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in adding mpls intent" )
                return None
            else:
                # TODO: print out all the options in this message?
                main.log.info( "MPLS intent installed between " +
                               str( ingressDevice ) + " and " +
                               str( egressDevice ) )
                match = re.search( 'id=0x([\da-f]+),', handle )
                if match:
                    return match.group()[ 3:-1 ]
                else:
                    main.log.error( "Error, intent ID not found" )
                    return None
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 removeIntent( self, intentId, app='org.onosproject.cli',
                      purge=False, sync=False ):
        """
        Remove intent for specified application id and intent id
        Optional args:-
        -s or --sync: Waits for the removal before returning
        -p or --purge: Purge the intent from the store after removal

        Returns:
            main.FALSE on error and
            cli output otherwise
        """
        try:
            cmdStr = "remove-intent"
            if purge:
                cmdStr += " -p"
            if sync:
                cmdStr += " -s"

            cmdStr += " " + app + " " + str( intentId )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in removing intent" )
                return main.FALSE
            else:
                # TODO: Should this be main.TRUE
                return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 removeAllIntents( self, purge=False, sync=False, app='org.onosproject.cli', timeout=30 ):
        """
        Description:
            Remove all the intents
        Optional args:-
            -s or --sync: Waits for the removal before returning
            -p or --purge: Purge the intent from the store after removal
        Returns:
            Returns main.TRUE if all intents are removed, otherwise returns
            main.FALSE; Returns None for exception
        """
        try:
            cmdStr = "remove-intent"
            if purge:
                cmdStr += " -p"
            if sync:
                cmdStr += " -s"

            cmdStr += " " + app
            handle = self.sendline( cmdStr, timeout=timeout )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in removing intent" )
                return main.FALSE
            else:
                return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 purgeWithdrawnIntents( self ):
        """
        Purges all WITHDRAWN Intents
        """
        try:
            cmdStr = "purge-intents"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in purging intents" )
                return main.FALSE
            else:
                return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 wipeout( self ):
        """
        Wipe out the flows,intents,links,devices,hosts, and groups from the ONOS.
        """
        try:
            cmdStr = "wipe-out please"
            handle = self.sendline( cmdStr, timeout=60 )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 routes( self, jsonFormat=False ):
        """
        NOTE: This method should be used after installing application:
              onos-app-sdnip
        Optional:
            * jsonFormat: enable output formatting in json
        Description:
            Obtain all routes in the system
        """
        try:
            cmdStr = "routes"
            if jsonFormat:
                cmdStr += " -j"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 ipv4RouteNumber( self ):
        """
        NOTE: This method should be used after installing application:
              onos-app-sdnip
        Description:
            Obtain the total IPv4 routes number in the system
        """
        try:
            cmdStr = "routes -j"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            jsonResult = json.loads( handle )
            return len( jsonResult[ 'routes4' ] )
        except AssertionError:
            main.log.exception( "" )
            return None
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) )
            return None
        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()

    # =============Function to check Bandwidth allocation========
    def allocations( self, jsonFormat = True ):
        """
        Description:
            Obtain Bandwidth Allocation Information from ONOS cli.
        """
        try:
            cmdStr = "allocations"
            if jsonFormat:
                cmdStr += " -j"
            handle = self.sendline( cmdStr, timeout=300 )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) )
            return None
        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 intents( self, jsonFormat = True, summary = False, **intentargs ):
        """
        Description:
            Obtain intents from the ONOS cli.
        Optional:
            * jsonFormat: Enable output formatting in json, default to True
            * summary: Whether only output the intent summary, defaults to False
            * type: Only output a certain type of intent. This options is valid
                    only when jsonFormat is True and summary is True.
        """
        try:
            cmdStr = "intents"
            if summary:
                cmdStr += " -s"
            if jsonFormat:
                cmdStr += " -j"
            handle = self.sendline( cmdStr, timeout=300 )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            args = utilities.parse_args( [ "TYPE" ], **intentargs )
            if "TYPE" in args.keys():
                intentType = args[ "TYPE" ]
            else:
                intentType = ""
            # IF we want the summary of a specific intent type
            if jsonFormat and summary and ( intentType != "" ):
                jsonResult = json.loads( handle )
                if intentType in jsonResult.keys():
                    return jsonResult[ intentType ]
                else:
                    main.log.error( "unknown TYPE, returning all types of intents" )
                    return handle
            else:
                return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) )
            return None
        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 getIntentState( self, intentsId, intentsJson=None ):
        """
        Description:
            Gets intent state. Accepts a single intent ID (string type) or a
            list of intent IDs.
        Parameters:
            intentsId: intent ID, both string type and list type are acceptable
            intentsJson: parsed json object from the onos:intents api
        Returns:
            Returns the state (string type) of the ID if a single intent ID is
            accepted.
            Returns a list of dictionaries if a list of intent IDs is accepted,
            and each dictionary maps 'id' to the Intent ID and 'state' to
            corresponding intent state.
        """

        try:
            state = "State is Undefined"
            if not intentsJson:
                rawJson = self.intents()
            else:
                rawJson = intentsJson
            parsedIntentsJson = json.loads( rawJson )
            if isinstance( intentsId, types.StringType ):
                for intent in parsedIntentsJson:
                    if intentsId == intent[ 'id' ]:
                        state = intent[ 'state' ]
                        return state
                main.log.info( "Cannot find intent ID" + str( intentsId ) +
                               " in the list" )
                return state
            elif isinstance( intentsId, types.ListType ):
                dictList = []
                for i in xrange( len( intentsId ) ):
                    stateDict = {}
                    for intent in parsedIntentsJson:
                        if intentsId[ i ] == intent[ 'id' ]:
                            stateDict[ 'state' ] = intent[ 'state' ]
                            stateDict[ 'id' ] = intentsId[ i ]
                            dictList.append( stateDict )
                            break
                if len( intentsId ) != len( dictList ):
                    main.log.warn( "Could not find all intents in ONOS output" )
                    main.log.debug( "expected ids: {} \n ONOS intents: {}".format( intentsId, parsedIntentsJson ) )
                return dictList
            else:
                main.log.info( "Invalid type for intentsId argument" )
                return None
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) )
            return None
        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 checkIntentState( self, intentsId, expectedState='INSTALLED' ):
        """
        Description:
            Check intents state
        Required:
            intentsId - List of intents ID to be checked
        Optional:
            expectedState - Check the expected state(s) of each intents
                            state in the list.
                            *NOTE: You can pass in a list of expected state,
                            Eg: expectedState = [ 'INSTALLED' , 'INSTALLING' ]
        Return:
            Returns main.TRUE only if all intent are the same as expected states,
            otherwise returns main.FALSE.
        """
        try:
            returnValue = main.TRUE
            # Generating a dictionary: intent id as a key and state as value

            # intentsDict = self.getIntentState( intentsId )
            intentsDict = []
            for intent in json.loads( self.intents() ):
                if isinstance( intentsId, types.StringType ) \
                        and intent.get( 'id' ) == intentsId:
                    intentsDict.append( intent )
                elif isinstance( intentsId, types.ListType ) \
                        and any( intent.get( 'id' ) == ids for ids in intentsId ):
                    intentsDict.append( intent )

            if not intentsDict:
                main.log.info( self.name + ": There is something wrong " +
                               "getting intents state" )
                return main.FALSE

            if isinstance( expectedState, types.StringType ):
                for intents in intentsDict:
                    if intents.get( 'state' ) != expectedState:
                        main.log.debug( self.name + " : Intent ID - " +
                                        intents.get( 'id' ) +
                                        " actual state = " +
                                        intents.get( 'state' )
                                        + " does not equal expected state = "
                                        + expectedState )
                        returnValue = main.FALSE
            elif isinstance( expectedState, types.ListType ):
                for intents in intentsDict:
                    if not any( state == intents.get( 'state' ) for state in
                                expectedState ):
                        main.log.debug( self.name + " : Intent ID - " +
                                        intents.get( 'id' ) +
                                        " actual state = " +
                                        intents.get( 'state' ) +
                                        " does not equal expected states = "
                                        + str( expectedState ) )
                        returnValue = main.FALSE

            if returnValue == main.TRUE:
                main.log.info( self.name + ": All " +
                               str( len( intentsDict ) ) +
                               " intents are in " + str( expectedState ) +
                               " state" )
            return returnValue
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 compareBandwidthAllocations( self, expectedAllocations ):
        """
        Description:
            Compare the allocated bandwidth with the given allocations
        Required:
            expectedAllocations - The expected ONOS output of the allocations command
        Return:
            Returns main.TRUE only if all intent are the same as expected states,
            otherwise returns main.FALSE.
        """
        # FIXME: Convert these string comparisons to object comparisons
        try:
            returnValue = main.TRUE
            bandwidthFailed = False
            rawAlloc = self.allocations()
            expectedFormat = StringIO( expectedAllocations )
            ONOSOutput = StringIO( rawAlloc )
            main.log.debug( "ONOSOutput: {}\nexpected output: {}".format( str( ONOSOutput ),
                                                                          str( expectedFormat ) ) )

            for actual, expected in izip( ONOSOutput, expectedFormat ):
                actual = actual.rstrip()
                expected = expected.rstrip()
                main.log.debug( "Expect: {}\nactual: {}".format( expected, actual ) )
                if actual != expected and 'allocated' in actual and 'allocated' in expected:
                    marker1 = actual.find( 'allocated' )
                    m1 = actual[ :marker1 ]
                    marker2 = expected.find( 'allocated' )
                    m2 = expected[ :marker2 ]
                    if m1 != m2:
                        bandwidthFailed = True
                elif actual != expected and 'allocated' not in actual and 'allocated' not in expected:
                    bandwidthFailed = True
            expectedFormat.close()
            ONOSOutput.close()

            if bandwidthFailed:
                main.log.error( "Bandwidth not allocated correctly using Intents!!" )
                returnValue = main.FALSE
            return returnValue
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 compareIntent( self, intentDict ):
        """
        Description:
            Compare the intent ids and states provided in the argument with all intents in ONOS
        Return:
            Returns main.TRUE if the two sets of intents match exactly, otherwise main.FALSE
        Arguments:
            intentDict: a dictionary which maps intent ids to intent states
        """
        try:
            intentsRaw = self.intents()
            intentsJson = json.loads( intentsRaw )
            intentDictONOS = {}
            for intent in intentsJson:
                intentDictONOS[ intent[ 'id' ] ] = intent[ 'state' ]
            returnValue = main.TRUE
            if len( intentDict ) != len( intentDictONOS ):
                main.log.warn( self.name + ": expected intent count does not match that in ONOS, " +
                               str( len( intentDict ) ) + " expected and " +
                               str( len( intentDictONOS ) ) + " actual" )
                returnValue = main.FALSE
            for intentID in intentDict.keys():
                if intentID not in intentDictONOS.keys():
                    main.log.debug( self.name + ": intent ID - " + intentID + " is not in ONOS" )
                    returnValue = main.FALSE
                else:
                    if intentDict[ intentID ] != intentDictONOS[ intentID ]:
                        main.log.debug( self.name + ": intent ID - " + intentID +
                                        " expected state is " + intentDict[ intentID ] +
                                        " but actual state is " + intentDictONOS[ intentID ] )
                        returnValue = main.FALSE
                    intentDictONOS.pop( intentID )
            if len( intentDictONOS ) > 0:
                returnValue = main.FALSE
                for intentID in intentDictONOS.keys():
                    main.log.debug( self.name + ": find extra intent in ONOS: intent ID " + intentID )
            if returnValue == main.TRUE:
                main.log.info( self.name + ": all intent IDs and states match that in ONOS" )
            return returnValue
        except KeyError:
            main.log.exception( self.name + ": KeyError exception found" )
            return main.ERROR
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intentsRaw ) )
            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 checkIntentSummary( self, timeout=60, noExit=True ):
        """
        Description:
            Check the number of installed intents.
        Optional:
            timeout - the timeout for pexcept
            noExit - If noExit, TestON will not exit if any except.
        Return:
            Returns main.TRUE only if the number of all installed intents are the same as total intents number
            , otherwise, returns main.FALSE.
        """

        try:
            cmd = "intents -s -j"

            # Check response if something wrong
            response = self.sendline( cmd, timeout=timeout, noExit=noExit )
            if response is None:
                return main.FALSE
            response = json.loads( response )

            # get total and installed number, see if they are match
            allState = response.get( 'all' )
            if allState.get( 'total' ) == allState.get( 'installed' ):
                main.log.info( 'Total Intents: {}   Installed Intents: {}'.format(
                    allState.get( 'total' ), allState.get( 'installed' ) ) )
                return main.TRUE
            main.log.info( 'Verified Intents failed Expected intents: {} installed intents: {}'.format(
                allState.get( 'total' ), allState.get( 'installed' ) ) )
            return main.FALSE

        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) )
            return None
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            if noExit:
                return main.FALSE
            else:
                main.cleanAndExit()
        except pexpect.TIMEOUT:
            main.log.error( self.name + ": ONOS timeout" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            if noExit:
                return main.FALSE
            else:
                main.cleanAndExit()

    def flows( self, state="any", jsonFormat=True, timeout=60, noExit=False, noCore=False, device="" ):
        return self.dataPlaneEntities( entity="flows", state=state, jsonFormat=jsonFormat,
            timeout=timeout, noExit=noExit, noCore=noCore, device=device )

    def groups( self, state="any", jsonFormat=True, timeout=60, noExit=False, noCore=False, device="" ):
        return self.dataPlaneEntities( entity="groups", state=state, jsonFormat=jsonFormat,
            timeout=timeout, noExit=noExit, noCore=noCore, device=device )

    def dataPlaneEntities( self, entity="flows", state="any", jsonFormat=True,
        timeout=60, noExit=False, noCore=False, device="" ):
        """
        Optional:
            * jsonFormat: enable output formatting in json
            * noCore: suppress core flows
        Description:
            Obtain dataplaneEntities currently installed
        """
        try:
            cmdStr = entity
            if jsonFormat:
                cmdStr += " -j"
            if noCore:
                cmdStr += " -n"
            cmdStr += " " + state
            cmdStr += " " + device
            handle = self.sendline( cmdStr, timeout=timeout, noExit=noExit )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            if re.search( "Error:", handle ):
                main.log.error( self.name + ": " + entity + "() response: " +
                                str( handle ) )
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except pexpect.TIMEOUT:
            main.log.error( self.name + ": ONOS timeout" )
            return None
        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 checkFlowCount( self, min=0, timeout=60 ):
        count = self.getTotalFlowsNum( timeout=timeout )
        count = int( count ) if count else 0
        main.log.debug( "found {} flows".format( count ) )
        return count if ( count >= min ) else False

    def checkFlowsState( self, isPENDING=True, timeout=60, noExit=False ):
        """
        Description:
            Check the if all the current flows are in ADDED state
            We check PENDING_ADD, PENDING_REMOVE, REMOVED, and FAILED flows,
            if the count of those states is 0, which means all current flows
            are in ADDED state, and return main.TRUE otherwise return main.FALSE
        Optional:
            * isPENDING:  whether the PENDING_ADD is also a correct status
        Return:
            returnValue - Returns main.TRUE only if all flows are in
                          ADDED state or PENDING_ADD if the isPENDING
                          parameter is set true, return main.FALSE otherwise.
        """
        try:
            states = [ "PENDING_ADD", "PENDING_REMOVE", "REMOVED", "FAILED" ]
            checkedStates = []
            statesCount = [ 0, 0, 0, 0 ]
            for s in states:
                rawFlows = self.flows( state=s, timeout = timeout )
                if rawFlows:
                    # if we didn't get flows or flows function return None, we should return
                    # main.Flase
                    checkedStates.append( json.loads( rawFlows ) )
                else:
                    return main.FALSE
            for i in range( len( states ) ):
                for c in checkedStates[ i ]:
                    try:
                        statesCount[ i ] += int( c.get( "flowCount" ) )
                    except TypeError:
                        main.log.exception( "Json object not as expected" )
                main.log.info( states[ i ] + " flows: " + str( statesCount[ i ] ) )

            # We want to count PENDING_ADD if isPENDING is true
            if isPENDING:
                if statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0:
                    return main.FALSE
            else:
                if statesCount[ 0 ] + statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0:
                    return main.FALSE
            return main.TRUE
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawFlows ) )
            return None

        except AssertionError:
            main.log.exception( "" )
            return None
        except pexpect.TIMEOUT:
            main.log.error( self.name + ": ONOS timeout" )
            return None
        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 checkGroupCount( self, min=0, timeout=60 ):
        count = self.getTotalGroupsNum( timeout=timeout )
        count = int( count ) if count else 0
        main.log.debug( "found {} groups".format( count ) )
        return count if ( count >= min ) else False

    def checkGroupsState( self, isPENDING=True, timeout=60, noExit=False ):
        """
        Description:
            Check the if all the current groups are in ADDED state
            We check PENDING_ADD, PENDING_REMOVE, REMOVED, and FAILED groups,
            if the count of those states is 0, which means all current groups
            are in ADDED state, and return main.TRUE otherwise return main.FALSE
        Optional:
            * isPENDING:  whether the PENDING_ADD is also a correct status
        Return:
            returnValue - Returns main.TRUE only if all groups are in
                          ADDED state or PENDING_ADD if the isPENDING
                          parameter is set true, return main.FALSE otherwise.
        """
        try:
            states = [ "PENDING_ADD", "PENDING_ADD_RETRY", "PENDING_DELETE", "PENDING_UPDATE", "WAITING_AUDIT_COMPLETE" ]
            checkedStates = []
            statesCount = [ 0, 0, 0, 0, 0 ]
            for s in states:
                rawGroups = self.groups( state=s, timeout = timeout )
                if rawGroups:
                    # if we didn't get groups or groups function return None, we should return
                    # main.Flase
                    checkedStates.append( json.loads( rawGroups ) )
                else:
                    return main.FALSE
            for i in range( len( states ) ):
                statesCount[ i ] += int( len(checkedStates[i]) )
                main.log.info( states[ i ] + " groups: " + str( statesCount[ i ] ) )

            # We want to count PENDING_ADD if isPENDING is true
            if isPENDING:
                if statesCount[ 2 ] + statesCount[ 3 ] + statesCount[ 4 ] > 0:
                    return main.FALSE
            else:
                if statesCount[ 0 ] + statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] + statesCount[ 4 ] > 0:
                    return main.FALSE
            return main.TRUE
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawGroups ) )
            return None

        except AssertionError:
            main.log.exception( "" )
            return None
        except pexpect.TIMEOUT:
            main.log.error( self.name + ": ONOS timeout" )
            return None
        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 pushTestIntents( self, ingress, egress, batchSize, offset="",
                         options="", timeout=10, background = False, noExit=False, getResponse=False ):
        """
        Description:
            Push a number of intents in a batch format to
            a specific point-to-point intent definition
        Required:
            * ingress: specify source dpid
            * egress: specify destination dpid
            * batchSize: specify number of intents to push
        Optional:
            * offset: the keyOffset is where the next batch of intents
                      will be installed
            * noExit: If set to True, TestON will not exit if any error when issus command
            * getResponse: If set to True, function will return ONOS response.

        Returns: If failed to push test intents, it will returen None,
                 if successful, return true.
                 Timeout expection will return None,
                 TypeError will return false
                 other expections will exit()
        """
        try:
            if background:
                back = "&"
            else:
                back = ""
            cmd = "push-test-intents {} {} {} {} {} {}".format( options,
                                                                ingress,
                                                                egress,
                                                                batchSize,
                                                                offset,
                                                                back )
            response = self.sendline( cmd, timeout=timeout, noExit=noExit )
            assert response is not None, "Error in sendline"
            assert "Command not found:" not in response, response
            main.log.info( response )
            if getResponse:
                return response

            # TODO: We should handle if there is failure in installation
            return main.TRUE

        except AssertionError:
            main.log.exception( "" )
            return None
        except pexpect.TIMEOUT:
            main.log.error( self.name + ": ONOS timeout" )
            return None
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def getTotalFlowsNum( self, timeout=60, noExit=False ):
        return self.getTotalEntitiesNum( entity="flows", timeout=60, noExit=False )

    def getTotalGroupsNum( self, timeout=60, noExit=False ):
        return self.getTotalEntitiesNum( entity="groups", timeout=60, noExit=False )

    def getTotalEntitiesNum( self, entity="flows", timeout=60, noExit=False ):
        """
        Description:
            Get the number of ADDED entities.
        Return:
            The number of ADDED entities
            Or return None if any exceptions
        """

        try:
            # get total added entities number
            cmd = entity + " -c added"
            rawEntities = self.sendline( cmd, timeout=timeout, noExit=noExit )
            if rawEntities:
                rawEntities = rawEntities.split( "\n" )
                totalEntities = 0
                for l in rawEntities:
                    totalEntities += int( l.split( "Count=" )[ 1 ] )
            else:
                main.log.warn( "Response not as expected!" )
                return None
            return totalEntities

        except IndexError:
            main.log.exception( "{}: Object not as expected!".format( self.name ) )
            main.log.debug( "rawEntities: {}".format( rawEntities ) )
            return None
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected!".format( self.name ) )
            return None
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            if not noExit:
                main.cleanAndExit()
            return None
        except pexpect.TIMEOUT:
            main.log.error( self.name + ": ONOS timeout" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            if not noExit:
                main.cleanAndExit()
            return None

    def getTotalIntentsNum( self, timeout=60, noExit = False ):
        """
        Description:
            Get the total number of intents, include every states.
        Optional:
            noExit - If noExit, TestON will not exit if any except.
        Return:
            The number of intents
        """
        try:
            cmd = "summary -j"
            response = self.sendline( cmd, timeout=timeout, noExit=noExit )
            if response is None:
                return -1
            response = json.loads( response )
            return int( response.get( "intents" ) )
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) )
            return None
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            if noExit:
                return -1
            else:
                main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            if noExit:
                return -1
            else:
                main.cleanAndExit()

    def intentsEventsMetrics( self, jsonFormat=True ):
        """
        Description:Returns topology metrics
        Optional:
            * jsonFormat: enable json formatting of output
        """
        try:
            cmdStr = "intents-events-metrics"
            if jsonFormat:
                cmdStr += " -j"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 topologyEventsMetrics( self, jsonFormat=True ):
        """
        Description:Returns topology metrics
        Optional:
            * jsonFormat: enable json formatting of output
        """
        try:
            cmdStr = "topology-events-metrics"
            if jsonFormat:
                cmdStr += " -j"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            if handle:
                return handle
            elif jsonFormat:
                # Return empty json
                return '{}'
            else:
                return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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()

    # Wrapper functions ****************
    # Wrapper functions use existing driver
    # functions and extends their use case.
    # For example, we may use the output of
    # a normal driver function, and parse it
    # using a wrapper function

    def getAllIntentsId( self ):
        """
        Description:
            Obtain all intent id's in a list
        """
        try:
            # Obtain output of intents function
            intentsStr = self.intents( jsonFormat=True )
            if intentsStr is None:
                raise TypeError
            # Convert to a dictionary
            intents = json.loads( intentsStr )
            intentIdList = []
            for intent in intents:
                intentIdList.append( intent[ 'id' ] )
            return intentIdList
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 flowAddedCount( self, deviceId, core=False ):
        """
        Determine the number of flow rules for the given device id that are
        in the added state
        Params:
            core: if True, only return the number of core flows added
        """
        try:
            if core:
                cmdStr = "flows any " + str( deviceId ) + " | " +\
                         "grep 'state=ADDED' | grep org.onosproject.core | wc -l"
            else:
                cmdStr = "flows any " + str( deviceId ) + " | " +\
                         "grep 'state=ADDED' | wc -l"
            handle = self.lineCount( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        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 groupAddedCount( self, deviceId, core=False ):
        """
        Determine the number of group rules for the given device id that are
        in the added state
        Params:
            core: if True, only return the number of core groups added
        """
        try:
            if core:
                cmdStr = "groups any " + str( deviceId ) + " | " +\
                         "grep 'state=ADDED' | grep org.onosproject.core | wc -l"
            else:
                cmdStr = "groups any " + str( deviceId ) + " | " +\
                         "grep 'state=ADDED' | wc -l"
            handle = self.lineCount( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        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 sendOnosCliCommand( self, cmd, params=[] ):
        """
        Handles sending an arbitrary command to the ONOS cli and parsing standard errors
        Params:
            cmd: The command to be sent in the onos cli
            params: Sending the parameters within the command we send in the cli
        """
        try:
            if not isinstance(params, list):
              params=[params]
            cmdStr = cmd + " " + ' '.join(params)
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            # Check for error in cli response
            assert "Error executing command" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            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 blackholeStaticRoute( self, subnet, addBlackhole=True ):
        """
        Manage black hole routes in onos.
        Params:
            subnet: The subnet to be blocked through this route
            addBlackhole: Boolean set to declare if we are adding or removing the blackhole route
        """
        if addBlackhole:
            addedBlackholeIP = self.sendOnosCliCommand('sr-blackhole add', subnet)
        else:
            removedBlackholeIP = self.sendOnosCliCommand('sr-blackhole remove', subnet)
        blackHoleList = self.sendOnosCliCommand('sr-blackhole list')
        if subnet in blackHoleList:
            exists = True
        else:
            exists = False
        if (addBlackhole and exists) or (not addBlackhole and not exists):
            return main.TRUE
        else:
            return main.FALSE

    def checkGroupAddedCount( self, deviceId, expectedGroupCount=0, core=False, comparison=0):
        """
        Description:
            Check whether the number of groups for the given device id that
            are in ADDED state is bigger than minGroupCount.
        Required:
            * deviceId: device id to check the number of added group rules
        Optional:
            * minGroupCount: the number of groups to compare
            * core: if True, only check the number of core groups added
            * comparison: if 0, compare with greater than minFlowCount
            *             if 1, compare with equal to minFlowCount
        Return:
            Returns the number of groups if it is bigger than minGroupCount,
            returns main.FALSE otherwise.
        """
        count = self.groupAddedCount( deviceId, core )
        count = int( count ) if count else 0
        main.log.debug( "found {} groups".format( count ) )
        return count if ((count > expectedGroupCount) if (comparison == 0) else (count == expectedGroupCount)) else main.FALSE

    def getGroups( self, deviceId, groupType="any" ):
        """
        Retrieve groups from a specific device.
        deviceId: Id of the device from which we retrieve groups
        groupType: Type of group
        """
        try:
            groupCmd = "groups -t {0} any {1}".format( groupType, deviceId )
            handle = self.sendline( groupCmd )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 checkFlowAddedCount( self, deviceId, expectedFlowCount=0, core=False, comparison=0):
        """
        Description:
            Check whether the number of flow rules for the given device id that
            are in ADDED state is bigger than minFlowCount.
        Required:
            * deviceId: device id to check the number of added flow rules
        Optional:
            * minFlowCount: the number of flow rules to compare
            * core: if True, only check the number of core flows added
            * comparison: if 0, compare with greater than minFlowCount
            *             if 1, compare with equal to minFlowCount
        Return:
            Returns the number of flow rules if it is bigger than minFlowCount,
            returns main.FALSE otherwise.
        """
        count = self.flowAddedCount( deviceId, core )
        count = int( count ) if count else 0
        main.log.debug( "found {} flows".format( count ) )
        return count if ((count >= expectedFlowCount) if (comparison == 0) else (count == expectedFlowCount)) else main.FALSE

    def getAllDevicesId( self ):
        """
        Use 'devices' function to obtain list of all devices
        and parse the result to obtain a list of all device
        id's. Returns this list. Returns empty list if no
        devices exist
        List is ordered sequentially

        This function may be useful if you are not sure of the
        device id, and wish to execute other commands using
        the ids. By obtaining the list of device ids on the fly,
        you can iterate through the list to get mastership, etc.
        """
        try:
            # Call devices and store result string
            devicesStr = self.devices( jsonFormat=False )
            idList = []

            if not devicesStr:
                main.log.info( "There are no devices to get id from" )
                return idList

            # Split the string into list by comma
            deviceList = devicesStr.split( "," )
            # Get temporary list of all arguments with string 'id='
            tempList = [ dev for dev in deviceList if "id=" in dev ]
            # Split list further into arguments before and after string
            # 'id='. Get the latter portion ( the actual device id ) and
            # append to idList
            for arg in tempList:
                idList.append( arg.split( "id=" )[ 1 ] )
            return idList

        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 getAllNodesId( self ):
        """
        Uses 'nodes' function to obtain list of all nodes
        and parse the result of nodes to obtain just the
        node id's.
        Returns:
            list of node id's
        """
        try:
            nodesStr = self.nodes( jsonFormat=True )
            idList = []
            # Sample nodesStr output
            # id=local, address=127.0.0.1:9876, state=READY *
            if not nodesStr:
                main.log.info( "There are no nodes to get id from" )
                return idList
            nodesJson = json.loads( nodesStr )
            idList = [ node.get( 'id' ) for node in nodesJson ]
            return idList
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, nodesStr ) )
            return None
        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 getDevice( self, dpid=None ):
        """
        Return the first device from the devices api whose 'id' contains 'dpid'
        Return None if there is no match
        """
        try:
            if dpid is None:
                return None
            else:
                dpid = dpid.replace( ':', '' )
                rawDevices = self.devices()
                devicesJson = json.loads( rawDevices )
                # search json for the device with dpid then return the device
                for device in devicesJson:
                    # print "%s in  %s?" % ( dpid, device[ 'id' ] )
                    if dpid in device[ 'id' ]:
                        return device
            return None
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawDevices ) )
            return None
        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 getTopology( self, topologyOutput ):
        """
        Definition:
            Loads a json topology output
        Return:
            topology = current ONOS topology
        """
        try:
            # either onos:topology or 'topology' will work in CLI
            topology = json.loads( topologyOutput )
            main.log.debug( topology )
            return topology
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, topologyOutput ) )
            return None
        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 checkStatus( self, numoswitch, numolink = -1, numoctrl = -1, numoSCCs=1, logLevel="info" ):
        """
        Checks the number of switches & links that ONOS sees against the
        supplied values. By default this will report to main.log, but the
        log level can be specific.

        Params: numoswitch = expected number of switches
                numolink = expected number of links
                numoctrl = expected number of controllers
                numoSCCs = Number of expected SCCs
                logLevel = level to log to.
                Currently accepts 'info', 'warn' and 'report'

        Returns: main.TRUE if the number of switches and links are correct,
                 main.FALSE if the number of switches and links is incorrect,
                 and main.ERROR otherwise
        """
        try:
            summary = self.summary()
            summary = json.loads( summary )
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summary ) )
            return main.ERROR
        try:
            topology = self.getTopology( self.topology() )
            if topology == {} or topology is None or summary == {} or summary is None:
                return main.ERROR
            output = ""
            # Is the number of switches is what we expected
            devices = topology.get( 'devices', False )
            links = topology.get( 'links', False )
            nodes = summary.get( 'nodes', False )
            SCCs = summary.get( 'SCC(s)', False )
            if devices is False or links is False or nodes is False or SCCs is False:
                main.log.warn( "Issues parsing topology and summary output" )
                main.log.debug( topology )
                main.log.debug( summary )
                return main.ERROR
            switchCheck = ( int( devices ) == int( numoswitch ) )
            if not switchCheck:
                main.log.debug( "switch Check Failed" )
            linkCheck = ( int( links ) == int( numolink ) ) or int( numolink ) == -1
            if not linkCheck:
                main.log.debug( "link Check Failed" )
            nodeCheck = ( int( nodes ) == int( numoctrl ) ) or int( numoctrl ) == -1
            if not nodeCheck:
                main.log.debug( "node Check Failed" )
            SCCsCheck = ( int( SCCs ) == int( numoSCCs ) ) or int( numoSCCs ) == -1
            if not SCCsCheck:
                main.log.debug( "SCCs Check Failed" )
            if switchCheck and linkCheck and nodeCheck and SCCsCheck:
                # We expected the correct numbers
                output = output + "The number of links, switches, nodes, and SCCs match "\
                    + "what was expected"
                result = main.TRUE
            else:
                output = output + \
                    "The number of links, switches, nodes, and SCCs does not match " + \
                    "what was expected"
                result = main.FALSE
            output = output + "\n ONOS sees %i devices " % int( devices )
            output = output + "(%i expected) " % int( numoswitch )
            if int( numolink ) >= 0:
                output = output + "and %i links " % int( links )
                output = output + "(%i expected) " % int( numolink )
            if int( numoctrl ) >= 0:
                output = output + "and %i controllers " % int( nodes )
                output = output + "(%i expected) " % int( numoctrl )
            if int( numoSCCs ) >= 0:
                output = output + "and %i SCCs " % int( SCCs )
                output = output + "(%i expected)" % int( numoSCCs )
            if logLevel == "report":
                main.log.report( output )
            elif logLevel == "warn":
                main.log.warn( output )
            else:
                main.log.info( output )
            main.TOPOOUTPUT = output
            return result
        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 deviceRole( self, deviceId, onosNode, role="master" ):
        """
        Calls the device-role cli command.
        deviceId must be the id of a device as seen in the onos devices command
        onosNode is the ip of one of the onos nodes in the cluster
        role must be either master, standby, or none

        Returns:
            main.TRUE or main.FALSE based on argument verification and
            main.ERROR if command returns and error
        """
        try:
            if role.lower() == "master" or role.lower() == "standby" or\
                    role.lower() == "none":
                cmdStr = "device-role " +\
                    str( deviceId ) + " " +\
                    str( onosNode ) + " " +\
                    str( role )
                handle = self.sendline( cmdStr )
                assert handle is not None, "Error in sendline"
                assert "Command not found:" not in handle, handle
                if re.search( "Error", handle ):
                    # end color output to escape any colours
                    # from the cli
                    main.log.error( self.name + ": " +
                                    handle + '\033[0m' )
                    return main.ERROR
                return main.TRUE
            else:
                main.log.error( "Invalid 'role' given to device_role(). " +
                                "Value was '" + str( role ) + "'." )
                return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 clusters( self, jsonFormat=True ):
        """
        Lists all topology clusters
        Optional argument:
            * jsonFormat - boolean indicating if you want output in json
        """
        try:
            cmdStr = "topo-clusters"
            if jsonFormat:
                cmdStr += " -j"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 electionTestLeader( self ):
        """
        CLI command to get the current leader for the Election test application
        NOTE: Requires installation of the onos-app-election feature
        Returns: Node IP of the leader if one exists
                 None if none exists
                 Main.FALSE on error
        """
        try:
            cmdStr = "election-test-leader"
            response = self.sendline( cmdStr )
            assert response is not None, "Error in sendline"
            assert "Command not found:" not in response, response
            # Leader
            leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\
                "app\sis\s(?P<node>.+)\."
            nodeSearch = re.search( leaderPattern, response )
            if nodeSearch:
                node = nodeSearch.group( 'node' )
                main.log.info( "Election-test-leader on " + str( self.name ) +
                               " found " + node + " as the leader" )
                return node
            # no leader
            nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\
                "the\sElection\sapp"
            nullSearch = re.search( nullPattern, response )
            if nullSearch:
                main.log.info( "Election-test-leader found no leader on " +
                               self.name )
                return None
            # error
            main.log.error( self.name + ": Error in electionTestLeader on " + self.name +
                            ": " + "unexpected response" )
            main.log.error( repr( response ) )
            return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return None
        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 electionTestRun( self ):
        """
        CLI command to run for leadership of the Election test application.
        NOTE: Requires installation of the onos-app-election feature
        Returns: Main.TRUE on success
                 Main.FALSE on error
        """
        try:
            cmdStr = "election-test-run"
            response = self.sendline( cmdStr )
            assert response is not None, "Error in sendline"
            assert "Command not found:" not in response, response
            # success
            successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\
                "Election\sapp."
            search = re.search( successPattern, response )
            if search:
                main.log.info( self.name + " entering leadership elections " +
                               "for the Election app." )
                return main.TRUE
            # error
            main.log.error( self.name + ": Error in electionTestRun on " + self.name +
                            ": " + "unexpected response" )
            main.log.error( repr( response ) )
            return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return None
        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 electionTestWithdraw( self ):
        """
         * CLI command to withdraw the local node from leadership election for
         * the Election test application.
         #NOTE: Requires installation of the onos-app-election feature
         Returns: Main.TRUE on success
                  Main.FALSE on error
        """
        try:
            cmdStr = "election-test-withdraw"
            response = self.sendline( cmdStr )
            assert response is not None, "Error in sendline"
            assert "Command not found:" not in response, response
            # success
            successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\
                "\sthe\sElection\sapp."
            if re.search( successPattern, response ):
                main.log.info( self.name + " withdrawing from leadership " +
                               "elections for the Election app." )
                return main.TRUE
            # error
            main.log.error( self.name + ": Error in electionTestWithdraw on " +
                            self.name + ": " + "unexpected response" )
            main.log.error( repr( response ) )
            return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return None
        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 getDevicePortsEnabledCount( self, dpid ):
        """
        Get the count of all enabled ports on a particular device/switch
        """
        try:
            dpid = str( dpid )
            cmdStr = "onos:ports -e " + dpid + " | wc -l"
            output = self.lineCount( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            if re.search( "No such device", output ):
                main.log.error( self.name + ": Error in getting ports" )
                return ( output, "Error" )
            return output
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return ( output, "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 getDeviceLinksActiveCount( self, dpid ):
        """
        Get the count of all enabled ports on a particular device/switch
        """
        try:
            dpid = str( dpid )
            cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l"
            output = self.lineCount( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            if re.search( "No such device", output ):
                main.log.error( self.name + ": Error in getting ports " )
                return ( output, "Error " )
            return output
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return ( output, "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 getAllIntentIds( self ):
        """
        Return a list of all Intent IDs
        """
        try:
            cmdStr = "onos:intents | grep id="
            output = self.sendline( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            if re.search( "Error", output ):
                main.log.error( self.name + ": Error in getting ports" )
                return ( output, "Error" )
            return output
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return ( output, "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 intentSummary( self ):
        """
        Returns a dictionary containing the current intent states and the count
        """
        try:
            intents = self.intents( )
            states = []
            for intent in json.loads( intents ):
                states.append( intent.get( 'state', None ) )
            out = [ ( i, states.count( i ) ) for i in set( states ) ]
            main.log.info( dict( out ) )
            return dict( out )
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intents ) )
            return None
        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 leaders( self, jsonFormat=True ):
        """
        Returns the output of the leaders command.
        Optional argument:
            * jsonFormat - boolean indicating if you want output in json
        """
        try:
            cmdStr = "onos:leaders"
            if jsonFormat:
                cmdStr += " -j"
            output = self.sendline( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            return output
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 leaderCandidates( self, jsonFormat=True ):
        """
        Returns the output of the leaders -c command.
        Optional argument:
            * jsonFormat - boolean indicating if you want output in json
        """
        try:
            cmdStr = "onos:leaders -c"
            if jsonFormat:
                cmdStr += " -j"
            output = self.sendline( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            return output
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 specificLeaderCandidate( self, topic ):
        """
        Returns a list in format [leader,candidate1,candidate2,...] for a given
        topic parameter and an empty list if the topic doesn't exist
        If no leader is elected leader in the returned list will be "none"
        Returns None if there is a type error processing the json object
        """
        try:
            cmdStr = "onos:leaders -j"
            rawOutput = self.sendline( cmdStr )
            assert rawOutput is not None, "Error in sendline"
            assert "Command not found:" not in rawOutput, rawOutput
            output = json.loads( rawOutput )
            results = []
            for dict in output:
                if dict[ "topic" ] == topic:
                    leader = dict[ "leader" ]
                    candidates = re.split( ", ", dict[ "candidates" ][ 1:-1 ] )
                    results.append( leader )
                    results.extend( candidates )
            return results
        except AssertionError:
            main.log.exception( "" )
            return None
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawOutput ) )
            return None
        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 pendingMap( self, jsonFormat=True ):
        """
        Returns the output of the intent Pending map.
        """
        try:
            cmdStr = "onos:intents -p"
            if jsonFormat:
                cmdStr += " -j"
            output = self.sendline( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            return output
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 partitions( self, candidates=False, jsonFormat=True ):
        """
        Returns the output of the raft partitions command for ONOS.
        """
        # Sample JSON
        # {
        #     "leader": "tcp://10.128.30.11:7238",
        #     "members": [
        #         "tcp://10.128.30.11:7238",
        #         "tcp://10.128.30.17:7238",
        #         "tcp://10.128.30.13:7238",
        #     ],
        #     "name": "p1",
        #     "term": 3
        # },
        try:
            cmdStr = "onos:partitions"
            if candidates:
                cmdStr += " -c"
            if jsonFormat:
                cmdStr += " -j"
            output = self.sendline( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            return output
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 apps( self, summary=False, active=False, jsonFormat=True ):
        """
        Returns the output of the apps command for ONOS. This command lists
        information about installed ONOS applications
        """
        # Sample JSON object
        # [{"name":"org.onosproject.openflow","id":0,"version":"1.2.0",
        # "description":"ONOS OpenFlow protocol southbound providers",
        # "origin":"ON.Lab","permissions":"[]","featuresRepo":"",
        # "features":"[onos-openflow]","state":"ACTIVE"}]
        try:
            cmdStr = "onos:apps"
            expectJson = False
            if summary:
                cmdStr += " -s"
            if active:
                cmdStr += " -a"
            if jsonFormat:
                cmdStr += " -j"
                expectJson = True
            output = self.sendline( cmdStr, expectJson=expectJson )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            assert "Error executing command" not in output, output
            return output
        # FIXME: look at specific exceptions/Errors
        except AssertionError:
            main.log.exception( self.name + ": Error in processing onos:app command." )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 appStatus( self, appName ):
        """
        Uses the onos:apps cli command to return the status of an application.
        Returns:
            "ACTIVE" - If app is installed and activated
            "INSTALLED" - If app is installed and deactivated
            "UNINSTALLED" - If app is not installed
            None - on error
        """
        try:
            if not isinstance( appName, types.StringType ):
                main.log.error( self.name + ".appStatus(): appName must be" +
                                " a string" )
                return None
            output = self.apps( jsonFormat=True )
            appsJson = json.loads( output )
            state = None
            for app in appsJson:
                if appName == app.get( 'name' ):
                    state = app.get( 'state' )
                    break
            if state == "ACTIVE" or state == "INSTALLED":
                return state
            elif state is None:
                main.log.warn( "{} app not found".format( appName ) )
                return "UNINSTALLED"
            elif state:
                main.log.error( "Unexpected state from 'onos:apps': " +
                                str( state ) )
                return state
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, output ) )
            return None
        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 app( self, appName, option ):
        """
        Interacts with the app command for ONOS. This command manages
        application inventory.
        """
        try:
            # Validate argument types
            valid = True
            if not isinstance( appName, types.StringType ):
                main.log.error( self.name + ".app(): appName must be a " +
                                "string" )
                valid = False
            if not isinstance( option, types.StringType ):
                main.log.error( self.name + ".app(): option must be a string" )
                valid = False
            if not valid:
                return main.FALSE
            # Validate Option
            option = option.lower()
            # NOTE: Install may become a valid option
            if option == "activate":
                pass
            elif option == "deactivate":
                pass
            elif option == "uninstall":
                pass
            else:
                # Invalid option
                main.log.error( "The ONOS app command argument only takes " +
                                "the values: (activate|deactivate|uninstall)" +
                                "; was given '" + option + "'" )
                return main.FALSE
            cmdStr = "onos:app " + option + " " + appName
            output = self.sendline( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            if "Error executing command" in output:
                main.log.error( self.name + ": Error in processing onos:app command: " +
                                str( output ) )
                return main.FALSE
            elif "No such application" in output:
                main.log.error( "The application '" + appName +
                                "' is not installed in ONOS" )
                return main.FALSE
            elif "Command not found:" in output:
                main.log.error( self.name + ": Error in processing onos:app command: " +
                                str( output ) )
                return main.FALSE
            elif "Unsupported command:" in output:
                main.log.error( "Incorrect command given to 'app': " +
                                str( output ) )
            # NOTE: we may need to add more checks here
            # else: Command was successful
            # main.log.debug( "app response: " + repr( output ) )
            return main.TRUE
        except AssertionError:
            main.log.exception( self.name + ": AssertionError exception found" )
            return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            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 activateApp( self, appName, check=True ):
        """
        Activate an app that is already installed in ONOS
        appName is the hierarchical app name, not the feature name
        If check is True, method will check the status of the app after the
        command is issued
        Returns main.TRUE if the command was successfully sent
                main.FALSE if the cli responded with an error or given
                    incorrect input
        """
        try:
            if not isinstance( appName, types.StringType ):
                main.log.error( self.name + ".activateApp(): appName must be" +
                                " a string" )
                return main.FALSE
            status = self.appStatus( appName )
            if status == "INSTALLED":
                response = self.app( appName, "activate" )
                if check and response == main.TRUE:
                    for i in range( 10 ):  # try 10 times then give up
                        status = self.appStatus( appName )
                        if status == "ACTIVE":
                            return main.TRUE
                        else:
                            main.log.debug( "The state of application " +
                                            appName + " is " + status )
                            time.sleep( 1 )
                    return main.FALSE
                else:  # not 'check' or command didn't succeed
                    return response
            elif status == "ACTIVE":
                return main.TRUE
            elif status == "UNINSTALLED":
                main.log.error( self.name + ": Tried to activate the " +
                                "application '" + appName + "' which is not " +
                                "installed." )
            else:
                main.log.error( "Unexpected return value from appStatus: " +
                                str( status ) )
                return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            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 deactivateApp( self, appName, check=True ):
        """
        Deactivate an app that is already activated in ONOS
        appName is the hierarchical app name, not the feature name
        If check is True, method will check the status of the app after the
        command is issued
        Returns main.TRUE if the command was successfully sent
                main.FALSE if the cli responded with an error or given
                    incorrect input
        """
        try:
            if not isinstance( appName, types.StringType ):
                main.log.error( self.name + ".deactivateApp(): appName must " +
                                "be a string" )
                return main.FALSE
            status = self.appStatus( appName )
            if status == "INSTALLED":
                return main.TRUE
            elif status == "ACTIVE":
                response = self.app( appName, "deactivate" )
                if check and response == main.TRUE:
                    for i in range( 10 ):  # try 10 times then give up
                        status = self.appStatus( appName )
                        if status == "INSTALLED":
                            return main.TRUE
                        else:
                            time.sleep( 1 )
                    return main.FALSE
                else:  # not check or command didn't succeed
                    return response
            elif status == "UNINSTALLED":
                main.log.warn( self.name + ": Tried to deactivate the " +
                                "application '" + appName + "' which is not " +
                                "installed." )
                return main.TRUE
            else:
                main.log.error( "Unexpected return value from appStatus: " +
                                str( status ) )
                return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            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 uninstallApp( self, appName, check=True ):
        """
        Uninstall an app that is already installed in ONOS
        appName is the hierarchical app name, not the feature name
        If check is True, method will check the status of the app after the
        command is issued
        Returns main.TRUE if the command was successfully sent
                main.FALSE if the cli responded with an error or given
                    incorrect input
        """
        # TODO: check with Thomas about the state machine for apps
        try:
            if not isinstance( appName, types.StringType ):
                main.log.error( self.name + ".uninstallApp(): appName must " +
                                "be a string" )
                return main.FALSE
            status = self.appStatus( appName )
            if status == "INSTALLED":
                response = self.app( appName, "uninstall" )
                if check and response == main.TRUE:
                    for i in range( 10 ):  # try 10 times then give up
                        status = self.appStatus( appName )
                        if status == "UNINSTALLED":
                            return main.TRUE
                        else:
                            time.sleep( 1 )
                    return main.FALSE
                else:  # not check or command didn't succeed
                    return response
            elif status == "ACTIVE":
                main.log.warn( self.name + ": Tried to uninstall the " +
                                "application '" + appName + "' which is " +
                                "currently active." )
                response = self.app( appName, "uninstall" )
                if check and response == main.TRUE:
                    for i in range( 10 ):  # try 10 times then give up
                        status = self.appStatus( appName )
                        if status == "UNINSTALLED":
                            return main.TRUE
                        else:
                            time.sleep( 1 )
                    return main.FALSE
                else:  # not check or command didn't succeed
                    return response
            elif status == "UNINSTALLED":
                return main.TRUE
            else:
                main.log.error( "Unexpected return value from appStatus: " +
                                str( status ) )
                return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            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 appIDs( self, jsonFormat=True ):
        """
        Show the mappings between app id and app names given by the 'app-ids'
        cli command
        """
        try:
            cmdStr = "app-ids"
            if jsonFormat:
                cmdStr += " -j"
            output = self.sendline( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            assert "Error executing command" not in output, output
            return output
        except AssertionError:
            main.log.exception( self.name + ": Error in processing onos:app-ids command." )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 appToIDCheck( self ):
        """
        This method will check that each application's ID listed in 'apps' is
        the same as the ID listed in 'app-ids'. The check will also check that
        there are no duplicate IDs issued. Note that an app ID should be
        a globaly unique numerical identifier for app/app-like features. Once
        an ID is registered, the ID is never freed up so that if an app is
        reinstalled it will have the same ID.

        Returns: main.TRUE  if the check passes and
                 main.FALSE if the check fails or
                 main.ERROR if there is some error in processing the test
        """
        try:
            # Grab IDs
            rawJson = self.appIDs( jsonFormat=True )
            if rawJson:
                ids = json.loads( rawJson )
            else:
                main.log.error( "app-ids returned nothing: " + repr( rawJson ) )
                return main.FALSE

            # Grab Apps
            rawJson = self.apps( jsonFormat=True )
            if rawJson:
                apps = json.loads( rawJson )
            else:
                main.log.error( "apps returned nothing:" + repr( rawJson ) )
                return main.FALSE

            result = main.TRUE
            for app in apps:
                appID = app.get( 'id' )
                if appID is None:
                    main.log.error( "Error parsing app: " + str( app ) )
                    result = main.FALSE
                appName = app.get( 'name' )
                if appName is None:
                    main.log.error( "Error parsing app: " + str( app ) )
                    result = main.FALSE
                # get the entry in ids that has the same appID
                current = filter( lambda item: item[ 'id' ] == appID, ids )
                if not current:  # if ids doesn't have this id
                    result = main.FALSE
                    main.log.error( "'app-ids' does not have the ID for " +
                                    str( appName ) + " that apps does." )
                    main.log.debug( "apps command returned: " + str( app ) +
                                    "; app-ids has: " + str( ids ) )
                elif len( current ) > 1:
                    # there is more than one app with this ID
                    result = main.FALSE
                    # We will log this later in the method
                elif not current[ 0 ][ 'name' ] == appName:
                    currentName = current[ 0 ][ 'name' ]
                    result = main.FALSE
                    main.log.error( "'app-ids' has " + str( currentName ) +
                                    " registered under id:" + str( appID ) +
                                    " but 'apps' has " + str( appName ) )
                else:
                    pass  # id and name match!

            # now make sure that app-ids has no duplicates
            idsList = []
            namesList = []
            for item in ids:
                idsList.append( item[ 'id' ] )
                namesList.append( item[ 'name' ] )
            if len( idsList ) != len( set( idsList ) ) or\
               len( namesList ) != len( set( namesList ) ):
                main.log.error( "'app-ids' has some duplicate entries: \n"
                                + json.dumps( ids,
                                              sort_keys=True,
                                              indent=4,
                                              separators=( ',', ': ' ) ) )
                result = main.FALSE
            return result
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) )
            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 getCfg( self, component=None, propName=None, short=False,
                jsonFormat=True ):
        """
        Get configuration settings from onos cli
        Optional arguments:
            component - Optionally only list configurations for a specific
                        component. If None, all components with configurations
                        are displayed. Case Sensitive string.
            propName - If component is specified, propName option will show
                       only this specific configuration from that component.
                       Case Sensitive string.
            jsonFormat - Returns output as json. Note that this will override
                         the short option
            short - Short, less verbose, version of configurations.
                    This is overridden by the json option
        returns:
            Output from cli as a string or None on error
        """
        try:
            baseStr = "cfg"
            cmdStr = " get"
            componentStr = ""
            if component:
                componentStr += " " + component
                if propName:
                    componentStr += " " + propName
            if jsonFormat:
                baseStr += " -j"
                expectJson = True
            elif short:
                baseStr += " -s"
                expectJson = False
            output = self.sendline( baseStr + cmdStr + componentStr, expectJson=expectJson )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            assert "Error executing command" not in output, output
            return output
        except AssertionError:
            main.log.exception( self.name + ": Error in processing 'cfg get' command." )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 setCfg( self, component, propName, value=None, check=True ):
        """
        Set/Unset configuration settings from ONOS cli
        Required arguments:
            component - The case sensitive name of the component whose
                        property is to be set
            propName - The case sensitive name of the property to be set/unset
        Optional arguments:
            value - The value to set the property to. If None, will unset the
                    property and revert it to it's default value(if applicable)
            check - Boolean, Check whether the option was successfully set this
                    only applies when a value is given.
        returns:
            main.TRUE on success or main.FALSE on failure. If check is False,
            will return main.TRUE unless there is an error
        """
        try:
            baseStr = "cfg"
            cmdStr = " set " + str( component ) + " " + str( propName )
            if value is not None:
                cmdStr += " " + str( value )
            output = self.sendline( baseStr + cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            assert "Error executing command" not in output, output
            if value and check:
                results = self.getCfg( component=str( component ),
                                       propName=str( propName ),
                                       jsonFormat=True )
                # Check if current value is what we just set
                try:
                    jsonOutput = json.loads( results )
                    current = jsonOutput[ 'value' ]
                except ( TypeError, ValueError ):
                    main.log.exception( "Error parsing cfg output" )
                    main.log.error( "output:" + repr( results ) )
                    return main.FALSE
                if current == str( value ):
                    return main.TRUE
                return main.FALSE
            return main.TRUE
        except AssertionError:
            main.log.exception( self.name + ": Error in processing 'cfg set' command." )
            return main.FALSE
        except ( TypeError, ValueError ):
            main.log.exception( "{}: Object not as expected: {!r}".format( self.name, results ) )
            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 distPrimitivesSend( self, cmd ):
        """
        Function to handle sending cli commands for the distributed primitives test app

        This command will catch some exceptions and retry the command on some
        specific store exceptions.

        Required arguments:
            cmd - The command to send to the cli
        returns:
            string containing the cli output
            None on Error
        """
        try:
            output = self.sendline( cmd )
            try:
                assert output is not None, "Error in sendline"
                # TODO: Maybe make this less hardcoded
                # ConsistentMap Exceptions
                assert "org.onosproject.store.service" not in output
                # Node not leader
                assert "java.lang.IllegalStateException" not in output
            except AssertionError:
                main.log.error( self.name + ": Error in processing '" + cmd + "' " +
                                "command: " + str( output ) )
                retryTime = 30  # Conservative time, given by Madan
                main.log.info( "Waiting " + str( retryTime ) +
                               "seconds before retrying." )
                time.sleep( retryTime )  # Due to change in mastership
                output = self.sendline( cmd )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            assert "Error executing command" not in output, output
            main.log.info( self.name + ": " + output )
            return output
        except AssertionError:
            main.log.exception( self.name + ": Error in processing '" + cmd + "' command." )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 setTestAdd( self, setName, values ):
        """
        CLI command to add elements to a distributed set.
        Arguments:
            setName - The name of the set to add to.
            values - The value(s) to add to the set, space seperated.
        Example usages:
            setTestAdd( "set1", "a b c" )
            setTestAdd( "set2", "1" )
        returns:
            main.TRUE on success OR
            main.FALSE if elements were already in the set OR
            main.ERROR on error
        """
        try:
            cmdStr = "set-test-add " + str( setName ) + " " + str( values )
            output = self.distPrimitivesSend( cmdStr )
            positiveMatch = "\[(.*)\] was added to the set " + str( setName )
            negativeMatch = "\[(.*)\] was already in set " + str( setName )
            if re.search( positiveMatch, output ):
                return main.TRUE
            elif re.search( negativeMatch, output ):
                return main.FALSE
            else:
                main.log.error( self.name + ": setTestAdd did not" +
                                " match expected output" )
                main.log.debug( self.name + " actual: " + repr( output ) )
                return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.ERROR
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def setTestRemove( self, setName, values, clear=False, retain=False ):
        """
        CLI command to remove elements from a distributed set.
        Required arguments:
            setName - The name of the set to remove from.
            values - The value(s) to remove from the set, space seperated.
        Optional arguments:
            clear - Clear all elements from the set
            retain - Retain only the  given values. (intersection of the
                     original set and the given set)
        returns:
            main.TRUE on success OR
            main.FALSE if the set was not changed OR
            main.ERROR on error
        """
        try:
            cmdStr = "set-test-remove "
            if clear:
                cmdStr += "-c " + str( setName )
            elif retain:
                cmdStr += "-r " + str( setName ) + " " + str( values )
            else:
                cmdStr += str( setName ) + " " + str( values )
            output = self.distPrimitivesSend( cmdStr )
            if clear:
                pattern = "Set " + str( setName ) + " cleared"
                if re.search( pattern, output ):
                    return main.TRUE
            elif retain:
                positivePattern = str( setName ) + " was pruned to contain " +\
                                  "only elements of set \[(.*)\]"
                negativePattern = str( setName ) + " was not changed by " +\
                                  "retaining only elements of the set " +\
                                  "\[(.*)\]"
                if re.search( positivePattern, output ):
                    return main.TRUE
                elif re.search( negativePattern, output ):
                    return main.FALSE
            else:
                positivePattern = "\[(.*)\] was removed from the set " +\
                                  str( setName )
                if ( len( values.split() ) == 1 ):
                    negativePattern = "\[(.*)\] was not in set " +\
                                      str( setName )
                else:
                    negativePattern = "No element of \[(.*)\] was in set " +\
                                      str( setName )
                if re.search( positivePattern, output ):
                    return main.TRUE
                elif re.search( negativePattern, output ):
                    return main.FALSE
            main.log.error( self.name + ": setTestRemove did not" +
                            " match expected output" )
            main.log.debug( self.name + " expected: " + pattern )
            main.log.debug( self.name + " actual: " + repr( output ) )
            return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.ERROR
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def setTestGet( self, setName, values="" ):
        """
        CLI command to get the elements in a distributed set.
        Required arguments:
            setName - The name of the set to remove from.
        Optional arguments:
            values - The value(s) to check if in the set, space seperated.
        returns:
            main.ERROR on error OR
            A list of elements in the set if no optional arguments are
                supplied OR
            A tuple containing the list then:
                main.FALSE if the given values are not in the set OR
                main.TRUE if the given values are in the set OR
        """
        try:
            values = str( values ).strip()
            setName = str( setName ).strip()
            length = len( values.split() )
            containsCheck = None
            # Patterns to match
            setPattern = "\[(.*)\]"
            pattern = "Items in set " + setName + ":\r\n" + setPattern
            containsTrue = "Set " + setName + " contains the value " + values
            containsFalse = "Set " + setName + " did not contain the value " +\
                            values
            containsAllTrue = "Set " + setName + " contains the the subset " +\
                              setPattern
            containsAllFalse = "Set " + setName + " did not contain the the" +\
                               " subset " + setPattern

            cmdStr = "set-test-get "
            cmdStr += setName + " " + values
            output = self.distPrimitivesSend( cmdStr )
            if length == 0:
                match = re.search( pattern, output )
            else:  # if given values
                if length == 1:  # Contains output
                    patternTrue = pattern + "\r\n" + containsTrue
                    patternFalse = pattern + "\r\n" + containsFalse
                else:  # ContainsAll output
                    patternTrue = pattern + "\r\n" + containsAllTrue
                    patternFalse = pattern + "\r\n" + containsAllFalse
                matchTrue = re.search( patternTrue, output )
                matchFalse = re.search( patternFalse, output )
                if matchTrue:
                    containsCheck = main.TRUE
                    match = matchTrue
                elif matchFalse:
                    containsCheck = main.FALSE
                    match = matchFalse
                else:
                    main.log.error( self.name + " setTestGet did not match " +
                                    "expected output" )
                    main.log.debug( self.name + " expected: " + pattern )
                    main.log.debug( self.name + " actual: " + repr( output ) )
                    match = None
            if match:
                setMatch = match.group( 1 )
                if setMatch == '':
                    setList = []
                else:
                    setList = setMatch.split( ", " )
                if length > 0:
                    return ( setList, containsCheck )
                else:
                    return setList
            else:  # no match
                main.log.error( self.name + ": setTestGet did not" +
                                " match expected output" )
                main.log.debug( self.name + " expected: " + pattern )
                main.log.debug( self.name + " actual: " + repr( output ) )
                return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.ERROR
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def setTestSize( self, setName ):
        """
        CLI command to get the elements in a distributed set.
        Required arguments:
            setName - The name of the set to remove from.
        returns:
            The integer value of the size returned or
            None on error
        """
        try:
            # TODO: Should this check against the number of elements returned
            #       and then return true/false based on that?
            setName = str( setName ).strip()
            # Patterns to match
            setPattern = "\[(.*)\]"
            pattern = "There are (\d+) items in set " + setName + ":\r\n" +\
                          setPattern
            cmdStr = "set-test-get -s "
            cmdStr += setName
            output = self.distPrimitivesSend( cmdStr )
            if output:
                match = re.search( pattern, output )
                if match:
                    setSize = int( match.group( 1 ) )
                    setMatch = match.group( 2 )
                    if len( setMatch.split() ) == setSize:
                        main.log.info( "The size returned by " + self.name +
                                       " matches the number of elements in " +
                                       "the returned set" )
                    else:
                        main.log.error( "The size returned by " + self.name +
                                        " does not match the number of " +
                                        "elements in the returned set." )
                    return setSize
            else:  # no match
                main.log.error( self.name + ": setTestGet did not" +
                                " match expected output" )
                main.log.debug( self.name + " expected: " + pattern )
                main.log.debug( self.name + " actual: " + repr( output ) )
                return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def counters( self, jsonFormat=True ):
        """
        Command to list the various counters in the system.
        returns:
            if jsonFormat, a string of the json object returned by the cli
            command
            if not jsonFormat, the normal string output of the cli command
            None on error
        """
        try:
            cmdStr = "counters"
            if jsonFormat:
                cmdStr += " -j"
            output = self.sendline( cmdStr )
            main.log.debug( self.name + ": Counters unparsed: " + output )
            output = output.split( "\r\n" )[ -1 ]
            main.log.debug( self.name + ": Counters parsed: " + output )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            assert "Error executing command" not in output, output
            main.log.info( self.name + ": " + output )
            return output
        except AssertionError:
            main.log.exception( self.name + ": Error in processing 'counters' command." )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 counterTestAddAndGet( self, counter, delta=1 ):
        """
        CLI command to add a delta to then get a distributed counter.
        Required arguments:
            counter - The name of the counter to increment.
        Optional arguments:
            delta - The long to add to the counter
        returns:
            integer value of the counter or
            None on Error
        """
        try:
            counter = str( counter )
            delta = int( delta )
            cmdStr = "counter-test-increment "
            cmdStr += counter
            if delta != 1:
                cmdStr += " " + str( delta )
            output = self.distPrimitivesSend( cmdStr )
            pattern = counter + " was updated to (-?\d+)"
            match = re.search( pattern, output )
            if match:
                return int( match.group( 1 ) )
            else:
                main.log.error( self.name + ": counterTestAddAndGet did not" +
                                " match expected output." )
                main.log.debug( self.name + " expected: " + pattern )
                main.log.debug( self.name + " actual: " + repr( output ) )
                return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def counterTestGetAndAdd( self, counter, delta=1 ):
        """
        CLI command to get a distributed counter then add a delta to it.
        Required arguments:
            counter - The name of the counter to increment.
        Optional arguments:
            delta - The long to add to the counter
        returns:
            integer value of the counter or
            None on Error
        """
        try:
            counter = str( counter )
            delta = int( delta )
            cmdStr = "counter-test-increment -g "
            cmdStr += counter
            if delta != 1:
                cmdStr += " " + str( delta )
            output = self.distPrimitivesSend( cmdStr )
            pattern = counter + " was updated to (-?\d+)"
            match = re.search( pattern, output )
            if match:
                return int( match.group( 1 ) )
            else:
                main.log.error( self.name + ": counterTestGetAndAdd did not" +
                                " match expected output." )
                main.log.debug( self.name + " expected: " + pattern )
                main.log.debug( self.name + " actual: " + repr( output ) )
                return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def valueTestGet( self, valueName ):
        """
        CLI command to get the value of an atomic value.
        Required arguments:
            valueName - The name of the value to get.
        returns:
            string value of the value or
            None on Error
        """
        try:
            valueName = str( valueName )
            cmdStr = "value-test "
            operation = "get"
            cmdStr = "value-test {} {}".format( valueName,
                                                operation )
            output = self.distPrimitivesSend( cmdStr )
            main.log.debug( self.name + ": value test unparsed: " + output )
            output = output.split( "\r\n" )[ -1 ]
            main.log.debug( self.name + ": value test parsed: " + output )
            pattern = "(\w+)"
            match = re.search( pattern, output )
            if match:
                return match.group( 1 )
            else:
                main.log.error( self.name + ": valueTestGet did not" +
                                " match expected output." )
                main.log.debug( self.name + " expected: " + pattern )
                main.log.debug( self.name + " actual: " + repr( output ) )
                return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def valueTestSet( self, valueName, newValue ):
        """
        CLI command to set the value of an atomic value.
        Required arguments:
            valueName - The name of the value to set.
            newValue - The value to assign to the given value.
        returns:
            main.TRUE on success or
            main.ERROR on Error
        """
        try:
            valueName = str( valueName )
            newValue = str( newValue )
            operation = "set"
            cmdStr = "value-test {} {} {}".format( valueName,
                                                   operation,
                                                   newValue )
            output = self.distPrimitivesSend( cmdStr )
            if output is not None:
                return main.TRUE
            else:
                return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.ERROR
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def valueTestCompareAndSet( self, valueName, oldValue, newValue ):
        """
        CLI command to compareAndSet the value of an atomic value.
        Required arguments:
            valueName - The name of the value.
            oldValue - Compare the current value of the atomic value to this
            newValue - If the value equals oldValue, set the value to newValue
        returns:
            main.TRUE on success or
            main.FALSE on failure or
            main.ERROR on Error
        """
        try:
            valueName = str( valueName )
            oldValue = str( oldValue )
            newValue = str( newValue )
            operation = "compareAndSet"
            cmdStr = "value-test {} {} {} {}".format( valueName,
                                                      operation,
                                                      oldValue,
                                                      newValue )
            output = self.distPrimitivesSend( cmdStr )
            pattern = "(\w+)"
            match = re.search( pattern, output )
            if match:
                result = match.group( 1 )
                if result == "true":
                    return main.TRUE
                elif result == "false":
                    return main.FALSE
            else:
                main.log.error( self.name + ": valueTestCompareAndSet did not" +
                                " match expected output." )
                main.log.debug( self.name + " expected: " + pattern )
                main.log.debug( self.name + " actual: " + repr( output ) )
                return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.ERROR
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def valueTestGetAndSet( self, valueName, newValue ):
        """
        CLI command to getAndSet the value of an atomic value.
        Required arguments:
            valueName - The name of the value to get.
            newValue - The value to assign to the given value
        returns:
            string value of the value or
            None on Error
        """
        try:
            valueName = str( valueName )
            cmdStr = "value-test "
            operation = "getAndSet"
            cmdStr += valueName + " " + operation
            cmdStr = "value-test {} {} {}".format( valueName,
                                                   operation,
                                                   newValue )
            output = self.distPrimitivesSend( cmdStr )
            pattern = "(\w+)"
            match = re.search( pattern, output )
            if match:
                return match.group( 1 )
            else:
                main.log.error( self.name + ": valueTestGetAndSet did not" +
                                " match expected output." )
                main.log.debug( self.name + " expected: " + pattern )
                main.log.debug( self.name + " actual: " + repr( output ) )
                return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def valueTestDestroy( self, valueName ):
        """
        CLI command to destroy an atomic value.
        Required arguments:
            valueName - The name of the value to destroy.
        returns:
            main.TRUE on success or
            main.ERROR on Error
        """
        try:
            valueName = str( valueName )
            cmdStr = "value-test "
            operation = "destroy"
            cmdStr += valueName + " " + operation
            output = self.distPrimitivesSend( cmdStr )
            if output is not None:
                return main.TRUE
            else:
                return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.ERROR
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def summary( self, jsonFormat=True, timeout=30 ):
        """
        Description: Execute summary command in onos
        Returns: json object ( summary -j ), returns main.FALSE if there is
        no output

        """
        try:
            cmdStr = "summary"
            if jsonFormat:
                cmdStr += " -j"
            handle = self.sendline( cmdStr, timeout=timeout )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Error:" not in handle, handle
            assert "Error executing" not in handle, handle
            if not handle:
                main.log.error( self.name + ": There is no output in " +
                                "summary command" )
                return main.FALSE
            return handle
        except AssertionError:
            main.log.exception( "{} Error in summary output:".format( self.name ) )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 getAddress( self):
        """
        Get the onos ip address from the cli. This is usefull when connecting using
        a container manager such as kubernetes. This function also sets self.address
        the value from ONOS.

        Returns:
            The string value of the key or
            None on Error
        """
        try:
            output = self.summary()
            address = json.loads( output ).get( 'node' )
            self.address = address
            return address
        except ( TypeError, ValueError ):
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def transactionalMapGet( self, keyName ):
        """
        CLI command to get the value of a key in a consistent map using
        transactions. This a test function and can only get keys from the
        test map hard coded into the cli command
        Required arguments:
            keyName - The name of the key to get
        returns:
            The string value of the key or
            None on Error
        """
        try:
            keyName = str( keyName )
            cmdStr = "transactional-map-test-get "
            cmdStr += keyName
            output = self.distPrimitivesSend( cmdStr )
            pattern = "Key-value pair \(" + keyName + ", (?P<value>.+)\) found."
            if "Key " + keyName + " not found." in output:
                main.log.warn( output )
                return None
            else:
                match = re.search( pattern, output )
                if match:
                    return match.groupdict()[ 'value' ]
                else:
                    main.log.error( self.name + ": transactionlMapGet did not" +
                                    " match expected output." )
                    main.log.debug( self.name + " expected: " + pattern )
                    main.log.debug( self.name + " actual: " + repr( output ) )
                    return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def transactionalMapPut( self, numKeys, value ):
        """
        CLI command to put a value into 'numKeys' number of keys in a
        consistent map using transactions. This a test function and can only
        put into keys named 'Key#' of the test map hard coded into the cli command
        Required arguments:
            numKeys - Number of keys to add the value to
            value - The string value to put into the keys
        returns:
            A dictionary whose keys are the name of the keys put into the map
            and the values of the keys are dictionaries whose key-values are
            'value': value put into map and optionaly
            'oldValue': Previous value in the key or
            None on Error

            Example output
            { 'Key1': {'oldValue': 'oldTestValue', 'value': 'Testing'},
              'Key2': {'value': 'Testing'} }
        """
        try:
            numKeys = str( numKeys )
            value = str( value )
            cmdStr = "transactional-map-test-put "
            cmdStr += numKeys + " " + value
            output = self.distPrimitivesSend( cmdStr )
            newPattern = 'Created Key (?P<key>(\w)+) with value (?P<value>(.)+)\.'
            updatedPattern = "Put (?P<value>(.)+) into key (?P<key>(\w)+)\. The old value was (?P<oldValue>(.)+)\."
            results = {}
            for line in output.splitlines():
                new = re.search( newPattern, line )
                updated = re.search( updatedPattern, line )
                if new:
                    results[ new.groupdict()[ 'key' ] ] = { 'value': new.groupdict()[ 'value' ] }
                elif updated:
                    results[ updated.groupdict()[ 'key' ] ] = { 'value': updated.groupdict()[ 'value' ],
                                                                'oldValue': updated.groupdict()[ 'oldValue' ] }
                else:
                    main.log.error( self.name + ": transactionlMapGet did not" +
                                    " match expected output." )
                    main.log.debug( "{} expected: {!r} or {!r}".format( self.name,
                                                                        newPattern,
                                                                        updatedPattern ) )
                    main.log.debug( self.name + " actual: " + repr( output ) )
            return results
        except ( TypeError, AttributeError ):
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def maps( self, jsonFormat=True ):
        """
        Description: Returns result of onos:maps
        Optional:
            * jsonFormat: enable json formatting of output
        """
        try:
            cmdStr = "maps"
            if jsonFormat:
                cmdStr += " -j"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 getSwController( self, uri, jsonFormat=True ):
        """
        Descrition: Gets the controller information from the device
        """
        try:
            cmd = "device-controllers "
            if jsonFormat:
                cmd += "-j "
            response = self.sendline( cmd + uri )
            assert response is not None, "Error in sendline"
            assert "Command not found:" not in response, response
            return response
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 setSwController( self, uri, ip, proto="tcp", port="6653", jsonFormat=True ):
        """
        Descrition: sets the controller(s) for the specified device

        Parameters:
            Required: uri - String: The uri of the device(switch).
                      ip - String or List: The ip address of the controller.
                      This parameter can be formed in a couple of different ways.
                        VALID:
                        10.0.0.1 - just the ip address
                        tcp:10.0.0.1 - the protocol and the ip address
                        tcp:10.0.0.1:6653 - the protocol and port can be specified,
                                            so that you can add controllers with different
                                            protocols and ports
                        INVALID:
                        10.0.0.1:6653 - this is not supported by ONOS

            Optional: proto - The type of connection e.g. tcp, ssl. If a list of ips are given
                      port - The port number.
                      jsonFormat - If set ONOS will output in json NOTE: This is currently not supported

        Returns: main.TRUE if ONOS returns without any errors, otherwise returns main.FALSE
        """
        try:
            cmd = "device-setcontrollers"

            if jsonFormat:
                cmd += " -j"
            cmd += " " + uri
            if isinstance( ip, str ):
                ip = [ ip ]
            for item in ip:
                if ":" in item:
                    sitem = item.split( ":" )
                    if len( sitem ) == 3:
                        cmd += " " + item
                    elif "." in sitem[ 1 ]:
                        cmd += " {}:{}".format( item, port )
                    else:
                        main.log.error( "Malformed entry: " + item )
                        raise TypeError
                else:
                    cmd += " {}:{}:{}".format( proto, item, port )
            response = self.sendline( cmd )
            assert response is not None, "Error in sendline"
            assert "Command not found:" not in response, response
            if "Error" in response:
                main.log.error( response )
                return main.FALSE
            return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            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 removeDevice( self, device ):
        '''
        Description:
            Remove a device from ONOS by passing the uri of the device(s).
        Parameters:
            device - (str or list) the id or uri of the device ex. "of:0000000000000001"
        Returns:
            Returns main.FALSE if an exception is thrown or an error is present
            in the response. Otherwise, returns main.TRUE.
        NOTE:
            If a host cannot be removed, then this function will return main.FALSE
        '''
        try:
            if isinstance( device, str ):
                deviceStr = device
                device = []
                device.append( deviceStr )

            for d in device:
                time.sleep( 1 )
                response = self.sendline( "device-remove {}".format( d ) )
                assert response is not None, "Error in sendline"
                assert "Command not found:" not in response, response
                if "Error" in response:
                    main.log.warn( "Error for device: {}\nResponse: {}".format( d, response ) )
                    return main.FALSE
            return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            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 removeHost( self, host ):
        '''
        Description:
            Remove a host from ONOS by passing the id of the host(s)
        Parameters:
            hostId - (str or list) the id or mac of the host ex. "00:00:00:00:00:01"
        Returns:
            Returns main.FALSE if an exception is thrown or an error is present
            in the response. Otherwise, returns main.TRUE.
        NOTE:
            If a host cannot be removed, then this function will return main.FALSE
        '''
        try:
            if isinstance( host, str ):
                host = list( host )

            for h in host:
                time.sleep( 1 )
                response = self.sendline( "host-remove {}".format( h ) )
                assert response is not None, "Error in sendline"
                assert "Command not found:" not in response, response
                if "Error" in response:
                    main.log.warn( "Error for host: {}\nResponse: {}".format( h, response ) )
                    return main.FALSE
            return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            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 link( self, begin, end, state, timeout=30, showResponse=True ):
        '''
        Description:
            Bring link down or up in the null-provider.
        params:
            begin - (string) One end of a device or switch.
            end - (string) the other end of the device or switch
        returns:
            main.TRUE if no exceptions were thrown and no Errors are
            present in the resoponse. Otherwise, returns main.FALSE
        '''
        try:
            cmd = "null-link null:{} null:{} {}".format( begin, end, state )
            response = self.sendline( cmd, showResponse=showResponse, timeout=timeout )
            assert response is not None, "Error in sendline"
            assert "Command not found:" not in response, response
            if "Error" in response or "Failure" in response:
                main.log.error( response )
                return main.FALSE
            return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            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 portstate( self, dpid, port, state ):
        '''
        Description:
             Changes the state of port in an OF switch by means of the
             PORTSTATUS OF messages.
        params:
            dpid - (string) Datapath ID of the device. Ex: 'of:0000000000000102'
            port - (string) target port in the device. Ex: '2'
            state - (string) target state (enable or disable)
        returns:
            main.TRUE if no exceptions were thrown and no Errors are
            present in the resoponse. Otherwise, returns main.FALSE
        '''
        try:
            state = state.lower()
            assert state == 'enable' or state == 'disable', "Unknown state"
            cmd = "portstate {} {} {}".format( dpid, port, state )
            response = self.sendline( cmd, showResponse=True )
            assert response is not None, "Error in sendline"
            assert "Command not found:" not in response, response
            if "Error" in response or "Failure" in response:
                main.log.error( response )
                return main.FALSE
            return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            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 logSet( self, level="INFO", app="org.onosproject" ):
        """
        Set the logging level to lvl for a specific app
        returns main.TRUE on success
        returns main.FALSE if Error occurred
        if noExit is True, TestON will not exit, but clean up
        Available level: DEBUG, TRACE, INFO, WARN, ERROR
        Level defaults to INFO
        """
        try:
            handle = self.sendline( "log:set %s %s" % ( level, app ) )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            if re.search( "Error", handle ):
                main.log.error( self.name + ": Error in setting log level" )
                main.log.error( handle )
                return main.FALSE
            else:
                return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 logList( self, saveValues=True ):
        """
        Gets the current log levels and optionally saves them
        returns a dict of the log levels or
        returns main.FALSE if Error occurred
        """
        try:
            self.handle.sendline( "log:list" )
            self.handle.expect( self.karafPrompt )

            response = self.handle.before
            logLevels = {}
            for line in response.splitlines():
                parsed = line.split('│')
                logger = parsed[0].strip()
                if len( parsed ) != 2 or 'Level' in parsed[1] or logger[0] == '─':
                    continue
                level = parsed[1].strip()
                logLevels[ logger ] = level
            if saveValues:
                self.logLevels = logLevels
            return logLevels
        except pexpect.TIMEOUT:
            main.log.exception( self.name + ": TIMEOUT exception found" )
            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 getGraphDict( self, timeout=60, includeHost=False ):
        """
        Return a dictionary which describes the latest network topology data as a
        graph.
        An example of the dictionary:
        { vertex1: { 'edges': ..., 'name': ..., 'protocol': ... },
          vertex2: { 'edges': ..., 'name': ..., 'protocol': ... } }
        Each vertex should at least have an 'edges' attribute which describes the
        adjacency information. The value of 'edges' attribute is also represented by
        a dictionary, which maps each edge (identified by the neighbor vertex) to a
        list of attributes.
        An example of the edges dictionary:
        'edges': { vertex2: { 'port': ..., 'weight': ... },
                   vertex3: { 'port': ..., 'weight': ... } }
        If includeHost == True, all hosts (and host-switch links) will be included
        in topology data.
        """
        graphDict = {}
        try:
            links = self.links()
            links = json.loads( links )
            devices = self.devices()
            devices = json.loads( devices )
            idToDevice = {}
            for device in devices:
                idToDevice[ device[ 'id' ] ] = device
            if includeHost:
                hosts = self.hosts()
                # FIXME: support 'includeHost' argument
            for link in links:
                nodeA = link[ 'src' ][ 'device' ]
                nodeB = link[ 'dst' ][ 'device' ]
                assert idToDevice[ nodeA ][ 'available' ] and idToDevice[ nodeB ][ 'available' ]
                if nodeA not in graphDict.keys():
                    graphDict[ nodeA ] = { 'edges': {},
                                           'dpid': idToDevice[ nodeA ][ 'id' ][ 3: ],
                                           'type': idToDevice[ nodeA ][ 'type' ],
                                           'available': idToDevice[ nodeA ][ 'available' ],
                                           'role': idToDevice[ nodeA ][ 'role' ],
                                           'mfr': idToDevice[ nodeA ][ 'mfr' ],
                                           'hw': idToDevice[ nodeA ][ 'hw' ],
                                           'sw': idToDevice[ nodeA ][ 'sw' ],
                                           'serial': idToDevice[ nodeA ][ 'serial' ],
                                           'chassisId': idToDevice[ nodeA ][ 'chassisId' ],
                                           'annotations': idToDevice[ nodeA ][ 'annotations' ]}
                else:
                    # Assert nodeB is not connected to any current links of nodeA
                    # assert nodeB not in graphDict[ nodeA ][ 'edges' ].keys()
                    pass
                graphDict[ nodeA ][ 'edges' ][ nodeB ] = { 'port': link[ 'src' ][ 'port' ],
                                                           'type': link[ 'type' ],
                                                           'state': link[ 'state' ] }
            return graphDict
        except ( TypeError, ValueError ):
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except KeyError:
            main.log.exception( self.name + ": KeyError exception found" )
            return None
        except AssertionError:
            main.log.exception( self.name + ": AssertionError exception found" )
            return None
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            return None

    def getIntentPerfSummary( self ):
        '''
        Send command to check intent-perf summary
        Returns: dictionary for intent-perf summary
                 if something wrong, function will return None
        '''
        cmd = "intent-perf -s"
        respDic = {}
        resp = self.sendline( cmd )
        assert resp is not None, "Error in sendline"
        assert "Command not found:" not in resp, resp
        try:
            # Generate the dictionary to return
            for l in resp.split( "\n" ):
                # Delete any white space in line
                temp = re.sub( r'\s+', '', l )
                temp = temp.split( ":" )
                respDic[ temp[ 0 ] ] = temp[ 1 ]

        except ( TypeError, ValueError ):
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except KeyError:
            main.log.exception( self.name + ": KeyError exception found" )
            return None
        except AssertionError:
            main.log.exception( self.name + ": AssertionError exception found" )
            return None
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            return None
        return respDic

    def logSearch( self, mode='all', searchTerm='', startLine='', logNum=1 ):
        """
        Searches the latest ONOS log file for the given search term and
        return a list that contains all the lines that have the search term.

        Arguments:
            searchTerm:
                The string to grep from the ONOS log.
            startLine:
                The term that decides which line is the start to search the searchTerm in
                the karaf log. For now, startTerm only works in 'first' mode.
            logNum:
                In some extreme cases, one karaf log is not big enough to contain all the
                information.Because of this, search mutiply logs is necessary to capture
                the right result. logNum is the number of karaf logs that we need to search
                the searchTerm.
            mode:
                all: return all the strings that contain the search term
                last: return the last string that contains the search term
                first: return the first string that contains the search term
                num: return the number of times that the searchTerm appears in the log
                total: return how many lines in karaf log
        """
        try:
            assert isinstance( searchTerm, str )
            # Build the log paths string
            logPath = '/opt/onos/log/karaf.log.'
            logPaths = '/opt/onos/log/karaf.log'
            for i in range( 1, logNum ):
                logPaths = logPath + str( i ) + " " + logPaths
            cmd = "cat " + logPaths
            if startLine:
                # 100000000 is just a extreme large number to make sure this function can
                # grep all the lines after startLine
                cmd = cmd + " | grep -A 100000000 \'" + startLine + "\'"
            if mode == 'all':
                cmd = cmd + " | grep \'" + searchTerm + "\'"
            elif mode == 'last':
                cmd = cmd + " | grep \'" + searchTerm + "\'" + " | tail -n 1"
            elif mode == 'first':
                cmd = cmd + " | grep \'" + searchTerm + "\'" + " | head -n 1"
            elif mode == 'num':
                cmd = cmd + " | grep \'" + searchTerm + "\' | wc -l"
                num = self.lineCount( cmd )
                return num
            elif mode == 'total':
                totalLines = self.lineCount( "cat /opt/onos/log/karaf.log | wc -l" )
                return int( totalLines )
            else:
                main.log.error( self.name + " unsupported mode" )
                return main.ERROR
            before = self.sendline( cmd )
            before = before.splitlines()
            # make sure the returned list only contains the search term
            returnLines = [ line for line in before if searchTerm in line ]
            return returnLines
        except AssertionError:
            main.log.error( self.name + " searchTerm is not string type" )
            return None
        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 vplsShow( self, jsonFormat=True ):
        """
        Description: Returns result of onos:vpls show, which should list the
                     configured VPLS networks and the assigned interfaces.
        Optional:
            * jsonFormat: enable json formatting of output
        Returns:
            The output of the command or None on error.
        """
        try:
            cmdStr = "vpls show"
            if jsonFormat:
                raise NotImplementedError
                cmdStr += " -j"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except NotImplementedError:
            main.log.exception( self.name + ": Json output not supported" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def parseVplsShow( self ):
        """
        Parse the cli output of 'vpls show' into json output. This is required
        as there is currently no json output available.
        """
        try:
            output = []
            raw = self.vplsShow( jsonFormat=False )
            namePat = "VPLS name: (?P<name>\w+)"
            interfacesPat = "Associated interfaces: \[(?P<interfaces>.*)\]"
            encapPat = "Encapsulation: (?P<encap>\w+)"
            pattern = "\s+".join( [ namePat, interfacesPat, encapPat ] )
            mIter = re.finditer( pattern, raw )
            for match in mIter:
                item = {}
                item[ 'name' ] = match.group( 'name' )
                ifaces = match.group( 'interfaces' ).split( ', ' )
                if ifaces == [ "" ]:
                    ifaces = []
                item[ 'interfaces' ] = ifaces
                encap = match.group( 'encap' )
                if encap != 'NONE':
                    item[ 'encapsulation' ] = encap.lower()
                output.append( item )
            return output
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def vplsList( self, jsonFormat=True ):
        """
        Description: Returns result of onos:vpls list, which should list the
                     configured VPLS networks.
        Optional:
            * jsonFormat: enable json formatting of output
        """
        try:
            cmdStr = "vpls list"
            if jsonFormat:
                raise NotImplementedError
                cmdStr += " -j"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except NotImplementedError:
            main.log.exception( self.name + ": Json output not supported" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def vplsCreate( self, network ):
        """
        CLI command to create a new VPLS network.
        Required arguments:
            network - String name of the network to create.
        returns:
            main.TRUE on success and main.FALSE on failure
        """
        try:
            network = str( network )
            cmdStr = "vpls create "
            cmdStr += network
            output = self.sendline( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            assert "Error executing command" not in output, output
            assert "VPLS already exists:" not in output, output
            return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            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 vplsDelete( self, network ):
        """
        CLI command to delete a VPLS network.
        Required arguments:
            network - Name of the network to delete.
        returns:
            main.TRUE on success and main.FALSE on failure
        """
        try:
            network = str( network )
            cmdStr = "vpls delete "
            cmdStr += network
            output = self.sendline( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            assert "Error executing command" not in output, output
            assert " not found" not in output, output
            assert "still updating" not in output, output
            return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            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 vplsAddIface( self, network, iface ):
        """
        CLI command to add an interface to a VPLS network.
        Required arguments:
            network - Name of the network to add the interface to.
            iface - The ONOS name for an interface.
        returns:
            main.TRUE on success and main.FALSE on failure
        """
        try:
            network = str( network )
            iface = str( iface )
            cmdStr = "vpls add-if "
            cmdStr += network + " " + iface
            output = self.sendline( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            assert "Error executing command" not in output, output
            assert "already associated to network" not in output, output
            assert "Interface cannot be added." not in output, output
            assert "still updating" not in output, output
            return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            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 vplsRemIface( self, network, iface ):
        """
        CLI command to remove an interface from a VPLS network.
        Required arguments:
            network - Name of the network to remove the interface from.
            iface - Name of the interface to remove.
        returns:
            main.TRUE on success and main.FALSE on failure
        """
        try:
            iface = str( iface )
            cmdStr = "vpls rem-if "
            cmdStr += network + " " + iface
            output = self.sendline( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            assert "Error executing command" not in output, output
            assert "is not configured" not in output, output
            assert "still updating" not in output, output
            return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            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 vplsClean( self ):
        """
        Description: Clears the VPLS app configuration.
        Returns: main.TRUE on success and main.FALSE on failure
        """
        try:
            cmdStr = "vpls clean"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "still updating" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            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 vplsSetEncap( self, network, encapType ):
        """
        CLI command to add an interface to a VPLS network.
        Required arguments:
            network - Name of the network to create.
            encapType - Type of encapsulation.
        returns:
            main.TRUE on success and main.FALSE on failure
        """
        try:
            network = str( network )
            encapType = str( encapType ).upper()
            assert encapType in [ "MPLS", "VLAN", "NONE" ], "Incorrect type"
            cmdStr = "vpls set-encap "
            cmdStr += network + " " + encapType
            output = self.sendline( cmdStr )
            assert output is not None, "Error in sendline"
            assert "Command not found:" not in output, output
            assert "Error executing command" not in output, output
            assert "already associated to network" not in output, output
            assert "Encapsulation type " not in output, output
            assert "still updating" not in output, output
            return main.TRUE
        except AssertionError:
            main.log.exception( "" )
            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 interfaces( self, jsonFormat=True ):
        """
        Description: Returns result of interfaces command.
        Optional:
            * jsonFormat: enable json formatting of output
        Returns:
            The output of the command or None on error.
        """
        try:
            cmdStr = "interfaces"
            if jsonFormat:
                raise NotImplementedError
                cmdStr += " -j"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":    " + self.handle.before )
            main.cleanAndExit()
        except NotImplementedError:
            main.log.exception( self.name + ": Json output not supported" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def getTimeStampFromLog( self, mode, searchTerm, splitTerm_before, splitTerm_after, startLine='', logNum=1 ):
        '''
        Get the timestamp of searchTerm from karaf log.

        Arguments:
            splitTerm_before and splitTerm_after:

                The terms that split the string that contains the timeStamp of
                searchTerm. For example, if that string is "xxxxxxxcreationTime =
                1419510501xxxxxx", then the splitTerm_before is "CreationTime = "
                and the splitTerm_after is "x"

            others:
                Please look at the "logsearch" Function in onosclidriver.py
        '''
        if logNum < 0:
            main.log.error( "Get wrong log number ")
            return main.ERROR
        lines = self.logSearch( mode=mode, searchTerm=searchTerm, startLine=startLine, logNum=logNum )
        if len( lines ) == 0:
            main.log.warn( "Captured timestamp string is empty" )
            return main.ERROR
        lines = lines[ 0 ]
        try:
            assert isinstance( lines, str )
            # get the target value
            line = lines.split( splitTerm_before )
            key = line[ 1 ].split( splitTerm_after )
            return int( key[ 0 ] )
        except IndexError:
            main.log.warn( "Index Error!" )
            return main.ERROR
        except AssertionError:
            main.log.warn( "Search Term Not Found " )
            return main.ERROR

    def workQueueAdd( self, queueName, value ):
        """
        CLI command to add a string to the specified Work Queue.
        This function uses the distributed primitives test app, which
        gives some cli access to distributed primitives for testing
        purposes only.

        Required arguments:
            queueName - The name of the queue to add to
            value - The value to add to the queue
        returns:
            main.TRUE on success, main.FALSE on failure and
            main.ERROR on error.
        """
        try:
            queueName = str( queueName )
            value = str( value )
            prefix = "work-queue-test"
            operation = "add"
            cmdStr = " ".join( [ prefix, queueName, operation, value ] )
            output = self.distPrimitivesSend( cmdStr )
            if "Invalid operation name" in output:
                main.log.warn( output )
                return main.ERROR
            elif "Done" in output:
                return main.TRUE
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.ERROR
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def workQueueAddMultiple( self, queueName, value1, value2 ):
        """
        CLI command to add two strings to the specified Work Queue.
        This function uses the distributed primitives test app, which
        gives some cli access to distributed primitives for testing
        purposes only.

        Required arguments:
            queueName - The name of the queue to add to
            value1 - The first value to add to the queue
            value2 - The second value to add to the queue
        returns:
            main.TRUE on success, main.FALSE on failure and
            main.ERROR on error.
        """
        try:
            queueName = str( queueName )
            value1 = str( value1 )
            value2 = str( value2 )
            prefix = "work-queue-test"
            operation = "addMultiple"
            cmdStr = " ".join( [ prefix, queueName, operation, value1, value2 ] )
            output = self.distPrimitivesSend( cmdStr )
            if "Invalid operation name" in output:
                main.log.warn( output )
                return main.ERROR
            elif "Done" in output:
                return main.TRUE
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.ERROR
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def workQueueTakeAndComplete( self, queueName, number=1 ):
        """
        CLI command to take a value from the specified Work Queue and compelte it.
        This function uses the distributed primitives test app, which
        gives some cli access to distributed primitives for testing
        purposes only.

        Required arguments:
            queueName - The name of the queue to add to
            number - The number of items to take and complete
        returns:
            main.TRUE on success, main.FALSE on failure and
            main.ERROR on error.
        """
        try:
            queueName = str( queueName )
            number = str( int( number ) )
            prefix = "work-queue-test"
            operation = "takeAndComplete"
            cmdStr = " ".join( [ prefix, queueName, operation, number ] )
            output = self.distPrimitivesSend( cmdStr )
            if "Invalid operation name" in output:
                main.log.warn( output )
                return main.ERROR
            elif "Done" in output:
                return main.TRUE
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.ERROR
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def workQueueDestroy( self, queueName ):
        """
        CLI command to destroy the specified Work Queue.
        This function uses the distributed primitives test app, which
        gives some cli access to distributed primitives for testing
        purposes only.

        Required arguments:
            queueName - The name of the queue to add to
        returns:
            main.TRUE on success, main.FALSE on failure and
            main.ERROR on error.
        """
        try:
            queueName = str( queueName )
            prefix = "work-queue-test"
            operation = "destroy"
            cmdStr = " ".join( [ prefix, queueName, operation ] )
            output = self.distPrimitivesSend( cmdStr )
            if "Invalid operation name" in output:
                main.log.warn( output )
                return main.ERROR
            return main.TRUE
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return main.ERROR
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def workQueueTotalPending( self, queueName ):
        """
        CLI command to get the Total Pending items of the specified Work Queue.
        This function uses the distributed primitives test app, which
        gives some cli access to distributed primitives for testing
        purposes only.

        Required arguments:
            queueName - The name of the queue to add to
        returns:
            The number of Pending items in the specified work queue or
            None on error
        """
        try:
            queueName = str( queueName )
            prefix = "work-queue-test"
            operation = "totalPending"
            cmdStr = " ".join( [ prefix, queueName, operation ] )
            output = self.distPrimitivesSend( cmdStr )
            main.log.debug( self.name + ": work queue unparsed: " + output )
            output = output.split( "\r\n" )[ -1 ]
            main.log.debug( self.name + ": work queue parsed: " + output )
            pattern = r'\d+'
            if "Invalid operation name" in output:
                main.log.warn( output )
                return None
            else:
                match = re.search( pattern, output )
                return match.group( 0 )
        except ( AttributeError, TypeError ):
            main.log.exception( self.name + ": Object not as expected; " + str( output ) )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def workQueueTotalCompleted( self, queueName ):
        """
        CLI command to get the Total Completed items of the specified Work Queue.
        This function uses the distributed primitives test app, which
        gives some cli access to distributed primitives for testing
        purposes only.

        Required arguments:
            queueName - The name of the queue to add to
        returns:
            The number of complete items in the specified work queue or
            None on error
        """
        try:
            queueName = str( queueName )
            prefix = "work-queue-test"
            operation = "totalCompleted"
            cmdStr = " ".join( [ prefix, queueName, operation ] )
            output = self.distPrimitivesSend( cmdStr )
            main.log.debug( self.name + ": work queue unparsed: " + output )
            output = output.split( "\r\n" )[ -1 ]
            main.log.debug( self.name + ": work queue parsed: " + output )
            pattern = r'\d+'
            if "Invalid operation name" in output:
                main.log.warn( output )
                return None
            else:
                match = re.search( pattern, output )
                return match.group( 0 )
        except ( AttributeError, TypeError ):
            main.log.exception( self.name + ": Object not as expected; " + str( output ) )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def workQueueTotalInProgress( self, queueName ):
        """
        CLI command to get the Total In Progress items of the specified Work Queue.
        This function uses the distributed primitives test app, which
        gives some cli access to distributed primitives for testing
        purposes only.

        Required arguments:
            queueName - The name of the queue to add to
        returns:
            The number of In Progress items in the specified work queue or
            None on error
        """
        try:
            queueName = str( queueName )
            prefix = "work-queue-test"
            operation = "totalInProgress"
            cmdStr = " ".join( [ prefix, queueName, operation ] )
            output = self.distPrimitivesSend( cmdStr )
            main.log.debug( self.name + ": work queue unparsed: " + output )
            output = output.split( "\r\n" )[ -1 ]
            main.log.debug( self.name + ": work queue parsed: " + output )
            pattern = r'\d+'
            if "Invalid operation name" in output:
                main.log.warn( output )
                return None
            else:
                match = re.search( pattern, output )
                return match.group( 0 )
        except ( AttributeError, TypeError ):
            main.log.exception( self.name + ": Object not as expected; " + str( output ) )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def events( self, args='-a' ):
        """
        Description: Returns events -a command output
        Optional:
            add other arguments
        """
        try:
            cmdStr = "events"
            if args:
                cmdStr += " " + args
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 getMaster( self, deviceID ):
        """
            Description: Obtains current master using "roles" command for a specific deviceID
        """
        try:
            return str( self.getRole( deviceID )[ 'master' ] )
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 issu( self ):
        """
        Short summary of In-Service Software Upgrade status

        Returns the output of the cli command or None on Error
        """
        try:
            cmdStr = "issu"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 issuInit( self ):
        """
        Initiates an In-Service Software Upgrade

        Returns main.TRUE on success, main.ERROR on error, else main.FALSE
        """
        try:
            cmdStr = "issu init"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            if "Initialized" in handle:
                return main.TRUE
            else:
                return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            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 issuUpgrade( self ):
        """
        Transitions stores to upgraded nodes

        Returns main.TRUE on success, main.ERROR on error, else main.FALSE
        """
        try:
            cmdStr = "issu upgrade"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            if "Upgraded" in handle:
                return main.TRUE
            else:
                return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            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 issuCommit( self ):
        """
        Finalizes an In-Service Software Upgrade

        Returns main.TRUE on success, main.ERROR on error, else main.FALSE
        """
        try:
            cmdStr = "issu commit"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            # TODO: Check the version returned by this command
            if "Committed version" in handle:
                return main.TRUE
            else:
                return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            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 issuRollback( self ):
        """
        Rolls back an In-Service Software Upgrade

        Returns main.TRUE on success, main.ERROR on error, else main.FALSE
        """
        try:
            cmdStr = "issu rollback"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            # TODO: Check the version returned by this command
            if "Rolled back to version" in handle:
                return main.TRUE
            else:
                return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            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 issuReset( self ):
        """
        Resets the In-Service Software Upgrade status after a rollback

        Returns main.TRUE on success, main.ERROR on error, else main.FALSE
        """
        try:
            cmdStr = "issu reset"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            # TODO: Check the version returned by this command
            if "Reset version" in handle:
                return main.TRUE
            else:
                return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return main.ERROR
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            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 issuStatus( self ):
        """
        Status of an In-Service Software Upgrade

        Returns the output of the cli command or None on Error
        """
        try:
            cmdStr = "issu status"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 issuVersion( self ):
        """
        Get the version of an In-Service Software Upgrade

        Returns the output of the cli command or None on Error
        """
        try:
            cmdStr = "issu version"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 mcastJoin( self, sIP, groupIP, sPort, dPorts ):
        """
        Create a multicast route by calling 'mcast-join' command
        sIP: source IP of the multicast route
        groupIP: group IP of the multicast route
        sPort: source port (e.g. of:0000000000000001/3 ) of the multicast route
        dPorts: a list of destination ports of the multicast route
        Returns main.TRUE if mcast route is added; Otherwise main.FALSE
        """
        try:
            cmdStr = "mcast-join"
            cmdStr += " " + str( sIP )
            cmdStr += " " + str( groupIP )
            cmdStr += " " + str( sPort )
            assert isinstance( dPorts, list )
            for dPort in dPorts:
                cmdStr += " " + str( dPort )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            assert "Error executing command" not in handle, handle
            if "Added the mcast route" in handle:
                return main.TRUE
            else:
                return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 mcastDelete( self, sIP, groupIP, dPorts ):
        """
        Delete a multicast route by calling 'mcast-delete' command
        sIP: source IP of the multicast route
        groupIP: group IP of the multicast route
        dPorts: a list of destination ports of the multicast route
        Returns main.TRUE if mcast route is deleted; Otherwise main.FALSE
        """
        try:
            cmdStr = "mcast-delete"
            cmdStr += " " + str( sIP )
            cmdStr += " " + str( groupIP )
            assert isinstance( dPorts, list )
            for dPort in dPorts:
                cmdStr += " " + str( dPort )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            assert "Error executing command" not in handle, handle
            if "Updated the mcast route" in handle:
                return main.TRUE
            else:
                return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 mcastHostJoin( self, sAddr, gAddr, srcs, sinks ):
        """
        Create a multicast route by calling 'mcast-host-join' command
        sAddr: we can provide * for ASM or a specific address for SSM
        gAddr: specifies multicast group address
        srcs: a list of HostId of the sources e.g. ["00:AA:00:00:00:01/None"]
        sinks: a list of HostId of the sinks e.g. ["00:AA:00:00:01:05/40"]
        Returns main.TRUE if mcast route is added; Otherwise main.FALSE
        """
        try:
            cmdStr = "mcast-host-join"
            cmdStr += " -sAddr " + str( sAddr )
            cmdStr += " -gAddr " + str( gAddr )
            assert isinstance( srcs, list )
            for src in srcs:
                cmdStr += " -srcs " + str( src )
            assert isinstance( sinks, list )
            for sink in sinks:
                cmdStr += " -sinks " + str( sink )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            assert "Error executing command" not in handle, handle
            if "Added the mcast route" in handle:
                return main.TRUE
            else:
                return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 mcastHostDelete( self, sAddr, gAddr, host=None ):
        """
        Delete multicast sink(s) by calling 'mcast-host-delete' command
        sAddr: we can provide * for ASM or a specific address for SSM
        gAddr: specifies multicast group address
        host: HostId of the sink e.g. "00:AA:00:00:01:05/40",
               will delete the route if not specified
        Returns main.TRUE if the mcast sink is deleted; Otherwise main.FALSE
        """
        try:
            cmdStr = "mcast-host-delete"
            cmdStr += " -sAddr " + str( sAddr )
            cmdStr += " -gAddr " + str( gAddr )
            if host:
                cmdStr += " -h " + str( host )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            assert "Error executing command" not in handle, handle
            if "Updated the mcast route" in handle:
                return main.TRUE
            elif "Deleted the mcast route" in handle:
                return main.TRUE
            else:
                return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 mcastSinkDelete( self, sAddr, gAddr, sink=None ):
        """
        Delete multicast sink(s) by calling 'mcast-sink-delete' command
        sAddr: we can provide * for ASM or a specific address for SSM
        gAddr: specifies multicast group address
        host: HostId of the sink e.g. "00:AA:00:00:01:05/40",
               will delete the route if not specified
        Returns main.TRUE if the mcast sink is deleted; Otherwise main.FALSE
        """
        try:
            cmdStr = "mcast-sink-delete"
            cmdStr += " -sAddr " + str( sAddr )
            cmdStr += " -gAddr " + str( gAddr )
            if sink:
                cmdStr += " -s " + str( sink )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            assert "Error executing command" not in handle, handle
            if "Updated the mcast route" in handle:
                return main.TRUE
            elif "Deleted the mcast route" in handle:
                return main.TRUE
            else:
                return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 mcastSourceDelete( self, sAddr, gAddr, srcs=None ):
        """
        Delete multicast src(s) by calling 'mcast-source-delete' command
        sAddr: we can provide * for ASM or a specific address for SSM
        gAddr: specifies multicast group address
        srcs: a list of host IDs of the sources e.g. ["00:AA:00:00:01:05/40"],
              will delete the route if not specified
        Returns main.TRUE if mcast sink is deleted; Otherwise main.FALSE
        """
        try:
            cmdStr = "mcast-source-delete"
            cmdStr += " -sAddr " + str( sAddr )
            cmdStr += " -gAddr " + str( gAddr )
            if srcs:
                assert isinstance( srcs, list )
                for src in srcs:
                    cmdStr += " -src " + str( src )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            assert "Error executing command" not in handle, handle
            if "Updated the mcast route" in handle:
                return main.TRUE
            elif "Deleted the mcast route" in handle:
                return main.TRUE
            else:
                return main.FALSE
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 netcfg( self, jsonFormat=True, args="" ):
        """
        Run netcfg cli command with given args
        """
        try:
            cmdStr = "netcfg"
            if jsonFormat:
                cmdStr = cmdStr + " -j"
            if args:
                cmdStr = cmdStr + " " + str( args )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            assert "Error executing command" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 composeT3Command( self, sAddr, dAddr, ipv6=False, verbose=True, simple=False ):
        """
        Compose and return a list of t3-troubleshoot cli commands for given source and destination addresses
        Options:
            sAddr: IP address of the source host
            dAddr: IP address of the destination host
            ipv6: True if hosts are IPv6
            verbose: return verbose t3 output if True
            simple: compose command for t3-troubleshoot-simple if True
        """
        try:
            # Collect information of both hosts from onos
            hosts = self.hosts()
            hosts = json.loads( hosts )
            sHost = None
            dHost = None
            for host in hosts:
                if sAddr in host[ "ipAddresses" ]:
                    sHost = host
                elif dAddr in host[ "ipAddresses" ]:
                    dHost = host
                if sHost and dHost:
                    break
            assert sHost, "Not able to find host with IP {}".format( sAddr )
            cmdList = []
            if simple:
                assert dHost, "Not able to find host with IP {}".format( dAddr )
                cmdStr = "t3-troubleshoot-simple"
                if verbose:
                    cmdStr += " -vv"
                if ipv6:
                    cmdStr += " -et ipv6"
                cmdStr += " {}/{} {}/{}".format( sHost[ "mac" ], sHost[ "vlan" ], dHost[ "mac" ], dHost[ "vlan" ] )
                cmdList.append( cmdStr )
            else:
                for location in sHost[ "locations" ]:
                    cmdStr = "t3-troubleshoot"
                    if verbose:
                        cmdStr += " -vv"
                    if ipv6:
                        cmdStr += " -et ipv6"
                    cmdStr += " -s " + str( sAddr )
                    cmdStr += " -sp " + str( location[ "elementId" ] ) + "/" + str( location[ "port" ] )
                    cmdStr += " -sm " + str( sHost[ "mac" ] )
                    if sHost[ "vlan" ] != "None":
                        cmdStr += " -vid " + sHost[ "vlan" ]
                    cmdStr += " -d " + str( dAddr )
                    netcfg = self.netcfg( args="devices {}".format( location[ "elementId" ] ) )
                    netcfg = json.loads( netcfg )
                    assert netcfg, "Failed to get netcfg"
                    cmdStr += " -dm " + str( netcfg[ "segmentrouting" ][ "routerMac" ] )
                    cmdList.append( cmdStr )
            return cmdList
        except AssertionError:
            main.log.exception( "" )
            return None
        except ( KeyError, TypeError ):
            main.log.exception( self.name + ": Object not as expected" )
            return None
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def t3( self, sAddr, dAddr, ipv6=False ):
        """
        Run t3-troubleshoot cli commands for all posible routes given source and destination addresses
        Options:
            sAddr: IP address of the source host
            dAddr: IP address of the destination host
        """
        try:
            cmdList = self.composeT3Command( sAddr, dAddr, ipv6 )
            assert cmdList is not None, "composeT3Command returned None"
            t3Output = ""
            for cmdStr in cmdList:
                handle = self.sendline( cmdStr )
                assert handle is not None, "Error in sendline"
                assert "Command not found:" not in handle, handle
                assert "Unsupported command:" not in handle, handle
                assert "Error executing command" not in handle, handle
                assert "Tracing packet" in handle
                t3Output += handle
            return t3Output
        except AssertionError:
            main.log.exception( "" )
            return None
        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 prepareForCLI( self, debug=True, maxRetries=120 ):
        """
        Prepare docker container to connect to onos cli
        """
        try:
            # Wait for log files to be created
            ready = 0
            retries = 0
            while not ready and retries < maxRetries:
                retries += 1
                self.handle.sendline( "ls -al /root/onos/apache-karaf-*/data/log" )
                ready = self.handle.expect( [ "No such file or directory", self.dockerPrompt ] )
                main.log.debug( "%s: %s" % ( self.name, self.handle.before ) )
                if not ready:
                    self.handle.expect( self.dockerPrompt )
                time.sleep( 1 )

            cmdList = []
            cmdList.append( "apt-get update" )
            cmdList.append( "apt-get install -y openssh-server" )
            # Some built in scripts are hardcoded
            cmdList.append( "ln -s /root/onos /opt/onos" )
            cmdList.append( "ln -s /root/onos/apache-karaf-*/data/log /opt/onos/log" )
            cmdList.append( "ls -al /opt/onos" )
            output = ""
            for cmdStr in cmdList:
                self.handle.sendline( cmdStr )
                self.handle.expect( self.dockerPrompt, timeout=420 )
                self.handle.sendline( "" )
                self.handle.expect( self.dockerPrompt )
                handle = self.handle.before
                assert "command not found" not in handle, handle
                assert "No such file or directory" not in handle, handle
                output += handle
            if debug:
                main.log.debug( "%s: %s" % ( self.name, output ) )
            return output
        except AssertionError:
            main.log.exception( "" )
            return None
        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" ):
        """
        Enables secure access to ONOS console
        by removing default users & keys.

        bin/onos-user-password onos rocks

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

        try:
            self.handle.sendline( "" )
            self.handle.expect( self.dockerPrompt )

            self.handle.sendline( "[ ! -f ~/.ssh/id_rsa.pub ] && ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' -q" )
            self.handle.expect( self.dockerPrompt )
            main.log.debug( "%s: %s%s" % ( self.name, self.handle.before, self.handle.after ) )

            self.handle.sendline( "bin/onos-user-key $(id -un) $(cut -d\\\\ -f2 ~/.ssh/id_rsa.pub)" )
            self.handle.expect( pexpect.TIMEOUT, timeout=10 )
            main.log.debug( "%s: %s" % ( self.name, self.handle.before ) )

            self.handle.sendline( "bin/onos-user-password %s %s" % ( userName, userPWD ) )
            i = self.handle.expect( [ "usage",
                                      self.dockerPrompt,
                                      pexpect.TIMEOUT ] )
            if i == 0:
                # malformed command
                main.log.warn( self.name + ": Could not parse onos-user-password command" )
                self.handle.expect( self.dockerPrompt )
                return main.FALSE
            elif i == 1:
                # Process started
                main.log.info( self.name + ": SSH password added for user " + userName )
                return main.TRUE
            elif i == 2:
                # timeout
                main.log.error( self.name + ": Failed to secure onos ssh " )
                main.log.debug( "%s: %s" % ( self.name, 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 routeAdd( self, prefix, nextHop, jsonFormat=True ):
        """
        Add a route with the given prefix and nextHop
        """
        try:
            cmdStr = "route-add %s %s %s" % ( "-j" if jsonFormat else "", prefix, nextHop )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            assert "Error executing command" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 routeRemove( self, prefix, nextHop, source=None, jsonFormat=True ):
        """
        Remove a route with the given prefix and nextHop
        """
        try:
            if source:
                raise NotImplemented
            cmdStr = "route-remove %s %s %s" % ( "-j" if jsonFormat else "", prefix, nextHop )
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            assert "Error executing command" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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 routes( self, jsonFormat=True, args="" ):
        """
        Get routes from ONOS
        """
        try:
            cmdStr = "routes"
            if jsonFormat:
                cmdStr = cmdStr + " -j"
            handle = self.sendline( cmdStr )
            assert handle is not None, "Error in sendline"
            assert "Command not found:" not in handle, handle
            assert "Unsupported command:" not in handle, handle
            assert "Error executing command" not in handle, handle
            return handle
        except AssertionError:
            main.log.exception( "" )
            return None
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            return None
        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()
