1
- #!/usr/bin/env python3
1
+ #!/usr/bin/python3
2
2
3
3
#####################################################################
4
4
#
@@ -38,15 +38,19 @@ from utilities_common import constants
38
38
import utilities_common .multi_asic as multi_asic_util
39
39
40
40
QueueStats = namedtuple ("QueueStats" , "queueindex, queuetype, totalpacket, totalbytes, droppacket, dropbytes" )
41
+ VoqStats = namedtuple ("VoqStats" , "queueindex, queuetype, totalpacket, totalbytes, droppacket, dropbytes, creditWDpkts" )
41
42
header = ['Port' , 'TxQ' , 'Counter/pkts' , 'Counter/bytes' , 'Drop/pkts' , 'Drop/bytes' ]
42
- voq_header = ['Port' , 'Voq' , 'Counter/pkts' , 'Counter/bytes' , 'Drop/pkts' , 'Drop/bytes' ]
43
+ voq_header = ['Port' , 'Voq' , 'Counter/pkts' , 'Counter/bytes' , 'Drop/pkts' , 'Drop/bytes' , 'Credit-WD-Del/pkts' ]
43
44
44
45
counter_bucket_dict = {
45
46
'SAI_QUEUE_STAT_PACKETS' : 2 ,
46
47
'SAI_QUEUE_STAT_BYTES' : 3 ,
47
48
'SAI_QUEUE_STAT_DROPPED_PACKETS' : 4 ,
48
49
'SAI_QUEUE_STAT_DROPPED_BYTES' : 5 ,
49
50
}
51
+ voq_counter_bucket_dict = {
52
+ 'SAI_QUEUE_STAT_CREDIT_WD_DELETED_PACKETS' : 6
53
+ }
50
54
51
55
from utilities_common .cli import json_dump
52
56
from utilities_common .netstat import ns_diff , STATUS_NA
@@ -73,15 +77,24 @@ cnstat_dir = 'N/A'
73
77
cnstat_fqn_file = 'N/A'
74
78
75
79
76
- def build_json (port , cnstat ):
80
+ def build_json (port , cnstat , voq = False ):
77
81
def ports_stats (k ):
78
82
p = {}
79
- p [k [1 ]] = {
80
- "totalpacket" : k [2 ],
81
- "totalbytes" : k [3 ],
82
- "droppacket" : k [4 ],
83
- "dropbytes" : k [5 ]
84
- }
83
+ if voq :
84
+ p [k [1 ]] = {
85
+ "totalpacket" : k [2 ],
86
+ "totalbytes" : k [3 ],
87
+ "droppacket" : k [4 ],
88
+ "dropbytes" : k [5 ],
89
+ "creditWDPkts" : k [6 ]
90
+ }
91
+ else :
92
+ p [k [1 ]] = {
93
+ "totalpacket" : k [2 ],
94
+ "totalbytes" : k [3 ],
95
+ "droppacket" : k [4 ],
96
+ "dropbytes" : k [5 ]
97
+ }
85
98
return p
86
99
87
100
out = {}
@@ -175,18 +188,30 @@ class Queuestat(object):
175
188
print ("Queue Type is invalid:" , table_id , queue_type )
176
189
sys .exit (1 )
177
190
178
- fields = ["0" ,"0" ,"0" ,"0" ,"0" ,"0" ]
191
+ if self .voq :
192
+ fields = ["0" ,"0" ,"0" ,"0" ,"0" ,"0" ,"0" ]
193
+ else :
194
+ fields = ["0" ,"0" ,"0" ,"0" ,"0" ,"0" ]
179
195
fields [0 ] = get_queue_index (table_id )
180
196
fields [1 ] = get_queue_type (table_id )
181
197
182
- for counter_name , pos in counter_bucket_dict .items ():
198
+ counter_dict = {}
199
+ counter_dict .update (counter_bucket_dict )
200
+ if self .voq :
201
+ counter_dict .update (voq_counter_bucket_dict )
202
+
203
+ for counter_name , pos in counter_dict .items ():
183
204
full_table_id = COUNTER_TABLE_PREFIX + table_id
184
205
counter_data = self .db .get (self .db .COUNTERS_DB , full_table_id , counter_name )
185
206
if counter_data is None :
186
207
fields [pos ] = STATUS_NA
187
208
elif fields [pos ] != STATUS_NA :
188
209
fields [pos ] = str (int (counter_data ))
189
- cntr = QueueStats ._make (fields )._asdict ()
210
+
211
+ if self .voq :
212
+ cntr = VoqStats ._make (fields )._asdict ()
213
+ else :
214
+ cntr = QueueStats ._make (fields )._asdict ()
190
215
return cntr
191
216
192
217
# Build a dictionary of the stats
@@ -211,14 +236,21 @@ class Queuestat(object):
211
236
if json_opt :
212
237
json_output [port ][key ] = data
213
238
continue
214
- if not non_zero or data ['totalpacket' ] != '0' or data ['totalbytes' ] != '0' or \
215
- data ['droppacket' ] != '0' or data ['dropbytes' ] != '0' :
216
- table .append ((port , data ['queuetype' ] + str (data ['queueindex' ]),
217
- data ['totalpacket' ], data ['totalbytes' ],
218
- data ['droppacket' ], data ['dropbytes' ]))
239
+ if self .voq :
240
+ if not non_zero or data ['totalpacket' ] != '0' or data ['totalbytes' ] != '0' or \
241
+ data ['droppacket' ] != '0' or data ['dropbytes' ] != '0' or data ['creditWDpkts' ] != '0' :
242
+ table .append ((port , data ['queuetype' ] + str (data ['queueindex' ]),
243
+ data ['totalpacket' ], data ['totalbytes' ],
244
+ data ['droppacket' ], data ['dropbytes' ], data ['creditWDpkts' ]))
245
+ else :
246
+ if not non_zero or data ['totalpacket' ] != '0' or data ['totalbytes' ] != '0' or \
247
+ data ['droppacket' ] != '0' or data ['dropbytes' ] != '0' :
248
+ table .append ((port , data ['queuetype' ] + str (data ['queueindex' ]),
249
+ data ['totalpacket' ], data ['totalbytes' ],
250
+ data ['droppacket' ], data ['dropbytes' ]))
219
251
220
252
if json_opt :
221
- json_output [port ].update (build_json (port , table ))
253
+ json_output [port ].update (build_json (port , table , self . voq ))
222
254
return json_output
223
255
else :
224
256
hdr = voq_header if self .voq else header
@@ -242,25 +274,42 @@ class Queuestat(object):
242
274
old_cntr = None
243
275
if key in cnstat_old_dict :
244
276
old_cntr = cnstat_old_dict .get (key )
245
-
246
277
if old_cntr is not None :
247
- if not non_zero or ns_diff (cntr ['totalpacket' ], old_cntr ['totalpacket' ]) != '0' or \
278
+ if self .voq :
279
+ if not non_zero or ns_diff (cntr ['totalpacket' ], old_cntr ['totalpacket' ]) != '0' or \
280
+ ns_diff (cntr ['totalbytes' ], old_cntr ['totalbytes' ]) != '0' or \
281
+ ns_diff (cntr ['droppacket' ], old_cntr ['droppacket' ]) != '0' or \
282
+ ns_diff (cntr ['dropbytes' ], old_cntr ['dropbytes' ]) != '0' or \
283
+ ns_diff (cntr ['creditWDpkts' ], old_cntr ['creditWDpkts' ]) != '0' :
284
+ table .append ((port , cntr ['queuetype' ] + str (cntr ['queueindex' ]),
285
+ ns_diff (cntr ['totalpacket' ], old_cntr ['totalpacket' ]),
286
+ ns_diff (cntr ['totalbytes' ], old_cntr ['totalbytes' ]),
287
+ ns_diff (cntr ['droppacket' ], old_cntr ['droppacket' ]),
288
+ ns_diff (cntr ['dropbytes' ], old_cntr ['dropbytes' ]),
289
+ ns_diff (cntr ['creditWDpkts' ], old_cntr ['creditWDpkts' ])))
290
+ elif not non_zero or cntr ['totalpacket' ] != '0' or cntr ['totalbytes' ] != '0' or \
291
+ cntr ['droppacket' ] != '0' or cntr ['dropbytes' ] != '0' or cntr ['creditWDpkts' ] != '0' :
292
+ table .append ((port , cntr ['queuetype' ] + str (cntr ['queueindex' ]),
293
+ cntr ['totalpacket' ], cntr ['totalbytes' ],
294
+ cntr ['droppacket' ], cntr ['dropbytes' ], cntr ['creditWDpkts' ]))
295
+ else :
296
+ if not non_zero or ns_diff (cntr ['totalpacket' ], old_cntr ['totalpacket' ]) != '0' or \
248
297
ns_diff (cntr ['totalbytes' ], old_cntr ['totalbytes' ]) != '0' or \
249
298
ns_diff (cntr ['droppacket' ], old_cntr ['droppacket' ]) != '0' or \
250
299
ns_diff (cntr ['dropbytes' ], old_cntr ['dropbytes' ]) != '0' :
251
- table .append ((port , cntr ['queuetype' ] + str (cntr ['queueindex' ]),
252
- ns_diff (cntr ['totalpacket' ], old_cntr ['totalpacket' ]),
253
- ns_diff (cntr ['totalbytes' ], old_cntr ['totalbytes' ]),
254
- ns_diff (cntr ['droppacket' ], old_cntr ['droppacket' ]),
255
- ns_diff (cntr ['dropbytes' ], old_cntr ['dropbytes' ])))
256
- elif not non_zero or cntr ['totalpacket' ] != '0' or cntr ['totalbytes' ] != '0' or \
300
+ table .append ((port , cntr ['queuetype' ] + str (cntr ['queueindex' ]),
301
+ ns_diff (cntr ['totalpacket' ], old_cntr ['totalpacket' ]),
302
+ ns_diff (cntr ['totalbytes' ], old_cntr ['totalbytes' ]),
303
+ ns_diff (cntr ['droppacket' ], old_cntr ['droppacket' ]),
304
+ ns_diff (cntr ['dropbytes' ], old_cntr ['dropbytes' ])))
305
+ elif not non_zero or cntr ['totalpacket' ] != '0' or cntr ['totalbytes' ] != '0' or \
257
306
cntr ['droppacket' ] != '0' or cntr ['dropbytes' ] != '0' :
258
- table .append ((port , cntr ['queuetype' ] + str (cntr ['queueindex' ]),
259
- cntr ['totalpacket' ], cntr ['totalbytes' ],
260
- cntr ['droppacket' ], cntr ['dropbytes' ]))
307
+ table .append ((port , cntr ['queuetype' ] + str (cntr ['queueindex' ]),
308
+ cntr ['totalpacket' ], cntr ['totalbytes' ],
309
+ cntr ['droppacket' ], cntr ['dropbytes' ]))
261
310
262
311
if json_opt :
263
- json_output [port ].update (build_json (port , table ))
312
+ json_output [port ].update (build_json (port , table , self . voq ))
264
313
return json_output
265
314
else :
266
315
hdr = voq_header if self .voq else header
0 commit comments