-
Notifications
You must be signed in to change notification settings - Fork 694
Add support for fabric monitor daemon (swss part). #2920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
prsunny
merged 15 commits into
sonic-net:master
from
jfeng-arista:master-add-fabric-monitor-daemon
Dec 2, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2fc409b
Add support for fabric monitor daemon (swss part).
jfeng-arista 7b73c97
Add test for fabric daemon
jfeng-arista 0dc9b25
remove global variables due to Orch class refactoring
jfeng-arista 98a5998
remove global variables due to Orch class refactoring
jfeng-arista e67c6e1
Merge branch 'master' into master-add-fabric-monitor-daemon
jfeng-arista cac41f6
Merge branch 'master' into master-add-fabric-monitor-daemon
jfeng-arista c2f7244
Merge branch 'master' into master-add-fabric-monitor-daemon
jfeng-arista 051cf22
Merge branch 'master' into master-add-fabric-monitor-daemon
jfeng-arista 81b1c3b
Merge branch 'master' into master-add-fabric-monitor-daemon
jfeng-arista 371e754
Merge branch 'master' into master-add-fabric-monitor-daemon
jfeng-arista 714bdc1
Merge branch 'master' into master-add-fabric-monitor-daemon
jfeng-arista da63ed4
Merge branch 'master' into master-add-fabric-monitor-daemon
jfeng-arista 4fc80a3
update fabric_port test
jfeng-arista aa17cb1
Merge branch 'master' into master-add-fabric-monitor-daemon
prsunny d1bbb7e
Merge branch 'master' into master-add-fabric-monitor-daemon
prsunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,119 @@ | ||
| #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; | ||
| 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) == "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_NOTICE("Write FABRIC_MONITOR:%s %s to %s", key.c_str(), field.c_str(), value.c_str()); | ||
| } | ||
| else | ||
| { | ||
| m_appFabricPortTable.set(key, fvs); | ||
| SWSS_LOG_NOTICE("Write FABRIC_PORT:%s %s to %s", key.c_str(), field.c_str(), value.c_str()); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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,30 @@ | ||
| #pragma once | ||
|
|
||
| #include "dbconnector.h" | ||
| #include "orch.h" | ||
| #include "producerstatetable.h" | ||
|
|
||
| #include <map> | ||
| #include <set> | ||
| #include <string> | ||
|
|
||
| namespace swss { | ||
|
|
||
|
|
||
| class FabricMgr : public Orch | ||
| { | ||
| public: | ||
| FabricMgr(DBConnector *cfgDb, DBConnector *appDb, const std::vector<std::string> &tableNames); | ||
|
|
||
| using Orch::doTask; | ||
| private: | ||
| Table m_cfgFabricMonitorTable; | ||
| Table m_cfgFabricPortTable; | ||
| Table m_appFabricMonitorTable; | ||
| Table m_appFabricPortTable; | ||
|
|
||
| void doTask(Consumer &consumer); | ||
| bool writeConfigToAppDb(const std::string &alias, const std::string &field, const std::string &value); | ||
| }; | ||
|
|
||
| } |
This file contains hidden or 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,73 @@ | ||
| #include <fstream> | ||
| #include <iostream> | ||
| #include <mutex> | ||
| #include <unistd.h> | ||
| #include <vector> | ||
|
|
||
| #include "exec.h" | ||
| #include "fabricmgr.h" | ||
| #include "schema.h" | ||
| #include "select.h" | ||
|
|
||
| using namespace std; | ||
| using namespace swss; | ||
|
|
||
| /* select() function timeout retry time, in millisecond */ | ||
| #define SELECT_TIMEOUT 1000 | ||
|
|
||
| int main(int argc, char **argv) | ||
| { | ||
| Logger::linkToDbNative("fabricmgrd"); | ||
| SWSS_LOG_ENTER(); | ||
|
|
||
| SWSS_LOG_NOTICE("--- Starting fabricmgrd ---"); | ||
|
|
||
| try | ||
| { | ||
| vector<string> cfg_fabric_tables = { | ||
| CFG_FABRIC_MONITOR_DATA_TABLE_NAME, | ||
| CFG_FABRIC_MONITOR_PORT_TABLE_NAME, | ||
| }; | ||
|
|
||
| DBConnector cfgDb("CONFIG_DB", 0); | ||
| DBConnector appDb("APPL_DB", 0); | ||
|
|
||
| FabricMgr fabricmgr(&cfgDb, &appDb, cfg_fabric_tables); | ||
|
|
||
| // TODO: add tables in stateDB which interface depends on to monitor list | ||
| vector<Orch *> cfgOrchList = {&fabricmgr}; | ||
|
|
||
| swss::Select s; | ||
| for (Orch *o : cfgOrchList) | ||
| { | ||
| s.addSelectables(o->getSelectables()); | ||
| } | ||
|
|
||
| while (true) | ||
| { | ||
| Selectable *sel; | ||
| int ret; | ||
|
|
||
| ret = s.select(&sel, SELECT_TIMEOUT); | ||
| if (ret == Select::ERROR) | ||
| { | ||
| SWSS_LOG_NOTICE("Error: %s!", strerror(errno)); | ||
| continue; | ||
| } | ||
| if (ret == Select::TIMEOUT) | ||
| { | ||
| fabricmgr.doTask(); | ||
| continue; | ||
| } | ||
|
|
||
| auto *c = (Executor *)sel; | ||
| c->execute(); | ||
| } | ||
| } | ||
| catch (const exception &e) | ||
| { | ||
| SWSS_LOG_ERROR("Runtime error: %s", e.what()); | ||
| } | ||
| return -1; | ||
| } | ||
|
|
This file contains hidden or 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,48 @@ | ||
| from swsscommon import swsscommon | ||
| from dvslib.dvs_database import DVSDatabase | ||
|
|
||
|
|
||
| class TestVirtualChassis(object): | ||
| def test_voq_switch_fabric_link(self, vst): | ||
| """Test fabric link manual isolation commands in VOQ switch. | ||
|
|
||
| By issuing config fabric port isolation command, the value | ||
| of isolateStatus field in config_db get changed. This test validates appl_db | ||
| updates of a fabric link isolateStatus as the value in config_db changed. | ||
| """ | ||
|
|
||
| dvss = vst.dvss | ||
| for name in dvss.keys(): | ||
| dvs = dvss[name] | ||
| # Get the config info | ||
| config_db = dvs.get_config_db() | ||
| metatbl = config_db.get_entry("DEVICE_METADATA", "localhost") | ||
|
|
||
| cfg_switch_type = metatbl.get("switch_type") | ||
| if cfg_switch_type == "fabric": | ||
arlakshm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # get config_db information | ||
| cdb = dvs.get_config_db() | ||
|
|
||
| # set config_db to isolateStatus: True | ||
| cdb.update_entry("FABRIC_PORT", "Fabric1", {"isolateStatus": "True"}) | ||
| cdb.wait_for_field_match("FABRIC_PORT", "Fabric1", {"isolateStatus": "True"}) | ||
|
|
||
| # check if appl_db value changes to isolateStatus: True | ||
| adb = dvs.get_app_db() | ||
| adb.wait_for_field_match("FABRIC_PORT_TABLE", "Fabric1", {"isolateStatus": "True"}) | ||
|
|
||
| # cleanup | ||
| cdb.update_entry("FABRIC_PORT", "Fabric1", {"isolateStatus": "False"}) | ||
| cdb.wait_for_field_match("FABRIC_PORT", "Fabric1", {"isolateStatus": "False"}) | ||
| adb.wait_for_field_match("FABRIC_PORT_TABLE", "Fabric1", {"isolateStatus": "False"}) | ||
| else: | ||
| print( "We do not check switch type:", cfg_switch_type ) | ||
|
|
||
|
|
||
| # Add Dummy always-pass test at end as workaroud | ||
| # for issue when Flaky fail on final test it invokes module tear-down before retrying | ||
| def test_nonflaky_dummy(): | ||
| pass | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.