param_reconfig_response.go 3.2 KB

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