Merge "Modify some steps which have no result"
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index cf2f54a..2eca3da 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -1990,31 +1990,44 @@
             main.cleanup()
             main.exit()
 
-    def checkFlowsState( self ):
+    def checkFlowsState( self, isPENDING_ADD = True ):
         """
         Description:
             Check the if all the current flows are in ADDED state or
             PENDING_ADD state
+        Optional:
+            * isPENDING_ADD: 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, return main.FALSE
-                          otherwise.
+                          ADDED state or PENDING_ADD if the PENDING_ADD
+                          parameter is set true, return main.FALSE otherwise.
         """
         try:
             tempFlows = json.loads( self.flows() )
             #print tempFlows[0]
             returnValue = main.TRUE
 
-            for device in tempFlows:
-                for flow in device.get( 'flows' ):
-                    if flow.get( 'state' ) != 'ADDED' and flow.get( 'state' ) != \
-                            'PENDING_ADD':
+            if isPENDING_ADD:
+                for device in tempFlows:
+                    for flow in device.get( 'flows' ):
+                        if flow.get( 'state' ) != 'ADDED' and \
+                            flow.get( 'state' ) != 'PENDING_ADD':
 
-                        main.log.info( self.name + ": flow Id: " +
-                                       str( flow.get( 'groupId' ) ) +
-                                       " | state:" +
-                                       str( flow.get( 'state' ) ) )
-                        returnValue = main.FALSE
+                            main.log.info( self.name + ": flow Id: " +
+                                           str( flow.get( 'groupId' ) ) +
+                                           " | state:" +
+                                           str( flow.get( 'state' ) ) )
+                            returnValue = main.FALSE
+            else:
+                for device in tempFlows:
+                    for flow in device.get( 'flows' ):
+                        if flow.get( 'state' ) != 'ADDED':
+
+                            main.log.info( self.name + ": flow Id: " +
+                                           str( flow.get( 'groupId' ) ) +
+                                           " | state:" +
+                                           str( flow.get( 'state' ) ) )
+                            returnValue = main.FALSE
 
             return returnValue
         except TypeError:
diff --git a/TestON/tests/HAclusterRestart/HAclusterRestart.py b/TestON/tests/HAclusterRestart/HAclusterRestart.py
index 1abca54..3026c1e 100644
--- a/TestON/tests/HAclusterRestart/HAclusterRestart.py
+++ b/TestON/tests/HAclusterRestart/HAclusterRestart.py
@@ -510,19 +510,22 @@
         # FIXME: Once we have a host discovery mechanism, use that instead
         # REACTIVE FWD test
         pingResult = main.FALSE
-        for i in range(2):  # Retry if pingall fails first time
-            time1 = time.time()
+        passMsg = "Reactive Pingall test passed"
+        time1 = time.time()
+        pingResult = main.Mininet1.pingall()
+        time2 = time.time()
+        if not pingResult:
+            main.log.warn("First pingall failed. Trying again...")
             pingResult = main.Mininet1.pingall()
-            if i == 0:
-                utilities.assert_equals(
-                    expect=main.TRUE,
-                    actual=pingResult,
-                    onpass="Reactive Pingall test passed",
-                    onfail="Reactive Pingall failed, " +
-                           "one or more ping pairs failed" )
-            time2 = time.time()
-            main.log.info( "Time for pingall: %2f seconds" %
-                           ( time2 - time1 ) )
+            passMsg += " on the second try"
+        utilities.assert_equals(
+            expect=main.TRUE,
+            actual=pingResult,
+            onpass= passMsg,
+            onfail="Reactive Pingall failed, " +
+                   "one or more ping pairs failed" )
+        main.log.info( "Time for pingall: %2f seconds" %
+                       ( time2 - time1 ) )
         # timeout for fwd flows
         time.sleep( 11 )
         # uninstall onos-app-fwd
@@ -2699,15 +2702,14 @@
         main.Mininet2.stopTcpdump()
 
         testname = main.TEST
-        main.log.error( main.params[ 'BACKUP' ][ 'ENABLED' ] )
         if main.params[ 'BACKUP' ][ 'ENABLED' ] == "True":
             main.step( "Copying MN pcap and ONOS log files to test station" )
             teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ]
             teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ]
