[VOL-4724] TIM Workflow Robot Test Setup

Added some configuration to the test enviroment for set up  multiple sanity test for tim workflow

Change-Id: I9cdc88eb278bb48945dd71befec81a7ddea9d312

Added some method to verify the correctness of flow rules genereted by ONOS.

Change-Id: Iba9a11a87070ce1bf4bbd7d06c767e1e2e1cac28

Added some Test Case to do a Sanity-Test for the TIM Workflow Test are x Multi OLT, Multi PON and Multi ONO About the correctness of generation about the ONOS flow rules

Change-Id: Ica62a7720554bb2cbf82597ee861a7149b89e30a

Test file structure to do a single OLT, Single PON and Single ONU Sanity Test for TIM Workflow

Change-Id: I5a1cdf323398055ec41d2dddbf5c842e3b50b393

Test file structure to do a single OLT, Single PON and Multi ONU Sanity Test for TIM Workflow

Change-Id: Ifc74e84da3bafda23c3501e40104624ff98a6007

Test file structure to do a single OLT, Multi PON and Multi ONU Sanity Test for TIM Workflow

Change-Id: I22a812ceac39caeb574feffc64892559f6c0096d

Test file structure to do a Multi OLT, Multi PON and Multi ONU Sanity Test for TIM Workflow

Change-Id: I68745b986cdb94347dff96ffd99608bffdfa8470

Robot Test Code to do TIM Workflow  Sanity Test
Scalability Test in ONOS and in OLTs and ONUs device

Change-Id: I1c21f45751b5502c16fbcadc6f70e50388389d3f
diff --git a/libraries/utils.robot b/libraries/utils.robot
index c42d35f..2bfe322 100755
--- a/libraries/utils.robot
+++ b/libraries/utils.robot
@@ -1714,3 +1714,112 @@
     END
     # Waiting extra time for the ONUs to come up
     Sleep    60s
