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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 connect_time = rtc::TimeMillis() - connect_start; | 522 connect_time = rtc::TimeMillis() - connect_start; |
523 if (connect_time < expected.connect_wait) { | 523 if (connect_time < expected.connect_wait) { |
524 LOG(LS_INFO) << "Connect time: " << connect_time << " ms"; | 524 LOG(LS_INFO) << "Connect time: " << connect_time << " ms"; |
525 } else { | 525 } else { |
526 LOG(LS_INFO) << "Connect time: " << "TIMEOUT (" | 526 LOG(LS_INFO) << "Connect time: " << "TIMEOUT (" |
527 << expected.connect_wait << " ms)"; | 527 << expected.connect_wait << " ms)"; |
528 } | 528 } |
529 | 529 |
530 // Allow a few turns of the crank for the best connections to emerge. | 530 // Allow a few turns of the crank for the best connections to emerge. |
531 // This may take up to 2 seconds. | 531 // This may take up to 2 seconds. |
532 if (ep1_ch1()->best_connection() && | 532 if (ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection()) { |
533 ep2_ch1()->best_connection()) { | |
534 int64_t converge_start = rtc::TimeMillis(); | 533 int64_t converge_start = rtc::TimeMillis(); |
535 int64_t converge_time; | 534 int64_t converge_time; |
536 int64_t converge_wait = 2000; | 535 int64_t converge_wait = 2000; |
537 // Verifying local and remote channel best connection information. This is | 536 // Verifying local and remote channel best connection information. This is |
538 // done only for the RFC 5245 as controlled agent will use USE-CANDIDATE | 537 // done only for the RFC 5245 as controlled agent will use USE-CANDIDATE |
539 // from controlling (ep1) agent. We can easily predict from EP1 result | 538 // from controlling (ep1) agent. We can easily predict from EP1 result |
540 // matrix. | 539 // matrix. |
541 EXPECT_TRUE_WAIT_MARGIN( | 540 EXPECT_TRUE_WAIT_MARGIN( |
542 CheckCandidate1(expected) && CheckCandidate2(expected), converge_wait, | 541 CheckCandidate1(expected) && CheckCandidate2(expected), converge_wait, |
543 converge_wait); | 542 converge_wait); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 // has higher tiebreaker value, channel1 should receive SignalRoleConflict. | 632 // has higher tiebreaker value, channel1 should receive SignalRoleConflict. |
634 EXPECT_TRUE_WAIT(GetRoleConflict(0), 1000); | 633 EXPECT_TRUE_WAIT(GetRoleConflict(0), 1000); |
635 EXPECT_FALSE(GetRoleConflict(1)); | 634 EXPECT_FALSE(GetRoleConflict(1)); |
636 | 635 |
637 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && | 636 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && |
638 ep1_ch1()->writable() && | 637 ep1_ch1()->writable() && |
639 ep2_ch1()->receiving() && | 638 ep2_ch1()->receiving() && |
640 ep2_ch1()->writable(), | 639 ep2_ch1()->writable(), |
641 1000); | 640 1000); |
642 | 641 |
643 EXPECT_TRUE(ep1_ch1()->best_connection() && | 642 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
644 ep2_ch1()->best_connection()); | 643 ep2_ch1()->selected_connection()); |
645 | 644 |
646 TestSendRecv(1); | 645 TestSendRecv(1); |
647 } | 646 } |
648 | 647 |
649 // We pass the candidates directly to the other side. | 648 // We pass the candidates directly to the other side. |
650 void OnCandidateGathered(cricket::TransportChannelImpl* ch, | 649 void OnCandidateGathered(cricket::TransportChannelImpl* ch, |
651 const cricket::Candidate& c) { | 650 const cricket::Candidate& c) { |
652 if (force_relay_ && c.type() != cricket::RELAY_PORT_TYPE) | 651 if (force_relay_ && c.type() != cricket::RELAY_PORT_TYPE) |
653 return; | 652 return; |
654 | 653 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
745 const char* data, size_t len) { | 744 const char* data, size_t len) { |
746 rtc::PacketOptions options; | 745 rtc::PacketOptions options; |
747 return channel->SendPacket(data, len, options, 0); | 746 return channel->SendPacket(data, len, options, 0); |
748 } | 747 } |
749 bool CheckDataOnChannel(cricket::TransportChannel* channel, | 748 bool CheckDataOnChannel(cricket::TransportChannel* channel, |
750 const char* data, int len) { | 749 const char* data, int len) { |
751 return GetChannelData(channel)->CheckData(data, len); | 750 return GetChannelData(channel)->CheckData(data, len); |
752 } | 751 } |
753 static const cricket::Candidate* LocalCandidate( | 752 static const cricket::Candidate* LocalCandidate( |
754 cricket::P2PTransportChannel* ch) { | 753 cricket::P2PTransportChannel* ch) { |
755 return (ch && ch->best_connection()) ? | 754 return (ch && ch->selected_connection()) |
756 &ch->best_connection()->local_candidate() : NULL; | 755 ? &ch->selected_connection()->local_candidate() |
756 : NULL; | |
757 } | 757 } |
758 static const cricket::Candidate* RemoteCandidate( | 758 static const cricket::Candidate* RemoteCandidate( |
759 cricket::P2PTransportChannel* ch) { | 759 cricket::P2PTransportChannel* ch) { |
760 return (ch && ch->best_connection()) ? | 760 return (ch && ch->selected_connection()) |
761 &ch->best_connection()->remote_candidate() : NULL; | 761 ? &ch->selected_connection()->remote_candidate() |
762 : NULL; | |
762 } | 763 } |
763 Endpoint* GetEndpoint(cricket::TransportChannel* ch) { | 764 Endpoint* GetEndpoint(cricket::TransportChannel* ch) { |
764 if (ep1_.HasChannel(ch)) { | 765 if (ep1_.HasChannel(ch)) { |
765 return &ep1_; | 766 return &ep1_; |
766 } else if (ep2_.HasChannel(ch)) { | 767 } else if (ep2_.HasChannel(ch)) { |
767 return &ep2_; | 768 return &ep2_; |
768 } else { | 769 } else { |
769 return NULL; | 770 return NULL; |
770 } | 771 } |
771 } | 772 } |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 // Emulate no remote credentials coming in. | 1108 // Emulate no remote credentials coming in. |
1108 set_clear_remote_candidates_ufrag_pwd(false); | 1109 set_clear_remote_candidates_ufrag_pwd(false); |
1109 CreateChannels(1); | 1110 CreateChannels(1); |
1110 // Only have remote credentials come in for ep2, not ep1. | 1111 // Only have remote credentials come in for ep2, not ep1. |
1111 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1112 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); |
1112 | 1113 |
1113 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive | 1114 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive |
1114 // candidate. | 1115 // candidate. |
1115 PauseCandidates(1); | 1116 PauseCandidates(1); |
1116 | 1117 |
1117 // The caller should have the best connection connected to the peer reflexive | 1118 // The caller should have the best connection connected to the peer reflexive |
Taylor Brandstetter
2016/06/21 18:33:26
s/best connection/selected connnection/g
honghaiz3
2016/06/22 08:03:16
Done.
| |
1118 // candidate. | 1119 // candidate. |
1119 const cricket::Connection* best_connection = NULL; | 1120 const cricket::Connection* selected_connection = NULL; |
1120 WAIT((best_connection = ep1_ch1()->best_connection()) != NULL, 2000); | 1121 WAIT((selected_connection = ep1_ch1()->selected_connection()) != NULL, 2000); |
1121 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type()); | 1122 EXPECT_EQ("prflx", |
1123 ep1_ch1()->selected_connection()->remote_candidate().type()); | |
1122 | 1124 |
1123 // Because we don't have a remote pwd, we don't ping yet. | 1125 // Because we don't have a remote pwd, we don't ping yet. |
1124 EXPECT_EQ(kIceUfrag[1], | 1126 EXPECT_EQ(kIceUfrag[1], |
1125 ep1_ch1()->best_connection()->remote_candidate().username()); | 1127 ep1_ch1()->selected_connection()->remote_candidate().username()); |
1126 EXPECT_EQ("", ep1_ch1()->best_connection()->remote_candidate().password()); | 1128 EXPECT_EQ("", |
1129 ep1_ch1()->selected_connection()->remote_candidate().password()); | |
1127 // Because we don't have ICE credentials yet, we don't know the generation. | 1130 // Because we don't have ICE credentials yet, we don't know the generation. |
1128 EXPECT_EQ(0u, ep1_ch1()->best_connection()->remote_candidate().generation()); | 1131 EXPECT_EQ(0u, |
1132 ep1_ch1()->selected_connection()->remote_candidate().generation()); | |
1129 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); | 1133 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); |
1130 | 1134 |
1131 // Add two sets of remote ICE credentials, so that the ones used by the | 1135 // Add two sets of remote ICE credentials, so that the ones used by the |
1132 // candidate will be generation 1 instead of 0. | 1136 // candidate will be generation 1 instead of 0. |
1133 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1137 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
1134 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1138 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
1135 // After setting the remote ICE credentials, the password and generation | 1139 // After setting the remote ICE credentials, the password and generation |
1136 // of the peer reflexive candidate should be updated. | 1140 // of the peer reflexive candidate should be updated. |
1137 EXPECT_EQ(kIcePwd[1], | 1141 EXPECT_EQ(kIcePwd[1], |
1138 ep1_ch1()->best_connection()->remote_candidate().password()); | 1142 ep1_ch1()->selected_connection()->remote_candidate().password()); |
1139 EXPECT_EQ(1u, ep1_ch1()->best_connection()->remote_candidate().generation()); | 1143 EXPECT_EQ(1u, |
1144 ep1_ch1()->selected_connection()->remote_candidate().generation()); | |
1140 EXPECT_TRUE(nullptr != ep1_ch1()->FindNextPingableConnection()); | 1145 EXPECT_TRUE(nullptr != ep1_ch1()->FindNextPingableConnection()); |
1141 | 1146 |
1142 ResumeCandidates(1); | 1147 ResumeCandidates(1); |
1143 | 1148 |
1144 WAIT(ep2_ch1()->best_connection() != NULL, 2000); | 1149 WAIT(ep2_ch1()->selected_connection() != NULL, 2000); |
1145 // Verify ep1's best connection is updated to use the 'local' candidate. | 1150 // Verify ep1's best connection is updated to use the 'local' candidate. |
1146 EXPECT_EQ_WAIT( | 1151 EXPECT_EQ_WAIT("local", |
1147 "local", | 1152 ep1_ch1()->selected_connection()->remote_candidate().type(), |
1148 ep1_ch1()->best_connection()->remote_candidate().type(), | 1153 2000); |
1149 2000); | 1154 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); |
1150 EXPECT_EQ(best_connection, ep1_ch1()->best_connection()); | |
1151 DestroyChannels(); | 1155 DestroyChannels(); |
1152 } | 1156 } |
1153 | 1157 |
1154 // Test that we properly create a connection on a STUN ping from unknown address | 1158 // Test that we properly create a connection on a STUN ping from unknown address |
1155 // when the signaling is slow and the end points are behind NAT. | 1159 // when the signaling is slow and the end points are behind NAT. |
1156 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { | 1160 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { |
1157 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, | 1161 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, |
1158 kDefaultPortAllocatorFlags); | 1162 kDefaultPortAllocatorFlags); |
1159 // Emulate no remote credentials coming in. | 1163 // Emulate no remote credentials coming in. |
1160 set_clear_remote_candidates_ufrag_pwd(false); | 1164 set_clear_remote_candidates_ufrag_pwd(false); |
1161 CreateChannels(1); | 1165 CreateChannels(1); |
1162 // Only have remote credentials come in for ep2, not ep1. | 1166 // Only have remote credentials come in for ep2, not ep1. |
1163 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1167 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); |
1164 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive | 1168 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive |
1165 // candidate. | 1169 // candidate. |
1166 PauseCandidates(1); | 1170 PauseCandidates(1); |
1167 | 1171 |
1168 // The caller should have the best connection connected to the peer reflexive | 1172 // The caller should have the best connection connected to the peer reflexive |
1169 // candidate. | 1173 // candidate. |
1170 WAIT(ep1_ch1()->best_connection() != NULL, 2000); | 1174 WAIT(ep1_ch1()->selected_connection() != NULL, 2000); |
1171 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type()); | 1175 EXPECT_EQ("prflx", |
1176 ep1_ch1()->selected_connection()->remote_candidate().type()); | |
1172 | 1177 |
1173 // Because we don't have a remote pwd, we don't ping yet. | 1178 // Because we don't have a remote pwd, we don't ping yet. |
1174 EXPECT_EQ(kIceUfrag[1], | 1179 EXPECT_EQ(kIceUfrag[1], |
1175 ep1_ch1()->best_connection()->remote_candidate().username()); | 1180 ep1_ch1()->selected_connection()->remote_candidate().username()); |
1176 EXPECT_EQ("", ep1_ch1()->best_connection()->remote_candidate().password()); | 1181 EXPECT_EQ("", |
1182 ep1_ch1()->selected_connection()->remote_candidate().password()); | |
1177 // Because we don't have ICE credentials yet, we don't know the generation. | 1183 // Because we don't have ICE credentials yet, we don't know the generation. |
1178 EXPECT_EQ(0u, ep1_ch1()->best_connection()->remote_candidate().generation()); | 1184 EXPECT_EQ(0u, |
1185 ep1_ch1()->selected_connection()->remote_candidate().generation()); | |
1179 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); | 1186 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); |
1180 | 1187 |
1181 // Add two sets of remote ICE credentials, so that the ones used by the | 1188 // Add two sets of remote ICE credentials, so that the ones used by the |
1182 // candidate will be generation 1 instead of 0. | 1189 // candidate will be generation 1 instead of 0. |
1183 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1190 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
1184 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1191 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
1185 // After setting the remote ICE credentials, the password and generation | 1192 // After setting the remote ICE credentials, the password and generation |
1186 // of the peer reflexive candidate should be updated. | 1193 // of the peer reflexive candidate should be updated. |
1187 EXPECT_EQ(kIcePwd[1], | 1194 EXPECT_EQ(kIcePwd[1], |
1188 ep1_ch1()->best_connection()->remote_candidate().password()); | 1195 ep1_ch1()->selected_connection()->remote_candidate().password()); |
1189 EXPECT_EQ(1u, ep1_ch1()->best_connection()->remote_candidate().generation()); | 1196 EXPECT_EQ(1u, |
1197 ep1_ch1()->selected_connection()->remote_candidate().generation()); | |
1190 | 1198 |
1191 ResumeCandidates(1); | 1199 ResumeCandidates(1); |
1192 | 1200 |
1193 const cricket::Connection* best_connection = NULL; | 1201 const cricket::Connection* selected_connection = NULL; |
1194 WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 2000); | 1202 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 2000); |
1195 | 1203 |
1196 // Wait to verify the connection is not culled. | 1204 // Wait to verify the connection is not culled. |
1197 WAIT(ep1_ch1()->writable(), 2000); | 1205 WAIT(ep1_ch1()->writable(), 2000); |
1198 EXPECT_EQ(ep2_ch1()->best_connection(), best_connection); | 1206 EXPECT_EQ(ep2_ch1()->selected_connection(), selected_connection); |
1199 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type()); | 1207 EXPECT_EQ("prflx", |
1208 ep1_ch1()->selected_connection()->remote_candidate().type()); | |
1200 DestroyChannels(); | 1209 DestroyChannels(); |
1201 } | 1210 } |
1202 | 1211 |
1203 // Test that if remote candidates don't have ufrag and pwd, we still work. | 1212 // Test that if remote candidates don't have ufrag and pwd, we still work. |
1204 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { | 1213 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { |
1205 set_clear_remote_candidates_ufrag_pwd(true); | 1214 set_clear_remote_candidates_ufrag_pwd(true); |
1206 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1215 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
1207 kDefaultPortAllocatorFlags); | 1216 kDefaultPortAllocatorFlags); |
1208 CreateChannels(1); | 1217 CreateChannels(1); |
1209 const cricket::Connection* best_connection = NULL; | 1218 const cricket::Connection* selected_connection = NULL; |
1210 // Wait until the callee's connections are created. | 1219 // Wait until the callee's connections are created. |
1211 WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 1000); | 1220 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 1000); |
1212 // Wait to see if they get culled; they shouldn't. | 1221 // Wait to see if they get culled; they shouldn't. |
1213 WAIT(ep2_ch1()->best_connection() != best_connection, 1000); | 1222 WAIT(ep2_ch1()->selected_connection() != selected_connection, 1000); |
1214 EXPECT_TRUE(ep2_ch1()->best_connection() == best_connection); | 1223 EXPECT_TRUE(ep2_ch1()->selected_connection() == selected_connection); |
1215 DestroyChannels(); | 1224 DestroyChannels(); |
1216 } | 1225 } |
1217 | 1226 |
1218 // Test that a host behind NAT cannot be reached when incoming_only | 1227 // Test that a host behind NAT cannot be reached when incoming_only |
1219 // is set to true. | 1228 // is set to true. |
1220 TEST_F(P2PTransportChannelTest, IncomingOnlyBlocked) { | 1229 TEST_F(P2PTransportChannelTest, IncomingOnlyBlocked) { |
1221 ConfigureEndpoints(NAT_FULL_CONE, OPEN, kDefaultPortAllocatorFlags, | 1230 ConfigureEndpoints(NAT_FULL_CONE, OPEN, kDefaultPortAllocatorFlags, |
1222 kDefaultPortAllocatorFlags); | 1231 kDefaultPortAllocatorFlags); |
1223 | 1232 |
1224 SetAllocatorFlags(0, kOnlyLocalPorts); | 1233 SetAllocatorFlags(0, kOnlyLocalPorts); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1280 VerifySavedTcpCandidates(0, cricket::TCPTYPE_PASSIVE_STR); | 1289 VerifySavedTcpCandidates(0, cricket::TCPTYPE_PASSIVE_STR); |
1281 VerifySavedTcpCandidates(1, cricket::TCPTYPE_ACTIVE_STR); | 1290 VerifySavedTcpCandidates(1, cricket::TCPTYPE_ACTIVE_STR); |
1282 | 1291 |
1283 // Resume candidates. | 1292 // Resume candidates. |
1284 ResumeCandidates(0); | 1293 ResumeCandidates(0); |
1285 ResumeCandidates(1); | 1294 ResumeCandidates(1); |
1286 | 1295 |
1287 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1296 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1288 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1297 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1289 1000); | 1298 1000); |
1290 EXPECT_TRUE( | 1299 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
1291 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1300 ep2_ch1()->selected_connection() && |
1292 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1301 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1293 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1302 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1294 | 1303 |
1295 TestSendRecv(1); | 1304 TestSendRecv(1); |
1296 DestroyChannels(); | 1305 DestroyChannels(); |
1297 } | 1306 } |
1298 | 1307 |
1299 TEST_F(P2PTransportChannelTest, TestIceRoleConflict) { | 1308 TEST_F(P2PTransportChannelTest, TestIceRoleConflict) { |
1300 AddAddress(0, kPublicAddrs[0]); | 1309 AddAddress(0, kPublicAddrs[0]); |
1301 AddAddress(1, kPublicAddrs[1]); | 1310 AddAddress(1, kPublicAddrs[1]); |
1302 TestSignalRoleConflict(); | 1311 TestSignalRoleConflict(); |
1303 } | 1312 } |
(...skipping 29 matching lines...) Expand all Loading... | |
1333 // original value. | 1342 // original value. |
1334 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); | 1343 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); |
1335 } | 1344 } |
1336 | 1345 |
1337 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && | 1346 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && |
1338 ep1_ch1()->writable() && | 1347 ep1_ch1()->writable() && |
1339 ep2_ch1()->receiving() && | 1348 ep2_ch1()->receiving() && |
1340 ep2_ch1()->writable(), | 1349 ep2_ch1()->writable(), |
1341 1000); | 1350 1000); |
1342 | 1351 |
1343 EXPECT_TRUE(ep1_ch1()->best_connection() && | 1352 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
1344 ep2_ch1()->best_connection()); | 1353 ep2_ch1()->selected_connection()); |
1345 | 1354 |
1346 TestSendRecv(1); | 1355 TestSendRecv(1); |
1347 DestroyChannels(); | 1356 DestroyChannels(); |
1348 } | 1357 } |
1349 | 1358 |
1350 // Verify that we can set DSCP value and retrieve properly from P2PTC. | 1359 // Verify that we can set DSCP value and retrieve properly from P2PTC. |
1351 TEST_F(P2PTransportChannelTest, TestDefaultDscpValue) { | 1360 TEST_F(P2PTransportChannelTest, TestDefaultDscpValue) { |
1352 AddAddress(0, kPublicAddrs[0]); | 1361 AddAddress(0, kPublicAddrs[0]); |
1353 AddAddress(1, kPublicAddrs[1]); | 1362 AddAddress(1, kPublicAddrs[1]); |
1354 | 1363 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1388 // Enable IPv6 | 1397 // Enable IPv6 |
1389 SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_IPV6); | 1398 SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_IPV6); |
1390 SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_IPV6); | 1399 SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_IPV6); |
1391 | 1400 |
1392 CreateChannels(1); | 1401 CreateChannels(1); |
1393 | 1402 |
1394 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1403 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1395 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1404 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1396 1000); | 1405 1000); |
1397 EXPECT_TRUE( | 1406 EXPECT_TRUE( |
1398 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1407 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && |
1399 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) && | 1408 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) && |
1400 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1])); | 1409 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1])); |
1401 | 1410 |
1402 TestSendRecv(1); | 1411 TestSendRecv(1); |
1403 DestroyChannels(); | 1412 DestroyChannels(); |
1404 } | 1413 } |
1405 | 1414 |
1406 // Testing forceful TURN connections. | 1415 // Testing forceful TURN connections. |
1407 TEST_F(P2PTransportChannelTest, TestForceTurn) { | 1416 TEST_F(P2PTransportChannelTest, TestForceTurn) { |
1408 ConfigureEndpoints( | 1417 ConfigureEndpoints( |
1409 NAT_PORT_RESTRICTED, NAT_SYMMETRIC, | 1418 NAT_PORT_RESTRICTED, NAT_SYMMETRIC, |
1410 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET, | 1419 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET, |
1411 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1420 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1412 set_force_relay(true); | 1421 set_force_relay(true); |
1413 | 1422 |
1414 SetAllocationStepDelay(0, kMinimumStepDelay); | 1423 SetAllocationStepDelay(0, kMinimumStepDelay); |
1415 SetAllocationStepDelay(1, kMinimumStepDelay); | 1424 SetAllocationStepDelay(1, kMinimumStepDelay); |
1416 | 1425 |
1417 CreateChannels(1); | 1426 CreateChannels(1); |
1418 | 1427 |
1419 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1428 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1420 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1429 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1421 2000); | 1430 2000); |
1422 | 1431 |
1423 EXPECT_TRUE(ep1_ch1()->best_connection() && | 1432 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
1424 ep2_ch1()->best_connection()); | 1433 ep2_ch1()->selected_connection()); |
1425 | 1434 |
1426 EXPECT_EQ("relay", RemoteCandidate(ep1_ch1())->type()); | 1435 EXPECT_EQ("relay", RemoteCandidate(ep1_ch1())->type()); |
1427 EXPECT_EQ("relay", LocalCandidate(ep1_ch1())->type()); | 1436 EXPECT_EQ("relay", LocalCandidate(ep1_ch1())->type()); |
1428 EXPECT_EQ("relay", RemoteCandidate(ep2_ch1())->type()); | 1437 EXPECT_EQ("relay", RemoteCandidate(ep2_ch1())->type()); |
1429 EXPECT_EQ("relay", LocalCandidate(ep2_ch1())->type()); | 1438 EXPECT_EQ("relay", LocalCandidate(ep2_ch1())->type()); |
1430 | 1439 |
1431 TestSendRecv(1); | 1440 TestSendRecv(1); |
1432 DestroyChannels(); | 1441 DestroyChannels(); |
1433 } | 1442 } |
1434 | 1443 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1490 ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1499 ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1491 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1500 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1492 1000, 1000); | 1501 1000, 1000); |
1493 TestSendRecv(1); | 1502 TestSendRecv(1); |
1494 // Make sure the P2PTransportChannels are actually using ports from the | 1503 // Make sure the P2PTransportChannels are actually using ports from the |
1495 // pooled sessions. | 1504 // pooled sessions. |
1496 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); | 1505 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); |
1497 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); | 1506 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); |
1498 EXPECT_NE(pooled_ports_1.end(), | 1507 EXPECT_NE(pooled_ports_1.end(), |
1499 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), | 1508 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), |
1500 ep1_ch1()->best_connection()->port())); | 1509 ep1_ch1()->selected_connection()->port())); |
1501 EXPECT_NE(pooled_ports_2.end(), | 1510 EXPECT_NE(pooled_ports_2.end(), |
1502 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), | 1511 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), |
1503 ep2_ch1()->best_connection()->port())); | 1512 ep2_ch1()->selected_connection()->port())); |
1504 } | 1513 } |
1505 | 1514 |
1506 // Test that a connection succeeds when the P2PTransportChannel uses a pooled | 1515 // Test that a connection succeeds when the P2PTransportChannel uses a pooled |
1507 // PortAllocatorSession that already finished gathering candidates. | 1516 // PortAllocatorSession that already finished gathering candidates. |
1508 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionAfterDoneGathering) { | 1517 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionAfterDoneGathering) { |
1509 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1518 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
1510 kDefaultPortAllocatorFlags); | 1519 kDefaultPortAllocatorFlags); |
1511 // First create a pooled session for each endpoint. | 1520 // First create a pooled session for each endpoint. |
1512 auto& allocator_1 = GetEndpoint(0)->allocator_; | 1521 auto& allocator_1 = GetEndpoint(0)->allocator_; |
1513 auto& allocator_2 = GetEndpoint(1)->allocator_; | 1522 auto& allocator_2 = GetEndpoint(1)->allocator_; |
(...skipping 19 matching lines...) Expand all Loading... | |
1533 ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1542 ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1534 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1543 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1535 1000, 1000); | 1544 1000, 1000); |
1536 TestSendRecv(1); | 1545 TestSendRecv(1); |
1537 // Make sure the P2PTransportChannels are actually using ports from the | 1546 // Make sure the P2PTransportChannels are actually using ports from the |
1538 // pooled sessions. | 1547 // pooled sessions. |
1539 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); | 1548 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); |
1540 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); | 1549 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); |
1541 EXPECT_NE(pooled_ports_1.end(), | 1550 EXPECT_NE(pooled_ports_1.end(), |
1542 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), | 1551 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), |
1543 ep1_ch1()->best_connection()->port())); | 1552 ep1_ch1()->selected_connection()->port())); |
1544 EXPECT_NE(pooled_ports_2.end(), | 1553 EXPECT_NE(pooled_ports_2.end(), |
1545 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), | 1554 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), |
1546 ep2_ch1()->best_connection()->port())); | 1555 ep2_ch1()->selected_connection()->port())); |
1547 } | 1556 } |
1548 | 1557 |
1549 // Test what happens when we have 2 users behind the same NAT. This can lead | 1558 // Test what happens when we have 2 users behind the same NAT. This can lead |
1550 // to interesting behavior because the STUN server will only give out the | 1559 // to interesting behavior because the STUN server will only give out the |
1551 // address of the outermost NAT. | 1560 // address of the outermost NAT. |
1552 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { | 1561 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { |
1553 protected: | 1562 protected: |
1554 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { | 1563 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { |
1555 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); | 1564 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); |
1556 rtc::NATSocketServer::Translator* outer_nat = | 1565 rtc::NATSocketServer::Translator* outer_nat = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1607 // Use only local ports for simplicity. | 1616 // Use only local ports for simplicity. |
1608 SetAllocatorFlags(0, kOnlyLocalPorts); | 1617 SetAllocatorFlags(0, kOnlyLocalPorts); |
1609 SetAllocatorFlags(1, kOnlyLocalPorts); | 1618 SetAllocatorFlags(1, kOnlyLocalPorts); |
1610 | 1619 |
1611 // Create channels and let them go writable, as usual. | 1620 // Create channels and let them go writable, as usual. |
1612 CreateChannels(1); | 1621 CreateChannels(1); |
1613 | 1622 |
1614 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1623 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1615 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1624 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1616 1000, 1000); | 1625 1000, 1000); |
1617 EXPECT_TRUE( | 1626 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
1618 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1627 ep2_ch1()->selected_connection() && |
1619 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1628 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1620 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1629 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1621 | 1630 |
1622 // Make the receiving timeout shorter for testing. | 1631 // Make the receiving timeout shorter for testing. |
1623 cricket::IceConfig config = CreateIceConfig(1000, false); | 1632 cricket::IceConfig config = CreateIceConfig(1000, false); |
1624 ep1_ch1()->SetIceConfig(config); | 1633 ep1_ch1()->SetIceConfig(config); |
1625 ep2_ch1()->SetIceConfig(config); | 1634 ep2_ch1()->SetIceConfig(config); |
1626 | 1635 |
1627 // Blackhole any traffic to or from the public addrs. | 1636 // Blackhole any traffic to or from the public addrs. |
1628 LOG(LS_INFO) << "Failing over..."; | 1637 LOG(LS_INFO) << "Failing over..."; |
1629 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); | 1638 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); |
1630 // The best connections will switch, so keep references to them. | 1639 // The best connections will switch, so keep references to them. |
1631 const cricket::Connection* best_connection1 = ep1_ch1()->best_connection(); | 1640 const cricket::Connection* selected_connection1 = |
1632 const cricket::Connection* best_connection2 = ep2_ch1()->best_connection(); | 1641 ep1_ch1()->selected_connection(); |
1642 const cricket::Connection* selected_connection2 = | |
1643 ep2_ch1()->selected_connection(); | |
1633 // We should detect loss of receiving within 1 second or so. | 1644 // We should detect loss of receiving within 1 second or so. |
1634 EXPECT_TRUE_WAIT( | 1645 EXPECT_TRUE_WAIT( |
1635 !best_connection1->receiving() && !best_connection2->receiving(), 3000); | 1646 !selected_connection1->receiving() && !selected_connection2->receiving(), |
1647 3000); | |
1636 | 1648 |
1637 // We should switch over to use the alternate addr immediately on both sides | 1649 // We should switch over to use the alternate addr immediately on both sides |
1638 // when we are not receiving. | 1650 // when we are not receiving. |
1639 EXPECT_TRUE_WAIT( | 1651 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection()->receiving() && |
1640 ep1_ch1()->best_connection()->receiving() && | 1652 ep2_ch1()->selected_connection()->receiving(), |
1641 ep2_ch1()->best_connection()->receiving(), 1000); | 1653 1000); |
1642 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); | 1654 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); |
1643 EXPECT_TRUE( | 1655 EXPECT_TRUE( |
1644 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1])); | 1656 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1])); |
1645 EXPECT_TRUE( | 1657 EXPECT_TRUE( |
1646 LocalCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[1])); | 1658 LocalCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[1])); |
1647 | 1659 |
1648 DestroyChannels(); | 1660 DestroyChannels(); |
1649 } | 1661 } |
1650 | 1662 |
1651 // Test that we can quickly switch links if an interface goes down. | 1663 // Test that we can quickly switch links if an interface goes down. |
1652 // The controlling side has two interfaces and one will die. | 1664 // The controlling side has two interfaces and one will die. |
1653 TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControllingSide) { | 1665 TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControllingSide) { |
1654 // Adding alternate address will make sure |kPublicAddrs| has the higher | 1666 // Adding alternate address will make sure |kPublicAddrs| has the higher |
1655 // priority than others. This is due to FakeNetwork::AddInterface method. | 1667 // priority than others. This is due to FakeNetwork::AddInterface method. |
1656 AddAddress(0, kAlternateAddrs[0]); | 1668 AddAddress(0, kAlternateAddrs[0]); |
1657 AddAddress(0, kPublicAddrs[0]); | 1669 AddAddress(0, kPublicAddrs[0]); |
1658 AddAddress(1, kPublicAddrs[1]); | 1670 AddAddress(1, kPublicAddrs[1]); |
1659 | 1671 |
1660 // Use only local ports for simplicity. | 1672 // Use only local ports for simplicity. |
1661 SetAllocatorFlags(0, kOnlyLocalPorts); | 1673 SetAllocatorFlags(0, kOnlyLocalPorts); |
1662 SetAllocatorFlags(1, kOnlyLocalPorts); | 1674 SetAllocatorFlags(1, kOnlyLocalPorts); |
1663 | 1675 |
1664 // Create channels and let them go writable, as usual. | 1676 // Create channels and let them go writable, as usual. |
1665 CreateChannels(1); | 1677 CreateChannels(1); |
1666 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1678 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1667 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1679 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1668 1000, 1000); | 1680 1000, 1000); |
1669 EXPECT_TRUE( | 1681 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
1670 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1682 ep2_ch1()->selected_connection() && |
1671 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1683 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1672 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1684 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1673 | 1685 |
1674 // Make the receiving timeout shorter for testing. | 1686 // Make the receiving timeout shorter for testing. |
1675 cricket::IceConfig config = CreateIceConfig(1000, false); | 1687 cricket::IceConfig config = CreateIceConfig(1000, false); |
1676 ep1_ch1()->SetIceConfig(config); | 1688 ep1_ch1()->SetIceConfig(config); |
1677 ep2_ch1()->SetIceConfig(config); | 1689 ep2_ch1()->SetIceConfig(config); |
1678 | 1690 |
1679 // Blackhole any traffic to or from the public addrs. | 1691 // Blackhole any traffic to or from the public addrs. |
1680 LOG(LS_INFO) << "Failing over..."; | 1692 LOG(LS_INFO) << "Failing over..."; |
1681 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); | 1693 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); |
1682 // The best connections will switch, so keep references to them. | 1694 // The best connections will switch, so keep references to them. |
1683 const cricket::Connection* best_connection1 = ep1_ch1()->best_connection(); | 1695 const cricket::Connection* selected_connection1 = |
1684 const cricket::Connection* best_connection2 = ep2_ch1()->best_connection(); | 1696 ep1_ch1()->selected_connection(); |
1697 const cricket::Connection* selected_connection2 = | |
1698 ep2_ch1()->selected_connection(); | |
1685 // We should detect loss of receiving within 1 second or so. | 1699 // We should detect loss of receiving within 1 second or so. |
1686 EXPECT_TRUE_WAIT( | 1700 EXPECT_TRUE_WAIT( |
1687 !best_connection1->receiving() && !best_connection2->receiving(), 3000); | 1701 !selected_connection1->receiving() && !selected_connection2->receiving(), |
1702 3000); | |
1688 | 1703 |
1689 // We should switch over to use the alternate addr immediately on both sides | 1704 // We should switch over to use the alternate addr immediately on both sides |
1690 // when we are not receiving. | 1705 // when we are not receiving. |
1691 EXPECT_TRUE_WAIT( | 1706 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection()->receiving() && |
1692 ep1_ch1()->best_connection()->receiving() && | 1707 ep2_ch1()->selected_connection()->receiving(), |
1693 ep2_ch1()->best_connection()->receiving(), 1000); | 1708 1000); |
1694 EXPECT_TRUE( | 1709 EXPECT_TRUE( |
1695 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); | 1710 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); |
1696 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1711 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1697 EXPECT_TRUE( | 1712 EXPECT_TRUE( |
1698 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); | 1713 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); |
1699 | 1714 |
1700 DestroyChannels(); | 1715 DestroyChannels(); |
1701 } | 1716 } |
1702 | 1717 |
1703 // Tests that a Wifi-Wifi connection has the highest precedence. | 1718 // Tests that a Wifi-Wifi connection has the highest precedence. |
(...skipping 11 matching lines...) Expand all Loading... | |
1715 SetAllocatorFlags(0, kOnlyLocalPorts); | 1730 SetAllocatorFlags(0, kOnlyLocalPorts); |
1716 SetAllocatorFlags(1, kOnlyLocalPorts); | 1731 SetAllocatorFlags(1, kOnlyLocalPorts); |
1717 | 1732 |
1718 // Create channels and let them go writable, as usual. | 1733 // Create channels and let them go writable, as usual. |
1719 CreateChannels(1); | 1734 CreateChannels(1); |
1720 | 1735 |
1721 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1736 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1722 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1737 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1723 1000, 1000); | 1738 1000, 1000); |
1724 // Need to wait to make sure the connections on both networks are writable. | 1739 // Need to wait to make sure the connections on both networks are writable. |
1725 EXPECT_TRUE_WAIT(ep1_ch1()->best_connection() && | 1740 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() && |
1726 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && | 1741 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && |
1727 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), | 1742 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), |
1728 1000); | 1743 1000); |
1729 EXPECT_TRUE_WAIT(ep2_ch1()->best_connection() && | 1744 EXPECT_TRUE_WAIT(ep2_ch1()->selected_connection() && |
1730 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]) && | 1745 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]) && |
1731 RemoteCandidate(ep2_ch1())->address().EqualIPs(wifi[0]), | 1746 RemoteCandidate(ep2_ch1())->address().EqualIPs(wifi[0]), |
1732 1000); | 1747 1000); |
1733 } | 1748 } |
1734 | 1749 |
1735 // Tests that a Wifi-Cellular connection has higher precedence than | 1750 // Tests that a Wifi-Cellular connection has higher precedence than |
1736 // a Cellular-Cellular connection. | 1751 // a Cellular-Cellular connection. |
1737 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiOverCellularNetwork) { | 1752 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiOverCellularNetwork) { |
1738 // The interface names are chosen so that |cellular| would have higher | 1753 // The interface names are chosen so that |cellular| would have higher |
1739 // candidate priority if it is not for the network type. | 1754 // candidate priority if it is not for the network type. |
1740 auto& wifi = kAlternateAddrs; | 1755 auto& wifi = kAlternateAddrs; |
1741 auto& cellular = kPublicAddrs; | 1756 auto& cellular = kPublicAddrs; |
1742 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); | 1757 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
1743 AddAddress(1, wifi[1], "test0", rtc::ADAPTER_TYPE_WIFI); | 1758 AddAddress(1, wifi[1], "test0", rtc::ADAPTER_TYPE_WIFI); |
1744 AddAddress(1, cellular[1], "test1", rtc::ADAPTER_TYPE_CELLULAR); | 1759 AddAddress(1, cellular[1], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
1745 | 1760 |
1746 // Use only local ports for simplicity. | 1761 // Use only local ports for simplicity. |
1747 SetAllocatorFlags(0, kOnlyLocalPorts); | 1762 SetAllocatorFlags(0, kOnlyLocalPorts); |
1748 SetAllocatorFlags(1, kOnlyLocalPorts); | 1763 SetAllocatorFlags(1, kOnlyLocalPorts); |
1749 | 1764 |
1750 // Create channels and let them go writable, as usual. | 1765 // Create channels and let them go writable, as usual. |
1751 CreateChannels(1); | 1766 CreateChannels(1); |
1752 | 1767 |
1753 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1768 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1754 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1769 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1755 1000, 1000); | 1770 1000, 1000); |
1756 // Need to wait to make sure the connections on both networks are writable. | 1771 // Need to wait to make sure the connections on both networks are writable. |
1757 EXPECT_TRUE_WAIT(ep1_ch1()->best_connection() && | 1772 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() && |
1758 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), | 1773 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), |
1759 1000); | 1774 1000); |
1760 EXPECT_TRUE_WAIT(ep2_ch1()->best_connection() && | 1775 EXPECT_TRUE_WAIT(ep2_ch1()->selected_connection() && |
1761 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]), | 1776 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]), |
1762 1000); | 1777 1000); |
1763 } | 1778 } |
1764 | 1779 |
1765 // Test that the backup connection is pinged at a rate no faster than | 1780 // Test that the backup connection is pinged at a rate no faster than |
1766 // what was configured. | 1781 // what was configured. |
1767 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { | 1782 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { |
1768 AddAddress(0, kPublicAddrs[0]); | 1783 AddAddress(0, kPublicAddrs[0]); |
1769 // Adding alternate address will make sure |kPublicAddrs| has the higher | 1784 // Adding alternate address will make sure |kPublicAddrs| has the higher |
1770 // priority than others. This is due to FakeNetwork::AddInterface method. | 1785 // priority than others. This is due to FakeNetwork::AddInterface method. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1865 // Use only local ports for simplicity. | 1880 // Use only local ports for simplicity. |
1866 SetAllocatorFlags(0, kOnlyLocalPorts); | 1881 SetAllocatorFlags(0, kOnlyLocalPorts); |
1867 SetAllocatorFlags(1, kOnlyLocalPorts); | 1882 SetAllocatorFlags(1, kOnlyLocalPorts); |
1868 | 1883 |
1869 // Create channels and let them go writable, as usual. | 1884 // Create channels and let them go writable, as usual. |
1870 CreateChannels(1); | 1885 CreateChannels(1); |
1871 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1886 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1872 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1887 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1873 1000); | 1888 1000); |
1874 EXPECT_TRUE( | 1889 EXPECT_TRUE( |
1875 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1890 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && |
1876 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1891 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1877 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1892 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1878 | 1893 |
1879 | 1894 |
1880 // Remove the public interface, add the alternate interface, and allocate | 1895 // Remove the public interface, add the alternate interface, and allocate |
1881 // a new generation of candidates for the new interface (via | 1896 // a new generation of candidates for the new interface (via |
1882 // MaybeStartGathering()). | 1897 // MaybeStartGathering()). |
1883 LOG(LS_INFO) << "Draining..."; | 1898 LOG(LS_INFO) << "Draining..."; |
1884 AddAddress(1, kAlternateAddrs[1]); | 1899 AddAddress(1, kAlternateAddrs[1]); |
1885 RemoveAddress(1, kPublicAddrs[1]); | 1900 RemoveAddress(1, kPublicAddrs[1]); |
1886 ep2_ch1()->MaybeStartGathering(); | 1901 ep2_ch1()->MaybeStartGathering(); |
1887 | 1902 |
1888 // We should switch over to use the alternate address after | 1903 // We should switch over to use the alternate address after |
1889 // an exchange of pings. | 1904 // an exchange of pings. |
1890 EXPECT_TRUE_WAIT( | 1905 EXPECT_TRUE_WAIT( |
1891 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1906 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && |
1892 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1907 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1893 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), | 1908 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), |
1894 3000); | 1909 3000); |
1895 | 1910 |
1896 DestroyChannels(); | 1911 DestroyChannels(); |
1897 } | 1912 } |
1898 | 1913 |
1899 */ | 1914 */ |
1900 | 1915 |
1901 // A collection of tests which tests a single P2PTransportChannel by sending | 1916 // A collection of tests which tests a single P2PTransportChannel by sending |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1970 | 1985 |
1971 int SendData(cricket::TransportChannel& channel, | 1986 int SendData(cricket::TransportChannel& channel, |
1972 const char* data, | 1987 const char* data, |
1973 size_t len, | 1988 size_t len, |
1974 int packet_id) { | 1989 int packet_id) { |
1975 rtc::PacketOptions options; | 1990 rtc::PacketOptions options; |
1976 options.packet_id = packet_id; | 1991 options.packet_id = packet_id; |
1977 return channel.SendPacket(data, len, options, 0); | 1992 return channel.SendPacket(data, len, options, 0); |
1978 } | 1993 } |
1979 | 1994 |
1995 cricket::Connection* CreateConnectionWithCandidate( | |
1996 cricket::P2PTransportChannel& channel, | |
1997 const std::string& ip_addr, | |
1998 int port, | |
1999 int priority, | |
2000 bool writable) { | |
2001 channel.AddRemoteCandidate(CreateHostCandidate(ip_addr, port, priority)); | |
2002 cricket::Connection* conn = WaitForConnectionTo(&channel, ip_addr, port); | |
2003 if (conn && writable) { | |
2004 conn->ReceivedPingResponse(); // make it writable | |
2005 } | |
2006 return conn; | |
2007 } | |
2008 | |
2009 void NominateConnection(cricket::Connection* conn) { | |
2010 conn->set_nominated(true); | |
2011 conn->SignalNominated(conn); | |
2012 } | |
2013 | |
1980 void OnSelectedCandidatePairChanged( | 2014 void OnSelectedCandidatePairChanged( |
1981 cricket::TransportChannel* transport_channel, | 2015 cricket::TransportChannel* transport_channel, |
1982 cricket::CandidatePairInterface* selected_candidate_pair, | 2016 cricket::CandidatePairInterface* selected_candidate_pair, |
1983 int last_sent_packet_id) { | 2017 int last_sent_packet_id) { |
1984 last_selected_candidate_pair_ = selected_candidate_pair; | 2018 last_selected_candidate_pair_ = selected_candidate_pair; |
1985 last_sent_packet_id_ = last_sent_packet_id; | 2019 last_sent_packet_id_ = last_sent_packet_id; |
2020 ++selected_candidate_pair_switches_; | |
1986 } | 2021 } |
1987 | 2022 |
1988 void ReceivePingOnConnection(cricket::Connection* conn, | 2023 void ReceivePingOnConnection(cricket::Connection* conn, |
1989 const std::string& remote_ufrag, | 2024 const std::string& remote_ufrag, |
1990 int priority) { | 2025 int priority) { |
1991 cricket::IceMessage msg; | 2026 cricket::IceMessage msg; |
1992 msg.SetType(cricket::STUN_BINDING_REQUEST); | 2027 msg.SetType(cricket::STUN_BINDING_REQUEST); |
1993 msg.AddAttribute(new cricket::StunByteStringAttribute( | 2028 msg.AddAttribute(new cricket::StunByteStringAttribute( |
1994 cricket::STUN_ATTR_USERNAME, | 2029 cricket::STUN_ATTR_USERNAME, |
1995 conn->local_candidate().username() + ":" + remote_ufrag)); | 2030 conn->local_candidate().username() + ":" + remote_ufrag)); |
(...skipping 15 matching lines...) Expand all Loading... | |
2011 channel_state_ = channel->GetState(); | 2046 channel_state_ = channel->GetState(); |
2012 } | 2047 } |
2013 | 2048 |
2014 cricket::CandidatePairInterface* last_selected_candidate_pair() { | 2049 cricket::CandidatePairInterface* last_selected_candidate_pair() { |
2015 return last_selected_candidate_pair_; | 2050 return last_selected_candidate_pair_; |
2016 } | 2051 } |
2017 int last_sent_packet_id() { return last_sent_packet_id_; } | 2052 int last_sent_packet_id() { return last_sent_packet_id_; } |
2018 bool channel_ready_to_send() { return channel_ready_to_send_; } | 2053 bool channel_ready_to_send() { return channel_ready_to_send_; } |
2019 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } | 2054 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } |
2020 cricket::TransportChannelState channel_state() { return channel_state_; } | 2055 cricket::TransportChannelState channel_state() { return channel_state_; } |
2056 int get_and_reset_selected_candidate_pair_switches() { | |
2057 int switches = selected_candidate_pair_switches_; | |
2058 selected_candidate_pair_switches_ = 0; | |
2059 return switches; | |
2060 } | |
2021 | 2061 |
2022 private: | 2062 private: |
2023 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 2063 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
2024 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 2064 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
2025 rtc::SocketServerScope ss_scope_; | 2065 rtc::SocketServerScope ss_scope_; |
2026 cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr; | 2066 cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr; |
2067 int selected_candidate_pair_switches_ = 0; | |
2027 int last_sent_packet_id_ = -1; | 2068 int last_sent_packet_id_ = -1; |
2028 bool channel_ready_to_send_ = false; | 2069 bool channel_ready_to_send_ = false; |
2029 cricket::TransportChannelState channel_state_ = cricket::STATE_INIT; | 2070 cricket::TransportChannelState channel_state_ = cricket::STATE_INIT; |
2030 }; | 2071 }; |
2031 | 2072 |
2032 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { | 2073 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { |
2033 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2074 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2034 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); | 2075 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); |
2035 PrepareChannel(&ch); | 2076 PrepareChannel(&ch); |
2036 ch.Connect(); | 2077 ch.Connect(); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2239 EXPECT_EQ(500, ch.receiving_timeout()); | 2280 EXPECT_EQ(500, ch.receiving_timeout()); |
2240 EXPECT_EQ(50, ch.check_receiving_interval()); | 2281 EXPECT_EQ(50, ch.check_receiving_interval()); |
2241 ch.Connect(); | 2282 ch.Connect(); |
2242 ch.MaybeStartGathering(); | 2283 ch.MaybeStartGathering(); |
2243 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2284 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
2244 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2285 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2245 ASSERT_TRUE(conn1 != nullptr); | 2286 ASSERT_TRUE(conn1 != nullptr); |
2246 | 2287 |
2247 conn1->ReceivedPing(); | 2288 conn1->ReceivedPing(); |
2248 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2289 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
2249 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); | 2290 EXPECT_TRUE_WAIT(ch.selected_connection() != nullptr, 1000); |
2250 EXPECT_TRUE_WAIT(ch.receiving(), 1000); | 2291 EXPECT_TRUE_WAIT(ch.receiving(), 1000); |
2251 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); | 2292 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); |
2252 } | 2293 } |
2253 | 2294 |
2254 // The controlled side will select a connection as the "best connection" based | 2295 // The controlled side will select a connection as the "best connection" based |
2255 // on priority until the controlling side nominates a connection, at which | 2296 // on priority until the controlling side nominates a connection, at which |
2256 // point the controlled side will select that connection as the | 2297 // point the controlled side will select that connection as the |
2257 // "best connection". Plus, SignalSelectedCandidatePair will be fired if the | 2298 // "best connection". Plus, SignalSelectedCandidatePair will be fired if the |
2258 // best connection changes and SignalReadyToSend will be fired if the new best | 2299 // best connection changes and SignalReadyToSend will be fired if the new best |
2259 // connection is writable. | 2300 // connection is writable. |
2260 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { | 2301 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { |
2261 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2302 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2262 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2303 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); |
2263 PrepareChannel(&ch); | 2304 PrepareChannel(&ch); |
2264 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2305 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
2265 ch.Connect(); | 2306 ch.Connect(); |
2266 ch.MaybeStartGathering(); | 2307 ch.MaybeStartGathering(); |
2267 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2308 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
2268 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2309 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2269 ASSERT_TRUE(conn1 != nullptr); | 2310 ASSERT_TRUE(conn1 != nullptr); |
2270 EXPECT_EQ(conn1, ch.best_connection()); | 2311 EXPECT_EQ(conn1, ch.selected_connection()); |
2271 EXPECT_EQ(conn1, last_selected_candidate_pair()); | 2312 EXPECT_EQ(conn1, last_selected_candidate_pair()); |
2272 EXPECT_EQ(-1, last_sent_packet_id()); | 2313 EXPECT_EQ(-1, last_sent_packet_id()); |
2273 // Channel is not ready to send because it is not writable. | 2314 // Channel is not ready to send because it is not writable. |
2274 EXPECT_FALSE(channel_ready_to_send()); | 2315 EXPECT_FALSE(channel_ready_to_send()); |
2275 | 2316 |
2276 int last_packet_id = 0; | 2317 int last_packet_id = 0; |
2277 const char* data = "ABCDEFGH"; | 2318 const char* data = "ABCDEFGH"; |
2278 int len = static_cast<int>(strlen(data)); | 2319 int len = static_cast<int>(strlen(data)); |
2279 SendData(ch, data, len, ++last_packet_id); | 2320 SendData(ch, data, len, ++last_packet_id); |
2280 // When a higher priority candidate comes in, the new connection is chosen | 2321 // When a higher priority candidate comes in, the new connection is chosen |
2281 // as the best connection. | 2322 // as the best connection. |
2282 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); | 2323 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); |
2283 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2324 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2284 ASSERT_TRUE(conn2 != nullptr); | 2325 ASSERT_TRUE(conn2 != nullptr); |
2285 EXPECT_EQ(conn2, ch.best_connection()); | 2326 EXPECT_EQ(conn2, ch.selected_connection()); |
2286 EXPECT_EQ(conn2, last_selected_candidate_pair()); | 2327 EXPECT_EQ(conn2, last_selected_candidate_pair()); |
2287 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | 2328 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
2288 EXPECT_FALSE(channel_ready_to_send()); | 2329 EXPECT_FALSE(channel_ready_to_send()); |
2289 | 2330 |
2290 // If a stun request with use-candidate attribute arrives, the receiving | 2331 // If a stun request with use-candidate attribute arrives, the receiving |
2291 // connection will be set as the best connection, even though | 2332 // connection will be set as the best connection, even though |
2292 // its priority is lower. | 2333 // its priority is lower. |
2293 SendData(ch, data, len, ++last_packet_id); | 2334 SendData(ch, data, len, ++last_packet_id); |
2294 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); | 2335 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); |
2295 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2336 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2296 ASSERT_TRUE(conn3 != nullptr); | 2337 ASSERT_TRUE(conn3 != nullptr); |
2297 // Because it has a lower priority, the best connection is still conn2. | 2338 // Because it has a lower priority, the best connection is still conn2. |
2298 EXPECT_EQ(conn2, ch.best_connection()); | 2339 EXPECT_EQ(conn2, ch.selected_connection()); |
2299 conn3->ReceivedPingResponse(); // Become writable. | 2340 conn3->ReceivedPingResponse(); // Become writable. |
2300 // But if it is nominated via use_candidate, it is chosen as the best | 2341 // But if it is nominated via use_candidate, it is chosen as the best |
2301 // connection. | 2342 // connection. |
2302 conn3->set_nominated(true); | 2343 conn3->set_nominated(true); |
2303 conn3->SignalNominated(conn3); | 2344 conn3->SignalNominated(conn3); |
2304 EXPECT_EQ(conn3, ch.best_connection()); | 2345 EXPECT_EQ(conn3, ch.selected_connection()); |
2305 EXPECT_EQ(conn3, last_selected_candidate_pair()); | 2346 EXPECT_EQ(conn3, last_selected_candidate_pair()); |
2306 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | 2347 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
2307 EXPECT_TRUE(channel_ready_to_send()); | 2348 EXPECT_TRUE(channel_ready_to_send()); |
2308 | 2349 |
2309 // Even if another higher priority candidate arrives, | 2350 // Even if another higher priority candidate arrives, |
2310 // it will not be set as the best connection because the best connection | 2351 // it will not be set as the best connection because the best connection |
2311 // is nominated by the controlling side. | 2352 // is nominated by the controlling side. |
2312 SendData(ch, data, len, ++last_packet_id); | 2353 SendData(ch, data, len, ++last_packet_id); |
2313 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100)); | 2354 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100)); |
2314 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 2355 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
2315 ASSERT_TRUE(conn4 != nullptr); | 2356 ASSERT_TRUE(conn4 != nullptr); |
2316 EXPECT_EQ(conn3, ch.best_connection()); | 2357 EXPECT_EQ(conn3, ch.selected_connection()); |
2317 // But if it is nominated via use_candidate and writable, it will be set as | 2358 // But if it is nominated via use_candidate and writable, it will be set as |
2318 // the best connection. | 2359 // the best connection. |
2319 conn4->set_nominated(true); | 2360 conn4->set_nominated(true); |
2320 conn4->SignalNominated(conn4); | 2361 conn4->SignalNominated(conn4); |
2321 // Not switched yet because conn4 is not writable. | 2362 // Not switched yet because conn4 is not writable. |
2322 EXPECT_EQ(conn3, ch.best_connection()); | 2363 EXPECT_EQ(conn3, ch.selected_connection()); |
2323 reset_channel_ready_to_send(); | 2364 reset_channel_ready_to_send(); |
2324 // The best connection switches after conn4 becomes writable. | 2365 // The best connection switches after conn4 becomes writable. |
2325 conn4->ReceivedPingResponse(); | 2366 conn4->ReceivedPingResponse(); |
2326 EXPECT_EQ(conn4, ch.best_connection()); | 2367 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); |
2327 EXPECT_EQ(conn4, last_selected_candidate_pair()); | 2368 EXPECT_EQ(conn4, last_selected_candidate_pair()); |
2328 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | 2369 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
2329 // SignalReadyToSend is fired again because conn4 is writable. | 2370 // SignalReadyToSend is fired again because conn4 is writable. |
2330 EXPECT_TRUE(channel_ready_to_send()); | 2371 EXPECT_TRUE(channel_ready_to_send()); |
2331 } | 2372 } |
2332 | 2373 |
2333 // The controlled side will select a connection as the "best connection" based | 2374 // The controlled side will select a connection as the "best connection" based |
2334 // on requests from an unknown address before the controlling side nominates | 2375 // on requests from an unknown address before the controlling side nominates |
2335 // a connection, and will nominate a connection from an unknown address if the | 2376 // a connection, and will nominate a connection from an unknown address if the |
2336 // request contains the use_candidate attribute. Plus, it will also sends back | 2377 // request contains the use_candidate attribute. Plus, it will also sends back |
(...skipping 12 matching lines...) Expand all Loading... | |
2349 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 2390 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); |
2350 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 2391 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; |
2351 request.AddAttribute(new cricket::StunUInt32Attribute( | 2392 request.AddAttribute(new cricket::StunUInt32Attribute( |
2352 cricket::STUN_ATTR_PRIORITY, prflx_priority)); | 2393 cricket::STUN_ATTR_PRIORITY, prflx_priority)); |
2353 cricket::TestUDPPort* port = static_cast<cricket::TestUDPPort*>(GetPort(&ch)); | 2394 cricket::TestUDPPort* port = static_cast<cricket::TestUDPPort*>(GetPort(&ch)); |
2354 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), | 2395 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), |
2355 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2396 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
2356 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2397 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2357 ASSERT_TRUE(conn1 != nullptr); | 2398 ASSERT_TRUE(conn1 != nullptr); |
2358 EXPECT_TRUE(port->sent_binding_response()); | 2399 EXPECT_TRUE(port->sent_binding_response()); |
2359 EXPECT_EQ(conn1, ch.best_connection()); | 2400 EXPECT_EQ(conn1, ch.selected_connection()); |
2360 conn1->ReceivedPingResponse(); | 2401 conn1->ReceivedPingResponse(); |
2361 EXPECT_EQ(conn1, ch.best_connection()); | 2402 EXPECT_EQ(conn1, ch.selected_connection()); |
2362 port->set_sent_binding_response(false); | 2403 port->set_sent_binding_response(false); |
2363 | 2404 |
2364 // Another connection is nominated via use_candidate. | 2405 // Another connection is nominated via use_candidate. |
2365 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2406 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
2366 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2407 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2367 ASSERT_TRUE(conn2 != nullptr); | 2408 ASSERT_TRUE(conn2 != nullptr); |
2368 // Because it has a lower priority, the best connection is still conn1. | 2409 // Because it has a lower priority, the best connection is still conn1. |
2369 EXPECT_EQ(conn1, ch.best_connection()); | 2410 EXPECT_EQ(conn1, ch.selected_connection()); |
2370 // When it is nominated via use_candidate and writable, it is chosen as the | 2411 // When it is nominated via use_candidate and writable, it is chosen as the |
2371 // best connection. | 2412 // best connection. |
2372 conn2->ReceivedPingResponse(); // Become writable. | 2413 conn2->ReceivedPingResponse(); // Become writable. |
2373 conn2->set_nominated(true); | 2414 conn2->set_nominated(true); |
2374 conn2->SignalNominated(conn2); | 2415 conn2->SignalNominated(conn2); |
2375 EXPECT_EQ(conn2, ch.best_connection()); | 2416 EXPECT_EQ(conn2, ch.selected_connection()); |
2376 | 2417 |
2377 // Another request with unknown address, it will not be set as the best | 2418 // Another request with unknown address, it will not be set as the best |
2378 // connection because the best connection was nominated by the controlling | 2419 // connection because the best connection was nominated by the controlling |
2379 // side. | 2420 // side. |
2380 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), | 2421 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), |
2381 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2422 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
2382 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2423 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2383 ASSERT_TRUE(conn3 != nullptr); | 2424 ASSERT_TRUE(conn3 != nullptr); |
2384 EXPECT_TRUE(port->sent_binding_response()); | 2425 EXPECT_TRUE(port->sent_binding_response()); |
2385 conn3->ReceivedPingResponse(); // Become writable. | 2426 conn3->ReceivedPingResponse(); // Become writable. |
2386 EXPECT_EQ(conn2, ch.best_connection()); | 2427 EXPECT_EQ(conn2, ch.selected_connection()); |
2387 port->set_sent_binding_response(false); | 2428 port->set_sent_binding_response(false); |
2388 | 2429 |
2389 // However if the request contains use_candidate attribute, it will be | 2430 // However if the request contains use_candidate attribute, it will be |
2390 // selected as the best connection. | 2431 // selected as the best connection. |
2391 request.AddAttribute( | 2432 request.AddAttribute( |
2392 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); | 2433 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); |
2393 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), | 2434 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), |
2394 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2435 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
2395 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 2436 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
2396 ASSERT_TRUE(conn4 != nullptr); | 2437 ASSERT_TRUE(conn4 != nullptr); |
2397 EXPECT_TRUE(port->sent_binding_response()); | 2438 EXPECT_TRUE(port->sent_binding_response()); |
2398 // conn4 is not the best connection yet because it is not writable. | 2439 // conn4 is not the best connection yet because it is not writable. |
2399 EXPECT_EQ(conn2, ch.best_connection()); | 2440 EXPECT_EQ(conn2, ch.selected_connection()); |
2400 conn4->ReceivedPingResponse(); // Become writable. | 2441 conn4->ReceivedPingResponse(); // Become writable. |
2401 EXPECT_EQ(conn4, ch.best_connection()); | 2442 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); |
2402 | 2443 |
2403 // Test that the request from an unknown address contains a ufrag from an old | 2444 // Test that the request from an unknown address contains a ufrag from an old |
2404 // generation. | 2445 // generation. |
2405 port->set_sent_binding_response(false); | 2446 port->set_sent_binding_response(false); |
2406 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 2447 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); |
2407 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 2448 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
2408 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), | 2449 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), |
2409 cricket::PROTO_UDP, &request, kIceUfrag[2], false); | 2450 cricket::PROTO_UDP, &request, kIceUfrag[2], false); |
2410 cricket::Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); | 2451 cricket::Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); |
2411 ASSERT_TRUE(conn5 != nullptr); | 2452 ASSERT_TRUE(conn5 != nullptr); |
2412 EXPECT_TRUE(port->sent_binding_response()); | 2453 EXPECT_TRUE(port->sent_binding_response()); |
2413 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); | 2454 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); |
2414 } | 2455 } |
2415 | 2456 |
2416 // The controlled side will select a connection as the "best connection" | 2457 // The controlled side will select a connection as the "best connection" |
2417 // based on media received until the controlling side nominates a connection, | 2458 // based on media received until the controlling side nominates a connection, |
2418 // at which point the controlled side will select that connection as | 2459 // at which point the controlled side will select that connection as |
2419 // the "best connection". | 2460 // the "best connection". |
2420 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { | 2461 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { |
2421 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2462 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2422 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2463 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); |
2423 PrepareChannel(&ch); | 2464 PrepareChannel(&ch); |
2424 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2465 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
2425 ch.Connect(); | 2466 ch.Connect(); |
2426 ch.MaybeStartGathering(); | 2467 ch.MaybeStartGathering(); |
2427 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 10)); | 2468 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 10)); |
2428 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2469 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2429 ASSERT_TRUE(conn1 != nullptr); | 2470 ASSERT_TRUE(conn1 != nullptr); |
2430 EXPECT_EQ(conn1, ch.best_connection()); | 2471 EXPECT_EQ(conn1, ch.selected_connection()); |
2431 | 2472 |
2432 // If a data packet is received on conn2, the best connection should | 2473 // If a data packet is received on conn2, the best connection should |
2433 // switch to conn2 because the controlled side must mirror the media path | 2474 // switch to conn2 because the controlled side must mirror the media path |
2434 // chosen by the controlling side. | 2475 // chosen by the controlling side. |
2435 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2476 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
2436 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2477 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2437 ASSERT_TRUE(conn2 != nullptr); | 2478 ASSERT_TRUE(conn2 != nullptr); |
2438 conn2->ReceivedPing(); // Start receiving. | 2479 conn2->ReceivedPing(); // Start receiving. |
2439 // Do not switch because it is not writable. | |
2440 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2480 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
2441 EXPECT_EQ(conn1, ch.best_connection()); | 2481 EXPECT_EQ(conn2, ch.selected_connection()); |
2442 | 2482 conn2->ReceivedPingResponse(); // Make it writable. |
2443 conn2->ReceivedPingResponse(); // Become writable. | |
2444 // Switch because it is writable. | |
2445 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0)); | |
2446 EXPECT_EQ(conn2, ch.best_connection()); | |
2447 | 2483 |
2448 // Now another STUN message with an unknown address and use_candidate will | 2484 // Now another STUN message with an unknown address and use_candidate will |
2449 // nominate the best connection. | 2485 // nominate the best connection. |
2450 cricket::IceMessage request; | 2486 cricket::IceMessage request; |
2451 request.SetType(cricket::STUN_BINDING_REQUEST); | 2487 request.SetType(cricket::STUN_BINDING_REQUEST); |
2452 request.AddAttribute(new cricket::StunByteStringAttribute( | 2488 request.AddAttribute(new cricket::StunByteStringAttribute( |
2453 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 2489 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); |
2454 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 2490 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; |
2455 request.AddAttribute(new cricket::StunUInt32Attribute( | 2491 request.AddAttribute(new cricket::StunUInt32Attribute( |
2456 cricket::STUN_ATTR_PRIORITY, prflx_priority)); | 2492 cricket::STUN_ATTR_PRIORITY, prflx_priority)); |
2457 request.AddAttribute( | 2493 request.AddAttribute( |
2458 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); | 2494 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); |
2459 cricket::Port* port = GetPort(&ch); | 2495 cricket::Port* port = GetPort(&ch); |
2460 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), | 2496 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), |
2461 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2497 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
2462 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2498 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2463 ASSERT_TRUE(conn3 != nullptr); | 2499 ASSERT_TRUE(conn3 != nullptr); |
2464 EXPECT_EQ(conn2, ch.best_connection()); // Not writable yet. | 2500 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet. |
2465 conn3->ReceivedPingResponse(); // Become writable. | 2501 conn3->ReceivedPingResponse(); // Become writable. |
2466 EXPECT_EQ(conn3, ch.best_connection()); | 2502 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); |
2467 | 2503 |
2468 // Now another data packet will not switch the best connection because the | 2504 // Now another data packet will not switch the best connection because the |
2469 // best connection was nominated by the controlling side. | 2505 // best connection was nominated by the controlling side. |
2470 conn2->ReceivedPing(); | 2506 conn2->ReceivedPing(); |
2471 conn2->ReceivedPingResponse(); | 2507 conn2->ReceivedPingResponse(); |
2472 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 2508 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
2473 EXPECT_EQ(conn3, ch.best_connection()); | 2509 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); |
2510 } | |
2511 | |
2512 TEST_F(P2PTransportChannelPingTest, TestDonotSwitchConnectionTooFrequently) { | |
Taylor Brandstetter
2016/06/21 18:33:26
Rename test to ControlledAgentDoesntSwitchConnecti
honghaiz3
2016/06/22 08:03:16
Done.
| |
2513 rtc::ScopedFakeClock clock; | |
2514 | |
2515 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | |
2516 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | |
2517 PrepareChannel(&ch); | |
2518 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | |
2519 ch.Connect(); | |
2520 ch.MaybeStartGathering(); | |
2521 // The connections have decreasing priority. | |
2522 cricket::Connection* conn1 = | |
2523 CreateConnectionWithCandidate(ch, "1.1.1.1", 1, 10, true); | |
2524 ASSERT_TRUE(conn1 != nullptr); | |
2525 cricket::Connection* conn2 = | |
2526 CreateConnectionWithCandidate(ch, "2.2.2.2", 2, 9, true); | |
2527 ASSERT_TRUE(conn2 != nullptr); | |
2528 cricket::Connection* conn3 = | |
2529 CreateConnectionWithCandidate(ch, "3.3.3.3", 3, 8, false); | |
2530 ASSERT_TRUE(conn3 != nullptr); | |
2531 | |
2532 // Simulate aggressive nomination on the controlling side. | |
2533 get_and_reset_selected_candidate_pair_switches(); | |
2534 NominateConnection(conn2); | |
2535 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | |
2536 EXPECT_EQ(conn2, last_selected_candidate_pair()); | |
2537 | |
2538 // Selected candidate pair will switch because conn1 has higher priority. | |
2539 NominateConnection(conn1); | |
2540 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | |
2541 EXPECT_EQ(conn1, last_selected_candidate_pair()); | |
2542 | |
2543 // Advance the clock by 1ms so that the last data receiving timestamp of | |
2544 // conn2 is larger. | |
2545 SIMULATED_WAIT(false, 1, clock); | |
2546 // Selected candidate pair won't switch until conn2 receives data and becomes | |
2547 // writable again because conn2 has lower priority and may have been pruned. | |
2548 NominateConnection(conn2); | |
2549 conn2->ReceivedPingResponse(); | |
2550 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches()); | |
2551 // Will switch if conn2 receives data. | |
2552 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | |
2553 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | |
2554 EXPECT_EQ(conn2, last_selected_candidate_pair()); | |
2555 | |
2556 // Advance the clock by 1ms so that the last data receiving timestamp of | |
2557 // conn3 is larger. | |
2558 SIMULATED_WAIT(false, 1, clock); | |
2559 // Selected candidate pair won't switch even if it is nominated and | |
2560 // received data because it is not writable. | |
2561 NominateConnection(conn3); | |
2562 conn3->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | |
2563 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches()); | |
2564 // It will switch if it becomes writable | |
2565 conn3->ReceivedPingResponse(); | |
2566 EXPECT_EQ_SIMULATED_WAIT(1, get_and_reset_selected_candidate_pair_switches(), | |
2567 kDefaultTimeout, clock); | |
2568 EXPECT_EQ(conn3, last_selected_candidate_pair()); | |
2569 | |
2570 // Make sure sorting won't reselect candidate pair. | |
2571 SIMULATED_WAIT(false, 10, clock); | |
2572 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches()); | |
2474 } | 2573 } |
Taylor Brandstetter
2016/06/21 18:33:26
This test's expectations are good but it's testing
honghaiz3
2016/06/22 08:03:16
I break this into three, making each of them small
| |
2475 | 2574 |
2476 // Test that if a new remote candidate has the same address and port with | 2575 // Test that if a new remote candidate has the same address and port with |
2477 // an old one, it will be used to create a new connection. | 2576 // an old one, it will be used to create a new connection. |
2478 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) { | 2577 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) { |
2479 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2578 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2480 cricket::P2PTransportChannel ch("candidate reuse", 1, &pa); | 2579 cricket::P2PTransportChannel ch("candidate reuse", 1, &pa); |
2481 PrepareChannel(&ch); | 2580 PrepareChannel(&ch); |
2482 ch.Connect(); | 2581 ch.Connect(); |
2483 ch.MaybeStartGathering(); | 2582 ch.MaybeStartGathering(); |
2484 const std::string host_address = "1.1.1.1"; | 2583 const std::string host_address = "1.1.1.1"; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2517 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { | 2616 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { |
2518 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2617 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2519 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2618 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2520 PrepareChannel(&ch); | 2619 PrepareChannel(&ch); |
2521 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2620 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
2522 ch.Connect(); | 2621 ch.Connect(); |
2523 ch.MaybeStartGathering(); | 2622 ch.MaybeStartGathering(); |
2524 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2623 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
2525 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2624 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2526 ASSERT_TRUE(conn1 != nullptr); | 2625 ASSERT_TRUE(conn1 != nullptr); |
2527 EXPECT_EQ(conn1, ch.best_connection()); | 2626 EXPECT_EQ(conn1, ch.selected_connection()); |
2528 conn1->ReceivedPingResponse(); // Becomes writable and receiving | 2627 conn1->ReceivedPingResponse(); // Becomes writable and receiving |
2529 | 2628 |
2530 // When a higher-priority, nominated candidate comes in, the connections with | 2629 // When a higher-priority, nominated candidate comes in, the connections with |
2531 // lower-priority are pruned. | 2630 // lower-priority are pruned. |
2532 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); | 2631 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); |
2533 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2632 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2534 ASSERT_TRUE(conn2 != nullptr); | 2633 ASSERT_TRUE(conn2 != nullptr); |
2535 conn2->ReceivedPingResponse(); // Becomes writable and receiving | 2634 conn2->ReceivedPingResponse(); // Becomes writable and receiving |
2536 conn2->set_nominated(true); | 2635 conn2->set_nominated(true); |
2537 conn2->SignalNominated(conn2); | 2636 conn2->SignalNominated(conn2); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2582 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { | 2681 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
2583 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2682 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2584 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2683 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2585 PrepareChannel(&ch); | 2684 PrepareChannel(&ch); |
2586 ch.SetIceConfig(CreateIceConfig(1000, false)); | 2685 ch.SetIceConfig(CreateIceConfig(1000, false)); |
2587 ch.Connect(); | 2686 ch.Connect(); |
2588 ch.MaybeStartGathering(); | 2687 ch.MaybeStartGathering(); |
2589 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); | 2688 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); |
2590 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2689 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2591 ASSERT_TRUE(conn1 != nullptr); | 2690 ASSERT_TRUE(conn1 != nullptr); |
2592 EXPECT_EQ(conn1, ch.best_connection()); | 2691 EXPECT_EQ(conn1, ch.selected_connection()); |
2593 conn1->ReceivedPingResponse(); // Becomes writable and receiving | 2692 conn1->ReceivedPingResponse(); // Becomes writable and receiving |
2594 | 2693 |
2595 // Add a low-priority connection |conn2|, which will be pruned, but it will | 2694 // Add a low-priority connection |conn2|, which will be pruned, but it will |
2596 // not be deleted right away. Once the current best connection becomes not | 2695 // not be deleted right away. Once the current best connection becomes not |
2597 // receiving, |conn2| will start to ping and upon receiving the ping response, | 2696 // receiving, |conn2| will start to ping and upon receiving the ping response, |
2598 // it will become the best connection. | 2697 // it will become the best connection. |
2599 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); | 2698 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
2600 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2699 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2601 ASSERT_TRUE(conn2 != nullptr); | 2700 ASSERT_TRUE(conn2 != nullptr); |
2602 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 2701 EXPECT_TRUE_WAIT(!conn2->active(), 1000); |
2603 // |conn2| should not send a ping yet. | 2702 // |conn2| should not send a ping yet. |
2604 EXPECT_EQ(cricket::Connection::STATE_WAITING, conn2->state()); | 2703 EXPECT_EQ(cricket::Connection::STATE_WAITING, conn2->state()); |
2605 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2704 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); |
2606 // Wait for |conn1| becoming not receiving. | 2705 // Wait for |conn1| becoming not receiving. |
2607 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); | 2706 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); |
2608 // Make sure conn2 is not deleted. | 2707 // Make sure conn2 is not deleted. |
2609 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2708 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2610 ASSERT_TRUE(conn2 != nullptr); | 2709 ASSERT_TRUE(conn2 != nullptr); |
2611 EXPECT_EQ_WAIT(cricket::Connection::STATE_INPROGRESS, conn2->state(), 1000); | 2710 EXPECT_EQ_WAIT(cricket::Connection::STATE_INPROGRESS, conn2->state(), 1000); |
2612 conn2->ReceivedPingResponse(); | 2711 conn2->ReceivedPingResponse(); |
2613 EXPECT_EQ_WAIT(conn2, ch.best_connection(), 1000); | 2712 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), 1000); |
2614 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); | 2713 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); |
2615 | 2714 |
2616 // When |conn1| comes back again, |conn2| will be pruned again. | 2715 // When |conn1| comes back again, |conn2| will be pruned again. |
2617 conn1->ReceivedPingResponse(); | 2716 conn1->ReceivedPingResponse(); |
2618 EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000); | 2717 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), 1000); |
2619 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 2718 EXPECT_TRUE_WAIT(!conn2->active(), 1000); |
2620 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2719 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); |
2621 } | 2720 } |
2622 | 2721 |
2623 // Test that if all connections in a channel has timed out on writing, they | 2722 // Test that if all connections in a channel has timed out on writing, they |
2624 // will all be deleted. We use Prune to simulate write_time_out. | 2723 // will all be deleted. We use Prune to simulate write_time_out. |
2625 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { | 2724 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { |
2626 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2725 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2627 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2726 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2628 PrepareChannel(&ch); | 2727 PrepareChannel(&ch); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2798 | 2897 |
2799 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix | 2898 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix |
2800 the flakiness. The following test becomes flaky because we now ping the | 2899 the flakiness. The following test becomes flaky because we now ping the |
2801 connections with fast rates until every connection is pinged at least three | 2900 connections with fast rates until every connection is pinged at least three |
2802 times. The best connection may have been pinged before |max_strong_interval|, | 2901 times. The best connection may have been pinged before |max_strong_interval|, |
2803 so it may not be the next connection to be pinged as expected in the test. | 2902 so it may not be the next connection to be pinged as expected in the test. |
2804 | 2903 |
2805 // Verify that conn3 will be the "best connection" since it is readable and | 2904 // Verify that conn3 will be the "best connection" since it is readable and |
2806 // writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next | 2905 // writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next |
2807 // pingable connection. | 2906 // pingable connection. |
2808 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000); | 2907 EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), 5000); |
2809 WAIT(false, max_strong_interval + 100); | 2908 WAIT(false, max_strong_interval + 100); |
2810 conn3->ReceivedPingResponse(); | 2909 conn3->ReceivedPingResponse(); |
2811 ASSERT_TRUE(conn3->writable()); | 2910 ASSERT_TRUE(conn3->writable()); |
2812 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); | 2911 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); |
2813 | 2912 |
2814 */ | 2913 */ |
2815 } | 2914 } |
2816 | 2915 |
2817 // Test that Relay/Relay connections will be pinged first when everything has | 2916 // Test that Relay/Relay connections will be pinged first when everything has |
2818 // been pinged even if the Relay/Relay connection wasn't the first to be pinged | 2917 // been pinged even if the Relay/Relay connection wasn't the first to be pinged |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2916 | 3015 |
2917 // TCP Relay/Relay is the next. | 3016 // TCP Relay/Relay is the next. |
2918 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 3017 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
2919 cricket::RELAY_PORT_TYPE, | 3018 cricket::RELAY_PORT_TYPE, |
2920 cricket::TCP_PROTOCOL_NAME); | 3019 cricket::TCP_PROTOCOL_NAME); |
2921 | 3020 |
2922 // Finally, Local/Relay will be pinged. | 3021 // Finally, Local/Relay will be pinged. |
2923 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 3022 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
2924 cricket::RELAY_PORT_TYPE); | 3023 cricket::RELAY_PORT_TYPE); |
2925 } | 3024 } |
OLD | NEW |