Skip to content
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

[orchagent] Init field of supported speeds while port initialization #1622

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 57 additions & 17 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1783,23 +1783,6 @@ bool PortsOrch::setHostIntfsStripTag(Port &port, sai_hostif_vlan_tag_t strip)
return true;
}

bool PortsOrch::isSpeedSupported(const std::string& alias, sai_object_id_t port_id, sai_uint32_t speed)
{
// This method will return false iff we get a list of supported speeds and the requested speed
// is not supported
// Otherwise the method will return true (even if we received errors)
initPortSupportedSpeeds(alias, port_id);

const auto &supp_speeds = m_portSupportedSpeeds[port_id];
if (supp_speeds.empty())
{
// we don't have the list for this port, so return true to change speed anyway
return true;
}

return std::find(supp_speeds.begin(), supp_speeds.end(), speed) != supp_speeds.end();
}

void PortsOrch::getPortSupportedSpeeds(const std::string& alias, sai_object_id_t port_id, PortSupportedSpeeds &supported_speeds)
{
sai_attribute_t attr;
Expand Down Expand Up @@ -1857,6 +1840,24 @@ void PortsOrch::getPortSupportedSpeeds(const std::string& alias, sai_object_id_t
}
}

const PortSupportedSpeeds& PortsOrch::getSupportedSpeed(const std::string& alias, sai_object_id_t port_id)
{
// This method will return vector of supported speeds for the port
// The method will return empty vector if there was something wrong during method execution.

// "Lazy" query of supported speeds for given port
// Once received the list will be stored in m_portSupportedSpeeds

if (!m_portSupportedSpeeds.count(port_id))
{
PortSupportedSpeeds supported_speeds;
getPortSupportedSpeeds(alias, port_id, supported_speeds);
m_portSupportedSpeeds[port_id] = supported_speeds;
}

return m_portSupportedSpeeds[port_id];
}

void PortsOrch::initPortSupportedSpeeds(const std::string& alias, sai_object_id_t port_id)
{
// If port supported speeds map already contains the information, save the SAI call
Expand All @@ -1873,6 +1874,23 @@ void PortsOrch::initPortSupportedSpeeds(const std::string& alias, sai_object_id_
m_portStateTable.set(alias, v);
}

bool PortsOrch::isSpeedSupported(const std::string& alias, sai_object_id_t port_id, sai_uint32_t speed)
{
// This method will return false if we get a list of supported speeds and the requested speed
// is not supported
// Otherwise the method will return true (even if did not receive list of supported speed)
initPortSupportedSpeeds(alias, port_id);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we removed initPortSupportedSpeeds in this function, just want to make sure initPortSupportedSpeeds was called always before calling this function.

const PortSupportedSpeeds &supp_speeds = getSupportedSpeed(alias, port_id);
if (supp_speeds.size() == 0)
{
// we don't have the list for this port, so return true to change speed anyway
return true;
}

return std::find(supp_speeds.begin(), supp_speeds.end(), speed) != supp_speeds.end();
}

/*
* If Gearbox is enabled and this is a Gearbox port then set the attributes accordingly.
*/
Expand Down Expand Up @@ -4167,6 +4185,28 @@ bool PortsOrch::initializePort(Port &port)
return false;
}

/*
* initialize field with supported speeds of the port.
*/
auto supp_speed_temp = getSupportedSpeed(port.m_alias, port.m_port_id);
/* Copy the vector to be able to modify it */
auto supp_speed(supp_speed_temp);
if (supp_speed.size() > 0)
{
sort(supp_speed.begin(), supp_speed.end());

string tmp_supp_speed_str = "";
/* Add (count - 1) elements to the string with separator*/
for (auto iter = supp_speed.begin(); iter < prev(supp_speed.end()); iter++)
{
tmp_supp_speed_str += to_string(*iter) + ",";
}
/* Add the last element w/o separator*/
tmp_supp_speed_str += to_string(supp_speed.back());

m_portTable->hset(port.m_alias, "supp_speed", tmp_supp_speed_str);
}

return true;
}

Expand Down
3 changes: 2 additions & 1 deletion orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,10 @@ class PortsOrch : public Orch, public Subject

bool setBridgePortAdminStatus(sai_object_id_t id, bool up);

bool isSpeedSupported(const std::string& alias, sai_object_id_t port_id, sai_uint32_t speed);
void getPortSupportedSpeeds(const std::string& alias, sai_object_id_t port_id, PortSupportedSpeeds &supported_speeds);
const PortSupportedSpeeds& getSupportedSpeed(const std::string& alias, sai_object_id_t port_id);
void initPortSupportedSpeeds(const std::string& alias, sai_object_id_t port_id);
bool isSpeedSupported(const std::string& alias, sai_object_id_t port_id, sai_uint32_t speed);
task_process_status setPortSpeed(Port &port, sai_uint32_t speed);
bool getPortSpeed(sai_object_id_t id, sai_uint32_t &speed);
bool setGearboxPortsAttr(Port &port, sai_port_attr_t id, void *value);
Expand Down