Skip to content

Commit d839eec

Browse files
authored
Add support for fabric monitor daemon (swss part). (sonic-net#2920)
* Add support for fabric monitor daemon (swss part).
1 parent 8dc0a85 commit d839eec

5 files changed

Lines changed: 278 additions & 1 deletion

File tree

cfgmgr/Makefile.am

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LIBNL_LIBS = -lnl-genl-3 -lnl-route-3 -lnl-3
55
SAIMETA_LIBS = -lsaimeta -lsaimetadata -lzmq
66
COMMON_LIBS = -lswsscommon
77

8-
bin_PROGRAMS = vlanmgrd teammgrd portmgrd intfmgrd buffermgrd vrfmgrd nbrmgrd vxlanmgrd sflowmgrd natmgrd coppmgrd tunnelmgrd macsecmgrd
8+
bin_PROGRAMS = vlanmgrd teammgrd portmgrd intfmgrd buffermgrd vrfmgrd nbrmgrd vxlanmgrd sflowmgrd natmgrd coppmgrd tunnelmgrd macsecmgrd fabricmgrd
99

1010
cfgmgrdir = $(datadir)/swss
1111

@@ -46,6 +46,11 @@ portmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLA
4646
portmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN)
4747
portmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS)
4848

49+
fabricmgrd_SOURCES = fabricmgrd.cpp fabricmgr.cpp $(COMMON_ORCH_SOURCE) shellcmd.h
50+
fabricmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN)
51+
fabricmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN)
52+
fabricmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS)
53+
4954
intfmgrd_SOURCES = intfmgrd.cpp intfmgr.cpp $(top_srcdir)/lib/subintf.cpp $(COMMON_ORCH_SOURCE) shellcmd.h
5055
intfmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN)
5156
intfmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN)
@@ -110,6 +115,7 @@ natmgrd_LDADD += -lgcovpreload
110115
coppmgrd_LDADD += -lgcovpreload
111116
tunnelmgrd_LDADD += -lgcovpreload
112117
macsecmgrd_LDADD += -lgcovpreload
118+
fabricmgrd_LDADD += -lgcovpreload
113119
endif
114120

115121
if ASAN_ENABLED
@@ -126,5 +132,6 @@ natmgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
126132
coppmgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
127133
tunnelmgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
128134
macsecmgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
135+
fabricmgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
129136
endif
130137

cfgmgr/fabricmgr.cpp

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+

cfgmgr/fabricmgr.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#include "dbconnector.h"
4+
#include "orch.h"
5+
#include "producerstatetable.h"
6+
7+
#include <map>
8+
#include <set>
9+
#include <string>
10+
11+
namespace swss {
12+
13+
14+
class FabricMgr : public Orch
15+
{
16+
public:
17+
FabricMgr(DBConnector *cfgDb, DBConnector *appDb, const std::vector<std::string> &tableNames);
18+
19+
using Orch::doTask;
20+
private:
21+
Table m_cfgFabricMonitorTable;
22+
Table m_cfgFabricPortTable;
23+
Table m_appFabricMonitorTable;
24+
Table m_appFabricPortTable;
25+
26+
void doTask(Consumer &consumer);
27+
bool writeConfigToAppDb(const std::string &alias, const std::string &field, const std::string &value);
28+
};
29+
30+
}

