Merge "Update gen-partition file to new version"
diff --git a/TestON/core/teston.py b/TestON/core/teston.py
index 4bbdc3c..ce53f52 100644
--- a/TestON/core/teston.py
+++ b/TestON/core/teston.py
@@ -162,7 +162,6 @@
         driver_options = {}
         if 'COMPONENTS' in self.componentDictionary[component].keys():
             driver_options = dict( self.componentDictionary[component]['COMPONENTS'] )
-
         driver_options['name'] = component
         driverName = self.componentDictionary[component]['type']
         driver_options['type'] = driverName
@@ -461,7 +460,10 @@
                     self.cleanupFlag = True
                     if self.initiated:
                         self.logger.testSummary( self )
-                    for component in self.componentDictionary.keys():
+                    components = self.componentDictionary
+                    for component in sorted( components,
+                                             key=lambda item: components[item]['connect_order'],
+                                             reverse=True ):
                         try:
                             tempObject = vars( self )[component]
                             print "Disconnecting from " + str( tempObject.name ) +\
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index e7718c0..f20589e 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -52,6 +52,11 @@
         self.home = None
         self.wrapped = sys.modules[ __name__ ]
         self.flag = 0
+        # TODO: Refactor driver to use these everywhere
+        self.mnPrompt = "mininet>"
+        self.hostPrompt = "~#"
+        self.bashPrompt = "\$"
+        self.scapyPrompt = ">>>"
 
     def connect( self, **connectargs ):
         """
@@ -70,7 +75,7 @@
                 self.home = "~/mininet"
 
             try:
-                if os.getenv( str( self.ip_address ) ) != None:
+                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 +
@@ -1088,7 +1093,7 @@
 
             # checks if there are results in the mininet response
             if "Results:" in response:
-                main.log.report(self.name +  ": iperf test completed")
+                main.log.report(self.name + ": iperf test completed")
                 # parse the mn results
                 response = response.split("\r\n")
                 response = response[len(response)-2]
@@ -1115,7 +1120,7 @@
         except pexpect.TIMEOUT:
             main.log.error( self.name + ": TIMEOUT exception found" )
             main.log.error( self.name + " response: " +
-                            repr ( self.handle.before ) )
+                            repr( self.handle.before ) )
             # NOTE: Send ctrl-c to make sure iperf is done
             self.handle.sendline( "\x03" )
             self.handle.expect( "Interrupt" )
@@ -1160,7 +1165,7 @@
 
             # check if there are in results in the mininet response
             if "Results:" in response:
-                main.log.report(self.name +  ": iperfudp test completed")
+                main.log.report(self.name + ": iperfudp test completed")
                 # parse the results
                 response = response.split("\r\n")
                 response = response[len(response)-2]
@@ -2650,6 +2655,679 @@
                 main.log.error( self.name + ":     " + self.handle.before )
                 return main.FALSE
 
+    def createHostComponent( self, name ):
+        """
+        Creates a new mininet cli component with the same parameters as self.
+        This new component is intended to be used to login to the hosts created
+        by mininet.
+
+        Arguments:
+            name - The string of the name of this component. The new component
+                   will be assigned to main.<name> .
+                   In addition, main.<name>.name = str( name )
+        """
+        try:
+            # look to see if this component already exists
+            getattr( main, name )
+        except AttributeError:
+            # namespace is clear, creating component
+            main.componentDictionary[name] = main.componentDictionary[self.name].copy()
+            main.componentDictionary[name]['connect_order'] = str( int( main.componentDictionary[name]['connect_order'] ) + 1 )
+            main.componentInit( name )
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+        else:
+            # namespace is not clear!
+            main.log.error( name + " component already exists!" )
+            # FIXME: Should we exit here?
+            main.cleanup()
+            main.exit()
+
+    def removeHostComponent( self, name ):
+        """
+        Remove host component
+        Arguments:
+            name - The string of the name of the component to delete.
+        """
+        try:
+            # Get host component
+            component = getattr( main, name )
+        except AttributeError:
+            main.log.error( "Component " + name + " does not exist." )
+            return
+        try:
+            # Disconnect from component
+            component.disconnect()
+            # Delete component
+            delattr( main, name )
+            # Delete component from ComponentDictionary
+            del( main.componentDictionary[name] )
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def startHostCli( self, host=None ):
+        """
+        Use the mininet m utility to connect to the host's cli
+        """
+        # These are fields that can be used by scapy packets. Initialized to None
+        self.hostIp = None
+        self.hostMac = None
+        try:
+            if not host:
+                host = self.name
+            self.handle.sendline( self.home + "/util/m " + host )
+            self.handle.expect( self.hostPrompt )
+            return main.TRUE
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return main.FALSE
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def startScapy( self ):
+        """
+        Start the Scapy cli
+        """
+        try:
+            self.handle.sendline( "scapy" )
+            self.handle.expect( self.scapyPrompt )
+            self.handle.sendline( "conf.color_theme = NoTheme()" )
+            self.handle.expect( self.scapyPrompt )
+            return main.TRUE
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return main.FALSE
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def stopScapy( self ):
+        """
+        Exit the Scapy cli
+        """
+        try:
+            self.handle.sendline( "exit()" )
+            self.handle.expect( self.hostPrompt )
+            return main.TRUE
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return main.FALSE
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def buildEther( self, **kwargs ):
+        """
+        Build an Ethernet frame
+
+        Will create a frame class with the given options. If a field is
+        left blank it will default to the below value unless it is
+        overwritten by the next frame.
+        Default frame:
+        ###[ Ethernet ]###
+          dst= ff:ff:ff:ff:ff:ff
+          src= 00:00:00:00:00:00
+          type= 0x800
+
+        Returns main.TRUE or main.FALSE on error
+        """
+        try:
+            # Set the Ethernet frame
+            cmd = 'ether = Ether( '
+            options = []
+            for key, value in kwargs.iteritems():
+                if isinstance( value, str ):
+                    value = '"' + value + '"'
+                options.append( str( key ) + "=" + str( value ) )
+            cmd += ", ".join( options )
+            cmd += ' )'
+            self.handle.sendline( cmd )
+            self.handle.expect( self.scapyPrompt )
+            if "Traceback" in self.handle.before:
+                # KeyError, SyntaxError, ...
+                main.log.error( "Error in sending command: " + self.handle.before )
+                return main.FALSE
+            self.handle.sendline( "packet = ether" )
+            self.handle.expect( self.scapyPrompt )
+            if "Traceback" in self.handle.before:
+                # KeyError, SyntaxError, ...
+                main.log.error( "Error in sending command: " + self.handle.before )
+                return main.FALSE
+            return main.TRUE
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return main.FALSE
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def buildIP( self, **kwargs ):
+        """
+        Build an IP frame
+
+        Will create a frame class with the given options. If a field is
+        left blank it will default to the below value unless it is
+        overwritten by the next frame.
+        Default frame:
+        ###[ IP ]###
+          version= 4
+          ihl= None
+          tos= 0x0
+          len= None
+          id= 1
+          flags=
+          frag= 0
+          ttl= 64
+          proto= hopopt
+          chksum= None
+          src= 127.0.0.1
+          dst= 127.0.0.1
+          \options\
+
+        Returns main.TRUE or main.FALSE on error
+        """
+        try:
+            # Set the IP frame
+            cmd = 'ip = IP( '
+            options = []
+            for key, value in kwargs.iteritems():
+                if isinstance( value, str ):
+                    value = '"' + value + '"'
+                options.append( str( key ) + "=" + str( value ) )
+            cmd += ", ".join( options )
+            cmd += ' )'
+            self.handle.sendline( cmd )
+            self.handle.expect( self.scapyPrompt )
+            if "Traceback" in self.handle.before:
+                # KeyError, SyntaxError, ...
+                main.log.error( "Error in sending command: " + self.handle.before )
+                return main.FALSE
+            self.handle.sendline( "packet = ether/ip" )
+            self.handle.expect( self.scapyPrompt )
+            if "Traceback" in self.handle.before:
+                # KeyError, SyntaxError, ...
+                main.log.error( "Error in sending command: " + self.handle.before )
+                return main.FALSE
+            return main.TRUE
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return main.FALSE
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def buildIPv6( self, **kwargs ):
+        """
+        Build an IPv6 frame
+
+        Will create a frame class with the given options. If a field is
+        left blank it will default to the below value unless it is
+        overwritten by the next frame.
+        Default frame:
+        ###[ IPv6 ]###
+          version= 6
+          tc= 0
+          fl= 0
+          plen= None
+          nh= No Next Header
+          hlim= 64
+          src= ::1
+          dst= ::1
+
+        Returns main.TRUE or main.FALSE on error
+        """
+        try:
+            # Set the IPv6 frame
+            cmd = 'ipv6 = IPv6( '
+            options = []
+            for key, value in kwargs.iteritems():
+                if isinstance( value, str ):
+                    value = '"' + value + '"'
+                options.append( str( key ) + "=" + str( value ) )
+            cmd += ", ".join( options )
+            cmd += ' )'
+            self.handle.sendline( cmd )
+            self.handle.expect( self.scapyPrompt )
+            if "Traceback" in self.handle.before:
+                # KeyError, SyntaxError, ...
+                main.log.error( "Error in sending command: " + self.handle.before )
+                return main.FALSE
+            self.handle.sendline( "packet = ether/ipv6" )
+            self.handle.expect( self.scapyPrompt )
+            if "Traceback" in self.handle.before:
+                # KeyError, SyntaxError, ...
+                main.log.error( "Error in sending command: " + self.handle.before )
+                return main.FALSE
+            return main.TRUE
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return main.FALSE
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def buildTCP( self, ipVersion=4, **kwargs ):
+        """
+        Build an TCP frame
+
+        Will create a frame class with the given options. If a field is
+        left blank it will default to the below value unless it is
+        overwritten by the next frame.
+
+        Options:
+        ipVersion - Either 4 (default) or 6, indicates what Internet Protocol
+                    frame to use to encapsulate into
+        Default frame:
+        ###[ TCP ]###
+          sport= ftp_data
+          dport= http
+          seq= 0
+          ack= 0
+          dataofs= None
+          reserved= 0
+          flags= S
+          window= 8192
+          chksum= None
+          urgptr= 0
+          options= {}
+
+        Returns main.TRUE or main.FALSE on error
+        """
+        try:
+            # Set the TCP frame
+            cmd = 'tcp = TCP( '
+            options = []
+            for key, value in kwargs.iteritems():
+                if isinstance( value, str ):
+                    value = '"' + value + '"'
+                options.append( str( key ) + "=" + str( value ) )
+            cmd += ", ".join( options )
+            cmd += ' )'
+            self.handle.sendline( cmd )
+            self.handle.expect( self.scapyPrompt )
+            if "Traceback" in self.handle.before:
+                # KeyError, SyntaxError, ...
+                main.log.error( "Error in sending command: " + self.handle.before )
+                return main.FALSE
+            if str( ipVersion ) is '4':
+                self.handle.sendline( "packet = ether/ip/tcp" )
+            elif str( ipVersion ) is '6':
+                self.handle.sendline( "packet = ether/ipv6/tcp" )
+            else:
+                main.log.error( "Unrecognized option for ipVersion, given " +
+                                repr( ipVersion ) )
+                return main.FALSE
+            self.handle.expect( self.scapyPrompt )
+            if "Traceback" in self.handle.before:
+                # KeyError, SyntaxError, ...
+                main.log.error( "Error in sending command: " + self.handle.before )
+                return main.FALSE
+            return main.TRUE
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return main.FALSE
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def buildUDP( self, ipVersion=4, **kwargs ):
+        """
+        Build an UDP frame
+
+        Will create a frame class with the given options. If a field is
+        left blank it will default to the below value unless it is
+        overwritten by the next frame.
+
+        Options:
+        ipVersion - Either 4 (default) or 6, indicates what Internet Protocol
+                    frame to use to encapsulate into
+        Default frame:
+        ###[ UDP ]###
+          sport= domain
+          dport= domain
+          len= None
+          chksum= None
+
+        Returns main.TRUE or main.FALSE on error
+        """
+        try:
+            # Set the UDP frame
+            cmd = 'udp = UDP( '
+            options = []
+            for key, value in kwargs.iteritems():
+                if isinstance( value, str ):
+                    value = '"' + value + '"'
+                options.append( str( key ) + "=" + str( value ) )
+            cmd += ", ".join( options )
+            cmd += ' )'
+            self.handle.sendline( cmd )
+            self.handle.expect( self.scapyPrompt )
+            if "Traceback" in self.handle.before:
+                # KeyError, SyntaxError, ...
+                main.log.error( "Error in sending command: " + self.handle.before )
+                return main.FALSE
+            if str( ipVersion ) is '4':
+                self.handle.sendline( "packet = ether/ip/udp" )
+            elif str( ipVersion ) is '6':
+                self.handle.sendline( "packet = ether/ipv6/udp" )
+            else:
+                main.log.error( "Unrecognized option for ipVersion, given " +
+                                repr( ipVersion ) )
+                return main.FALSE
+            self.handle.expect( self.scapyPrompt )
+            if "Traceback" in self.handle.before:
+                # KeyError, SyntaxError, ...
+                main.log.error( "Error in sending command: " + self.handle.before )
+                return main.FALSE
+            return main.TRUE
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return main.FALSE
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def buildICMP( self, **kwargs ):
+        """
+        Build an ICMP frame
+
+        Will create a frame class with the given options. If a field is
+        left blank it will default to the below value unless it is
+        overwritten by the next frame.
+        Default frame:
+        ###[ ICMP ]###
+          type= echo-request
+          code= 0
+          chksum= None
+          id= 0x0
+          seq= 0x0
+
+        Returns main.TRUE or main.FALSE on error
+        """
+        try:
+            # Set the ICMP frame
+            cmd = 'icmp = ICMP( '
+            options = []
+            for key, value in kwargs.iteritems():
+                if isinstance( value, str ):
+                    value = '"' + value + '"'
+                options.append( str( key ) + "=" + str( value ) )
+            cmd += ", ".join( options )
+            cmd += ' )'
+            self.handle.sendline( cmd )
+            self.handle.expect( self.scapyPrompt )
+            if "Traceback" in self.handle.before:
+                # KeyError, SyntaxError, ...
+                main.log.error( "Error in sending command: " + self.handle.before )
+                return main.FALSE
+            self.handle.sendline( "packet = ether/ip/icmp" )
+            self.handle.expect( self.scapyPrompt )
+            if "Traceback" in self.handle.before:
+                # KeyError, SyntaxError, ...
+                main.log.error( "Error in sending command: " + self.handle.before )
+                return main.FALSE
+            return main.TRUE
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return main.FALSE
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def sendPacket( self, packet=None, timeout=1 ):
+        """
+        Send a packet with either the given scapy packet command, or use the
+        packet saved in the variable 'packet'.
+
+        Examples of a valid string for packet:
+
+        Simple IP packet
+        packet='Ether(dst="a6:d9:26:df:1d:4b")/IP(dst="10.0.0.2")'
+
+        A Ping with two vlan tags
+        packet='Ether(dst='ff:ff:ff:ff:ff:ff')/Dot1Q(vlan=1)/Dot1Q(vlan=10)/
+                IP(dst='255.255.255.255', src='192.168.0.1')/ICMP()'
+
+        Returns main.TRUE or main.FALSE on error
+        """
+        try:
+            # TODO: add all params, or use kwargs
+            sendCmd = 'srp( '
+            if packet:
+                sendCmd += packet
+            else:
+                sendCmd += "packet"
+            sendCmd += ', timeout=' + str( timeout ) + ')'
+            self.handle.sendline( sendCmd )
+            self.handle.expect( self.scapyPrompt )
+            if "Traceback" in self.handle.before:
+                # KeyError, SyntaxError, ...
+                main.log.error( "Error in sending command: " + self.handle.before )
+                return main.FALSE
+            # TODO: Check # of packets sent?
+            return main.TRUE
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return main.FALSE
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def startFilter( self, ifaceName=None, sniffCount=1, pktFilter="ip" ):
+        """
+        Listen for packets using the given filters
+
+        Options:
+        ifaceName - the name of the interface to listen on. If none is given,
+                    defaults to <host name>-eth0
+        pktFilter - A string in Berkeley Packet Filter (BPF) format which
+                    specifies which packets to sniff
+        sniffCount - The number of matching packets to capture before returning
+
+        Returns main.TRUE or main.FALSE on error
+        """
+        try:
+            # TODO: add all params, or use kwargs
+            ifaceName = str( ifaceName ) if ifaceName else self.name + "-eth0"
+            # Set interface
+            self.handle.sendline( ' conf.iface = "' + ifaceName + '"' )
+            self.handle.expect( self.scapyPrompt )
+            cmd = 'pkt = sniff(count = ' + str( sniffCount ) +\
+                  ', filter = "' + str( pktFilter ) + '")'
+            self.handle.sendline( cmd )
+            self.handle.expect( '"\)\r\n' )
+            # TODO: parse this?
+            return main.TRUE
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return main.FALSE
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def checkFilter( self ):
+        """
+        Check that a filter returned and returns the reponse
+        """
+        try:
+            i = self.handle.expect( [ self.scapyPrompt, pexpect.TIMEOUT ] )
+            if i == 0:
+                return main.TRUE
+            else:
+                return main.FALSE
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def killFilter( self ):
+        """
+        Kill a scapy filter
+        """
+        try:
+            self.handle.send( "\x03" )  # Send a ctrl-c to kill the filter
+            self.handle.expect( self.scapyPrompt )
+            return self.handle.before
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return None
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def readPackets( self ):
+        """
+        Read all the packets captured by the previous filter
+        """
+        try:
+            self.handle.sendline( "for p in pkt: p \n")
+            self.handle.expect( "for p in pkt: p \r\n... \r\n" )
+            self.handle.expect( self.scapyPrompt )
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return None
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+        return self.handle.before
+
+    def updateSelf( self ):
+        """
+        Updates local MAC and IP fields
+        """
+        self.hostMac = self.getMac()
+        self.hostIp = self.getIp()
+
+    def getMac( self, ifaceName=None ):
+        """
+        Save host's MAC address
+        """
+        try:
+            ifaceName = str( ifaceName ) if ifaceName else self.name + "-eth0"
+            cmd = 'get_if_hwaddr("' + str( ifaceName ) + '")'
+            self.handle.sendline( cmd )
+            self.handle.expect( self.scapyPrompt )
+            pattern = r'(([0-9a-f]{2}[:-]){5}([0-9a-f]{2}))'
+            match = re.search( pattern, self.handle.before )
+            if match:
+                return match.group()
+            else:
+                # the command will have an exception if iface doesn't exist
+                return None
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return None
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
+    def getIp( self, ifaceName=None ):
+        """
+        Save host's IP address
+        """
+        try:
+            ifaceName = ifaceName if ifaceName else self.name + "-eth0"
+            cmd = 'get_if_addr("' + str( ifaceName ) + '")'
+            self.handle.sendline( cmd )
+            self.handle.expect( self.scapyPrompt )
+
+            pattern = r'(((2[0-5]|1[0-9]|[0-9])?[0-9]\.){3}((2[0-5]|1[0-9]|[0-9])?[0-9]))'
+            match = re.search( pattern, self.handle.before )
+            if match:
+                # NOTE: The command will return 0.0.0.0 if the iface doesn't exist
+                return match.group()
+            else:
+                return None
+        except pexpect.TIMEOUT:
+            main.log.exception( self.name + ": Command timed out" )
+            return None
+        except pexpect.EOF:
+            main.log.exception( self.name + ": connection closed." )
+            main.cleanup()
+            main.exit()
+        except Exception:
+            main.log.exception( self.name + ": Uncaught exception!" )
+            main.cleanup()
+            main.exit()
+
 if __name__ != "__main__":
-    import sys
     sys.modules[ __name__ ] = MininetCliDriver()
diff --git a/TestON/tests/FUNCflow/FUNCflow.params b/TestON/tests/FUNCflow/FUNCflow.params
index e0dde55..0aa8e89 100755
--- a/TestON/tests/FUNCflow/FUNCflow.params
+++ b/TestON/tests/FUNCflow/FUNCflow.params
@@ -6,10 +6,11 @@
     # 8 - Compare topology
     # 9 - Report logs
     # 10 - Start mininet and assign switches to controller
+    # 66 - Testing Scapy
     # 1000 - Add flows
     # 2000 - Verify flows are in the ADDED state
     # 3000 - Delete flows
-    <testcases>1,2,10,11,1000,2000,3000,100</testcases>
+    <testcases>1,2,10,11,1000,2000,[66]*3,3000</testcases>
 
     <SCALE>
         <max>1</max>
diff --git a/TestON/tests/FUNCflow/FUNCflow.py b/TestON/tests/FUNCflow/FUNCflow.py
index fdd2c1f..89a7e32 100644
--- a/TestON/tests/FUNCflow/FUNCflow.py
+++ b/TestON/tests/FUNCflow/FUNCflow.py
@@ -310,6 +310,74 @@
 
 
 
+    def CASE66( self, main ):
+        '''
+        Testing scapy
+        '''
+        main.case( "Testing scapy" )
+        main.step( "Creating Host1 component" )
+        main.Mininet1.createHostComponent( "h1" )
+        main.Mininet1.createHostComponent( "h2" )
+        hosts = [main.h1, main.h2]
+        for host in hosts:
+            host.startHostCli()
+            host.startScapy()
+            host.updateSelf()
+            main.log.debug( host.name )
+            main.log.debug( host.hostIp )
+            main.log.debug( host.hostMac )
+
+        main.step( "Sending/Receiving Test packet - Filter doesn't match" )
+        main.h2.startFilter()
+        main.h1.buildEther( dst=main.h2.hostMac )
+        main.h1.sendPacket( )
+        finished = main.h2.checkFilter()
+        i = ""
+        if finished:
+            a = main.h2.readPackets()
+            for i in a.splitlines():
+                main.log.info( i )
+        else:
+            kill = main.h2.killFilter()
+            main.log.debug( kill )
+            main.h2.handle.sendline( "" )
+            main.h2.handle.expect( main.h2.scapyPrompt )
+            main.log.debug( main.h2.handle.before )
+        utilities.assert_equals( expect=True,
+                                 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
+                                 onpass="Pass",
+                                 onfail="Fail" )
+
+        main.step( "Sending/Receiving Test packet - Filter matches" )
+        main.h2.startFilter()
+        main.h1.buildEther( dst=main.h2.hostMac )
+        main.h1.buildIP( dst=main.h2.hostIp )
+        main.h1.sendPacket( )
+        finished = main.h2.checkFilter()
+        i = ""
+        if finished:
+            a = main.h2.readPackets()
+            for i in a.splitlines():
+                main.log.info( i )
+        else:
+            kill = main.h2.killFilter()
+            main.log.debug( kill )
+            main.h2.handle.sendline( "" )
+            main.h2.handle.expect( main.h2.scapyPrompt )
+            main.log.debug( main.h2.handle.before )
+        utilities.assert_equals( expect=True,
+                                 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
+                                 onpass="Pass",
+                                 onfail="Fail" )
+
+
+
+        main.step( "Clean up host components" )
+        for host in hosts:
+            host.stopScapy()
+        main.Mininet1.removeHostComponent("h1")
+        main.Mininet1.removeHostComponent("h2")
+
     def CASE1000( self, main ):
         '''
             Add flows
diff --git a/TestON/tests/SCPFscaleTopo/SCPFscaleTopo.params b/TestON/tests/SCPFscaleTopo/SCPFscaleTopo.params
index 1e8635e..cd9390c 100755
--- a/TestON/tests/SCPFscaleTopo/SCPFscaleTopo.params
+++ b/TestON/tests/SCPFscaleTopo/SCPFscaleTopo.params
@@ -2,15 +2,13 @@
 
     # 1 - optional pull and build ONOS package
     # 2 - set cell and install ONOS
-    # 10 - start mininet and assign switches to controller
-    # 11 - pingall
-    # 12 - compare topology
-    # 100 - balance master
-    # 200 - bring down onos node
-    # 300 - bring up onos node
+    # 10 - start mininet and verify topo
+    # 11 - verify topo
+    # 100 - balance master and bring onos node down
+    # 200 - bring onos node up and balance masters
     # 1000 - report logs
 
-    <testcases>1,2,[10,100,11,12,200,100,11,12,300,100,11,12,1000]*3</testcases>
+    <testcases>1,2,[10,100,11,200,11,1000]*3</testcases>
 
     <DEPENDENCY>
         <path>/tests/SCPFscaleTopo/Dependency/</path>
@@ -37,19 +35,32 @@
     <SLEEP>
         <startup>15</startup>
         <fwd>30</fwd>
-        <topoAttempts>1</topoAttempts>
         <balance>10</balance>
         <nodeDown>10</nodeDown>
         <nodeUp>10</nodeUp>
+        <pingall>3</pingall>
+        <stopMN>5</stopMN>
+        <startMN>5</startMN>
     </SLEEP>
 
     <TIMEOUT>
-        <pingall>1000</pingall>
+        <pingall>240</pingall>
     </TIMEOUT>
 
+    <ATTEMPTS>
+        <topoCmp>1</topoCmp>
+        <pingall>2</pingall>
+    </ATTEMPTS>
+
     <TOPOLOGY>
         <topology>torus</topology>
         <scale>5,10,20</scale>
     </TOPOLOGY>
 
+    <PINGALL>
+        <sleep>3</sleep>
+        <attempts>5</attempts>
+        <timeout>1000</timeout>
+    </PINGALL>
+
 </PARAMS>
diff --git a/TestON/tests/SCPFscaleTopo/SCPFscaleTopo.py b/TestON/tests/SCPFscaleTopo/SCPFscaleTopo.py
index b44d482..e0f2f1a 100644
--- a/TestON/tests/SCPFscaleTopo/SCPFscaleTopo.py
+++ b/TestON/tests/SCPFscaleTopo/SCPFscaleTopo.py
@@ -23,73 +23,60 @@
             - Build ONOS package
         """
 
