Skip to content

Commit ca72820

Browse files
authored
[FEC] Adding support of override based on attribute query of SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_OVERRIDE (sonic-net#2874)
1 parent aabe741 commit ca72820

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

orchagent/portsorch.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,18 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector<table_name_wi
512512
}
513513
}
514514

515+
sai_attr_capability_t attr_cap;
516+
if (sai_query_attribute_capability(gSwitchId, SAI_OBJECT_TYPE_PORT,
517+
SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_OVERRIDE,
518+
&attr_cap) != SAI_STATUS_SUCCESS)
519+
{
520+
SWSS_LOG_NOTICE("Unable to query autoneg fec mode override");
521+
}
522+
else if (attr_cap.set_implemented && attr_cap.create_implemented)
523+
{
524+
fec_override_sup = true;
525+
}
526+
515527
/* Get default 1Q bridge and default VLAN */
516528
sai_status_t status;
517529
sai_attribute_t attr;
@@ -1502,6 +1514,28 @@ bool PortsOrch::setPortTpid(Port &port, sai_uint16_t tpid)
15021514
return true;
15031515
}
15041516

1517+
bool PortsOrch::setPortFecOverride(sai_object_id_t port_obj, bool fec_override)
1518+
{
1519+
sai_attribute_t attr;
1520+
sai_status_t status;
1521+
1522+
attr.id = SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_OVERRIDE;
1523+
attr.value.booldata = fec_override;
1524+
1525+
status = sai_port_api->set_port_attribute(port_obj, &attr);
1526+
if (status != SAI_STATUS_SUCCESS)
1527+
{
1528+
SWSS_LOG_ERROR("Failed to set fec override %d to port pid:%" PRIx64, attr.value.booldata, port_obj);
1529+
task_process_status handle_status = handleSaiSetStatus(SAI_API_PORT, status);
1530+
if (handle_status != task_success)
1531+
{
1532+
return parseHandleSaiStatusFailure(handle_status);
1533+
}
1534+
}
1535+
SWSS_LOG_INFO("Set fec override %d to port pid:%" PRIx64, attr.value.booldata, port_obj);
1536+
return true;
1537+
}
1538+
15051539
bool PortsOrch::setPortFec(Port &port, sai_port_fec_mode_t fec_mode)
15061540
{
15071541
SWSS_LOG_ENTER();
@@ -1521,6 +1555,10 @@ bool PortsOrch::setPortFec(Port &port, sai_port_fec_mode_t fec_mode)
15211555
}
15221556
}
15231557

1558+
if (fec_override_sup && !setPortFecOverride(port.m_port_id, true))
1559+
{
1560+
return false;
1561+
}
15241562
setGearboxPortsAttr(port, SAI_PORT_ATTR_FEC_MODE, &fec_mode);
15251563

15261564
SWSS_LOG_NOTICE("Set port %s FEC mode %d", port.m_alias.c_str(), fec_mode);
@@ -2524,6 +2562,10 @@ bool PortsOrch::setGearboxPortAttr(const Port &port, dest_port_type_t port_type,
25242562
m_gearboxTable->hset(key, speed_attr, to_string(speed));
25252563
SWSS_LOG_NOTICE("BOX: Updated APPL_DB key:%s %s %d", key.c_str(), speed_attr.c_str(), speed);
25262564
}
2565+
else if (id == SAI_PORT_ATTR_FEC_MODE && fec_override_sup && !setPortFecOverride(dest_port_id, true))
2566+
{
2567+
return false;
2568+
}
25272569
}
25282570
else
25292571
{

orchagent/portsorch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ class PortsOrch : public Orch, public Subject
322322
map<string, uint32_t> m_bridge_port_ref_count;
323323

324324
NotificationConsumer* m_portStatusNotificationConsumer;
325+
bool fec_override_sup = false;
325326

326327
swss::SelectableTimer *m_port_state_poller = nullptr;
327328

@@ -379,6 +380,7 @@ class PortsOrch : public Orch, public Subject
379380
bool setPortPvid (Port &port, sai_uint32_t pvid);
380381
bool getPortPvid(Port &port, sai_uint32_t &pvid);
381382
bool setPortFec(Port &port, sai_port_fec_mode_t fec_mode);
383+
bool setPortFecOverride(sai_object_id_t port_obj, bool fec_override);
382384
bool setPortPfcAsym(Port &port, sai_port_priority_flow_control_mode_t pfc_asym);
383385
bool getDestPortId(sai_object_id_t src_port_id, dest_port_type_t port_type, sai_object_id_t &des_port_id);
384386

tests/test_port_fec_override.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import time
2+
import os
3+
import pytest
4+
5+
from swsscommon import swsscommon
6+
7+
DVS_ENV = ["HWSKU=Mellanox-SN2700"]
8+
9+
class TestPort(object):
10+
def test_PortFecOverride(self, dvs, testlog):
11+
db = swsscommon.DBConnector(0, dvs.redis_sock, 0)
12+
adb = dvs.get_asic_db()
13+
14+
ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE")
15+
16+
# set fec
17+
fvs = swsscommon.FieldValuePairs([("fec","rs")])
18+
ptbl.set("Ethernet4", fvs)
19+
20+
# validate if fec rs is pushed to asic db when set first time
21+
port_oid = adb.port_name_map["Ethernet4"]
22+
expected_fields = {"SAI_PORT_ATTR_FEC_MODE":"SAI_PORT_FEC_MODE_RS", "SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_OVERRIDE":"true"}
23+
adb.wait_for_field_match("ASIC_STATE:SAI_OBJECT_TYPE_PORT", port_oid, expected_fields)
24+
25+
26+
# Add Dummy always-pass test at end as workaroud
27+
# for issue when Flaky fail on final test it invokes module tear-down before retrying
28+
def test_nonflaky_dummy():
29+
pass
30+

0 commit comments

Comments
 (0)