Skip to content

Commit be2d5c8

Browse files
oleksandrivantsivlguohan
authored andcommitted
[aclshow]: Move ACL show command to Config DB. (sonic-net#144)
1 parent 1d37c9c commit be2d5c8

File tree

1 file changed

+13
-43
lines changed

1 file changed

+13
-43
lines changed

scripts/aclshow

+13-43
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class AclStat(object):
4646
"""
4747
Process aclstat
4848
"""
49+
50+
ACL_TABLE = "ACL_TABLE"
51+
ACL_RULE = "ACL_RULE"
52+
4953
def __init__(self, ports, rules, tables):
5054
self.port_map = {}
5155
self.acl_tables = {}
@@ -65,9 +69,11 @@ class AclStat(object):
6569

6670
# Set up db connections
6771
self.db = swsssdk.SonicV2Connector(host="127.0.0.1")
68-
self.db.connect(self.db.APPL_DB)
6972
self.db.connect(self.db.COUNTERS_DB)
7073

74+
self.configdb = swsssdk.ConfigDBConnector()
75+
self.configdb.connect()
76+
7177
self.read_port_map()
7278
self.validate_ports()
7379

@@ -127,26 +133,7 @@ class AclStat(object):
127133
"""
128134
Get ACL tables from the DB
129135
"""
130-
tables = self.db.keys(self.db.APPL_DB, "ACL_TABLE:*")
131-
132-
if verboseflag:
133-
print("ACL Tables found:", len(tables))
134-
135-
if not tables:
136-
return
137-
138-
for table in tables:
139-
table_name = table.split(":")[1]
140-
if self.table_list and not table_name in self.table_list:
141-
continue
142-
143-
table_props = self.db.get_all(self.db.APPL_DB, table)
144-
145-
if self.port_list:
146-
table_port_list = table_props['ports'].split(",")
147-
if not self.intersect(self.port_list, table_port_list):
148-
continue
149-
self.acl_tables[table_name] = table_props
136+
self.acl_tables = self.configdb.get_table(self.ACL_TABLE)
150137

151138
if verboseflag:
152139
print("ACL Tables to show:", len(self.acl_tables))
@@ -155,24 +142,7 @@ class AclStat(object):
155142
"""
156143
Get ACL rules from the DB
157144
"""
158-
for table_name in self.acl_tables.keys():
159-
rules = self.db.keys(self.db.APPL_DB, "ACL_RULE_TABLE:%s:*" % table_name)
160-
if not rules:
161-
if verboseflag:
162-
print("No ACL rules found in %s" % table_name)
163-
continue
164-
165-
if verboseflag:
166-
rules_cnt = len(rules)
167-
print("ACL Rules found in %s:" % table_name, rules_cnt)
168-
169-
for rule in rules:
170-
rule_name = rule.split(":")[2]
171-
if self.rule_list and not rule_name in self.rule_list:
172-
continue
173-
rule_props = lowercase_keys(self.db.get_all(self.db.APPL_DB, rule))
174-
rule_props["table"] = table_name
175-
self.acl_rules[table_name, rule_name] = rule_props
145+
self.acl_rules = self.configdb.get_table(self.ACL_RULE)
176146

177147
if verboseflag:
178148
print("ACL Rules to show:", len(self.acl_rules))
@@ -218,7 +188,7 @@ class AclStat(object):
218188
print out ACL rules and counters
219189
"""
220190
def get_action(rule):
221-
for action in ['packet_action', 'mirror_action']:
191+
for action in ['PACKET_ACTION', 'MIRROR_ACTION']:
222192
if action in rule:
223193
return rule[action]
224194
return "(no action found)"
@@ -231,9 +201,9 @@ class AclStat(object):
231201
continue
232202
rule = self.acl_rules[rule_key]
233203
ports = self.acl_tables[rule_key[0]]['ports']
234-
line = [rule_key[1], rule['table'],
235-
self.acl_tables[rule['table']]['type'],
236-
rule['priority'],
204+
line = [rule_key[1], rule_key[0],
205+
self.acl_tables[rule_key[0]]['type'],
206+
rule['PRIORITY'],
237207
get_action(rule),
238208
self.get_counter_value(rule_key, 'packets'),
239209
self.get_counter_value(rule_key, 'bytes')]

0 commit comments

Comments
 (0)