-            # NOTE: MN Pcap file is being saved to ~/packet_captures
-            #       scp this file as MN and TestON aren't necessarily the same vm
-            # FIXME: scp
-            # mn files
+            # NOTE: MN Pcap file is being saved to logdir.
+            #       We scp this file as MN and TestON aren't necessarily the same vm
+
+            # FIXME: To be replaced with a Jenkin's post script
             # TODO: Load these from params
             # NOTE: must end in /
             logFolder = "/opt/onos/log/"
@@ -2715,14 +2717,9 @@
             # NOTE: must end in /
             for f in logFiles:
                 for node in main.nodes:
-                    # scp sdn@<ip>:<file path> <test's log path>/<node name>-<orig filename>
-                    main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address +
-                                                    ":" + logFolder + f + " " +
-                                                    main.logdir + "/" +
-                                                    node.name + "-" + f )
-                    main.ONOSbench.handle.expect( "\$ " )
-                    print main.ONOSbench.handle.before
-
+                    dstName =  main.logdir + "/" + node.name + "-" + f
+                    main.ONOSbench.secureCopy( node.user_name, node.ip_address,
+                                               logFolder + f, dstName )
             # std*.log's
             # NOTE: must end in /
             logFolder = "/opt/onos/var/"
@@ -2730,17 +2727,9 @@
             # NOTE: must end in /
             for f in logFiles:
                 for node in main.nodes:
-                    # scp sdn@<ip>:<file path> <test's log path>/<node name>-<orig filename>
-                    main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address +
-                                                    ":" + logFolder + f + " " +
-                                                    main.logdir + "/" +
-                                                    node.name + "-" + f )
-                    main.ONOSbench.handle.expect( "\$ " )
-                    print main.ONOSbench.handle.before
-            # sleep so scp can finish
-            time.sleep( 10 )
-            # main.step( "Packing and rotating pcap archives" )
-            # os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
+                    dstName =  main.logdir + "/" + node.name + "-" + f
+                    main.ONOSbench.secureCopy( node.user_name, node.ip_address,
+                                               logFolder + f, dstName )
         else:
             main.log.debug( "skipping saving log files" )
 
diff --git a/TestON/tests/HAminorityRestart/HAminorityRestart.py b/TestON/tests/HAminorityRestart/HAminorityRestart.py
index 855f380..69c0645 100644
--- a/TestON/tests/HAminorityRestart/HAminorityRestart.py
+++ b/TestON/tests/HAminorityRestart/HAminorityRestart.py
@@ -494,19 +494,22 @@
         # FIXME: Once we have a host discovery mechanism, use that instead
         # REACTIVE FWD test
         pingResult = main.FALSE
-        for i in range(2):  # Retry if pingall fails first time
-            time1 = time.time()
+        passMsg = "Reactive Pingall test passed"
+        time1 = time.time()
+        pingResult = main.Mininet1.pingall()
+        time2 = time.time()
+        if not pingResult:
+            main.log.warn("First pingall failed. Trying again...")
             pingResult = main.Mininet1.pingall()
-            if i == 0:
-                utilities.assert_equals(
-                    expect=main.TRUE,
-                    actual=pingResult,
-                    onpass="Reactive Pingall test passed",
-                    onfail="Reactive Pingall failed, " +
-                           "one or more ping pairs failed" )
-            time2 = time.time()
-            main.log.info( "Time for pingall: %2f seconds" %
-                           ( time2 - time1 ) )
+            passMsg += " on the second try"
+        utilities.assert_equals(
+            expect=main.TRUE,
+            actual=pingResult,
+            onpass= passMsg,
+            onfail="Reactive Pingall failed, " +
+                   "one or more ping pairs failed" )
+        main.log.info( "Time for pingall: %2f seconds" %
+                       ( time2 - time1 ) )
         # timeout for fwd flows
         time.sleep( 11 )
         # uninstall onos-app-fwd
@@ -1671,6 +1674,12 @@
         assert main.CLIs, "main.CLIs not defined"
         assert main.nodes, "main.nodes not defined"
         main.case( "Restart minority of ONOS nodes" )
+
+        main.step( "Checking ONOS Logs for errors" )
+        for node in main.nodes:
+            main.log.debug( "Checking logs for errors on " + node.name + ":" )
+            main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
+
         main.step( "Killing 3 ONOS nodes" )
         killTime = time.time()
         # TODO: Randomize these nodes or base this on partitions
