Skip to content

Commit

Permalink
Update StateDB with error if state change failed, Update APP_DB in al…
Browse files Browse the repository at this point in the history
…l state chg req (sonic-net#1662)

If orchagent fails in state change, update StateDB with "error" state
Update APP_DB for every state change request from Linkmgr irrespective of internal handling in orchagent
  • Loading branch information
prsunny authored and raphaelt-nvidia committed Oct 5, 2021
1 parent c63a0cd commit ad51231
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 14 additions & 5 deletions orchagent/muxorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern sai_router_interface_api_t* sai_router_intfs_api;
#define MUX_ACL_TABLE_NAME "mux_acl_table";
#define MUX_ACL_RULE_NAME "mux_acl_rule";
#define MUX_HW_STATE_UNKNOWN "unknown"
#define MUX_HW_STATE_PENDING "pending"
#define MUX_HW_STATE_ERROR "error"

const map<std::pair<MuxState, MuxState>, MuxStateChange> muxStateTransition =
{
Expand Down Expand Up @@ -387,6 +387,9 @@ void MuxCable::setState(string new_state)
SWSS_LOG_NOTICE("[%s] Set MUX state from %s to %s", mux_name_.c_str(),
muxStateValToString.at(state_).c_str(), new_state.c_str());

// Update HW Mux cable state anyways
mux_cb_orch_->updateMuxState(mux_name_, new_state);

MuxState ns = muxStateStringToVal.at(new_state);

auto it = muxStateTransition.find(make_pair(state_, ns));
Expand All @@ -398,8 +401,6 @@ void MuxCable::setState(string new_state)
return;
}

mux_cb_orch_->updateMuxState(mux_name_, new_state);

MuxState state = state_;
state_ = ns;

Expand All @@ -410,6 +411,7 @@ void MuxCable::setState(string new_state)
//Reset back to original state
state_ = state;
st_chg_in_progress_ = false;
st_chg_failed_ = true;
throw std::runtime_error("Failed to handle state transition");
}

Expand Down Expand Up @@ -1272,7 +1274,7 @@ bool MuxCableOrch::addOperation(const Request& request)
{
SWSS_LOG_ERROR("Mux Error setting state %s for port %s. Error: %s",
state.c_str(), port_name.c_str(), error.what());
return false;
return true;
}

SWSS_LOG_NOTICE("Mux State set to %s for port %s", state.c_str(), port_name.c_str());
Expand Down Expand Up @@ -1341,7 +1343,14 @@ bool MuxStateOrch::addOperation(const Request& request)

if (mux_state != hw_state)
{
mux_state = MUX_HW_STATE_UNKNOWN;
if (mux_obj->isStateChangeFailed())
{
mux_state = MUX_HW_STATE_ERROR;
}
else
{
mux_state = MUX_HW_STATE_UNKNOWN;
}
}

SWSS_LOG_NOTICE("Mux setting State DB entry (hw state %s, mux state %s) for port %s",
Expand Down
2 changes: 2 additions & 0 deletions orchagent/muxorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class MuxCable
void setState(string state);
string getState();
bool isStateChangeInProgress() { return st_chg_in_progress_; }
bool isStateChangeFailed() { return st_chg_failed_; }

bool isIpInSubnet(IpAddress ip);
void updateNeighbor(NextHopKey nh, bool add);
Expand All @@ -107,6 +108,7 @@ class MuxCable

MuxState state_ = MuxState::MUX_STATE_INIT;
bool st_chg_in_progress_ = false;
bool st_chg_failed_ = false;

IpPrefix srv_ip4_, srv_ip6_;
IpAddress peer_ip4_;
Expand Down

0 comments on commit ad51231

Please sign in to comment.