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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 } | 482 } |
483 } | 483 } |
484 | 484 |
485 void Test(const Result& expected) { | 485 void Test(const Result& expected) { |
486 int32 connect_start = rtc::Time(), connect_time; | 486 int32 connect_start = rtc::Time(), connect_time; |
487 | 487 |
488 // Create the channels and wait for them to connect. | 488 // Create the channels and wait for them to connect. |
489 CreateChannels(1); | 489 CreateChannels(1); |
490 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && | 490 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && |
491 ep2_ch1() != NULL && | 491 ep2_ch1() != NULL && |
492 ep1_ch1()->readable() && | 492 ep1_ch1()->receiving() && |
493 ep1_ch1()->writable() && | 493 ep1_ch1()->writable() && |
494 ep2_ch1()->readable() && | 494 ep2_ch1()->receiving() && |
495 ep2_ch1()->writable(), | 495 ep2_ch1()->writable(), |
496 expected.connect_wait, | 496 expected.connect_wait, |
497 1000); | 497 1000); |
498 connect_time = rtc::TimeSince(connect_start); | 498 connect_time = rtc::TimeSince(connect_start); |
499 if (connect_time < expected.connect_wait) { | 499 if (connect_time < expected.connect_wait) { |
500 LOG(LS_INFO) << "Connect time: " << connect_time << " ms"; | 500 LOG(LS_INFO) << "Connect time: " << connect_time << " ms"; |
501 } else { | 501 } else { |
502 LOG(LS_INFO) << "Connect time: " << "TIMEOUT (" | 502 LOG(LS_INFO) << "Connect time: " << "TIMEOUT (" |
503 << expected.connect_wait << " ms)"; | 503 << expected.connect_wait << " ms)"; |
504 } | 504 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 if (channels == 2 && ep1_ch2() && ep2_ch2()) { | 551 if (channels == 2 && ep1_ch2() && ep2_ch2()) { |
552 // local_channel2 <==> remote_channel2 | 552 // local_channel2 <==> remote_channel2 |
553 EXPECT_EQ_WAIT(len, SendData(ep1_ch2(), data, len), 1000); | 553 EXPECT_EQ_WAIT(len, SendData(ep1_ch2(), data, len), 1000); |
554 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch2(), data, len), 1000); | 554 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch2(), data, len), 1000); |
555 EXPECT_EQ_WAIT(len, SendData(ep2_ch2(), data, len), 1000); | 555 EXPECT_EQ_WAIT(len, SendData(ep2_ch2(), data, len), 1000); |
556 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch2(), data, len), 1000); | 556 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch2(), data, len), 1000); |
557 } | 557 } |
558 } | 558 } |
559 } | 559 } |
560 | 560 |
561 // This test waits for the transport to become readable and writable on both | 561 // This test waits for the transport to become receiving and writable on both |
562 // end points. Once they are, the end points set new local ice credentials to | 562 // end points. Once they are, the end points set new local ice credentials to |
563 // restart the ice gathering. Finally it waits for the transport to select a | 563 // restart the ice gathering. Finally it waits for the transport to select a |
564 // new connection using the newly generated ice candidates. | 564 // new connection using the newly generated ice candidates. |
565 // Before calling this function the end points must be configured. | 565 // Before calling this function the end points must be configured. |
566 void TestHandleIceUfragPasswordChanged() { | 566 void TestHandleIceUfragPasswordChanged() { |
567 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 567 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
568 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 568 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); |
569 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->readable() && ep1_ch1()->writable() && | 569 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
570 ep2_ch1()->readable() && ep2_ch1()->writable(), | 570 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
571 1000, 1000); | 571 1000, 1000); |
572 | 572 |
573 const cricket::Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1()); | 573 const cricket::Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1()); |
574 const cricket::Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1()); | 574 const cricket::Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1()); |
575 const cricket::Candidate* old_remote_candidate1 = | 575 const cricket::Candidate* old_remote_candidate1 = |
576 RemoteCandidate(ep1_ch1()); | 576 RemoteCandidate(ep1_ch1()); |
577 const cricket::Candidate* old_remote_candidate2 = | 577 const cricket::Candidate* old_remote_candidate2 = |
578 RemoteCandidate(ep2_ch1()); | 578 RemoteCandidate(ep2_ch1()); |
579 | 579 |
580 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); | 580 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); |
(...skipping 23 matching lines...) Expand all Loading... |
604 SetIceRole(1, cricket::ICEROLE_CONTROLLING); | 604 SetIceRole(1, cricket::ICEROLE_CONTROLLING); |
605 SetIceTiebreaker(1, kTiebreaker2); | 605 SetIceTiebreaker(1, kTiebreaker2); |
606 | 606 |
607 // Creating channels with both channels role set to CONTROLLING. | 607 // Creating channels with both channels role set to CONTROLLING. |
608 CreateChannels(1); | 608 CreateChannels(1); |
609 // Since both the channels initiated with controlling state and channel2 | 609 // Since both the channels initiated with controlling state and channel2 |
610 // has higher tiebreaker value, channel1 should receive SignalRoleConflict. | 610 // has higher tiebreaker value, channel1 should receive SignalRoleConflict. |
611 EXPECT_TRUE_WAIT(GetRoleConflict(0), 1000); | 611 EXPECT_TRUE_WAIT(GetRoleConflict(0), 1000); |
612 EXPECT_FALSE(GetRoleConflict(1)); | 612 EXPECT_FALSE(GetRoleConflict(1)); |
613 | 613 |
614 EXPECT_TRUE_WAIT(ep1_ch1()->readable() && | 614 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && |
615 ep1_ch1()->writable() && | 615 ep1_ch1()->writable() && |
616 ep2_ch1()->readable() && | 616 ep2_ch1()->receiving() && |
617 ep2_ch1()->writable(), | 617 ep2_ch1()->writable(), |
618 1000); | 618 1000); |
619 | 619 |
620 EXPECT_TRUE(ep1_ch1()->best_connection() && | 620 EXPECT_TRUE(ep1_ch1()->best_connection() && |
621 ep2_ch1()->best_connection()); | 621 ep2_ch1()->best_connection()); |
622 | 622 |
623 TestSendRecv(1); | 623 TestSendRecv(1); |
624 } | 624 } |
625 | 625 |
626 // We pass the candidates directly to the other side. | 626 // We pass the candidates directly to the other side. |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 CreateChannels(1); | 1089 CreateChannels(1); |
1090 TestHandleIceUfragPasswordChanged(); | 1090 TestHandleIceUfragPasswordChanged(); |
1091 DestroyChannels(); | 1091 DestroyChannels(); |
1092 } | 1092 } |
1093 | 1093 |
1094 // Test the operation of GetStats. | 1094 // Test the operation of GetStats. |
1095 TEST_F(P2PTransportChannelTest, GetStats) { | 1095 TEST_F(P2PTransportChannelTest, GetStats) { |
1096 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1096 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
1097 kDefaultPortAllocatorFlags); | 1097 kDefaultPortAllocatorFlags); |
1098 CreateChannels(1); | 1098 CreateChannels(1); |
1099 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->readable() && ep1_ch1()->writable() && | 1099 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1100 ep2_ch1()->readable() && ep2_ch1()->writable(), | 1100 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1101 1000, 1000); | 1101 1000, 1000); |
1102 TestSendRecv(1); | 1102 TestSendRecv(1); |
1103 cricket::ConnectionInfos infos; | 1103 cricket::ConnectionInfos infos; |
1104 ASSERT_TRUE(ep1_ch1()->GetStats(&infos)); | 1104 ASSERT_TRUE(ep1_ch1()->GetStats(&infos)); |
1105 ASSERT_EQ(1U, infos.size()); | 1105 ASSERT_EQ(1U, infos.size()); |
1106 EXPECT_TRUE(infos[0].new_connection); | 1106 EXPECT_TRUE(infos[0].new_connection); |
1107 EXPECT_TRUE(infos[0].best_connection); | 1107 EXPECT_TRUE(infos[0].best_connection); |
1108 EXPECT_TRUE(infos[0].readable); | 1108 EXPECT_TRUE(infos[0].receiving); |
1109 EXPECT_TRUE(infos[0].writable); | 1109 EXPECT_TRUE(infos[0].writable); |
1110 EXPECT_FALSE(infos[0].timeout); | 1110 EXPECT_FALSE(infos[0].timeout); |
1111 EXPECT_EQ(10U, infos[0].sent_total_packets); | 1111 EXPECT_EQ(10U, infos[0].sent_total_packets); |
1112 EXPECT_EQ(0U, infos[0].sent_discarded_packets); | 1112 EXPECT_EQ(0U, infos[0].sent_discarded_packets); |
1113 EXPECT_EQ(10 * 36U, infos[0].sent_total_bytes); | 1113 EXPECT_EQ(10 * 36U, infos[0].sent_total_bytes); |
1114 EXPECT_EQ(10 * 36U, infos[0].recv_total_bytes); | 1114 EXPECT_EQ(10 * 36U, infos[0].recv_total_bytes); |
1115 EXPECT_GT(infos[0].rtt, 0U); | 1115 EXPECT_GT(infos[0].rtt, 0U); |
1116 DestroyChannels(); | 1116 DestroyChannels(); |
1117 } | 1117 } |
1118 | 1118 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 ConfigureEndpoints(NAT_FULL_CONE, OPEN, kDefaultPortAllocatorFlags, | 1223 ConfigureEndpoints(NAT_FULL_CONE, OPEN, kDefaultPortAllocatorFlags, |
1224 kDefaultPortAllocatorFlags); | 1224 kDefaultPortAllocatorFlags); |
1225 | 1225 |
1226 SetAllocatorFlags(0, kOnlyLocalPorts); | 1226 SetAllocatorFlags(0, kOnlyLocalPorts); |
1227 CreateChannels(1); | 1227 CreateChannels(1); |
1228 ep1_ch1()->set_incoming_only(true); | 1228 ep1_ch1()->set_incoming_only(true); |
1229 | 1229 |
1230 // Pump for 1 second and verify that the channels are not connected. | 1230 // Pump for 1 second and verify that the channels are not connected. |
1231 rtc::Thread::Current()->ProcessMessages(1000); | 1231 rtc::Thread::Current()->ProcessMessages(1000); |
1232 | 1232 |
1233 EXPECT_FALSE(ep1_ch1()->readable()); | 1233 EXPECT_FALSE(ep1_ch1()->receiving()); |
1234 EXPECT_FALSE(ep1_ch1()->writable()); | 1234 EXPECT_FALSE(ep1_ch1()->writable()); |
1235 EXPECT_FALSE(ep2_ch1()->readable()); | 1235 EXPECT_FALSE(ep2_ch1()->receiving()); |
1236 EXPECT_FALSE(ep2_ch1()->writable()); | 1236 EXPECT_FALSE(ep2_ch1()->writable()); |
1237 | 1237 |
1238 DestroyChannels(); | 1238 DestroyChannels(); |
1239 } | 1239 } |
1240 | 1240 |
1241 // Test that a peer behind NAT can connect to a peer that has | 1241 // Test that a peer behind NAT can connect to a peer that has |
1242 // incoming_only flag set. | 1242 // incoming_only flag set. |
1243 TEST_F(P2PTransportChannelTest, IncomingOnlyOpen) { | 1243 TEST_F(P2PTransportChannelTest, IncomingOnlyOpen) { |
1244 ConfigureEndpoints(OPEN, NAT_FULL_CONE, kDefaultPortAllocatorFlags, | 1244 ConfigureEndpoints(OPEN, NAT_FULL_CONE, kDefaultPortAllocatorFlags, |
1245 kDefaultPortAllocatorFlags); | 1245 kDefaultPortAllocatorFlags); |
1246 | 1246 |
1247 SetAllocatorFlags(0, kOnlyLocalPorts); | 1247 SetAllocatorFlags(0, kOnlyLocalPorts); |
1248 CreateChannels(1); | 1248 CreateChannels(1); |
1249 ep1_ch1()->set_incoming_only(true); | 1249 ep1_ch1()->set_incoming_only(true); |
1250 | 1250 |
1251 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && | 1251 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && |
1252 ep1_ch1()->readable() && ep1_ch1()->writable() && | 1252 ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1253 ep2_ch1()->readable() && ep2_ch1()->writable(), | 1253 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1254 1000, 1000); | 1254 1000, 1000); |
1255 | 1255 |
1256 DestroyChannels(); | 1256 DestroyChannels(); |
1257 } | 1257 } |
1258 | 1258 |
1259 TEST_F(P2PTransportChannelTest, TestTcpConnectionsFromActiveToPassive) { | 1259 TEST_F(P2PTransportChannelTest, TestTcpConnectionsFromActiveToPassive) { |
1260 AddAddress(0, kPublicAddrs[0]); | 1260 AddAddress(0, kPublicAddrs[0]); |
1261 AddAddress(1, kPublicAddrs[1]); | 1261 AddAddress(1, kPublicAddrs[1]); |
1262 | 1262 |
1263 SetAllocationStepDelay(0, kMinimumStepDelay); | 1263 SetAllocationStepDelay(0, kMinimumStepDelay); |
1264 SetAllocationStepDelay(1, kMinimumStepDelay); | 1264 SetAllocationStepDelay(1, kMinimumStepDelay); |
1265 | 1265 |
1266 int kOnlyLocalTcpPorts = cricket::PORTALLOCATOR_DISABLE_UDP | | 1266 int kOnlyLocalTcpPorts = cricket::PORTALLOCATOR_DISABLE_UDP | |
1267 cricket::PORTALLOCATOR_DISABLE_STUN | | 1267 cricket::PORTALLOCATOR_DISABLE_STUN | |
1268 cricket::PORTALLOCATOR_DISABLE_RELAY; | 1268 cricket::PORTALLOCATOR_DISABLE_RELAY; |
1269 // Disable all protocols except TCP. | 1269 // Disable all protocols except TCP. |
1270 SetAllocatorFlags(0, kOnlyLocalTcpPorts); | 1270 SetAllocatorFlags(0, kOnlyLocalTcpPorts); |
1271 SetAllocatorFlags(1, kOnlyLocalTcpPorts); | 1271 SetAllocatorFlags(1, kOnlyLocalTcpPorts); |
1272 | 1272 |
1273 SetAllowTcpListen(0, true); // actpass. | 1273 SetAllowTcpListen(0, true); // actpass. |
1274 SetAllowTcpListen(1, false); // active. | 1274 SetAllowTcpListen(1, false); // active. |
1275 | 1275 |
1276 CreateChannels(1); | 1276 CreateChannels(1); |
1277 | 1277 |
1278 EXPECT_TRUE_WAIT(ep1_ch1()->readable() && ep1_ch1()->writable() && | 1278 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1279 ep2_ch1()->readable() && ep2_ch1()->writable(), | 1279 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1280 1000); | 1280 1000); |
1281 EXPECT_TRUE( | 1281 EXPECT_TRUE( |
1282 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1282 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
1283 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1283 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1284 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1284 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1285 | 1285 |
1286 std::string kTcpProtocol = "tcp"; | 1286 std::string kTcpProtocol = "tcp"; |
1287 EXPECT_EQ(kTcpProtocol, RemoteCandidate(ep1_ch1())->protocol()); | 1287 EXPECT_EQ(kTcpProtocol, RemoteCandidate(ep1_ch1())->protocol()); |
1288 EXPECT_EQ(kTcpProtocol, LocalCandidate(ep1_ch1())->protocol()); | 1288 EXPECT_EQ(kTcpProtocol, LocalCandidate(ep1_ch1())->protocol()); |
1289 EXPECT_EQ(kTcpProtocol, RemoteCandidate(ep2_ch1())->protocol()); | 1289 EXPECT_EQ(kTcpProtocol, RemoteCandidate(ep2_ch1())->protocol()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 ep1_ch1()->SetIceTiebreaker(kTiebreaker2); | 1324 ep1_ch1()->SetIceTiebreaker(kTiebreaker2); |
1325 | 1325 |
1326 const std::vector<cricket::PortInterface *> ports_after = ep1_ch1()->ports(); | 1326 const std::vector<cricket::PortInterface *> ports_after = ep1_ch1()->ports(); |
1327 for (size_t i = 0; i < ports_after.size(); ++i) { | 1327 for (size_t i = 0; i < ports_after.size(); ++i) { |
1328 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, ports_before[i]->GetIceRole()); | 1328 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, ports_before[i]->GetIceRole()); |
1329 // SetIceTiebreaker after Connect() has been called will fail. So expect the | 1329 // SetIceTiebreaker after Connect() has been called will fail. So expect the |
1330 // original value. | 1330 // original value. |
1331 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); | 1331 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); |
1332 } | 1332 } |
1333 | 1333 |
1334 EXPECT_TRUE_WAIT(ep1_ch1()->readable() && | 1334 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && |
1335 ep1_ch1()->writable() && | 1335 ep1_ch1()->writable() && |
1336 ep2_ch1()->readable() && | 1336 ep2_ch1()->receiving() && |
1337 ep2_ch1()->writable(), | 1337 ep2_ch1()->writable(), |
1338 1000); | 1338 1000); |
1339 | 1339 |
1340 EXPECT_TRUE(ep1_ch1()->best_connection() && | 1340 EXPECT_TRUE(ep1_ch1()->best_connection() && |
1341 ep2_ch1()->best_connection()); | 1341 ep2_ch1()->best_connection()); |
1342 | 1342 |
1343 TestSendRecv(1); | 1343 TestSendRecv(1); |
1344 DestroyChannels(); | 1344 DestroyChannels(); |
1345 } | 1345 } |
1346 | 1346 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 | 1381 |
1382 SetAllocationStepDelay(0, kMinimumStepDelay); | 1382 SetAllocationStepDelay(0, kMinimumStepDelay); |
1383 SetAllocationStepDelay(1, kMinimumStepDelay); | 1383 SetAllocationStepDelay(1, kMinimumStepDelay); |
1384 | 1384 |
1385 // Enable IPv6 | 1385 // Enable IPv6 |
1386 SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_IPV6); | 1386 SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_IPV6); |
1387 SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_IPV6); | 1387 SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_IPV6); |
1388 | 1388 |
1389 CreateChannels(1); | 1389 CreateChannels(1); |
1390 | 1390 |
1391 EXPECT_TRUE_WAIT(ep1_ch1()->readable() && ep1_ch1()->writable() && | 1391 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1392 ep2_ch1()->readable() && ep2_ch1()->writable(), | 1392 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1393 1000); | 1393 1000); |
1394 EXPECT_TRUE( | 1394 EXPECT_TRUE( |
1395 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1395 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
1396 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) && | 1396 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) && |
1397 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1])); | 1397 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1])); |
1398 | 1398 |
1399 TestSendRecv(1); | 1399 TestSendRecv(1); |
1400 DestroyChannels(); | 1400 DestroyChannels(); |
1401 } | 1401 } |
1402 | 1402 |
1403 // Testing forceful TURN connections. | 1403 // Testing forceful TURN connections. |
1404 TEST_F(P2PTransportChannelTest, TestForceTurn) { | 1404 TEST_F(P2PTransportChannelTest, TestForceTurn) { |
1405 ConfigureEndpoints( | 1405 ConfigureEndpoints( |
1406 NAT_PORT_RESTRICTED, NAT_SYMMETRIC, | 1406 NAT_PORT_RESTRICTED, NAT_SYMMETRIC, |
1407 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET, | 1407 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET, |
1408 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1408 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1409 set_force_relay(true); | 1409 set_force_relay(true); |
1410 | 1410 |
1411 SetAllocationStepDelay(0, kMinimumStepDelay); | 1411 SetAllocationStepDelay(0, kMinimumStepDelay); |
1412 SetAllocationStepDelay(1, kMinimumStepDelay); | 1412 SetAllocationStepDelay(1, kMinimumStepDelay); |
1413 | 1413 |
1414 CreateChannels(1); | 1414 CreateChannels(1); |
1415 | 1415 |
1416 EXPECT_TRUE_WAIT(ep1_ch1()->readable() && ep1_ch1()->writable() && | 1416 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1417 ep2_ch1()->readable() && ep2_ch1()->writable(), | 1417 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1418 2000); | 1418 2000); |
1419 | 1419 |
1420 EXPECT_TRUE(ep1_ch1()->best_connection() && | 1420 EXPECT_TRUE(ep1_ch1()->best_connection() && |
1421 ep2_ch1()->best_connection()); | 1421 ep2_ch1()->best_connection()); |
1422 | 1422 |
1423 EXPECT_EQ("relay", RemoteCandidate(ep1_ch1())->type()); | 1423 EXPECT_EQ("relay", RemoteCandidate(ep1_ch1())->type()); |
1424 EXPECT_EQ("relay", LocalCandidate(ep1_ch1())->type()); | 1424 EXPECT_EQ("relay", LocalCandidate(ep1_ch1())->type()); |
1425 EXPECT_EQ("relay", RemoteCandidate(ep2_ch1())->type()); | 1425 EXPECT_EQ("relay", RemoteCandidate(ep2_ch1())->type()); |
1426 EXPECT_EQ("relay", LocalCandidate(ep2_ch1())->type()); | 1426 EXPECT_EQ("relay", LocalCandidate(ep2_ch1())->type()); |
1427 | 1427 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 // priority than others. This is due to FakeNetwork::AddInterface method. | 1485 // priority than others. This is due to FakeNetwork::AddInterface method. |
1486 AddAddress(1, kAlternateAddrs[1]); | 1486 AddAddress(1, kAlternateAddrs[1]); |
1487 AddAddress(1, kPublicAddrs[1]); | 1487 AddAddress(1, kPublicAddrs[1]); |
1488 | 1488 |
1489 // Use only local ports for simplicity. | 1489 // Use only local ports for simplicity. |
1490 SetAllocatorFlags(0, kOnlyLocalPorts); | 1490 SetAllocatorFlags(0, kOnlyLocalPorts); |
1491 SetAllocatorFlags(1, kOnlyLocalPorts); | 1491 SetAllocatorFlags(1, kOnlyLocalPorts); |
1492 | 1492 |
1493 // Create channels and let them go writable, as usual. | 1493 // Create channels and let them go writable, as usual. |
1494 CreateChannels(1); | 1494 CreateChannels(1); |
1495 EXPECT_TRUE_WAIT(ep1_ch1()->readable() && ep1_ch1()->writable() && | 1495 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1496 ep2_ch1()->readable() && ep2_ch1()->writable(), | 1496 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1497 1000); | 1497 1000); |
1498 EXPECT_TRUE( | 1498 EXPECT_TRUE( |
1499 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1499 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
1500 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1500 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1501 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1501 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1502 | 1502 |
1503 // Blackhole any traffic to or from the public addrs. | 1503 // Blackhole any traffic to or from the public addrs. |
1504 LOG(LS_INFO) << "Failing over..."; | 1504 LOG(LS_INFO) << "Failing over..."; |
1505 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, | 1505 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, |
1506 kPublicAddrs[1]); | 1506 kPublicAddrs[1]); |
(...skipping 22 matching lines...) Expand all Loading... |
1529 // Test that we can switch links in a coordinated fashion. | 1529 // Test that we can switch links in a coordinated fashion. |
1530 TEST_F(P2PTransportChannelMultihomedTest, TestDrain) { | 1530 TEST_F(P2PTransportChannelMultihomedTest, TestDrain) { |
1531 AddAddress(0, kPublicAddrs[0]); | 1531 AddAddress(0, kPublicAddrs[0]); |
1532 AddAddress(1, kPublicAddrs[1]); | 1532 AddAddress(1, kPublicAddrs[1]); |
1533 // Use only local ports for simplicity. | 1533 // Use only local ports for simplicity. |
1534 SetAllocatorFlags(0, kOnlyLocalPorts); | 1534 SetAllocatorFlags(0, kOnlyLocalPorts); |
1535 SetAllocatorFlags(1, kOnlyLocalPorts); | 1535 SetAllocatorFlags(1, kOnlyLocalPorts); |
1536 | 1536 |
1537 // Create channels and let them go writable, as usual. | 1537 // Create channels and let them go writable, as usual. |
1538 CreateChannels(1); | 1538 CreateChannels(1); |
1539 EXPECT_TRUE_WAIT(ep1_ch1()->readable() && ep1_ch1()->writable() && | 1539 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1540 ep2_ch1()->readable() && ep2_ch1()->writable(), | 1540 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1541 1000); | 1541 1000); |
1542 EXPECT_TRUE( | 1542 EXPECT_TRUE( |
1543 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1543 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
1544 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1544 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1545 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1545 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1546 | 1546 |
1547 | 1547 |
1548 // Remove the public interface, add the alternate interface, and allocate | 1548 // Remove the public interface, add the alternate interface, and allocate |
1549 // a new generation of candidates for the new interface (via Connect()). | 1549 // a new generation of candidates for the new interface (via Connect()). |
1550 LOG(LS_INFO) << "Draining..."; | 1550 LOG(LS_INFO) << "Draining..."; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1677 PrepareChannel(&ch); | 1677 PrepareChannel(&ch); |
1678 ch.Connect(); | 1678 ch.Connect(); |
1679 | 1679 |
1680 // Create conn1 and keep track of original candidate priority. | 1680 // Create conn1 and keep track of original candidate priority. |
1681 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1681 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
1682 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1682 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
1683 ASSERT_TRUE(conn1 != nullptr); | 1683 ASSERT_TRUE(conn1 != nullptr); |
1684 uint32 remote_priority = conn1->remote_candidate().priority(); | 1684 uint32 remote_priority = conn1->remote_candidate().priority(); |
1685 | 1685 |
1686 // Create a higher priority candidate and make the connection | 1686 // Create a higher priority candidate and make the connection |
1687 // readable/writable. This will prune conn1. | 1687 // receiving/writable. This will prune conn1. |
1688 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1688 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
1689 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1689 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
1690 ASSERT_TRUE(conn2 != nullptr); | 1690 ASSERT_TRUE(conn2 != nullptr); |
1691 conn2->ReceivedPing(); | 1691 conn2->ReceivedPing(); |
1692 conn2->ReceivedPingResponse(); | 1692 conn2->ReceivedPingResponse(); |
1693 | 1693 |
1694 // Wait for conn1 being destroyed. | 1694 // Wait for conn1 to be destroyed. |
1695 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 3000); | 1695 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 3000); |
1696 cricket::Port* port = GetPort(&ch); | 1696 cricket::Port* port = GetPort(&ch); |
1697 | 1697 |
1698 // Create a minimal STUN message with prflx priority. | 1698 // Create a minimal STUN message with prflx priority. |
1699 cricket::IceMessage request; | 1699 cricket::IceMessage request; |
1700 request.SetType(cricket::STUN_BINDING_REQUEST); | 1700 request.SetType(cricket::STUN_BINDING_REQUEST); |
1701 request.AddAttribute(new cricket::StunByteStringAttribute( | 1701 request.AddAttribute(new cricket::StunByteStringAttribute( |
1702 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 1702 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); |
1703 uint32 prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 1703 uint32 prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; |
1704 request.AddAttribute(new cricket::StunUInt32Attribute( | 1704 request.AddAttribute(new cricket::StunUInt32Attribute( |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1876 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1876 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
1877 ASSERT_TRUE(conn1 != nullptr); | 1877 ASSERT_TRUE(conn1 != nullptr); |
1878 EXPECT_EQ(conn1, ch.best_connection()); | 1878 EXPECT_EQ(conn1, ch.best_connection()); |
1879 | 1879 |
1880 // If a data packet is received on conn2, the best connection should | 1880 // If a data packet is received on conn2, the best connection should |
1881 // switch to conn2 because the controlled side must mirror the media path | 1881 // switch to conn2 because the controlled side must mirror the media path |
1882 // chosen by the controlling side. | 1882 // chosen by the controlling side. |
1883 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); | 1883 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); |
1884 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1884 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
1885 ASSERT_TRUE(conn2 != nullptr); | 1885 ASSERT_TRUE(conn2 != nullptr); |
1886 conn2->ReceivedPing(); // Become readable. | 1886 conn2->ReceivedPing(); // Start receiving. |
1887 // Do not switch because it is not writable. | 1887 // Do not switch because it is not writable. |
1888 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 1888 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
1889 EXPECT_EQ(conn1, ch.best_connection()); | 1889 EXPECT_EQ(conn1, ch.best_connection()); |
1890 | 1890 |
1891 conn2->ReceivedPingResponse(); // Become writable. | 1891 conn2->ReceivedPingResponse(); // Become writable. |
1892 // Switch because it is writable. | 1892 // Switch because it is writable. |
1893 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0)); | 1893 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0)); |
1894 EXPECT_EQ(conn2, ch.best_connection()); | 1894 EXPECT_EQ(conn2, ch.best_connection()); |
1895 | 1895 |
1896 // Now another STUN message with an unknown address and use_candidate will | 1896 // Now another STUN message with an unknown address and use_candidate will |
(...skipping 16 matching lines...) Expand all Loading... |
1913 conn3->ReceivedPingResponse(); // Become writable. | 1913 conn3->ReceivedPingResponse(); // Become writable. |
1914 EXPECT_EQ(conn3, ch.best_connection()); | 1914 EXPECT_EQ(conn3, ch.best_connection()); |
1915 | 1915 |
1916 // Now another data packet will not switch the best connection because the | 1916 // Now another data packet will not switch the best connection because the |
1917 // best connection was nominated by the controlling side. | 1917 // best connection was nominated by the controlling side. |
1918 conn2->ReceivedPing(); | 1918 conn2->ReceivedPing(); |
1919 conn2->ReceivedPingResponse(); | 1919 conn2->ReceivedPingResponse(); |
1920 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 1920 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
1921 EXPECT_EQ(conn3, ch.best_connection()); | 1921 EXPECT_EQ(conn3, ch.best_connection()); |
1922 } | 1922 } |
OLD | NEW |