[VOL-2923] Verify Subscriber Flows Added for ONUs on ONOS

Change-Id: Id5270abc041c1678866d5080b567cf0cd51a2dab
diff --git a/libraries/onos.robot b/libraries/onos.robot
index 2847d7f..472d56a 100644
--- a/libraries/onos.robot
+++ b/libraries/onos.robot
@@ -103,6 +103,51 @@
     Should Be True    ${matched}    No fabric switch found
     [Return]    ${of_id}
 
+Verify Subscriber Access Flows Added for ONU
+    [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${onu_port}    ${nni_port}    ${c_tag}    ${s_tag}
+    [Documentation]    Verifies if the Subscriber Access Flows are added in ONOS for the ONU
+    # Verify upstream table=0 flow
+    ${upstream_flow_0_cmd}=    Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep VLAN_VID:0 |
+    ...     grep VLAN_ID:${c_tag} | grep transition=TABLE:1
+    ${upstream_flow_0_added}=    Execute ONOS CLI Command    ${ip}    ${port}
+    ...    ${upstream_flow_0_cmd}
+    Should Not Be Empty    ${upstream_flow_0_added}
+    # Verify upstream table=1 flow
+    ${flow_vlan_push_cmd}=    Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep VLAN_VID:${c_tag} |
+    ...     grep VLAN_PUSH | grep VLAN_ID:${s_tag} | grep OUTPUT:${nni_port}
+    ${upstream_flow_1_added}=    Execute ONOS CLI Command    ${ip}    ${port}
+    ...    ${flow_vlan_push_cmd}
+    Should Not Be Empty    ${upstream_flow_1_added}
+    # Verify downstream table=0 flow
+    ${flow_vlan_pop_cmd}=    Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep VLAN_VID:${s_tag} |
+    ...     grep VLAN_POP | grep transition=TABLE:1
+    ${downstream_flow_0_added}=    Execute ONOS CLI Command    ${ip}    ${port}
+    ...    ${flow_vlan_pop_cmd}
+    Should Not Be Empty    ${downstream_flow_0_added}
+    # Verify downstream table=1 flow
+    ${downstream_flow_1_cmd}=    Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep VLAN_VID:${c_tag} |
+    ...     grep VLAN_ID:0 | grep OUTPUT:${onu_port}
+    ${downstream_flow_1_added}=    Execute ONOS CLI Command    ${ip}    ${port}
+    ...    ${downstream_flow_1_cmd}
+    Should Not Be Empty    ${downstream_flow_1_added}
+    # Verify ipv4 dhcp upstream flow
+    ${upstream_flow_ipv4_cmd}=    Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep ETH_TYPE=ipv4 |
+    ...     grep VLAN_VID:${c_tag} | grep OUTPUT:CONTROLLER
+    ${upstream_flow_ipv4_added}=    Execute ONOS CLI Command    ${ip}    ${port}
+    ...    ${upstream_flow_ipv4_cmd}
+    # Verify ipv4 dhcp downstream flow
+    # Note: This flow will be one per nni per olt
+    ${downstream_flow_ipv4_cmd}=    Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep ETH_TYPE=ipv4 |
+    ...     grep OUTPUT:CONTROLLER
+    ${downstream_flow_ipv4_added}=    Execute ONOS CLI Command    ${ip}    ${port}
+    ...    ${downstream_flow_ipv4_cmd}
+
 Verify Subscriber Access Flows Added for ONU DT
     [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${onu_port}    ${nni_port}    ${s_tag}
     [Documentation]    Verifies if the Subscriber Access Flows are added in ONOS for the ONU
diff --git a/libraries/utils.robot b/libraries/utils.robot
index 81c10f9..fb6fc06 100644
--- a/libraries/utils.robot
+++ b/libraries/utils.robot
@@ -151,6 +151,9 @@
     ...    and avoids duplication of code.
     ${of_id}=    Wait Until Keyword Succeeds    ${timeout}    15s    Validate OLT Device in ONOS    ${olt_serial_number}
     Set Global Variable    ${of_id}
+    ${nni_port}=    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    2s
+    ...    Get NNI Port in ONOS    ${of_id}
+    Set Global Variable    ${nni_port}
     FOR    ${I}    IN RANGE    0    ${num_onus}
         ${src}=    Set Variable    ${hosts.src[${I}]}
         ${dst}=    Set Variable    ${hosts.dst[${I}]}
@@ -182,6 +185,10 @@
         # Verify that no pending flows exist for the ONU port
         Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    2s
         ...    Verify No Pending Flows For ONU    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}    ${onu_port}
+        # Verify subscriber access flows are added for the ONU port
+        Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    5s
+        ...    Verify Subscriber Access Flows Added For ONU    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}    ${of_id}
+        ...    ${onu_port}    ${nni_port}    ${src['c_tag']}    ${src['s_tag']}
         Run Keyword If    ${has_dataplane}    Run Keyword And Continue On Failure    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']}