[CORD-2862] TestON drivers for OFDPA and Host

Change-Id: I5a0005c128c091aadee567a144c0acef55235184
diff --git a/TestON/drivers/common/cli/hostdriver.py b/TestON/drivers/common/cli/hostdriver.py
new file mode 100644
index 0000000..238721e
--- /dev/null
+++ b/TestON/drivers/common/cli/hostdriver.py
@@ -0,0 +1,198 @@
+#!/usr/bin/env python
+"""
+Copyright 2018 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/>.
+"""
+
+import pexpect
+import re
+import sys
+import types
+import os
+import time
+from math import pow
+from drivers.common.clidriver import CLI
+
+class HostDriver( CLI ):
+    """
+    This class is created as a standalone host driver.
+    """
+    def __init__( self ):
+        super( HostDriver, self ).__init__()
+        self.handle = self
+        self.name = None
+        self.shortName = None
+        self.home = None
+
+    def connect( self, **connectargs ):
+        """
+        Creates ssh handle for host.
+        NOTE:
+        The ip_address would come from the topo file using the host tag, the
+        value can be an environment variable as well as a "localhost" to get
+        the ip address needed to ssh to the "bench"
+        """
+        try:
+            for key in connectargs:
+                vars( self )[ key ] = connectargs[ key ]
+            self.name = self.options[ 'name' ]
+            self.shortName = self.options[ 'shortName' ]
+
+            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(
+                HostDriver,
+                self ).connect(
+                user_name=self.user_name,
+                ip_address=self.ip_address,
+                port=None,
+                pwd=self.pwd )
+
+            if self.handle:
+                main.log.info( "Connection successful to the " +
+                               self.user_name +
+                               "@" +
+                               self.ip_address )
+                self.handle.sendline( "" )
+                self.handle.expect( self.prompt )
+                return main.TRUE
+            else:
+                main.log.error( "Connection failed to " +
+                                self.user_name +
+                                "@" +
+                                self.ip_address )
+                return main.FALSE
+        except pexpect.EOF:
+            main.log.error( self.name + ": EOF exception found" )
+            main.log.error( self.name + ":     " + self.handle.before )
+            main.cleanAndExit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanAndExit()
+
+    def disconnect( self, **connectargs ):
+        """
+        Called when test is complete to disconnect the handle.
+        """
+        response = main.TRUE
+        try:
+            if self.handle:
+                # Disconnect from the host
+                self.handle.sendline( "" )
+                self.handle.expect( self.prompt )
+                self.handle.sendline( "exit" )
+                i = self.handle.expect( [ "closed", pexpect.TIMEOUT ], timeout=2 )
+                if i == 1:
+                    main.log.error(
+                        self.name +
+                        ": timeout when waiting for response" )
+                    main.log.error( "response: " + str( self.handle.before ) )
+        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 + ": Connection failed to the host" )
+            response = main.FALSE
+        return response
+
+    def ping( self, dst, ipv6=False, wait=3 ):
+        """
+        Description:
+            Ping from this host to another
+        Required:
+            dst: IP address of destination host
+        Optional:
+            ipv6: will use ping6 command if True; otherwise use ping command
+            wait: timeout for ping command
+        """
+        try:
+            command = "ping6" if ipv6 else "ping"
+            command += " -c 1 -i 1 -W " + str( wait ) + " " + str( dst )
+            main.log.info( self.name + ": Sending: " + command )
+            self.handle.sendline( command )
+            i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
+                                    timeout=wait + 1 )
+            if i == 1:
+                main.log.error(
+                    self.name +
+                    ": timeout when waiting for response" )
+                main.log.error( "response: " + str( self.handle.before ) )
+            self.handle.sendline( "" )
+            self.handle.expect( self.prompt )
+            response = self.handle.before
+            if re.search( ',\s0\%\spacket\sloss', response ):
+                main.log.info( self.name + ": no packets lost, host is reachable" )
+                return main.TRUE
+            else:
+                main.log.warn(
+                    self.name +
+                    ": PACKET LOST, HOST IS NOT REACHABLE" )
+                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 ifconfig( self, wait=3 ):
+        """
+        Run ifconfig command on host and return output
+        """
+        try:
+            command = "ifconfig"
+            main.log.info( self.name + ": Sending: " + command )
+            self.handle.sendline( command )
+            i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
+                                    timeout=wait + 1 )
+            if i == 1:
+                main.log.error(
+                    self.name +
+                    ": timeout when waiting for response" )
+                main.log.error( "response: " + str( self.handle.before ) )
+            self.handle.sendline( "" )
+            self.handle.expect( self.prompt )
+            response = self.handle.before
+            return response
+        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()
diff --git a/TestON/drivers/common/cli/networkdriver.py b/TestON/drivers/common/cli/networkdriver.py
index d1a7faf..38d7531 100755
--- a/TestON/drivers/common/cli/networkdriver.py
+++ b/TestON/drivers/common/cli/networkdriver.py
@@ -122,9 +122,9 @@
         try:
             for key, value in main.componentDictionary.items():
                 if hasattr( main, key ):
-                    if value[ 'type' ] in [ 'MininetSwitchDriver' ]:
+                    if value[ 'type' ] in [ 'MininetSwitchDriver', 'OFDPASwitchDriver' ]:
                         self.switches[ key ] = getattr( main, key )
-                    elif value[ 'type' ] in [ 'MininetHostDriver' ]:
+                    elif value[ 'type' ] in [ 'MininetHostDriver', 'HostDriver' ]:
                         self.hosts[ key ] = getattr( main, key )
             return main.TRUE
         except Exception:
@@ -138,7 +138,7 @@
         hosts = {}
         try:
             for hostComponent in self.hosts.values():
-                #TODO: return more host data
+                # TODO: return more host data
                 hosts[ hostComponent.options[ 'shortName' ] ] = {}
         except Exception:
             main.log.error( self.name + ": host component not as expected" )
diff --git a/TestON/drivers/common/cli/ofdpa/__init__.py b/TestON/drivers/common/cli/ofdpa/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/TestON/drivers/common/cli/ofdpa/__init__.py
diff --git a/TestON/drivers/common/cli/ofdpa/ofagent.conf.template b/TestON/drivers/common/cli/ofdpa/ofagent.conf.template
new file mode 100644
index 0000000..9dccbcf
--- /dev/null
+++ b/TestON/drivers/common/cli/ofdpa/ofagent.conf.template
@@ -0,0 +1,99 @@
+# Controller
+#-----------------------
+#CTRL1_IP="127.0.0.1"
+#CTRL1_PORT="6653"
+#CTRL2_IP="127.0.0.1"
+#CTRL2_PORT="6653"
+#CTRL3_IP="127.0.0.1"
+#CTRL3_PORT="6653"
+
+#LISTEN_IP="0.0.0.0"
+#LISTEN_PORT="6653"
+
+# Datapath ID
+#-----------------------
+#DPID=`cat /sys/class/net/ma1/address | sed 's/://g'`
+#DPID="1"
+
+# In-band management
+#-----------------------
+#IB_MGMT_VLAN="1"
+#IB_MGMT_PORT_ARG="-p 5"
+
+# Debug options
+#-----------------------
+#OPT_ARGS="-a2 -d4 -c1 -c2 -c3 -c4 -c5"
+
+# Maximu number of log files (valid: 0-10; 0:disble logging)
+MAX_LOG_NUM=0
+
+#----------------------------------------------------------------------------
+# OPT_ARGS:
+#----------------------------------------------------------------------------
+#
+# Controllers:
+#  -i, --dpid=DATAPATHID      The Datapath ID for this switch.
+#  -l, --listen=IP[:PORT]     A local IP address on which to listen for
+#                             controllers (may use this option multiple times)
+#  -t, --controller=IP[:PORT] A Controller IP address (may use this option
+#                             multiple times)
+#
+# TLS:
+#      --cacert=CACERTIFICATE The Certificate Authority certficate
+#      --cert=CERTIFICATE     The SSL public certificate file for the switch
+#      --cipher=CIPHER        The list of ciphers to use
+#      --key=KEYFILE          The SSL private key file for the switch
+#
+# Management VLAN:
+#  -p, --port=MGMTPORT        A port in the mgmt VLAN (may use this option
+#                             multiple times)
+#  -v, --vlan=MGMTVLAN        The VLAN to be reserved for management.
+#
+# Debugging:
+#  -a, --agentdebuglvl=AGENTDEBUGLVL
+#                             The verbosity of OF Agent debug messages.
+#  -c, --ofdpadebugcomp=OFPDACOMPONENT
+#                             The OF-DPA component for which debug messages are
+#                             enabled.
+#  -d, --ofdpadebuglvl=OFDPADEBUGLVL
+#                             The verbosity of OF-DPA debug messages.
+#
+#
+# Note:
+# IPv6 address parameters are specified following RFC3986.
+# To include a port number, enclose the IPv6 address in square brackets:
+#         Example: -t [2001:db8:1f70::999:de8:7648:6e8]:6653
+#
+# To use TLS when connecting to a controller, prefix the IP address with "tls:".
+#         Example: -t tls:[2001:db8:1f70::999:de8:7648:6e8]:6653
+#
+# Note: it is necessary to have a private key and public certificate to use TLS.
+# If the CA certificate is not provided, then the switch does not validate
+# certificates.  This can be helpful if self-signed certificates are being used.
+#
+# Default values:
+# No controllers connections
+# Note: may listen on mutiple IP addresses.  E.g., IPv4 and IPv6.
+# OFAGENTDEBUGLVL  = 0
+# Valid OF Agent debug levels are 0 - 2.
+# OFDPADEBUGLVL  = 0
+# Valid OF-DPA debug levels are 0 - 4.
+# No components enabled for debug:
+# Valid OF-DPA components are:
+#         1 = API
+#         2 = Mapping
+#         3 = RPC
+#         4 = OFDB
+#         5 = Datapath
+#         6 = G8131
+#         7 = Y1731
+#         8 = sFlow
+#         9 = SDK
+# DATAPATHID = 0xda7a
+# No defaults for the management VLAN and port(s).  The management VLAN feature
+# is disabled by default.
+# CIPHER = HIGH
+# CACERTIFICATE =
+# KEYFILE = /etc/ssl/private/switch.key
+# CERTIFICATE = /etc/ssl/certs/switch.crt
+#----------------------------------------------------------------------------
diff --git a/TestON/drivers/common/cli/ofdpa/ofdpaswitchdriver.py b/TestON/drivers/common/cli/ofdpa/ofdpaswitchdriver.py
new file mode 100644
index 0000000..b080c96
--- /dev/null
+++ b/TestON/drivers/common/cli/ofdpa/ofdpaswitchdriver.py
@@ -0,0 +1,327 @@
+#!/usr/bin/env python
+"""
+Copyright 2018 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/>.
+"""
+
+import pexpect
+import re
+import json
+import types
+import time
+import os
+from drivers.common.clidriver import CLI
+from core import utilities
+from shutil import copyfile
+
+class OFDPASwitchDriver( CLI ):
+
+    def __init__( self ):
+        """
+        Initialize client
+        """
+        super( CLI, self ).__init__()
+        self.name = None
+        self.handle = None
+        self.prompt = "~#"
+        # Respect to bin folder
+        self.home = "../drivers/common/cli/ofdpa/"
+        # Local home for functions using scp
+        self.tempDirectory = "/tmp/"
+        self.conf = "ofagent.conf"
+        self.switchDirectory = "/etc/ofagent/"
+
+    def connect( self, **connectargs ):
+        """
+        Creates ssh handle for Accton cli.
+        """
+        try:
+            # Parse keys in xml object
+            for key in connectargs:
+                vars( self )[ key ] = connectargs[ key ]
+            # Get the name
+            self.name = self.options['name']
+            # Get the dpid
+            self.dpid = self.options[ 'dpid' ]
+            # Parse the IP address
+            try:
+                if os.getenv( str( self.ip_address ) ) is not None:
+                    self.ip_address = os.getenv( str( self.ip_address ) )
+                # Otherwise is an ip address
+                else:
+                    main.log.info( self.name + ": Trying to connect to " + self.ip_address )
+            # Error handling
+            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 ) )
+            # Build the handle using the above information
+            self.handle = super(OFDPASwitchDriver, self ).connect(
+                user_name=self.user_name,
+                ip_address=self.ip_address,
+                port=None,
+                pwd=self.pwd)
+            # Successful connection
+            if self.handle:
+                main.log.info( "Connection successful to the host " + self.user_name + "@" + self.ip_address )
+                self.handle.sendline( "" )
+                self.handle.expect( self.prompt )
+                return main.TRUE
+            # Connection failed
+            else:
+                main.log.error( "Connection failed to the host " + self.user_name + "@" + self.ip_address )
+                main.log.error( "Failed to connect to the OFDPA CLI" )
+                return main.FALSE
+        # Error handling
+        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.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def disconnect( self ):
+        """
+        Called when Test is complete to disconnect the OFDPASwitchDriver handle.
+        """
+        response = main.TRUE
+        try:
+            if self.handle:
+                # Stop the ofagent
+                self.stopOfAgent()
+                # Disconnect from the device
+                self.handle.sendline( "" )
+                self.handle.expect( self.prompt )
+                self.handle.sendline( "exit" )
+                self.handle.expect( "closed" )
+        # Errors handling
+        except pexpect.TIMEOUT:
+            main.log.error( self.name + ": pexpect.TIMEOUT found" )
+            return 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 + ": Connection failed to the host" )
+            response = main.FALSE
+            return response
+
+    def assignSwController( self, ip, port="6653", ptcp=""):
+        """
+        Description:
+            The assignment is realized properly creating the agent.conf
+            for each switch and then pushing it into the device.
+        Required:
+            ip - Ip addresses of controllers. This can be a list or a string.
+        Optional:
+            port - controller port is ignored
+            ptcp - ptcp information is ignored
+        Return:
+            Returns main.TRUE if the switch is correctly assigned to controllers,
+            otherwise it will return main.FALSE or an appropriate exception(s)
+        """
+        assignResult = main.TRUE
+        # Initial arguments for OFDPA
+        opt_args = 'OPT_ARGS="-d 2 -c 2 -c 4 '
+        onosIp = ""
+        # Parses the controller option
+        try:
+            if isinstance( ip, types.StringType ):
+                onosIp = "-t " + str( ip )
+            elif isinstance( ip, types.ListType ):
+                for ipAddress in ip:
+                        onosIp += "-t " + str( ipAddress ) + " "
+            else:
+                main.log.error( self.name + ": Invalid ip address" )
+                return main.FALSE
+            # Complete the arguments adding the dpid
+            opt_args += onosIp + '-i %s' % self.dpid + '"'
+            # Create a copy of the cfg file using the template
+            self.createCfg()
+            # Load the cfg file and adds the missing option
+            self.updateCfg( opt_args )
+            # Backup the cfg on the switch
+            self.backupCfg()
+            # Push the new cfg on the device
+            self.pushCfg()
+            # Start the ofagent on the device
+            self.startOfAgent()
+            # Enable all the ports
+            assignResult = utilities.retry(
+                self.enablePorts,
+                main.FALSE,
+                kwargs={},
+                attempts=5,
+                sleep=10)
+            # Done return true
+            return assignResult
+        # Errors handling
+        except pexpect.TIMEOUT:
+            main.log.error( self.name + ": pexpect.TIMEOUT found" )
+            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 createCfg( self ):
+        """
+        Create in bench context a new config file starting from the template
+        """
+        copyfile(self.home + self.conf + ".template", self.tempDirectory + self.conf)
+
+    def updateCfg( self, opt_args):
+        """
+        Add the arguments related to the current switch (self)
+        """
+        with open(self.tempDirectory + self.conf, "a") as cfg:
+            cfg.write(opt_args + "\n")
+            cfg.close()
+
+    def backupCfg( self ):
+        """
+        Create a backup file of the old configuration on the switch
+        """
+        self.handle.sendline( "" )
+        self.handle.expect( self.prompt )
+        self.handle.sendline( "cp %s%s %s%s.backup" % (self.switchDirectory, self.conf, self.switchDirectory, self.conf) )
+        self.handle.expect( self.prompt )
+
+    def pushCfg( self ):
+        """
+        Push the new configuration from the network bench
+        """
+        # We use os.system to send the command from TestON cluster
+        # to the switches. This means that passwordless access is
+        # necessary in order to push the configuration file
+        os.system( "scp " + self.tempDirectory + self.conf + " " +
+                   self.user_name + "@" + self.ip_address + ":" + self.switchDirectory)
+
+    def startOfAgent( self ):
+        """
+        Start the ofagent on the device
+        """
+        self.handle.sendline( "" )
+        self.handle.expect( self.prompt )
+        self.handle.sendline( "service ofagentd start" )
+        self.handle.expect( self.prompt )
+
+    def stopOfAgent( self ):
+        """
+        Stop the ofagent on the device
+        """
+        self.handle.sendline( "" )
+        self.handle.expect( self.prompt )
+        self.handle.sendline( "service ofagentd stop" )
+        self.handle.expect( self.prompt )
+
+    def dumpFlows( self ):
+        """
+        Dump the flows from the devices
+        FIXME need changes in the workflow in order to be used
+        """
+        try:
+            self.handle.sendline( "" )
+            self.handle.expect( self.prompt )
+            # Create the dump of the flows locally on the switches
+            self.handle.sendline( "client_flowtable_dump" )
+            self.handle.expect( self.prompt )
+            response = self.handle.before
+            # Write back in the tmp folder - needs to be changed in future
+            with open(self.tempDirectory + "flows_%s.txt" % self.dpid, "w") as flows:
+                flows.write(response + "\n")
+                flows.close()
+            # Done return for further processing
+            return response
+        # Errors handling
+        except pexpect.TIMEOUT:
+            main.log.error( self.name + ": pexpect.TIMEOUT found" )
+            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 dumpGroups( self ):
+        """
+        Dump the groups from the devices
+        FIXME need changes in the workflow in order to be used
+        """
+        try:
+            self.handle.sendline( "" )
+            self.handle.expect( self.prompt )
+            self.handle.sendline( "client_grouptable_dump > groups.txt" )
+            self.handle.expect( self.prompt )
+            response = self.handle.before
+            # Write back in the tmp folder - needs to be changed in future
+            with open(self.tempDirectory + "groups_%s.txt" % self.dpid, "w") as groups:
+                groups.write(response + "\n")
+                groups.close()
+            # Done return for further processing
+            return response
+        # Errors handling
+        except pexpect.TIMEOUT:
+            main.log.error( self.name + ": pexpect.TIMEOUT found" )
+            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 enablePorts( self ):
+        """
+        Enable all the ports on the devices
+        It needs to wait for the boot
+        """
+        self.handle.sendline( "" )
+        self.handle.expect( self.prompt )
+        self.handle.sendline( "client_port_table_dump" )
+        self.handle.expect( self.prompt )
+        response = self.handle.before
+        if "Error from ofdpaClientInitialize()" in response:
+            main.log.warn(
+                self.name +
+                ": Not yet started" )
+            return main.FALSE
+        main.log.info( self.name + ": started" )
+        self.handle.sendline( "sh portspeed.sh" )
+        self.handle.expect( self.prompt )
+        return main.TRUE
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index 52ef98a..b7d10bd 100755
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -3035,7 +3035,7 @@
             main.log.exception( self.name + ": Uncaught exception!" )
             main.cleanAndExit()
 
-    def checkStatus( self, numoswitch, numolink, numoctrl = -1, logLevel="info" ):
+    def checkStatus( self, numoswitch, numolink = -1, numoctrl = -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
@@ -3071,7 +3071,7 @@
                 return main.ERROR
             switchCheck = ( int( devices ) == int( numoswitch ) )
             # Is the number of links is what we expected
-            linkCheck = ( int( links ) == int( numolink ) )
+            linkCheck = ( int( links ) == int( numolink ) ) or int( numolink ) == -1
             nodeCheck = ( int( nodes ) == int( numoctrl ) ) or int( numoctrl ) == -1
             if switchCheck and linkCheck and nodeCheck:
                 # We expected the correct numbers
@@ -3085,8 +3085,9 @@
                 result = main.FALSE
             output = output + "\n ONOS sees %i devices" % int( devices )
             output = output + " (%i expected) " % int( numoswitch )
-            output = output + "and %i links " % int( links )
-            output = output + "(%i expected)" % int( numolink )
+            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 )