diff --git a/orchagent/fabricportsorch.cpp b/orchagent/fabricportsorch.cpp index e379115cbb..0105dcf6d7 100644 --- a/orchagent/fabricportsorch.cpp +++ b/orchagent/fabricportsorch.cpp @@ -23,11 +23,12 @@ #define FABRIC_PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS 10000 #define FABRIC_QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP "FABRIC_QUEUE_STAT_COUNTER" #define FABRIC_QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS 100000 -#define SWITCH_DEBUG_COUNTER_FLEX_COUNTER_GROUP "SWITCH_DEBUG_COUNTER" -#define SWITCH_DEBUG_COUNTER_POLLING_INTERVAL_MS 100000 #define FABRIC_DEBUG_POLLING_INTERVAL_DEFAULT (60) #define FABRIC_MONITOR_DATA "FABRIC_MONITOR_DATA" #define APPL_FABRIC_PORT_PREFIX "Fabric" +#define SWITCH_DEBUG_COUNTER_FLEX_COUNTER_GROUP "SWITCH_DEBUG_COUNTER" +#define SWITCH_DEBUG_COUNTER_POLLING_INTERVAL_MS 60000 +#define SWITCH_STANDARD_DROP_COUNTERS "SWITCH_STD_DROP_COUNTER-" // constants for link monitoring #define MAX_SKIP_CRCERR_ON_LNKUP_POLLS 20 @@ -41,15 +42,11 @@ #define ERROR_RATE_RX_CELLS_CFG 61035156 #define FABRIC_LINK_RATE 44316 -const vector switch_voq_counter_ids = -{ - SAI_SWITCH_STAT_PACKET_INTEGRITY_DROP -}; - extern sai_object_id_t gSwitchId; extern sai_switch_api_t *sai_switch_api; extern sai_port_api_t *sai_port_api; extern sai_queue_api_t *sai_queue_api; +extern string gMySwitchType; const vector port_stat_ids = { @@ -70,6 +67,11 @@ static const vector queue_stat_ids = SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL, }; +const vector switch_drop_counter_ids = +{ + SAI_SWITCH_STAT_PACKET_INTEGRITY_DROP +}; + FabricPortsOrch::FabricPortsOrch(DBConnector *appl_db, vector &tableNames, bool fabricPortStatEnabled, bool fabricQueueStatEnabled) : Orch(appl_db, tableNames), @@ -77,8 +79,6 @@ FabricPortsOrch::FabricPortsOrch(DBConnector *appl_db, vector(new Table(m_counter_db.get(), COUNTERS_FABRIC_QUEUE_NAME_MAP)); m_portNamePortCounterTable = unique_ptr(new Table(m_counter_db.get(), COUNTERS_FABRIC_PORT_NAME_MAP)); m_fabricCounterTable = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_TABLE)); - m_counterNameToSwitchStatMap = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP)); + + // Create Switch level drop counters for fabric switch. switchorch adds for other switch types + if (gMySwitchType == "fabric") + { + switch_drop_counter_manager = new FlexCounterManager(SWITCH_DEBUG_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, + SWITCH_DEBUG_COUNTER_POLLING_INTERVAL_MS, true); + m_counterNameToSwitchStatMap = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP)); + } m_appl_db = shared_ptr(new DBConnector("APPL_DB", 0)); m_applTable = unique_ptr
(new Table(m_appl_db.get(), APP_FABRIC_MONITOR_PORT_TABLE_NAME)); @@ -1514,24 +1521,24 @@ void FabricPortsOrch::doTask(swss::SelectableTimer &timer) updateFabricCapacity(); updateFabricRate(); } - if (!m_isSwitchStatsGenerated) + if ((gMySwitchType == "fabric") && (!m_isSwitchStatsGenerated)) { - createSwitchVoqCounters(); + createSwitchDropCounters(); + m_isSwitchStatsGenerated = true; } } } -void FabricPortsOrch::createSwitchVoqCounters(void) +void FabricPortsOrch::createSwitchDropCounters(void) { std::unordered_set counter_stats; - for (const auto& it: switch_voq_counter_ids) + for (const auto& it: switch_drop_counter_ids) { - counter_stats.emplace(sai_serialize_switch_stat(it)); + std::string drop_stats = sai_serialize_switch_stat(it); + counter_stats.emplace(drop_stats); + vector switchNameSwitchCounterMap; + switchNameSwitchCounterMap.emplace_back((SWITCH_STANDARD_DROP_COUNTERS + drop_stats), drop_stats); + m_counterNameToSwitchStatMap->set("", switchNameSwitchCounterMap); } - switch_drop_counter_manager.setCounterIdList(gSwitchId, CounterType::SWITCH_DEBUG, counter_stats); - - vector switchNameSwitchCounterMap; - switchNameSwitchCounterMap.emplace_back("SWITCH_ID", sai_serialize_object_id(gSwitchId)); - m_counterNameToSwitchStatMap->set("", switchNameSwitchCounterMap); - m_isSwitchStatsGenerated = true; + switch_drop_counter_manager->setCounterIdList(gSwitchId, CounterType::SWITCH_DEBUG, counter_stats); } diff --git a/orchagent/fabricportsorch.h b/orchagent/fabricportsorch.h index 46049ccec6..e4c47bf7af 100644 --- a/orchagent/fabricportsorch.h +++ b/orchagent/fabricportsorch.h @@ -19,7 +19,6 @@ class FabricPortsOrch : public Orch, public Subject bool fabricPortStatEnabled=true, bool fabricQueueStatEnabled=true); bool allPortsReady(); void generateQueueStats(); - void createSwitchVoqCounters(void); private: bool m_fabricPortStatEnabled; @@ -44,7 +43,7 @@ class FabricPortsOrch : public Orch, public Subject FlexCounterManager port_stat_manager; FlexCounterManager queue_stat_manager; - FlexCounterManager switch_drop_counter_manager; + FlexCounterManager *switch_drop_counter_manager = nullptr; sai_uint32_t m_fabricPortCount; map m_fabricLanePortMap; @@ -71,6 +70,7 @@ class FabricPortsOrch : public Orch, public Subject void updateFabricCapacity(); bool checkFabricPortMonState(); void updateFabricRate(); + void createSwitchDropCounters(); void doTask() override; void doTask(Consumer &consumer); diff --git a/orchagent/switchorch.cpp b/orchagent/switchorch.cpp index 1674673366..3e68cdcf2c 100644 --- a/orchagent/switchorch.cpp +++ b/orchagent/switchorch.cpp @@ -26,6 +26,7 @@ extern MacAddress gVxlanMacAddress; extern CrmOrch *gCrmOrch; extern event_handle_t g_events_handle; extern string gMyAsicName; +extern string gMySwitchType; const map switch_attribute_map = { @@ -92,6 +93,10 @@ const std::set switch_asic_sdk_health_eve SAI_SWITCH_ASIC_SDK_HEALTH_CATEGORY_CPU_HW, SAI_SWITCH_ASIC_SDK_HEALTH_CATEGORY_ASIC_HW }; +const vector switch_drop_counter_ids = +{ + SAI_SWITCH_STAT_PACKET_INTEGRITY_DROP +}; const std::set switch_non_sai_attribute_set = {"ordered_ecmp"}; @@ -124,7 +129,11 @@ SwitchOrch::SwitchOrch(DBConnector *db, vector& connectors, Tabl m_asicSensorsTable(new Table(m_stateDb.get(), ASIC_TEMPERATURE_INFO_TABLE_NAME)), m_sensorsPollerTimer (new SelectableTimer((timespec { .tv_sec = DEFAULT_ASIC_SENSORS_POLLER_INTERVAL, .tv_nsec = 0 }))), m_stateDbForNotification(new DBConnector(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)), - m_asicSdkHealthEventTable(new Table(m_stateDbForNotification.get(), STATE_ASIC_SDK_HEALTH_EVENT_TABLE_NAME)) + m_asicSdkHealthEventTable(new Table(m_stateDbForNotification.get(), STATE_ASIC_SDK_HEALTH_EVENT_TABLE_NAME)), + switch_drop_counter_manager(SWITCH_DEBUG_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, + SWITCH_DEBUG_COUNTER_POLLING_INTERVAL_MS, true), + m_switchDropCntrPollEnableTimer (new SelectableTimer((timespec { .tv_sec = DEFAULT_SWITCH_DROP_COUNTER_POLL_ENABLE_TIMER_INTERVAL, + .tv_nsec = 0 }))) { m_restartCheckNotificationConsumer = new NotificationConsumer(db, "RESTARTCHECK"); auto restartCheckNotifier = new Notifier(m_restartCheckNotificationConsumer, this, "RESTARTCHECK"); @@ -139,6 +148,16 @@ SwitchOrch::SwitchOrch(DBConnector *db, vector& connectors, Tabl auto executorT = new ExecutableTimer(m_sensorsPollerTimer, this, "ASIC_SENSORS_POLL_TIMER"); Orch::addExecutor(executorT); + + // Add Switch level drop counters to FLEX_COUNTER_DB only for VOQ switch type since it is supported by only VOQ/fabric switches now. + if(gMySwitchType == "voq") + { + m_counter_db = shared_ptr(new DBConnector("COUNTERS_DB", 0)); + m_counterNameToSwitchStatMap = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP)); + auto executorSwitchT = new ExecutableTimer(m_switchDropCntrPollEnableTimer, this, "SWITCH_DROP_COUNTER_TIMER"); + Orch::addExecutor(executorSwitchT); + m_switchDropCntrPollEnableTimer->start(); + } } void SwitchOrch::initAsicSdkHealthEventNotification() @@ -1297,7 +1316,12 @@ void SwitchOrch::doTask(SelectableTimer &timer) SWSS_LOG_INFO("Eliminate ASIC/SDK health %s", str.c_str()); } } -} + else if (&timer == m_switchDropCntrPollEnableTimer) + { + createSwitchDropCounters(); + m_switchDropCntrPollEnableTimer->stop(); + } + } void SwitchOrch::initSensorsTable() { @@ -1515,3 +1539,17 @@ bool SwitchOrch::querySwitchCapability(sai_object_type_t sai_object, sai_attr_id } } } + +void SwitchOrch::createSwitchDropCounters(void) +{ + std::unordered_set counter_stats; + for (const auto& it: switch_drop_counter_ids) + { + std::string drop_stats = sai_serialize_switch_stat(it); + counter_stats.emplace(drop_stats); + vector switchNameSwitchCounterMap; + switchNameSwitchCounterMap.emplace_back((SWITCH_STANDARD_DROP_COUNTERS + drop_stats), drop_stats); + m_counterNameToSwitchStatMap->set("", switchNameSwitchCounterMap); + } + switch_drop_counter_manager.setCounterIdList(gSwitchId, CounterType::SWITCH_DEBUG, counter_stats); +} diff --git a/orchagent/switchorch.h b/orchagent/switchorch.h index 95cd04dbdf..c759da0ab0 100644 --- a/orchagent/switchorch.h +++ b/orchagent/switchorch.h @@ -5,11 +5,17 @@ #include "timer.h" #include "switch/switch_capabilities.h" #include "switch/switch_helper.h" +#include "flex_counter_manager.h" #define DEFAULT_ASIC_SENSORS_POLLER_INTERVAL 60 #define ASIC_SENSORS_POLLER_STATUS "ASIC_SENSORS_POLLER_STATUS" #define ASIC_SENSORS_POLLER_INTERVAL "ASIC_SENSORS_POLLER_INTERVAL" +#define DEFAULT_SWITCH_DROP_COUNTER_POLL_ENABLE_TIMER_INTERVAL 180 +#define SWITCH_DEBUG_COUNTER_FLEX_COUNTER_GROUP "SWITCH_DEBUG_COUNTER" +#define SWITCH_STANDARD_DROP_COUNTERS "SWITCH_STD_DROP_COUNTER-" +#define SWITCH_DEBUG_COUNTER_POLLING_INTERVAL_MS 60000 + #define SWITCH_CAPABILITY_TABLE_PORT_TPID_CAPABLE "PORT_TPID_CAPABLE" #define SWITCH_CAPABILITY_TABLE_LAG_TPID_CAPABLE "LAG_TPID_CAPABLE" #define SWITCH_CAPABILITY_TABLE_ORDERED_ECMP_CAPABLE "ORDERED_ECMP_CAPABLE" @@ -75,6 +81,7 @@ class SwitchOrch : public Orch void initSensorsTable(); void querySwitchTpidCapability(); void querySwitchPortEgressSampleCapability(); + void createSwitchDropCounters(void); // Switch hash bool setSwitchHashFieldListSai(const SwitchHash &hash, bool isEcmpHash) const; @@ -110,6 +117,11 @@ class SwitchOrch : public Orch std::shared_ptr m_stateDb = nullptr; std::shared_ptr m_asicSensorsTable= nullptr; swss::SelectableTimer* m_sensorsPollerTimer = nullptr; + std::shared_ptr m_counter_db; + FlexCounterManager switch_drop_counter_manager; + std::shared_ptr m_counterNameToSwitchStatMap; + swss::SelectableTimer* m_switchDropCntrPollEnableTimer = nullptr; + bool m_sensorsPollerEnabled = false; time_t m_sensorsPollerInterval = DEFAULT_ASIC_SENSORS_POLLER_INTERVAL; bool m_sensorsPollerIntervalChanged = false;