Skip to content

Commit 3fd812d

Browse files
jaganbal-aJaganathan Anbalagan
and
Jaganathan Anbalagan
authored
Orchagent changes for synchronizing npu/phy device Tx in the data path before enabling transceiver<CMIS compliant> Tx. (#2277)
* Signed-off-by: Jaganathan Anbalagan <[email protected]> orchagent changes for sonic-net/SONiC#916 * Signed-off-by: Jaganathan Anbalagan <[email protected]> Addressing PR comment * Signed-off-by: Jaganathan Anbalagan <[email protected]> Addressing PR comments-cosmetic * Signed-off-by: Jaganathan Anbalagan <[email protected]> fixed typo * Signed-off-by: Jaganathan Anbalagan <[email protected]> VS test code and addressing PR comment * Signed-off-by: Jaganathan Anbalagan <[email protected]> set host_tx_ready to false if gbsyncd SAI API fails. Co-authored-by: Jaganathan Anbalagan <[email protected]>
1 parent 47f6162 commit 3fd812d

File tree

3 files changed

+89
-6
lines changed

3 files changed

+89
-6
lines changed

orchagent/portsorch.cpp

+59-6
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,38 @@ void PortsOrch::getCpuPort(Port &port)
10321032
port = m_cpuPort;
10331033
}
10341034

1035+
/*
1036+
* Create host_tx_ready field in PORT_TABLE of STATE-DB
1037+
* and set the field to false by default for the
1038+
* front<Ethernet> port.
1039+
*/
1040+
void PortsOrch::initHostTxReadyState(Port &port)
1041+
{
1042+
SWSS_LOG_ENTER();
1043+
1044+
vector<FieldValueTuple> tuples;
1045+
bool exist = m_portStateTable.get(port.m_alias, tuples);
1046+
string hostTxReady;
1047+
1048+
if (exist)
1049+
{
1050+
for (auto i : tuples)
1051+
{
1052+
if (fvField(i) == "host_tx_ready")
1053+
{
1054+
hostTxReady = fvValue(i);
1055+
}
1056+
}
1057+
}
1058+
1059+
if (hostTxReady.empty())
1060+
{
1061+
m_portStateTable.hset(port.m_alias, "host_tx_ready", "false");
1062+
SWSS_LOG_INFO("initalize hostTxReady %s with status %s",
1063+
port.m_alias.c_str(), hostTxReady.c_str());
1064+
}
1065+
}
1066+
10351067
bool PortsOrch::setPortAdminStatus(Port &port, bool state)
10361068
{
10371069
SWSS_LOG_ENTER();
@@ -1040,22 +1072,40 @@ bool PortsOrch::setPortAdminStatus(Port &port, bool state)
10401072
attr.id = SAI_PORT_ATTR_ADMIN_STATE;
10411073
attr.value.booldata = state;
10421074

1075+
/* Update the host_tx_ready to false before setting admin_state, when admin state is false */
1076+
if (!state)
1077+
{
1078+
m_portStateTable.hset(port.m_alias, "host_tx_ready", "false");
1079+
SWSS_LOG_INFO("Set admin status DOWN host_tx_ready to false to port pid:%" PRIx64,
1080+
port.m_port_id);
1081+
}
1082+
10431083
sai_status_t status = sai_port_api->set_port_attribute(port.m_port_id, &attr);
10441084
if (status != SAI_STATUS_SUCCESS)
10451085
{
10461086
SWSS_LOG_ERROR("Failed to set admin status %s to port pid:%" PRIx64,
10471087
state ? "UP" : "DOWN", port.m_port_id);
1088+
m_portStateTable.hset(port.m_alias, "host_tx_ready", "false");
10481089
task_process_status handle_status = handleSaiSetStatus(SAI_API_PORT, status);
10491090
if (handle_status != task_success)
10501091
{
10511092
return parseHandleSaiStatusFailure(handle_status);
10521093
}
10531094
}
10541095

1055-
SWSS_LOG_INFO("Set admin status %s to port pid:%" PRIx64,
1056-
state ? "UP" : "DOWN", port.m_port_id);
1057-
1058-
setGearboxPortsAttr(port, SAI_PORT_ATTR_ADMIN_STATE, &state);
1096+
bool gbstatus = setGearboxPortsAttr(port, SAI_PORT_ATTR_ADMIN_STATE, &state);
1097+
if (gbstatus != true)
1098+
{
1099+
m_portStateTable.hset(port.m_alias, "host_tx_ready", "false");
1100+
}
1101+
1102+
/* Update the state table for host_tx_ready*/
1103+
if (state && (gbstatus == true) && (status == SAI_STATUS_SUCCESS) )
1104+
{
1105+
m_portStateTable.hset(port.m_alias, "host_tx_ready", "true");
1106+
SWSS_LOG_INFO("Set admin status UP host_tx_ready to true to port pid:%" PRIx64,
1107+
port.m_port_id);
1108+
}
10591109

10601110
return true;
10611111
}
@@ -1940,7 +1990,7 @@ void PortsOrch::initPortSupportedSpeeds(const std::string& alias, sai_object_id_
19401990
*/
19411991
bool PortsOrch::setGearboxPortsAttr(Port &port, sai_port_attr_t id, void *value)
19421992
{
1943-
bool status;
1993+
bool status = false;
19441994

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

@@ -3367,7 +3417,10 @@ void PortsOrch::doPortTask(Consumer &consumer)
33673417
}
33683418

33693419
}
3370-
3420+
3421+
/* create host_tx_ready field in state-db */
3422+
initHostTxReadyState(p);
3423+
33713424
/* Last step set port admin status */
33723425
if (!admin_status.empty() && (p.m_admin_state_up != (admin_status == "up")))
33733426
{

orchagent/portsorch.h

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class PortsOrch : public Orch, public Subject
9595
bool getPortByBridgePortId(sai_object_id_t bridge_port_id, Port &port);
9696
void setPort(string alias, Port port);
9797
void getCpuPort(Port &port);
98+
void initHostTxReadyState(Port &port);
9899
bool getInbandPort(Port &port);
99100
bool getVlanByVlanId(sai_vlan_id_t vlan_id, Port &vlan);
100101

tests/test_admin_status.py

+29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def setup_db(self, dvs):
99
self.pdb = swsscommon.DBConnector(0, dvs.redis_sock, 0)
1010
self.adb = swsscommon.DBConnector(1, dvs.redis_sock, 0)
1111
self.cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0)
12+
self.sdb = swsscommon.DBConnector(6, dvs.redis_sock, 0)
1213

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

