fix(j1939-21): respect sequence number for fragmented frames on reass… - #73
Open
drewr95 wants to merge 2 commits into
Open
fix(j1939-21): respect sequence number for fragmented frames on reass…#73drewr95 wants to merge 2 commits into
drewr95 wants to merge 2 commits into
Conversation
drewr95
requested review from
RaulSMS and
khauersp
and
a lite review from Copilot
August 20, 2026 18:45
There was a problem hiding this comment.
Pull request overview
This PR addresses Issue #69 by enforcing strict TP.DT sequence-number ordering during J1939-21 multi-packet reassembly, aborting/terminating sessions when out-of-sequence packets are received to prevent corrupted payload delivery.
Changes:
- Track
next_expected_packetin the receive buffer for both BAM and CMDT sessions. - Validate TP.DT packet sequence numbers in
_process_tp_dt, abort/cleanup on violations, and raise aValueError. - Add ECU-level tests covering out-of-sequence scenarios for BAM and CMDT sessions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| j1939/j1939_21.py | Adds receive-side sequence tracking and abort/error behavior for out-of-sequence TP.DT packets. |
| test/test_ecu.py | Adds tests ensuring out-of-sequence TP.DT packets terminate sessions and prevent partial delivery. |
Suppressed comments (1)
test/test_ecu.py:128
- This test requests the
feederfixture but never uses it, which adds unnecessary setup/overhead and can hide accidental dependencies. Remove the unused fixture parameter.
def test_peer_to_peer_sequence_gap_after_valid_packet_aborts(feeder):
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
drewr95
force-pushed
the
fix/69-sequential-packet-reassembly
branch
from
August 20, 2026 18:54
f3b9215 to
a8f7a11
Compare
khauersp
approved these changes
Aug 21, 2026
khauersp
left a comment
Collaborator
There was a problem hiding this comment.
Do we need to implement this for j1939_22?
Collaborator
Author
I'm honestly not sure if j1939-22 requires this. It can be a follow up issue and I can research into it |
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.
Summary
Fixes #69
This pull request strengthens the Transport Protocol (TP) implementation in
j1939_21.pyby enforcing strict sequence checking for incoming TP.DT packets, ensuring that out-of-sequence packets are correctly detected and handled according to the J1939-21 specification. It also adds comprehensive tests to verify these behaviors.Transport Protocol improvements:
_process_tp_dt: Now tracks the next expected packet and raises aValueErrorif a duplicate or invalid sequence number is received, aborting the session and cleaning up resources as appropriate.next_expected_packetfield in the receive buffer during both BAM and CMDT session setup in_process_tp_cm, ensuring consistent state tracking. [1] [2]Testing enhancements:
test/test_ecu.pyto verify that out-of-sequence TP.DT packets are correctly rejected for both BAM and peer-to-peer (CMDT) sessions, and that session state is properly cleaned up after errors.Test infrastructure:
pytestand relevant classes to support the new test cases.These changes improve protocol compliance, robustness, and test coverage for the J1939 TP implementation.