Skip to content
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

[action] [PR:223] [warmboot] use config_db connector to update mux mode config instead of CLI (#223) #227

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/DbInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,46 @@ void DbInterface::getSoCIpAddress(std::shared_ptr<swss::DBConnector> configDbCon
processSoCIpAddress(entries);
}

//
// ---> getMuxModeConfig();
//
// retrieve MUX mode configuration
//
std::map<std::string, std::string> DbInterface::getMuxModeConfig()
{
MUXLOGINFO("Reading MUX mode configuration");
std::shared_ptr<swss::DBConnector> configDbPtr = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0);
swss::Table configDbMuxCableTable(configDbPtr.get(), CFG_MUX_CABLE_TABLE_NAME);
std::vector<swss::KeyOpFieldsValuesTuple> entries;
std::map<std::string, std::string> PortToMuxModeConfigMapping;

configDbMuxCableTable.getContent(entries);

for (auto &entry: entries) {
std::string portName = kfvKey(entry);
std::vector<swss::FieldValueTuple> fieldValues = kfvFieldsValues(entry);

std::vector<swss::FieldValueTuple>::const_iterator cit = std::find_if(
fieldValues.cbegin(),
fieldValues.cend(),
[] (const swss::FieldValueTuple &fv) {return fvField(fv) == "state";}
);

if (cit != fieldValues.cend()) {
const std::string f = cit->first;
std::string muxMode = cit->second;

MUXLOGDEBUG(boost::format("port: %s, mode mux %s = %s") % portName % f % muxMode);

PortToMuxModeConfigMapping[portName] = muxMode;
} else {
MUXLOGERROR(boost::format("port: %s, mode mux is not found in %s table") % portName % CFG_MUX_CABLE_TABLE_NAME);
}
}

return PortToMuxModeConfigMapping;
}

// ---> warmRestartReconciliation(const std::string &portName);
//
// port warm restart reconciliation procedure
Expand Down
9 changes: 9 additions & 0 deletions src/DbInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,15 @@ class DbInterface
*/
virtual void setWarmStartStateReconciled(){swss::WarmStart::setWarmStartState("linkmgrd", swss::WarmStart::RECONCILED);};

/**
*@method getMuxModeConfig
*
*@brief retrieve mux mode config
*
*@return port to mux mode map
*/
virtual std::map<std::string, std::string> getMuxModeConfig();

private:
friend class test::MuxManagerTest;

Expand Down
11 changes: 9 additions & 2 deletions src/MuxManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,15 @@ void MuxManager::handleWarmRestartReconciliationTimeout(const boost::system::err
MUXLOGWARNING("Reconciliation timed out after warm restart, set service to reconciled now.");
}

int rc = system("sudo config muxcable mode auto all");
MUXLOGWARNING(boost::format("config mux mode back to auto completed with return code %d") % rc);
std::map<std::string, std::string> muxModeMap = mDbInterfacePtr->getMuxModeConfig();
for (auto it = muxModeMap.begin(); it != muxModeMap.end(); ++it) {
if (it->second == "auto") {
continue;
}

MUXLOGWARNING(boost::format("config mux mode back to auto for %s") % it->first);
mDbInterfacePtr->setMuxMode(it->first, "auto");
}

mDbInterfacePtr->setWarmStartStateReconciled();
}
Expand Down
9 changes: 9 additions & 0 deletions test/FakeDbInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,13 @@ void FakeDbInterface::postSwitchCause(
mLastPostedSwitchCause = cause;
}

std::map<std::string, std::string> FakeDbInterface::getMuxModeConfig()
{
mGetMuxModeConfigInvokeCount++;

std::map<std::string, std::string> muxModeConfig;
muxModeConfig["Ethernet0"] = "manual";
return muxModeConfig;
}

} /* namespace test */
2 changes: 2 additions & 0 deletions test/FakeDbInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class FakeDbInterface: public mux::DbInterface
virtual void handleSetMuxState(const std::string portName, mux_state::MuxState::Label label) override;
virtual void handleSetPeerMuxState(const std::string portName, mux_state::MuxState::Label label) override;
virtual void getMuxState(const std::string &portName) override;
virtual std::map<std::string, std::string> getMuxModeConfig() override;
virtual void probeMuxState(const std::string &portName) override;
virtual void handleProbeForwardingState(const std::string portName) override;
virtual void setMuxLinkmgrState(
Expand Down Expand Up @@ -95,6 +96,7 @@ class FakeDbInterface: public mux::DbInterface
uint32_t mSetMuxModeInvokeCount = 0;
uint32_t mSetWarmStartStateReconciledInvokeCount = 0;
uint32_t mPostSwitchCauseInvokeCount = 0;
uint32_t mGetMuxModeConfigInvokeCount = 0;

link_manager::ActiveStandbyStateMachine::SwitchCause mLastPostedSwitchCause;

Expand Down