From 75972e77c3c167d1f90dcdc5b295169f486feeb1 Mon Sep 17 00:00:00 2001 From: Jipan Yang Date: Tue, 13 Nov 2018 17:01:23 -0800 Subject: [PATCH] =?UTF-8?q?Restore=20port=20oper=20status=20form=20appDB?= =?UTF-8?q?=20port=20table=20during=20restore=20phase=20o=E2=80=A6=20(#683?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Restore port oper status form appDB port table during restore phase of warm restart Signed-off-by: Jipan Yang * Restore port oper_status upon initializePort() for warm start Signed-off-by: Jipan Yang --- orchagent/portsorch.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index bfc571d73306..c0dab54e647f 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -2304,6 +2304,24 @@ bool PortsOrch::initializePort(Port &p) p.m_oper_status = SAI_PORT_OPER_STATUS_UP; } + /* + * If oper_status is not empty, orchagent is doing warm start, restore hostif oper status. + */ + if (!operStatus.empty()) + { + sai_attribute_t attr; + attr.id = SAI_HOSTIF_ATTR_OPER_STATUS; + attr.value.booldata = (p.m_oper_status == SAI_PORT_OPER_STATUS_UP); + + sai_status_t status = sai_hostif_api->set_hostif_attribute(p.m_hif_id, &attr); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_WARN("Failed to set operation status %s to host interface %s", + operStatus.c_str(), p.m_alias.c_str()); + return false; + } + } + return true; } @@ -2914,11 +2932,7 @@ void PortsOrch::doTask(NotificationConsumer &consumer) SWSS_LOG_ERROR("Failed to get port object for port id 0x%lx", id); continue; } - - if (status != port.m_oper_status) - { - updatePortOperStatus(port, status); - } + updatePortOperStatus(port, status); } sai_deserialize_free_port_oper_status_ntf(count, portoperstatus); @@ -2930,11 +2944,13 @@ void PortsOrch::updatePortOperStatus(Port &port, sai_port_oper_status_t status) SWSS_LOG_NOTICE("Port %s oper state set from %s to %s", port.m_alias.c_str(), oper_status_strings.at(port.m_oper_status).c_str(), oper_status_strings.at(status).c_str()); - - this->updateDbPortOperStatus(port.m_port_id, status); - if (status == SAI_PORT_OPER_STATUS_UP || port.m_oper_status == SAI_PORT_OPER_STATUS_UP) + if (status != port.m_oper_status) { - this->setHostIntfsOperStatus(port.m_port_id, status == SAI_PORT_OPER_STATUS_UP); + this->updateDbPortOperStatus(port.m_port_id, status); + if (status == SAI_PORT_OPER_STATUS_UP || port.m_oper_status == SAI_PORT_OPER_STATUS_UP) + { + this->setHostIntfsOperStatus(port.m_port_id, status == SAI_PORT_OPER_STATUS_UP); + } } } @@ -2972,4 +2988,4 @@ void PortsOrch::refreshPortStatus() updatePortOperStatus(p, status); } } -} +} \ No newline at end of file