Skip to content

Commit

Permalink
Signed-off-by: Jaganathan Anbalagan <[email protected]>
Browse files Browse the repository at this point in the history
orchagent changes for sonic-net/SONiC#916
  • Loading branch information
Jaganathan Anbalagan committed Jul 1, 2022
1 parent a8e238a commit 086c58a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
61 changes: 56 additions & 5 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,36 @@ void PortsOrch::getCpuPort(Port &port)
port = m_cpuPort;
}

bool PortsOrch::initHostTxReadyState(Port &port)
{
SWSS_LOG_ENTER();

vector<FieldValueTuple> tuples;
bool exist = m_portStateTable.get(port.m_alias, tuples);
string hostTxReady;

if (exist)
{
for (auto i : tuples)
{
if (fvField(i) == "host_tx_ready")
{
hostTxReady = fvValue(i);
}
}
}

/* Create host_tx_ready field in state-DB and set it to false by default. */
if (hostTxReady.empty())
{
m_portStateTable.hset(port.m_alias, "host_tx_ready", "false");
SWSS_LOG_INFO("initalize hostTxReady %s with status %s",
port.m_alias.c_str(), hostTxReady.c_str());
}

return true;
}

bool PortsOrch::setPortAdminStatus(Port &port, bool state)
{
SWSS_LOG_ENTER();
Expand All @@ -1040,6 +1070,13 @@ bool PortsOrch::setPortAdminStatus(Port &port, bool state)
attr.id = SAI_PORT_ATTR_ADMIN_STATE;
attr.value.booldata = state;

/* Update the host_tx_ready to false before setting admin_state, when admin state is false */
if (!state)
{
m_portStateTable.hset(port.m_alias, "host_tx_ready", "false");
SWSS_LOG_INFO("Set admin status false %s to port pid:%" PRIx64, state ? "true" : "false", port.m_port_id);
}

sai_status_t status = sai_port_api->set_port_attribute(port.m_port_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
Expand All @@ -1052,10 +1089,20 @@ bool PortsOrch::setPortAdminStatus(Port &port, bool state)
}
}

SWSS_LOG_INFO("Set admin status %s to port pid:%" PRIx64,
state ? "UP" : "DOWN", port.m_port_id);

setGearboxPortsAttr(port, SAI_PORT_ATTR_ADMIN_STATE, &state);
bool gbstatus = setGearboxPortsAttr(port, SAI_PORT_ATTR_ADMIN_STATE, &state);
if(gbstatus != true)
{
SWSS_LOG_ERROR("Failed to set admin status on PHY %s to port pid:%" PRIx64,
state ? "UP" : "DOWN", port.m_port_id);
/* add task handler to recover/take action on this failure */
}

/* Update the state table for 'host_tx_ready'*/
if (state && (gbstatus == true) && (status == SAI_STATUS_SUCCESS) )
{
m_portStateTable.hset(port.m_alias, "host_tx_ready", "true");
SWSS_LOG_INFO("Set admin status true %s to port pid:%" PRIx64, state ? "true" : "false", port.m_port_id);
}

return true;
}
Expand Down Expand Up @@ -1940,7 +1987,7 @@ void PortsOrch::initPortSupportedSpeeds(const std::string& alias, sai_object_id_
*/
bool PortsOrch::setGearboxPortsAttr(Port &port, sai_port_attr_t id, void *value)
{
bool status;
bool status = false;

status = setGearboxPortAttr(port, PHY_PORT_TYPE, id, value);

Expand Down Expand Up @@ -3363,6 +3410,10 @@ void PortsOrch::doPortTask(Consumer &consumer)

}

if (!initHostTxReadyState(p)) {
SWSS_LOG_ERROR("Failed to initialize host_tx_ready for port %s ", alias.c_str());
}

/* Last step set port admin status */
if (!admin_status.empty() && (p.m_admin_state_up != (admin_status == "up")))
{
Expand Down
1 change: 1 addition & 0 deletions orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class PortsOrch : public Orch, public Subject
bool getPortByBridgePortId(sai_object_id_t bridge_port_id, Port &port);
void setPort(string alias, Port port);
void getCpuPort(Port &port);
bool initHostTxReadyState(Port &port);
bool getInbandPort(Port &port);
bool getVlanByVlanId(sai_vlan_id_t vlan_id, Port &vlan);

Expand Down

0 comments on commit 086c58a

Please sign in to comment.