forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flexcounter]: add support to change port/queue counter poll interval (…
…sonic-net#499) Signed-off-by: Sihui Han <sihan@microsoft.com>
- Loading branch information
1 parent
8d810be
commit 8c23538
Showing
7 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <unordered_map> | ||
#include "flexcounterorch.h" | ||
#include "portsorch.h" | ||
#include "select.h" | ||
#include "notifier.h" | ||
#include "redisclient.h" | ||
#include "sai_serialize.h" | ||
|
||
extern sai_port_api_t *sai_port_api; | ||
|
||
extern PortsOrch *gPortsOrch; | ||
|
||
unordered_map<string, string> flexCounterGroupMap = | ||
{ | ||
{"PORT", PORT_STAT_COUNTER_FLEX_COUNTER_GROUP}, | ||
{"QUEUE", QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP}, | ||
}; | ||
|
||
FlexCounterOrch::FlexCounterOrch(DBConnector *db, vector<string> &tableNames): | ||
Orch(db, tableNames), | ||
m_flexCounterDb(new DBConnector(FLEX_COUNTER_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)), | ||
m_flexCounterGroupTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE)) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
} | ||
|
||
FlexCounterOrch::~FlexCounterOrch(void) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
} | ||
|
||
void FlexCounterOrch::doTask(Consumer &consumer) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
if (!gPortsOrch->isInitDone()) | ||
{ | ||
return; | ||
} | ||
|
||
auto it = consumer.m_toSync.begin(); | ||
while (it != consumer.m_toSync.end()) | ||
{ | ||
KeyOpFieldsValuesTuple t = it->second; | ||
|
||
string key = kfvKey(t); | ||
string op = kfvOp(t); | ||
auto data = kfvFieldsValues(t); | ||
|
||
if (!flexCounterGroupMap.count(key)) | ||
{ | ||
SWSS_LOG_NOTICE("Invalid flex counter group input, %s", key.c_str()); | ||
consumer.m_toSync.erase(it++); | ||
continue; | ||
} | ||
|
||
if (op == SET_COMMAND) | ||
{ | ||
for (auto valuePair:data) | ||
{ | ||
const auto &field = fvField(valuePair); | ||
const auto &value = fvValue(valuePair); | ||
|
||
if (field == POLL_INTERVAL_FIELD) | ||
{ | ||
vector<FieldValueTuple> fieldValues; | ||
fieldValues.emplace_back(POLL_INTERVAL_FIELD, value); | ||
m_flexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues); | ||
} | ||
/* In future add the support to disable/enable counter query here.*/ | ||
} | ||
} | ||
|
||
consumer.m_toSync.erase(it++); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef FLEXCOUNTER_ORCH_H | ||
#define FLEXCOUNTER_ORCH_H | ||
|
||
#include "orch.h" | ||
#include "port.h" | ||
#include "producertable.h" | ||
|
||
extern "C" { | ||
#include "sai.h" | ||
} | ||
|
||
class FlexCounterOrch: public Orch | ||
{ | ||
public: | ||
void doTask(Consumer &consumer); | ||
FlexCounterOrch(DBConnector *db, vector<string> &tableNames); | ||
virtual ~FlexCounterOrch(void); | ||
|
||
private: | ||
shared_ptr<DBConnector> m_flexCounterDb = nullptr; | ||
shared_ptr<ProducerTable> m_flexCounterGroupTable = nullptr; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters