Skip to content

Commit

Permalink
handled the priority of ACL rules to be case insensitive (sonic-net#918)
Browse files Browse the repository at this point in the history
* handled the priority of ACL rules to be case insensitive

* addressed code review comments of keyword Priority combinations and added a separate test case

Co-authored-by: Madhan Babu <madhan@arc-build-server.mtr.labs.mlnx>
  • Loading branch information
madhanmellanox and Madhan Babu authored Jun 15, 2020
1 parent a21e01a commit fc2fa78
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
6 changes: 5 additions & 1 deletion acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,11 @@ def show_rule(self, table_name, rule_id):
header = ("Table", "Rule", "Priority", "Action", "Match")

def pop_priority(val):
priority = val.pop("PRIORITY")
priority = "N/A"
for key in dict(val):
if (key.upper() == "PRIORITY"):
priority = val.pop(key)
return priority
return priority

def pop_action(val):
Expand Down
6 changes: 5 additions & 1 deletion scripts/aclshow
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,12 @@ class AclStat(object):
self.get_counter_value(rule_key, 'packets') == 'N/A'):
continue
rule = self.acl_rules[rule_key]
rule_priority = -1
for key,val in rule.items():
if key.upper() == "PRIORITY":
rule_priority = val
line = [rule_key[1], rule_key[0],
rule['PRIORITY'],
rule_priority,
self.get_counter_value(rule_key, 'packets'),
self.get_counter_value(rule_key, 'bytes')]
aclstat.append(line)
Expand Down
18 changes: 17 additions & 1 deletion sonic-utilities-tests/aclshow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
RULE_4 DATAACL 9996 401 400
RULE_7 DATAACL 9993 701 700
RULE_9 DATAACL 9991 901 900
RULE_10 DATAACL 9989 1001 1000
DEFAULT_RULE DATAACL 1 2 1
RULE_6 EVERFLOW 9994 601 600
"""
Expand All @@ -39,6 +40,7 @@
RULE_05 DATAACL 9995 0 0
RULE_7 DATAACL 9993 701 700
RULE_9 DATAACL 9991 901 900
RULE_10 DATAACL 9989 1001 1000
DEFAULT_RULE DATAACL 1 2 1
RULE_6 EVERFLOW 9994 601 600
RULE_08 EVERFLOW 9992 0 0
Expand All @@ -51,6 +53,13 @@
RULE_1 DATAACL 9999 101 100
"""

# Expected output for aclshow -r RULE_1 -t DATAACL
rule10_dataacl_output = '' + \
"""RULE NAME TABLE NAME PRIO PACKETS COUNT BYTES COUNT
----------- ------------ ------ --------------- -------------
RULE_10 DATAACL 9989 1001 1000
"""

# Expected output for aclshow -a -r RULE_05
rule05_all_output = ''+ \
"""RULE NAME TABLE NAME PRIO PACKETS COUNT BYTES COUNT
Expand All @@ -68,7 +77,7 @@
rule4_rule6_verbose_output = '' + \
"""Reading ACL info...
Total number of ACL Tables: 5
Total number of ACL Rules: 10
Total number of ACL Rules: 11
RULE NAME TABLE NAME PRIO PACKETS COUNT BYTES COUNT
----------- ------------ ------ --------------- -------------
Expand All @@ -93,6 +102,7 @@
RULE_4 DATAACL 9996 401 400
RULE_7 DATAACL 9993 701 700
RULE_9 DATAACL 9991 901 900
RULE_10 DATAACL 9989 1001 1000
DEFAULT_RULE DATAACL 1 2 1
"""

Expand All @@ -111,6 +121,7 @@
RULE_05 DATAACL 9995 0 0
RULE_7 DATAACL 9993 0 0
RULE_9 DATAACL 9991 0 0
RULE_10 DATAACL 9989 0 0
DEFAULT_RULE DATAACL 1 0 0
RULE_6 EVERFLOW 9994 0 0
RULE_08 EVERFLOW 9992 0 0
Expand Down Expand Up @@ -184,6 +195,11 @@ def test_rule0():
test = Aclshow(all = None, clear = None, rules = 'RULE_0', tables = None, verbose = None)
assert test.result.getvalue() == rule0_output

# aclshow -r RULE_10 -t DATAACL
def test_rule10_lowercase_priority():
test = Aclshow(all = None, clear = None, rules = 'RULE_10', tables = 'DATAACL', verbose = None)
assert test.result.getvalue() == rule10_dataacl_output

# aclshow -r RULE_4,RULE_6 -vv
def test_rule4_rule6_verbose():
test = Aclshow(all = None, clear = None, rules = 'RULE_4,RULE_6', tables = None, verbose = True)
Expand Down
5 changes: 5 additions & 0 deletions sonic-utilities-tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@
"L4_DST_PORT": "4661",
"PACKET_ACTION": "FORWARD",
"PRIORITY": "9991"
},
"ACL_RULE|DATAACL|RULE_10": {
"PACKET_ACTION": "DROP",
"priority": "9989",
"SRC_IP": "10.0.0.3/32"
},
"ACL_TABLE|DATAACL": {
"policy_desc": "DATAACL",
Expand Down
4 changes: 4 additions & 0 deletions sonic-utilities-tests/mock_tables/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
"Bytes": "900",
"Packets": "901"
},
"COUNTERS:DATAACL:RULE_10": {
"Bytes": "1000",
"Packets": "1001"
},
"COUNTERS:oid:0x1000000000002": {
"SAI_PORT_STAT_IF_IN_ERRORS": "10",
"SAI_PORT_STAT_IF_IN_DISCARDS": "100",
Expand Down

0 comments on commit fc2fa78

Please sign in to comment.