+
+Perform Sanity Test TIM
+    [Documentation]    This keyword iterate all OLTs and performs Sanity Test Procedure for TIM workflow
+    ...    For repeating sanity test without subscriber changes set flag supress_add_subscriber=True.
+    ...    In all other (common) cases flag has to be set False (default).
+    [Arguments]    ${supress_add_subscriber}=False    ${maclearning_enabled}=False
+    FOR    ${J}    IN RANGE    0    ${num_olts}
+        ${olt_serial_number}=    Set Variable    ${list_olts}[${J}][sn]
+        ${num_onus}=    Set Variable    ${list_olts}[${J}][onucount]
+        ${olt_device_id}=    Get OLTDeviceID From OLT List    ${olt_serial_number}
+        ${of_id}=    Wait Until Keyword Succeeds    ${timeout}    15s    Validate OLT Device in ONOS
+        ...    ${olt_serial_number}
+        Set Global Variable    ${of_id}
+
+        #Permorm test on flow rules that are writen inside ONOS, OLT and ONUs
+        ${nni_port}=    Wait Until Keyword Succeeds    ${timeout}    2s    Get NNI Port in ONOS    ${of_id}
+        Perform Sanity Test TIM Per OLT    ${of_id}    ${nni_port}    ${olt_serial_number}    ${num_onus}
+        ...    ${supress_add_subscriber}
+
+        #Scalability Test
+        #Extract the total iphotetical number of UNIs that an OLT controll having multiple ONUs connected
+        ${num_of_provisioned_onus_ports}=      Count Number of UNI ports for OLT
+        ...     ${olt_serial_number}    hsia
+
+        # Verify ONOS Flows
+        # Number of Access Flows for OLT on ONOS are equals to:
+        # a standard downstream flow for the Any VLAN, that flow exist when there are at least 1 onu,
+        # 4 rules for each single ONU/UNI
+        # and there are 3 default flows lldp, igmp and pppoe flow rules for the OLT
+        ${onos_flows_count}=    Run Keyword    Calculate Tim flows
+        ...     ${num_of_provisioned_onus_ports}    1   true  true     true    true
+
+        Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    5s
+        ...    Verify Subscriber Access Flows Added Count TIM    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}    ${of_id}
+        ...    ${onos_flows_count}
+
+        # Verify VOLTHA Flows
+        # Number of per OLT Flows are 3 times the Number of Active ONUs
+        # (for downstream and upstream) + 3 on the NNI port the LLDP, IGMP and PPPoE default flows
+        ${olt_flows}=    Evaluate   3 * ${num_of_provisioned_onus_ports} + 3
+        Run Keyword    Wait Until Keyword Succeeds    ${timeout}    5s    Validate OLT Flows
+        ...    ${olt_flows}    ${olt_device_id}
+        ${List_ONU_Serial}    Create List
+        Set Suite Variable    ${List_ONU_Serial}
+        Build ONU SN List    ${List_ONU_Serial}    ${olt_serial_number}
+        Log    ${List_ONU_Serial}
+        # Number of per ONU Flows equals 3
+        ${onu_flows}=    Set Variable    3
+        Wait Until Keyword Succeeds    ${timeout}    5s    Validate ONU Flows
+        ...    ${List_ONU_Serial}    ${onu_flows}
+    END
+
+Count Number of UNI ports for OLT
+    [Documentation]  Count Provisioned UNI ports, for ONUs connected with specified OLT
+    [Arguments]    ${olt_serial_number}     ${type_of_service}
+    ${num_of_provisioned_onus_ports}=      Evaluate     0
+    FOR    ${I}    IN RANGE    0    ${num_all_onus}
+        ${src}=    Set Variable    ${hosts.src[${I}]}
+        Continue For Loop If    "${olt_serial_number}"!="${src['olt']}"
+        Continue For Loop If    "${type_of_service}"!="${src['service_type']}"
+        ${num_of_provisioned_onus_ports}=      Evaluate     ${num_of_provisioned_onus_ports} + 1
+    END
+    [Return]    ${num_of_provisioned_onus_ports}
+
+
+Perform Sanity Test TIM Per OLT
+    [Arguments]    ${of_id}    ${nni_port}    ${olt_serial_number}    ${num_onus}    ${supress_add_subscriber}=False
+    [Documentation]    This keyword performs Sanity Test Procedure for TIM Workflow
+    ...    Sanity test performs pppoe and flows for all the ONUs (and for each UNIs of a consider ONU)
+    ...    This keyword can be used to call in any other tests where sanity check is required
+    ...    and avoids duplication of code.
+    ...    For repeating sanity test without subscriber changes set flag supress_add_subscriber=True.
+    ...    In all other (common) cases flag has to be set False (default).
+    Wait Until Keyword Succeeds    ${timeout}    5s
+        ...    Verify Downstream Flows for Single OLT NNI Port TIM    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}    ${of_id}
+        ...    ${nni_port}
+
+    FOR    ${I}    IN RANGE    0    ${num_all_onus}
+        ${src}=    Set Variable    ${hosts.src[${I}]}
+        ${dst}=    Set Variable    ${hosts.dst[${I}]}
+        Continue For Loop If    "${olt_serial_number}"!="${src['olt']}"
+        ${onu_device_id}=    Get Device ID From SN    ${src['onu']}
+        ${onu_port}=    Wait Until Keyword Succeeds    ${timeout}    2s
+        ...    Get ONU Port in ONOS    ${src['onu']}    ${of_id}    ${src['uni_id']}
+        # Check ONU port is Enabled in ONOS
+        Wait Until Keyword Succeeds   120s   2s
+        ...    Verify UNI Port Is Enabled   ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}    ${src['onu']}    ${src['uni_id']}
+
+        # Subscribe a RG on a defualt UNI_id=1
+        ${add_subscriber_access} =  Set Variable     volt-add-subscriber-access ${of_id} ${onu_port}
+        Run Keyword If    '${supress_add_subscriber}' == 'False'
+        ...     Execute ONOS CLI Command use single connection    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}   ${add_subscriber_access}
+
+        # Verify ONU state in voltha
+        ${onu_reasons}=  Create List     omci-flows-pushed
+        Run Keyword    Append To List    ${onu_reasons}    onu-reenabled
+        Wait Until Keyword Succeeds    ${timeout}    5s    Validate Device
+        ...    ENABLED    ACTIVE    REACHABLE
+        ...    ${src['onu']}    onu=True    onu_reason=${onu_reasons}
+
+        # Verify subscriber access flows are added for a single ONU puniort
+        Wait Until Keyword Succeeds    ${timeout}    5s
+        ...    Verify Subscriber Access Flows Added For Single ONU Port TIM    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}    ${of_id}
+        ...    ${onu_port}    ${nni_port}    ${src['c_tag']}    ${src['uni_tag']}
+
+        # TO DO: Verify Meters in ONOS
+        #Wait Until Keyword Succeeds    ${timeout}    5s
+        #...    Verify Meters in ONOS Ietf    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}    ${of_id}    ${onu_port}
+    END