56+
def check_host_tx_ready_status(self, dvs, port, admin_status):
57+
assert admin_status == "up" or admin_status == "down"
58+
ptbl = swsscommon.Table(self.sdb, "PORT_TABLE")
59+
(status, fvs) = ptbl.get(port)
60+
assert status == True
61+
assert "host_tx_ready" in [fv[0] for fv in fvs]
62+
for fv in fvs:
63+
if fv[0] == "host_tx_ready":
64+
assert fv[1] == "true" if admin_status == "up" else "false"
65+
5566
def test_PortChannelMemberAdminStatus(self, dvs, testlog):
5667
self.setup_db(dvs)
5768

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

93+
def test_PortHostTxReadiness(self, dvs, testlog):
94+
self.setup_db(dvs)
95+
96+
# configure admin status to interface
97+
self.set_admin_status("Ethernet0", "up")
98+
self.set_admin_status("Ethernet4", "down")
99+
self.set_admin_status("Ethernet8", "up")
100+
101+
# check ASIC port database
102+
self.check_admin_status(dvs, "Ethernet0", "up")
103+
self.check_admin_status(dvs, "Ethernet4", "down")
104+
self.check_admin_status(dvs, "Ethernet8", "up")
105+
106+
# check host readiness status in PORT TABLE of STATE-DB
107+
self.check_host_tx_ready_status(dvs, "Ethernet0", "up")
108+
self.check_host_tx_ready_status(dvs, "Ethernet4", "down")
109+
self.check_host_tx_ready_status(dvs, "Ethernet8", "up")
110+
82111

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

0 commit comments

Comments
 (0)