|
| 1 | +#include "logger.h" |
| 2 | +#include "dbconnector.h" |
| 3 | +#include "producerstatetable.h" |
| 4 | +#include "tokenize.h" |
| 5 | +#include "ipprefix.h" |
| 6 | +#include "fabricmgr.h" |
| 7 | +#include "exec.h" |
| 8 | +#include "shellcmd.h" |
| 9 | +#include <swss/redisutility.h> |
| 10 | + |
| 11 | +using namespace std; |
| 12 | +using namespace swss; |
| 13 | + |
| 14 | +FabricMgr::FabricMgr(DBConnector *cfgDb, DBConnector *appDb, const vector<string> &tableNames) : |
| 15 | + Orch(cfgDb, tableNames), |
| 16 | + m_cfgFabricMonitorTable(cfgDb, CFG_FABRIC_MONITOR_DATA_TABLE_NAME), |
| 17 | + m_cfgFabricPortTable(cfgDb, CFG_FABRIC_MONITOR_PORT_TABLE_NAME), |
| 18 | + m_appFabricMonitorTable(appDb, APP_FABRIC_MONITOR_DATA_TABLE_NAME), |
| 19 | + m_appFabricPortTable(appDb, APP_FABRIC_MONITOR_PORT_TABLE_NAME) |
| 20 | +{ |
| 21 | +} |
| 22 | + |
| 23 | +void FabricMgr::doTask(Consumer &consumer) |
| 24 | +{ |
| 25 | + SWSS_LOG_ENTER(); |
| 26 | + |
| 27 | + auto table = consumer.getTableName(); |
| 28 | + |
| 29 | + auto it = consumer.m_toSync.begin(); |
| 30 | + while (it != consumer.m_toSync.end()) |
| 31 | + { |
| 32 | + KeyOpFieldsValuesTuple t = it->second; |
| 33 | + |
| 34 | + string key = kfvKey(t); |
| 35 | + string op = kfvOp(t); |
| 36 | + |
| 37 | + if (op == SET_COMMAND) |
| 38 | + { |
| 39 | + |
| 40 | + string monErrThreshCrcCells, monErrThreshRxCells; |
| 41 | + string monPollThreshRecovery, monPollThreshIsolation; |
| 42 | + string isolateStatus; |
| 43 | + string alias, lanes; |
| 44 | + std::vector<FieldValueTuple> field_values; |
| 45 | + string value; |
| 46 | + |
| 47 | + for (auto i : kfvFieldsValues(t)) |
| 48 | + { |
| 49 | + if (fvField(i) == "monErrThreshCrcCells") |
| 50 | + { |
| 51 | + monErrThreshCrcCells = fvValue(i); |
| 52 | + writeConfigToAppDb(key, "monErrThreshCrcCells", monErrThreshCrcCells); |
| 53 | + } |
| 54 | + else if (fvField(i) == "monErrThreshRxCells") |
| 55 | + { |
| 56 | + monErrThreshRxCells = fvValue(i); |
| 57 | + writeConfigToAppDb(key, "monErrThreshRxCells", monErrThreshRxCells); |
| 58 | + } |
| 59 | + else if (fvField(i) == "monPollThreshRecovery") |
| 60 | + { |
| 61 | + monPollThreshRecovery = fvValue(i); |
| 62 | + writeConfigToAppDb(key, "monPollThreshRecovery", monPollThreshRecovery); |
| 63 | + } |
| 64 | + else if (fvField(i) == "monPollThreshIsolation") |
| 65 | + { |
| 66 | + monPollThreshIsolation = fvValue(i); |
| 67 | + writeConfigToAppDb(key, "monPollThreshIsolation", monPollThreshIsolation); |
| 68 | + } |
| 69 | + else if (fvField(i) == "alias") |
| 70 | + { |
| 71 | + alias = fvValue(i); |
| 72 | + writeConfigToAppDb(key, "alias", alias); |
| 73 | + } |
| 74 | + else if (fvField(i) == "lanes") |
| 75 | + { |
| 76 | + lanes = fvValue(i); |
| 77 | + writeConfigToAppDb(key, "lanes", lanes); |
| 78 | + } |
| 79 | + else if (fvField(i) == "isolateStatus") |
| 80 | + { |
| 81 | + isolateStatus = fvValue(i); |
| 82 | + writeConfigToAppDb(key, "isolateStatus", isolateStatus); |
| 83 | + } |
| 84 | + else |
| 85 | + { |
| 86 | + field_values.emplace_back(i); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + for (auto &entry : field_values) |
| 91 | + { |
| 92 | + writeConfigToAppDb(key, fvField(entry), fvValue(entry)); |
| 93 | + } |
| 94 | + |
| 95 | + } |
| 96 | + it = consumer.m_toSync.erase(it); |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +bool FabricMgr::writeConfigToAppDb(const std::string &key, const std::string &field, const std::string &value) |
| 101 | +{ |
| 102 | + vector<FieldValueTuple> fvs; |
| 103 | + FieldValueTuple fv(field, value); |
| 104 | + fvs.push_back(fv); |
| 105 | + if (key == "FABRIC_MONITOR_DATA") |
| 106 | + { |
| 107 | + m_appFabricMonitorTable.set(key, fvs); |
| 108 | + SWSS_LOG_NOTICE("Write FABRIC_MONITOR:%s %s to %s", key.c_str(), field.c_str(), value.c_str()); |
| 109 | + } |
| 110 | + else |
| 111 | + { |
| 112 | + m_appFabricPortTable.set(key, fvs); |
| 113 | + SWSS_LOG_NOTICE("Write FABRIC_PORT:%s %s to %s", key.c_str(), field.c_str(), value.c_str()); |
| 114 | + } |
| 115 | + |
| 116 | + return true; |
| 117 | +} |
| 118 | + |
| 119 | + |
0 commit comments