1 /* 2 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #include "net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter.h" 11 12 #include <stdint.h> 13 14 #include <string> 15 #include <type_traits> 16 #include <vector> 17 18 #include "absl/types/optional.h" 19 #include "api/array_view.h" 20 #include "net/dcsctp/packet/bounded_byte_reader.h" 21 #include "net/dcsctp/packet/bounded_byte_writer.h" 22 #include "net/dcsctp/packet/tlv_trait.h" 23 #include "rtc_base/strings/string_builder.h" 24 25 namespace dcsctp { 26 27 // https://tools.ietf.org/html/rfc6525#section-4.3 28 29 // 0 1 2 3 30 // 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 31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 32 // | Parameter Type = 15 | Parameter Length = 8 | 33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 34 // | Re-configuration Request Sequence Number | 35 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 36 constexpr int SSNTSNResetRequestParameter::kType; 37 Parse(rtc::ArrayView<const uint8_t> data)38absl::optional<SSNTSNResetRequestParameter> SSNTSNResetRequestParameter::Parse( 39 rtc::ArrayView<const uint8_t> data) { 40 absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data); 41 if (!reader.has_value()) { 42 return absl::nullopt; 43 } 44 ReconfigRequestSN request_sequence_number(reader->Load32<4>()); 45 46 return SSNTSNResetRequestParameter(request_sequence_number); 47 } 48 SerializeTo(std::vector<uint8_t> & out) const49void SSNTSNResetRequestParameter::SerializeTo(std::vector<uint8_t>& out) const { 50 BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out); 51 writer.Store32<4>(*request_sequence_number_); 52 } 53 ToString() const54std::string SSNTSNResetRequestParameter::ToString() const { 55 rtc::StringBuilder sb; 56 sb << "SSN/TSN Reset Request, req_seq_nbr=" << *request_sequence_number(); 57 return sb.Release(); 58 } 59 60 } // namespace dcsctp 61