[VOL-3812] BBSim Igmp Scale

Change-Id: Iff816b0f6eff4315411aa6e16307a06b1997eee4
diff --git a/tests/scale/Voltha_Scale_Tests.robot b/tests/scale/Voltha_Scale_Tests.robot
index 333f4a0..e903ca9 100644
--- a/tests/scale/Voltha_Scale_Tests.robot
+++ b/tests/scale/Voltha_Scale_Tests.robot
@@ -50,13 +50,21 @@
 Resource          ../../libraries/voltha.robot
 Resource          ../../libraries/flows.robot
 Resource          ../../libraries/k8s.robot
+Resource          ../../libraries/utils.robot
+Resource          ../../libraries/bbsim.robot
 Resource          ../../variables/variables.robot
 
 *** Variables ***
 ${ONOS_SSH_IP}  127.0.0.1
 ${ONOS_SSH_PORT}    8101
+${ONOS_REST_IP}  127.0.0.1
 ${ONOS_REST_PORT}    8181
 
+${BBSIM_REST_IP}    127.0.0.1
+${BBSIM_REST_PORT}    50071
+
+${NAMESPACE}      default
+
 # Scale pipeline values
 ${stackId}  1
 ${olt}  1
@@ -76,6 +84,8 @@
 # Per-test logging on failure is turned off by default; set this variable to enable
 ${container_log_dir}    ${None}
 
+${timeout}    10m
+
 *** Test Cases ***
 
 Create and Enable devices
@@ -186,6 +196,74 @@
         Wait for DHCP Ack     ${onos_ssh_connection}  ${total_onus_per_olt}     ${workflow}     ${deviceId}
     END
 
+Perform Igmp Join
+    [Documentation]    Performs Igmp Join for all the ONUs of all the OLTs (based on Rest Endpoint)
+    [Tags]    non-critical    igmp    igmp-join
+    FOR    ${INDEX}    IN RANGE    0    ${olt}
+        ${bbsim_rel}=    Catenate    SEPARATOR=    bbsim    ${INDEX}
+        ${bbsim_rel_local_port}=    Evaluate    ${BBSIM_REST_PORT}+${INDEX}
+        Create Session    ${bbsim_rel}    http://${BBSIM_REST_IP}:${bbsim_rel_local_port}
+        ${bbsim_pod}=    Get Pod Name By Label    ${NAMESPACE}    release     ${bbsim_rel}
+        ${onu_list}=    Get ONUs List    ${NAMESPACE}    ${bbsim_pod}
+        Perform Igmp Join or Leave Per OLT    ${bbsim_rel}    ${onu_list}    join
+        List Service    ${NAMESPACE}    ${bbsim_pod}
+    END
+
+Wait for ONUs Join Igmp Group
+    [Documentation]    Checks the ONUs Join the IGMP Group
+    ...    Note: Currently, it expects all the ONUs on an OLT joined the same group
+    [Tags]    non-critical    igmp    igmp-join    igmp-count-verify    igmp-join-count-verify
+    ${onos_devices}=    Compute Device IDs
+    FOR     ${deviceId}     IN  @{onos_devices}
+        Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    5s
+        ...    Verify ONUs in Group Count in ONOS    ${onos_ssh_connection}    ${total_onus_per_olt}    ${deviceId}
+    END
+
+#Verify Igmp Join
+#    [Documentation]    Verifies Igmp Groups in ONOS
+#    [Tags]    non-critical    igmp    igmp-join    igmp-verify    igmp-join-verify
+#    ${onos_devices}=    Compute Device IDs
+#    FOR    ${INDEX}    IN RANGE    0    ${olt}
+#        ${bbsim_rel}=    Catenate    SEPARATOR=    bbsim    ${INDEX}
+#        ${bbsim_pod}=    Get Pod Name By Label    ${NAMESPACE}    release     ${bbsim_rel}
+#        ${onu_list}=    Get ONUs List    ${NAMESPACE}    ${bbsim_pod}
+#        Verify Igmp Groups in ONOS    ${onos_devices}[${INDEX}]    ${onu_list}
+#    END
+
+Perform Igmp Leave
+    [Documentation]    Performs Igmp Leave for all the ONUs of all the OLTs (based on Rest Endpoint)
+    [Tags]    non-critical    igmp    igmp-leave
+    FOR    ${INDEX}    IN RANGE    0    ${olt}
+        ${bbsim_rel}=    Catenate    SEPARATOR=    bbsim    ${INDEX}
+        ${bbsim_rel_local_port}=    Evaluate    ${BBSIM_REST_PORT}+${INDEX}
+        Create Session    ${bbsim_rel}    http://${BBSIM_REST_IP}:${bbsim_rel_local_port}
+        ${bbsim_pod}=    Get Pod Name By Label    ${NAMESPACE}    release     ${bbsim_rel}
+        ${onu_list}=    Get ONUs List    ${NAMESPACE}    ${bbsim_pod}
+        Perform Igmp Join or Leave Per OLT    ${bbsim_rel}    ${onu_list}    leave
+        List Service    ${NAMESPACE}    ${bbsim_pod}
+    END
+
+Wait for ONUs Leave Igmp Group
+    [Documentation]    Checks the ONUs Leave the IGMP Group
+    ...    Note: Currently, it expects all the ONUs on an OLT left the same group
+    [Tags]    non-critical    igmp    igmp-leave    igmp-count-verify    igmp-leave-count-verify
+    ${onos_devices}=    Compute Device IDs
+    FOR     ${deviceId}     IN  @{onos_devices}
+        Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    5s
+        ...    Verify Empty Group in ONOS    ${onos_ssh_connection}    ${deviceId}
+    END
+
+#Verify Igmp Leave
+#    [Documentation]    Verifies Igmp Groups in ONOS
+#    [Tags]    non-critical    igmp    igmp-leave    igmp-verify    igmp-leave-verify
+#    ${onos_devices}=    Compute Device IDs
+#    FOR    ${INDEX}    IN RANGE    0    ${olt}
+#        ${bbsim_rel}=    Catenate    SEPARATOR=    bbsim    ${INDEX}
+#        ${bbsim_pod}=    Get Pod Name By Label    ${NAMESPACE}    release     ${bbsim_rel}
+#        ${onu_list}=    Get ONUs List    ${NAMESPACE}    ${bbsim_pod}
+#        Verify Igmp Groups in ONOS    ${onos_devices}[${INDEX}]    ${onu_list}    False
+#    END
+
 Disable and Delete devices
     [Documentation]  Disable and delete the OLTs in VOLTHA
     [Tags]      non-critical    teardown