-        main.case( "Constructing test variables and building ONOS package" )
+        main.case( "Constructing test variables" )
         main.step( "Constructing test variables" )
         stepResult = main.FALSE
 
-        try:
-            main.testOnDirectory = os.path.dirname( os.getcwd ( ) )
-            main.apps = main.params[ 'ENV' ][ 'cellApps' ]
-            gitBranch = main.params[ 'GIT' ][ 'branch' ]
-            main.dependencyPath = main.testOnDirectory + \
-                                  main.params[ 'DEPENDENCY' ][ 'path' ]
-            main.multiovs = main.params[ 'DEPENDENCY' ][ 'multiovs' ]
-            main.topoName = main.params[ 'TOPOLOGY' ][ 'topology' ]
-            main.numCtrls = int( main.params[ 'CTRL' ][ 'numCtrls' ] )
-            main.topoScale = ( main.params[ 'TOPOLOGY' ][ 'scale' ] ).split( "," )
-            main.topoScaleSize = len( main.topoScale )
-            wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
-            wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
-            wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ]
-            main.checkTopoAttempts = int( main.params['SLEEP']['topoAttempts'])
-            main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
-            main.fwdSleep = int( main.params[ 'SLEEP' ][ 'fwd' ] )
-            main.balanceSleep = int( main.params[ 'SLEEP' ][ 'balance' ] )
-            main.nodeDownSleep = int( main.params[ 'SLEEP' ][ 'nodeDown' ] )
-            main.nodeUpSleep = int( main.params[ 'SLEEP' ][ 'nodeUp' ] )
-            main.pingallTimeout = int( main.params[ 'TIMEOUT' ][ 'pingall' ] )
-            gitPull = main.params[ 'GIT' ][ 'pull' ]
-            main.homeDir = os.path.expanduser('~')
-            main.cellData = {} # for creating cell file
-            main.hostsData = {}
-            main.CLIs = []
-            main.ONOSip = []
-            main.activeNodes = []
-            main.ONOSip = main.ONOSbench.getOnosIps()
+        main.testOnDirectory = os.path.dirname( os.getcwd ( ) )
+        main.apps = main.params[ 'ENV' ][ 'cellApps' ]
+        gitBranch = main.params[ 'GIT' ][ 'branch' ]
+        main.dependencyPath = main.testOnDirectory + \
+                              main.params[ 'DEPENDENCY' ][ 'path' ]
+        main.multiovs = main.params[ 'DEPENDENCY' ][ 'multiovs' ]
+        main.topoName = main.params[ 'TOPOLOGY' ][ 'topology' ]
+        main.numCtrls = int( main.params[ 'CTRL' ][ 'numCtrls' ] )
+        main.topoScale = ( main.params[ 'TOPOLOGY' ][ 'scale' ] ).split( "," )
+        main.topoScaleSize = len( main.topoScale )
+        wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
+        wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
+        wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ]
+        main.topoCmpAttempts = int( main.params[ 'ATTEMPTS' ][ 'topoCmp' ] )
+        main.pingallAttempts = int( main.params[ 'ATTEMPTS' ][ 'pingall' ] )
+        main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
+        main.fwdSleep = int( main.params[ 'SLEEP' ][ 'fwd' ] )
+        main.balanceSleep = int( main.params[ 'SLEEP' ][ 'balance' ] )
+        main.nodeDownSleep = int( main.params[ 'SLEEP' ][ 'nodeDown' ] )
+        main.nodeUpSleep = int( main.params[ 'SLEEP' ][ 'nodeUp' ] )
+        main.pingallSleep = int( main.params[ 'SLEEP' ][ 'pingall' ] )
+        main.stopMNSleep = int( main.params[ 'SLEEP' ][ 'stopMN' ] )
+        main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] )
+        main.pingTimeout = int( main.params[ 'TIMEOUT' ][ 'pingall' ] )
+        gitPull = main.params[ 'GIT' ][ 'pull' ]
+        main.homeDir = os.path.expanduser('~')
+        main.cellData = {} # for creating cell file
+        main.hostsData = {}
+        main.CLIs = []
+        main.ONOSip = []
+        main.activeNodes = []
+        main.ONOSip = main.ONOSbench.getOnosIps()
 
