@@ -182,35 +182,46 @@ void DebugCounterOrch::doTask(Consumer& consumer)
182
182
// DROP_COUNTER_CAPABILITIES table in STATE_DB.
183
183
void DebugCounterOrch::publishDropCounterCapabilities ()
184
184
{
185
- string supported_ingress_drop_reasons = DropCounter::serializeSupportedDropReasons (
186
- DropCounter::getSupportedDropReasons (SAI_DEBUG_COUNTER_ATTR_IN_DROP_REASON_LIST));
187
- string supported_egress_drop_reasons = DropCounter::serializeSupportedDropReasons (
188
- DropCounter::getSupportedDropReasons (SAI_DEBUG_COUNTER_ATTR_OUT_DROP_REASON_LIST));
185
+ supported_ingress_drop_reasons = DropCounter::getSupportedDropReasons (SAI_DEBUG_COUNTER_ATTR_IN_DROP_REASON_LIST);
186
+ supported_egress_drop_reasons = DropCounter::getSupportedDropReasons (SAI_DEBUG_COUNTER_ATTR_OUT_DROP_REASON_LIST);
187
+
188
+ string ingress_drop_reason_str = DropCounter::serializeSupportedDropReasons (supported_ingress_drop_reasons);
189
+ string egress_drop_reason_str = DropCounter::serializeSupportedDropReasons (supported_egress_drop_reasons);
189
190
190
191
for (auto const &counter_type : DebugCounter::getDebugCounterTypeLookup ())
191
192
{
192
- string num_counters = std::to_string (DropCounter::getSupportedDebugCounterAmounts (counter_type.second ));
193
-
194
193
string drop_reasons;
195
194
if (counter_type.first == PORT_INGRESS_DROPS || counter_type.first == SWITCH_INGRESS_DROPS)
196
195
{
197
- drop_reasons = supported_ingress_drop_reasons ;
196
+ drop_reasons = ingress_drop_reason_str ;
198
197
}
199
198
else
200
199
{
201
- drop_reasons = supported_egress_drop_reasons ;
200
+ drop_reasons = egress_drop_reason_str ;
202
201
}
203
202
204
- // Only include available capabilities in State DB
205
- if (num_counters != " 0 " && ! drop_reasons.empty ())
203
+ // Don't bother publishing counters that have no drop reasons
204
+ if (drop_reasons.empty ())
206
205
{
207
- vector<FieldValueTuple> fieldValues;
208
- fieldValues.push_back (FieldValueTuple (" count" , num_counters));
209
- fieldValues.push_back (FieldValueTuple (" reasons" , drop_reasons));
206
+ continue ;
207
+ }
210
208
211
- SWSS_LOG_DEBUG (" Setting '%s' capabilities to count='%s', reasons='%s'" , counter_type.first .c_str (), num_counters.c_str (), drop_reasons.c_str ());
212
- m_debugCapabilitiesTable->set (counter_type.first , fieldValues);
209
+ string num_counters = std::to_string (DropCounter::getSupportedDebugCounterAmounts (counter_type.second ));
210
+
211
+ // Don't bother publishing counters that aren't available.
212
+ if (num_counters == " 0" )
213
+ {
214
+ continue ;
213
215
}
216
+
217
+ supported_counter_types.emplace (counter_type.first );
218
+
219
+ vector<FieldValueTuple> fieldValues;
220
+ fieldValues.push_back (FieldValueTuple (" count" , num_counters));
221
+ fieldValues.push_back (FieldValueTuple (" reasons" , drop_reasons));
222
+
223
+ SWSS_LOG_DEBUG (" Setting '%s' capabilities to count='%s', reasons='%s'" , counter_type.first .c_str (), num_counters.c_str (), drop_reasons.c_str ());
224
+ m_debugCapabilitiesTable->set (counter_type.first , fieldValues);
214
225
}
215
226
}
216
227
@@ -229,12 +240,19 @@ task_process_status DebugCounterOrch::installDebugCounter(const string& counter_
229
240
return task_process_status::task_success;
230
241
}
231
242
232
- // Note : this method currently assumes that all counters are drop counters.
243
+ // NOTE : this method currently assumes that all counters are drop counters.
233
244
// If you are adding support for a non-drop counter than it may make sense
234
245
// to either: a) dispatch to different handlers in doTask or b) dispatch to
235
246
// different helper methods in this method.
236
247
237
248
string counter_type = getDebugCounterType (attributes);
249
+
250
+ if (supported_counter_types.find (counter_type) == supported_counter_types.end ())
251
+ {
252
+ SWSS_LOG_ERROR (" Specified counter type '%s' is not supported." , counter_type.c_str ());
253
+ return task_process_status::task_failed;
254
+ }
255
+
238
256
addFreeCounter (counter_name, counter_type);
239
257
reconcileFreeDropCounters (counter_name);
240
258
@@ -287,7 +305,15 @@ task_process_status DebugCounterOrch::addDropReason(const string& counter_name,
287
305
288
306
if (!isDropReasonValid (drop_reason))
289
307
{
290
- return task_failed;
308
+ SWSS_LOG_ERROR (" Specified drop reason '%s' is invalid." , drop_reason.c_str ());
309
+ return task_process_status::task_failed;
310
+ }
311
+
312
+ if (supported_ingress_drop_reasons.find (drop_reason) == supported_ingress_drop_reasons.end () &&
313
+ supported_egress_drop_reasons.find (drop_reason) == supported_egress_drop_reasons.end ())
314
+ {
315
+ SWSS_LOG_ERROR (" Specified drop reason '%s' is not supported." , drop_reason.c_str ());
316
+ return task_process_status::task_failed;
291
317
}
292
318
293
319
auto it = debug_counters.find (counter_name);
0 commit comments