Skip to content

Commit ec507a4

Browse files
authored
[ACL] Support ACTION_COUNTER action in custom ACL table type (#2550)
* Support COUNTER action in custom ACL Signed-off-by: bingwang <[email protected]>
1 parent 1a74604 commit ec507a4

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

orchagent/aclorch.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ static acl_rule_attr_lookup_t aclDTelActionLookup =
107107
{ ACTION_DTEL_REPORT_ALL_PACKETS, SAI_ACL_ENTRY_ATTR_ACTION_DTEL_REPORT_ALL_PACKETS }
108108
};
109109

110+
static acl_rule_attr_lookup_t aclOtherActionLookup =
111+
{
112+
{ ACTION_COUNTER, SAI_ACL_ENTRY_ATTR_ACTION_COUNTER}
113+
};
114+
110115
static acl_packet_action_lookup_t aclPacketActionLookup =
111116
{
112117
{ PACKET_ACTION_FORWARD, SAI_PACKET_ACTION_FORWARD },
@@ -635,6 +640,7 @@ bool AclTableTypeParser::parseAclTableTypeActions(const std::string& value, AclT
635640
auto l3Action = aclL3ActionLookup.find(action);
636641
auto mirrorAction = aclMirrorStageLookup.find(action);
637642
auto dtelAction = aclDTelActionLookup.find(action);
643+
auto otherAction = aclOtherActionLookup.find(action);
638644

639645
if (l3Action != aclL3ActionLookup.end())
640646
{
@@ -648,11 +654,16 @@ bool AclTableTypeParser::parseAclTableTypeActions(const std::string& value, AclT
648654
{
649655
saiActionAttr = dtelAction->second;
650656
}
657+
else if (otherAction != aclOtherActionLookup.end())
658+
{
659+
saiActionAttr = otherAction->second;
660+
}
651661
else
652662
{
653663
SWSS_LOG_ERROR("Unknown action %s", action.c_str());
654664
return false;
655665
}
666+
SWSS_LOG_INFO("Added action %s", action.c_str());
656667

657668
builder.withAction(AclEntryActionToAclAction(saiActionAttr));
658669
}
@@ -4439,10 +4450,12 @@ void AclOrch::doAclTableTypeTask(Consumer &consumer)
44394450
}
44404451

44414452
addAclTableType(builder.build());
4453+
SWSS_LOG_NOTICE("Created ACL table type %s", key.c_str());
44424454
}
44434455
else if (op == DEL_COMMAND)
44444456
{
44454457
removeAclTableType(key);
4458+
SWSS_LOG_NOTICE("Removed ACL table type %s", key.c_str());
44464459
}
44474460
else
44484461
{

orchagent/aclorch.h

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#define ACTION_DTEL_TAIL_DROP_REPORT_ENABLE "TAIL_DROP_REPORT_ENABLE"
6666
#define ACTION_DTEL_FLOW_SAMPLE_PERCENT "FLOW_SAMPLE_PERCENT"
6767
#define ACTION_DTEL_REPORT_ALL_PACKETS "REPORT_ALL_PACKETS"
68+
#define ACTION_COUNTER "COUNTER"
6869

6970
#define PACKET_ACTION_FORWARD "FORWARD"
7071
#define PACKET_ACTION_DROP "DROP"

tests/dvslib/dvs_acl.py

+25-2
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,21 @@ def create_acl_table_type(
5454
self,
5555
name: str,
5656
matches: List[str],
57-
bpoint_types: List[str]
57+
bpoint_types: List[str],
58+
actions: List[str]
5859
) -> None:
5960
"""Create a new ACL table type in Config DB.
6061
6162
Args:
6263
name: The name for the new ACL table type.
6364
matches: A list of matches to use in ACL table.
6465
bpoint_types: A list of bind point types to use in ACL table.
66+
actions: A list of actions to use in ACL table
6567
"""
6668
table_type_attrs = {
6769
"matches@": ",".join(matches),
68-
"bind_points@": ",".join(bpoint_types)
70+
"bind_points@": ",".join(bpoint_types),
71+
"actions@": ",".join(actions)
6972
}
7073

7174
self.config_db.create_entry(self.CDB_ACL_TABLE_TYPE_NAME, name, table_type_attrs)
@@ -306,6 +309,26 @@ def verify_acl_table_port_binding(
306309

307310
self.verify_acl_table_group_members(acl_table_id, acl_table_group_ids, num_tables)
308311

312+
313+
def verify_acl_table_action_list(
314+
self,
315+
acl_table_id: str,
316+
expected_action_list: List[str],
317+
) -> None:
318+
"""Verify that the ACL table has specified action list.
319+
Args:
320+
acl_table_id: The ACL table that is being checked.
321+
expected_action_list: The expected action list set to the given ACL table.
322+
"""
323+
fvs = self.asic_db.wait_for_entry(self.ADB_ACL_TABLE_NAME, acl_table_id)
324+
action_list_str = fvs.get('SAI_ACL_TABLE_ATTR_ACL_ACTION_TYPE_LIST')
325+
action_count, actions = action_list_str.split(':')
326+
action_list = actions.split(',')
327+
assert (int(action_count) == len(action_list))
328+
for action in expected_action_list:
329+
assert action in action_list
330+
331+
309332
def create_acl_rule(
310333
self,
311334
table_name: str,

tests/test_acl_egress_table.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"VLAN_ID"
1515
]
1616
CUSTOM_TABLE_TYPE_BPOINT_TYPES = ["PORT","PORTCHANNEL"]
17+
CUSTOM_TABLE_TYPE_ACTIONS = ["PACKET_ACTION,COUNTER"]
18+
EXPECTED_ACTION_LIST = ['SAI_ACL_ACTION_TYPE_PACKET_ACTION','SAI_ACL_ACTION_TYPE_COUNTER']
1719
TABLE_NAME = "EGRESS_TEST"
1820
BIND_PORTS = ["Ethernet0", "Ethernet4"]
1921
RULE_NAME = "EGRESS_TEST_RULE"
@@ -23,7 +25,7 @@ class TestEgressAclTable:
2325
@pytest.fixture
2426
def egress_acl_table(self, dvs_acl):
2527
try:
26-
dvs_acl.create_acl_table_type(TABLE_TYPE, CUSTOM_TABLE_TYPE_MATCHES, CUSTOM_TABLE_TYPE_BPOINT_TYPES)
28+
dvs_acl.create_acl_table_type(TABLE_TYPE, CUSTOM_TABLE_TYPE_MATCHES, CUSTOM_TABLE_TYPE_BPOINT_TYPES, CUSTOM_TABLE_TYPE_ACTIONS)
2729
dvs_acl.create_acl_table(TABLE_NAME, TABLE_TYPE, BIND_PORTS, stage="egress")
2830
yield dvs_acl.get_acl_table_ids(1)[0]
2931
finally:
@@ -33,14 +35,15 @@ def egress_acl_table(self, dvs_acl):
3335

3436
def test_EgressAclTableCreationDeletion(self, dvs_acl):
3537
try:
36-
dvs_acl.create_acl_table_type(TABLE_TYPE, CUSTOM_TABLE_TYPE_MATCHES, CUSTOM_TABLE_TYPE_BPOINT_TYPES)
38+
dvs_acl.create_acl_table_type(TABLE_TYPE, CUSTOM_TABLE_TYPE_MATCHES, CUSTOM_TABLE_TYPE_BPOINT_TYPES, CUSTOM_TABLE_TYPE_ACTIONS)
3739
dvs_acl.create_acl_table(TABLE_NAME, TABLE_TYPE, BIND_PORTS, stage="egress")
3840

3941
acl_table_id = dvs_acl.get_acl_table_ids(1)[0]
4042
acl_table_group_ids = dvs_acl.get_acl_table_group_ids(len(BIND_PORTS))
4143

4244
dvs_acl.verify_acl_table_group_members(acl_table_id, acl_table_group_ids, 1)
4345
dvs_acl.verify_acl_table_port_binding(acl_table_id, BIND_PORTS, 1, stage="egress")
46+
dvs_acl.verify_acl_table_action_list(acl_table_id, EXPECTED_ACTION_LIST)
4447
finally:
4548
dvs_acl.remove_acl_table(TABLE_NAME)
4649
dvs_acl.remove_acl_table_type(TABLE_TYPE)

0 commit comments

Comments
 (0)