Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into bookworm
  • Loading branch information
zjswhhh committed Jul 10, 2024
2 parents 005af1c + 2b7e4f9 commit 410472c
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 10 deletions.
28 changes: 28 additions & 0 deletions src/DbInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,34 @@ void DbInterface::processMuxLinkmgrConfigNotifiction(std::deque<swss::KeyOpField
}
}

MUXLOGINFO(boost::format("key: %s, Operation: %s, f: %s, v: %s") %
key %
operation %
f %
v
);
}
} else if (key == "TIMED_OSCILLATION") {
std::string operation = kfvOp(entry);
std::vector<swss::FieldValueTuple> 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") {
try {
mMuxManagerPtr->setOscillationInterval_sec(boost::lexical_cast<uint32_t> (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") %
key %
operation %
Expand Down
22 changes: 22 additions & 0 deletions src/MuxManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
5 changes: 2 additions & 3 deletions src/MuxPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,11 @@ void MuxPort::handleDefaultRouteState(const std::string &routeState)
state = link_manager::LinkManagerStateMachineBase::DefaultRoute::NA;
}

boost::asio::io_service &ioService = mStrand.context();
ioService.post(mStrand.wrap(boost::bind(
boost::asio::post(mStrand, boost::bind(
&link_manager::LinkManagerStateMachineBase::handleDefaultRouteStateNotification,
mLinkManagerStateMachinePtr.get(),
state
)));
));
}

//
Expand Down
24 changes: 23 additions & 1 deletion src/common/MuxConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions src/common/MuxPortConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
41 changes: 37 additions & 4 deletions src/link_manager/LinkManagerStateMachineActiveStandby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ ActiveStandbyStateMachine::ActiveStandbyStateMachine(
mMuxStateMachine.setWaitStateCause(mux_state::WaitState::WaitStateCause::SwssUpdate);
mMuxPortPtr->setMuxLinkmgrState(mLabel);
initializeTransitionFunctionTable();

mOscillationTimer.expires_from_now(boost::posix_time::seconds(1));
}

//
Expand Down Expand Up @@ -476,12 +474,16 @@ void ActiveStandbyStateMachine::handleStateChange(LinkProberEvent &event, link_p
mMuxPortPtr->postLinkProberMetricsEvent(link_manager::ActiveStandbyStateMachine::LinkProberMetrics::LinkProberActiveStart);

mStandbyUnknownUpCount = 0;

tryCancelOscillationTimerIfAlive();
}

if (state == link_prober::LinkProberState::Label::Standby) {
mMuxPortPtr->postLinkProberMetricsEvent(link_manager::ActiveStandbyStateMachine::LinkProberMetrics::LinkProberStandbyStart);

mActiveUnknownUpCount = 0;

tryCancelOscillationTimerIfAlive();
}

CompositeState nextState = mCompositeState;
Expand Down Expand Up @@ -542,6 +544,10 @@ void ActiveStandbyStateMachine::handleStateChange(MuxStateEvent &event, mux_stat
mStandbyUnknownUpCount = 0;
}

if (state == mux_state::MuxState::Label::Standby) {
tryCancelOscillationTimerIfAlive();
}

updateMuxLinkmgrState();
}

Expand All @@ -567,6 +573,9 @@ void ActiveStandbyStateMachine::handleStateChange(LinkStateEvent &event, link_st
// There is a problem with this approach as it will hide link flaps that result in lost heart-beats.
initLinkProberState(nextState, true);
// enterMuxWaitState(nextState);

// reset mux probing backoff factor when link goes up
mMuxUnknownBackoffFactor = 1;
} else if (ls(mCompositeState) == link_state::LinkState::Up &&
ls(nextState) == link_state::LinkState::Down &&
ms(mCompositeState) != mux_state::MuxState::Label::Standby) {
Expand All @@ -575,6 +584,12 @@ void ActiveStandbyStateMachine::handleStateChange(LinkStateEvent &event, link_st

mActiveUnknownUpCount = 0;
mStandbyUnknownUpCount = 0;

mWaitActiveUpCount = 0;
mWaitStandbyUpBackoffFactor = 1;
mUnknownActiveUpBackoffFactor = 1;

tryCancelOscillationTimerIfAlive();
} else {
mStateTransitionHandler[ps(nextState)][ms(nextState)][ls(nextState)](nextState);
}
Expand Down Expand Up @@ -1057,6 +1072,8 @@ void ActiveStandbyStateMachine::handleMuxWaitTimeout(boost::system::error_code e
void ActiveStandbyStateMachine::startOscillationTimer()
{
// Note: This timer is started when Mux state is active and link prober is in wait state.
MUXLOGINFO(boost::format("%s: start the oscillation timer") % mMuxPortConfig.getPortName());
mOscillationTimerAlive = true;
mOscillationTimer.expires_from_now(boost::posix_time::seconds(
mMuxPortConfig.getOscillationInterval_sec()
));
Expand All @@ -1067,6 +1084,20 @@ void ActiveStandbyStateMachine::startOscillationTimer()
)));
}

