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