@@ -2095,10 +2104,6 @@
                                 " and ONOS"
 
         main.step( "Comparing ONOS topology to MN" )
-        devicesResults = main.TRUE
-        linksResults = main.TRUE
-        hostsResults = main.TRUE
-        hostAttachmentResults = True
         topoResult = main.FALSE
         elapsed = 0
         count = 0
@@ -2106,6 +2111,10 @@
         startTime = time.time()
         # Give time for Gossip to work
         while topoResult == main.FALSE and elapsed < 60:
+            devicesResults = main.TRUE
+            linksResults = main.TRUE
+            hostsResults = main.TRUE
+            hostAttachmentResults = True
             count += 1
             cliStart = time.time()
             devices = []
@@ -2638,49 +2647,36 @@
         main.Mininet2.stopTcpdump()
 
         testname = main.TEST
-        if main.params[ 'BACKUP' ] == "True":
+        if main.params[ 'BACKUP' ][ 'ENABLED' ] == "True":
             main.step( "Copying MN pcap and ONOS log files to test station" )
             teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ]
             teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ]
-            # NOTE: MN Pcap file is being saved to ~/packet_captures
-            #       scp this file as MN and TestON aren't necessarily the same vm
-            # FIXME: scp
-            # mn files
+            # NOTE: MN Pcap file is being saved to logdir.
+            #       We scp this file as MN and TestON aren't necessarily the same vm
+
+            # FIXME: To be replaced with a Jenkin's post script
             # TODO: Load these from params
             # NOTE: must end in /
             logFolder = "/opt/onos/log/"
             logFiles = [ "karaf.log", "karaf.log.1" ]
             # NOTE: must end in /
-            dstDir = "~/packet_captures/"
             for f in logFiles:
                 for node in main.nodes:
-                    main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address +
-                                                    ":" + logFolder + f + " " +
-                                                    teststationUser + "@" +
-                                                    teststationIP + ":" +
-                                                    dstDir + str( testname ) +
-                                                    "-" + node.name + "-" + f )
-                    main.ONOSbench.handle.expect( "\$" )
-
+                    dstName =  main.logdir + "/" + node.name + "-" + f
+                    main.ONOSbench.secureCopy( node.user_name, node.ip_address,
+                                               logFolder + f, dstName )
             # std*.log's
             # NOTE: must end in /
             logFolder = "/opt/onos/var/"
             logFiles = [ "stderr.log", "stdout.log" ]
             # NOTE: must end in /
-            dstDir = "~/packet_captures/"
             for f in logFiles:
                 for node in main.nodes:
-                    main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address +
-                                                    ":" + logFolder + f + " " +
-                                                    teststationUser + "@" +
-                                                    teststationIP + ":" +
-                                                    dstDir + str( testname ) +
-                                                    "-" + node.name + "-" + f )
-                    main.ONOSbench.handle.expect( "\$" )
-            # sleep so scp can finish
-            time.sleep( 10 )
-            main.step( "Packing and rotating pcap archives" )
-            os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
+                    dstName =  main.logdir + "/" + node.name + "-" + f
+                    main.ONOSbench.secureCopy( node.user_name, node.ip_address,
+                                               logFolder + f, dstName )
+        else:
+            main.log.debug( "skipping saving log files" )
 
         main.step( "Stopping Mininet" )
         mnResult = main.Mininet1.stopNet()
@@ -2690,9 +2686,8 @@
 
         main.step( "Checking ONOS Logs for errors" )
         for node in main.nodes:
-            print colors[ 'purple' ] + "Checking logs for errors on " + \
-                node.name + ":" + colors[ 'end' ]
-            print main.ONOSbench.checkLogs( node.ip_address, restart=True )
+            main.log.debug( "Checking logs for errors on " + node.name + ":" )
+            main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
 
         try:
             timerLog = open( main.logdir + "/Timers.csv", 'w')
diff --git a/TestON/tests/HAsanity/HAsanity.py b/TestON/tests/HAsanity/HAsanity.py
index 6ceaead..e136d5e 100644
--- a/TestON/tests/HAsanity/HAsanity.py
+++ b/TestON/tests/HAsanity/HAsanity.py
@@ -494,19 +494,22 @@
         # FIXME: Once we have a host discovery mechanism, use that instead
         # REACTIVE FWD test
         pingResult = main.FALSE
