@@ -73,8 +73,10 @@ class AclLoader(object):
73
73
ACL_TABLE = "ACL_TABLE"
74
74
ACL_RULE = "ACL_RULE"
75
75
CFG_ACL_TABLE = "ACL_TABLE"
76
+ APPL_ACL_TABLE = "ACL_TABLE_TABLE"
76
77
STATE_ACL_TABLE = "ACL_TABLE_TABLE"
77
78
CFG_ACL_RULE = "ACL_RULE"
79
+ APPL_ACL_RULE = "ACL_RULE_TABLE"
78
80
STATE_ACL_RULE = "ACL_RULE_TABLE"
79
81
ACL_TABLE_TYPE_MIRROR = "MIRROR"
80
82
ACL_TABLE_TYPE_CTRLPLANE = "CTRLPLANE"
@@ -135,6 +137,8 @@ def __init__(self):
135
137
self .configdb .connect ()
136
138
self .statedb = SonicV2Connector (host = "127.0.0.1" )
137
139
self .statedb .connect (self .statedb .STATE_DB )
140
+ self .appldb = SonicV2Connector (host = "127.0.0.1" )
141
+ self .appldb .connect (self .statedb .APPL_DB )
138
142
139
143
# For multi-npu architecture we will have both global and per front asic namespace.
140
144
# Global namespace will be used for Control plane ACL which are via IPTables.
@@ -165,8 +169,8 @@ def __init__(self):
165
169
self .read_rules_info ()
166
170
self .read_sessions_info ()
167
171
self .read_policers_info ()
168
- self .acl_table_status = self .read_acl_object_status_info (self .CFG_ACL_TABLE , self .STATE_ACL_TABLE )
169
- self .acl_rule_status = self .read_acl_object_status_info (self .CFG_ACL_RULE , self .STATE_ACL_RULE )
172
+ self .acl_table_status = self .read_acl_object_status_info (self .tables_db_info . keys () , self .STATE_ACL_TABLE )
173
+ self .acl_rule_status = self .read_acl_object_status_info (self .rules_db_info . keys () , self .STATE_ACL_RULE )
170
174
171
175
def read_tables_info (self ):
172
176
"""
@@ -199,16 +203,51 @@ def read_tables_info(self):
199
203
self .tables_db_info [table ]['ports' ] += entry .get (
200
204
'ports' , [])
201
205
206
+ if self .per_npu_configdb :
207
+ # Note: Ability to read table information from APPL_DB is not yet supported for masic devices
208
+ return
209
+
210
+ appl_db_keys = self .appldb .keys (self .appldb .APPL_DB , "{}:*" .format (self .APPL_ACL_TABLE ))
211
+ if not appl_db_keys :
212
+ return
213
+
214
+ for app_acl_tbl in appl_db_keys :
215
+ key = app_acl_tbl .split (":" )[- 1 ]
216
+ if key in self .tables_db_info :
217
+ # Shouldn't be hit, table is either programmed to APPL or CONFIG DB
218
+ continue
219
+ self .tables_db_info [key ] = dict ()
220
+ for f , v in self .appldb .get_all (self .appldb .APPL_DB , app_acl_tbl ).items ():
221
+ if f .lower () == "ports" :
222
+ v = v .split ("," )
223
+ self .tables_db_info [key ][f .lower ()] = v
224
+
202
225
def get_tables_db_info (self ):
203
226
return self .tables_db_info
204
227
205
228
def read_rules_info (self ):
206
229
"""
207
- Read ACL_RULE table from configuration database
230
+ Read ACL_RULE table from CFG_DB and APPL_DB database
208
231
:return:
209
232
"""
210
233
self .rules_db_info = self .configdb .get_table (self .ACL_RULE )
211
234
235
+ if self .per_npu_configdb :
236
+ # Note: Ability to read table information from APPL_DB is not yet supported for masic devices
237
+ return
238
+
239
+ # Read rule information from APPL_DB
240
+ appl_db_keys = self .appldb .keys (self .appldb .APPL_DB , "{}:*" .format (self .APPL_ACL_RULE ))
241
+ if not appl_db_keys :
242
+ return
243
+
244
+ for app_acl_rule in appl_db_keys :
245
+ _ , tid , rid = app_acl_rule .split (":" )
246
+ if (tid , rid ) in self .rules_db_info :
247
+ # Shouldn't be hit, table is either programmed to APPL or CONFIG DB
248
+ continue
249
+ self .rules_db_info [(tid , rid )] = self .appldb .get_all (self .appldb .APPL_DB , app_acl_rule )
250
+
212
251
def get_rules_db_info (self ):
213
252
return self .rules_db_info
214
253
@@ -259,16 +298,10 @@ def read_sessions_info(self):
259
298
self .sessions_db_info [key ]["status" ] = state_db_info .get ("status" , "inactive" ) if state_db_info else "error"
260
299
self .sessions_db_info [key ]["monitor_port" ] = state_db_info .get ("monitor_port" , "" ) if state_db_info else ""
261
300
262
- def read_acl_object_status_info (self , cfg_db_table_name , state_db_table_name ):
301
+ def read_acl_object_status_info (self , keys , state_db_table_name ):
263
302
"""
264
303
Read ACL_TABLE status or ACL_RULE status from STATE_DB
265
304
"""
266
- if self .per_npu_configdb :
267
- namespace_configdb = list (self .per_npu_configdb .values ())[0 ]
268
- keys = namespace_configdb .get_table (cfg_db_table_name ).keys ()
269
- else :
270
- keys = self .configdb .get_table (cfg_db_table_name ).keys ()
271
-
272
305
status = {}
273
306
for key in keys :
274
307
# For ACL_RULE, the key is (acl_table_name, acl_rule_name)
@@ -922,19 +955,19 @@ def show_table(self, table_name):
922
955
status = self .acl_table_status [key ]['status' ]
923
956
else :
924
957
status = 'N/A'
925
- if val [ "type" ] == AclLoader .ACL_TABLE_TYPE_CTRLPLANE :
958
+ if val . get ( "type" , "N/A" ) == AclLoader .ACL_TABLE_TYPE_CTRLPLANE :
926
959
services = natsorted (val ["services" ])
927
- data .append ([key , val [ "type" ], services [0 ], val [ "policy_desc" ] , stage , status ])
960
+ data .append ([key , val . get ( "type" , "N/A" ), services [0 ], val . get ( "policy_desc" , "" ) , stage , status ])
928
961
929
962
if len (services ) > 1 :
930
963
for service in services [1 :]:
931
964
data .append (["" , "" , service , "" , "" , "" ])
932
965
else :
933
- if not val [ "ports" ] :
934
- data .append ([key , val ["type" ], "" , val [ "policy_desc" ] , stage , status ])
966
+ if not val . get ( "ports" , []) :
967
+ data .append ([key , val ["type" ], "" , val . get ( "policy_desc" , "" ) , stage , status ])
935
968
else :
936
969
ports = natsorted (val ["ports" ])
937
- data .append ([key , val ["type" ], ports [0 ], val [ "policy_desc" ] , stage , status ])
970
+ data .append ([key , val ["type" ], ports [0 ], val . get ( "policy_desc" , "" ) , stage , status ])
938
971
939
972
if len (ports ) > 1 :
940
973
for port in ports [1 :]:
0 commit comments