//
// ---> tryCancelOscillationTimerIfAlive();
//
// cancel the oscillation timer if it is alive
//
void ActiveStandbyStateMachine::tryCancelOscillationTimerIfAlive()
{
if (mOscillationTimerAlive) {
MUXLOGINFO(boost::format("%s: cancel the oscillation timer") % mMuxPortConfig.getPortName());
mOscillationTimerAlive = false;
mOscillationTimer.cancel();
}
}

//
// ---> handleOscillationTimeout(boost::system::error_code errorCode);
//
Expand All @@ -1076,7 +1107,9 @@ void ActiveStandbyStateMachine::handleOscillationTimeout(boost::system::error_co
{
MUXLOGDEBUG(mMuxPortConfig.getPortName());

if (errorCode == boost::system::errc::success &&
mOscillationTimerAlive = false;
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) {
Expand Down Expand Up @@ -1310,7 +1343,7 @@ void ActiveStandbyStateMachine::LinkProberWaitMuxActiveLinkUpTransitionFunction(
mSuspendTxFnPtr(mMuxPortConfig.getLinkWaitTimeout_msec());
}

if (mOscillationTimer.expires_at() < boost::posix_time::microsec_clock::local_time()) {
if (!mOscillationTimerAlive) {
startOscillationTimer();
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/link_manager/LinkManagerStateMachineActiveStandby.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,15 @@ class ActiveStandbyStateMachine: public LinkManagerStateMachineBase,
*/
void startOscillationTimer();

/**
*@method tryCancelOscillationTimerIfAlive
*
*@brief cancel the oscillation timer if it is alive
*
*@return none
*/
inline void tryCancelOscillationTimerIfAlive();

/**
*@method handleOscillationTimeout
*
Expand Down Expand Up @@ -859,6 +868,7 @@ class ActiveStandbyStateMachine: public LinkManagerStateMachineBase,
boost::asio::deadline_timer mDeadlineTimer;
boost::asio::deadline_timer mWaitTimer;
boost::asio::deadline_timer mOscillationTimer;
bool mOscillationTimerAlive = false;

boost::function<void ()> mInitializeProberFnPtr;
boost::function<void ()> mStartProbingFnPtr;
Expand Down
1 change: 1 addition & 0 deletions test/FakeMuxPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class FakeMuxPort : public ::mux::MuxPort {
link_prober::LinkProberStateMachineBase* getLinkProberStateMachinePtr() { return getLinkManagerStateMachinePtr()->getLinkProberStateMachinePtr().get(); };
mux_state::MuxStateMachine& getMuxStateMachine() { return getLinkManagerStateMachinePtr()->getMuxStateMachine(); };
link_state::LinkStateMachine& getLinkStateMachine() { return getLinkManagerStateMachinePtr()->getLinkStateMachine(); };
link_manager::LinkManagerStateMachineBase::DefaultRoute getDefaultRouteState() { return getLinkManagerStateMachinePtr()->getDefaultRouteState(); };

bool getPendingMuxModeChange() { return getActiveStandbyStateMachinePtr()->mPendingMuxModeChange; };
common::MuxPortConfig::Mode getTargetMuxMode() { return getActiveStandbyStateMachinePtr()->mTargetMuxMode; };
Expand Down
Loading

0 comments on commit 410472c

Please sign in to comment.