Skip to content

Commit

Permalink
Orchagent changes for synchronizing npu/phy device Tx in the data pat…
Browse files Browse the repository at this point in the history
…h before enabling transceiver<CMIS compliant> Tx. (#2277)

* Signed-off-by: Jaganathan Anbalagan <jaganbal@cisco.com>

orchagent changes for sonic-net/SONiC#916

* Signed-off-by: Jaganathan Anbalagan <jaganbal@cisco.com>

Addressing PR comment

* Signed-off-by: Jaganathan Anbalagan <jaganbal@cisco.com>

Addressing PR comments-cosmetic

* Signed-off-by: Jaganathan Anbalagan <jaganbal@cisco.com>

fixed typo

* Signed-off-by: Jaganathan Anbalagan <jaganbal@cisco.com>

VS test code and addressing PR comment

* Signed-off-by: Jaganathan Anbalagan <jaganbal@cisco.com>

set host_tx_ready to false if gbsyncd SAI API fails.

Co-authored-by: Jaganathan Anbalagan <jaganbal@cisco.com>
  • Loading branch information
jaganbal-a and Jaganathan Anbalagan authored Jul 13, 2022
1 parent 47f6162 commit 3fd812d
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 6 deletions.
65 changes: 59 additions & 6 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,38 @@ void PortsOrch::getCpuPort(Port &port)
port = m_cpuPort;
}

/*
* Create host_tx_ready field in PORT_TABLE of STATE-DB
* and set the field to false by default for the
* front<Ethernet> port.
*/
void 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);
}
}
}

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());
}
}

bool PortsOrch::setPortAdminStatus(Port &port, bool state)
{
SWSS_LOG_ENTER();
Expand All @@ -1040,22 +1072,40 @@ 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 DOWN host_tx_ready to false to port pid:%" PRIx64,
port.m_port_id);
}

sai_status_t status = sai_port_api->set_port_attribute(port.m_port_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set admin status %s to port pid:%" PRIx64,
state ? "UP" : "DOWN", port.m_port_id);
m_portStateTable.hset(port.m_alias, "host_tx_ready", "false");
task_process_status handle_status = handleSaiSetStatus(SAI_API_PORT, status);
if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}

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)
{
m_portStateTable.hset(port.m_alias, "host_tx_ready", "false");
}

/* 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 UP host_tx_ready to true to port pid:%" PRIx64,
port.m_port_id);
}

return true;
}
Expand Down Expand Up @@ -1940,7 +1990,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 @@ -3367,7 +3417,10 @@ void PortsOrch::doPortTask(Consumer &consumer)
}

}


/* create host_tx_ready field in state-db */
initHostTxReadyState(p);

/* 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);
void initHostTxReadyState(Port &port);
bool getInbandPort(Port &port);
bool getVlanByVlanId(sai_vlan_id_t vlan_id, Port &vlan);

Expand Down
29 changes: 29 additions & 0 deletions tests/test_admin_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def setup_db(self, dvs):
self.pdb = swsscommon.DBConnector(0, dvs.redis_sock, 0)
self.adb = swsscommon.DBConnector(1, dvs.redis_sock, 0)
self.cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0)
self.sdb = swsscommon.DBConnector(6, dvs.redis_sock, 0)

def set_admin_status(self, port, admin_status):
assert admin_status == "up" or admin_status == "down"
Expand Down Expand Up @@ -52,6 +53,16 @@ def check_admin_status(self, dvs, port, admin_status):
if fv[0] == "SAI_PORT_ATTR_ADMIN_STATE":
assert fv[1] == "true" if admin_status == "up" else "false"

def check_host_tx_ready_status(self, dvs, port, admin_status):
assert admin_status == "up" or admin_status == "down"
ptbl = swsscommon.Table(self.sdb, "PORT_TABLE")
(status, fvs) = ptbl.get(port)
assert status == True
assert "host_tx_ready" in [fv[0] for fv in fvs]
for fv in fvs:
if fv[0] == "host_tx_ready":
assert fv[1] == "true" if admin_status == "up" else "false"

def test_PortChannelMemberAdminStatus(self, dvs, testlog):
self.setup_db(dvs)

Expand Down Expand Up @@ -79,6 +90,24 @@ def test_PortChannelMemberAdminStatus(self, dvs, testlog):
# remove port channel
self.remove_port_channel(dvs, "PortChannel6")

def test_PortHostTxReadiness(self, dvs, testlog):
self.setup_db(dvs)

# configure admin status to interface
self.set_admin_status("Ethernet0", "up")
self.set_admin_status("Ethernet4", "down")
self.set_admin_status("Ethernet8", "up")

# check ASIC port database
self.check_admin_status(dvs, "Ethernet0", "up")
self.check_admin_status(dvs, "Ethernet4", "down")
self.check_admin_status(dvs, "Ethernet8", "up")

# check host readiness status in PORT TABLE of STATE-DB
self.check_host_tx_ready_status(dvs, "Ethernet0", "up")
self.check_host_tx_ready_status(dvs, "Ethernet4", "down")
self.check_host_tx_ready_status(dvs, "Ethernet8", "up")


# Add Dummy always-pass test at end as workaroud
# for issue when Flaky fail on final test it invokes module tear-down before retrying
Expand Down

0 comments on commit 3fd812d

Please sign in to comment.