Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ACL UT #233

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions tests/ut/test_acl_ut.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ def test_create_table(self, npu, acl_state):
"SAI_ACL_TABLE_GROUP_ATTR_ACL_STAGE", "SAI_ACL_STAGE_INGRESS",
"SAI_ACL_TABLE_ATTR_ACL_BIND_POINT_TYPE_LIST",
"2:SAI_ACL_BIND_POINT_TYPE_PORT,SAI_ACL_BIND_POINT_TYPE_LAG",
"SAI_ACL_TABLE_ATTR_ACL_ACTION_TYPE_LIST",
"2:SAI_ACL_ACTION_TYPE_PACKET_ACTION,SAI_ACL_ACTION_TYPE_COUNTER",
# ACL table fields
"SAI_ACL_TABLE_ATTR_FIELD_ETHER_TYPE", "true",
"SAI_ACL_TABLE_ATTR_FIELD_DST_MAC", "true",
"SAI_ACL_TABLE_ATTR_FIELD_OUTER_VLAN_ID", "true",
"SAI_ACL_TABLE_ATTR_FIELD_ACL_IP_TYPE", "true",
"SAI_ACL_TABLE_ATTR_FIELD_SRC_IP", "true",
"SAI_ACL_TABLE_ATTR_FIELD_DST_IP", "true",
"SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6", "true",
"SAI_ACL_TABLE_ATTR_FIELD_ICMP_TYPE", "true",
"SAI_ACL_TABLE_ATTR_FIELD_ICMP_CODE", "true",
"SAI_ACL_TABLE_ATTR_FIELD_IP_PROTOCOL", "true",
Expand All @@ -44,6 +48,11 @@ def test_create_table(self, npu, acl_state):
acl_state["table_oid"] = npu.create(SaiObjType.ACL_TABLE, attrs)
assert acl_state["table_oid"] != "oid:0x0"

status, data = npu.get(acl_state["table_oid"], ["SAI_ACL_TABLE_ATTR_AVAILABLE_ACL_COUNTER"], False)
npu.assert_status_success(status)

acl_state["table_counters"] = data.uint32()


@pytest.mark.parametrize(
"match,action,priority",
Expand Down Expand Up @@ -99,13 +108,16 @@ def test_create_table(self, npu, acl_state):
)
@pytest.mark.dependency(depends=['TestIngressACL::test_create_table'])
def test_create_entry(self, npu, acl_state, match, action, priority):
# Create ACL counter
counter_attrs = [
"SAI_ACL_COUNTER_ATTR_TABLE_ID", acl_state["table_oid"],
"SAI_ACL_COUNTER_ATTR_ENABLE_BYTE_COUNT", "true",
"SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT", "true",
]
counter_oid = npu.create(SaiObjType.ACL_COUNTER, counter_attrs)
counter_oid = None
if acl_state["table_counters"] > 0:
# Create ACL counter
counter_attrs = [
"SAI_ACL_COUNTER_ATTR_TABLE_ID", acl_state["table_oid"],
"SAI_ACL_COUNTER_ATTR_ENABLE_BYTE_COUNT", "true",
"SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT", "true",
]
counter_oid = npu.create(SaiObjType.ACL_COUNTER, counter_attrs)
acl_state["table_counters"] -= 1

# Create ACL entry
entry_attrs = [
Expand All @@ -122,18 +134,20 @@ def test_create_entry(self, npu, acl_state, match, action, priority):
entry_attrs.append(field[0])
entry_attrs.append(field[1] + "&mask:" + field[2])

# Add ACL entry action counter
entry_attrs.append("SAI_ACL_ENTRY_ATTR_ACTION_COUNTER")
entry_attrs.append(counter_oid)
if counter_oid:
# Add ACL entry action counter
entry_attrs.append("SAI_ACL_ENTRY_ATTR_ACTION_COUNTER")
entry_attrs.append(counter_oid)

status, entry_oid = npu.create(SaiObjType.ACL_ENTRY, entry_attrs, do_assert=False)
if status != "SAI_STATUS_SUCCESS":
if status != "SAI_STATUS_SUCCESS" and counter_oid:
npu.remove(counter_oid)
assert status == "SAI_STATUS_SUCCESS"
assert status == "SAI_STATUS_SUCCESS", f"Failed to create ACL entry {entry_attrs}"

# Cache OIDs
acl_state["entries"].append(entry_oid)
acl_state["entries"].append(counter_oid)
if counter_oid:
acl_state["entries"].append(counter_oid)


@pytest.mark.dependency(depends=['TestIngressACL::test_create_table'])
Expand Down