diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index c65e69986992..748c9c4b8f9c 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -12,6 +12,7 @@ using namespace swss; /* select() function timeout retry time */ #define SELECT_TIMEOUT 1000 +#define PFC_WD_POLL_MSECS 100 extern sai_switch_api_t* sai_switch_api; extern sai_object_id_t gSwitchId; @@ -103,7 +104,7 @@ bool OrchDaemon::init() m_select = new Select(); vector pfc_wd_tables = { - APP_PFC_WD_TABLE_NAME + CFG_PFC_WD_TABLE_NAME }; if (platform == MLNX_PLATFORM_SUBSTRING) diff --git a/orchagent/pfcwdorch.cpp b/orchagent/pfcwdorch.cpp index 09b954320922..96c2b75586eb 100644 --- a/orchagent/pfcwdorch.cpp +++ b/orchagent/pfcwdorch.cpp @@ -9,6 +9,8 @@ #include "notifier.h" #include "redisclient.h" +#define PFC_WD_FLEX_COUNTER_GROUP "PFC_WD" +#define PFC_WD_GLOBAL "GLOBAL" #define PFC_WD_ACTION "action" #define PFC_WD_DETECTION_TIME "detection_time" #define PFC_WD_RESTORATION_TIME "restoration_time" @@ -357,6 +359,31 @@ void PfcWdOrch::deleteEntry(const string& name) SWSS_LOG_NOTICE("Stopped PFC Watchdog on port %s", name.c_str()); } +template +void PfcWdSwOrch::createEntry(const string& key, + const vector& data) +{ + if (key == PFC_WD_GLOBAL) + { + for (auto valuePair: data) + { + const auto &field = fvField(valuePair); + const auto &value = fvValue(valuePair); + + if (field == POLL_INTERVAL_FIELD) + { + vector fieldValues; + fieldValues.emplace_back(POLL_INTERVAL_FIELD, value); + m_flexCounterGroupTable->set(PFC_WD_FLEX_COUNTER_GROUP, fieldValues); + } + } + } + else + { + PfcWdOrch::createEntry(key, data); + } +} + template void PfcWdSwOrch::registerInWdDb(const Port& port, uint32_t detectionTime, uint32_t restorationTime, PfcWdAction action) @@ -375,12 +402,12 @@ void PfcWdSwOrch::registerInWdDb(const Port& port, if (!c_portStatIds.empty()) { - string key = sai_serialize_object_id(port.m_port_id) + ":" + std::to_string(m_pollInterval); + string key = getFlexCounterTableKey(sai_serialize_object_id(port.m_port_id)); vector fieldValues; string str = counterIdsToStr(c_portStatIds, &sai_serialize_port_stat); - fieldValues.emplace_back(PFC_WD_PORT_COUNTER_ID_LIST, str); + fieldValues.emplace_back(PORT_COUNTER_ID_LIST, str); - m_pfcWdTable->set(key, fieldValues); + m_flexCounterTable->set(key, fieldValues); } uint8_t pfcMask = attr.value.u8; @@ -412,21 +439,20 @@ void PfcWdSwOrch::registerInWdDb(const Port& port, if (!c_queueStatIds.empty()) { string str = counterIdsToStr(c_queueStatIds, sai_serialize_queue_stat); - queueFieldValues.emplace_back(PFC_WD_QUEUE_COUNTER_ID_LIST, str); + queueFieldValues.emplace_back(QUEUE_COUNTER_ID_LIST, str); } if (!c_queueAttrIds.empty()) { string str = counterIdsToStr(c_queueAttrIds, sai_serialize_queue_attr); - queueFieldValues.emplace_back(PFC_WD_QUEUE_ATTR_ID_LIST, str); + queueFieldValues.emplace_back(QUEUE_ATTR_ID_LIST, str); } // Create internal entry m_entryMap.emplace(queueId, PfcWdQueueEntry(action, port.m_port_id, i)); - string key = queueIdStr + ":" + std::to_string(m_pollInterval); - - m_pfcWdTable->set(key, queueFieldValues); + string key = getFlexCounterTableKey(queueIdStr); + m_flexCounterTable->set(key, queueFieldValues); // Initialize PFC WD related counters PfcWdActionHandler::initWdCounters( @@ -435,21 +461,27 @@ void PfcWdSwOrch::registerInWdDb(const Port& port, } } +template +string PfcWdSwOrch::getFlexCounterTableKey(string key) +{ + return string(PFC_WD_FLEX_COUNTER_GROUP) + ":" + key; +} + template void PfcWdSwOrch::unregisterFromWdDb(const Port& port) { SWSS_LOG_ENTER(); - string key = sai_serialize_object_id(port.m_port_id) + ":" + std::to_string(m_pollInterval); - m_pfcWdTable->del(key); + string key = getFlexCounterTableKey(sai_serialize_object_id(port.m_port_id)); + m_flexCounterTable->del(key); for (uint8_t i = 0; i < PFC_WD_TC_MAX; i++) { sai_object_id_t queueId = port.m_queue_ids[i]; - string key = sai_serialize_object_id(queueId) + ":" + std::to_string(m_pollInterval); + string key = getFlexCounterTableKey(sai_serialize_object_id(queueId)); // Unregister in syncd - m_pfcWdTable->del(key); + m_flexCounterTable->del(key); m_entryMap.erase(queueId); // Clean up @@ -471,8 +503,9 @@ PfcWdSwOrch::PfcWdSwOrch( const vector &queueAttrIds, int pollInterval): PfcWdOrch(db, tableNames), - m_pfcWdDb(new DBConnector(PFC_WD_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)), - m_pfcWdTable(new ProducerStateTable(m_pfcWdDb.get(), PFC_WD_STATE_TABLE)), + m_flexCounterDb(new DBConnector(FLEX_COUNTER_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)), + m_flexCounterTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_TABLE)), + m_flexCounterGroupTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE)), c_portStatIds(portStatIds), c_queueStatIds(queueStatIds), c_queueAttrIds(queueAttrIds), @@ -504,17 +537,13 @@ PfcWdSwOrch::PfcWdSwOrch( restoreLuaScript); vector fieldValues; - fieldValues.emplace_back(SAI_OBJECT_TYPE, sai_serialize_object_type(SAI_OBJECT_TYPE_QUEUE)); - - auto pluginTable = ProducerStateTable(m_pfcWdDb.get(), PLUGIN_TABLE); - string detectShaKey = detectSha + ":" + std::to_string(m_pollInterval); - string restoreShaKey = restoreSha + ":" + std::to_string(m_pollInterval); - pluginTable.set(detectShaKey, fieldValues); - pluginTable.set(restoreShaKey, fieldValues); + fieldValues.emplace_back(QUEUE_PLUGIN_FIELD, detectSha + "," + restoreSha); + fieldValues.emplace_back(POLL_INTERVAL_FIELD, to_string(m_pollInterval)); + m_flexCounterGroupTable->set(PFC_WD_FLEX_COUNTER_GROUP, fieldValues); } catch (...) { - SWSS_LOG_WARN("Lua scripts for PFC watchdog were not loaded"); + SWSS_LOG_WARN("Lua scripts and polling interval for PFC watchdog were not set successfully"); } auto consumer = new swss::NotificationConsumer( @@ -528,6 +557,7 @@ template PfcWdSwOrch::~PfcWdSwOrch(void) { SWSS_LOG_ENTER(); + m_flexCounterGroupTable->del(PFC_WD_FLEX_COUNTER_GROUP); } template diff --git a/orchagent/pfcwdorch.h b/orchagent/pfcwdorch.h index a32abe7729d0..c828894b4a09 100644 --- a/orchagent/pfcwdorch.h +++ b/orchagent/pfcwdorch.h @@ -4,7 +4,7 @@ #include "orch.h" #include "port.h" #include "pfcactionhandler.h" -#include "producerstatetable.h" +#include "producertable.h" #include "notificationconsumer.h" #include "timer.h" #include @@ -51,9 +51,9 @@ class PfcWdOrch: public Orch static PfcWdAction deserializeAction(const string& key); static string serializeAction(const PfcWdAction &action); -private: - void createEntry(const string& key, const vector& data); + virtual void createEntry(const string& key, const vector& data); void deleteEntry(const string& name); +private: PfcFrameCounters getPfcFrameCounters(sai_object_id_t portId); shared_ptr m_countersDb = nullptr; @@ -79,6 +79,7 @@ class PfcWdSwOrch: public PfcWdOrch uint32_t detectionTime, uint32_t restorationTime, PfcWdAction action); virtual bool stopWdOnPort(const Port& port); + void createEntry(const string& key, const vector& data); //XXX Add port/queue state change event handlers private: struct PfcWdQueueEntry @@ -101,14 +102,16 @@ class PfcWdSwOrch: public PfcWdOrch void unregisterFromWdDb(const Port& port); void doTask(swss::NotificationConsumer &wdNotification); + string getFlexCounterTableKey(string s); map m_entryMap; const vector c_portStatIds; const vector c_queueStatIds; const vector c_queueAttrIds; - shared_ptr m_pfcWdDb = nullptr; - shared_ptr m_pfcWdTable = nullptr; + shared_ptr m_flexCounterDb = nullptr; + shared_ptr m_flexCounterTable = nullptr; + shared_ptr m_flexCounterGroupTable = nullptr; atomic_bool m_runPfcWdSwOrchThread = { false }; shared_ptr m_pfcWatchdogThread = nullptr; diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index d00edfd30aa3..069a4ba35da8 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -31,6 +31,7 @@ extern sai_object_id_t gSwitchId; #define VLAN_PREFIX "Vlan" #define DEFAULT_VLAN_ID 1 #define FLEX_STAT_COUNTER_POLL_MSECS "1000" +#define STAT_COUNTER_FLEX_COUNTER_GROUP "STAT_COUNTER" static map fec_mode_map = { @@ -113,8 +114,13 @@ PortsOrch::PortsOrch(DBConnector *db, vector tableNames) : m_queueIndexTable = unique_ptr(new Table(m_counter_db.get(), COUNTERS_QUEUE_INDEX_MAP)); m_queueTypeTable = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_QUEUE_TYPE_MAP)); - m_flex_db = shared_ptr(new DBConnector(PFC_WD_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)); - m_flexCounterTable = unique_ptr(new ProducerStateTable(m_flex_db.get(), PFC_WD_STATE_TABLE)); + m_flex_db = shared_ptr(new DBConnector(FLEX_COUNTER_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)); + m_flexCounterTable = unique_ptr(new ProducerTable(m_flex_db.get(), FLEX_COUNTER_TABLE)); + m_flexCounterGroupTable = unique_ptr(new ProducerTable(m_flex_db.get(), FLEX_COUNTER_GROUP_TABLE)); + + vector fields; + fields.emplace_back(POLL_INTERVAL_FIELD, FLEX_STAT_COUNTER_POLL_MSECS); + m_flexCounterGroupTable->set(STAT_COUNTER_FLEX_COUNTER_GROUP, fields); uint32_t i, j; sai_status_t status; @@ -923,6 +929,11 @@ bool PortsOrch::removePort(sai_object_id_t port_id) return true; } +string PortsOrch::getFlexCounterTableKey(string key) +{ + return string(STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key; +} + bool PortsOrch::initPort(const string &alias, const set &lane_set) { SWSS_LOG_ENTER(); @@ -956,8 +967,7 @@ bool PortsOrch::initPort(const string &alias, const set &lane_set) m_counterTable->set("", fields); /* Add port to flex_counter for updating stat counters */ - string key = sai_serialize_object_id(p.m_port_id) + ":" + FLEX_STAT_COUNTER_POLL_MSECS; - + string key = getFlexCounterTableKey(sai_serialize_object_id(p.m_port_id)); std::string delimiter = ""; std::ostringstream counters_stream; for (const auto &id: portStatIds) @@ -967,7 +977,7 @@ bool PortsOrch::initPort(const string &alias, const set &lane_set) } fields.clear(); - fields.emplace_back(PFC_WD_PORT_COUNTER_ID_LIST, counters_stream.str()); + fields.emplace_back(PORT_COUNTER_ID_LIST, counters_stream.str()); m_flexCounterTable->set(key, fields); @@ -1720,7 +1730,7 @@ void PortsOrch::initializeQueues(Port &port) queueTypeVector.push_back(queueTypeTuple); } - string key = sai_serialize_object_id(port.m_queue_ids[queueIndex]) + ":" + FLEX_STAT_COUNTER_POLL_MSECS; + string key = getFlexCounterTableKey(sai_serialize_object_id(port.m_queue_ids[queueIndex])); std::string delimiter = ""; std::ostringstream counters_stream; @@ -1731,7 +1741,7 @@ void PortsOrch::initializeQueues(Port &port) } vector fieldValues; - fieldValues.emplace_back(PFC_WD_QUEUE_COUNTER_ID_LIST, counters_stream.str()); + fieldValues.emplace_back(QUEUE_COUNTER_ID_LIST, counters_stream.str()); m_flexCounterTable->set(key, fieldValues); } diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index 279833e214bb..df75eb8b61e4 100644 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -8,7 +8,7 @@ #include "port.h" #include "observer.h" #include "macaddress.h" -#include "producerstatetable.h" +#include "producertable.h" #define FCS_LEN 4 #define VLAN_TAG_LEN 4 @@ -63,8 +63,10 @@ class PortsOrch : public Orch, public Subject unique_ptr
m_queuePortTable; unique_ptr
m_queueIndexTable; unique_ptr
m_queueTypeTable; - unique_ptr m_flexCounterTable; + unique_ptr m_flexCounterTable; + unique_ptr m_flexCounterGroupTable; + std:: string getFlexCounterTableKey(std::string s); shared_ptr m_counter_db; shared_ptr m_flex_db;