| 1 |
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly> |
| 2 |
// SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
package sctp |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/assert" |
| 10 |
) |
| 11 |
|
| 12 |
func testChunkReconfigParamA() []byte { |
| 13 |
return []byte{ |
| 14 |
0x00, 0x0d, 0x00, 0x16, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 15 |
0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
func testChunkReconfigParamB() []byte { |
| 20 |
return []byte{0x0, 0xd, 0x0, 0x10, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x3} |
| 21 |
} |
| 22 |
|
| 23 |
func TestParamOutgoingResetRequest_Success(t *testing.T) { |
| 24 |
tt := []struct { |
| 25 |
binary []byte |
| 26 |
parsed *paramOutgoingResetRequest |
| 27 |
}{ |
| 28 |
{ |
| 29 |
testChunkReconfigParamA(), |
| 30 |
¶mOutgoingResetRequest{ |
| 31 |
paramHeader: paramHeader{ |
| 32 |
typ: outSSNResetReq, |
| 33 |
len: 22, |
| 34 |
raw: testChunkReconfigParamA()[4:], |
| 35 |
}, |
| 36 |
reconfigRequestSequenceNumber: 1, |
| 37 |
reconfigResponseSequenceNumber: 2, |
| 38 |
senderLastTSN: 3, |
| 39 |
streamIdentifiers: []uint16{4, 5, 6}, |
| 40 |
}, |
| 41 |
}, |
| 42 |
{ |
| 43 |
testChunkReconfigParamB(), |
| 44 |
¶mOutgoingResetRequest{ |
| 45 |
paramHeader: paramHeader{ |
| 46 |
typ: outSSNResetReq, |
| 47 |
len: 16, |
| 48 |
raw: testChunkReconfigParamB()[4:], |
| 49 |
}, |
| 50 |
reconfigRequestSequenceNumber: 1, |
| 51 |
reconfigResponseSequenceNumber: 2, |
| 52 |
senderLastTSN: 3, |
| 53 |
streamIdentifiers: []uint16{}, |
| 54 |
}, |
| 55 |
}, |
| 56 |
} |
| 57 |
|
| 58 |
for i, tc := range tt { |
| 59 |
actual := ¶mOutgoingResetRequest{} |
| 60 |
_, err := actual.unmarshal(tc.binary) |
| 61 |
assert.NoErrorf(t, err, "failed to unmarshal #%d", i) |
| 62 |
assert.Equal(t, tc.parsed, actual) |
| 63 |
|
| 64 |
b, err := actual.marshal() |
| 65 |
assert.NoErrorf(t, err, "failed to marshal #%d", i) |
| 66 |
assert.Equal(t, tc.binary, b) |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
func TestParamOutgoingResetRequest_Failure(t *testing.T) { |
| 71 |
tt := []struct { |
| 72 |
name string |
| 73 |
binary []byte |
| 74 |
}{ |
| 75 |
{"packet too short", testChunkReconfigParamA()[:8]}, |
| 76 |
{"param too short", []byte{0x0, 0xd, 0x0, 0x4}}, |
| 77 |
} |
| 78 |
|
| 79 |
for i, tc := range tt { |
| 80 |
actual := ¶mOutgoingResetRequest{} |
| 81 |
_, err := actual.unmarshal(tc.binary) |
| 82 |
assert.Errorf(t, err, "expected unmarshal #%d: '%s' to fail.", i, tc.name) |
| 83 |
} |
| 84 |
} |