Skip to content

[202511] loganalyzer: Remove IPFIX template size estimation, query actual size from SAI instead#4305

Closed
Pterosaur wants to merge 8 commits intosonic-net:202511from
Pterosaur:backport/202511/hft-ipfix-template-size
Closed

[202511] loganalyzer: Remove IPFIX template size estimation, query actual size from SAI instead#4305
Pterosaur wants to merge 8 commits intosonic-net:202511from
Pterosaur:backport/202511/hft-ipfix-template-size

Conversation

@Pterosaur
Copy link
Copy Markdown
Contributor

Description of PR

Backport of #4304 to 202511 branch.

Original PR: #4304

Summary:
Remove the IPFIX template size estimation logic in HFTelProfile::updateTemplates() and replace it with a two-phase SAI query: first query the required buffer size (count=0, list=nullptr), then allocate and fetch the actual data. This avoids incorrect size estimates that could cause buffer overflow or truncation.

Includes mock test coverage for all code paths in updateTemplates().

Conflict resolution

tests/mock_tests/Makefile.am: 202511 branch does not have portphyattr_ut.cpp and counternameupdater_ut.cpp (present on master). Resolved by adding only hftelprofile_ut.cpp to the existing file list.

Type of change

  • Bug fix

Approach

See original PR #4304 for full details.

How did you verify/test it?

Mock tests cover all code paths in updateTemplates():

  • BufferOverflow_ThenSuccess: BUFFER_OVERFLOW → SUCCESS happy path
  • Success_EmptyTemplate: SUCCESS with count=0
  • FirstCall_UnexpectedFailure: unexpected error on size query
  • SecondCall_Failure: data fetch fails after BUFFER_OVERFLOW
  • UnknownOID_Throws: unknown tel-type OID

Any platform specific information?

No.

Documentation

N/A

…tead

The previous approach estimated the IPFIX template buffer size based on
counter subscription counts, but the estimation could be inaccurate and
result in SAI_STATUS_BUFFER_OVERFLOW errors with noisy error logs from
the SDK layer.

Instead of estimating, pass count=0 and list=nullptr to
get_tam_tel_type_attribute() to query the required buffer size first,
then allocate the exact buffer and fetch the data. This follows the
standard SAI pattern for variable-length attribute queries and eliminates
the unreliable estimation logic.

Signed-off-by: Ze Gan <ganze718@gmail.com>
Add unit tests covering all code paths in updateTemplates() to satisfy
the diff-coverage ≥80% requirement:

- BufferOverflow_ThenSuccess: SAI returns BUFFER_OVERFLOW on the size
  query, then SUCCESS on the data fetch (happy path with templates).
- Success_EmptyTemplate: SAI returns SUCCESS with count=0 on the first
  call (no templates available).
- FirstCall_UnexpectedFailure: SAI returns an unexpected error on the
  size query.
- SecondCall_Failure: SAI returns BUFFER_OVERFLOW on the size query but
  fails on the data fetch.
- UnknownOID_Throws: caller passes an OID not registered in the
  profile.

Uses the bufferorch_ut.cpp pattern: copy sai_tam_api_t, override
get_tam_tel_type_attribute with a mock, restore on tear-down.

Signed-off-by: Ze Gan <ganze718@gmail.com>
@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).

Remove unused 'tel_oid' parameter from Stub::init() to fix
-Werror=unused-parameter build failure.

Signed-off-by: Ze Gan <ganze718@gmail.com>
@Pterosaur Pterosaur force-pushed the backport/202511/hft-ipfix-template-size branch from ed33884 to 6fc0c72 Compare March 8, 2026 01:12
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Move #define private/protected public before all #include directives
to ensure hftelprofile.h is expanded with public access, even when
indirectly included via mock_orchagent_main.h -> hftelorch.h.

Signed-off-by: Ze Gan <ganze718@gmail.com>
@Pterosaur Pterosaur force-pushed the backport/202511/hft-ipfix-template-size branch from 126d5ec to c2771b2 Compare March 9, 2026 02:11
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

The UpdateTemplatesTest fixture assumed sai_tam_api was already
initialized by other test fixtures, but execution order is not
guaranteed. Initialize a default sai_tam_api_t when NULL.

Signed-off-by: Ze Gan <ganze718@gmail.com>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Use void* intermediate cast to avoid -Wcast-align error when
casting aligned unsigned char buffer to HFTelProfile* on ARM.

Signed-off-by: Ze Gan <ganze718@gmail.com>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@vmittal-msft
Copy link
Copy Markdown
Contributor

@Pterosaur please help resolve conflicts

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@vmittal-msft
Copy link
Copy Markdown
Contributor

@Pterosaur please help again

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@PriyanshTratiya
Copy link
Copy Markdown

PriyanshTratiya commented Mar 20, 2026

Hi @Pterosaur closing this PR as a cherry pick got merged yesterday with this PR: #4369, let me know if we need anything else in 202511 for the original PR

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants