Feat/12236 packet count v4 - #43
Closed
Davihan11 wants to merge 8 commits into
Closed
Conversation
STL_EXACT was never passed to the TRex client manager (AdHocExactStlProfile always constructed the base manager with mode=STL), so it only served to select a separate profile class in the tests. Replace it with a dedicated --trex-exact-count flag that is decoupled from mode selection: the mode stays STL and the exact packet count is handled inside STL's run(). - Remove STL_EXACT from the TrexMode enum and str_to_trex_mode() - Drop 'stl.exact' from --force-trex-mode / --prefer-trex-mode choices - Add --trex-exact-count (store_true) pytest option
Move the STLTXSingleBurst exact-count logic from the AdHocExactStlProfile subclass into the base STL branch of run(). When --trex-exact-count is set, run() builds STLStream/STLTXSingleBurst streams (pps = --trex-pps * multiplier, total_pkts = --trex-total-packets) instead of the duration-based push_remote loop. For non-STL modes the flag is ignored with a warning. - Delete ad_hoc_exact_stl_profile.py - Store request on the base manager so run() can read pytest options - Simplify all 'STL | STL_EXACT' case branches to 'STL'
Remove the AdHocExactStlProfile branches and always instantiate the normal profile class. The exact packet count is now enabled via the --trex-exact-count flag handled centrally in STL's run(), so the tests no longer need to branch on a separate mode. STL is added to the available modes where it was previously only reachable through STL_EXACT.
- Add -ec | --trex-exact-count flag to pytest_start.sh and pass it through - Reword -pps / -tp help to reference the STL exact-count mode - Update README to describe exact packet count as an STL option enabled by --trex-exact-count instead of a separate stl.exact mode
argparse interprets % as a format character in help strings, so the literal <drop_rate%> in the --binary-search help raised 'unsupported format character' when rendering --help. Escape it as %%.
…eparators - Move merge_pcaps() from trex_client_manager.py to util/trex_util.py so it lives with the other TRex helpers. - Introduce a BaseAdHocTrex parent subclass in trex_client_manager.py that owns the shared ad-hoc __init__ (runtime pcaps + STL mode); AdHocStlProfile now inherits it instead of duplicating the constructor. - Use underscore separators for large numeric literals (200_000, 10_000_000) in conftest.py for readability.
Address PR review feedback for the packet-count feature: - Replace the three separate options (--trex-exact-count, --trex-pps, --trex-total-packets) with a single --trex-stl-burst [PPS] [PACKET_COUNT] option (and -sb in pytest_start.sh). Defaults: 200000 PPS, 10000000 packets. - Stream pcap merging in merge_pcaps() (PcapReader/PcapWriter) so large pcaps are not loaded fully into memory. - Introduce a Pcap NamedTuple in trex_client_manager.py and use per-test unique merged pcap names to avoid overwrites/races. - Fix trex client class imports to go through the 'trex' alias so isinstance() checks in STLClient.add_streams() keep working. - Add ruff pre-commit config and ignore runtime-generated merged pcaps. - Update README and param_template accordingly.
There was a problem hiding this comment.
Pull request overview
This PR enhances the Suricata-Test-Suite TRex integration by improving STL PCAP handling (multi-PCAP merging) and adding an STL exact packet-count (“burst”) mode to make traffic generation more deterministic and easier to control across runs and multiplier-based modes.
Changes:
- Added streaming multi-PCAP merge support and integrated merged-PCAP behavior into STL profile initialization.
- Introduced an STL exact-count mode controlled via
--trex-stl-burst, plus corresponding CLI wiring and docs. - Expanded several test suites to allow selecting STL mode via
--force-trex-mode/--prefer-trex-mode, and refactored ad-hoc STL profiles to share a common base.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| util/trex_util.py | Adds merge_pcaps() helper to interleave multiple PCAPs into a single merged PCAP. |
| assets/trex/traffic_profiles/trex_client_manager.py | Refactors PCAP representation, merges multi-PCAP STL profiles, and implements STL burst mode in run(). |
| assets/trex/traffic_profiles/ad_hoc_stl_trex_profile.py | Switches ad-hoc STL profile to reuse the new shared ad-hoc base class. |
| conftest.py | Adds pytest option --trex-stl-burst and updates binary-search help text. |
| pytest_start.sh | Adds -sb/--trex-stl-burst flag parsing and forwards it to pytest. |
| README.md | Documents multi-PCAP STL merging, STL exact-count mode, and mode forcing/preference options. |
| param_template.py | Adjusts MTU parameter list (removes 2500, leaves 3000). |
| tests/web_50_sites/test_web_50_sites.py | Allows STL as a selectable TRex mode for this test. |
| tests/pcap_replay/test_pcap_replay.py | Uses get_trex_mode to validate forced/preferred modes and passes explicit mode into profile. |
| tests/nfs_smb_simple/test_nfs_smb_simple.py | Allows STL as a selectable TRex mode for this test. |
| tests/https_simple/test_https_simple.py | Allows STL as a selectable TRex mode for this test. |
| tests/http_simple/test_http_simple.py | Allows STL as a selectable TRex mode for this test. |
| tests/http_https_smb_simple/test_http_https_smb_simple.py | Allows STL as a selectable TRex mode for this test. |
| .gitignore | Ignores merged STL PCAPs generated at runtime. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+53
to
+56
| quotas = [w / total_w for w in weights] | ||
| min_q = min(q for q in quotas if q > 0) | ||
| # zero-weight sources emit nothing; others emit at least 1 packet per round | ||
| per_round = [0 if q <= 0 else max(1, round(q / min_q)) for q in quotas] |
Collaborator
Author
There was a problem hiding this comment.
We are using weights with 10, 100, 1000. Not relevant at this scale.
--trex-stl-burst is parsed as floats, but TRex requires an integer packet count. Cast total_pkts to int while keeping pps as a float (since pps is scaled by a float multiplier).
Collaborator
Author
|
found a bug where trex refuses float packet values. |
matyas7dub
requested changes
Aug 15, 2026
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.
This pull request introduces significant improvements to the TRex STL (Stateless) traffic generator integration, focusing on enhanced multi-PCAP handling and the addition of an exact packet count (burst) mode. The changes improve both the usability and determinism of traffic generation for testing. The most important changes are grouped below.
STL Mode Enhancements
--trex-stl-burstoption. This enables deterministic testing where you need to send precisely N packets. The packet count is fixed, but the send rate is scaled by the traffic multiplier, supporting binary search and enumeration.Codebase Refactoring and Usability
PcapNamedTuple for better type safety and clarity, and updated all STL/ASTF/STF profile logic to use this structure. PCAP upload, merging, and replay logic is now more robust and easier to maintain.BaseAdHocTrexclass: Provides a unified base for ad-hoc STL profiles that receive their PCAPs at runtime, ensuring consistent behavior across test profiles.Documentation and Developer Experience
README.mdhas been expanded to describe multi-PCAP merging, the new STL exact-count mode, and usage examples for both. It also documents the new--force-trex-modeand--prefer-trex-modeoptions for test selection.