[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/flows.robot b/libraries/flows.robot
index ff8b673..f6e6a4a 100644
--- a/libraries/flows.robot
+++ b/libraries/flows.robot
@@ -35,7 +35,9 @@
     ...     ${uni_count}    ${olt_count}    ${provisioned}  ${withLldp}
     ...     ELSE IF     $workflow=="tt"     Calculate Tt Flows
     ...     ${uni_count}    ${olt_count}    ${provisioned}  ${withDhcp}     ${withIgmp}     ${withLldp}
-    ...     ELSE    Fail    Workflow ${workflow} should be one of 'att', 'dt', 'tt'
+    ...     ELSE IF     $workflow=="tim"     Calculate Tim Flows
+    ...     ${uni_count}    ${olt_count}    ${provisioned}  ${withPppoe}     ${withIgmp}     ${withLldp}
+    ...     ELSE    Fail    Workflow ${workflow} should be one of 'att', 'dt', 'tt' , 'tim'
     Return From Keyword     ${expectedFlows}
 
 Calculate Att flows
@@ -130,4 +132,31 @@
     ...     Evaluate     ${totalDhcpFlows} + ${totalLldpFlows} + ${totalIgmpFlows}
     ...     ELSE
     ...     Evaluate    (${uni_count} * 15) + ${totalDhcpFlows} + ${totalLldpFlows} + ${totalIgmpFlows}
+    Return From Keyword     ${flow_count}
+
+Calculate Tim flows
+    [Documentation]  Calculate the flow for the Tim workflow
+    [Arguments]  ${uni_count}    ${olt_count}   ${provisioned}  ${withPppoe}     ${withIgmp}    ${withLldp}
+    # (1 LLDP + 1 PPPoE + 1 IGMP) for each OLTs before provisioning
+    # 1 Any VLAN + (4 * UNIs) * (1 LLDP + 1 PPPoE + 1 IGMP) for each OLTs after provisioning
+    ${anyVlanFlowsCount}=   Evaluate    1
+    ${pppoeFlowsCount}=   Run Keyword If   $withPppoe=='true'
+    ...     Evaluate     1
+    ...     ELSE
+    ...     Evaluate     0
+    ${lldpFlowsCount}=   Run Keyword If   $withLldp=='true'
+    ...     Evaluate     1
+    ...     ELSE
+    ...     Evaluate     0
+    ${igmpFlowsCount}=   Run Keyword If   $withIgmp=='true'
+    ...     Evaluate     1
+    ...     ELSE
+    ...     Evaluate     0
+    ${pppoeFlowsCount}=   Evaluate   ${olt_count} * ${pppoeFlowsCount}
+    ${totalLldpFlows}=   Evaluate   ${olt_count} * ${lldpFlowsCount}
+    ${totalIgmpFlows}=   Evaluate   ${olt_count} * ${igmpFlowsCount}
+    ${flow_count}=  Run Keyword If  $provisioned=='false'
+    ...     Evaluate     ${pppoeFlowsCount} + ${totalLldpFlows} + ${totalIgmpFlows}
+    ...     ELSE
+    ...     Evaluate    ${anyVlanFlowsCount} + (${uni_count} * 4) + ${pppoeFlowsCount} + ${totalLldpFlows} + ${totalIgmpFlows}
     Return From Keyword     ${flow_count}
\ No newline at end of file
diff --git a/libraries/onos.robot b/libraries/onos.robot
index b6a9cb9..c2c949d 100755
--- a/libraries/onos.robot
+++ b/libraries/onos.robot
@@ -461,6 +461,14 @@
     ${access_flows_added_count}=      Get Line Count      ${access_flows_added}
     Should Be Equal As Integers    ${access_flows_added_count}    ${expected_flows}
 
+Verify Subscriber Access Flows Added Count TIM
+    [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${expected_flows}
+    [Documentation]    Matches for total number of subscriber access flows added for all onus
+    ${access_flows_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    flows -s ADDED ${olt_of_id} | grep -v deviceId
+    ${access_flows_added_count}=      Get Line Count      ${access_flows_added}
+    Should Be Equal As Integers    ${access_flows_added_count}    ${expected_flows}
+
 Verify Added Flow Count for OLT TT
     [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${expected_flows}
     [Documentation]    Total number of added flows given OLT with subscriber flows
@@ -494,6 +502,75 @@
     ...    ${downstream_flow_igmp_cmd}
     Should Not Be Empty    ${downstream_flow_igmp_added}
 
+Verify Downstream Flows for Single OLT NNI Port TIM
+    [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${nni_port}
+    [Documentation]    Verifies if the downstream flows from the NNI port to the CONTROLLER port are added in ONOS for the OLT
+
+    # Verify PPPoE downstream flow form NNI to CONTROLLER port
+    ${downstream_pppoed_cmd}=     Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep ETH_TYPE:pppoed | grep OUTPUT:CONTROLLER
+    ${downstream_pppoed}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    ${downstream_pppoed_cmd}
+    Should Not Be Empty    ${downstream_pppoed}
+
+    # Verify IGMP downstream flow form NNI to CONTROLLER port
+    ${downstream_igmp_cmd}=     Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep ETH_TYPE:ipv4 | grep IP_PROTO:2 | grep OUTPUT:CONTROLLER
+    ${downstream_igmp}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    ${downstream_igmp_cmd}
+    Should Not Be Empty    ${downstream_igmp}
+
+    # Verify LLDP downstream flow form NNI to CONTROLLER port
+    ${downstream_lldp_cmd}=     Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep ETH_TYPE:lldp | grep OUTPUT:CONTROLLER
+    ${downstream_lldp}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    ${downstream_lldp_cmd}
+    Should Not Be Empty    ${downstream_lldp}
+
+Verify Subscriber Access Flows Added for Single ONU Port TIM
+    [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${onu_port}    ${nni_port}    ${c_tag}   ${uni_tag}
+    [Documentation]    Verifies if the Subscriber Access Flows are added in ONOS for the ONU
+
+    # Verify upstream pppoed flow from UNI port to CONTROLLER
+    ${upstream_flow_pppoed_added_cmd}=   Catenate    SEPARATOR=
+    ...     flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep ETH_TYPE:pppoed |
+    ...     grep VLAN_VID:${uni_tag} | grep OUTPUT:CONTROLLER
+    ${upstream_flow_pppoed_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    ${upstream_flow_pppoed_added_cmd}
+    Should Not Be Empty    ${upstream_flow_pppoed_added}
+
+    # Verify upstream table=0 flow, from UNI to TABLE 1
+    ${upstream_flow_0_added_cmd}=     Catenate    SEPARATOR=
+    ...     flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep VLAN_VID:${uni_tag} |
+    ...     grep VLAN_ID:${c_tag}  | grep transition=TABLE:1
+    ${upstream_flow_0_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    ${upstream_flow_0_added_cmd}
+    Should Not Be Empty    ${upstream_flow_0_added}
+
+    # Verify upstream table=1 flow, from UNI to NNI
+    ${flow_vlan_UNI_to_NNI_cmd}=     Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep table=1 | grep IN_PORT:${onu_port} | grep VLAN_VID:${c_tag} |
+    ...    grep OUTPUT:${nni_port}
+    ${flow_vlan_UNI_to_NNI}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    ${flow_vlan_UNI_to_NNI_cmd}
+    Should Not Be Empty    ${flow_vlan_UNI_to_NNI}
+
+    # Verify downstream table=0 flow, from NNI to TABLE 1
+    ${downstream_flow_0_added_cmd}=     Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep VLAN_VID:Any |
+    ...    grep transition=TABLE:1
+    ${downstream_flow_0_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    ${downstream_flow_0_added_cmd}
+    Should Not Be Empty    ${downstream_flow_0_added}
+
+    # Verify downstream table=1 flow, from NNI to UNI
+    ${downstream_form_NNI_to_UNI_in_table_1_cmd}=     Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep table=1 | grep IN_PORT:${nni_port} | grep VLAN_VID:${c_tag} |
+    ...    grep VLAN_ID:${uni_tag} | grep OUTPUT:${onu_port}
+    ${downstream_form_NNI_to_UNI_in_table_1}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    ${downstream_form_NNI_to_UNI_in_table_1_cmd}
+    Should Not Be Empty    ${downstream_form_NNI_to_UNI_in_table_1}
+
 Get Programmed Subscribers
     [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${onu_port}    ${filter}=${EMPTY}
     [Documentation]    Retrieves the subscriber details at a given location
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