-        for i in range(2):  # Retry if pingall fails first time
-            time1 = time.time()
+        passMsg = "Reactive Pingall test passed"
+        time1 = time.time()
+        pingResult = main.Mininet1.pingall()
+        time2 = time.time()
+        if not pingResult:
+            main.log.warn("First pingall failed. Trying again...")
             pingResult = main.Mininet1.pingall()
-            if i == 0:
-                utilities.assert_equals(
-                    expect=main.TRUE,
-                    actual=pingResult,
-                    onpass="Reactive Pingall test passed",
-                    onfail="Reactive Pingall failed, " +
-                           "one or more ping pairs failed" )
-            time2 = time.time()
-            main.log.info( "Time for pingall: %2f seconds" %
-                           ( time2 - time1 ) )
+            passMsg += " on the second try"
+        utilities.assert_equals(
+            expect=main.TRUE,
+            actual=pingResult,
+            onpass= passMsg,
+            onfail="Reactive Pingall failed, " +
+                   "one or more ping pairs failed" )
+        main.log.info( "Time for pingall: %2f seconds" %
+                       ( time2 - time1 ) )
         # timeout for fwd flows
         time.sleep( 11 )
         # uninstall onos-app-fwd
@@ -515,11 +518,6 @@
         utilities.assert_equals( expect=main.TRUE, actual=uninstallResult,
                                  onpass="Uninstall fwd successful",
                                  onfail="Uninstall fwd failed" )
-        '''
-        main.Mininet1.handle.sendline( "py [ h.cmd( \"arping -c 1 10.1.1.1 \" ) for h in net.hosts ] ")
-        import time
-        time.sleep(60)
-        '''
 
         main.step( "Check app ids" )
         threads = []
@@ -2048,10 +2046,6 @@
                                 " and ONOS"
 
         main.step( "Comparing ONOS topology to MN" )
-        devicesResults = main.TRUE
-        linksResults = main.TRUE
-        hostsResults = main.TRUE
-        hostAttachmentResults = True
         topoResult = main.FALSE
         elapsed = 0
         count = 0
@@ -2059,6 +2053,10 @@
         startTime = time.time()
         # Give time for Gossip to work
         while topoResult == main.FALSE and elapsed < 60:
+            devicesResults = main.TRUE
+            linksResults = main.TRUE
+            hostsResults = main.TRUE
+            hostAttachmentResults = True
             count += 1
             cliStart = time.time()
             devices = []
@@ -2601,49 +2599,36 @@
         main.Mininet2.stopTcpdump()
 
         testname = main.TEST
-        if main.params[ 'BACKUP' ] == "True":
+        if main.params[ 'BACKUP' ][ 'ENABLED' ] == "True":
             main.step( "Copying MN pcap and ONOS log files to test station" )
             teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ]
             teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ]
-            # NOTE: MN Pcap file is being saved to ~/packet_captures
-            #       scp this file as MN and TestON aren't necessarily the same vm
-            # FIXME: scp
-            # mn files
+            # NOTE: MN Pcap file is being saved to logdir.
+            #       We scp this file as MN and TestON aren't necessarily the same vm
+
+            # FIXME: To be replaced with a Jenkin's post script
             # TODO: Load these from params
             # NOTE: must end in /
             logFolder = "/opt/onos/log/"
             logFiles = [ "karaf.log", "karaf.log.1" ]
             # NOTE: must end in /
-            dstDir = "~/packet_captures/"
             for f in logFiles:
                 for node in main.nodes:
-                    main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address +
-                                                    ":" + logFolder + f + " " +
-                                                    teststationUser + "@" +
-                                                    teststationIP + ":" +
-                                                    dstDir + str( testname ) +
-                                                    "-" + node.name + "-" + f )
-                    main.ONOSbench.handle.expect( "\$" )
-
+                    dstName =  main.logdir + "/" + node.name + "-" + f
+                    main.ONOSbench.secureCopy( node.user_name, node.ip_address,
+                                               logFolder + f, dstName )
             # std*.log's
             # NOTE: must end in /
             logFolder = "/opt/onos/var/"
             logFiles = [ "stderr.log", "stdout.log" ]
             # NOTE: must end in /
-            dstDir = "~/packet_captures/"
             for f in logFiles:
                 for node in main.nodes:
