Dumping flows on each test now

Change-Id: Iec628582c76b287868d7ee405dbed128d93cc3fe
diff --git a/TestON/tests/USECASE/USECASE_SegmentRouting/README.md b/TestON/tests/USECASE/USECASE_SegmentRouting/README.md
index da75079..8240068 100644
--- a/TestON/tests/USECASE/USECASE_SegmentRouting/README.md
+++ b/TestON/tests/USECASE/USECASE_SegmentRouting/README.md
@@ -1,18 +1,33 @@
-This test is designed to verify basic connectivity the SegmentRouting application.
+This test is designed to verify basic connectivity the SegmentRouting application via pingaall.
 
 It consists of 
 
-1) Installing and Starting ONOS
-2) Starting Mininet and testing connectivity
+1) Configure and Install ONOS
+2) Start Mininet and check flow state
+2) Test connectivity
 
 Requirements
 
- - A single ONOS instance is required for the test, the application is currently not stable in a cluster.
+ - A single ONOS instance is required for the test, the application is currently not stable in a cluster as of today.
  - An updated version of the CPQD switch has to be running to make sure it supports group chaining.
 
 Step 1:
-In this step we copy the proper config file to ONOS, next we package ONOS and install it in the target machine.
+In this step, we copy config file to ONOS, next we package ONOS and install it in the target machine.
 
 Step 2:
 
-In this step we start a 2x2 leaf-spine topology, connect to ONOS, and next we send several pings between hosts to test connectivity.
+In this step we start the topology, connect to ONOS
+
+Step:3
+
+Here, we send several pings between hosts to test connectivity.
+
+Then Steps are repeated for different configurations and topologies.
+
+    Configurations:
+     1) APPS=openflow-base,netcfghostprovider,netcfglinksprovider
+     2) APPS=openflow
+
+    Topologies:
+     1) 2x2 Leaf-Spine
+     2) 4x4 Leaf-Spine
diff --git a/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.params b/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.params
index eb55d5f..1ef9eea 100755
--- a/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.params
+++ b/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.params
@@ -1,6 +1,6 @@
 <PARAMS>
 
-    <testcases>1,2,11,9,2,11,9,2,11,9,2,11,9</testcases>
+    <testcases>1,[2,3,4,10]*4</testcases>
 
     <SCALE>
         <size>1</size>
diff --git a/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.py b/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.py
index 7eb4dd7..0057a10 100644
--- a/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.py
+++ b/TestON/tests/USECASE/USECASE_SegmentRouting/USECASE_SegmentRouting.py
@@ -127,7 +127,7 @@
         for i in range( main.numCtrls ):
             tempOnosIp.append( main.ONOSip[i] )
         onosUser = main.params[ 'ENV' ][ 'cellUser' ]
-        main.step("Creating cell file")
+        main.step("Create and Apply cell file")
         main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
                                        "temp",
                                        main.Mininet1.ip_address,
@@ -135,7 +135,6 @@
                                        tempOnosIp,
                                        onosUser )
 
-        main.step( "Apply cell to environment" )
         cellResult = main.ONOSbench.setCell( "temp" )
         verifyResult = main.ONOSbench.verifyCell()
         stepResult = cellResult and verifyResult
@@ -145,7 +144,7 @@
                                         "environment",
                                  onfail="Failed to apply cell to environment " )
 
-        main.step( "Creating ONOS package" )
+        main.step( "Create and Install ONOS package" )
         main.jsonFile=main.json.pop(0)
         main.ONOSbench.handle.sendline( "cp "+main.path+"/"+main.jsonFile+".json ~/onos/tools/package/config/network-cfg.json")
         packageResult = main.ONOSbench.onosPackage()
@@ -155,9 +154,8 @@
         #                         onpass="Successfully created ONOS package",
         #                         onfail="Failed to create ONOS package" )
 
-        time.sleep( main.startUpSleep )
+        #time.sleep( main.startUpSleep )
 
