Skip to content

Add functions to serialize and deserialize strict flags and use these functions for port_error_status#1817

Open
saksarav-nokia wants to merge 5 commits intosonic-net:masterfrom
saksarav-nokia:saksarav-nokia-strict-flags
Open

Add functions to serialize and deserialize strict flags and use these functions for port_error_status#1817
saksarav-nokia wants to merge 5 commits intosonic-net:masterfrom
saksarav-nokia:saksarav-nokia-strict-flags

Conversation

@saksarav-nokia
Copy link
Copy Markdown
Contributor

Fixes the issue reported in sonic-net/sonic-buildimage#24895
This PR depends on opencomputeproject/SAI#2264

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Comment thread meta/SaiSerialize.cpp Outdated
SWSS_LOG_ENTER();

sai_deserialize_enum(s, &sai_metadata_enum_sai_port_error_status_t, (int32_t&)status);
sai_deserialize_flags(s, &sai_metadata_enum_sai_port_error_status_t, (int32_t&)status);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please bring serialize enum here, and move sai_desrialize_flags to deserialize_enum and check if flags strict is set

Comment thread meta/SaiSerialize.cpp Outdated
SWSS_LOG_ENTER();

return sai_serialize_enum(status, &sai_metadata_enum_sai_port_error_status_t);
return sai_serialize_flags(status, &sai_metadata_enum_sai_port_error_status_t);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same here as comment in deserialize

Comment thread meta/SaiSerialize.cpp Outdated
return sai_serialize_number(value);
}

std::string sai_serialize_flags(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you will need unittests for both those methods

@kcudnik
Copy link
Copy Markdown
Collaborator

kcudnik commented Mar 27, 2026

@saksarav-nokia hey, i took a look at your implementaion and it seems too complex for me, i made a proposal for serialization method for you: kcudnik@7ecbac8b
i forgot to add test case in Test where flags == 0

i assumed that meta->valuesnames[0] in each struct enum is always zero, but this will not be the case untill SAI submodule will be updated, so this extra check would need to be added in this serialieze, and i made fix here to support both case scenarios: kcudnik@3dc4b1c

i also added deserialize here:kcudnik@6749a44d its more flexible since it can support 0x token inside string not only at the end, but it don't support ignored values, and i didn't actually tested id xD you can do that :) its also flawed, if you give it empty string you will get 0 as return also if you give it strings with all pipes "|||" it will also return zero, it can be ether bug or feature :) for example "FOO||BAR" will be correctly deserialized, but serialize will not produce such string, and any missing value which is not in enum will be silently ignored which we probalby want to add warning or throw

@saksarav-nokia
Copy link
Copy Markdown
Contributor Author

saksarav-nokia commented Mar 30, 2026

@saksarav-nokia hey, i took a look at your implementaion and it seems too complex for me, i made a proposal for serialization method for you: kcudnik@7ecbac8b i forgot to add test case in Test where flags == 0

i assumed that meta->valuesnames[0] in each struct enum is always zero, but this will not be the case untill SAI submodule will be updated, so this extra check would need to be added in this serialieze, and i made fix here to support both case scenarios: kcudnik@3dc4b1c

i also added deserialize here:kcudnik@6749a44d its more flexible since it can support 0x token inside string not only at the end, but it don't support ignored values, and i didn't actually tested id xD you can do that :) its also flawed, if you give it empty string you will get 0 as return also if you give it strings with all pipes "|||" it will also return zero, it can be ether bug or feature :) for example "FOO||BAR" will be correctly deserialized, but serialize will not produce such string, and any missing value which is not in enum will be silently ignored which we probalby want to add warning or throw

Thanks @kcudnik . Do you want me to create a PR and i can close mine. Or do you want me to take your changes, test it and update this PR with the new changes?. Anyway i am pulling your changes, update the unit test for deserialize and testing it. So let me know

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@saksarav-nokia
Copy link
Copy Markdown
Contributor Author

@kcudnik , i took your changes and fixed minor issues and also added LOG_WARNING in deserialize. also added unit test for deserialize. Tested in the BCM platform based chassis switch.

