@@ -72,6 +72,10 @@ class AclLoader(object):
72
72
73
73
ACL_TABLE = "ACL_TABLE"
74
74
ACL_RULE = "ACL_RULE"
75
+ CFG_ACL_TABLE = "ACL_TABLE"
76
+ STATE_ACL_TABLE = "ACL_TABLE_TABLE"
77
+ CFG_ACL_RULE = "ACL_RULE"
78
+ STATE_ACL_RULE = "ACL_RULE_TABLE"
75
79
ACL_TABLE_TYPE_MIRROR = "MIRROR"
76
80
ACL_TABLE_TYPE_CTRLPLANE = "CTRLPLANE"
77
81
CFG_MIRROR_SESSION_TABLE = "MIRROR_SESSION"
@@ -117,11 +121,16 @@ def __init__(self):
117
121
self .tables_db_info = {}
118
122
self .rules_db_info = {}
119
123
self .rules_info = {}
124
+ self .tables_state_info = None
125
+ self .rules_state_info = None
120
126
121
127
# Load database config files
122
128
load_db_config ()
123
129
124
130
self .sessions_db_info = {}
131
+ self .acl_table_status = {}
132
+ self .acl_rule_status = {}
133
+
125
134
self .configdb = ConfigDBConnector ()
126
135
self .configdb .connect ()
127
136
self .statedb = SonicV2Connector (host = "127.0.0.1" )
@@ -156,6 +165,8 @@ def __init__(self):
156
165
self .read_rules_info ()
157
166
self .read_sessions_info ()
158
167
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 )
159
170
160
171
def read_tables_info (self ):
161
172
"""
@@ -210,7 +221,7 @@ def read_sessions_info(self):
210
221
for key in self .sessions_db_info :
211
222
if self .per_npu_statedb :
212
223
# For multi-npu platforms we will read from all front asic name space
213
- # statedb as the monitor port will be differnt for each asic
224
+ # statedb as the monitor port will be different for each asic
214
225
# and it's status also might be different (ideally should not happen)
215
226
# We will store them as dict of 'asic' : value
216
227
self .sessions_db_info [key ]["status" ] = {}
@@ -224,6 +235,35 @@ def read_sessions_info(self):
224
235
self .sessions_db_info [key ]["status" ] = state_db_info .get ("status" , "inactive" ) if state_db_info else "error"
225
236
self .sessions_db_info [key ]["monitor_port" ] = state_db_info .get ("monitor_port" , "" ) if state_db_info else ""
226
237
238
+ def read_acl_object_status_info (self , cfg_db_table_name , state_db_table_name ):
239
+ """
240
+ Read ACL_TABLE status or ACL_RULE status from STATE_DB
241
+ """
242
+ if self .per_npu_configdb :
243
+ namespace_configdb = list (self .per_npu_configdb .values ())[0 ]
244
+ keys = namespace_configdb .get_table (cfg_db_table_name ).keys ()
245
+ else :
246
+ keys = self .configdb .get_table (cfg_db_table_name ).keys ()
247
+
248
+ status = {}
249
+ for key in keys :
250
+ # For ACL_RULE, the key is (acl_table_name, acl_rule_name)
251
+ if isinstance (key , tuple ):
252
+ state_db_key = key [0 ] + "|" + key [1 ]
253
+ else :
254
+ state_db_key = key
255
+ status [key ] = {}
256
+ if self .per_npu_statedb :
257
+ status [key ]['status' ] = {}
258
+ for namespace_key , namespace_statedb in self .per_npu_statedb .items ():
259
+ state_db_info = namespace_statedb .get_all (self .statedb .STATE_DB , "{}|{}" .format (state_db_table_name , state_db_key ))
260
+ status [key ]['status' ][namespace_key ] = state_db_info .get ("status" , "N/A" ) if state_db_info else "N/A"
261
+ else :
262
+ state_db_info = self .statedb .get_all (self .statedb .STATE_DB , "{}|{}" .format (state_db_table_name , state_db_key ))
263
+ status [key ]['status' ] = state_db_info .get ("status" , "N/A" ) if state_db_info else "N/A"
264
+
265
+ return status
266
+
227
267
def get_sessions_db_info (self ):
228
268
return self .sessions_db_info
229
269
@@ -786,32 +826,36 @@ def show_table(self, table_name):
786
826
:param table_name: Optional. ACL table name. Filter tables by specified name.
787
827
:return:
788
828
"""
789
- header = ("Name" , "Type" , "Binding" , "Description" , "Stage" )
829
+ header = ("Name" , "Type" , "Binding" , "Description" , "Stage" , "Status" )
790
830
791
831
data = []
792
832
for key , val in self .get_tables_db_info ().items ():
793
833
if table_name and key != table_name :
794
834
continue
795
-
835
+
796
836
stage = val .get ("stage" , Stage .INGRESS ).lower ()
797
-
837
+ # Get ACL table status from STATE_DB
838
+ if key in self .acl_table_status :
839
+ status = self .acl_table_status [key ]['status' ]
840
+ else :
841
+ status = 'N/A'
798
842
if val ["type" ] == AclLoader .ACL_TABLE_TYPE_CTRLPLANE :
799
843
services = natsorted (val ["services" ])
800
- data .append ([key , val ["type" ], services [0 ], val ["policy_desc" ], stage ])
844
+ data .append ([key , val ["type" ], services [0 ], val ["policy_desc" ], stage , status ])
801
845
802
846
if len (services ) > 1 :
803
847
for service in services [1 :]:
804
- data .append (["" , "" , service , "" , "" ])
848
+ data .append (["" , "" , service , "" , "" , "" ])
805
849
else :
806
850
if not val ["ports" ]:
807
- data .append ([key , val ["type" ], "" , val ["policy_desc" ], stage ])
851
+ data .append ([key , val ["type" ], "" , val ["policy_desc" ], stage , status ])
808
852
else :
809
853
ports = natsorted (val ["ports" ])
810
- data .append ([key , val ["type" ], ports [0 ], val ["policy_desc" ], stage ])
854
+ data .append ([key , val ["type" ], ports [0 ], val ["policy_desc" ], stage , status ])
811
855
812
856
if len (ports ) > 1 :
813
857
for port in ports [1 :]:
814
- data .append (["" , "" , port , "" , "" ])
858
+ data .append (["" , "" , port , "" , "" , "" ])
815
859
816
860
print (tabulate .tabulate (data , headers = header , tablefmt = "simple" , missingval = "" ))
817
861
@@ -871,7 +915,7 @@ def show_rule(self, table_name, rule_id):
871
915
:param rule_id: Optional. ACL rule name. Filter rule by specified rule name.
872
916
:return:
873
917
"""
874
- header = ("Table" , "Rule" , "Priority" , "Action" , "Match" )
918
+ header = ("Table" , "Rule" , "Priority" , "Action" , "Match" , "Status" )
875
919
876
920
def pop_priority (val ):
877
921
priority = "N/A"
@@ -917,11 +961,16 @@ def pop_matches(val):
917
961
priority = pop_priority (val )
918
962
action = pop_action (val )
919
963
matches = pop_matches (val )
920
-
921
- rule_data = [[tname , rid , priority , action , matches [0 ]]]
964
+ # Get ACL rule status from STATE_DB
965
+ status_key = (tname , rid )
966
+ if status_key in self .acl_rule_status :
967
+ status = self .acl_rule_status [status_key ]['status' ]
968
+ else :
969
+ status = "N/A"
970
+ rule_data = [[tname , rid , priority , action , matches [0 ], status ]]
922
971
if len (matches ) > 1 :
923
972
for m in matches [1 :]:
924
- rule_data .append (["" , "" , "" , "" , m ])
973
+ rule_data .append (["" , "" , "" , "" , m , "" ])
925
974
926
975
raw_data .append ([priority , rule_data ])
927
976
0 commit comments