@@ -209,6 +287,11 @@
     ${total_onus_per_olt}=   Evaluate    ${pon} * ${onu}
     Set Suite Variable  ${total_onus_per_olt}
 
+    ${onos_auth}=    Create List    karaf    karaf
+    Create Session    ONOS    http://${ONOS_REST_IP}:${ONOS_REST_PORT}    auth=${ONOS_AUTH}
+    Run Keyword If    '${workflow}'=='tt'
+    ...    Send File To Onos    ${CURDIR}/../../tests/data/onos-igmp.json    apps/
+
     ${onos_ssh_connection}    Open ONOS SSH Connection    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}
     Set Suite Variable  ${onos_ssh_connection}
 
@@ -228,4 +311,21 @@
         Append To List  ${device_ids}    ${id}
     END
 
-    [Return]    ${device_ids}
\ No newline at end of file
+    [Return]    ${device_ids}
+
+Perform Igmp Join or Leave Per OLT
+    [Documentation]    Performs Igmp Join for all the ONUs of an OLT (based on Rest Endpoint)
+    [Arguments]    ${bbsim_rel_session}    ${onu_list}    ${task}
+    FOR    ${onu}    IN    @{onu_list}
+        JoinOrLeave Igmp Rest Based    ${bbsim_rel_session}    ${onu}    ${task}    224.0.0.22
+    END
+
+Verify Igmp Groups in ONOS
+    [Documentation]   Verifies Igmp Groups in ONOS for all ONUs of an OLT
+    [Arguments]    ${devId}    ${onu_list}    ${group_exist}=True
+    FOR    ${onu}    IN    @{onu_list}
+        ${onu_port}=    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    2s
+        ...    Get ONU Port in ONOS    ${onu}    ${devId}
+        Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    2s
+        ...    Verify ONU in Groups    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}    ${devId}    ${onu_port}    ${group_exist}
+    END