Victor Boivie | 2a3942f | 2023-04-06 07:11:31 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023 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/socket/transmission_control_block.h" |
| 11 | |
| 12 | #include <array> |
| 13 | #include <cstdint> |
| 14 | #include <memory> |
| 15 | #include <type_traits> |
| 16 | #include <vector> |
| 17 | |
| 18 | #include "absl/types/optional.h" |
| 19 | #include "api/array_view.h" |
| 20 | #include "api/task_queue/task_queue_base.h" |
| 21 | #include "net/dcsctp/common/handover_testing.h" |
| 22 | #include "net/dcsctp/common/internal_types.h" |
| 23 | #include "net/dcsctp/packet/chunk/reconfig_chunk.h" |
| 24 | #include "net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.h" |
| 25 | #include "net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h" |
| 26 | #include "net/dcsctp/packet/parameter/parameter.h" |
| 27 | #include "net/dcsctp/packet/parameter/reconfiguration_response_parameter.h" |
| 28 | #include "net/dcsctp/public/dcsctp_message.h" |
| 29 | #include "net/dcsctp/rx/data_tracker.h" |
| 30 | #include "net/dcsctp/rx/reassembly_queue.h" |
| 31 | #include "net/dcsctp/socket/capabilities.h" |
| 32 | #include "net/dcsctp/socket/mock_context.h" |
| 33 | #include "net/dcsctp/socket/mock_dcsctp_socket_callbacks.h" |
| 34 | #include "net/dcsctp/testing/data_generator.h" |
| 35 | #include "net/dcsctp/testing/testing_macros.h" |
| 36 | #include "net/dcsctp/timer/timer.h" |
| 37 | #include "net/dcsctp/tx/mock_send_queue.h" |
| 38 | #include "net/dcsctp/tx/retransmission_queue.h" |
| 39 | #include "rtc_base/gunit.h" |
| 40 | #include "test/gmock.h" |
| 41 | |
| 42 | namespace dcsctp { |
| 43 | namespace { |
| 44 | using ::testing::Return; |
| 45 | using ::testing::StrictMock; |
| 46 | |
| 47 | constexpr VerificationTag kMyVerificationTag = VerificationTag(123); |
| 48 | constexpr VerificationTag kPeerVerificationTag = VerificationTag(456); |
| 49 | constexpr TSN kMyInitialTsn = TSN(10); |
| 50 | constexpr TSN kPeerInitialTsn = TSN(1000); |
| 51 | constexpr size_t kArwnd = 65536; |
| 52 | constexpr TieTag kTieTag = TieTag(12345678); |
| 53 | |
| 54 | class TransmissionControlBlockTest : public testing::Test { |
| 55 | protected: |
| 56 | TransmissionControlBlockTest() |
| 57 | : sender_(callbacks_, on_send_fn_.AsStdFunction()), |
| 58 | timer_manager_([this](webrtc::TaskQueueBase::DelayPrecision precision) { |
| 59 | return callbacks_.CreateTimeout(precision); |
| 60 | }) {} |
| 61 | |
| 62 | DcSctpOptions options_; |
| 63 | Capabilities capabilities_; |
| 64 | StrictMock<MockDcSctpSocketCallbacks> callbacks_; |
| 65 | StrictMock<MockSendQueue> send_queue_; |
| 66 | testing::MockFunction<void(rtc::ArrayView<const uint8_t>, SendPacketStatus)> |
| 67 | on_send_fn_; |
| 68 | testing::MockFunction<bool()> on_connection_established; |
| 69 | PacketSender sender_; |
| 70 | TimerManager timer_manager_; |
| 71 | }; |
| 72 | |
| 73 | TEST_F(TransmissionControlBlockTest, LogsBasicInfoInToString) { |
| 74 | EXPECT_CALL(send_queue_, EnableMessageInterleaving); |
| 75 | |
| 76 | capabilities_.negotiated_maximum_incoming_streams = 1000; |
| 77 | capabilities_.negotiated_maximum_outgoing_streams = 2000; |
| 78 | TransmissionControlBlock tcb( |
| 79 | timer_manager_, "log: ", options_, capabilities_, callbacks_, send_queue_, |
| 80 | kMyVerificationTag, kMyInitialTsn, kPeerVerificationTag, kPeerInitialTsn, |
| 81 | kArwnd, kTieTag, sender_, on_connection_established.AsStdFunction()); |
| 82 | |
| 83 | EXPECT_EQ(tcb.ToString(), |
| 84 | "verification_tag=000001c8, last_cumulative_ack=999, capabilities= " |
| 85 | "max_in=1000 max_out=2000"); |
| 86 | } |
| 87 | |
| 88 | TEST_F(TransmissionControlBlockTest, LogsAllCapabilitiesInToSring) { |
| 89 | EXPECT_CALL(send_queue_, EnableMessageInterleaving); |
| 90 | |
| 91 | capabilities_.negotiated_maximum_incoming_streams = 1000; |
| 92 | capabilities_.negotiated_maximum_outgoing_streams = 2000; |
| 93 | capabilities_.message_interleaving = true; |
| 94 | capabilities_.partial_reliability = true; |
Victor Boivie | 850296b | 2023-09-21 09:29:58 | [diff] [blame] | 95 | capabilities_.zero_checksum = true; |
Victor Boivie | 2a3942f | 2023-04-06 07:11:31 | [diff] [blame] | 96 | capabilities_.reconfig = true; |
| 97 | |
| 98 | TransmissionControlBlock tcb( |
| 99 | timer_manager_, "log: ", options_, capabilities_, callbacks_, send_queue_, |
| 100 | kMyVerificationTag, kMyInitialTsn, kPeerVerificationTag, kPeerInitialTsn, |
| 101 | kArwnd, kTieTag, sender_, on_connection_established.AsStdFunction()); |
| 102 | |
Victor Boivie | 850296b | 2023-09-21 09:29:58 | [diff] [blame] | 103 | EXPECT_EQ( |
| 104 | tcb.ToString(), |
| 105 | "verification_tag=000001c8, last_cumulative_ack=999, " |
| 106 | "capabilities=PR,IL,Reconfig,ZeroChecksum, max_in=1000 max_out=2000"); |
Victor Boivie | 2a3942f | 2023-04-06 07:11:31 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | TEST_F(TransmissionControlBlockTest, IsInitiallyHandoverReady) { |
| 110 | EXPECT_CALL(send_queue_, EnableMessageInterleaving); |
| 111 | EXPECT_CALL(send_queue_, HasStreamsReadyToBeReset).WillOnce(Return(false)); |
| 112 | |
| 113 | TransmissionControlBlock tcb( |
| 114 | timer_manager_, "log: ", options_, capabilities_, callbacks_, send_queue_, |
| 115 | kMyVerificationTag, kMyInitialTsn, kPeerVerificationTag, kPeerInitialTsn, |
| 116 | kArwnd, kTieTag, sender_, on_connection_established.AsStdFunction()); |
| 117 | |
| 118 | EXPECT_TRUE(tcb.GetHandoverReadiness().IsReady()); |
| 119 | } |
| 120 | } // namespace |
| 121 | } // namespace dcsctp |