-
Notifications
You must be signed in to change notification settings - Fork 547
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
ghost
wants to merge
4
commits into
sonic-net:master
Choose a base branch
from
unknown repository
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8f6c2f2
[orchagent] Init field of supported speeds while port initialization
ad7de0a
[orchagent/portsorch] Refactoring, remove duplicate code
addfe2c
[orchagent/portsorch] Fixed transfer by reference
144b6c1
[orchagent/portsorch] Return of a call to the initPortSupportedSpeeds…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 | ||
|
@@ -1873,6 +1874,22 @@ 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) | ||
|
||
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. Since we removed |
||
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. | ||
*/ | ||
|
@@ -4167,6 +4184,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; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should be
getPortSupportedSpeeds(alias, port_id, supported_speeds);
?