[testutils] standardize packet payload generation#267
Merged
fruffy merged 2 commits intoJul 18, 2026
Conversation
Add a common payload helper for simple packet builders. Support explicit payloads, truncate them to pktlen, and fill remaining space with a consistent incrementing-byte pattern. Keep protocol-specific payload arguments for compatibility and reject calls that specify both generic and protocol-specific payloads. Signed-off-by: Artur Novotarskyi <artur.novotarskyi@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR standardizes how ptf.testutils “simple_*_packet” builders generate payload bytes by introducing a shared helper that supports explicit payload injection, truncation to pktlen, and deterministic padding for the remainder.
Changes:
- Added
_add_payload_and_padding()helper and refactored multiple packet builders to use it for consistent padding/payload handling. - Introduced a new generic
payloadargument to several builders while keeping legacy protocol-specific payload parameters (and rejecting conflicting usage). - Added unit tests covering default payload consistency, payload truncation/padding behavior, and conflicting payload argument validation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/ptf/testutils.py |
Introduces _add_payload_and_padding and migrates multiple simple packet builders to use it; adds generic payload support and conflict checks for legacy payload args. |
utests/tests/ptf/test_testutils.py |
Adds tests validating the standardized payload generation behavior and conflict handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Artur Novotarskyi <artur.novotarskyi@gmail.com>
fruffy
approved these changes
Jul 14, 2026
Contributor
Author
|
@fruffy Thanks for the review! All checks are green. Could you please merge this PR? |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add a common payload helper for simple packet builders. Support explicit payloads, truncate them to pktlen, and fill remaining space with a consistent incrementing-byte pattern.
Keep protocol-specific payload arguments for compatibility and reject calls that specify both generic and protocol-specific payloads.
Fixes #167