-                    main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address +
-                                                    ":" + logFolder + f + " " +
-                                                    teststationUser + "@" +
-                                                    teststationIP + ":" +
-                                                    dstDir + str( testname ) +
-                                                    "-" + node.name + "-" + f )
-                    main.ONOSbench.handle.expect( "\$" )
-            # sleep so scp can finish
-            time.sleep( 10 )
-            main.step( "Packing and rotating pcap archives" )
-            os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
+                    dstName =  main.logdir + "/" + node.name + "-" + f
+                    main.ONOSbench.secureCopy( node.user_name, node.ip_address,
+                                               logFolder + f, dstName )
+        else:
+            main.log.debug( "skipping saving log files" )
 
         main.step( "Stopping Mininet" )
         mnResult = main.Mininet1.stopNet()
@@ -2653,9 +2638,8 @@
 
         main.step( "Checking ONOS Logs for errors" )
         for node in main.nodes:
-            print colors[ 'purple' ] + "Checking logs for errors on " + \
-                node.name + ":" + colors[ 'end' ]
-            print main.ONOSbench.checkLogs( node.ip_address )
+            main.log.debug( "Checking logs for errors on " + node.name + ":" )
+            main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
 
         try:
             timerLog = open( main.logdir + "/Timers.csv", 'w')
diff --git a/TestON/tests/HAsingleInstanceRestart/HAsingleInstanceRestart.py b/TestON/tests/HAsingleInstanceRestart/HAsingleInstanceRestart.py
index 8a86647..a2602d1 100644
--- a/TestON/tests/HAsingleInstanceRestart/HAsingleInstanceRestart.py
+++ b/TestON/tests/HAsingleInstanceRestart/HAsingleInstanceRestart.py
@@ -391,19 +391,22 @@
         # FIXME: Once we have a host discovery mechanism, use that instead
         # REACTIVE FWD test
         pingResult = main.FALSE
-        for i in range(2):  # Retry if pingall fails first time
-            time1 = time.time()
+        passMsg = "Reactive Pingall test passed"
+        time1 = time.time()
+        pingResult = main.Mininet1.pingall()
+        time2 = time.time()
+        if not pingResult:
+            main.log.warn("First pingall failed. Trying again...")
             pingResult = main.Mininet1.pingall()
-            if i == 0:
-                utilities.assert_equals(
-                    expect=main.TRUE,
-                    actual=pingResult,
-                    onpass="Reactive Pingall test passed",
-                    onfail="Reactive Pingall failed, " +
-                           "one or more ping pairs failed" )
-            time2 = time.time()
-            main.log.info( "Time for pingall: %2f seconds" %
-                           ( time2 - time1 ) )
+            passMsg += " on the second try"
+        utilities.assert_equals(
+            expect=main.TRUE,
+            actual=pingResult,
+            onpass= passMsg,
+            onfail="Reactive Pingall failed, " +
+                   "one or more ping pairs failed" )
+        main.log.info( "Time for pingall: %2f seconds" %
+                       ( time2 - time1 ) )
         # timeout for fwd flows
         time.sleep( 11 )
         # uninstall onos-app-fwd
@@ -1184,6 +1187,12 @@
         main.case( "Restart ONOS node" )
         main.caseExplanation = "Killing ONOS process and restart cli " +\
                                 "sessions once onos is up."
+
+        main.step( "Checking ONOS Logs for errors" )
+        for node in main.nodes:
+            main.log.debug( "Checking logs for errors on " + node.name + ":" )
+            main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
+
         main.step( "Killing ONOS processes" )
         killResult = main.ONOSbench.onosKill( main.nodes[0].ip_address )
         start = time.time()
@@ -1423,10 +1432,6 @@
                                 " and ONOS"
 
         main.step( "Comparing ONOS topology to MN" )
-        devicesResults = main.TRUE
-        linksResults = main.TRUE
-        hostsResults = main.TRUE
-        hostAttachmentResults = True
         topoResult = main.FALSE
         elapsed = 0
         count = 0
@@ -1434,6 +1439,10 @@
         startTime = time.time()
         # Give time for Gossip to work
         while topoResult == main.FALSE and elapsed < 60:
+            devicesResults = main.TRUE
+            linksResults = main.TRUE
+            hostsResults = main.TRUE
+            hostAttachmentResults = True
             count += 1
             cliStart = time.time()
             devices = []