-        except Exception:
-            main.log.exception( "Exception: constructing test variables" )
-            main.cleanup()
-            main.exit()
-
-        try:
-            for i in range(main.numCtrls):
+        for i in range(main.numCtrls):
                 main.CLIs.append( getattr( main, 'ONOScli%s' % (i+1) ) )
 
-        except Exception:
-            main.log.exception( "Exception: assinging ONOS cli handles to a list" )
-            main.cleanup()
-            main.exit()
+        main.startUp = imp.load_source( wrapperFile1,
+                                        main.dependencyPath +
+                                        wrapperFile1 +
+                                        ".py" )
 
-        try:
-            main.startUp = imp.load_source( wrapperFile1,
-                                            main.dependencyPath +
-                                            wrapperFile1 +
-                                            ".py" )
+        main.scaleTopoFunction = imp.load_source( wrapperFile2,
+                                                  main.dependencyPath +
+                                                  wrapperFile2 +
+                                                  ".py" )
 
-            main.scaleTopoFunction = imp.load_source( wrapperFile2,
-                                                      main.dependencyPath +
-                                                      wrapperFile2 +
-                                                      ".py" )
-
-            main.topo = imp.load_source( wrapperFile3,
-                                         main.dependencyPath +
-                                         wrapperFile3 +
-                                         ".py" )
-        except Exception:
-            main.log.exception( "Exception: importing wrapper files" )
-            main.cleanup()
-            main.exit()
+        main.topo = imp.load_source( wrapperFile3,
+                                     main.dependencyPath +
+                                     wrapperFile3 +
+                                     ".py" )
 
         main.ONOSbench.scp( main.Mininet1,
                             main.dependencyPath +
@@ -243,31 +230,36 @@
 
     def CASE10( self, main ):
         """
-            Starting up torus topology
+            Starting up torus topology, pingall, and compare topo
         """
-        main.case( "Starting up torus topology" )
-        main.step( "Starting up torus topology" )
+        import json
+
+        main.case( "Starting up Mininet and verifying topology" )
+        main.caseExplanation = "Starting Mininet with a scalling topology and " +\
+                "comparing topology elements between Mininet and ONOS"
 
         main.log.info( "Checking if mininet is already running" )
         if len( main.topoScale ) < main.topoScaleSize:
             main.log.info( "Mininet is already running. Stopping mininet." )
             main.Mininet1.stopNet()
-            time.sleep(5)
+            time.sleep(main.stopMNSleep)
         else:
             main.log.info( "Mininet was not running" )
 
-        try:
+        if main.topoScale:
             scale = main.topoScale.pop(0)
-        except Exception:
-            main.log.exception("Exception: popping from list of topology scales ")
-            main.cleanup()
-            main.exit()
+        else: main.log.error( "topology scale is empty" )
 
-        mnCmd = " mn --custom=" + main.homeDir + "/mininet/custom/multiovs.py " +\
-                "--switch=ovsm --topo " + main.topoName + ","+ scale + "," + scale +\
-                " --controller=remote,ip=" + main.ONOSip[ 0 ] +\
-                " --controller=remote,ip=" + main.ONOSip[ 1 ] +\
-                " --controller=remote,ip=" + main.ONOSip[ 2 ] + " --mac"
+
+        main.step( "Starting up TORUS %sx%s topology" % (scale, scale) )
+
+        main.log.info( "Constructing Mininet command" )
+        mnCmd = " mn --custom " + main.Mininet1.home + main.multiovs +\
+                " --switch ovsm --topo " + main.topoName + ","+ scale + "," + scale
+
+        for i in range( main.numCtrls ):
+                mnCmd += " --controller remote,ip=" + main.ONOSip[ i ]
+
         stepResult = main.Mininet1.startNet(mnCmd=mnCmd)
         utilities.assert_equals( expect=main.TRUE,
                                  actual=stepResult,
@@ -276,36 +268,23 @@
                                  onfail=main.topoName +
                                     " topology failed to start" )
 
+        time.sleep( main.startMNSleep )
 
-    def CASE11( self, main ):
-        '''
-            Pingall
-        '''
-        main.case( "Pingall" )
-        main.step( "Pingall" )
-        pingResult = main.Mininet1.pingall( timeout=main.pingallTimeout )
-        if not pingResult:
-            main.log.warn( "First pingall failed. Retrying..." )
-            time.sleep(3)
-            pingResult = main.Mininet1.pingall( timeout=main.pingallTimeout )
+        main.step( "Pinging all hosts" )
+
+        for i in range(main.pingallAttempts):
+            pingResult = main.Mininet1.pingall(timeout=main.pingTimeout)
+            if not pingResult:
+                main.log.warn( "Pingall attempt: %s failed" % (i+1) )
+                time.sleep(main.pingallSleep)
+            else: break
 
         utilities.assert_equals( expect=main.TRUE,
                                  actual=pingResult,
                                  onpass="Pingall successfull",
                                  onfail="Pingall failed" )
 
-
-    def CASE12( self, main ):
-        """
-        Compare Topo
-        """
-        import json
-
-        main.case( "Compare ONOS Topology view to Mininet topology" )
-        main.caseExplanation = "Compare topology elements between Mininet" +\
-                                " and ONOS"
-
-        main.step( "Gathering topology information" )
+        main.log.info( "Gathering topology information" )
         devicesResults = main.TRUE
         linksResults = main.TRUE
         hostsResults = main.TRUE
@@ -367,19 +346,112 @@
                                  onfail="ONOS" + controllerStr +
                                  " hosts don't match Mininet" )
 
