-
Notifications
You must be signed in to change notification settings - Fork 79
/
param_reconfig_response.go
98 lines (86 loc) · 3.31 KB
/
param_reconfig_response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package sctp
import (
"encoding/binary"
"errors"
"fmt"
)
// This parameter is used by the receiver of a Re-configuration Request
// Parameter to respond to the request.
//
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Parameter Type = 16 | Parameter Length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Re-configuration Response Sequence Number |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Result |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Sender's Next TSN (optional) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Receiver's Next TSN (optional) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
type paramReconfigResponse struct {
paramHeader
// This value is copied from the request parameter and is used by the
// receiver of the Re-configuration Response Parameter to tie the
// response to the request.
reconfigResponseSequenceNumber uint32
// This value describes the result of the processing of the request.
result reconfigResult
}
type reconfigResult uint32
const (
reconfigResultSuccessNOP reconfigResult = 0
reconfigResultSuccessPerformed reconfigResult = 1
reconfigResultDenied reconfigResult = 2
reconfigResultErrorWrongSSN reconfigResult = 3
reconfigResultErrorRequestAlreadyInProgress reconfigResult = 4
reconfigResultErrorBadSequenceNumber reconfigResult = 5
reconfigResultInProgress reconfigResult = 6
)
// Reconfiguration response errors
var (
ErrReconfigRespParamTooShort = errors.New("reconfig response parameter too short")
)
func (t reconfigResult) String() string {
switch t {
case reconfigResultSuccessNOP:
return "0: Success - Nothing to do"
case reconfigResultSuccessPerformed:
return "1: Success - Performed"
case reconfigResultDenied:
return "2: Denied"
case reconfigResultErrorWrongSSN:
return "3: Error - Wrong SSN"
case reconfigResultErrorRequestAlreadyInProgress:
return "4: Error - Request already in progress"
case reconfigResultErrorBadSequenceNumber:
return "5: Error - Bad Sequence Number"
case reconfigResultInProgress:
return "6: In progress"
default:
return fmt.Sprintf("Unknown reconfigResult: %d", t)
}
}
func (r *paramReconfigResponse) marshal() ([]byte, error) {
r.typ = reconfigResp
r.raw = make([]byte, 8)
binary.BigEndian.PutUint32(r.raw, r.reconfigResponseSequenceNumber)
binary.BigEndian.PutUint32(r.raw[4:], uint32(r.result))
return r.paramHeader.marshal()
}
func (r *paramReconfigResponse) unmarshal(raw []byte) (param, error) {
err := r.paramHeader.unmarshal(raw)
if err != nil {
return nil, err
}
if len(r.raw) < 8 {
return nil, ErrReconfigRespParamTooShort
}
r.reconfigResponseSequenceNumber = binary.BigEndian.Uint32(r.raw)
r.result = reconfigResult(binary.BigEndian.Uint32(r.raw[4:]))
return r, nil
}