@@ -1765,45 +1774,36 @@
         main.Mininet2.stopTcpdump()
 
         testname = main.TEST
-        if main.params[ 'BACKUP' ] == "True":
+        if main.params[ 'BACKUP' ][ 'ENABLED' ] == "True":
             main.step( "Copying MN pcap and ONOS log files to test station" )
             teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ]
             teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ]
-            # NOTE: MN Pcap file is being saved to ~/packet_captures
-            #       scp this file as MN and TestON aren't necessarily the same vm
-            # FIXME: scp
-            # mn files
+            # NOTE: MN Pcap file is being saved to logdir.
+            #       We scp this file as MN and TestON aren't necessarily the same vm
+
+            # FIXME: To be replaced with a Jenkin's post script
             # TODO: Load these from params
             # NOTE: must end in /
             logFolder = "/opt/onos/log/"
             logFiles = [ "karaf.log", "karaf.log.1" ]
             # NOTE: must end in /
-            dstDir = "~/packet_captures/"
             for f in logFiles:
-                main.ONOSbench.handle.sendline( "scp sdn@" + main.nodes[0].ip_address + ":" +
-                                                logFolder + f + " " +
-                                                teststationUser + "@" +
-                                                teststationIP + ":" + dstDir +
-                                                str( testname ) + "-ONOS1-" + f )
-                main.ONOSbench.handle.expect( "\$" )
-
+                for node in main.nodes:
+                    dstName =  main.logdir + "/" + node.name + "-" + f
+                    main.ONOSbench.secureCopy( node.user_name, node.ip_address,
+                                               logFolder + f, dstName )
             # std*.log's
             # NOTE: must end in /
             logFolder = "/opt/onos/var/"
             logFiles = [ "stderr.log", "stdout.log" ]
             # NOTE: must end in /
-            dstDir = "~/packet_captures/"
             for f in logFiles:
-                main.ONOSbench.handle.sendline( "scp sdn@" + main.nodes[0].ip_address + ":" +
-                                                logFolder + f + " " +
-                                                teststationUser + "@" +
-                                                teststationIP + ":" + dstDir +
-                                                str( testname ) + "-ONOS1-" + f )
-                main.ONOSbench.handle.expect( "\$" )
-            # sleep so scp can finish
-            time.sleep( 10 )
-            main.step( "Packing and rotating pcap archives" )
-            os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
+                for node in main.nodes:
+                    dstName =  main.logdir + "/" + node.name + "-" + f
+                    main.ONOSbench.secureCopy( node.user_name, node.ip_address,
+                                               logFolder + f, dstName )
+        else:
+            main.log.debug( "skipping saving log files" )
 
         main.step( "Stopping Mininet" )
         mnResult = main.Mininet1.stopNet()
@@ -1812,9 +1812,9 @@
                                  onfail="MN cleanup NOT successful" )
 
         main.step( "Checking ONOS Logs for errors" )
-        print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \
-            colors[ 'end' ]
-        print main.ONOSbench.checkLogs( main.nodes[0].ip_address, restart=True )
+        for node in main.nodes:
+            main.log.debug( "Checking logs for errors on " + node.name + ":" )
+            main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
 
         try:
             timerLog = open( main.logdir + "/Timers.csv", 'w')
diff --git a/TestON/tests/USECASE_SdnipI2/Dependency/Functions.py b/TestON/tests/USECASE_SdnipI2/Dependency/Functions.py
index 732ff41..0b860a1 100644
--- a/TestON/tests/USECASE_SdnipI2/Dependency/Functions.py
+++ b/TestON/tests/USECASE_SdnipI2/Dependency/Functions.py
@@ -39,3 +39,16 @@
         expect = intentNumExpected, actual = intentNumActual,
         onpass = "***P2P intent number is correct!***",
         onfail = "***P2P intent number is wrong!***" )
