[VOL-3092] Validating flows in VOLTHA physical device

Change-Id: I8448159564aa96887476ba2bfa8030d55ff1891b
diff --git a/libraries/flows.robot b/libraries/flows.robot
index 678270a..8e15939 100644
--- a/libraries/flows.robot
+++ b/libraries/flows.robot
@@ -59,11 +59,11 @@
     ${flow_count}=  Run Keyword If  $provisioned=='false'
     ...     Evaluate    (${uni_count} * ${eapFlowsCount}) + (${olt_count} * 2)
     ...     ELSE
-    ...     Calculate Att Provisione Flows  ${olt_count}    ${uni_count}
+    ...     Calculate Att Provisioned Flows  ${olt_count}    ${uni_count}
     ...     ${eapFlowsCount}   ${dhcpFlowsCount}   ${igmpFlowsCount}
     Return From Keyword     ${flow_count}
 
-Calculate Att Provisione Flows
+Calculate Att Provisioned Flows
     [Documentation]  This calculate the flows for provisioned subscribers in the ATT workflow
     [Arguments]  ${olt_count}   ${uni_count}    ${eapFlowsCount}   ${dhcpFlowsCount}   ${igmpFlowsCount}
     ${eap}=     Evaluate    ${uni_count} * ${eapFlowsCount}
diff --git a/libraries/voltctl.robot b/libraries/voltctl.robot
index 0d51b0e..33f5247 100644
--- a/libraries/voltctl.robot
+++ b/libraries/voltctl.robot
@@ -142,6 +142,15 @@
     Log    ${devices}
     Should Be Equal As Integers    ${rc1}    0
 
+Get Device List from Voltha by type
+    [Documentation]    Gets Device List Output from Voltha applying filtering by device type
+    [Arguments]  ${type}
+    ${rc1}    ${devices}=    Run and Return Rc and Output
+    ...     ${VOLTCTL_CONFIG}; voltctl device list -f Type=${type} -o json
+    Log    ${devices}
+    Should Be Equal As Integers    ${rc1}    0
+    Return From Keyword     ${devices}
+
 Get Logical Device List from Voltha
     [Documentation]    Gets Logical Device List Output from Voltha (in json format)
     ${rc1}    ${devices}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG}; voltctl logicaldevice list -o json
@@ -482,6 +491,9 @@
         Should Be Equal As Integers    ${rc}    0
         ${total_flows}=     Evaluate    ${total_flows} + ${flows}
     END
+    ${msg}=     Format String   Found {total_flows} flows of {targetFlows} expected
+    ...     total_flows=${total_flows}  targetFlows=${targetFlows}
+    Log     ${msg}
     Should Be Equal As Integers    ${targetFlows}    ${total_flows}
 
 Wait for Logical Devices flows
@@ -494,3 +506,30 @@
     # TODO extend Validate Logical Device Flows to check the correct number of flows
     Wait Until Keyword Succeeds     10m     5s  Count Logical Devices flows     ${targetFlows}
 
+Count OpenOLT Device Flows
+    [Documentation]  Count the flows across openolt devices in VOLTHA
+    [Arguments]  ${targetFlows}
+    ${output}=     Get Device List from Voltha by type      openolt
+    ${devices}=    To Json    ${output}
+    ${total_flows}=     Set Variable    0
+    FOR     ${device}   IN  @{devices}
+        ${rc}    ${flows}=    Run and Return Rc and Output
+        ...     ${VOLTCTL_CONFIG}; voltctl device flows ${device['id']} | grep -v ID | wc -l
+        Should Be Equal As Integers    ${rc}    0
+        ${total_flows}=     Evaluate    ${total_flows} + ${flows}
+    END
+    ${msg}=     Format String   Found {total_flows} flows of {targetFlows} expected
+    ...     total_flows=${total_flows}  targetFlows=${targetFlows}
+    Log     ${msg}
+    Should Be Equal As Integers    ${targetFlows}    ${total_flows}
+
+Wait for OpenOLT Devices flows
+    [Documentation]  Waits until the flows have been provisioned in the openolt devices
+    [Arguments]  ${workflow}    ${uni_count}    ${olt_count}    ${provisioned}
+    ...     ${withEapol}    ${withDhcp}     ${withIgmp}
+    ${targetFlows}=     Calculate flows by workflow     ${workflow}    ${uni_count}    ${olt_count}     ${provisioned}
+    ...     ${withEapol}    ${withDhcp}     ${withIgmp}
+    # In the physical device we only have 2 data plane flows (on the PON) instead of 4
+    ${targetFlows}=     Evaluate    ${targetFlows} - (${uni_count} * 2)
+    Log     ${targetFlows}
+    Wait Until Keyword Succeeds     10m     5s  Count OpenOLT Device Flows     ${targetFlows}
\ No newline at end of file
diff --git a/tests/scale/Voltha_Scale_Tests.robot b/tests/scale/Voltha_Scale_Tests.robot
index c5b530c..76708ea 100644
--- a/tests/scale/Voltha_Scale_Tests.robot
+++ b/tests/scale/Voltha_Scale_Tests.robot
@@ -106,6 +106,13 @@
     Wait for Logical Devices flows   ${workflow}    ${total_onus}    ${olt}    false
     ...     ${withEapol}    ${withDhcp}     ${withIgmp}
 
+Flows validation in VOLTHA Adapters before subscriber provisioning
+    [Documentation]  Check that all flows has been store in devices of type openolt
+    [Tags]      non-critical    flow-before   plot-voltha-openolt-flows-before
+    Should Be Equal   ${enableFlowProvisioning}     true
+    Wait for OpenOLT Devices flows   ${workflow}    ${total_onus}    ${olt}    false
+    ...     ${withEapol}    ${withDhcp}     ${withIgmp}
+
 Flows validation in ONOS before subscriber provisioning
     [Documentation]    Check that all the flows has been acknowledged
     [Tags]      non-critical    flow-before   plot-onos-flows-before
@@ -136,6 +143,13 @@
     Wait for Logical Devices flows   ${workflow}    ${total_onus}    ${olt}    true
     ...     ${withEapol}    ${withDhcp}     ${withIgmp}
 
+Flows validation in VOLTHA Adapters after subscriber provisioning
+    [Documentation]  Check that all flows has been store in devices of type openolt
+    [Tags]      non-critical    flow-after   plot-voltha-openolt-flows-after
+    Should Be Equal   ${enableFlowProvisioning}     true
+    Wait for OpenOLT Devices flows   ${workflow}    ${total_onus}    ${olt}    true
+    ...     ${withEapol}    ${withDhcp}     ${withIgmp}
+
 Flows validation in ONOS after subscriber provisioning
     [Documentation]    Check that all the flows has been acknowledged
     [Tags]      non-critical    flow-after    plot-onos-flows-after