[VOL-4647] Added DT FTTB Sanity Test

Change-Id: I499705bd744204a67b709234f424fcdc3c17d881
diff --git a/libraries/onos.robot b/libraries/onos.robot
index aff9866..cecfc19 100755
--- a/libraries/onos.robot
+++ b/libraries/onos.robot
@@ -349,6 +349,109 @@
     ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep VLAN_VID:Any | grep OUTPUT:${onu_port}
     Should Not Be Empty    ${downstream_flow_1_added}
 
+Verify Subscriber Access Flows Added for DT FTTB
+    [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${onu_port}    ${nni_port}    ${s_tag}    ${c_tag}
+    [Documentation]    Verifies if the Subscriber Access Flows are added in ONOS for the ONU
+    # Upstream
+    # ONU
+    ${us_flow_onu_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep VLAN_VID:${c_tag} | grep transition=TABLE:1
+    Should Not Be Empty    ${us_flow_onu_added}
+    # OLT
+    ${us_flow_olt_cmd}=    Catenate
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep VLAN_VID:${c_tag} |
+    ...    grep VLAN_ID:${s_tag} | grep OUTPUT:${nni_port}
+    ${us_flow_olt_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    ${us_flow_olt_cmd}
+    Should Not Be Empty    ${us_flow_olt_added}
+    # Downstream
+    # OLT
+    ${ds_flow_olt_cmd}=    Catenate
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep VLAN_VID:${s_tag} |
+    ...    grep VLAN_ID:${c_tag} | grep transition=TABLE:1
+    ${ds_flow_olt_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    ${ds_flow_olt_cmd}
+    Should Not Be Empty    ${ds_flow_olt_added}
+    # ONU
+    ${ds_flow_onu_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep VLAN_VID:${c_tag} | grep OUTPUT:${onu_port}
+    Should Not Be Empty    ${ds_flow_onu_added}
+
+Verify DPU ANCP Flows Added for DT FTTB
+    [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${onu_port}    ${nni_port}    ${s_tag}    ${c_tag}
+    [Documentation]    Verifies if the DPU ANCP Flows are added in ONOS for the ONU
+    # Upstream
+    # ONU
+    ${us_flow_onu_cmd}=    Catenate
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep VLAN_VID:${c_tag} |
+    ...    grep VLAN_ID:${s_tag} | grep transition=TABLE:1
+    ${us_flow_onu_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    ${us_flow_onu_cmd}
+    Should Not Be Empty    ${us_flow_onu_added}
+    # OLT
+    ${us_flow_olt_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep VLAN_VID:${s_tag} | grep OUTPUT:${nni_port}
+    Should Not Be Empty    ${us_flow_olt_added}
+    # Downstream
+    # OLT
+    ${ds_flow_olt_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep VLAN_VID:${s_tag} | grep transition=TABLE:1
+    Should Not Be Empty    ${ds_flow_olt_added}
+    # ONU
+    ${ds_flow_onu_cmd}=    Catenate
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep VLAN_VID:${s_tag} |
+    ...    grep VLAN_ID:${c_tag} | grep OUTPUT:${onu_port}
+    ${ds_flow_onu_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    ${ds_flow_onu_cmd}
+    Should Not Be Empty    ${ds_flow_onu_added}
+
+Verify DPU MGMT Flows Added for DT FTTB
+    [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${onu_port}    ${nni_port}    ${s_tag}    ${c_tag}
+    [Documentation]    Verifies if the DPU MGMT Flows are added in ONOS for the ONU
+    # Upstream
+    # ONU
+    ${us_flow_onu_cmd}=    Catenate
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep VLAN_VID:${c_tag} |
+    ...    grep VLAN_ID:${s_tag} | grep transition=TABLE:1
+    ${us_flow_onu_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    ${us_flow_onu_cmd}
+    Should Not Be Empty    ${us_flow_onu_added}
+    # OLT
+    ${us_flow_olt_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep VLAN_VID:${s_tag} | grep OUTPUT:${nni_port}
+    Should Not Be Empty    ${us_flow_olt_added}
+    # Downstream
+    # OLT
+    ${ds_flow_olt_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep VLAN_VID:${s_tag} | grep transition=TABLE:1
+    Should Not Be Empty    ${ds_flow_olt_added}
+    # ONU
+    ${ds_flow_onu_cmd}=    Catenate
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep VLAN_VID:${s_tag} |
+    ...    grep VLAN_ID:${c_tag} | grep OUTPUT:${onu_port}
+    ${ds_flow_onu_added}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
+    ...    ${ds_flow_onu_cmd}
+    Should Not Be Empty    ${ds_flow_onu_added}
+
+Verify ONOS Flows Added for DT FTTB
+    [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${onu_port}    ${nni_port}    ${service}
+    [Documentation]    Verifies if the Flows are added in ONOS for the ONU
+    ${num_services}=    Get Length    ${service}
+    FOR     ${I}    IN RANGE    0    ${num_services}
+        ${service_name}=    Set Variable    ${service[${I}]['name']}
+        ${stag}=    Set Variable    ${service[${I}]['s_tag']}
+        ${ctag}=    Set Variable    ${service[${I}]['c_tag']}
+        Run Keyword If    '${service_name}' == 'FTTB_SUBSCRIBER_TRAFFIC'
+        ...    Verify Subscriber Access Flows Added for DT FTTB    ${ip}    ${port}
+        ...    ${olt_of_id}    ${onu_port}    ${nni_port}    ${stag}    ${ctag}
+        ...    ELSE IF    '${service_name}' == 'DPU_ANCP_TRAFFIC'
+        ...    Verify DPU ANCP Flows Added for DT FTTB    ${ip}    ${port}
+        ...    ${olt_of_id}    ${onu_port}    ${nni_port}    ${stag}    ${ctag}
+        ...    ELSE IF    '${service_name}' == 'DPU_MGMT_TRAFFIC'
+        ...    Verify DPU MGMT Flows Added for DT FTTB    ${ip}    ${port}
+        ...    ${olt_of_id}    ${onu_port}    ${nni_port}    ${stag}    ${ctag}
+    END
+
 Verify Subscriber Access Flows Added Count DT
     [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${expected_flows}
     [Documentation]    Matches for total number of subscriber access flows added for all onus
@@ -391,13 +494,26 @@
     Should Not Be Empty    ${downstream_flow_igmp_added}
 
 Get Programmed Subscribers
-    [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${onu_port}
+    [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${onu_port}    ${filter}=${EMPTY}
     [Documentation]    Retrieves the subscriber details at a given location
-    ${sub_location}=    Catenate    SEPARATOR=/    ${olt_of_id}    ${onu_port}
-    ${programmed_sub}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}
-    ...    volt-programmed-subscribers | grep ${sub_location}
+    ${cmd}=    Set Variable If    '${filter}' == '${EMPTY}'
+    ...    volt-programmed-subscribers ${olt_of_id} ${onu_port}
+    ...    volt-programmed-subscribers ${olt_of_id} ${onu_port} | grep ${filter} --color=none
+    ${programmed_sub}=    Execute ONOS CLI Command use single connection    ${ip}    ${port}    ${cmd}
     [Return]    ${programmed_sub}
 
+Verify Programmed Subscribers DT FTTB
+    [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${onu_port}    ${service}
+    [Documentation]    Verifies the subscriber is present at a given location
+    ${num_services}=    Get Length    ${service}
+    FOR    ${I}    IN RANGE    0    ${num_services}
+        ${service_name}=    Set Variable    ${service[${I}]['name']}
+        ${programmed_subscriber}=    Get Programmed Subscribers    ${ip}    ${port}    ${olt_of_id}    ${onu_port}
+        ...    ${service_name}
+        Log    ${programmed_subscriber}
+        Should Not Be Empty    ${programmed_subscriber}
+    END
+
 Get Upstream and Downstream Bandwidth Profile Name
     [Arguments]    ${programmed_sub}
     [Documentation]    Retrieves the upstream and downstream bandwidth profile name
@@ -500,11 +616,11 @@
     [Return]    ${cir}    ${cbs}    ${pir}    ${pbs}    ${gir}
 
 Verify Meters in ONOS Ietf
-    [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${onu_port}
+    [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${onu_port}    ${filter}=${EMPTY}
     [Documentation]    Verifies the meters with BW Ietf format (currently, DT workflow uses this format)
     # Get programmed subscriber
     ${programmed_sub}=    Get Programmed Subscribers    ${ip}    ${port}
-    ...    ${olt_of_id}    ${onu_port}
+    ...    ${olt_of_id}    ${onu_port}    ${filter}
     Log    ${programmed_sub}
     ${us_bw_profile}    ${ds_bw_profile}    Get Upstream and Downstream Bandwidth Profile Name
     ...    ${programmed_sub}
diff --git a/libraries/utils.robot b/libraries/utils.robot
index ec94c5f..defd154 100755
--- a/libraries/utils.robot
+++ b/libraries/utils.robot
@@ -351,6 +351,69 @@
         ...    ${dst['container_name']}
     END
 
+Perform Sanity Test DT FTTB
+    [Documentation]    This keyword iterate all OLTs and performs Sanity Test Procedure for DT-FTTB 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
+    FOR    ${J}    IN RANGE    0    ${num_olts}
+        ${olt_serial_number}=    Set Variable    ${list_olts}[${J}][sn]
+        ${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}
+        ${nni_port}=    Wait Until Keyword Succeeds    ${timeout}    2s    Get NNI Port in ONOS    ${of_id}
+        Perform Sanity Test DT FTTB Per OLT    ${of_id}    ${nni_port}    ${olt_serial_number}
+        ...    ${supress_add_subscriber}
+    END
+
+Perform Sanity Test DT FTTB Per OLT
+    [Arguments]    ${of_id}    ${nni_port}    ${olt_serial_number}    ${supress_add_subscriber}=False
+    [Documentation]    This keyword performs Sanity Test Procedure for DT-FTTB Workflow
+    ...    Sanity test performs dhcp and pings (without EAPOL and DHCP flows) for all the ONUs given for the POD
+    ...    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).
+    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']}
+        Run Keyword Unless    ${supress_add_subscriber}
+        ...    Execute ONOS CLI Command use single connection    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}
+        ...    volt-add-subscriber-access ${of_id} ${onu_port}
+        # Verify ONOS flows are added for the ONU port
+        Wait Until Keyword Succeeds    ${timeout}    5s
+        ...    Verify ONOS Flows Added For DT FTTB    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}    ${of_id}
+        ...    ${onu_port}    ${nni_port}    ${src['service']}
+        # Verify that the Subscriber is present at the given location
+        Wait Until Keyword Succeeds    ${timeout}    5s
+        ...    Verify Programmed Subscribers DT FTTB    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}    ${of_id}
+        ...    ${onu_port}    ${src['service']}
+        # Verify ONU state in voltha
+        ${onu_reasons}=  Create List     omci-flows-pushed
+        Wait Until Keyword Succeeds    ${timeout}    5s    Validate Device
+        ...    ENABLED    ACTIVE    REACHABLE
+        ...    ${src['onu']}    onu=True    onu_reason=${onu_reasons}
+        # 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}
+        ...    ${src['service'][0]['name']}
+        # Verify Mac Learner Mappings
+        Wait Until Keyword Succeeds    ${timeout}    5s    Validate Mac Learner Mapping in ONOS
+        ...    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}    ${of_id}    ${onu_port}    ${src['service'][2]['s_tag']}
+        Run Keyword If    ${has_dataplane}    Validate DHCP and Ping    True
+        ...    True    ${src['dp_iface_name']}    ${src['s_tag']}    ${src['c_tag']}    ${dst['dp_iface_ip_qinq']}
+        ...    ${src['ip']}    ${src['user']}    ${src['pass']}    ${src['container_type']}    ${src['container_name']}
+        ...    ${dst['dp_iface_name']}    ${dst['ip']}    ${dst['user']}    ${dst['pass']}    ${dst['container_type']}
+        ...    ${dst['container_name']}
+    END
+
 Validate All OLT Flows
     [Documentation]    This keyword iterate all OLTs and performs Sanity Test Procedure for DT workflow
     FOR    ${J}    IN RANGE    0    ${num_olts}