-
Notifications
You must be signed in to change notification settings - Fork 549
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 SWSS support for link event damping feature #2933
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 |
---|---|---|
|
@@ -21,6 +21,7 @@ using namespace swss; | |
// types -------------------------------------------------------------------------------------------------------------- | ||
|
||
typedef decltype(PortConfig::serdes) PortSerdes_t; | ||
typedef decltype(PortConfig::link_event_damping_config) PortDampingConfig_t; | ||
|
||
// constants ---------------------------------------------------------------------------------------------------------- | ||
|
||
|
@@ -126,6 +127,12 @@ 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_redis_link_event_damping_algorithm_t> g_linkEventDampingAlgorithmMap = | ||
{ | ||
{ "disabled", SAI_REDIS_LINK_EVENT_DAMPING_ALGORITHM_DISABLED }, | ||
{ "aied", SAI_REDIS_LINK_EVENT_DAMPING_ALGORITHM_AIED } | ||
}; | ||
|
||
// functions ---------------------------------------------------------------------------------------------------------- | ||
|
||
template<typename T> | ||
|
@@ -246,6 +253,11 @@ std::string PortHelper::getPtTimestampTemplateStr(const PortConfig &port) const | |
return this->getFieldValueStr(port, PORT_PT_TIMESTAMP_TEMPLATE); | ||
} | ||
|
||
std::string PortHelper::getDampingAlgorithm(const PortConfig &port) const | ||
{ | ||
return this->getFieldValueStr(port, PORT_DAMPING_ALGO); | ||
} | ||
|
||
bool PortHelper::parsePortAlias(PortConfig &port, const std::string &field, const std::string &value) const | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
@@ -786,6 +798,60 @@ bool PortHelper::parsePortSubport(PortConfig &port, const std::string &field, co | |
return true; | ||
} | ||
|
||
bool PortHelper::parsePortLinkEventDampingAlgorithm(PortConfig &port, const std::string &field, const std::string &value) const | ||
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. Can you please confirm that this is applied when user dynamically changes the link damping configs and not just during initialization? 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. Link event damping algorithm and config can be applied at runtime by changing the entries in CONFIG DB. |
||
{ | ||
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 = g_linkEventDampingAlgorithmMap.find(value); | ||
if (cit == g_linkEventDampingAlgorithmMap.cend()) | ||
{ | ||
SWSS_LOG_ERROR("Failed to parse field(%s): invalid value(%s)", field.c_str(), value.c_str()); | ||
return false; | ||
} | ||
|
||
port.link_event_damping_algorithm.value = cit->second; | ||
port.link_event_damping_algorithm.is_set = true; | ||
|
||
return true; | ||
} | ||
|
||
template<typename T> | ||
bool PortHelper::parsePortLinkEventDampingConfig(T &damping_config_attr, const std::string &field, const std::string &value) const | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
if (value.empty()) | ||
{ | ||
SWSS_LOG_ERROR("Failed to parse field(%s): empty string is prohibited", field.c_str()); | ||
return false; | ||
} | ||
|
||
try | ||
{ | ||
damping_config_attr.value = to_uint<std::uint32_t>(value); | ||
damping_config_attr.is_set = true; | ||
} | ||
catch (const std::exception &e) | ||
{ | ||
SWSS_LOG_ERROR("Failed to parse field(%s): %s", field.c_str(), e.what()); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
template bool PortHelper::parsePortLinkEventDampingConfig(decltype(PortDampingConfig_t::max_suppress_time) &damping_config_attr, const std::string &field, const std::string &value) const; | ||
template bool PortHelper::parsePortLinkEventDampingConfig(decltype(PortDampingConfig_t::decay_half_life) &damping_config_attr, const std::string &field, const std::string &value) const; | ||
template bool PortHelper::parsePortLinkEventDampingConfig(decltype(PortDampingConfig_t::suppress_threshold) &damping_config_attr, const std::string &field, const std::string &value) const; | ||
template bool PortHelper::parsePortLinkEventDampingConfig(decltype(PortDampingConfig_t::reuse_threshold) &damping_config_attr, const std::string &field, const std::string &value) const; | ||
template bool PortHelper::parsePortLinkEventDampingConfig(decltype(PortDampingConfig_t::flap_penalty) &damping_config_attr, const std::string &field, const std::string &value) const; | ||
|
||
bool PortHelper::parsePortPtIntfId(PortConfig &port, const std::string &field, const std::string &value) const | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
@@ -1121,6 +1187,48 @@ bool PortHelper::parsePortConfig(PortConfig &port) const | |
return false; | ||
} | ||
} | ||
else if (field == PORT_DAMPING_ALGO) | ||
{ | ||
if (!this->parsePortLinkEventDampingAlgorithm(port, field, value)) | ||
{ | ||
return false; | ||
} | ||
} | ||
else if (field == PORT_MAX_SUPPRESS_TIME) | ||
{ | ||
if (!this->parsePortLinkEventDampingConfig(port.link_event_damping_config.max_suppress_time, field, value)) | ||
{ | ||
return false; | ||
} | ||
} | ||
else if (field == PORT_DECAY_HALF_LIFE) | ||
{ | ||
if (!this->parsePortLinkEventDampingConfig(port.link_event_damping_config.decay_half_life, field, value)) | ||
{ | ||
return false; | ||
} | ||
} | ||
else if (field == PORT_SUPPRESS_THRESHOLD) | ||
{ | ||
if (!this->parsePortLinkEventDampingConfig(port.link_event_damping_config.suppress_threshold, field, value)) | ||
{ | ||
return false; | ||
} | ||
} | ||
else if (field == PORT_REUSE_THRESHOLD) | ||
{ | ||
if (!this->parsePortLinkEventDampingConfig(port.link_event_damping_config.reuse_threshold, field, value)) | ||
{ | ||
return false; | ||
} | ||
} | ||
else if (field == PORT_FLAP_PENALTY) | ||
{ | ||
if (!this->parsePortLinkEventDampingConfig(port.link_event_damping_config.flap_penalty, field, value)) | ||
{ | ||
return false; | ||
Comment on lines
+1190
to
+1229
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. all this and entire function could be refactored to have a stdL::map<string,function> to execute if string is compared and seems all the functions take teh same 3 parameters 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. Hi @kcudnik, thanks for reviewing the PR. I prefer to hold off refactoring the parsePortConfig function for now, since the first parameter is different between some of the functions. If you have more suggestions, please feel free to let me know. 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. you have opportunity right now to do refactoring, because you understand surrounding code that you are adding, and leaving this now as is, will result to add more and more code like you are adding that instead of refactoring, take this from my experience. |
||
} | ||
} | ||
else | ||
{ | ||
SWSS_LOG_WARN("Unknown field(%s): skipping ...", field.c_str()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3171,6 +3171,49 @@ task_process_status PortsOrch::setPortLinkTraining(const Port &port, bool state) | |
return task_success; | ||
} | ||
|
||
ReturnCode PortsOrch::setPortLinkEventDampingAlgorithm(Port &port, | ||
sai_redis_link_event_damping_algorithm_t &link_event_damping_algorithm) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
sai_attribute_t attr; | ||
attr.id = SAI_REDIS_PORT_ATTR_LINK_EVENT_DAMPING_ALGORITHM; | ||
attr.value.s32 = link_event_damping_algorithm; | ||
|
||
CHECK_ERROR_AND_LOG_AND_RETURN( | ||
sai_port_api->set_port_attribute(port.m_port_id, &attr), | ||
"Failed to set link event damping algorithm (" << link_event_damping_algorithm << ") for port " | ||
<< port.m_alias); | ||
|
||
SWSS_LOG_INFO("Set link event damping algorithm %u for port %s", link_event_damping_algorithm, port.m_alias.c_str()); | ||
return ReturnCode(); | ||
} | ||
|
||
ReturnCode PortsOrch::setPortLinkEventDampingAiedConfig(Port &port, | ||
sai_redis_link_event_damping_algo_aied_config_t &config) { | ||
|
||
SWSS_LOG_ENTER(); | ||
sai_attribute_t attr; | ||
attr.id = SAI_REDIS_PORT_ATTR_LINK_EVENT_DAMPING_ALGO_AIED_CONFIG; | ||
attr.value.ptr = (void *) &config; | ||
|
||
std::stringstream msg; | ||
msg << "link event damping algorithm aied config for port " << port.m_alias << " - "; | ||
msg << "max_suppress_time: " << config.max_suppress_time << ", "; | ||
msg << "decay_half_life: " << config.decay_half_life << ", "; | ||
msg << "suppress_threshold: " << config.suppress_threshold << ", "; | ||
msg << "reuse_threshold: " << config.reuse_threshold << ", "; | ||
msg << "flap_penalty: " << config.flap_penalty; | ||
|
||
std::string msg_str = msg.str(); | ||
|
||
CHECK_ERROR_AND_LOG_AND_RETURN( | ||
sai_port_api->set_port_attribute(port.m_port_id, &attr), "Failed to set " + msg_str); | ||
|
||
SWSS_LOG_INFO("Set %s", msg_str.c_str()); | ||
|
||
return ReturnCode(); | ||
} | ||
|
||
bool PortsOrch::setHostIntfsOperStatus(const Port& port, bool isUp) const | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
@@ -4033,6 +4076,86 @@ void PortsOrch::doPortTask(Consumer &consumer) | |
} | ||
} | ||
|
||
if (pCfg.link_event_damping_algorithm.is_set) | ||
{ | ||
if (p.m_link_event_damping_algorithm != pCfg.link_event_damping_algorithm.value) | ||
{ | ||
auto status = setPortLinkEventDampingAlgorithm(p, pCfg.link_event_damping_algorithm.value); | ||
if (!status.ok()) | ||
{ | ||
SWSS_LOG_ERROR( | ||
"Failed to set port %s link event damping algorithm to %s", | ||
p.m_alias.c_str(), m_portHlpr.getDampingAlgorithm(pCfg).c_str() | ||
); | ||
it = taskMap.erase(it); | ||
continue; | ||
} | ||
|
||
p.m_link_event_damping_algorithm = pCfg.link_event_damping_algorithm.value; | ||
m_portList[p.m_alias] = p; | ||
|
||
SWSS_LOG_NOTICE( | ||
"Set port %s link event damping algorithm to %s", | ||
p.m_alias.c_str(), m_portHlpr.getDampingAlgorithm(pCfg).c_str() | ||
); | ||
} | ||
} | ||
|
||
sai_redis_link_event_damping_algo_aied_config_t aied_config = { | ||
p.m_max_suppress_time, | ||
p.m_suppress_threshold, | ||
p.m_reuse_threshold, | ||
p.m_decay_half_life, | ||
p.m_flap_penalty, | ||
}; | ||
|
||
if (pCfg.link_event_damping_config.max_suppress_time.is_set) | ||
{ | ||
aied_config.max_suppress_time = pCfg.link_event_damping_config.max_suppress_time.value; | ||
} | ||
if (pCfg.link_event_damping_config.decay_half_life.is_set) | ||
{ | ||
aied_config.decay_half_life = pCfg.link_event_damping_config.decay_half_life.value; | ||
} | ||
if (pCfg.link_event_damping_config.suppress_threshold.is_set) | ||
{ | ||
aied_config.suppress_threshold = pCfg.link_event_damping_config.suppress_threshold.value; | ||
} | ||
if (pCfg.link_event_damping_config.reuse_threshold.is_set) | ||
{ | ||
aied_config.reuse_threshold = pCfg.link_event_damping_config.reuse_threshold.value; | ||
} | ||
if (pCfg.link_event_damping_config.flap_penalty.is_set) | ||
{ | ||
aied_config.flap_penalty = pCfg.link_event_damping_config.flap_penalty.value; | ||
} | ||
|
||
bool config_changed = !(aied_config.max_suppress_time == p.m_max_suppress_time && | ||
aied_config.decay_half_life == p.m_decay_half_life && | ||
aied_config.suppress_threshold == p.m_suppress_threshold && | ||
aied_config.reuse_threshold == p.m_reuse_threshold && | ||
aied_config.flap_penalty == p.m_flap_penalty); | ||
|
||
if (config_changed) | ||
{ | ||
auto status = setPortLinkEventDampingAiedConfig(p, aied_config); | ||
if (!status.ok()) | ||
{ | ||
SWSS_LOG_ERROR("Failed to set port %s link event damping config", p.m_alias.c_str()); | ||
it = taskMap.erase(it); | ||
continue; | ||
} | ||
|
||
p.m_max_suppress_time = aied_config.max_suppress_time; | ||
p.m_decay_half_life = aied_config.decay_half_life; | ||
p.m_suppress_threshold = aied_config.suppress_threshold; | ||
p.m_reuse_threshold = aied_config.reuse_threshold; | ||
p.m_flap_penalty = aied_config.flap_penalty; | ||
m_portList[p.m_alias] = p; | ||
|
||
SWSS_LOG_NOTICE("Set port %s link event damping config successfully", p.m_alias.c_str()); | ||
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. there is already a log in setPortLinkEventDampingAiedConfig, how about changing that to NOTICE and remove all logs here? 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. I removed some log messages that were also in setPortLinkEventDampingAiedConfig. |
||
} | ||
|
||
if (pCfg.speed.is_set) | ||
{ | ||
if (p.m_speed != pCfg.speed.value) | ||
|
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.
is it possible to use std::optional or boost::optional here?
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.
Hi @Junchao-Mellanox, thanks for your review. There was a refactor change in portsorch.cpp, and my change follows the existing port config. Maybe there can be a cleanup task in the future to update the port config to use std::optional.