Merge "Fix a bug of totalFlows is -1 beacuse timeout     - Use REST API to get total ADDED flows"
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index 74ba41f..fad5ce5 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -2203,12 +2203,44 @@
         Return:
             The number of ADDED flows
         """
+
         try:
+            # get total added flows number
             cmd = "flows -s|grep ADDED|wc -l"
-            response = self.sendline( cmd, timeout=timeout )
-            if response == None:
-                return  -1
-            return int( response )
+            totalFlows = self.sendline( cmd, timeout=timeout )
+
+            if totalFlows == None:
+                # if timeout, we will get total number of all flows, and subtract other states
+                states = ["PENDING_ADD", "PENDING_REMOVE", "REMOVED", "FAILED"]
+                checkedStates = []
+                totalFlows = 0
+                statesCount = [0, 0, 0, 0]
+
+                # get total flows from summary
+                response = json.loads( self.sendline( "summary -j", timeout=timeout ) )
+                totalFlows = int( response.get("flows") )
+
+                for s in states:
+                    rawFlows = self.flows( state=s, timeout = timeout )
+                    if rawFlows == None:
+                        # if timeout, return the total flows number from summary command
+                        return totalFlows
+                    checkedStates.append( json.loads( rawFlows ) )
+
+                # Calculate ADDED flows number, equal total subtracts others
+                for i in range( len( states ) ):
+                    for c in checkedStates[i]:
+                        try:
+                            statesCount[i] += int( c.get( "flowCount" ) )
+                        except TypeError:
+                            main.log.exception( "Json object not as expected" )
+                    totalFlows = totalFlows - int( statesCount[i] )
+                    main.log.info( states[i] + " flows: " + str( statesCount[i] ) )
+
+                return totalFlows
+
+            return totalFlows
+
         except TypeError:
             main.log.exception( self.name + ": Object not as expected" )
             return None
diff --git a/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.params b/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.params
index 2324185..1871979 100755
--- a/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.params
+++ b/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.params
@@ -66,17 +66,17 @@
         # CASE20
         <PUSH>
             <batch_size>1000</batch_size>
-            <min_intents>10000</min_intents>
+            <min_intents>100000</min_intents>
             <max_intents>1000000</max_intents>
-            <check_interval>10000</check_interval>
+            <check_interval>100000</check_interval>
         </PUSH>
 
         # if reroute is true
         <REROUTE>
             <batch_size>1000</batch_size>
             <min_intents>10000</min_intents>
-            <max_intents>1000000</max_intents>
-            <check_interval>100000</check_interval>
+            <max_intents>10000</max_intents>
+            <check_interval>10000</check_interval>
         </REROUTE>
     </NULL>
 
diff --git a/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.py b/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.py
index c543d8c..4bca4da 100644
--- a/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.py
+++ b/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.py
@@ -476,7 +476,12 @@
                                  onpass = "Successfully pushed and verified intents",
                                  onfail = "Failed to push and verify intents" )
         currIntents = main.ONOScli1.getTotalIntentsNum()
-        currFlows = main.ONOScli1.getTotalFlowsNum( timeout = main.timeout )
+        currFlows = 0
+        # Get current flows from REST API
+        temp = json.loads( main.ONOSrest1.flows() )
+        for t in temp:
+            if t.get("state") == "ADDED":
+                currFlows = currFlows + 1
         main.log.info( "Total Intents Installed: {}".format( currIntents ) )
         main.log.info( "Total Flows ADDED: {}".format( currFlows ) )
 
diff --git a/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.topo b/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.topo
index f34ed12..f2fbc0a 100755
--- a/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.topo
+++ b/TestON/tests/SCPFmaxIntents/SCPFmaxIntents.topo
@@ -21,6 +21,17 @@
             </COMPONENTS>
         </ONOScli1>
 
+        <ONOSrest1>
+            <host>OC1</host>
+            <port>8181</port>
+            <user>onos</user>
+            <password>rocks</password>
+            <type>OnosRestDriver</type>
+            <connect_order>3</connect_order>
+            <COMPONENTS>
+            </COMPONENTS>
+        </ONOSrest1>
+
         <Mininet1>
             <host>localhost</host>
             <user>admin</user>