cfgmgr/fabricmgrd.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include <fstream>
2+
#include <iostream>
3+
#include <mutex>
4+
#include <unistd.h>
5+
#include <vector>
6+
7+
#include "exec.h"
8+
#include "fabricmgr.h"
9+
#include "schema.h"
10+
#include "select.h"
11+
12+
using namespace std;
13+
using namespace swss;
14+
15+
/* select() function timeout retry time, in millisecond */
16+
#define SELECT_TIMEOUT 1000
17+
18+
int main(int argc, char **argv)
19+
{
20+
Logger::linkToDbNative("fabricmgrd");
21+
SWSS_LOG_ENTER();
22+
23+
SWSS_LOG_NOTICE("--- Starting fabricmgrd ---");
24+
25+
try
26+
{
27+
vector<string> cfg_fabric_tables = {
28+
CFG_FABRIC_MONITOR_DATA_TABLE_NAME,
29+
CFG_FABRIC_MONITOR_PORT_TABLE_NAME,
30+
};
31+
32+
DBConnector cfgDb("CONFIG_DB", 0);
33+
DBConnector appDb("APPL_DB", 0);
34+
35+
FabricMgr fabricmgr(&cfgDb, &appDb, cfg_fabric_tables);
36+
37+
// TODO: add tables in stateDB which interface depends on to monitor list
38+
vector<Orch *> cfgOrchList = {&fabricmgr};
39+
40+
swss::Select s;
41+
for (Orch *o : cfgOrchList)
42+
{
43+
s.addSelectables(o->getSelectables());
44+
}
45+
46+
while (true)
47+
{
48+
Selectable *sel;
49+
int ret;
50+
51+
ret = s.select(&sel, SELECT_TIMEOUT);
52+
if (ret == Select::ERROR)
53+
{
54+
SWSS_LOG_NOTICE("Error: %s!", strerror(errno));
55+
continue;
56+
}
57+
if (ret == Select::TIMEOUT)
58+
{
59+
fabricmgr.doTask();
60+
continue;
61+
}
62+
63+
auto *c = (Executor *)sel;
64+
c->execute();
65+
}
66+
}
67+
catch (const exception &e)
68+
{
69+
SWSS_LOG_ERROR("Runtime error: %s", e.what());
70+
}
71+
return -1;
72+
}
73+

tests/test_fabric_port.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from swsscommon import swsscommon
2+
from dvslib.dvs_database import DVSDatabase
3+
4+
5+
class TestVirtualChassis(object):
6+
def test_voq_switch_fabric_link(self, vst):
7+
"""Test fabric link manual isolation commands in VOQ switch.
8+
9+
By issuing config fabric port isolation command, the value
10+
of isolateStatus field in config_db get changed. This test validates appl_db
11+
updates of a fabric link isolateStatus as the value in config_db changed.
12+
"""
13+
14+
dvss = vst.dvss
15+
for name in dvss.keys():
16+
dvs = dvss[name]
17+
# Get the config info
18+
config_db = dvs.get_config_db()
19+
metatbl = config_db.get_entry("DEVICE_METADATA", "localhost")
20+
21+
cfg_switch_type = metatbl.get("switch_type")
22+
if cfg_switch_type == "fabric":
23+
24+
# get config_db information
25+
cdb = dvs.get_config_db()
26+
27+
# set config_db to isolateStatus: True
28+
cdb.update_entry("FABRIC_PORT", "Fabric1", {"isolateStatus": "True"})
29+
cdb.wait_for_field_match("FABRIC_PORT", "Fabric1", {"isolateStatus": "True"})
30+
31+
# check if appl_db value changes to isolateStatus: True
32+
adb = dvs.get_app_db()
33+
adb.wait_for_field_match("FABRIC_PORT_TABLE", "Fabric1", {"isolateStatus": "True"})
34+
35+
# cleanup
36+
cdb.update_entry("FABRIC_PORT", "Fabric1", {"isolateStatus": "False"})
37+
cdb.wait_for_field_match("FABRIC_PORT", "Fabric1", {"isolateStatus": "False"})
38+
adb.wait_for_field_match("FABRIC_PORT_TABLE", "Fabric1", {"isolateStatus": "False"})
39+
else:
40+
print( "We do not check switch type:", cfg_switch_type )
41+
42+
43+
# Add Dummy always-pass test at end as workaroud
44+
# for issue when Flaky fail on final test it invokes module tear-down before retrying
45+
def test_nonflaky_dummy():
46+
pass
47+
48+

0 commit comments

Comments
 (0)