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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 "TESTICEPWD00000000000003"}; | 94 "TESTICEPWD00000000000003"}; |
95 | 95 |
96 static const uint64_t kTiebreaker1 = 11111; | 96 static const uint64_t kTiebreaker1 = 11111; |
97 static const uint64_t kTiebreaker2 = 22222; | 97 static const uint64_t kTiebreaker2 = 22222; |
98 | 98 |
99 enum { | 99 enum { |
100 MSG_CANDIDATE | 100 MSG_CANDIDATE |
101 }; | 101 }; |
102 | 102 |
103 static cricket::IceConfig CreateIceConfig(int receiving_timeout_ms, | 103 static cricket::IceConfig CreateIceConfig(int receiving_timeout_ms, |
104 bool gather_continually) { | 104 bool gather_continually, |
| 105 int backup_ping_interval = -1) { |
105 cricket::IceConfig config; | 106 cricket::IceConfig config; |
106 config.receiving_timeout_ms = receiving_timeout_ms; | 107 config.receiving_timeout_ms = receiving_timeout_ms; |
107 config.gather_continually = gather_continually; | 108 config.gather_continually = gather_continually; |
| 109 config.backup_connection_ping_interval = backup_ping_interval; |
108 return config; | 110 return config; |
109 } | 111 } |
110 | 112 |
111 // This test simulates 2 P2P endpoints that want to establish connectivity | 113 // This test simulates 2 P2P endpoints that want to establish connectivity |
112 // with each other over various network topologies and conditions, which can be | 114 // with each other over various network topologies and conditions, which can be |
113 // specified in each individial test. | 115 // specified in each individial test. |
114 // A virtual network (via VirtualSocketServer) along with virtual firewalls and | 116 // A virtual network (via VirtualSocketServer) along with virtual firewalls and |
115 // NATs (via Firewall/NATSocketServer) are used to simulate the various network | 117 // NATs (via Firewall/NATSocketServer) are used to simulate the various network |
116 // conditions. We can configure the IP addresses of the endpoints, | 118 // conditions. We can configure the IP addresses of the endpoints, |
117 // block various types of connectivity, or add arbitrary levels of NAT. | 119 // block various types of connectivity, or add arbitrary levels of NAT. |
(...skipping 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1641 ep2_ch1()->best_connection()->receiving(), 1000); | 1643 ep2_ch1()->best_connection()->receiving(), 1000); |
1642 EXPECT_TRUE( | 1644 EXPECT_TRUE( |
1643 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); | 1645 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); |
1644 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1646 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1645 EXPECT_TRUE( | 1647 EXPECT_TRUE( |
1646 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); | 1648 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); |
1647 | 1649 |
1648 DestroyChannels(); | 1650 DestroyChannels(); |
1649 } | 1651 } |
1650 | 1652 |
| 1653 // Test that the backup connection is pinged at a rate no faster than |
| 1654 // what was configured. |
| 1655 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { |
| 1656 AddAddress(0, kPublicAddrs[0]); |
| 1657 // Adding alternate address will make sure |kPublicAddrs| has the higher |
| 1658 // priority than others. This is due to FakeNetwork::AddInterface method. |
| 1659 AddAddress(1, kAlternateAddrs[1]); |
| 1660 AddAddress(1, kPublicAddrs[1]); |
| 1661 |
| 1662 // Use only local ports for simplicity. |
| 1663 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 1664 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 1665 |
| 1666 // Create channels and let them go writable, as usual. |
| 1667 CreateChannels(1); |
| 1668 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1669 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1670 1000, 1000); |
| 1671 int backup_ping_interval = 2000; |
| 1672 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false, backup_ping_interval)); |
| 1673 // After the state becomes COMPLETED, the backup connection will be pinged |
| 1674 // once every |backup_ping_interval| milliseconds. |
| 1675 ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == cricket::STATE_COMPLETED, 1000); |
| 1676 const std::vector<cricket::Connection*>& connections = |
| 1677 ep2_ch1()->connections(); |
| 1678 ASSERT_EQ(2U, connections.size()); |
| 1679 cricket::Connection* backup_conn = connections[1]; |
| 1680 EXPECT_TRUE_WAIT(backup_conn->writable(), 3000); |
| 1681 uint32_t last_ping_response_ms = backup_conn->last_ping_response_received(); |
| 1682 EXPECT_TRUE_WAIT( |
| 1683 last_ping_response_ms < backup_conn->last_ping_response_received(), 5000); |
| 1684 int time_elapsed = |
| 1685 backup_conn->last_ping_response_received() - last_ping_response_ms; |
| 1686 LOG(LS_INFO) << "Time elapsed: " << time_elapsed; |
| 1687 EXPECT_GE(time_elapsed, backup_ping_interval); |
| 1688 } |
| 1689 |
1651 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { | 1690 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { |
1652 AddAddress(0, kAlternateAddrs[0]); | 1691 AddAddress(0, kAlternateAddrs[0]); |
1653 AddAddress(0, kPublicAddrs[0]); | 1692 AddAddress(0, kPublicAddrs[0]); |
1654 AddAddress(1, kPublicAddrs[1]); | 1693 AddAddress(1, kPublicAddrs[1]); |
1655 // Create channels and let them go writable, as usual. | 1694 // Create channels and let them go writable, as usual. |
1656 CreateChannels(1); | 1695 CreateChannels(1); |
1657 | 1696 |
1658 // Both transport channels will reach STATE_COMPLETED quickly. | 1697 // Both transport channels will reach STATE_COMPLETED quickly. |
1659 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, | 1698 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, |
1660 ep1_ch1()->GetState(), 1000); | 1699 ep1_ch1()->GetState(), 1000); |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2134 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2173 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2135 ASSERT_TRUE(conn1 != nullptr); | 2174 ASSERT_TRUE(conn1 != nullptr); |
2136 ASSERT_TRUE(conn2 != nullptr); | 2175 ASSERT_TRUE(conn2 != nullptr); |
2137 // Now there are two connections, so the transport channel is connecting. | 2176 // Now there are two connections, so the transport channel is connecting. |
2138 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); | 2177 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); |
2139 // |conn1| becomes writable and receiving; it then should prune |conn2|. | 2178 // |conn1| becomes writable and receiving; it then should prune |conn2|. |
2140 conn1->ReceivedPingResponse(); | 2179 conn1->ReceivedPingResponse(); |
2141 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); | 2180 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); |
2142 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2181 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); |
2143 conn1->Prune(); // All connections are pruned. | 2182 conn1->Prune(); // All connections are pruned. |
2144 EXPECT_EQ(cricket::TransportChannelState::STATE_FAILED, ch.GetState()); | 2183 // Need to wait until the channel state is updated. |
| 2184 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_FAILED, ch.GetState(), |
| 2185 1000); |
2145 } | 2186 } |
2146 | 2187 |
2147 // Test that when a low-priority connection is pruned, it is not deleted | 2188 // Test that when a low-priority connection is pruned, it is not deleted |
2148 // right away, and it can become active and be pruned again. | 2189 // right away, and it can become active and be pruned again. |
2149 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { | 2190 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
2150 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2191 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2151 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); | 2192 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); |
2152 PrepareChannel(&ch); | 2193 PrepareChannel(&ch); |
2153 ch.SetIceConfig(CreateIceConfig(1000, false)); | 2194 ch.SetIceConfig(CreateIceConfig(1000, false)); |
2154 ch.Connect(); | 2195 ch.Connect(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2238 // It should stop getting ports after a new connection becomes strongly | 2279 // It should stop getting ports after a new connection becomes strongly |
2239 // connected. | 2280 // connected. |
2240 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 2281 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); |
2241 ch.MaybeStartGathering(); | 2282 ch.MaybeStartGathering(); |
2242 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); | 2283 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); |
2243 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2284 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2244 ASSERT_TRUE(conn2 != nullptr); | 2285 ASSERT_TRUE(conn2 != nullptr); |
2245 conn2->ReceivedPingResponse(); // Becomes writable and receiving | 2286 conn2->ReceivedPingResponse(); // Becomes writable and receiving |
2246 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 2287 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
2247 } | 2288 } |
OLD | NEW |