+
+def checkFlowNum( main, switch, flowNumExpected ):
+    main.step( "Check flow entry number in " + switch )
+    main.log.info( "Flow number expected:" )
+    main.log.info( flowNumExpected )
+    main.log.info( "Flow number actual:" )
+    flowNumActual = main.Mininet.getSwitchFlowCount( switch )
+    main.log.info( flowNumActual )
+    utilities.assertEquals( \
+        expect = flowNumExpected, actual = flowNumActual,
+        onpass = "***Flow number in " + switch + " is correct!***",
+        onfail = "***Flow number in " + switch + " is wrong!***" )
+
diff --git a/TestON/tests/USECASE_SdnipI2/USECASE_SdnipI2.params b/TestON/tests/USECASE_SdnipI2/USECASE_SdnipI2.params
index fd65488..0396a2b 100644
--- a/TestON/tests/USECASE_SdnipI2/USECASE_SdnipI2.params
+++ b/TestON/tests/USECASE_SdnipI2/USECASE_SdnipI2.params
@@ -1,6 +1,6 @@
 <PARAMS>
 
-    <testcases>100, 101, 102, 7, 8, 1, 4</testcases>
+    <testcases>100, 101, 102, 7, 8, 9, 10, 1, 4</testcases>
 
     #Environment variables
     <ENV>
diff --git a/TestON/tests/USECASE_SdnipI2/USECASE_SdnipI2.py b/TestON/tests/USECASE_SdnipI2/USECASE_SdnipI2.py
index c1ff688..45ea369 100644
--- a/TestON/tests/USECASE_SdnipI2/USECASE_SdnipI2.py
+++ b/TestON/tests/USECASE_SdnipI2/USECASE_SdnipI2.py
@@ -232,12 +232,20 @@
             onfail = "***MultiPointToSinglePoint Intent Num in SDN-IP is \
             wrong!***" )
 
+        main.step( "Check whether all flow status are ADDED" )
+        utilities.assertEquals( \
+            expect = main.TRUE,
+            actual = main.ONOScli.checkFlowsState( isPENDING_ADD = False ),
+            onpass = "***Flow status is correct!***",
+            onfail = "***Flow status is wrong!***" )
+
 
     def CASE4( self, main ):
         '''
         Ping test in data plane for each route
         '''
         main.case( "This case is to check ping for each route" )
+        main.step( "Start ping tests between hosts behind BGP peers" )
         result1 = main.Mininet.pingHost( src = "host64514", target = "host64515" )
         result2 = main.Mininet.pingHost( src = "host64515", target = "host64516" )
         result3 = main.Mininet.pingHost( src = "host64514", target = "host64516" )
@@ -291,6 +299,13 @@
             main.log.info( "Bring down link failed!!!" )
             main.exit();
 
+        main.step( "Check whether all flow status are ADDED" )
+        utilities.assertEquals( \
+            expect = main.TRUE,
+            actual = main.ONOScli.checkFlowsState( isPENDING_ADD = False ),
+            onpass = "***Flow status is correct!***",
+            onfail = "***Flow status is wrong!***" )
+
 
     def CASE6(self, main):
         '''
@@ -330,6 +345,13 @@
         else:
             main.log.info( "Bring up link failed!!!" )
             main.exit();
+
+        main.step( "Check whether all flow status are ADDED" )
+        utilities.assertEquals( \
+            expect = main.TRUE,
+            actual = main.ONOScli.checkFlowsState( isPENDING_ADD = False ),
+            onpass = "***Flow status is correct!***",
+            onfail = "***Flow status is wrong!***" )
         '''
         Note: at the end of this test case, we should carry out ping test.
         So we run CASE4 again after CASE6
@@ -354,6 +376,13 @@
             main.log.info( "Stop switch failed!!!" )
             main.exit();
 
