[VOL-3638] Multistack
- Checking ports on a per-device base
- Checking flows before provisioning on a per-device base
- Checking authenticated subscribers on a per-device base
- Checking flows after provisioning on a per-device base
- Checking subscribers IP on a per-device base

Change-Id: I9e44c32183e6fa91ac8692aff9cd7bc2cf680ba5
diff --git a/libraries/onos.robot b/libraries/onos.robot
index 77f4091..7368e8c 100755
--- a/libraries/onos.robot
+++ b/libraries/onos.robot
@@ -40,7 +40,7 @@
     @{result_values}    SSHLibrary.Execute Command    ${cmd}    return_rc=True
     ...    return_stderr=True    return_stdout=True
     ${output}    Set Variable    @{result_values}[0]
-    Log    ${output}
+    Log    Command output: ${output}
     Should Be Empty    @{result_values}[1]
     Should Be Equal As Integers    @{result_values}[2]    0
     [Return]    ${output}
@@ -382,20 +382,22 @@
     Should Not Be Empty    ${aaa_users}    ONU port ${onu_port} not found in aaa-users
 
 Assert Number of AAA-Users
-    [Arguments]    ${onos_ssh_connection}    ${expected_onus}
+    [Arguments]    ${onos_ssh_connection}    ${expected_onus}   ${deviceId}
     [Documentation]    Matches for number of aaa-users authorized based on number of onus
     ${aaa_users}=    Execute ONOS CLI Command on open connection     ${onos_ssh_connection}
-    ...     aaa-users | grep AUTHORIZED | wc -l
+    ...     aaa-users | grep ${deviceId} | grep AUTHORIZED | wc -l
+    Log     Found ${aaa_users} of ${expected_onus} expected authenticated users on device ${deviceId}
     Should Be Equal As Integers    ${aaa_users}    ${expected_onus}
 
 Validate DHCP Allocations
-    [Arguments]    ${onos_ssh_connection}    ${count}   ${workflow}
+    [Arguments]    ${onos_ssh_connection}    ${count}   ${workflow}     ${deviceId}
     [Documentation]    Matches for number of dhcpacks based on number of onus
     ${allocations}=    Execute ONOS CLI Command on open connection     ${onos_ssh_connection}
-    ...     dhcpl2relay-allocations | grep DHCPACK | wc -l
+    ...     dhcpl2relay-allocations | grep ${deviceId} | grep DHCPACK | wc -l
     # if the workflow is TT we'll have 2 allocations for each ONU
     ${ttAllocations}=     Evaluate   (${count} * 2)
     ${count}=    Set Variable If  $workflow=='tt'    ${ttAllocations}   ${count}
+    Log     Found ${allocations} of ${count} expected DHCPACK on device ${deviceId}
     Should Be Equal As Integers    ${allocations}    ${count}
 
 Validate Subscriber DHCP Allocation
@@ -431,28 +433,30 @@
     END
 
 Assert Ports in ONOS
-    [Arguments]    ${onos_ssh_connection}     ${count}     ${filter}
+    [Arguments]    ${onos_ssh_connection}     ${count}     ${deviceId}  ${filter}
     [Documentation]    Check that a certain number of ports are enabled in ONOS
     ${ports}=    Execute ONOS CLI Command on open connection     ${onos_ssh_connection}
-        ...    ports -e | grep ${filter} | wc -l
+        ...    ports -e ${deviceId} | grep ${filter} | wc -l
+    Log     Found ${ports} of ${count} expected ports on device ${deviceId}
     Should Be Equal As Integers    ${ports}    ${count}
 
 Wait for Ports in ONOS
-    [Arguments]    ${onos_ssh_connection}     ${count}     ${filter}
-    [Documentation]    Waits untill a certain number of ports are enabled in ONOS
+    [Arguments]    ${onos_ssh_connection}     ${count}     ${deviceId}  ${filter}
+    [Documentation]    Waits untill a certain number of ports are enabled in ONOS for a particular deviceId
     Wait Until Keyword Succeeds     10m     5s      Assert Ports in ONOS
-    ...     ${onos_ssh_connection}     ${count}     ${filter}
+    ...     ${onos_ssh_connection}     ${count}     ${deviceId}     ${filter}
 
 Wait for AAA Authentication
-    [Arguments]    ${onos_ssh_connection}     ${count}
+    [Arguments]    ${onos_ssh_connection}     ${count}  ${deviceId}
     [Documentation]    Waits untill a certain number of subscribers are authenticated in ONOS
-    Wait Until Keyword Succeeds     10m     5s      Assert Number of AAA-Users      ${onos_ssh_connection}     ${count}
+    Wait Until Keyword Succeeds     10m     5s      Assert Number of AAA-Users
+    ...     ${onos_ssh_connection}     ${count}     ${deviceId}
 
 Wait for DHCP Ack
