From 29bcb52acb276b5662bc484450ec07d32738e443 Mon Sep 17 00:00:00 2001 From: Jing Zhang Date: Thu, 23 May 2024 00:17:18 +0000 Subject: [PATCH 1/6] .. --- src/DbInterface.cpp | 24 +++++++++++++++++++ src/MuxManager.h | 22 +++++++++++++++++ src/common/MuxConfig.h | 24 ++++++++++++++++++- src/common/MuxPortConfig.h | 9 +++++++ .../LinkManagerStateMachineActiveStandby.cpp | 3 ++- 5 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/DbInterface.cpp b/src/DbInterface.cpp index d5f43572..99321839 100644 --- a/src/DbInterface.cpp +++ b/src/DbInterface.cpp @@ -1076,6 +1076,30 @@ void DbInterface::processMuxLinkmgrConfigNotifiction(std::deque fieldValues = kfvFieldsValues(entry); + + for (auto &fieldValue: fieldValues) { + std::string f = fvField(fieldValue); + std::string v = fvValue(fieldValue); + if (f == "oscillation_enabled") { + if (v == "true") { + mMuxManagerPtr->setOscillationEnabled(true); + } else if (v == "false"){ + mMuxManagerPtr->setOscillationEnabled(false); + } + } else if (f == "interval_sec") { + mMuxManagerPtr->setOscillationInterval_sec(boost::lexical_cast (v)); + } + MUXLOGINFO(boost::format("key: %s, Operation: %s, f: %s, v: %s") % key % operation % diff --git a/src/MuxManager.h b/src/MuxManager.h index 3ae75b72..d49fe2c7 100644 --- a/src/MuxManager.h +++ b/src/MuxManager.h @@ -123,6 +123,28 @@ class MuxManager */ inline void setTimeoutIpv6_msec(uint32_t timeout_msec) {mMuxConfig.setTimeoutIpv6_msec(timeout_msec);}; + /** + *@method setOscillationEnabled + * + *@brief setter for enable/disable oscillation + * + *@param enable (in) true to enable oscillation + * + *@return none + */ + inline void setOscillationEnabled(bool enable) {mMuxConfig.setOscillationEnabled(enable);}; + + /** + *@method setOscillationInterval_sec + * + *@brief setter for oscillation interval in sec + * + *@param interval_sec (in) interval in sec + * + *@return none + */ + inline void setOscillationInterval_sec(uint32_t interval_sec) {mMuxConfig.setOscillationInterval_sec(interval_sec);}; + /** *@method setLinkProberStatUpdateIntervalCount * diff --git a/src/common/MuxConfig.h b/src/common/MuxConfig.h index 588492cb..8ad6454e 100644 --- a/src/common/MuxConfig.h +++ b/src/common/MuxConfig.h @@ -97,6 +97,17 @@ class MuxConfig */ inline void setTimeoutIpv6_msec(uint32_t timeout_msec) {mTimeoutIpv6_msec = timeout_msec;}; + /** + *@method setOscillationEnabled + * + *@brief setter for enabling/disabling mux state oscillation + * + *@param enable (in) enable/disable mux state oscillation + * + *@return none + */ + inline void setOscillationEnabled(bool enable) {mEnableTimedOscillationWhenNoHeartbeat = enable;}; + /** *@method setLinkProberStatUpdateIntervalCount * @@ -274,6 +285,15 @@ class MuxConfig */ inline uint32_t getSuspendTimeout_msec() const {return (mNegativeStateChangeRetryCount + 1) * mTimeoutIpv4_msec;}; + /** + *@method getIfOscillationEnabled + * + *@brief getter for oscillation flag + * + *@return oscillation flag + */ + inline bool getIfOscillationEnabled() const {return mEnableTimedOscillationWhenNoHeartbeat;}; + /** *@method getOscillationInterval_sec * @@ -433,7 +453,6 @@ class MuxConfig private: uint8_t mNumberOfThreads = 5; - uint32_t mOscillationTimeout_sec = 300; uint32_t mTimeoutIpv4_msec = 100; uint32_t mTimeoutIpv6_msec = 1000; uint32_t mPositiveStateChangeRetryCount = 1; @@ -443,6 +462,9 @@ class MuxConfig uint32_t mMuxStateChangeRetryCount = 1; uint32_t mLinkStateChangeRetryCount = 1; + bool mEnableTimedOscillationWhenNoHeartbeat = true; + uint32_t mOscillationTimeout_sec = 300; + bool mEnableSwitchoverMeasurement = false; uint32_t mDecreasedTimeoutIpv4_msec = 10; diff --git a/src/common/MuxPortConfig.h b/src/common/MuxPortConfig.h index bc1f82e0..fa8a8b60 100644 --- a/src/common/MuxPortConfig.h +++ b/src/common/MuxPortConfig.h @@ -192,6 +192,15 @@ class MuxPortConfig */ inline uint32_t getLinkWaitTimeout_msec() const {return mMuxConfig.getSuspendTimeout_msec();}; + /** + *@method getIfOscillationEnabled + * + *@brief getter for mux state oscillation enable flag + * + *@return oscillation enable flag + */ + inline bool getIfOscillationEnabled() const {return mMuxConfig.getIfOscillationEnabled();}; + /** *@method getOscillationInterval_sec * diff --git a/src/link_manager/LinkManagerStateMachineActiveStandby.cpp b/src/link_manager/LinkManagerStateMachineActiveStandby.cpp index cfb5cea3..e7c668cd 100644 --- a/src/link_manager/LinkManagerStateMachineActiveStandby.cpp +++ b/src/link_manager/LinkManagerStateMachineActiveStandby.cpp @@ -1083,7 +1083,8 @@ void ActiveStandbyStateMachine::handleOscillationTimeout(boost::system::error_co { MUXLOGDEBUG(mMuxPortConfig.getPortName()); - if (errorCode == boost::system::errc::success && + if (mMuxPortConfig.getIfOscillationEnabled() && + errorCode == boost::system::errc::success && ps(mCompositeState) == link_prober::LinkProberState::Label::Wait && ms(mCompositeState) == mux_state::MuxState::Label::Active && ls(mCompositeState) == link_state::LinkState::Label::Up) { From cd620036b28198660d5c57b025d7703bed60a5b0 Mon Sep 17 00:00:00 2001 From: Jing Zhang Date: Thu, 23 May 2024 21:25:24 +0000 Subject: [PATCH 2/6] UT --- test/MuxManagerTest.cpp | 54 +++++++++++++++++++++++++++++++++++++++++ test/MuxManagerTest.h | 7 ++++++ 2 files changed, 61 insertions(+) diff --git a/test/MuxManagerTest.cpp b/test/MuxManagerTest.cpp index 461b8ca1..5c483218 100644 --- a/test/MuxManagerTest.cpp +++ b/test/MuxManagerTest.cpp @@ -479,6 +479,20 @@ void MuxManagerTest::resetUpdateEthernetFrameFn(const std::string &portName) } } +uint32_t MuxManagerTest::getOscillationInterval_sec(std::string port) +{ + std::shared_ptr muxPortPtr = mMuxManagerPtr->mPortMap[port]; + + return muxPortPtr->mMuxPortConfig.getOscillationInterval_sec(); +} + +bool MuxManagerTest::getOscillationEnabled(std::string port) +{ + std::shared_ptr muxPortPtr = mMuxManagerPtr->mPortMap[port]; + + return muxPortPtr->mMuxPortConfig.getIfOscillationEnabled(); +} + TEST_F(MuxManagerTest, UpdatePortCableTypeActiveStandby) { std::string port = MuxManagerTest::PortName; @@ -663,6 +677,46 @@ TEST_F(MuxManagerTest, SrcMacAddressUpdate) EXPECT_TRUE(mFakeLinkProber->mUpdateEthernetFrameCallCount == updateEthernetFrameCallCountBefore + 1); } +TEST_P(OscillationIntervalTest, OscillationInterval) +{ + std::string port = "Ethernet0"; + createPort(port); + + std::deque entries = { + {"TIMED_OSCILLATION", "SET", {{"oscillation_interval", std::get<0>(GetParam())}}} + }; + processMuxLinkmgrConfigNotifiction(entries); + + runIoService(); + + EXPECT_TRUE(getOscillationInterval_sec(port) == std::get<1>(GetParam())); +} + +INSTANTIATE_TEST_CASE_P( + OscillationInterval, + OscillationIntervalTest, + ::testing::Values( + std::make_tuple("1200", 1200), + std::make_tuple("1", 300), + std::make_tuple("invalid", 300), + ) +); + +TEST_F(MuxManagerTest, OscillationDisabled) +{ + std::string port = "Ethernet0"; + createPort(port); + + std::deque entries = { + {"TIMED_OSCILLATION", "SET", {{"oscillation_enabled", "false"}}} + }; + processMuxLinkmgrConfigNotifiction(entries); + + runIoService(); + + EXPECT_TRUE(getOscillationEnabled(port) == false); +} + TEST_F(MuxManagerTest, ServerMacAddress) { std::string port = "Ethernet0"; diff --git a/test/MuxManagerTest.h b/test/MuxManagerTest.h index 5874d4fb..8d3fda92 100644 --- a/test/MuxManagerTest.h +++ b/test/MuxManagerTest.h @@ -56,9 +56,11 @@ class MuxManagerTest: public testing::Test uint32_t getTimeoutIpv4_msec(std::string port); uint32_t getTimeoutIpv6_msec(std::string port); uint32_t getLinkWaitTimeout_msec(std::string port); + uint32_t getOscillationInterval_sec(std::string port); bool getIfUseWellKnownMac(std::string port); bool setUseWellKnownMacActiveActive(bool use); bool getIfUseToRMac(std::string port); + bool getOscillationEnabled(std::string port); boost::asio::ip::address getBladeIpv4Address(std::string port); std::array getBladeMacAddress(std::string port); std::array getLastUpdatedMacAddress(std::string port); @@ -123,6 +125,11 @@ class MuxConfigUpdateTest: public MuxManagerTest, { }; +class OscillationIntervalTest: public MuxManagerTest, + public testing::WithParamInterface> +{ +}; + } /* namespace test */ #endif /* MUXMANAGERTEST_H_ */ From b4970a341336f1ac719b2bc2858ed8eecd33c618 Mon Sep 17 00:00:00 2001 From: Jing Zhang Date: Thu, 23 May 2024 21:28:22 +0000 Subject: [PATCH 3/6] UT --- test/MuxManagerTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/MuxManagerTest.cpp b/test/MuxManagerTest.cpp index 5c483218..b2f058a0 100644 --- a/test/MuxManagerTest.cpp +++ b/test/MuxManagerTest.cpp @@ -698,7 +698,7 @@ INSTANTIATE_TEST_CASE_P( ::testing::Values( std::make_tuple("1200", 1200), std::make_tuple("1", 300), - std::make_tuple("invalid", 300), + std::make_tuple("invalid", 300) ) ); From dc2f4236e0b7715daea07a37c1be96900e9e6476 Mon Sep 17 00:00:00 2001 From: Jing Zhang Date: Thu, 23 May 2024 22:12:22 +0000 Subject: [PATCH 4/6] UT --- test/MuxManagerTest.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/MuxManagerTest.cpp b/test/MuxManagerTest.cpp index b2f058a0..c2ded45c 100644 --- a/test/MuxManagerTest.cpp +++ b/test/MuxManagerTest.cpp @@ -687,8 +687,6 @@ TEST_P(OscillationIntervalTest, OscillationInterval) }; processMuxLinkmgrConfigNotifiction(entries); - runIoService(); - EXPECT_TRUE(getOscillationInterval_sec(port) == std::get<1>(GetParam())); } @@ -712,8 +710,6 @@ TEST_F(MuxManagerTest, OscillationDisabled) }; processMuxLinkmgrConfigNotifiction(entries); - runIoService(); - EXPECT_TRUE(getOscillationEnabled(port) == false); } From c709586b434d6a9f0d2bf33f3da4cead1261a44b Mon Sep 17 00:00:00 2001 From: Jing Zhang Date: Fri, 24 May 2024 17:14:51 +0000 Subject: [PATCH 5/6] .. --- test/MuxManagerTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/MuxManagerTest.cpp b/test/MuxManagerTest.cpp index c2ded45c..f4d5da9f 100644 --- a/test/MuxManagerTest.cpp +++ b/test/MuxManagerTest.cpp @@ -683,7 +683,7 @@ TEST_P(OscillationIntervalTest, OscillationInterval) createPort(port); std::deque entries = { - {"TIMED_OSCILLATION", "SET", {{"oscillation_interval", std::get<0>(GetParam())}}} + {"TIMED_OSCILLATION", "SET", {{"interval_sec", std::get<0>(GetParam())}}} }; processMuxLinkmgrConfigNotifiction(entries); From ef2d71b87fafb477b442a0749ddc6da762b95406 Mon Sep 17 00:00:00 2001 From: Jing Zhang Date: Fri, 24 May 2024 18:22:55 +0000 Subject: [PATCH 6/6] .. --- src/DbInterface.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/DbInterface.cpp b/src/DbInterface.cpp index 99321839..21688b75 100644 --- a/src/DbInterface.cpp +++ b/src/DbInterface.cpp @@ -1097,7 +1097,11 @@ void DbInterface::processMuxLinkmgrConfigNotifiction(std::dequesetOscillationEnabled(false); } } else if (f == "interval_sec") { - mMuxManagerPtr->setOscillationInterval_sec(boost::lexical_cast (v)); + try { + mMuxManagerPtr->setOscillationInterval_sec(boost::lexical_cast (v)); + } catch (boost::bad_lexical_cast const &badLexicalCast) { + MUXLOGWARNING(boost::format("bad lexical cast: %s") % badLexicalCast.what()); + } } MUXLOGINFO(boost::format("key: %s, Operation: %s, f: %s, v: %s") %