Skip to content

Fix inconsistent mux state #92

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
merged 2 commits into from
Jun 28, 2022
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
28 changes: 25 additions & 3 deletions src/link_manager/LinkManagerStateMachineActiveActive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,15 @@ void ActiveActiveStateMachine::initializeTransitionFunctionTable()
MUXLOGWARNING("Initializing State Transition Table...");
LinkManagerStateMachineBase::initializeTransitionFunctionTable();

mStateTransitionHandler[link_prober::LinkProberState::Label::Active]
[mux_state::MuxState::Label::Active]
[link_state::LinkState::Label::Up] =
boost::bind(
&ActiveActiveStateMachine::LinkProberActiveMuxActiveLinkUpTransitionFunction,
this,
boost::placeholders::_1
);

mStateTransitionHandler[link_prober::LinkProberState::Label::Active]
[mux_state::MuxState::Label::Standby]
[link_state::LinkState::Label::Up] =
Expand Down Expand Up @@ -580,6 +589,19 @@ void ActiveActiveStateMachine::initializeTransitionFunctionTable()
);
}

//
// ---> LinkProberActiveMuxActiveLinkUpTransitionFunction(CompositeState &nextState);
//
// transition function when entering {LinkProberActive, MuxActive, LinkUp} state
//
void ActiveActiveStateMachine::LinkProberActiveMuxActiveLinkUpTransitionFunction(CompositeState &nextState)
{
MUXLOGINFO(mMuxPortConfig.getPortName());
if (ms(mCompositeState) == mux_state::MuxState::Unknown) {
switchMuxState(nextState, mux_state::MuxState::Label::Active);
}
}

//
// ---> LinkProberActiveMuxStandbyLinkUpTransitionFunction(CompositeState &nextState);
//
Expand Down Expand Up @@ -1002,9 +1024,9 @@ void ActiveActiveStateMachine::handlePeerMuxWaitTimeout(boost::system::error_cod
}
}

//
//
// ---> handleDefaultRouteStateNotification(const DefaultRoute routeState);
//
//
// handle default route state notification from routeorch
//
void ActiveActiveStateMachine::handleDefaultRouteStateNotification(const DefaultRoute routeState)
Expand All @@ -1029,7 +1051,7 @@ void ActiveActiveStateMachine::shutdownOrRestartLinkProberOnDefaultRoute()
if (mMuxPortConfig.getMode() == common::MuxPortConfig::Mode::Auto && mDefaultRouteState == DefaultRoute::NA) {
mShutdownTxFnPtr();
} else {
// If mux mode is in manual/standby/active mode, we should restart link prober.
// If mux mode is in manual/standby/active mode, we should restart link prober.
// If default route state is "ok", we should retart link prober.
mRestartTxFnPtr();
}
Expand Down
9 changes: 9 additions & 0 deletions src/link_manager/LinkManagerStateMachineActiveActive.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ class ActiveActiveStateMachine : public LinkManagerStateMachineBase,
*/
void initializeTransitionFunctionTable() override;

/**
* @method LinkProberActiveMuxActiveLinkUpTransitionFunction
*
* @brief transition function when entering {LinkProberActive, MuxActive, LinkUp} state
*
* @param nextState reference to composite state
*/
void LinkProberActiveMuxActiveLinkUpTransitionFunction(CompositeState &nextState);

/**
* @method LinkProberActiveMuxStandbyLinkUpTransitionFunction
*
Expand Down
51 changes: 41 additions & 10 deletions test/LinkManagerStateMachineActiveActiveTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ TEST_F(LinkManagerStateMachineActiveActiveTest, MuxActiveLinkProberPeerUnknown)
TEST_F(LinkManagerStateMachineActiveActiveTest, MuxActiveConfigDetachedLinkProberPeerUnknown)
{
setMuxActive();

postPeerLinkProberEvent(link_prober::LinkProberState::PeerActive);
VALIDATE_PEER_STATE(PeerActive, Active);

Expand Down Expand Up @@ -415,26 +415,57 @@ TEST_F(LinkManagerStateMachineActiveActiveTest, MuxStandbyLinkProberPeerUnknown)
EXPECT_EQ(mDbInterfacePtr->mSetPeerMuxStateInvokeCount, 0);
}

TEST_F(LinkManagerStateMachineActiveActiveTest, MuxActivDefaultRouteState)
TEST_F(LinkManagerStateMachineActiveActiveTest, MuxActivDefaultRouteState)
{
setMuxActive();

postDefaultRouteEvent("ok", 1);
EXPECT_FALSE(mMuxConfig.getIfEnableDefaultRouteFeature());
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mShutdownTxProbeCallCount,0);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mRestartTxProbeCallCount,1);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mShutdownTxProbeCallCount, 0);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mRestartTxProbeCallCount, 1);

postDefaultRouteEvent("na", 1);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mShutdownTxProbeCallCount,0);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mRestartTxProbeCallCount,2);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mShutdownTxProbeCallCount, 0);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mRestartTxProbeCallCount, 2);

mMuxConfig.enableDefaultRouteFeature(true);
postDefaultRouteEvent("na", 1);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mShutdownTxProbeCallCount,1);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mRestartTxProbeCallCount,2);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mShutdownTxProbeCallCount, 1);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mRestartTxProbeCallCount, 2);

postDefaultRouteEvent("ok", 1);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mShutdownTxProbeCallCount,1);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mRestartTxProbeCallCount,3);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mShutdownTxProbeCallCount, 1);
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mRestartTxProbeCallCount, 3);
}

TEST_F(LinkManagerStateMachineActiveActiveTest, LinkmgrdBootupSequenceHeartBeatFirst)
{
activateStateMachine();
VALIDATE_STATE(Wait, Wait, Down);

postLinkEvent(link_state::LinkState::Up);
VALIDATE_STATE(Wait, Wait, Up);

// the first toggle fails because the the inital mux state
// is standby when linkmgrd first boots up
postLinkProberEvent(link_prober::LinkProberState::Active, 4);
VALIDATE_STATE(Active, Active, Up);
EXPECT_EQ(mDbInterfacePtr->mSetMuxStateInvokeCount, 1);
EXPECT_EQ(mDbInterfacePtr->mLastSetMuxState, mux_state::MuxState::Label::Active);

// now linkmgrd should be stuck in mux wait timeout

handleProbeMuxState("unknown", 3);
VALIDATE_STATE(Active, Unknown, Up);

// now linkmgrd should be stuck in mux probe timeout
runIoService(4);

// xcvrd now answers the mux probe
handleProbeMuxState("active", 4);
VALIDATE_STATE(Active, Active, Up);
EXPECT_EQ(mDbInterfacePtr->mSetMuxStateInvokeCount, 2);
EXPECT_EQ(mDbInterfacePtr->mLastSetMuxState, mux_state::MuxState::Label::Active);
}

} /* namespace test */