Skip to content

Commit fc2fa78

Browse files
madhanmellanoxMadhan Babu
and
Madhan Babu
authored
handled the priority of ACL rules to be case insensitive (sonic-net#918)
* 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 <[email protected]>
1 parent a21e01a commit fc2fa78

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

acl_loader/main.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,11 @@ def show_rule(self, table_name, rule_id):
762762
header = ("Table", "Rule", "Priority", "Action", "Match")
763763

764764
def pop_priority(val):
765-
priority = val.pop("PRIORITY")
765+
priority = "N/A"
766+
for key in dict(val):
767+
if (key.upper() == "PRIORITY"):
768+
priority = val.pop(key)
769+
return priority
766770
return priority
767771

768772
def pop_action(val):

scripts/aclshow

+5-1
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,12 @@ class AclStat(object):
169169
self.get_counter_value(rule_key, 'packets') == 'N/A'):
170170
continue
171171
rule = self.acl_rules[rule_key]
172+
rule_priority = -1
173+
for key,val in rule.items():
174+
if key.upper() == "PRIORITY":
175+
rule_priority = val
172176
line = [rule_key[1], rule_key[0],
173-
rule['PRIORITY'],
177+
rule_priority,
174178
self.get_counter_value(rule_key, 'packets'),
175179
self.get_counter_value(rule_key, 'bytes')]
176180
aclstat.append(line)

sonic-utilities-tests/aclshow_test.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
RULE_4 DATAACL 9996 401 400
2525
RULE_7 DATAACL 9993 701 700
2626
RULE_9 DATAACL 9991 901 900
27+
RULE_10 DATAACL 9989 1001 1000
2728
DEFAULT_RULE DATAACL 1 2 1
2829
RULE_6 EVERFLOW 9994 601 600
2930
"""
@@ -39,6 +40,7 @@
3940
RULE_05 DATAACL 9995 0 0
4041
RULE_7 DATAACL 9993 701 700
4142
RULE_9 DATAACL 9991 901 900
43+
RULE_10 DATAACL 9989 1001 1000
4244
DEFAULT_RULE DATAACL 1 2 1
4345
RULE_6 EVERFLOW 9994 601 600
4446
RULE_08 EVERFLOW 9992 0 0
@@ -51,6 +53,13 @@
5153
RULE_1 DATAACL 9999 101 100
5254
"""
5355

56+
# Expected output for aclshow -r RULE_1 -t DATAACL
57+
rule10_dataacl_output = '' + \
58+
"""RULE NAME TABLE NAME PRIO PACKETS COUNT BYTES COUNT
59+
----------- ------------ ------ --------------- -------------
60+
RULE_10 DATAACL 9989 1001 1000
61+
"""
62+
5463
# Expected output for aclshow -a -r RULE_05
5564
rule05_all_output = ''+ \
5665
"""RULE NAME TABLE NAME PRIO PACKETS COUNT BYTES COUNT
@@ -68,7 +77,7 @@
6877
rule4_rule6_verbose_output = '' + \
6978
"""Reading ACL info...
7079
Total number of ACL Tables: 5
71-
Total number of ACL Rules: 10
80+
Total number of ACL Rules: 11
7281
7382
RULE NAME TABLE NAME PRIO PACKETS COUNT BYTES COUNT
7483
----------- ------------ ------ --------------- -------------
@@ -93,6 +102,7 @@
93102
RULE_4 DATAACL 9996 401 400
94103
RULE_7 DATAACL 9993 701 700
95104
RULE_9 DATAACL 9991 901 900
105+
RULE_10 DATAACL 9989 1001 1000
96106
DEFAULT_RULE DATAACL 1 2 1
97107
"""
98108

@@ -111,6 +121,7 @@
111121
RULE_05 DATAACL 9995 0 0
112122
RULE_7 DATAACL 9993 0 0
113123
RULE_9 DATAACL 9991 0 0
124+
RULE_10 DATAACL 9989 0 0
114125
DEFAULT_RULE DATAACL 1 0 0
115126
RULE_6 EVERFLOW 9994 0 0
116127
RULE_08 EVERFLOW 9992 0 0
@@ -184,6 +195,11 @@ def test_rule0():
184195
test = Aclshow(all = None, clear = None, rules = 'RULE_0', tables = None, verbose = None)
185196
assert test.result.getvalue() == rule0_output
186197

198+
# aclshow -r RULE_10 -t DATAACL
199+
def test_rule10_lowercase_priority():
200+
test = Aclshow(all = None, clear = None, rules = 'RULE_10', tables = 'DATAACL', verbose = None)
201+
assert test.result.getvalue() == rule10_dataacl_output
202+
187203
# aclshow -r RULE_4,RULE_6 -vv
188204
def test_rule4_rule6_verbose():
189205
test = Aclshow(all = None, clear = None, rules = 'RULE_4,RULE_6', tables = None, verbose = True)

sonic-utilities-tests/mock_tables/config_db.json

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@
9393
"L4_DST_PORT": "4661",
9494
"PACKET_ACTION": "FORWARD",
9595
"PRIORITY": "9991"
96+
},
97+
"ACL_RULE|DATAACL|RULE_10": {
98+
"PACKET_ACTION": "DROP",
99+
"priority": "9989",
100+
"SRC_IP": "10.0.0.3/32"
96101
},
97102
"ACL_TABLE|DATAACL": {
98103
"policy_desc": "DATAACL",

sonic-utilities-tests/mock_tables/counters_db.json

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@
115115
"Bytes": "900",
116116
"Packets": "901"
117117
},
118+
"COUNTERS:DATAACL:RULE_10": {
119+
"Bytes": "1000",
120+
"Packets": "1001"
121+
},
118122
"COUNTERS:oid:0x1000000000002": {
119123
"SAI_PORT_STAT_IF_IN_ERRORS": "10",
120124
"SAI_PORT_STAT_IF_IN_DISCARDS": "100",

0 commit comments

Comments
 (0)