-    [Arguments]    ${onos_ssh_connection}     ${count}  ${workflow}
+    [Arguments]    ${onos_ssh_connection}     ${count}  ${workflow}     ${deviceId}
     [Documentation]    Waits untill a certain number of subscribers have received a DHCP_ACK
     Wait Until Keyword Succeeds     10m     5s      Validate DHCP Allocations
-        ...     ${onos_ssh_connection}     ${count}  ${workflow}
+        ...     ${onos_ssh_connection}     ${count}  ${workflow}    ${deviceId}
 
 Provision subscriber
     [Documentation]  Calls volt-add-subscriber-access in ONOS
@@ -496,7 +500,8 @@
     END
 
 List OLTs
-    [Documentation]  Returns a list of OLTs known to ONOS
+    # NOTE this method is not currently used but it can come useful in the future
+    [Documentation]  Returns a list of all OLTs known to ONOS
     [Arguments]  ${onos_ssh_connection}
     [Return]  ['of:00000a0a0a0a0a00', 'of:00000a0a0a0a0a01']
     ${result}=      Create List
@@ -515,19 +520,20 @@
 
 Count ADDED flows
     [Documentation]  Count the flows in ADDED state in ONOS
-    [Arguments]  ${onos_ssh_connection}    ${targetFlows}
+    [Arguments]  ${onos_ssh_connection}    ${targetFlows}   ${deviceId}
     ${flows}=    Execute ONOS CLI Command on open connection     ${onos_ssh_connection}
-    ...     flows -s | grep ADDED | wc -l
+    ...     flows -s any ${deviceId} | grep ADDED | wc -l
+    Log     Found ${flows} of ${targetFlows} expected flows on device ${deviceId}
     Should Be Equal As Integers    ${targetFlows}    ${flows}
 
 Wait for all flows to in ADDED state
     [Documentation]  Waits until the flows have been provisioned
-    [Arguments]  ${onos_ssh_connection}     ${workflow}    ${uni_count}    ${olt_count}    ${provisioned}
+    [Arguments]  ${onos_ssh_connection}     ${deviceId}     ${workflow}    ${uni_count}    ${olt_count}    ${provisioned}
     ...     ${withEapol}    ${withDhcp}     ${withIgmp}     ${withLldp}
     ${targetFlows}=     Calculate flows by workflow     ${workflow}    ${uni_count}    ${olt_count}     ${provisioned}
     ...     ${withEapol}    ${withDhcp}     ${withIgmp}     ${withLldp}
     Wait Until Keyword Succeeds     10m     5s      Count ADDED flows
-    ...     ${onos_ssh_connection}  ${targetFlows}
+    ...     ${onos_ssh_connection}  ${targetFlows}  ${deviceId}
 
 Get Bandwidth Details
     [Arguments]    ${bandwidth_profile_name}
diff --git a/tests/scale/Voltha_Scale_Tests.robot b/tests/scale/Voltha_Scale_Tests.robot
index 1d5c849..333f4a0 100644
--- a/tests/scale/Voltha_Scale_Tests.robot
+++ b/tests/scale/Voltha_Scale_Tests.robot
@@ -58,6 +58,7 @@
 ${ONOS_REST_PORT}    8181
 
 # Scale pipeline values
+${stackId}  1
 ${olt}  1
 ${pon}  1
 ${onu}  1
@@ -97,7 +98,10 @@
 Port Discovery in ONOS
     [Documentation]    Check that all the UNI ports show up in ONOS
     [Tags]      non-critical    activation    plot-onos-ports
-    Wait for Ports in ONOS      ${onos_ssh_connection}  ${total_onus}   BBSM
+    ${onos_devices}=    Compute Device IDs
+    FOR     ${deviceId}     IN  @{onos_devices}
+        Wait for Ports in ONOS      ${onos_ssh_connection}  ${total_onus_per_olt}   ${deviceId}     BBSM
+    END
 
 Flows validation in VOLTHA before subscriber provisioning
     [Documentation]    Check that all the flows has been stored in the logical device
@@ -119,21 +123,29 @@
     [Tags]      non-critical    flow-before   plot-onos-flows-before
     # NOTE fail the test immediately if we're trying to check flows without provisioning them
     Should Be Equal   ${enableFlowProvisioning}     true
-    Wait for all flows to in ADDED state    ${onos_ssh_connection}
-    ...     ${workflow}    ${total_onus}    ${olt}    false     ${withEapol}    ${withDhcp}
-    ...     ${withIgmp}   ${withLLDP}
+
+    ${onos_devices}=    Compute Device IDs
+    FOR     ${deviceId}     IN  @{onos_devices}
+        Wait for all flows to in ADDED state    ${onos_ssh_connection}
+        ...     ${deviceId}     ${workflow}    ${total_onus_per_olt}    1    false
+        ...     ${withEapol}    ${withDhcp}     ${withIgmp}   ${withLLDP}
+    END
 
 Wait for subscribers to be Authenticated
     [Documentation]    Check that all subscribers have successfully authenticated
     [Tags]      non-critical    authentication    plot-onos-auth
