@@ -182,35 +182,46 @@ void DebugCounterOrch::doTask(Consumer& consumer)
182182// DROP_COUNTER_CAPABILITIES table in STATE_DB.
183183void DebugCounterOrch::publishDropCounterCapabilities ()
184184{
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);
189190
190191 for (auto const &counter_type : DebugCounter::getDebugCounterTypeLookup ())
191192 {
192- string num_counters = std::to_string (DropCounter::getSupportedDebugCounterAmounts (counter_type.second ));
193-
194193 string drop_reasons;
195194 if (counter_type.first == PORT_INGRESS_DROPS || counter_type.first == SWITCH_INGRESS_DROPS)
196195 {
197- drop_reasons = supported_ingress_drop_reasons ;
196+ drop_reasons = ingress_drop_reason_str ;
198197 }
199198 else
200199 {
201- drop_reasons = supported_egress_drop_reasons ;
200+ drop_reasons = egress_drop_reason_str ;
202201 }
203202
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 ())
206205 {
207- vector<FieldValueTuple> fieldValues;
208- fieldValues.push_back (FieldValueTuple (" count" , num_counters));
209- fieldValues.push_back (FieldValueTuple (" reasons" , drop_reasons));
206+ continue ;
207+ }
210208
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 ;
213215 }
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);
214225 }
215226}
216227
@@ -229,12 +240,19 @@ task_process_status DebugCounterOrch::installDebugCounter(const string& counter_
229240 return task_process_status::task_success;
230241 }
231242
232- // Note : this method currently assumes that all counters are drop counters.
243+ // NOTE : this method currently assumes that all counters are drop counters.
233244 // If you are adding support for a non-drop counter than it may make sense
234245 // to either: a) dispatch to different handlers in doTask or b) dispatch to
235246 // different helper methods in this method.
236247
237248 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+
238256 addFreeCounter (counter_name, counter_type);
239257 reconcileFreeDropCounters (counter_name);
240258
@@ -287,7 +305,15 @@ task_process_status DebugCounterOrch::addDropReason(const string& counter_name,
287305
288306 if (!isDropReasonValid (drop_reason))
289307 {
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;
291317 }
292318
293319 auto it = debug_counters.find (counter_name);
0 commit comments