OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 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 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 "TESTICEPWD00000000000002", | 95 "TESTICEPWD00000000000002", |
96 "TESTICEPWD00000000000003"}; | 96 "TESTICEPWD00000000000003"}; |
97 | 97 |
98 static const uint64_t kTiebreaker1 = 11111; | 98 static const uint64_t kTiebreaker1 = 11111; |
99 static const uint64_t kTiebreaker2 = 22222; | 99 static const uint64_t kTiebreaker2 = 22222; |
100 | 100 |
101 enum { | 101 enum { |
102 MSG_CANDIDATE | 102 MSG_CANDIDATE |
103 }; | 103 }; |
104 | 104 |
105 static cricket::IceConfig CreateIceConfig(int receiving_timeout_ms, | 105 static cricket::IceConfig CreateIceConfig(int receiving_timeout, |
106 bool gather_continually, | 106 bool gather_continually, |
107 int backup_ping_interval = -1) { | 107 int backup_ping_interval = -1) { |
108 cricket::IceConfig config; | 108 cricket::IceConfig config; |
109 config.receiving_timeout_ms = receiving_timeout_ms; | 109 config.receiving_timeout = receiving_timeout; |
110 config.gather_continually = gather_continually; | 110 config.gather_continually = gather_continually; |
111 config.backup_connection_ping_interval = backup_ping_interval; | 111 config.backup_connection_ping_interval = backup_ping_interval; |
112 return config; | 112 return config; |
113 } | 113 } |
114 | 114 |
115 // This test simulates 2 P2P endpoints that want to establish connectivity | 115 // This test simulates 2 P2P endpoints that want to establish connectivity |
116 // with each other over various network topologies and conditions, which can be | 116 // with each other over various network topologies and conditions, which can be |
117 // specified in each individial test. | 117 // specified in each individial test. |
118 // A virtual network (via VirtualSocketServer) along with virtual firewalls and | 118 // A virtual network (via VirtualSocketServer) along with virtual firewalls and |
119 // NATs (via Firewall/NATSocketServer) are used to simulate the various network | 119 // NATs (via Firewall/NATSocketServer) are used to simulate the various network |
(...skipping 1957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2077 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2077 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
2078 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1); | 2078 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1); |
2079 ASSERT_TRUE(conn3 != nullptr); | 2079 ASSERT_TRUE(conn3 != nullptr); |
2080 EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority); | 2080 EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority); |
2081 } | 2081 } |
2082 | 2082 |
2083 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { | 2083 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { |
2084 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2084 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2085 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2085 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); |
2086 PrepareChannel(&ch); | 2086 PrepareChannel(&ch); |
2087 // Default receiving timeout and checking receiving delay should not be too | 2087 // Default receiving timeout and checking receiving interval should not be too |
2088 // small. | 2088 // small. |
2089 EXPECT_LE(1000, ch.receiving_timeout()); | 2089 EXPECT_LE(1000, ch.receiving_timeout()); |
2090 EXPECT_LE(200, ch.check_receiving_delay()); | 2090 EXPECT_LE(200, ch.check_receiving_interval()); |
2091 ch.SetIceConfig(CreateIceConfig(500, false)); | 2091 ch.SetIceConfig(CreateIceConfig(500, false)); |
2092 EXPECT_EQ(500, ch.receiving_timeout()); | 2092 EXPECT_EQ(500, ch.receiving_timeout()); |
2093 EXPECT_EQ(50, ch.check_receiving_delay()); | 2093 EXPECT_EQ(50, ch.check_receiving_interval()); |
2094 ch.Connect(); | 2094 ch.Connect(); |
2095 ch.MaybeStartGathering(); | 2095 ch.MaybeStartGathering(); |
2096 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2096 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
2097 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2097 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2098 ASSERT_TRUE(conn1 != nullptr); | 2098 ASSERT_TRUE(conn1 != nullptr); |
2099 | 2099 |
2100 conn1->ReceivedPing(); | 2100 conn1->ReceivedPing(); |
2101 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2101 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
2102 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); | 2102 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); |
2103 EXPECT_TRUE_WAIT(ch.receiving(), 1000); | 2103 EXPECT_TRUE_WAIT(ch.receiving(), 1000); |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2485 cricket::RelayServerConfig config(cricket::RELAY_TURN); | 2485 cricket::RelayServerConfig config(cricket::RELAY_TURN); |
2486 config.credentials = kRelayCredentials; | 2486 config.credentials = kRelayCredentials; |
2487 config.ports.push_back( | 2487 config.ports.push_back( |
2488 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); | 2488 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); |
2489 allocator_->AddTurnServer(config); | 2489 allocator_->AddTurnServer(config); |
2490 allocator_->set_step_delay(kMinimumStepDelay); | 2490 allocator_->set_step_delay(kMinimumStepDelay); |
2491 } | 2491 } |
2492 | 2492 |
2493 cricket::P2PTransportChannel& StartTransportChannel( | 2493 cricket::P2PTransportChannel& StartTransportChannel( |
2494 bool prioritize_most_likely_to_work, | 2494 bool prioritize_most_likely_to_work, |
2495 uint32_t max_strong_delay) { | 2495 int max_strong_interval) { |
2496 channel_.reset( | 2496 channel_.reset( |
2497 new cricket::P2PTransportChannel("checks", 1, nullptr, allocator())); | 2497 new cricket::P2PTransportChannel("checks", 1, nullptr, allocator())); |
2498 cricket::IceConfig config = channel_->config(); | 2498 cricket::IceConfig config = channel_->config(); |
2499 config.prioritize_most_likely_candidate_pairs = | 2499 config.prioritize_most_likely_candidate_pairs = |
2500 prioritize_most_likely_to_work; | 2500 prioritize_most_likely_to_work; |
2501 config.max_strong_delay = max_strong_delay; | 2501 config.max_strong_interval = max_strong_interval; |
2502 channel_->SetIceConfig(config); | 2502 channel_->SetIceConfig(config); |
2503 PrepareChannel(channel_.get()); | 2503 PrepareChannel(channel_.get()); |
2504 channel_->Connect(); | 2504 channel_->Connect(); |
2505 channel_->MaybeStartGathering(); | 2505 channel_->MaybeStartGathering(); |
2506 return *channel_.get(); | 2506 return *channel_.get(); |
2507 } | 2507 } |
2508 | 2508 |
2509 cricket::BasicPortAllocator* allocator() { return allocator_.get(); } | 2509 cricket::BasicPortAllocator* allocator() { return allocator_.get(); } |
2510 cricket::TestTurnServer* turn_server() { return &turn_server_; } | 2510 cricket::TestTurnServer* turn_server() { return &turn_server_; } |
2511 | 2511 |
(...skipping 27 matching lines...) Expand all Loading... |
2539 rtc::FakeNetworkManager network_manager_; | 2539 rtc::FakeNetworkManager network_manager_; |
2540 cricket::TestTurnServer turn_server_; | 2540 cricket::TestTurnServer turn_server_; |
2541 rtc::scoped_ptr<cricket::P2PTransportChannel> channel_; | 2541 rtc::scoped_ptr<cricket::P2PTransportChannel> channel_; |
2542 }; | 2542 }; |
2543 | 2543 |
2544 // Test that Relay/Relay connections will be pinged first when no other | 2544 // Test that Relay/Relay connections will be pinged first when no other |
2545 // connections have been pinged yet, unless we need to ping a trigger check or | 2545 // connections have been pinged yet, unless we need to ping a trigger check or |
2546 // we have a best connection. | 2546 // we have a best connection. |
2547 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, | 2547 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, |
2548 TestRelayRelayFirstWhenNothingPingedYet) { | 2548 TestRelayRelayFirstWhenNothingPingedYet) { |
2549 const uint32_t max_strong_delay = 100; | 2549 const int max_strong_interval = 100; |
2550 cricket::P2PTransportChannel& ch = | 2550 cricket::P2PTransportChannel& ch = |
2551 StartTransportChannel(true, max_strong_delay); | 2551 StartTransportChannel(true, max_strong_interval); |
2552 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); | 2552 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); |
2553 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); | 2553 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); |
2554 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); | 2554 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); |
2555 | 2555 |
2556 ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1)); | 2556 ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1)); |
2557 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); | 2557 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); |
2558 | 2558 |
2559 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); | 2559 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); |
2560 | 2560 |
2561 // Relay/Relay should be the first pingable connection. | 2561 // Relay/Relay should be the first pingable connection. |
(...skipping 10 matching lines...) Expand all Loading... |
2572 | 2572 |
2573 // Make conn3 the best connection. | 2573 // Make conn3 the best connection. |
2574 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2574 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2575 EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE); | 2575 EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE); |
2576 EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE); | 2576 EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE); |
2577 conn3->ReceivedPingResponse(); | 2577 conn3->ReceivedPingResponse(); |
2578 ASSERT_TRUE(conn3->writable()); | 2578 ASSERT_TRUE(conn3->writable()); |
2579 conn3->ReceivedPing(); | 2579 conn3->ReceivedPing(); |
2580 | 2580 |
2581 // Verify that conn3 will be the "best connection" since it is readable and | 2581 // Verify that conn3 will be the "best connection" since it is readable and |
2582 // writable. After |MAX_CURRENT_STRONG_DELAY|, it should be the next pingable | 2582 // writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next |
2583 // connection. | 2583 // pingable connection. |
2584 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000); | 2584 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000); |
2585 WAIT(false, max_strong_delay + 100); | 2585 WAIT(false, max_strong_interval + 100); |
2586 conn3->ReceivedPingResponse(); | 2586 conn3->ReceivedPingResponse(); |
2587 ASSERT_TRUE(conn3->writable()); | 2587 ASSERT_TRUE(conn3->writable()); |
2588 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); | 2588 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); |
2589 } | 2589 } |
2590 | 2590 |
2591 // Test that Relay/Relay connections will be pinged first when everything has | 2591 // Test that Relay/Relay connections will be pinged first when everything has |
2592 // been pinged even if the Relay/Relay connection wasn't the first to be pinged | 2592 // been pinged even if the Relay/Relay connection wasn't the first to be pinged |
2593 // in the first round. | 2593 // in the first round. |
2594 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, | 2594 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, |
2595 TestRelayRelayFirstWhenEverythingPinged) { | 2595 TestRelayRelayFirstWhenEverythingPinged) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2690 | 2690 |
2691 // TCP Relay/Relay is the next. | 2691 // TCP Relay/Relay is the next. |
2692 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 2692 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
2693 cricket::RELAY_PORT_TYPE, | 2693 cricket::RELAY_PORT_TYPE, |
2694 cricket::TCP_PROTOCOL_NAME); | 2694 cricket::TCP_PROTOCOL_NAME); |
2695 | 2695 |
2696 // Finally, Local/Relay will be pinged. | 2696 // Finally, Local/Relay will be pinged. |
2697 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 2697 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
2698 cricket::RELAY_PORT_TYPE); | 2698 cricket::RELAY_PORT_TYPE); |
2699 } | 2699 } |
OLD | NEW |