+    def CASE11( self, main ):
+        """
+            Pingall, and compare topo
+        """
+        import json
+
+        scale = main.topoScale[0]
+
+        main.case( "Verifying topology: TORUS %sx%s" % (scale, scale) )
+        main.caseExplanation = "Pinging all hosts andcomparing topology " +\
+                "elements between Mininet and ONOS"
+        main.step( "Pinging all hosts" )
+
+        for i in range(main.pingallAttempts):
+            pingResult = main.Mininet1.pingall(timeout=main.pingTimeout)
+            if not pingResult:
+                main.log.warn( "Pingall attempt: %s failed" % (i+1) )
+                time.sleep(main.pingallSleep)
+            else: break
+
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=pingResult,
+                                 onpass="Pingall successfull",
+                                 onfail="Pingall failed" )
+
+        main.log.info( "Gathering topology information" )
+        devicesResults = main.TRUE
+        linksResults = main.TRUE
+        hostsResults = main.TRUE
+
+        devices = main.topo.getAllDevices( main )
+        hosts = main.topo.getAllHosts( main )
+        ports = main.topo.getAllPorts( main )
+        links = main.topo.getAllLinks( main )
+        clusters = main.topo.getAllClusters( main )
+
+        mnSwitches = main.Mininet1.getSwitches()
+        mnLinks = main.Mininet1.getLinks()
+        mnHosts = main.Mininet1.getHosts()
+
+        main.step( "Comparing MN topology to ONOS topology" )
+
+        for controller in range(len(main.activeNodes)):
+            controllerStr = str( main.activeNodes[controller] + 1 )
+            if devices[ controller ] and ports[ controller ] and\
+                "Error" not in devices[ controller ] and\
+                "Error" not in ports[ controller ]:
+
+                currentDevicesResult = main.Mininet1.compareSwitches(
+                        mnSwitches,
+                        json.loads( devices[ controller ] ),
+                        json.loads( ports[ controller ] ) )
+            else:
+                currentDevicesResult = main.FALSE
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=currentDevicesResult,
+                                     onpass="ONOS" + controllerStr +
+                                     " Switches view is correct",
+                                     onfail="ONOS" + controllerStr +
+                                     " Switches view is incorrect" )
+
+            if links[ controller ] and "Error" not in links[ controller ]:
+                currentLinksResult = main.Mininet1.compareLinks(
+                        mnSwitches, mnLinks,
+                        json.loads( links[ controller ] ) )
+            else:
+                currentLinksResult = main.FALSE
+            utilities.assert_equals( expect=main.TRUE,
+                                     actual=currentLinksResult,
+                                     onpass="ONOS" + controllerStr +
+                                     " links view is correct",
+                                     onfail="ONOS" + controllerStr +
+                                     " links view is incorrect" )
+
+            if hosts[ controller ] or "Error" not in hosts[ controller ]:
+                currentHostsResult = main.Mininet1.compareHosts(
+                        mnHosts,
+                        json.loads( hosts[ controller ] ) )
+            else:
+                currentHostsResult = main.FALSE
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=currentHostsResult,
+                                 onpass="ONOS" + controllerStr +
+                                 " hosts exist in Mininet",
+                                 onfail="ONOS" + controllerStr +
+                                 " hosts don't match Mininet" )
+
+
     def CASE100( self, main ):
         '''
-            Balance master
+            Balance masters, ping and bring third ONOS node down
         '''
-        main.case("Balancing Masters")
-        main.step("Balancing Masters")
-        try:
+        scale = main.topoScale[0]
+
+        main.case("Balancing Masters and bring ONOS node 3 down: TORUS %sx%s" % (scale, scale))
+        main.caseExplanation = "Balance masters to make sure " +\
+                        "each controller has some devices and " +\
+                        "stop ONOS node 3 service. "
+
+        main.step( "Balancing Masters" )
+        stepResult = main.FALSE
+        if main.activeNodes:
             controller = main.activeNodes[0]
             stepResult = main.CLIs[controller].balanceMasters()
-        except Exception:
-            main.log.exception("Exception: balancing masters")
-            main.cleanup()
-            main.exit()
+        else: main.log.error( "List of active nodes is empty" )
+
         utilities.assert_equals( expect=main.TRUE,
                                  actual=stepResult,
                                  onpass="Balance masters was successfull",
@@ -387,12 +459,20 @@
 
         time.sleep(main.balanceSleep)
 
+        main.step( "Pinging all hosts" )
 
-    def CASE200( self, main ):
-        '''
-            Bring third node down
-        '''
-        main.case( "Stopping an ONOS service" )
+        for i in range(main.pingallAttempts):
+            pingResult = main.Mininet1.pingall(timeout=main.pingTimeout)
+            if not pingResult:
+                main.log.warn( "Pingall attempt: %s failed" % (i+1) )
+                time.sleep(main.pingallSleep)
+            else: break
+
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=pingResult,
+                                 onpass="Pingall successfull",
+                                 onfail="Pingall failed" )
+
         main.step( "Bringing down node 3" )
 
         # Always bring down the third node
