@@ -46,6 +46,10 @@ class AclStat(object):
46
46
"""
47
47
Process aclstat
48
48
"""
49
+
50
+ ACL_TABLE = "ACL_TABLE"
51
+ ACL_RULE = "ACL_RULE"
52
+
49
53
def __init__ (self , ports , rules , tables ):
50
54
self .port_map = {}
51
55
self .acl_tables = {}
@@ -65,9 +69,11 @@ class AclStat(object):
65
69
66
70
# Set up db connections
67
71
self .db = swsssdk .SonicV2Connector (host = "127.0.0.1" )
68
- self .db .connect (self .db .APPL_DB )
69
72
self .db .connect (self .db .COUNTERS_DB )
70
73
74
+ self .configdb = swsssdk .ConfigDBConnector ()
75
+ self .configdb .connect ()
76
+
71
77
self .read_port_map ()
72
78
self .validate_ports ()
73
79
@@ -127,26 +133,7 @@ class AclStat(object):
127
133
"""
128
134
Get ACL tables from the DB
129
135
"""
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 )
150
137
151
138
if verboseflag :
152
139
print ("ACL Tables to show:" , len (self .acl_tables ))
@@ -155,24 +142,7 @@ class AclStat(object):
155
142
"""
156
143
Get ACL rules from the DB
157
144
"""
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 )
176
146
177
147
if verboseflag :
178
148
print ("ACL Rules to show:" , len (self .acl_rules ))
@@ -218,7 +188,7 @@ class AclStat(object):
218
188
print out ACL rules and counters
219
189
"""
220
190
def get_action (rule ):
221
- for action in ['packet_action ' , 'mirror_action ' ]:
191
+ for action in ['PACKET_ACTION ' , 'MIRROR_ACTION ' ]:
222
192
if action in rule :
223
193
return rule [action ]
224
194
return "(no action found)"
@@ -231,9 +201,9 @@ class AclStat(object):
231
201
continue
232
202
rule = self .acl_rules [rule_key ]
233
203
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 ' ],
237
207
get_action (rule ),
238
208
self .get_counter_value (rule_key , 'packets' ),
239
209
self .get_counter_value (rule_key , 'bytes' )]
0 commit comments