Skip to content

Commit

Permalink
[libsai] Add attr name logging when doing get api
Browse files Browse the repository at this point in the history
Using metadata add generic code to obtain attr name and log it when
attr is not supported
  • Loading branch information
kcudnik committed Oct 21, 2023
1 parent c18ea3f commit f83d737
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions dash-pipeline/SAI/src/dashsai.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "dashsai.h"

extern "C" {
#include "saimetadata.h"
}

#include <cstdlib>

using namespace dash;
Expand Down Expand Up @@ -341,6 +345,10 @@ sai_status_t DashSai::getSwitchAttribute(

for (uint32_t i = 0; i < attr_count ; i++, attr++)
{
auto *md = sai_metadata_get_attr_metadata(SAI_OBJECT_TYPE_SWITCH, attr->id);

const char* attrName = md ? md->attridname : "unknown";

switch(attr->id)
{
case SAI_SWITCH_ATTR_NUMBER_OF_ACTIVE_PORTS:
Expand Down Expand Up @@ -421,12 +429,12 @@ sai_status_t DashSai::getSwitchAttribute(

if (getenv(DASH_USE_NOT_SUPPORTED))
{
DASH_LOG_WARN("[%d] attr %d is NOT SUPPORTED", i, attr->id);
DASH_LOG_WARN("[%d] attr %d %s is NOT SUPPORTED", i, attr->id, attrName);

return SAI_STATUS_NOT_SUPPORTED;
}

DASH_LOG_WARN("[%d] attr %d is NOT SUPPORTED, but returning SAI_STATUS_SUCCESS", i, attr->id);
DASH_LOG_WARN("[%d] attr %d %s is NOT SUPPORTED, but returning SAI_STATUS_SUCCESS", i, attr->id, attrName);

memset(&attr->value, 0, sizeof(attr->value)); // clear potential caller garbage

Expand All @@ -449,6 +457,10 @@ sai_status_t DashSai::getPortAttribute(

for (uint32_t i = 0; i < attr_count ; i++, attr++)
{
auto *md = sai_metadata_get_attr_metadata(SAI_OBJECT_TYPE_PORT, attr->id);

const char* attrName = md ? md->attridname : "unknown";

switch(attr->id)
{
case SAI_PORT_ATTR_QOS_NUMBER_OF_QUEUES:
Expand Down Expand Up @@ -488,12 +500,12 @@ sai_status_t DashSai::getPortAttribute(

if (getenv(DASH_USE_NOT_SUPPORTED))
{
DASH_LOG_WARN("[%d] attr %d is NOT SUPPORTED", i, attr->id);
DASH_LOG_WARN("[%d] attr %d %s is NOT SUPPORTED", i, attr->id, attrName);

return SAI_STATUS_NOT_SUPPORTED;
}

DASH_LOG_WARN("[%d] attr %d is NOT SUPPORTED, but returning SAI_STATUS_SUCCESS", i, attr->id);
DASH_LOG_WARN("[%d] attr %d %s is NOT SUPPORTED, but returning SAI_STATUS_SUCCESS", i, attr->id, attrName);

memset(&attr->value, 0, sizeof(attr->value)); // clear potential caller garbage

Expand Down

0 comments on commit f83d737

Please sign in to comment.