-
Notifications
You must be signed in to change notification settings - Fork 539
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
[sonic-swss:TPID CONFIG]Added Orchagent TPID config support for Port/LAG #1747
Changes from 1 commit
7c2768c
3522e81
37285d1
9bc5391
88619b0
a4855a7
88eea45
ef088bc
090a2b7
67b0f87
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 |
---|---|---|
|
@@ -10,6 +10,11 @@ | |
#include "sairedis.h" | ||
#include "chassisorch.h" | ||
|
||
extern "C" { | ||
#include "sai.h" | ||
} | ||
#include "sai_serialize.h" | ||
|
||
using namespace std; | ||
using namespace swss; | ||
|
||
|
@@ -275,6 +280,56 @@ bool OrchDaemon::init() | |
|
||
gMacsecOrch = new MACsecOrch(m_applDb, m_stateDb, macsec_app_tables, gPortsOrch); | ||
|
||
Table m_switchTable(stateDbSwitchTable.first, stateDbSwitchTable.second); | ||
// Check if SAI is capable of handling TPID config and store result in StateDB switch capability table | ||
{ | ||
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. Please move this section to switch init and make this part of switchorch class. 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. Changed per suggestion in my new commit. |
||
vector<FieldValueTuple> fvVector; | ||
sai_status_t status = SAI_STATUS_SUCCESS; | ||
sai_attr_capability_t capability; | ||
|
||
// Check if SAI is capable of handling TPID for Port | ||
status = sai_query_attribute_capability(gSwitchId, SAI_OBJECT_TYPE_PORT, SAI_PORT_ATTR_TPID, &capability); | ||
if (status != SAI_STATUS_SUCCESS) | ||
{ | ||
SWSS_LOG_WARN("Could not query port TPID capability %d", status); | ||
// Since pre-req of TPID support requires querry capability failed, it means TPID not supported | ||
fvVector.emplace_back(SWITCH_CAPABILITY_TABLE_PORT_TPID_CAPABLE, "false"); | ||
} | ||
else | ||
{ | ||
if (capability.set_implemented) | ||
{ | ||
fvVector.emplace_back(SWITCH_CAPABILITY_TABLE_PORT_TPID_CAPABLE, "true"); | ||
} | ||
else | ||
{ | ||
fvVector.emplace_back(SWITCH_CAPABILITY_TABLE_PORT_TPID_CAPABLE, "false"); | ||
} | ||
SWSS_LOG_NOTICE("port TPID capability %d", capability.set_implemented); | ||
} | ||
// Check if SAI is capable of handling TPID for LAG | ||
status = sai_query_attribute_capability(gSwitchId, SAI_OBJECT_TYPE_LAG, SAI_LAG_ATTR_TPID, &capability); | ||
if (status != SAI_STATUS_SUCCESS) | ||
{ | ||
SWSS_LOG_WARN("Could not query LAG TPID capability %d", status); | ||
// Since pre-req of TPID support requires querry capability failed, it means TPID not supported | ||
fvVector.emplace_back(SWITCH_CAPABILITY_TABLE_LAG_TPID_CAPABLE, "false"); | ||
} | ||
else | ||
{ | ||
if (capability.set_implemented) | ||
{ | ||
fvVector.emplace_back(SWITCH_CAPABILITY_TABLE_LAG_TPID_CAPABLE, "true"); | ||
} | ||
else | ||
{ | ||
fvVector.emplace_back(SWITCH_CAPABILITY_TABLE_LAG_TPID_CAPABLE, "false"); | ||
} | ||
SWSS_LOG_NOTICE("LAG TPID capability %d", capability.set_implemented); | ||
} | ||
m_switchTable.set("switch", fvVector); | ||
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 can use the API 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. Got it. Will change this per your suggestion. 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. Changed per suggestion in my new commit. |
||
} | ||
|
||
/* | ||
* The order of the orch list is important for state restore of warm start and | ||
* the queued processing in m_toSync map after gPortsOrch->allPortsReady() is set. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -917,6 +917,36 @@ bool PortsOrch::setPortMtu(sai_object_id_t id, sai_uint32_t mtu) | |
return true; | ||
} | ||
|
||
|
||
bool PortsOrch::setPortTpid(sai_object_id_t id, sai_uint16_t tpid) | ||
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 we combine this with Lag to have single function and pass 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 a chance that we may end up having to implement the LAG handling by having Orchagent apply the LAG TPID config to all its LAG members. This is because currently only one SAI vendor supports TPID setting on Port only and not yet for LAG. For our fanout switch usage, this is already good enough. But if we ever want to apply it to LAG while SAI vendor not supporting it, it will be much easier to have the port/LAG handling having its own function to do the handling. So for now, let's keep the way it is just in case the enhancement is needed in the future. 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. ok |
||
{ | ||
SWSS_LOG_ENTER(); | ||
sai_status_t status = SAI_STATUS_SUCCESS; | ||
sai_attribute_t attr; | ||
|
||
attr.id = SAI_PORT_ATTR_TPID; | ||
|
||
attr.value.u16 = (uint16_t)tpid; | ||
|
||
status = sai_port_api->set_port_attribute(id, &attr); | ||
if (status != SAI_STATUS_SUCCESS) | ||
{ | ||
SWSS_LOG_ERROR("Failed to set TPID 0x%x to port pid:%" PRIx64 ", rv:%d", | ||
attr.value.u16, id, status); | ||
task_process_status handle_status = handleSaiSetStatus(SAI_API_PORT, status); | ||
if (handle_status != task_success) | ||
{ | ||
return parseHandleSaiStatusFailure(handle_status); | ||
} | ||
} | ||
else | ||
{ | ||
SWSS_LOG_NOTICE("Set TPID 0x%x to port pid:%" PRIx64, attr.value.u16, id); | ||
} | ||
return true; | ||
} | ||
|
||
|
||
bool PortsOrch::setPortFec(Port &port, sai_port_fec_mode_t mode) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
@@ -2353,6 +2383,8 @@ void PortsOrch::doPortTask(Consumer &consumer) | |
string learn_mode; | ||
int an = -1; | ||
int index = -1; | ||
string tpid_string; | ||
uint16_t tpid = 0; | ||
|
||
for (auto i : kfvFieldsValues(t)) | ||
{ | ||
|
@@ -2384,6 +2416,15 @@ void PortsOrch::doPortTask(Consumer &consumer) | |
{ | ||
mtu = (uint32_t)stoul(fvValue(i)); | ||
} | ||
/* Set port TPID */ | ||
if (fvField(i) == "tpid") | ||
{ | ||
tpid_string = fvValue(i); | ||
// Need to get rid of the leading 0x | ||
tpid_string.erase(0,2); | ||
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. Is it better to use str.find and then str.erase(0, pos)? Do we always expect a 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. The CLI enforces that the TPID values must be one of the following: "0x8100", "0x9100", "0x9200", or "0x88A8". |
||
tpid = (uint16_t)stoi(tpid_string, 0, 16); | ||
SWSS_LOG_DEBUG("Handling TPID to 0x%x, string value:%s", tpid, tpid_string.c_str()); | ||
} | ||
/* Set port speed */ | ||
else if (fvField(i) == "speed") | ||
{ | ||
|
@@ -2699,6 +2740,22 @@ void PortsOrch::doPortTask(Consumer &consumer) | |
} | ||
} | ||
|
||
if (tpid != 0 && tpid != p.m_tpid) | ||
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. How do we reset? I think the check should be just 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. In this case "tpid !=0" check serves the purpose of identifying whether it is handling non-TPID operations in which case variable tpid is initialized to "0" and there is no need to perform TPID operation. This is inline with how MTU and speed setting is being handled. Hope this explains why this check is required. |
||
{ | ||
SWSS_LOG_DEBUG("Set port %s TPID to 0x%x", alias.c_str(), tpid); | ||
if (setPortTpid(p.m_port_id, tpid)) | ||
{ | ||
p.m_tpid = tpid; | ||
m_portList[alias] = p; | ||
} | ||
else | ||
{ | ||
SWSS_LOG_ERROR("Failed to set port %s TPID to 0x%x", alias.c_str(), tpid); | ||
it++; | ||
continue; | ||
} | ||
} | ||
|
||
if (!fec_mode.empty()) | ||
{ | ||
if (fec_mode_map.find(fec_mode) != fec_mode_map.end()) | ||
|
@@ -3151,6 +3208,8 @@ void PortsOrch::doLagTask(Consumer &consumer) | |
string operation_status; | ||
uint32_t lag_id = 0; | ||
int32_t switch_id = -1; | ||
string tpid_string; | ||
uint16_t tpid = 0; | ||
|
||
for (auto i : kfvFieldsValues(t)) | ||
{ | ||
|
@@ -3180,6 +3239,14 @@ void PortsOrch::doLagTask(Consumer &consumer) | |
{ | ||
switch_id = stoi(fvValue(i)); | ||
} | ||
else if (fvField(i) == "tpid") | ||
{ | ||
tpid_string = fvValue(i); | ||
// Need to get rid of the leading 0x | ||
tpid_string.erase(0,2); | ||
tpid = (uint16_t)stoi(tpid_string, 0, 16); | ||
SWSS_LOG_DEBUG("reading TPID string:%s to uint16: 0x%x", tpid_string.c_str(), tpid); | ||
} | ||
} | ||
|
||
if (table_name == CHASSIS_APP_LAG_TABLE_NAME) | ||
|
@@ -3236,6 +3303,23 @@ void PortsOrch::doLagTask(Consumer &consumer) | |
updateChildPortsMtu(l, mtu); | ||
} | ||
|
||
if (tpid != 0) | ||
{ | ||
if (tpid != l.m_tpid) | ||
{ | ||
if(!setLagTpid(l.m_lag_id, tpid)) | ||
{ | ||
SWSS_LOG_ERROR("Failed to set LAG %s TPID 0x%x", alias.c_str(), tpid); | ||
} | ||
else | ||
{ | ||
SWSS_LOG_DEBUG("Set LAG %s TPID to 0x%x", alias.c_str(), tpid); | ||
l.m_tpid = tpid; | ||
m_portList[alias] = l; | ||
} | ||
} | ||
} | ||
|
||
if (!learn_mode.empty() && (l.m_learn_mode != learn_mode)) | ||
{ | ||
if (l.m_bridge_port_id != SAI_NULL_OBJECT_ID) | ||
|
@@ -4441,6 +4525,35 @@ bool PortsOrch::removeLagMember(Port &lag, Port &port) | |
return true; | ||
} | ||
|
||
bool PortsOrch::setLagTpid(sai_object_id_t id, sai_uint16_t tpid) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
sai_status_t status = SAI_STATUS_SUCCESS; | ||
sai_attribute_t attr; | ||
|
||
attr.id = SAI_LAG_ATTR_TPID; | ||
|
||
attr.value.u16 = (uint16_t)tpid; | ||
|
||
status = sai_lag_api->set_lag_attribute(id, &attr); | ||
if (status != SAI_STATUS_SUCCESS) | ||
{ | ||
SWSS_LOG_ERROR("Failed to set TPID 0x%x to LAG pid:%" PRIx64 ", rv:%d", | ||
attr.value.u16, id, status); | ||
task_process_status handle_status = handleSaiSetStatus(SAI_API_LAG, status); | ||
if (handle_status != task_success) | ||
{ | ||
return parseHandleSaiStatusFailure(handle_status); | ||
} | ||
} | ||
else | ||
{ | ||
SWSS_LOG_NOTICE("Set TPID 0x%x to LAG pid:%" PRIx64 , attr.value.u16, id); | ||
} | ||
return true; | ||
} | ||
|
||
|
||
bool PortsOrch::setCollectionOnLagMember(Port &lagMember, bool enableCollection) | ||
{ | ||
/* Port must be LAG member */ | ||
|
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.
Please have it in same line
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.
Will change the logging to same line.