|
| 1 | +#include <unordered_map> |
| 2 | +#include "flexcounterorch.h" |
| 3 | +#include "portsorch.h" |
| 4 | +#include "select.h" |
| 5 | +#include "notifier.h" |
| 6 | +#include "redisclient.h" |
| 7 | +#include "sai_serialize.h" |
| 8 | + |
| 9 | +extern sai_port_api_t *sai_port_api; |
| 10 | + |
| 11 | +extern PortsOrch *gPortsOrch; |
| 12 | + |
| 13 | +unordered_map<string, string> flexCounterGroupMap = |
| 14 | +{ |
| 15 | + {"PORT", PORT_STAT_COUNTER_FLEX_COUNTER_GROUP}, |
| 16 | + {"QUEUE", QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP}, |
| 17 | +}; |
| 18 | + |
| 19 | +FlexCounterOrch::FlexCounterOrch(DBConnector *db, vector<string> &tableNames): |
| 20 | + Orch(db, tableNames), |
| 21 | + m_flexCounterDb(new DBConnector(FLEX_COUNTER_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)), |
| 22 | + m_flexCounterGroupTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE)) |
| 23 | +{ |
| 24 | + SWSS_LOG_ENTER(); |
| 25 | +} |
| 26 | + |
| 27 | +FlexCounterOrch::~FlexCounterOrch(void) |
| 28 | +{ |
| 29 | + SWSS_LOG_ENTER(); |
| 30 | +} |
| 31 | + |
| 32 | +void FlexCounterOrch::doTask(Consumer &consumer) |
| 33 | +{ |
| 34 | + SWSS_LOG_ENTER(); |
| 35 | + |
| 36 | + if (!gPortsOrch->isInitDone()) |
| 37 | + { |
| 38 | + return; |
| 39 | + } |
| 40 | + |
| 41 | + auto it = consumer.m_toSync.begin(); |
| 42 | + while (it != consumer.m_toSync.end()) |
| 43 | + { |
| 44 | + KeyOpFieldsValuesTuple t = it->second; |
| 45 | + |
| 46 | + string key = kfvKey(t); |
| 47 | + string op = kfvOp(t); |
| 48 | + auto data = kfvFieldsValues(t); |
| 49 | + |
| 50 | + if (!flexCounterGroupMap.count(key)) |
| 51 | + { |
| 52 | + SWSS_LOG_NOTICE("Invalid flex counter group input, %s", key.c_str()); |
| 53 | + consumer.m_toSync.erase(it++); |
| 54 | + continue; |
| 55 | + } |
| 56 | + |
| 57 | + if (op == SET_COMMAND) |
| 58 | + { |
| 59 | + for (auto valuePair:data) |
| 60 | + { |
| 61 | + const auto &field = fvField(valuePair); |
| 62 | + const auto &value = fvValue(valuePair); |
| 63 | + |
| 64 | + if (field == POLL_INTERVAL_FIELD) |
| 65 | + { |
| 66 | + vector<FieldValueTuple> fieldValues; |
| 67 | + fieldValues.emplace_back(POLL_INTERVAL_FIELD, value); |
| 68 | + m_flexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues); |
| 69 | + } |
| 70 | + /* In future add the support to disable/enable counter query here.*/ |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + consumer.m_toSync.erase(it++); |
| 75 | + } |
| 76 | +} |
0 commit comments