-
Notifications
You must be signed in to change notification settings - Fork 520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for configuring loopback mode (PHY and MAC) #3095
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,14 @@ static const std::unordered_map<std::string, sai_port_path_tracing_timestamp_typ | |
{ PORT_PT_TIMESTAMP_TEMPLATE_4, SAI_PORT_PATH_TRACING_TIMESTAMP_TYPE_20_27 } | ||
}; | ||
|
||
static const std::unordered_map<std::string, sai_port_loopback_mode_t> portLoopbackModeMap = { | ||
{"none", SAI_PORT_LOOPBACK_MODE_NONE}, | ||
{"phy_local", SAI_PORT_LOOPBACK_MODE_PHY}, | ||
{"mac_local", SAI_PORT_LOOPBACK_MODE_MAC}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @royyi8 how is it different from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
https://github.com/opencomputeproject/SAI/blob/master/inc/saiport.h#L114 |
||
{"phy_remote", SAI_PORT_LOOPBACK_MODE_PHY_REMOTE}, | ||
{"mac_remote", SAI_PORT_LOOPBACK_MODE_MAC_REMOTE}, | ||
}; | ||
|
||
static const std::unordered_map<std::string, sai_redis_link_event_damping_algorithm_t> g_linkEventDampingAlgorithmMap = | ||
{ | ||
{ "disabled", SAI_REDIS_LINK_EVENT_DAMPING_ALGORITHM_DISABLED }, | ||
|
@@ -253,6 +261,11 @@ std::string PortHelper::getPtTimestampTemplateStr(const PortConfig &port) const | |
return this->getFieldValueStr(port, PORT_PT_TIMESTAMP_TEMPLATE); | ||
} | ||
|
||
std::string PortHelper::getLoopbackModeStr(const PortConfig &port) const | ||
{ | ||
return this->getFieldValueStr(port, PORT_LOOPBACK_MODE); | ||
} | ||
|
||
std::string PortHelper::getDampingAlgorithm(const PortConfig &port) const | ||
{ | ||
return this->getFieldValueStr(port, PORT_DAMPING_ALGO); | ||
|
@@ -919,6 +932,29 @@ bool PortHelper::parsePortPtTimestampTemplate(PortConfig &port, const std::strin | |
return true; | ||
} | ||
|
||
bool PortHelper::parsePortLoopbackMode(PortConfig &port, const std::string &field, const std::string &value) const | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
if (value.empty()) | ||
{ | ||
SWSS_LOG_ERROR("Failed to parse field(%s): empty value is prohibited", field.c_str()); | ||
return false; | ||
} | ||
|
||
const auto &cit = portLoopbackModeMap.find(value); | ||
if (cit == portLoopbackModeMap.cend()) | ||
{ | ||
SWSS_LOG_ERROR("Failed to parse field(%s): invalid value(%s)", field.c_str(), value.c_str()); | ||
return false; | ||
} | ||
|
||
port.loopback_mode.value = cit->second; | ||
port.loopback_mode.is_set = true; | ||
|
||
return true; | ||
} | ||
|
||
bool PortHelper::parsePortConfig(PortConfig &port) const | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
@@ -1187,6 +1223,13 @@ bool PortHelper::parsePortConfig(PortConfig &port) const | |
return false; | ||
} | ||
} | ||
else if (field == PORT_LOOPBACK_MODE) | ||
{ | ||
if (!this->parsePortLoopbackMode(port, field, value)) | ||
{ | ||
return false; | ||
} | ||
} | ||
else if (field == PORT_DAMPING_ALGO) | ||
{ | ||
if (!this->parsePortLinkEventDampingAlgorithm(port, field, value)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4595,6 +4595,30 @@ void PortsOrch::doPortTask(Consumer &consumer) | |
} | ||
} | ||
|
||
if (pCfg.loopback_mode.is_set) | ||
{ | ||
if (p.m_loopback_mode != pCfg.loopback_mode.value) | ||
{ | ||
auto status = setPortLoopbackMode(p.m_port_id, pCfg.loopback_mode.value); | ||
if (status.ok()) | ||
{ | ||
SWSS_LOG_NOTICE("Set port %s loopback mode to %s", | ||
p.m_alias.c_str(), | ||
m_portHlpr.getLoopbackModeStr(pCfg).c_str()); | ||
p.m_loopback_mode = pCfg.loopback_mode.value; | ||
m_portList[p.m_alias] = p; | ||
} | ||
else | ||
{ | ||
SWSS_LOG_ERROR( | ||
"Failed to set port %s loopback mode to %s", | ||
p.m_alias.c_str(), m_portHlpr.getLoopbackModeStr(pCfg).c_str()); | ||
it = taskMap.erase(it); | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
/* create host_tx_ready field in state-db */ | ||
initHostTxReadyState(p); | ||
|
||
|
@@ -8528,6 +8552,27 @@ void PortsOrch::getPortSerdesVal(const std::string& val_str, | |
} | ||
} | ||
|
||
ReturnCode PortsOrch::setPortLoopbackMode(sai_object_id_t id, sai_port_loopback_mode_t loopback_mode) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
sai_attribute_t attr; | ||
attr.id = SAI_PORT_ATTR_LOOPBACK_MODE; | ||
attr.value.u32 = loopback_mode; | ||
|
||
sai_status_t status = sai_port_api->set_port_attribute(id, &attr); | ||
if (status != SAI_STATUS_SUCCESS) | ||
{ | ||
LOG_ERROR_AND_RETURN(ReturnCode(status) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @royyi8 this won't crash OA right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that is correct. It logs the error and returns from the current function. https://github.com/sonic-net/sonic-swss/blob/master/orchagent/return_code.h#L50 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @royyi8 can we avoid crash. Why crash OA if one port fails? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @prgeor To clarify, the code will not crash OA. It will simply log an error and return status failed in the |
||
<< "Failed to set loopback mode " << attr.value.u32 | ||
<< " to port pid 0x" << std::hex << id | ||
<< ", rv: " << sai_serialize_status(status)); | ||
} | ||
|
||
SWSS_LOG_INFO("Set loopback mode %u on port pid: %" PRIx64, attr.value.u32, id); | ||
return ReturnCode(); | ||
} | ||
|
||
/* Bring up/down Vlan interface associated with L3 VNI*/ | ||
bool PortsOrch::updateL3VniStatus(uint16_t vlan_id, bool isUp) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@royyi8 How is it different from
SAI_PORT_INTERNAL_LOOPBACK_MODE_PHY
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same reason as above.
SAI_PORT_LOOPBACK_MODE_PHY
is the corresponding attribute forSAI_PORT_INTERNAL_LOOPBACK_MODE_PHY
in thesai_port_loopback_mode_t
enum.