[VOL-3804] Test for BBSim

Change-Id: I5dbecebb8f876379b34e60cb56388ea681866a03
diff --git a/libraries/onos.robot b/libraries/onos.robot
index 66904b9..1f785f5 100755
--- a/libraries/onos.robot
+++ b/libraries/onos.robot
@@ -419,6 +419,38 @@
     ${aaa_users}=    Execute ONOS CLI Command    ${ip}    ${port}    aaa-users | grep AUTHORIZED | grep ${onu_port}
     Should Not Be Empty    ${aaa_users}    ONU port ${onu_port} not found in aaa-users
 
+Verify ONU in Groups
+    [Arguments]    ${ip_onos}    ${port_onos}    ${deviceId}    ${onu_port}    ${group_exist}=True
+    [Documentation]    Verifies that the specified onu_port exists in groups output
+    ${result}=    Execute ONOS CLI Command    ${ip_onos}    ${port_onos}    groups -j
+    Log    Groups: ${result}
+    ${groups}=    To Json    ${result}
+    ${length}=    Get Length    ${groups}
+    ${buckets}=    Create List
+    ${matched}=    Set Variable    False
+    FOR    ${INDEX}    IN RANGE    0    ${length}
+        ${value}=    Get From List    ${groups}    ${INDEX}
+        ${devId}=    Get From Dictionary    ${value}    deviceId
+        ${bucket}=    Get From Dictionary    ${value}    buckets
+        Run Keyword If    '${devId}'=='${deviceId}'
+        ...    Append To List    ${buckets}    ${bucket}
+    END
+    ${bucket_len}=    Get Length    ${buckets}
+    FOR    ${INDEX1}    IN RANGE    0    ${bucket_len}
+        ${value}=    Get From List    ${buckets}    ${INDEX}
+        ${value_bucket}=    Get From List    ${value}    0
+        ${treatment}=    Get From Dictionary    ${value_bucket}    treatment
+        ${instructions}=    Get From Dictionary    ${treatment}    instructions
+        ${instructions_val}=    Get From List    ${instructions}    0
+        ${port}=    Get From Dictionary    ${instructions_val}    port
+        ${matched}=    Set Variable If    '${port}'=='${onu_port}'    True    False
+        Exit For Loop If    ${matched}
+    END
+    Run Keyword If    ${group_exist}
+    ...    Should Be True    ${matched}    No match for ${deviceId} and ${onu_port} found in ONOS groups
+    ...    ELSE
+    ...    Should Be True    '${matched}'=='False'    Match for ${deviceId} and ${onu_port} found in ONOS groups
+
 Assert Number of AAA-Users
     [Arguments]    ${onos_ssh_connection}    ${expected_onus}   ${deviceId}
     [Documentation]    Matches for number of aaa-users authorized based on number of onus