-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: panic due to negative seqnums in sequence unwrapper
Out-of-order sequence numbers from a previous wrap around causes the sequence unwrapper to generate negative sequence numbers. That, in turn, generates a panic in the jitterbuffer and receive logs. Adjust the sequence unwrapper to adjust the wraparound counters if older packets from a previous wraparound arrive.
- Loading branch information
1 parent
c3b506b
commit 602359d
Showing
3 changed files
with
115 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSequenceUnwrapper(t *testing.T) { | ||
unwrapper := NewSequenceUnwrapper(16) | ||
|
||
// Test case 1: Initialisation | ||
result := unwrapper.Unwrap(uint64(65534)) | ||
expected := int64(65534) | ||
if result != expected { | ||
t.Errorf("[T1] Unexpected result. Expected: %d, Got: %d", expected, result) | ||
} | ||
|
||
// Test case 2: in-order seqnum increment | ||
result = unwrapper.Unwrap(uint64(65535)) | ||
expected = int64(65535) | ||
if result != expected { | ||
t.Errorf("[T2] Unexpected result. Expected: %d, Got: %d", expected, result) | ||
} | ||
|
||
// Test case 3: first wraparound (in-order seqnum increment) | ||
result = unwrapper.Unwrap(uint64(0)) | ||
expected = int64(65536) | ||
if result != expected { | ||
t.Errorf("[T3] Unexpected result. Expected: %d, Got: %d", expected, result) | ||
} | ||
|
||
// Test case 4: Increment after wraparound (with gap) | ||
result = unwrapper.Unwrap(uint64(2)) | ||
expected = int64(65538) | ||
if result != expected { | ||
t.Errorf("[T4] Unexpected result. Expected: %d, Got: %d", expected, result) | ||
} | ||
|
||
// Test case 5: second wraparound (simulated in-order seqnum increments) | ||
for i := 3; i < (1 << 16); i++ { | ||
unwrapper.Unwrap(uint64(i)) | ||
} | ||
result = unwrapper.Unwrap(uint64(0)) | ||
expected = int64(131072) | ||
if result != expected { | ||
t.Errorf("[T5] Unexpected result. Expected: %d, Got: %d", expected, result) | ||
} | ||
|
||
// Test case 6: Duplicate seqnum | ||
result = unwrapper.Unwrap(uint64(0)) | ||
expected = int64(131072) | ||
if result != expected { | ||
t.Errorf("[T6] Unexpected result. Expected: %d, Got: %d", expected, result) | ||
} | ||
|
||
// Test case for negative values | ||
// Assuming highestSequenceNumber is 2, wrapArounds is 0, inMax is 65536 | ||
// and lastSeqNo is 65535 | ||
// Test case 7: Negative value | ||
unwrapper.highestSequenceNumber = 2 | ||
unwrapper.wrapArounds = 0 | ||
unwrapper.inMax = 65536 | ||
unwrapper.lastSeqNo = 65530 | ||
result = unwrapper.Unwrap(uint64(65534)) | ||
expected = int64(65534) | ||
if result != expected { | ||
t.Errorf("[T7] Unexpected result for negative values. Expected: %d, Got: %d", expected, result) | ||
} | ||
} |