-    Wait for AAA Authentication     ${onos_ssh_connection}  ${total_onus}
+
+    ${onos_devices}=    Compute Device IDs
+    FOR     ${deviceId}     IN  @{onos_devices}
+        Wait for AAA Authentication     ${onos_ssh_connection}  ${total_onus_per_olt}   ${deviceId}
+    END
 
 Provision subscribers
     [Documentation]    Provision data plane flows for all the subscribers
     [Tags]      non-critical    provision
     Should Be Equal   ${enableSubscriberProvisioning}     true
-    ${olts}=    List OLTs   ${onos_ssh_connection}
-    FOR     ${olt}  IN  @{olts}
+    ${onos_devices}=    Compute Device IDs
+    FOR     ${olt}  IN  @{onos_devices}
         Provision all subscribers on device  ${onos_ssh_connection}     ${ONOS_SSH_IP}     ${ONOS_REST_PORT}  ${olt}
     END
 
@@ -142,6 +154,7 @@
     [Tags]      non-critical    flow-after    plot-voltha-flows-after
     # NOTE fail the test immediately if we're trying to check flows without provisioning them
     Should Be Equal   ${enableFlowProvisioning}     true
+
     Wait for Logical Devices flows   ${workflow}    ${total_onus}    ${olt}    true
     ...     ${withEapol}    ${withDhcp}     ${withIgmp}    ${withLLDP}
 
@@ -157,14 +170,21 @@
     [Tags]      non-critical    flow-after    plot-onos-flows-after
     # NOTE fail the test immediately if we're trying to check flows without provisioning them
     Should Be Equal   ${enableFlowProvisioning}     true
-    Wait for all flows to in ADDED state    ${onos_ssh_connection}
-    ...     ${workflow}    ${total_onus}    ${olt}    true      ${withEapol}    ${withDhcp}
-    ...     ${withIgmp}   ${withLLDP}
+
+    ${onos_devices}=    Compute Device IDs
+    FOR     ${deviceId}     IN  @{onos_devices}
+        Wait for all flows to in ADDED state    ${onos_ssh_connection}
+        ...     ${deviceId}     ${workflow}    ${total_onus_per_olt}    1    true
+        ...     ${withEapol}    ${withDhcp}     ${withIgmp}   ${withLLDP}
+    END
 
 Wait for subscribers to have an IP
     [Documentation]    Check that all subscribers have received a DHCP_ACK
     [Tags]      non-critical    dhcp  plot-onos-dhcp
-    Wait for DHCP Ack     ${onos_ssh_connection}  ${total_onus}     ${workflow}
+    ${onos_devices}=    Compute Device IDs
+    FOR     ${deviceId}     IN  @{onos_devices}
+        Wait for DHCP Ack     ${onos_ssh_connection}  ${total_onus_per_olt}     ${workflow}     ${deviceId}
+    END
 
 Disable and Delete devices
     [Documentation]  Disable and delete the OLTs in VOLTHA
@@ -186,9 +206,26 @@
     ${total_onus}=   Evaluate    ${olt} * ${pon} * ${onu}
     Set Suite Variable  ${total_onus}
 
+    ${total_onus_per_olt}=   Evaluate    ${pon} * ${onu}
+    Set Suite Variable  ${total_onus_per_olt}
+
     ${onos_ssh_connection}    Open ONOS SSH Connection    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}
     Set Suite Variable  ${onos_ssh_connection}
 
 Teardown Suite
    [Documentation]    Close the SSH connection to ONOS
-    Close ONOS SSH Connection   ${onos_ssh_connection}
\ No newline at end of file
+    Close ONOS SSH Connection   ${onos_ssh_connection}
+
+Compute device IDs
+    [Documentation]  Creates a list of ONOS device ID based on the test configuration
+    # TODO read ${olt} and ${stackid} from parameters
+    ${base}=    Set Variable    of:00000a0a0a0a0a
+    ${device_ids}=      Create List
+    FOR    ${olt_id}    IN RANGE    0    ${olt}
+        ${decimal_id}=  Catenate    SEPARATOR=  ${stackid}  ${olt_id}
+        ${piece}=   Convert To Hex  ${decimal_id}  length=2    lowercase=yes
+        ${id}=  Catenate    SEPARATOR=  ${base}     ${piece}
+        Append To List  ${device_ids}    ${id}
+    END
+
+    [Return]    ${device_ids}
\ No newline at end of file