@@ -401,17 +481,11 @@
         # Printing purposes
         node = main.deadNode + 1
 
-        main.log.info( "deadnode: %s" % node )
-
         main.log.info( "Stopping node %s" % node )
-        startResult = main.ONOSbench.onosStop( main.ONOSip[ main.deadNode ] )
+        stepResult = main.ONOSbench.onosStop( main.ONOSip[ main.deadNode ] )
 
-        try:
-            main.activeNodes.pop( main.deadNode )
-        except Exception:
-            main.log.exception( "Exception: popping from list of active nodes" )
-            main.cleanup()
-            main.exit()
+        main.log.info( "Removing dead node from list of active nodes" )
+        main.activeNodes.pop( main.deadNode )
 
         utilities.assert_equals( expect=main.TRUE,
                              actual=stepResult,
@@ -421,25 +495,27 @@
         time.sleep(main.nodeDownSleep)
 
 
-    def CASE300( self, main ):
+    def CASE200( self, main ):
         '''
-            Bring up onos node
+            Bring up onos node and balance masters
         '''
-        main.case( "Bring the dead ONOS node back up" )
-        main.step( "Bringing up an onos node" )
+
+        scale = main.topoScale[0]
+
+        main.case("Bring ONOS node 3 up and balance masters: TORUS %sx%s" % (scale, scale))
+        main.caseExplanation = "Bring node 3 back up and balance the masters"
 
         node = main.deadNode + 1
 
         main.log.info( "Starting node %s" % node )
-        startResult = main.ONOSbench.onosStart( main.ONOSip[ main.deadNode ] )
+        stepResult = main.ONOSbench.onosStart( main.ONOSip[ main.deadNode ] )
 
         main.log.info( "Starting onos cli" )
-        startCliResult = main.CLIs[ main.deadNode ].startOnosCli( main.ONOSip[ main.deadNode ] )
+        stepResult = stepResult and main.CLIs[ main.deadNode ].startOnosCli( main.ONOSip[ main.deadNode ] )
 
+        main.log.info( "Adding previously dead node to list of active nodes" )
         main.activeNodes.append( main.deadNode )
 
-        stepResult = startResult and startCliResult
-
         utilities.assert_equals( expect=main.TRUE,
                                  actual=stepResult,
                                  onpass="Successfully brought up onos node %s" % node,
@@ -448,16 +524,38 @@
 
         time.sleep(main.nodeUpSleep)
 
+        main.step( "Balancing Masters" )
+        stepResult = main.FALSE
+        if main.activeNodes:
+            controller = main.activeNodes[0]
+            stepResult = main.CLIs[controller].balanceMasters()
+        else: main.log.error( "List of active nodes is empty" )
+
+        utilities.assert_equals( expect=main.TRUE,
+                                 actual=stepResult,
+                                 onpass="Balance masters was successfull",
+                                 onfail="Failed to balance masters")
+
+        time.sleep(main.balanceSleep)
+
+        for i in range(main.pingallAttempts):
+            pingResult = main.Mininet1.pingall(timeout=main.pingTimeout)
+            if not pingResult:
+                main.log.warn( "Pingall attempt: %s failed" % (i+1) )
+                time.sleep(main.pingallSleep)
+            else: break
+
     def CASE1000( self, main ):
         '''
             Report errors/warnings/exceptions
         '''
+        main.case( "Checking logs for errors, warnings, and exceptions" )
         main.log.info("Error report: \n" )
         main.ONOSbench.logReport( main.ONOSip[ 0 ],
-                                  [ "INFO",
-                                    "FOLLOWER",
-                                    "WARN",
-                                    "flow",
-                                    "ERROR",
-                                    "Except" ],
-                                  "s" )
+                                                            [ "INFO",
+                                                              "FOLLOWER",
+                                                              "WARN",
+                                                              "flow",
+                                                              "ERROR",
+                                                              "Except" ],
+                                                            "s" )