+        main.step( "Check whether all flow status are ADDED" )
+        utilities.assertEquals( \
+            expect = main.TRUE,
+            actual = main.ONOScli.checkFlowsState( isPENDING_ADD = False ),
+            onpass = "***Flow status is correct!***",
+            onfail = "***Flow status is wrong!***" )
+
         '''
         main.step( "Stop sw8" )
         result = main.Mininet.switch( SW = "sw8", OPTION = "stop" )
@@ -407,12 +436,99 @@
             main.cleanup()
             main.exit();
 
+        main.step( "Check whether all flow status are ADDED" )
+        utilities.assertEquals( \
+            expect = main.TRUE,
+            actual = main.ONOScli.checkFlowsState( isPENDING_ADD = False ),
+            onpass = "***Flow status is correct!***",
+            onfail = "***Flow status is wrong!***" )
+
+
+    def CASE9(self, main):
+        '''
+        Bring down a switch in best path, check:
+        route number, P2P intent number, M2S intent number, ping test
+        '''
+        main.case( "This case is to stop switch in best path, \
+        check route number, P2P intent number, M2S intent number, ping test" )
+
+        main.step( "Check the flow status before stopping sw11" )
+        main.Functions.checkFlowNum( main, "sw11", 13 )
+        main.Functions.checkFlowNum( main, "sw1", 3 )
+        main.Functions.checkFlowNum( main, "sw7", 3 )
+        main.log.info( main.Mininet.checkFlows( "sw11" ) )
+        main.log.info( main.Mininet.checkFlows( "sw1" ) )
+        main.log.info( main.Mininet.checkFlows( "sw7" ) )
+
+        main.step( "Stop sw11" )
+        result = main.Mininet.switch( SW = "sw11", OPTION = "stop" )
+        if result:
+            time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
+            main.Functions.checkRouteNum( main, 3 )
+            main.Functions.checkM2SintentNum( main, 3 )
+            main.Functions.checkP2PintentNum( main, 18 )
+
+        else:
+            main.log.info( "Stop switch failed!!!" )
+            main.cleanup()
+            main.exit();
+
+        main.step( "Check whether all flow status are ADDED" )
+        utilities.assertEquals( \
+            expect = main.TRUE,
+            actual = main.ONOScli.checkFlowsState( isPENDING_ADD = False ),
+            onpass = "***Flow status is correct!***",
+            onfail = "***Flow status is wrong!***" )
+        '''
+        Note: this test case should be followed by ping test, CASE1 and CASE4
+        '''
+
+
+    def CASE10( self, main ):
+        '''
+        Bring up the switch which was stopped in CASE9, check:
+        route number, P2P intent number, M2S intent number, ping test
+        '''
+        main.case( "This case is to start switch which was stopped in CASE9, \
+        check route number, P2P intent number, M2S intent number, ping test" )
+        main.step( "Start sw11" )
+        result = main.Mininet.switch( SW = "sw11", OPTION = "start" )
+        if result:
+            time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
+            main.Functions.checkRouteNum( main, 3 )
+            main.Functions.checkM2SintentNum( main, 3 )
+            main.Functions.checkP2PintentNum( main, 18 )
+
+            main.step( "Check the flow status after stop and start sw11" )
+            main.Functions.checkFlowNum( main, "sw11", 3 )
+            main.Functions.checkFlowNum( main, "sw1", 11 )
+            main.Functions.checkFlowNum( main, "sw7", 5 )
+            main.log.info( main.Mininet.checkFlows( "sw11" ) )
+            main.log.info( main.Mininet.checkFlows( "sw1" ) )
+            main.log.info( main.Mininet.checkFlows( "sw7" ) )
+        else:
+            main.log.info( "Start switch failed!!!" )
+            main.cleanup()
+            main.exit();
+
+        main.step( "Check whether all flow status are ADDED" )
+        utilities.assertEquals( \
+            expect = main.TRUE,
+            actual = main.ONOScli.checkFlowsState( isPENDING_ADD = False ),
+            onpass = "***Flow status is correct!***",
+            onfail = "***Flow status is wrong!***" )
+        '''
+        Note: this test case should be followed by ping test, CASE1 and CASE4
+        '''
+
 
     def CASE20( self, main ):
         '''
         ping test from 3 bgp peers to BGP speaker
         '''
-        main.case( "This case is to check ping between BGP peers and speakers" )
+        main.case( "This case is to check ping between BGP peers and speakers, \
+        and expect all ping tests to fail." )
+        main.step( "Start ping tests between BGP speaker and BGP peers" )
         result1 = main.Mininet.pingHost( src = "speaker1", target = "peer64514" )
         result2 = main.Mininet.pingHost( src = "speaker1", target = "peer64515" )
         result3 = main.Mininet.pingHost( src = "speaker1", target = "peer64516" )
@@ -432,7 +548,9 @@
         '''
         Ping test in data plane for each route
         '''
-        main.case( "This case is to check ping for each route" )
+        main.case( "This case is to check ping for each route, and expect \
+        all ping tests to fail." )
+        main.step( "Start ping tests between hosts behind BGP peers" )
         result1 = main.Mininet.pingHost( src = "host64514", target = "host64515" )
         result2 = main.Mininet.pingHost( src = "host64515", target = "host64516" )
         result3 = main.Mininet.pingHost( src = "host64514", target = "host64516" )