| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 | 13 |
| 14 #include "webrtc/p2p/base/dtlstransport.h" | 14 #include "webrtc/p2p/base/dtlstransport.h" |
| 15 #include "webrtc/p2p/base/faketransportcontroller.h" | 15 #include "webrtc/p2p/base/faketransportcontroller.h" |
| 16 #include "webrtc/base/common.h" | 16 #include "webrtc/base/common.h" |
| 17 #include "webrtc/base/dscp.h" | 17 #include "webrtc/base/dscp.h" |
| 18 #include "webrtc/base/gunit.h" | 18 #include "webrtc/base/gunit.h" |
| 19 #include "webrtc/base/helpers.h" | 19 #include "webrtc/base/helpers.h" |
| 20 #include "webrtc/base/ssladapter.h" | 20 #include "webrtc/base/ssladapter.h" |
| 21 #include "webrtc/base/sslidentity.h" | 21 #include "webrtc/base/sslidentity.h" |
| 22 #include "webrtc/base/sslstreamadapter.h" | 22 #include "webrtc/base/sslstreamadapter.h" |
| 23 #include "webrtc/base/stringutils.h" | 23 #include "webrtc/base/stringutils.h" |
| 24 | 24 |
| 25 #define MAYBE_SKIP_TEST(feature) \ | 25 #define MAYBE_SKIP_TEST(feature) \ |
| 26 if (!(rtc::SSLStreamAdapter::feature())) { \ | 26 if (!(rtc::SSLStreamAdapter::feature())) { \ |
| 27 LOG(LS_INFO) << "Feature disabled... skipping"; \ | 27 LOG(LS_INFO) << #feature " feature disabled... skipping"; \ |
| 28 return; \ | 28 return; \ |
| 29 } | 29 } |
| 30 | 30 |
| 31 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; | 31 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; |
| 32 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; | 32 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; |
| 33 static const size_t kPacketNumOffset = 8; | 33 static const size_t kPacketNumOffset = 8; |
| 34 static const size_t kPacketHeaderLen = 12; | 34 static const size_t kPacketHeaderLen = 12; |
| 35 static const int kFakePacketId = 0x1234; | 35 static const int kFakePacketId = 0x1234; |
| 36 static const int kTimeout = 10000; | 36 static const int kTimeout = 10000; |
| 37 | 37 |
| 38 static bool IsRtpLeadByte(uint8_t b) { | 38 static bool IsRtpLeadByte(uint8_t b) { |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 size_t packet_size_ = 0u; | 406 size_t packet_size_ = 0u; |
| 407 std::set<int> received_; | 407 std::set<int> received_; |
| 408 bool use_dtls_srtp_ = false; | 408 bool use_dtls_srtp_ = false; |
| 409 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; | 409 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; |
| 410 bool negotiated_dtls_ = false; | 410 bool negotiated_dtls_ = false; |
| 411 int received_dtls_client_hellos_ = 0; | 411 int received_dtls_client_hellos_ = 0; |
| 412 int received_dtls_server_hellos_ = 0; | 412 int received_dtls_server_hellos_ = 0; |
| 413 rtc::SentPacket sent_packet_; | 413 rtc::SentPacket sent_packet_; |
| 414 }; | 414 }; |
| 415 | 415 |
| 416 | 416 // Note that this test always uses a FakeClock, due to the |fake_clock_| member |
| 417 // variable. |
| 417 class DtlsTransportChannelTest : public testing::Test { | 418 class DtlsTransportChannelTest : public testing::Test { |
| 418 public: | 419 public: |
| 419 DtlsTransportChannelTest() | 420 DtlsTransportChannelTest() |
| 420 : client1_("P1"), | 421 : client1_("P1"), |
| 421 client2_("P2"), | 422 client2_("P2"), |
| 422 channel_ct_(1), | 423 channel_ct_(1), |
| 423 use_dtls_(false), | 424 use_dtls_(false), |
| 424 use_dtls_srtp_(false), | 425 use_dtls_srtp_(false), |
| 425 ssl_expected_version_(rtc::SSL_PROTOCOL_DTLS_12) {} | 426 ssl_expected_version_(rtc::SSL_PROTOCOL_DTLS_12) {} |
| 426 | 427 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 } | 555 } |
| 555 | 556 |
| 556 void TestTransfer(size_t channel, size_t size, size_t count, bool srtp) { | 557 void TestTransfer(size_t channel, size_t size, size_t count, bool srtp) { |
| 557 LOG(LS_INFO) << "Expect packets, size=" << size; | 558 LOG(LS_INFO) << "Expect packets, size=" << size; |
| 558 client2_.ExpectPackets(channel, size); | 559 client2_.ExpectPackets(channel, size); |
| 559 client1_.SendPackets(channel, size, count, srtp); | 560 client1_.SendPackets(channel, size, count, srtp); |
| 560 EXPECT_EQ_WAIT(count, client2_.NumPacketsReceived(), kTimeout); | 561 EXPECT_EQ_WAIT(count, client2_.NumPacketsReceived(), kTimeout); |
| 561 } | 562 } |
| 562 | 563 |
| 563 protected: | 564 protected: |
| 565 rtc::ScopedFakeClock fake_clock_; |
| 564 DtlsTestClient client1_; | 566 DtlsTestClient client1_; |
| 565 DtlsTestClient client2_; | 567 DtlsTestClient client2_; |
| 566 int channel_ct_; | 568 int channel_ct_; |
| 567 bool use_dtls_; | 569 bool use_dtls_; |
| 568 bool use_dtls_srtp_; | 570 bool use_dtls_srtp_; |
| 569 rtc::SSLProtocolVersion ssl_expected_version_; | 571 rtc::SSLProtocolVersion ssl_expected_version_; |
| 570 }; | 572 }; |
| 571 | 573 |
| 572 // Test that transport negotiation of ICE, no DTLS works properly. | 574 // Test that transport negotiation of ICE, no DTLS works properly. |
| 573 TEST_F(DtlsTransportChannelTest, TestChannelSetupIce) { | 575 TEST_F(DtlsTransportChannelTest, TestChannelSetupIce) { |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 client1_.transport()->SetRemoteTransportDescription( | 969 client1_.transport()->SetRemoteTransportDescription( |
| 968 MakeTransportDescription(client2_.certificate(), | 970 MakeTransportDescription(client2_.certificate(), |
| 969 cricket::CONNECTIONROLE_ACTIVE), | 971 cricket::CONNECTIONROLE_ACTIVE), |
| 970 cricket::CA_ANSWER, nullptr); | 972 cricket::CA_ANSWER, nullptr); |
| 971 EXPECT_TRUE(client1_.Connect(&client2_, true)); | 973 EXPECT_TRUE(client1_.Connect(&client2_, true)); |
| 972 EXPECT_TRUE_WAIT( | 974 EXPECT_TRUE_WAIT( |
| 973 client1_.all_channels_writable() && client2_.all_channels_writable(), | 975 client1_.all_channels_writable() && client2_.all_channels_writable(), |
| 974 kTimeout); | 976 kTimeout); |
| 975 EXPECT_EQ(1, client1_.received_dtls_client_hellos()); | 977 EXPECT_EQ(1, client1_.received_dtls_client_hellos()); |
| 976 } | 978 } |
| 979 |
| 980 // Test that packets are retransmitted according to the expected schedule. |
| 981 // Each time a timeout occurs, the retransmission timer should be doubled up to |
| 982 // 60 seconds. The timer defaults to 1 second, but for WebRTC we should be |
| 983 // initializing it to 50ms. |
| 984 TEST_F(DtlsTransportChannelTest, TestRetransmissionSchedule) { |
| 985 MAYBE_SKIP_TEST(HaveDtls); |
| 986 // We can only change the retransmission schedule with a recently-added |
| 987 // BoringSSL API. Skip the test if not built with BoringSSL. |
| 988 MAYBE_SKIP_TEST(IsBoringSsl); |
| 989 |
| 990 PrepareDtls(true, true, rtc::KT_DEFAULT); |
| 991 // Exchange transport descriptions. |
| 992 Negotiate(cricket::CONNECTIONROLE_ACTPASS, cricket::CONNECTIONROLE_ACTIVE); |
| 993 |
| 994 // Make client2_ writable, but not client1_. |
| 995 // This means client1_ will send DTLS client hellos but get no response. |
| 996 EXPECT_TRUE(client2_.Connect(&client1_, true)); |
| 997 EXPECT_TRUE_WAIT(client2_.all_raw_channels_writable(), kTimeout); |
| 998 |
| 999 // Wait for the first client hello to be sent. |
| 1000 EXPECT_EQ_WAIT(1, client1_.received_dtls_client_hellos(), kTimeout); |
| 1001 EXPECT_FALSE(client1_.all_raw_channels_writable()); |
| 1002 |
| 1003 static int timeout_schedule_ms[] = {50, 100, 200, 400, 800, 1600, |
| 1004 3200, 6400, 12800, 25600, 51200, 60000}; |
| 1005 |
| 1006 int expected_hellos = 1; |
| 1007 for (size_t i = 0; |
| 1008 i < (sizeof(timeout_schedule_ms) / sizeof(timeout_schedule_ms[0])); |
| 1009 ++i) { |
| 1010 // For each expected retransmission time, advance the fake clock a |
| 1011 // millisecond before the expected time and verify that no unexpected |
| 1012 // retransmissions were sent. Then advance it the final millisecond and |
| 1013 // verify that the expected retransmission was sent. |
| 1014 fake_clock_.AdvanceTime( |
| 1015 rtc::TimeDelta::FromMilliseconds(timeout_schedule_ms[i] - 1)); |
| 1016 EXPECT_EQ(expected_hellos, client1_.received_dtls_client_hellos()); |
| 1017 fake_clock_.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1)); |
| 1018 EXPECT_EQ(++expected_hellos, client1_.received_dtls_client_hellos()); |
| 1019 } |
| 1020 } |
| OLD | NEW |