summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/net/dcsctp/packet/parameter
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /third_party/libwebrtc/net/dcsctp/packet/parameter
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/net/dcsctp/packet/parameter')
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.cc68
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.h63
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/add_incoming_streams_request_parameter_test.cc38
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.cc67
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.h63
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter_test.cc38
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/forward_tsn_supported_parameter.cc45
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/forward_tsn_supported_parameter.h49
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/forward_tsn_supported_parameter_test.cc34
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/heartbeat_info_parameter.cc60
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/heartbeat_info_parameter.h54
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.cc89
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.h66
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter_test.cc42
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.cc101
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h78
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter_test.cc47
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/parameter.cc96
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/parameter.h96
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/parameter_test.cc53
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/reconfiguration_response_parameter.cc152
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/reconfiguration_response_parameter.h92
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/reconfiguration_response_parameter_test.cc68
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter.cc60
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter.h59
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter_test.cc37
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/state_cookie_parameter.cc51
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/state_cookie_parameter.h55
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/state_cookie_parameter_test.cc40
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/supported_extensions_parameter.cc65
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/supported_extensions_parameter.h62
-rw-r--r--third_party/libwebrtc/net/dcsctp/packet/parameter/supported_extensions_parameter_test.cc42
32 files changed, 2030 insertions, 0 deletions
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.cc
new file mode 100644
index 0000000000..c33e3e11f6
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.cc
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.h"
+
+#include <stdint.h>
+
+#include <string>
+#include <type_traits>
+#include <vector>
+
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "net/dcsctp/common/internal_types.h"
+#include "net/dcsctp/packet/bounded_byte_reader.h"
+#include "net/dcsctp/packet/bounded_byte_writer.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+#include "rtc_base/strings/string_builder.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc6525#section-4.6
+
+// 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 = 18 | Parameter Length = 12 |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | Re-configuration Request Sequence Number |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | Number of new streams | Reserved |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+constexpr int AddIncomingStreamsRequestParameter::kType;
+
+absl::optional<AddIncomingStreamsRequestParameter>
+AddIncomingStreamsRequestParameter::Parse(rtc::ArrayView<const uint8_t> data) {
+ absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
+ if (!reader.has_value()) {
+ return absl::nullopt;
+ }
+ ReconfigRequestSN request_sequence_number(reader->Load32<4>());
+ uint16_t nbr_of_new_streams = reader->Load16<8>();
+
+ return AddIncomingStreamsRequestParameter(request_sequence_number,
+ nbr_of_new_streams);
+}
+
+void AddIncomingStreamsRequestParameter::SerializeTo(
+ std::vector<uint8_t>& out) const {
+ BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out);
+ writer.Store32<4>(*request_sequence_number_);
+ writer.Store16<8>(nbr_of_new_streams_);
+}
+
+std::string AddIncomingStreamsRequestParameter::ToString() const {
+ rtc::StringBuilder sb;
+ sb << "Add Incoming Streams Request, req_seq_nbr="
+ << *request_sequence_number();
+ return sb.Release();
+}
+
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.h b/third_party/libwebrtc/net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.h
new file mode 100644
index 0000000000..3859eb3f7e
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef NET_DCSCTP_PACKET_PARAMETER_ADD_INCOMING_STREAMS_REQUEST_PARAMETER_H_
+#define NET_DCSCTP_PACKET_PARAMETER_ADD_INCOMING_STREAMS_REQUEST_PARAMETER_H_
+#include <stddef.h>
+#include <stdint.h>
+
+#include <string>
+#include <vector>
+
+#include "absl/strings/string_view.h"
+#include "api/array_view.h"
+#include "net/dcsctp/common/internal_types.h"
+#include "net/dcsctp/packet/parameter/parameter.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc6525#section-4.6
+struct AddIncomingStreamsRequestParameterConfig : ParameterConfig {
+ static constexpr int kType = 18;
+ static constexpr size_t kHeaderSize = 12;
+ static constexpr size_t kVariableLengthAlignment = 0;
+};
+
+class AddIncomingStreamsRequestParameter
+ : public Parameter,
+ public TLVTrait<AddIncomingStreamsRequestParameterConfig> {
+ public:
+ static constexpr int kType = AddIncomingStreamsRequestParameterConfig::kType;
+
+ explicit AddIncomingStreamsRequestParameter(
+ ReconfigRequestSN request_sequence_number,
+ uint16_t nbr_of_new_streams)
+ : request_sequence_number_(request_sequence_number),
+ nbr_of_new_streams_(nbr_of_new_streams) {}
+
+ static absl::optional<AddIncomingStreamsRequestParameter> Parse(
+ rtc::ArrayView<const uint8_t> data);
+
+ void SerializeTo(std::vector<uint8_t>& out) const override;
+ std::string ToString() const override;
+
+ ReconfigRequestSN request_sequence_number() const {
+ return request_sequence_number_;
+ }
+ uint16_t nbr_of_new_streams() const { return nbr_of_new_streams_; }
+
+ private:
+ ReconfigRequestSN request_sequence_number_;
+ uint16_t nbr_of_new_streams_;
+};
+
+} // namespace dcsctp
+
+#endif // NET_DCSCTP_PACKET_PARAMETER_ADD_INCOMING_STREAMS_REQUEST_PARAMETER_H_
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/add_incoming_streams_request_parameter_test.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/add_incoming_streams_request_parameter_test.cc
new file mode 100644
index 0000000000..a29257a8f8
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/add_incoming_streams_request_parameter_test.cc
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.h"
+
+#include <stdint.h>
+
+#include <type_traits>
+#include <vector>
+
+#include "net/dcsctp/testing/testing_macros.h"
+#include "rtc_base/gunit.h"
+
+namespace dcsctp {
+namespace {
+
+TEST(AddIncomingStreamsRequestParameterTest, SerializeAndDeserialize) {
+ AddIncomingStreamsRequestParameter parameter(ReconfigRequestSN(1), 2);
+
+ std::vector<uint8_t> serialized;
+ parameter.SerializeTo(serialized);
+
+ ASSERT_HAS_VALUE_AND_ASSIGN(
+ AddIncomingStreamsRequestParameter deserialized,
+ AddIncomingStreamsRequestParameter::Parse(serialized));
+
+ EXPECT_EQ(*deserialized.request_sequence_number(), 1u);
+ EXPECT_EQ(deserialized.nbr_of_new_streams(), 2u);
+}
+
+} // namespace
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.cc
new file mode 100644
index 0000000000..4787ee9718
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.cc
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.h"
+
+#include <stdint.h>
+
+#include <string>
+#include <type_traits>
+#include <vector>
+
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "net/dcsctp/packet/bounded_byte_reader.h"
+#include "net/dcsctp/packet/bounded_byte_writer.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+#include "rtc_base/strings/string_builder.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc6525#section-4.5
+
+// 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 = 17 | Parameter Length = 12 |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | Re-configuration Request Sequence Number |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | Number of new streams | Reserved |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+constexpr int AddOutgoingStreamsRequestParameter::kType;
+
+absl::optional<AddOutgoingStreamsRequestParameter>
+AddOutgoingStreamsRequestParameter::Parse(rtc::ArrayView<const uint8_t> data) {
+ absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
+ if (!reader.has_value()) {
+ return absl::nullopt;
+ }
+ ReconfigRequestSN request_sequence_number(reader->Load32<4>());
+ uint16_t nbr_of_new_streams = reader->Load16<8>();
+
+ return AddOutgoingStreamsRequestParameter(request_sequence_number,
+ nbr_of_new_streams);
+}
+
+void AddOutgoingStreamsRequestParameter::SerializeTo(
+ std::vector<uint8_t>& out) const {
+ BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out);
+ writer.Store32<4>(*request_sequence_number_);
+ writer.Store16<8>(nbr_of_new_streams_);
+}
+
+std::string AddOutgoingStreamsRequestParameter::ToString() const {
+ rtc::StringBuilder sb;
+ sb << "Add Outgoing Streams Request, req_seq_nbr="
+ << *request_sequence_number();
+ return sb.Release();
+}
+
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.h b/third_party/libwebrtc/net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.h
new file mode 100644
index 0000000000..01e8f91cfa
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef NET_DCSCTP_PACKET_PARAMETER_ADD_OUTGOING_STREAMS_REQUEST_PARAMETER_H_
+#define NET_DCSCTP_PACKET_PARAMETER_ADD_OUTGOING_STREAMS_REQUEST_PARAMETER_H_
+#include <stddef.h>
+#include <stdint.h>
+
+#include <string>
+#include <vector>
+
+#include "absl/strings/string_view.h"
+#include "api/array_view.h"
+#include "net/dcsctp/common/internal_types.h"
+#include "net/dcsctp/packet/parameter/parameter.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc6525#section-4.5
+struct AddOutgoingStreamsRequestParameterConfig : ParameterConfig {
+ static constexpr int kType = 17;
+ static constexpr size_t kHeaderSize = 12;
+ static constexpr size_t kVariableLengthAlignment = 0;
+};
+
+class AddOutgoingStreamsRequestParameter
+ : public Parameter,
+ public TLVTrait<AddOutgoingStreamsRequestParameterConfig> {
+ public:
+ static constexpr int kType = AddOutgoingStreamsRequestParameterConfig::kType;
+
+ explicit AddOutgoingStreamsRequestParameter(
+ ReconfigRequestSN request_sequence_number,
+ uint16_t nbr_of_new_streams)
+ : request_sequence_number_(request_sequence_number),
+ nbr_of_new_streams_(nbr_of_new_streams) {}
+
+ static absl::optional<AddOutgoingStreamsRequestParameter> Parse(
+ rtc::ArrayView<const uint8_t> data);
+
+ void SerializeTo(std::vector<uint8_t>& out) const override;
+ std::string ToString() const override;
+
+ ReconfigRequestSN request_sequence_number() const {
+ return request_sequence_number_;
+ }
+ uint16_t nbr_of_new_streams() const { return nbr_of_new_streams_; }
+
+ private:
+ ReconfigRequestSN request_sequence_number_;
+ uint16_t nbr_of_new_streams_;
+};
+
+} // namespace dcsctp
+
+#endif // NET_DCSCTP_PACKET_PARAMETER_ADD_OUTGOING_STREAMS_REQUEST_PARAMETER_H_
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter_test.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter_test.cc
new file mode 100644
index 0000000000..d0303b1ba8
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter_test.cc
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.h"
+
+#include <stdint.h>
+
+#include <type_traits>
+#include <vector>
+
+#include "net/dcsctp/testing/testing_macros.h"
+#include "rtc_base/gunit.h"
+
+namespace dcsctp {
+namespace {
+
+TEST(AddOutgoingStreamsRequestParameterTest, SerializeAndDeserialize) {
+ AddOutgoingStreamsRequestParameter parameter(ReconfigRequestSN(1), 2);
+
+ std::vector<uint8_t> serialized;
+ parameter.SerializeTo(serialized);
+
+ ASSERT_HAS_VALUE_AND_ASSIGN(
+ AddOutgoingStreamsRequestParameter deserialized,
+ AddOutgoingStreamsRequestParameter::Parse(serialized));
+
+ EXPECT_EQ(*deserialized.request_sequence_number(), 1u);
+ EXPECT_EQ(deserialized.nbr_of_new_streams(), 2u);
+}
+
+} // namespace
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/forward_tsn_supported_parameter.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/forward_tsn_supported_parameter.cc
new file mode 100644
index 0000000000..7dd8e1923f
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/forward_tsn_supported_parameter.cc
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/forward_tsn_supported_parameter.h"
+
+#include <stdint.h>
+
+#include <vector>
+
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc3758#section-3.1
+
+// 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 = 49152 | Parameter Length = 4 |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+constexpr int ForwardTsnSupportedParameter::kType;
+
+absl::optional<ForwardTsnSupportedParameter>
+ForwardTsnSupportedParameter::Parse(rtc::ArrayView<const uint8_t> data) {
+ if (!ParseTLV(data).has_value()) {
+ return absl::nullopt;
+ }
+ return ForwardTsnSupportedParameter();
+}
+
+void ForwardTsnSupportedParameter::SerializeTo(
+ std::vector<uint8_t>& out) const {
+ AllocateTLV(out);
+}
+
+std::string ForwardTsnSupportedParameter::ToString() const {
+ return "Forward TSN Supported";
+}
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/forward_tsn_supported_parameter.h b/third_party/libwebrtc/net/dcsctp/packet/parameter/forward_tsn_supported_parameter.h
new file mode 100644
index 0000000000..d4cff4ac21
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/forward_tsn_supported_parameter.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef NET_DCSCTP_PACKET_PARAMETER_FORWARD_TSN_SUPPORTED_PARAMETER_H_
+#define NET_DCSCTP_PACKET_PARAMETER_FORWARD_TSN_SUPPORTED_PARAMETER_H_
+#include <stddef.h>
+#include <stdint.h>
+
+#include <string>
+#include <vector>
+
+#include "absl/strings/string_view.h"
+#include "api/array_view.h"
+#include "net/dcsctp/packet/parameter/parameter.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc3758#section-3.1
+struct ForwardTsnSupportedParameterConfig : ParameterConfig {
+ static constexpr int kType = 49152;
+ static constexpr size_t kHeaderSize = 4;
+ static constexpr size_t kVariableLengthAlignment = 0;
+};
+
+class ForwardTsnSupportedParameter
+ : public Parameter,
+ public TLVTrait<ForwardTsnSupportedParameterConfig> {
+ public:
+ static constexpr int kType = ForwardTsnSupportedParameterConfig::kType;
+
+ ForwardTsnSupportedParameter() {}
+
+ static absl::optional<ForwardTsnSupportedParameter> Parse(
+ rtc::ArrayView<const uint8_t> data);
+
+ void SerializeTo(std::vector<uint8_t>& out) const override;
+ std::string ToString() const override;
+};
+
+} // namespace dcsctp
+
+#endif // NET_DCSCTP_PACKET_PARAMETER_FORWARD_TSN_SUPPORTED_PARAMETER_H_
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/forward_tsn_supported_parameter_test.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/forward_tsn_supported_parameter_test.cc
new file mode 100644
index 0000000000..fb4f983fae
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/forward_tsn_supported_parameter_test.cc
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/forward_tsn_supported_parameter.h"
+
+#include <stdint.h>
+
+#include <type_traits>
+#include <vector>
+
+#include "net/dcsctp/testing/testing_macros.h"
+#include "rtc_base/gunit.h"
+
+namespace dcsctp {
+namespace {
+
+TEST(ForwardTsnSupportedParameterTest, SerializeAndDeserialize) {
+ ForwardTsnSupportedParameter parameter;
+
+ std::vector<uint8_t> serialized;
+ parameter.SerializeTo(serialized);
+
+ ASSERT_HAS_VALUE_AND_ASSIGN(ForwardTsnSupportedParameter deserialized,
+ ForwardTsnSupportedParameter::Parse(serialized));
+}
+
+} // namespace
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/heartbeat_info_parameter.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/heartbeat_info_parameter.cc
new file mode 100644
index 0000000000..918976d305
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/heartbeat_info_parameter.cc
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/heartbeat_info_parameter.h"
+
+#include <stdint.h>
+
+#include <string>
+#include <type_traits>
+#include <vector>
+
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "net/dcsctp/packet/bounded_byte_reader.h"
+#include "net/dcsctp/packet/bounded_byte_writer.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+#include "rtc_base/strings/string_builder.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc4960#section-3.3.5
+
+// 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
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | Type = 4 | Chunk Flags | Heartbeat Length |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// \ \
+// / Heartbeat Information TLV (Variable-Length) /
+// \ \
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+constexpr int HeartbeatInfoParameter::kType;
+
+absl::optional<HeartbeatInfoParameter> HeartbeatInfoParameter::Parse(
+ rtc::ArrayView<const uint8_t> data) {
+ absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
+ if (!reader.has_value()) {
+ return absl::nullopt;
+ }
+ return HeartbeatInfoParameter(reader->variable_data());
+}
+
+void HeartbeatInfoParameter::SerializeTo(std::vector<uint8_t>& out) const {
+ BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out, info_.size());
+ writer.CopyToVariableData(info_);
+}
+
+std::string HeartbeatInfoParameter::ToString() const {
+ rtc::StringBuilder sb;
+ sb << "Heartbeat Info parameter (info_length=" << info_.size() << ")";
+ return sb.Release();
+}
+
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/heartbeat_info_parameter.h b/third_party/libwebrtc/net/dcsctp/packet/parameter/heartbeat_info_parameter.h
new file mode 100644
index 0000000000..ec503a94b2
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/heartbeat_info_parameter.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef NET_DCSCTP_PACKET_PARAMETER_HEARTBEAT_INFO_PARAMETER_H_
+#define NET_DCSCTP_PACKET_PARAMETER_HEARTBEAT_INFO_PARAMETER_H_
+#include <stddef.h>
+
+#include <cstdint>
+#include <string>
+#include <vector>
+
+#include "absl/strings/string_view.h"
+#include "api/array_view.h"
+#include "net/dcsctp/packet/parameter/parameter.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc4960#section-3.3.5
+struct HeartbeatInfoParameterConfig : ParameterConfig {
+ static constexpr int kType = 1;
+ static constexpr size_t kHeaderSize = 4;
+ static constexpr size_t kVariableLengthAlignment = 1;
+};
+
+class HeartbeatInfoParameter : public Parameter,
+ public TLVTrait<HeartbeatInfoParameterConfig> {
+ public:
+ static constexpr int kType = HeartbeatInfoParameterConfig::kType;
+
+ explicit HeartbeatInfoParameter(rtc::ArrayView<const uint8_t> info)
+ : info_(info.begin(), info.end()) {}
+
+ static absl::optional<HeartbeatInfoParameter> Parse(
+ rtc::ArrayView<const uint8_t> data);
+
+ void SerializeTo(std::vector<uint8_t>& out) const override;
+ std::string ToString() const override;
+
+ rtc::ArrayView<const uint8_t> info() const { return info_; }
+
+ private:
+ std::vector<uint8_t> info_;
+};
+
+} // namespace dcsctp
+
+#endif // NET_DCSCTP_PACKET_PARAMETER_HEARTBEAT_INFO_PARAMETER_H_
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.cc
new file mode 100644
index 0000000000..6191adfe9d
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.cc
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.h"
+
+#include <stddef.h>
+
+#include <cstdint>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "net/dcsctp/packet/bounded_byte_reader.h"
+#include "net/dcsctp/packet/bounded_byte_writer.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+#include "rtc_base/strings/string_builder.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc6525#section-4.2
+
+// 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 = 14 | Parameter Length = 8 + 2 * N |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | Re-configuration Request Sequence Number |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | Stream Number 1 (optional) | Stream Number 2 (optional) |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// / ...... /
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | Stream Number N-1 (optional) | Stream Number N (optional) |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+constexpr int IncomingSSNResetRequestParameter::kType;
+
+absl::optional<IncomingSSNResetRequestParameter>
+IncomingSSNResetRequestParameter::Parse(rtc::ArrayView<const uint8_t> data) {
+ absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
+ if (!reader.has_value()) {
+ return absl::nullopt;
+ }
+
+ ReconfigRequestSN request_sequence_number(reader->Load32<4>());
+
+ size_t stream_count = reader->variable_data_size() / kStreamIdSize;
+ std::vector<StreamID> stream_ids;
+ stream_ids.reserve(stream_count);
+ for (size_t i = 0; i < stream_count; ++i) {
+ BoundedByteReader<kStreamIdSize> sub_reader =
+ reader->sub_reader<kStreamIdSize>(i * kStreamIdSize);
+
+ stream_ids.push_back(StreamID(sub_reader.Load16<0>()));
+ }
+
+ return IncomingSSNResetRequestParameter(request_sequence_number,
+ std::move(stream_ids));
+}
+
+void IncomingSSNResetRequestParameter::SerializeTo(
+ std::vector<uint8_t>& out) const {
+ size_t variable_size = stream_ids_.size() * kStreamIdSize;
+ BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out, variable_size);
+
+ writer.Store32<4>(*request_sequence_number_);
+
+ for (size_t i = 0; i < stream_ids_.size(); ++i) {
+ BoundedByteWriter<kStreamIdSize> sub_writer =
+ writer.sub_writer<kStreamIdSize>(i * kStreamIdSize);
+ sub_writer.Store16<0>(*stream_ids_[i]);
+ }
+}
+
+std::string IncomingSSNResetRequestParameter::ToString() const {
+ rtc::StringBuilder sb;
+ sb << "Incoming SSN Reset Request, req_seq_nbr="
+ << *request_sequence_number();
+ return sb.Release();
+}
+
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.h b/third_party/libwebrtc/net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.h
new file mode 100644
index 0000000000..18963efafc
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef NET_DCSCTP_PACKET_PARAMETER_INCOMING_SSN_RESET_REQUEST_PARAMETER_H_
+#define NET_DCSCTP_PACKET_PARAMETER_INCOMING_SSN_RESET_REQUEST_PARAMETER_H_
+#include <stddef.h>
+
+#include <cstdint>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "absl/strings/string_view.h"
+#include "api/array_view.h"
+#include "net/dcsctp/common/internal_types.h"
+#include "net/dcsctp/packet/parameter/parameter.h"
+#include "net/dcsctp/public/types.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc6525#section-4.2
+struct IncomingSSNResetRequestParameterConfig : ParameterConfig {
+ static constexpr int kType = 14;
+ static constexpr size_t kHeaderSize = 8;
+ static constexpr size_t kVariableLengthAlignment = 2;
+};
+
+class IncomingSSNResetRequestParameter
+ : public Parameter,
+ public TLVTrait<IncomingSSNResetRequestParameterConfig> {
+ public:
+ static constexpr int kType = IncomingSSNResetRequestParameterConfig::kType;
+
+ explicit IncomingSSNResetRequestParameter(
+ ReconfigRequestSN request_sequence_number,
+ std::vector<StreamID> stream_ids)
+ : request_sequence_number_(request_sequence_number),
+ stream_ids_(std::move(stream_ids)) {}
+
+ static absl::optional<IncomingSSNResetRequestParameter> Parse(
+ rtc::ArrayView<const uint8_t> data);
+
+ void SerializeTo(std::vector<uint8_t>& out) const override;
+ std::string ToString() const override;
+
+ ReconfigRequestSN request_sequence_number() const {
+ return request_sequence_number_;
+ }
+ rtc::ArrayView<const StreamID> stream_ids() const { return stream_ids_; }
+
+ private:
+ static constexpr size_t kStreamIdSize = sizeof(uint16_t);
+
+ ReconfigRequestSN request_sequence_number_;
+ std::vector<StreamID> stream_ids_;
+};
+
+} // namespace dcsctp
+
+#endif // NET_DCSCTP_PACKET_PARAMETER_INCOMING_SSN_RESET_REQUEST_PARAMETER_H_
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter_test.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter_test.cc
new file mode 100644
index 0000000000..17793f6638
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter_test.cc
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.h"
+
+#include <cstdint>
+#include <type_traits>
+#include <vector>
+
+#include "api/array_view.h"
+#include "net/dcsctp/testing/testing_macros.h"
+#include "rtc_base/gunit.h"
+#include "test/gmock.h"
+
+namespace dcsctp {
+namespace {
+using ::testing::ElementsAre;
+
+TEST(IncomingSSNResetRequestParameterTest, SerializeAndDeserialize) {
+ IncomingSSNResetRequestParameter parameter(
+ ReconfigRequestSN(1), {StreamID(2), StreamID(3), StreamID(4)});
+
+ std::vector<uint8_t> serialized;
+ parameter.SerializeTo(serialized);
+
+ ASSERT_HAS_VALUE_AND_ASSIGN(
+ IncomingSSNResetRequestParameter deserialized,
+ IncomingSSNResetRequestParameter::Parse(serialized));
+
+ EXPECT_EQ(*deserialized.request_sequence_number(), 1u);
+ EXPECT_THAT(deserialized.stream_ids(),
+ ElementsAre(StreamID(2), StreamID(3), StreamID(4)));
+}
+
+} // namespace
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.cc
new file mode 100644
index 0000000000..c25a2426be
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.cc
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h"
+
+#include <stddef.h>
+
+#include <cstdint>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "net/dcsctp/common/internal_types.h"
+#include "net/dcsctp/packet/bounded_byte_reader.h"
+#include "net/dcsctp/packet/bounded_byte_writer.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+#include "net/dcsctp/public/types.h"
+#include "rtc_base/strings/string_builder.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc6525#section-4.1
+
+// 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 = 13 | Parameter Length = 16 + 2 * N |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | Re-configuration Request Sequence Number |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | Re-configuration Response Sequence Number |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | Sender's Last Assigned TSN |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | Stream Number 1 (optional) | Stream Number 2 (optional) |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// / ...... /
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | Stream Number N-1 (optional) | Stream Number N (optional) |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+constexpr int OutgoingSSNResetRequestParameter::kType;
+
+absl::optional<OutgoingSSNResetRequestParameter>
+OutgoingSSNResetRequestParameter::Parse(rtc::ArrayView<const uint8_t> data) {
+ absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
+ if (!reader.has_value()) {
+ return absl::nullopt;
+ }
+
+ ReconfigRequestSN request_sequence_number(reader->Load32<4>());
+ ReconfigRequestSN response_sequence_number(reader->Load32<8>());
+ TSN sender_last_assigned_tsn(reader->Load32<12>());
+
+ size_t stream_count = reader->variable_data_size() / kStreamIdSize;
+ std::vector<StreamID> stream_ids;
+ stream_ids.reserve(stream_count);
+ for (size_t i = 0; i < stream_count; ++i) {
+ BoundedByteReader<kStreamIdSize> sub_reader =
+ reader->sub_reader<kStreamIdSize>(i * kStreamIdSize);
+
+ stream_ids.push_back(StreamID(sub_reader.Load16<0>()));
+ }
+
+ return OutgoingSSNResetRequestParameter(
+ request_sequence_number, response_sequence_number,
+ sender_last_assigned_tsn, std::move(stream_ids));
+}
+
+void OutgoingSSNResetRequestParameter::SerializeTo(
+ std::vector<uint8_t>& out) const {
+ size_t variable_size = stream_ids_.size() * kStreamIdSize;
+ BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out, variable_size);
+
+ writer.Store32<4>(*request_sequence_number_);
+ writer.Store32<8>(*response_sequence_number_);
+ writer.Store32<12>(*sender_last_assigned_tsn_);
+
+ for (size_t i = 0; i < stream_ids_.size(); ++i) {
+ BoundedByteWriter<kStreamIdSize> sub_writer =
+ writer.sub_writer<kStreamIdSize>(i * kStreamIdSize);
+ sub_writer.Store16<0>(*stream_ids_[i]);
+ }
+}
+
+std::string OutgoingSSNResetRequestParameter::ToString() const {
+ rtc::StringBuilder sb;
+ sb << "Outgoing SSN Reset Request, req_seq_nbr=" << *request_sequence_number()
+ << ", resp_seq_nbr=" << *response_sequence_number()
+ << ", sender_last_asg_tsn=" << *sender_last_assigned_tsn();
+ return sb.Release();
+}
+
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h b/third_party/libwebrtc/net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h
new file mode 100644
index 0000000000..6eb44e079f
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef NET_DCSCTP_PACKET_PARAMETER_OUTGOING_SSN_RESET_REQUEST_PARAMETER_H_
+#define NET_DCSCTP_PACKET_PARAMETER_OUTGOING_SSN_RESET_REQUEST_PARAMETER_H_
+#include <stddef.h>
+#include <stdint.h>
+
+#include <cstdint>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "absl/strings/string_view.h"
+#include "api/array_view.h"
+#include "net/dcsctp/common/internal_types.h"
+#include "net/dcsctp/packet/parameter/parameter.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+#include "net/dcsctp/public/types.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc6525#section-4.1
+struct OutgoingSSNResetRequestParameterConfig : ParameterConfig {
+ static constexpr int kType = 13;
+ static constexpr size_t kHeaderSize = 16;
+ static constexpr size_t kVariableLengthAlignment = 2;
+};
+
+class OutgoingSSNResetRequestParameter
+ : public Parameter,
+ public TLVTrait<OutgoingSSNResetRequestParameterConfig> {
+ public:
+ static constexpr int kType = OutgoingSSNResetRequestParameterConfig::kType;
+
+ explicit OutgoingSSNResetRequestParameter(
+ ReconfigRequestSN request_sequence_number,
+ ReconfigRequestSN response_sequence_number,
+ TSN sender_last_assigned_tsn,
+ std::vector<StreamID> stream_ids)
+ : request_sequence_number_(request_sequence_number),
+ response_sequence_number_(response_sequence_number),
+ sender_last_assigned_tsn_(sender_last_assigned_tsn),
+ stream_ids_(std::move(stream_ids)) {}
+
+ static absl::optional<OutgoingSSNResetRequestParameter> Parse(
+ rtc::ArrayView<const uint8_t> data);
+
+ void SerializeTo(std::vector<uint8_t>& out) const override;
+ std::string ToString() const override;
+
+ ReconfigRequestSN request_sequence_number() const {
+ return request_sequence_number_;
+ }
+ ReconfigRequestSN response_sequence_number() const {
+ return response_sequence_number_;
+ }
+ TSN sender_last_assigned_tsn() const { return sender_last_assigned_tsn_; }
+ rtc::ArrayView<const StreamID> stream_ids() const { return stream_ids_; }
+
+ private:
+ static constexpr size_t kStreamIdSize = sizeof(uint16_t);
+
+ ReconfigRequestSN request_sequence_number_;
+ ReconfigRequestSN response_sequence_number_;
+ TSN sender_last_assigned_tsn_;
+ std::vector<StreamID> stream_ids_;
+};
+
+} // namespace dcsctp
+
+#endif // NET_DCSCTP_PACKET_PARAMETER_OUTGOING_SSN_RESET_REQUEST_PARAMETER_H_
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter_test.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter_test.cc
new file mode 100644
index 0000000000..dae73c2fba
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter_test.cc
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h"
+
+#include <cstdint>
+#include <type_traits>
+#include <vector>
+
+#include "api/array_view.h"
+#include "net/dcsctp/common/internal_types.h"
+#include "net/dcsctp/public/types.h"
+#include "net/dcsctp/testing/testing_macros.h"
+#include "rtc_base/gunit.h"
+#include "test/gmock.h"
+
+namespace dcsctp {
+namespace {
+using ::testing::ElementsAre;
+
+TEST(OutgoingSSNResetRequestParameterTest, SerializeAndDeserialize) {
+ OutgoingSSNResetRequestParameter parameter(
+ ReconfigRequestSN(1), ReconfigRequestSN(2), TSN(3),
+ {StreamID(4), StreamID(5), StreamID(6)});
+
+ std::vector<uint8_t> serialized;
+ parameter.SerializeTo(serialized);
+
+ ASSERT_HAS_VALUE_AND_ASSIGN(
+ OutgoingSSNResetRequestParameter deserialized,
+ OutgoingSSNResetRequestParameter::Parse(serialized));
+
+ EXPECT_EQ(*deserialized.request_sequence_number(), 1u);
+ EXPECT_EQ(*deserialized.response_sequence_number(), 2u);
+ EXPECT_EQ(*deserialized.sender_last_assigned_tsn(), 3u);
+ EXPECT_THAT(deserialized.stream_ids(),
+ ElementsAre(StreamID(4), StreamID(5), StreamID(6)));
+}
+
+} // namespace
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/parameter.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/parameter.cc
new file mode 100644
index 0000000000..b3b2bffef7
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/parameter.cc
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/parameter.h"
+
+#include <stddef.h>
+
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "absl/memory/memory.h"
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "net/dcsctp/common/math.h"
+#include "net/dcsctp/packet/bounded_byte_reader.h"
+#include "net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.h"
+#include "net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.h"
+#include "net/dcsctp/packet/parameter/forward_tsn_supported_parameter.h"
+#include "net/dcsctp/packet/parameter/heartbeat_info_parameter.h"
+#include "net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.h"
+#include "net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h"
+#include "net/dcsctp/packet/parameter/reconfiguration_response_parameter.h"
+#include "net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter.h"
+#include "net/dcsctp/packet/parameter/state_cookie_parameter.h"
+#include "net/dcsctp/packet/parameter/supported_extensions_parameter.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+#include "rtc_base/logging.h"
+#include "rtc_base/strings/string_builder.h"
+
+namespace dcsctp {
+
+constexpr size_t kParameterHeaderSize = 4;
+
+Parameters::Builder& Parameters::Builder::Add(const Parameter& p) {
+ // https://tools.ietf.org/html/rfc4960#section-3.2.1
+ // "If the length of the parameter is not a multiple of 4 bytes, the sender
+ // pads the parameter at the end (i.e., after the Parameter Value field) with
+ // all zero bytes."
+ if (data_.size() % 4 != 0) {
+ data_.resize(RoundUpTo4(data_.size()));
+ }
+
+ p.SerializeTo(data_);
+ return *this;
+}
+
+std::vector<ParameterDescriptor> Parameters::descriptors() const {
+ rtc::ArrayView<const uint8_t> span(data_);
+ std::vector<ParameterDescriptor> result;
+ while (!span.empty()) {
+ BoundedByteReader<kParameterHeaderSize> header(span);
+ uint16_t type = header.Load16<0>();
+ uint16_t length = header.Load16<2>();
+ result.emplace_back(type, span.subview(0, length));
+ size_t length_with_padding = RoundUpTo4(length);
+ if (length_with_padding > span.size()) {
+ break;
+ }
+ span = span.subview(length_with_padding);
+ }
+ return result;
+}
+
+absl::optional<Parameters> Parameters::Parse(
+ rtc::ArrayView<const uint8_t> data) {
+ // Validate the parameter descriptors
+ rtc::ArrayView<const uint8_t> span(data);
+ while (!span.empty()) {
+ if (span.size() < kParameterHeaderSize) {
+ RTC_DLOG(LS_WARNING) << "Insufficient parameter length";
+ return absl::nullopt;
+ }
+ BoundedByteReader<kParameterHeaderSize> header(span);
+ uint16_t length = header.Load16<2>();
+ if (length < kParameterHeaderSize || length > span.size()) {
+ RTC_DLOG(LS_WARNING) << "Invalid parameter length field";
+ return absl::nullopt;
+ }
+ size_t length_with_padding = RoundUpTo4(length);
+ if (length_with_padding > span.size()) {
+ break;
+ }
+ span = span.subview(length_with_padding);
+ }
+ return Parameters(std::vector<uint8_t>(data.begin(), data.end()));
+}
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/parameter.h b/third_party/libwebrtc/net/dcsctp/packet/parameter/parameter.h
new file mode 100644
index 0000000000..e8fa67c8f7
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/parameter.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef NET_DCSCTP_PACKET_PARAMETER_PARAMETER_H_
+#define NET_DCSCTP_PACKET_PARAMETER_PARAMETER_H_
+
+#include <stddef.h>
+
+#include <algorithm>
+#include <cstdint>
+#include <iterator>
+#include <memory>
+#include <string>
+#include <type_traits>
+#include <utility>
+#include <vector>
+
+#include "absl/algorithm/container.h"
+#include "absl/strings/string_view.h"
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+#include "rtc_base/strings/string_builder.h"
+
+namespace dcsctp {
+
+class Parameter {
+ public:
+ Parameter() {}
+ virtual ~Parameter() = default;
+
+ Parameter(const Parameter& other) = default;
+ Parameter& operator=(const Parameter& other) = default;
+
+ virtual void SerializeTo(std::vector<uint8_t>& out) const = 0;
+ virtual std::string ToString() const = 0;
+};
+
+struct ParameterDescriptor {
+ ParameterDescriptor(uint16_t type, rtc::ArrayView<const uint8_t> data)
+ : type(type), data(data) {}
+ uint16_t type;
+ rtc::ArrayView<const uint8_t> data;
+};
+
+class Parameters {
+ public:
+ class Builder {
+ public:
+ Builder() {}
+ Builder& Add(const Parameter& p);
+ Parameters Build() { return Parameters(std::move(data_)); }
+
+ private:
+ std::vector<uint8_t> data_;
+ };
+
+ static absl::optional<Parameters> Parse(rtc::ArrayView<const uint8_t> data);
+
+ Parameters() {}
+ Parameters(Parameters&& other) = default;
+ Parameters& operator=(Parameters&& other) = default;
+
+ rtc::ArrayView<const uint8_t> data() const { return data_; }
+ std::vector<ParameterDescriptor> descriptors() const;
+
+ template <typename P>
+ absl::optional<P> get() const {
+ static_assert(std::is_base_of<Parameter, P>::value,
+ "Template parameter not derived from Parameter");
+ for (const auto& p : descriptors()) {
+ if (p.type == P::kType) {
+ return P::Parse(p.data);
+ }
+ }
+ return absl::nullopt;
+ }
+
+ private:
+ explicit Parameters(std::vector<uint8_t> data) : data_(std::move(data)) {}
+ std::vector<uint8_t> data_;
+};
+
+struct ParameterConfig {
+ static constexpr int kTypeSizeInBytes = 2;
+};
+
+} // namespace dcsctp
+
+#endif // NET_DCSCTP_PACKET_PARAMETER_PARAMETER_H_
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/parameter_test.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/parameter_test.cc
new file mode 100644
index 0000000000..467e324592
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/parameter_test.cc
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/parameter.h"
+
+#include <cstdint>
+#include <type_traits>
+#include <vector>
+
+#include "api/array_view.h"
+#include "net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+#include "net/dcsctp/testing/testing_macros.h"
+#include "rtc_base/gunit.h"
+#include "test/gmock.h"
+
+namespace dcsctp {
+namespace {
+using ::testing::ElementsAre;
+using ::testing::SizeIs;
+
+TEST(ParameterTest, SerializeDeserializeParameter) {
+ Parameters parameters =
+ Parameters::Builder()
+ .Add(OutgoingSSNResetRequestParameter(ReconfigRequestSN(123),
+ ReconfigRequestSN(456),
+ TSN(789), {StreamID(42)}))
+ .Build();
+
+ rtc::ArrayView<const uint8_t> serialized = parameters.data();
+
+ ASSERT_HAS_VALUE_AND_ASSIGN(Parameters parsed, Parameters::Parse(serialized));
+ auto descriptors = parsed.descriptors();
+ ASSERT_THAT(descriptors, SizeIs(1));
+ EXPECT_THAT(descriptors[0].type, OutgoingSSNResetRequestParameter::kType);
+
+ ASSERT_HAS_VALUE_AND_ASSIGN(
+ OutgoingSSNResetRequestParameter parsed_param,
+ OutgoingSSNResetRequestParameter::Parse(descriptors[0].data));
+ EXPECT_EQ(*parsed_param.request_sequence_number(), 123u);
+ EXPECT_EQ(*parsed_param.response_sequence_number(), 456u);
+ EXPECT_EQ(*parsed_param.sender_last_assigned_tsn(), 789u);
+ EXPECT_THAT(parsed_param.stream_ids(), ElementsAre(StreamID(42)));
+}
+
+} // namespace
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/reconfiguration_response_parameter.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/reconfiguration_response_parameter.cc
new file mode 100644
index 0000000000..fafb204acc
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/reconfiguration_response_parameter.cc
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/reconfiguration_response_parameter.h"
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <string>
+#include <type_traits>
+#include <vector>
+
+#include "absl/strings/string_view.h"
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "net/dcsctp/packet/bounded_byte_reader.h"
+#include "net/dcsctp/packet/bounded_byte_writer.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+#include "rtc_base/logging.h"
+#include "rtc_base/strings/string_builder.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc6525#section-4.4
+
+// 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) |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+constexpr int ReconfigurationResponseParameter::kType;
+
+absl::string_view ToString(ReconfigurationResponseParameter::Result result) {
+ switch (result) {
+ case ReconfigurationResponseParameter::Result::kSuccessNothingToDo:
+ return "Success: nothing to do";
+ case ReconfigurationResponseParameter::Result::kSuccessPerformed:
+ return "Success: performed";
+ case ReconfigurationResponseParameter::Result::kDenied:
+ return "Denied";
+ case ReconfigurationResponseParameter::Result::kErrorWrongSSN:
+ return "Error: wrong ssn";
+ case ReconfigurationResponseParameter::Result::
+ kErrorRequestAlreadyInProgress:
+ return "Error: request already in progress";
+ case ReconfigurationResponseParameter::Result::kErrorBadSequenceNumber:
+ return "Error: bad sequence number";
+ case ReconfigurationResponseParameter::Result::kInProgress:
+ return "In progress";
+ }
+}
+
+absl::optional<ReconfigurationResponseParameter>
+ReconfigurationResponseParameter::Parse(rtc::ArrayView<const uint8_t> data) {
+ absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
+ if (!reader.has_value()) {
+ return absl::nullopt;
+ }
+
+ ReconfigRequestSN response_sequence_number(reader->Load32<4>());
+ Result result;
+ uint32_t result_nbr = reader->Load32<8>();
+ switch (result_nbr) {
+ case 0:
+ result = ReconfigurationResponseParameter::Result::kSuccessNothingToDo;
+ break;
+ case 1:
+ result = ReconfigurationResponseParameter::Result::kSuccessPerformed;
+ break;
+ case 2:
+ result = ReconfigurationResponseParameter::Result::kDenied;
+ break;
+ case 3:
+ result = ReconfigurationResponseParameter::Result::kErrorWrongSSN;
+ break;
+ case 4:
+ result = ReconfigurationResponseParameter::Result::
+ kErrorRequestAlreadyInProgress;
+ break;
+ case 5:
+ result =
+ ReconfigurationResponseParameter::Result::kErrorBadSequenceNumber;
+ break;
+ case 6:
+ result = ReconfigurationResponseParameter::Result::kInProgress;
+ break;
+ default:
+ RTC_DLOG(LS_WARNING) << "Invalid reconfig response result: "
+ << result_nbr;
+ return absl::nullopt;
+ }
+
+ if (reader->variable_data().empty()) {
+ return ReconfigurationResponseParameter(response_sequence_number, result);
+ } else if (reader->variable_data_size() != kNextTsnHeaderSize) {
+ RTC_DLOG(LS_WARNING) << "Invalid parameter size";
+ return absl::nullopt;
+ }
+
+ BoundedByteReader<kNextTsnHeaderSize> sub_reader =
+ reader->sub_reader<kNextTsnHeaderSize>(0);
+
+ TSN sender_next_tsn(sub_reader.Load32<0>());
+ TSN receiver_next_tsn(sub_reader.Load32<4>());
+
+ return ReconfigurationResponseParameter(response_sequence_number, result,
+ sender_next_tsn, receiver_next_tsn);
+}
+
+void ReconfigurationResponseParameter::SerializeTo(
+ std::vector<uint8_t>& out) const {
+ size_t variable_size =
+ (sender_next_tsn().has_value() ? kNextTsnHeaderSize : 0);
+ BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out, variable_size);
+
+ writer.Store32<4>(*response_sequence_number_);
+ uint32_t result_nbr =
+ static_cast<std::underlying_type<Result>::type>(result_);
+ writer.Store32<8>(result_nbr);
+
+ if (sender_next_tsn().has_value()) {
+ BoundedByteWriter<kNextTsnHeaderSize> sub_writer =
+ writer.sub_writer<kNextTsnHeaderSize>(0);
+
+ sub_writer.Store32<0>(sender_next_tsn_.has_value() ? **sender_next_tsn_
+ : 0);
+ sub_writer.Store32<4>(receiver_next_tsn_.has_value() ? **receiver_next_tsn_
+ : 0);
+ }
+}
+
+std::string ReconfigurationResponseParameter::ToString() const {
+ rtc::StringBuilder sb;
+ sb << "Re-configuration Response, resp_seq_nbr="
+ << *response_sequence_number();
+ return sb.Release();
+}
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/reconfiguration_response_parameter.h b/third_party/libwebrtc/net/dcsctp/packet/parameter/reconfiguration_response_parameter.h
new file mode 100644
index 0000000000..c5a68acb33
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/reconfiguration_response_parameter.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef NET_DCSCTP_PACKET_PARAMETER_RECONFIGURATION_RESPONSE_PARAMETER_H_
+#define NET_DCSCTP_PACKET_PARAMETER_RECONFIGURATION_RESPONSE_PARAMETER_H_
+#include <stddef.h>
+
+#include <cstdint>
+#include <string>
+#include <vector>
+
+#include "absl/strings/string_view.h"
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "net/dcsctp/common/internal_types.h"
+#include "net/dcsctp/packet/parameter/parameter.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc6525#section-4.4
+struct ReconfigurationResponseParameterConfig : ParameterConfig {
+ static constexpr int kType = 16;
+ static constexpr size_t kHeaderSize = 12;
+ static constexpr size_t kVariableLengthAlignment = 4;
+};
+
+class ReconfigurationResponseParameter
+ : public Parameter,
+ public TLVTrait<ReconfigurationResponseParameterConfig> {
+ public:
+ static constexpr int kType = ReconfigurationResponseParameterConfig::kType;
+
+ enum class Result {
+ kSuccessNothingToDo = 0,
+ kSuccessPerformed = 1,
+ kDenied = 2,
+ kErrorWrongSSN = 3,
+ kErrorRequestAlreadyInProgress = 4,
+ kErrorBadSequenceNumber = 5,
+ kInProgress = 6,
+ };
+
+ ReconfigurationResponseParameter(ReconfigRequestSN response_sequence_number,
+ Result result)
+ : response_sequence_number_(response_sequence_number),
+ result_(result),
+ sender_next_tsn_(absl::nullopt),
+ receiver_next_tsn_(absl::nullopt) {}
+
+ explicit ReconfigurationResponseParameter(
+ ReconfigRequestSN response_sequence_number,
+ Result result,
+ TSN sender_next_tsn,
+ TSN receiver_next_tsn)
+ : response_sequence_number_(response_sequence_number),
+ result_(result),
+ sender_next_tsn_(sender_next_tsn),
+ receiver_next_tsn_(receiver_next_tsn) {}
+
+ static absl::optional<ReconfigurationResponseParameter> Parse(
+ rtc::ArrayView<const uint8_t> data);
+
+ void SerializeTo(std::vector<uint8_t>& out) const override;
+ std::string ToString() const override;
+
+ ReconfigRequestSN response_sequence_number() const {
+ return response_sequence_number_;
+ }
+ Result result() const { return result_; }
+ absl::optional<TSN> sender_next_tsn() const { return sender_next_tsn_; }
+ absl::optional<TSN> receiver_next_tsn() const { return receiver_next_tsn_; }
+
+ private:
+ static constexpr size_t kNextTsnHeaderSize = 8;
+ ReconfigRequestSN response_sequence_number_;
+ Result result_;
+ absl::optional<TSN> sender_next_tsn_;
+ absl::optional<TSN> receiver_next_tsn_;
+};
+
+absl::string_view ToString(ReconfigurationResponseParameter::Result result);
+
+} // namespace dcsctp
+
+#endif // NET_DCSCTP_PACKET_PARAMETER_RECONFIGURATION_RESPONSE_PARAMETER_H_
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/reconfiguration_response_parameter_test.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/reconfiguration_response_parameter_test.cc
new file mode 100644
index 0000000000..8125d93cd0
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/reconfiguration_response_parameter_test.cc
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/reconfiguration_response_parameter.h"
+
+#include <stdint.h>
+
+#include <type_traits>
+#include <vector>
+
+#include "absl/types/optional.h"
+#include "net/dcsctp/testing/testing_macros.h"
+#include "rtc_base/gunit.h"
+#include "test/gmock.h"
+
+namespace dcsctp {
+namespace {
+
+TEST(ReconfigurationResponseParameterTest, SerializeAndDeserializeFirstForm) {
+ ReconfigurationResponseParameter parameter(
+ ReconfigRequestSN(1),
+ ReconfigurationResponseParameter::Result::kSuccessPerformed);
+
+ std::vector<uint8_t> serialized;
+ parameter.SerializeTo(serialized);
+
+ ASSERT_HAS_VALUE_AND_ASSIGN(
+ ReconfigurationResponseParameter deserialized,
+ ReconfigurationResponseParameter::Parse(serialized));
+
+ EXPECT_EQ(*deserialized.response_sequence_number(), 1u);
+ EXPECT_EQ(deserialized.result(),
+ ReconfigurationResponseParameter::Result::kSuccessPerformed);
+ EXPECT_EQ(deserialized.sender_next_tsn(), absl::nullopt);
+ EXPECT_EQ(deserialized.receiver_next_tsn(), absl::nullopt);
+}
+
+TEST(ReconfigurationResponseParameterTest,
+ SerializeAndDeserializeFirstFormSecondForm) {
+ ReconfigurationResponseParameter parameter(
+ ReconfigRequestSN(1),
+ ReconfigurationResponseParameter::Result::kSuccessPerformed, TSN(2),
+ TSN(3));
+
+ std::vector<uint8_t> serialized;
+ parameter.SerializeTo(serialized);
+
+ ASSERT_HAS_VALUE_AND_ASSIGN(
+ ReconfigurationResponseParameter deserialized,
+ ReconfigurationResponseParameter::Parse(serialized));
+
+ EXPECT_EQ(*deserialized.response_sequence_number(), 1u);
+ EXPECT_EQ(deserialized.result(),
+ ReconfigurationResponseParameter::Result::kSuccessPerformed);
+ EXPECT_TRUE(deserialized.sender_next_tsn().has_value());
+ EXPECT_EQ(**deserialized.sender_next_tsn(), 2u);
+ EXPECT_TRUE(deserialized.receiver_next_tsn().has_value());
+ EXPECT_EQ(**deserialized.receiver_next_tsn(), 3u);
+}
+
+} // namespace
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter.cc
new file mode 100644
index 0000000000..d656e0db8f
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter.cc
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter.h"
+
+#include <stdint.h>
+
+#include <string>
+#include <type_traits>
+#include <vector>
+
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "net/dcsctp/packet/bounded_byte_reader.h"
+#include "net/dcsctp/packet/bounded_byte_writer.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+#include "rtc_base/strings/string_builder.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc6525#section-4.3
+
+// 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 = 15 | Parameter Length = 8 |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | Re-configuration Request Sequence Number |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+constexpr int SSNTSNResetRequestParameter::kType;
+
+absl::optional<SSNTSNResetRequestParameter> SSNTSNResetRequestParameter::Parse(
+ rtc::ArrayView<const uint8_t> data) {
+ absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
+ if (!reader.has_value()) {
+ return absl::nullopt;
+ }
+ ReconfigRequestSN request_sequence_number(reader->Load32<4>());
+
+ return SSNTSNResetRequestParameter(request_sequence_number);
+}
+
+void SSNTSNResetRequestParameter::SerializeTo(std::vector<uint8_t>& out) const {
+ BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out);
+ writer.Store32<4>(*request_sequence_number_);
+}
+
+std::string SSNTSNResetRequestParameter::ToString() const {
+ rtc::StringBuilder sb;
+ sb << "SSN/TSN Reset Request, req_seq_nbr=" << *request_sequence_number();
+ return sb.Release();
+}
+
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter.h b/third_party/libwebrtc/net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter.h
new file mode 100644
index 0000000000..e31d7ebe8f
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef NET_DCSCTP_PACKET_PARAMETER_SSN_TSN_RESET_REQUEST_PARAMETER_H_
+#define NET_DCSCTP_PACKET_PARAMETER_SSN_TSN_RESET_REQUEST_PARAMETER_H_
+#include <stddef.h>
+#include <stdint.h>
+
+#include <string>
+#include <vector>
+
+#include "absl/strings/string_view.h"
+#include "api/array_view.h"
+#include "net/dcsctp/common/internal_types.h"
+#include "net/dcsctp/packet/parameter/parameter.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc6525#section-4.3
+struct SSNTSNResetRequestParameterConfig : ParameterConfig {
+ static constexpr int kType = 15;
+ static constexpr size_t kHeaderSize = 8;
+ static constexpr size_t kVariableLengthAlignment = 0;
+};
+
+class SSNTSNResetRequestParameter
+ : public Parameter,
+ public TLVTrait<SSNTSNResetRequestParameterConfig> {
+ public:
+ static constexpr int kType = SSNTSNResetRequestParameterConfig::kType;
+
+ explicit SSNTSNResetRequestParameter(
+ ReconfigRequestSN request_sequence_number)
+ : request_sequence_number_(request_sequence_number) {}
+
+ static absl::optional<SSNTSNResetRequestParameter> Parse(
+ rtc::ArrayView<const uint8_t> data);
+
+ void SerializeTo(std::vector<uint8_t>& out) const override;
+ std::string ToString() const override;
+
+ ReconfigRequestSN request_sequence_number() const {
+ return request_sequence_number_;
+ }
+
+ private:
+ ReconfigRequestSN request_sequence_number_;
+};
+
+} // namespace dcsctp
+
+#endif // NET_DCSCTP_PACKET_PARAMETER_SSN_TSN_RESET_REQUEST_PARAMETER_H_
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter_test.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter_test.cc
new file mode 100644
index 0000000000..eeb973cbcb
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter_test.cc
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter.h"
+
+#include <stdint.h>
+
+#include <type_traits>
+#include <vector>
+
+#include "net/dcsctp/testing/testing_macros.h"
+#include "rtc_base/gunit.h"
+#include "test/gmock.h"
+
+namespace dcsctp {
+namespace {
+
+TEST(SSNTSNResetRequestParameterTest, SerializeAndDeserialize) {
+ SSNTSNResetRequestParameter parameter(ReconfigRequestSN(1));
+
+ std::vector<uint8_t> serialized;
+ parameter.SerializeTo(serialized);
+
+ ASSERT_HAS_VALUE_AND_ASSIGN(SSNTSNResetRequestParameter deserialized,
+ SSNTSNResetRequestParameter::Parse(serialized));
+
+ EXPECT_EQ(*deserialized.request_sequence_number(), 1u);
+}
+
+} // namespace
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/state_cookie_parameter.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/state_cookie_parameter.cc
new file mode 100644
index 0000000000..9777aa6667
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/state_cookie_parameter.cc
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/state_cookie_parameter.h"
+
+#include <stdint.h>
+
+#include <string>
+#include <type_traits>
+#include <vector>
+
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "net/dcsctp/packet/bounded_byte_reader.h"
+#include "net/dcsctp/packet/bounded_byte_writer.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+#include "rtc_base/strings/string_builder.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc4960#section-3.3.3.1
+
+constexpr int StateCookieParameter::kType;
+
+absl::optional<StateCookieParameter> StateCookieParameter::Parse(
+ rtc::ArrayView<const uint8_t> data) {
+ absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
+ if (!reader.has_value()) {
+ return absl::nullopt;
+ }
+ return StateCookieParameter(reader->variable_data());
+}
+
+void StateCookieParameter::SerializeTo(std::vector<uint8_t>& out) const {
+ BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out, data_.size());
+ writer.CopyToVariableData(data_);
+}
+
+std::string StateCookieParameter::ToString() const {
+ rtc::StringBuilder sb;
+ sb << "State Cookie parameter (cookie_length=" << data_.size() << ")";
+ return sb.Release();
+}
+
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/state_cookie_parameter.h b/third_party/libwebrtc/net/dcsctp/packet/parameter/state_cookie_parameter.h
new file mode 100644
index 0000000000..f4355495e2
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/state_cookie_parameter.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef NET_DCSCTP_PACKET_PARAMETER_STATE_COOKIE_PARAMETER_H_
+#define NET_DCSCTP_PACKET_PARAMETER_STATE_COOKIE_PARAMETER_H_
+#include <stddef.h>
+#include <stdint.h>
+
+#include <cstdint>
+#include <string>
+#include <vector>
+
+#include "absl/strings/string_view.h"
+#include "api/array_view.h"
+#include "net/dcsctp/packet/parameter/parameter.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc4960#section-3.3.3.1
+struct StateCookieParameterConfig : ParameterConfig {
+ static constexpr int kType = 7;
+ static constexpr size_t kHeaderSize = 4;
+ static constexpr size_t kVariableLengthAlignment = 1;
+};
+
+class StateCookieParameter : public Parameter,
+ public TLVTrait<StateCookieParameterConfig> {
+ public:
+ static constexpr int kType = StateCookieParameterConfig::kType;
+
+ explicit StateCookieParameter(rtc::ArrayView<const uint8_t> data)
+ : data_(data.begin(), data.end()) {}
+
+ static absl::optional<StateCookieParameter> Parse(
+ rtc::ArrayView<const uint8_t> data);
+
+ void SerializeTo(std::vector<uint8_t>& out) const override;
+ std::string ToString() const override;
+
+ rtc::ArrayView<const uint8_t> data() const { return data_; }
+
+ private:
+ std::vector<uint8_t> data_;
+};
+
+} // namespace dcsctp
+
+#endif // NET_DCSCTP_PACKET_PARAMETER_STATE_COOKIE_PARAMETER_H_
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/state_cookie_parameter_test.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/state_cookie_parameter_test.cc
new file mode 100644
index 0000000000..bcca38b586
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/state_cookie_parameter_test.cc
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/state_cookie_parameter.h"
+
+#include <stdint.h>
+
+#include <type_traits>
+#include <vector>
+
+#include "api/array_view.h"
+#include "net/dcsctp/testing/testing_macros.h"
+#include "rtc_base/gunit.h"
+#include "test/gmock.h"
+
+namespace dcsctp {
+namespace {
+using ::testing::ElementsAre;
+
+TEST(StateCookieParameterTest, SerializeAndDeserialize) {
+ uint8_t cookie[] = {1, 2, 3};
+ StateCookieParameter parameter(cookie);
+
+ std::vector<uint8_t> serialized;
+ parameter.SerializeTo(serialized);
+
+ ASSERT_HAS_VALUE_AND_ASSIGN(StateCookieParameter deserialized,
+ StateCookieParameter::Parse(serialized));
+
+ EXPECT_THAT(deserialized.data(), ElementsAre(1, 2, 3));
+}
+
+} // namespace
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/supported_extensions_parameter.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/supported_extensions_parameter.cc
new file mode 100644
index 0000000000..6a8fb214de
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/supported_extensions_parameter.cc
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/supported_extensions_parameter.h"
+
+#include <cstdint>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "net/dcsctp/common/str_join.h"
+#include "net/dcsctp/packet/bounded_byte_reader.h"
+#include "net/dcsctp/packet/bounded_byte_writer.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+#include "rtc_base/strings/string_builder.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc5061#section-4.2.7
+
+// 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 = 0x8008 | Parameter Length |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | CHUNK TYPE 1 | CHUNK TYPE 2 | CHUNK TYPE 3 | CHUNK TYPE 4 |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | .... |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | CHUNK TYPE N | PAD | PAD | PAD |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+constexpr int SupportedExtensionsParameter::kType;
+
+absl::optional<SupportedExtensionsParameter>
+SupportedExtensionsParameter::Parse(rtc::ArrayView<const uint8_t> data) {
+ absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
+ if (!reader.has_value()) {
+ return absl::nullopt;
+ }
+
+ std::vector<uint8_t> chunk_types(reader->variable_data().begin(),
+ reader->variable_data().end());
+ return SupportedExtensionsParameter(std::move(chunk_types));
+}
+
+void SupportedExtensionsParameter::SerializeTo(
+ std::vector<uint8_t>& out) const {
+ BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out, chunk_types_.size());
+ writer.CopyToVariableData(chunk_types_);
+}
+
+std::string SupportedExtensionsParameter::ToString() const {
+ rtc::StringBuilder sb;
+ sb << "Supported Extensions (" << StrJoin(chunk_types_, ", ") << ")";
+ return sb.Release();
+}
+} // namespace dcsctp
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/supported_extensions_parameter.h b/third_party/libwebrtc/net/dcsctp/packet/parameter/supported_extensions_parameter.h
new file mode 100644
index 0000000000..5689fd8035
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/supported_extensions_parameter.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef NET_DCSCTP_PACKET_PARAMETER_SUPPORTED_EXTENSIONS_PARAMETER_H_
+#define NET_DCSCTP_PACKET_PARAMETER_SUPPORTED_EXTENSIONS_PARAMETER_H_
+#include <stddef.h>
+
+#include <algorithm>
+#include <cstdint>
+#include <iterator>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "absl/strings/string_view.h"
+#include "api/array_view.h"
+#include "net/dcsctp/packet/parameter/parameter.h"
+#include "net/dcsctp/packet/tlv_trait.h"
+
+namespace dcsctp {
+
+// https://tools.ietf.org/html/rfc5061#section-4.2.7
+struct SupportedExtensionsParameterConfig : ParameterConfig {
+ static constexpr int kType = 0x8008;
+ static constexpr size_t kHeaderSize = 4;
+ static constexpr size_t kVariableLengthAlignment = 1;
+};
+
+class SupportedExtensionsParameter
+ : public Parameter,
+ public TLVTrait<SupportedExtensionsParameterConfig> {
+ public:
+ static constexpr int kType = SupportedExtensionsParameterConfig::kType;
+
+ explicit SupportedExtensionsParameter(std::vector<uint8_t> chunk_types)
+ : chunk_types_(std::move(chunk_types)) {}
+
+ static absl::optional<SupportedExtensionsParameter> Parse(
+ rtc::ArrayView<const uint8_t> data);
+
+ void SerializeTo(std::vector<uint8_t>& out) const override;
+ std::string ToString() const override;
+
+ bool supports(uint8_t chunk_type) const {
+ return std::find(chunk_types_.begin(), chunk_types_.end(), chunk_type) !=
+ chunk_types_.end();
+ }
+
+ rtc::ArrayView<const uint8_t> chunk_types() const { return chunk_types_; }
+
+ private:
+ std::vector<uint8_t> chunk_types_;
+};
+} // namespace dcsctp
+
+#endif // NET_DCSCTP_PACKET_PARAMETER_SUPPORTED_EXTENSIONS_PARAMETER_H_
diff --git a/third_party/libwebrtc/net/dcsctp/packet/parameter/supported_extensions_parameter_test.cc b/third_party/libwebrtc/net/dcsctp/packet/parameter/supported_extensions_parameter_test.cc
new file mode 100644
index 0000000000..c870af2e70
--- /dev/null
+++ b/third_party/libwebrtc/net/dcsctp/packet/parameter/supported_extensions_parameter_test.cc
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "net/dcsctp/packet/parameter/supported_extensions_parameter.h"
+
+#include <cstdint>
+#include <type_traits>
+#include <vector>
+
+#include "api/array_view.h"
+#include "net/dcsctp/testing/testing_macros.h"
+#include "rtc_base/gunit.h"
+#include "test/gmock.h"
+
+namespace dcsctp {
+namespace {
+using ::testing::ElementsAre;
+
+TEST(SupportedExtensionsParameterTest, SerializeAndDeserialize) {
+ SupportedExtensionsParameter parameter({1, 2, 3});
+
+ std::vector<uint8_t> serialized;
+ parameter.SerializeTo(serialized);
+
+ ASSERT_HAS_VALUE_AND_ASSIGN(SupportedExtensionsParameter deserialized,
+ SupportedExtensionsParameter::Parse(serialized));
+
+ EXPECT_THAT(deserialized.chunk_types(), ElementsAre(1, 2, 3));
+ EXPECT_TRUE(deserialized.supports(1));
+ EXPECT_TRUE(deserialized.supports(2));
+ EXPECT_TRUE(deserialized.supports(3));
+ EXPECT_FALSE(deserialized.supports(4));
+}
+
+} // namespace
+} // namespace dcsctp