-        main.step( "Installing ONOS package" )
         onosInstallResult = main.TRUE
         for i in range( main.numCtrls ):
             onosInstallResult = onosInstallResult and \
@@ -187,13 +185,38 @@
                 startResult = startResult and \
                         main.ONOSbench.onosStart( main.ONOSip[ i ] )
         stepResult = onosIsUp and stopResult and startResult
+
         utilities.assert_equals( expect=main.TRUE,
                                  actual=stepResult,
                                  onpass="ONOS service is ready",
                                  onfail="ONOS service did not start properly" )
-        time.sleep( 2*main.startUpSleep )
+        #time.sleep( 2*main.startUpSleep )
+        main.ONOSbench.handle.sendline( "onos-secure-ssh")
+        main.step( "Checking if ONOS CLI is ready" )
+        cliResult = main.CLIs[0].startOnosCli( main.ONOSip[ 0 ],
+                                           commandlineTimeout=100, onosStartTimeout=600 )
+        utilities.assert_equals( expect=main.TRUE,
+                             actual=cliResult,
+                             onpass="ONOS CLI is ready",
+                             onfail="ONOS CLI is not ready" )
+        for i in range( 10 ):
+            ready = True
+            output = main.CLIs[0].summary()
+            if not output:
+                ready = False
+            if ready:
+                break
+            time.sleep( 10 )
+        utilities.assert_equals( expect=True, actual=ready,
+                                 onpass="ONOS summary command succeded",
+                                 onfail="ONOS summary command failed" )
 
-    def CASE9( self, main ):
+        if not ready:
+            main.log.error( "ONOS startup failed!" )
+            main.cleanup()
+            main.exit()
+
+    def CASE10( self, main ):
         '''
             Report errors/warnings/exceptions
         '''
@@ -214,7 +237,7 @@
                                     "Except" ],
                                   "s" )
 
-    def CASE11( self, main ):
+    def CASE3( self, main ):
         """
             Start mininet
         """
@@ -240,13 +263,44 @@
         if not topoResult:
             main.cleanup()
             main.exit()
-        main.step("Waiting for switch initialization and configuration")
-        time.sleep( 3*main.startUpSleep)
+        #main.step("Waiting for switch initialization and configuration")
+        main.step(" Check whether the flow count is bigger than 80" )
+        count =  utilities.retry( main.CLIs[0].checkFlowCount,
+                                 main.FALSE,
+                                 kwargs={'min':80},
+                                 attempts=10 )
+        utilities.assertEquals( \
+            expect=True,
+            actual=(count>0),
+            onpass="Flow count looks correct: "+str(count),
+            onfail="Flow count looks wrong: "+str(count) )
+
+        main.step( "Check whether all flow status are ADDED" )
+        flowCheck = utilities.retry( main.CLIs[0].checkFlowsState,
+                                 main.FALSE,
+                                 kwargs={'isPENDING':False},
+                                 attempts=10 )
+        utilities.assertEquals( \
+            expect=main.TRUE,
+            actual=flowCheck,
+            onpass="Flow status is correct!",
+            onfail="Flow status is wrong!" )
+        main.ONOSbench.dumpFlows( main.ONOSip[0],
+                 main.logdir, "flows" + main.jsonFile)
+        #time.sleep( 3*main.startUpSleep)
+
+    def CASE4( self, main ):
+        main.case( "Check full connectivity" )
+        main.log.report( "Check full connectivity" )
+
+        main.step("Check full connectivity")
         pa = main.Mininet1.pingall()
         utilities.assert_equals( expect=main.TRUE, actual=pa,
                                  onpass="Full connectivity successfully tested",
                                  onfail="Full connectivity failed" )
         # cleanup mininet
+        main.ONOSbench.dumpFlows( main.ONOSip[0],
+                 main.logdir, "flows" + main.jsonFile)
         main.ONOSbench.onosStop( main.ONOSip[0] )
         main.Mininet1.stopNet()