@saksarav-nokia saksarav-nokia force-pushed the saksarav-nokia-strict-flags branch from 5e880ad to 99d354b Compare March 31, 2026 13:37
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Comment thread meta/sai_serialize.h Outdated
_In_ const int32_t value,
_In_ const sai_enum_metadata_t* meta);
_In_ const sai_enum_metadata_t* meta,
_In_ bool flagCheck = true);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why this flag is added it should not be used at all, current implementation should be backward compatible

Comment thread meta/SaiSerialize.cpp Outdated
_In_ const int32_t value,
_In_ const sai_enum_metadata_t* meta)
_In_ const sai_enum_metadata_t* meta,
bool flagCheck)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

plese remove that flag check, the entire purpose to serialize strict flags here in this enum is to not have this flag

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was about to message you in the comment regarding that change . The reason i added that flag is that the sai_stat_st_capability_t -> sai_stat_capability_t has sai_stat_id and uint32_t stat_modes. So when sai_serialize_stats_st_capability_list or sai_serialize_stat_st_capability is called with meta of type sai_stats_mode_t as by the unit_test, sai_serialize_stat_capability was serializing it incorrectly and unit test was failing. If you don't want a flag, i can fix the unit tests serialize_stat_st_capability_list . So sai_serialize_stats_st_capability_list should not be called with sai_metadata_enum_sai_stats_mode_t

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yea so this is special case since it's uint32_t field, maybe it should be converetd in SAI to enum,, but currently i see that stat_mode field is serialized as array, so i think it would be ahrd to make it backward compatible with new serialization, maybe just leave satt_mode as is ?

also i just noticed, that having pipe (|) in serializing enum as string, could mess some issues with recording/reading recording file, just wondering on that, didnt hit that caase yet, but then saiplayer parsing would beed to be updated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok. let me take the sairedis.rec with these changes and paly it in saiplayer and test it.

@saksarav-nokia saksarav-nokia force-pushed the saksarav-nokia-strict-flags branch from 06ddd6f to dff4f0c Compare March 31, 2026 19:14
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@saksarav-nokia saksarav-nokia force-pushed the saksarav-nokia-strict-flags branch from 90ec43b to 904a266 Compare March 31, 2026 20:31
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@saksarav-nokia
Copy link
Copy Markdown
Contributor Author

/azpw run

@mssonicbld
Copy link
Copy Markdown
Collaborator

⚠️ Notice: /azpw run only runs failed jobs now. If you want to trigger a whole pipline run, please rebase your branch or close and reopen the PR.
💡 Tip: You can also use /azpw retry to retry failed jobs directly.

Retrying failed(or canceled) jobs...

@mssonicbld
Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) stages in build 1076076:

✅Stage BuildAsan:

  • Job amd64: retried.

Comment thread meta/SaiSerialize.cpp
continue;
}

for (i = 0; i < meta->valuescount; ++i)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

declare size_t in this ilie in forloop this is not C

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@kcudnik , I had it in the for loop first, but when i added the check and SYS_LOG_WARN message after the for loop, i had to use the variable "i" and hence moved it out.
if (i == meta->valuescount)
{
// v is empty or doesn't match any enum
SWSS_LOG_WARN("%s in %s has invalid enum for %s", v.c_str(), s.c_str(), meta->name);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@kcudnik , Could you please check my response.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ok then declare it at lease close to for

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok. Thanks. I addressed your comment. Pls check

@saksarav-nokia saksarav-nokia marked this pull request as ready for review April 1, 2026 14:56
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

… functions for port_error_status

Signed-off-by: saksarav <sakthivadivu.saravanaraj@nokia.com>
Signed-off-by: saksarav <sakthivadivu.saravanaraj@nokia.com>
Signed-off-by: saksarav <sakthivadivu.saravanaraj@nokia.com>
… the correct meta

Signed-off-by: saksarav <sakthivadivu.saravanaraj@nokia.com>
Signed-off-by: saksarav <sakthivadivu.saravanaraj@nokia.com>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants