Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 1311433009: A few updates on connection states (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Merge with the head Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 // Test that we can establish connectivity when both peers are multihomed. 1475 // Test that we can establish connectivity when both peers are multihomed.
1476 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { 1476 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) {
1477 AddAddress(0, kPublicAddrs[0]); 1477 AddAddress(0, kPublicAddrs[0]);
1478 AddAddress(0, kAlternateAddrs[0]); 1478 AddAddress(0, kAlternateAddrs[0]);
1479 AddAddress(1, kPublicAddrs[1]); 1479 AddAddress(1, kPublicAddrs[1]);
1480 AddAddress(1, kAlternateAddrs[1]); 1480 AddAddress(1, kAlternateAddrs[1]);
1481 Test(kLocalUdpToLocalUdp); 1481 Test(kLocalUdpToLocalUdp);
1482 } 1482 }
1483 1483
1484 // Test that we can quickly switch links if an interface goes down. 1484 // Test that we can quickly switch links if an interface goes down.
1485 TEST_F(P2PTransportChannelMultihomedTest, TestFailover) { 1485 // The controlled side has two interfaces and one will die.
1486 TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControlledSide) {
1486 AddAddress(0, kPublicAddrs[0]); 1487 AddAddress(0, kPublicAddrs[0]);
1487 // Adding alternate address will make sure |kPublicAddrs| has the higher 1488 // Adding alternate address will make sure |kPublicAddrs| has the higher
1488 // priority than others. This is due to FakeNetwork::AddInterface method. 1489 // priority than others. This is due to FakeNetwork::AddInterface method.
1489 AddAddress(1, kAlternateAddrs[1]); 1490 AddAddress(1, kAlternateAddrs[1]);
1490 AddAddress(1, kPublicAddrs[1]); 1491 AddAddress(1, kPublicAddrs[1]);
1491 1492
1492 // Use only local ports for simplicity. 1493 // Use only local ports for simplicity.
1493 SetAllocatorFlags(0, kOnlyLocalPorts); 1494 SetAllocatorFlags(0, kOnlyLocalPorts);
1494 SetAllocatorFlags(1, kOnlyLocalPorts); 1495 SetAllocatorFlags(1, kOnlyLocalPorts);
1495 1496
1496 // Create channels and let them go writable, as usual. 1497 // Create channels and let them go writable, as usual.
1497 CreateChannels(1); 1498 CreateChannels(1);
1499
1500 // Make the receiving timeout shorter for testing.
1501 ep1_ch1()->SetReceivingTimeout(1000);
1502 ep2_ch1()->SetReceivingTimeout(1000);
1503
1498 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1504 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1499 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1505 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1500 1000); 1506 1000);
1501 EXPECT_TRUE( 1507 EXPECT_TRUE(
1502 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 1508 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
1503 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 1509 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
1504 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 1510 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
1505 1511
1506 // Blackhole any traffic to or from the public addrs. 1512 // Blackhole any traffic to or from the public addrs.
1507 LOG(LS_INFO) << "Failing over..."; 1513 LOG(LS_INFO) << "Failing over...";
1508 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, 1514 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]);
1509 kPublicAddrs[1]); 1515 // The best connections will switch, so keep references to them.
1516 const cricket::Connection* best_connection1 = ep1_ch1()->best_connection();
1517 const cricket::Connection* best_connection2 = ep2_ch1()->best_connection();
1518 // We should detect loss of receiving within 1 second or so.
1519 EXPECT_TRUE_WAIT(
1520 !best_connection1->receiving() && !best_connection2->receiving(), 3000);
1510 1521
1511 // We should detect loss of connectivity within 5 seconds or so. 1522 // We should switch over to use the alternate addr immediately on both sides
1512 EXPECT_TRUE_WAIT(!ep1_ch1()->writable(), 7000); 1523 // when we are not receiving.
1513
1514 // We should switch over to use the alternate addr immediately
1515 // when we lose writability.
1516 EXPECT_TRUE_WAIT( 1524 EXPECT_TRUE_WAIT(
1517 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 1525 ep1_ch1()->best_connection()->receiving() &&
1518 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 1526 ep2_ch1()->best_connection()->receiving(), 1000);
1519 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), 1527 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]));
1520 3000); 1528 EXPECT_TRUE(
1529 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]));
1530 EXPECT_TRUE(
1531 LocalCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[1]));
1521 1532
1522 DestroyChannels(); 1533 DestroyChannels();
1523 } 1534 }
1535
1536 // Test that we can quickly switch links if an interface goes down.
1537 // The controlling side has two interfaces and one will die.
1538 TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControllingSide) {
1539 // Adding alternate address will make sure |kPublicAddrs| has the higher
1540 // priority than others. This is due to FakeNetwork::AddInterface method.
1541 AddAddress(0, kAlternateAddrs[0]);
1542 AddAddress(0, kPublicAddrs[0]);
1543 AddAddress(1, kPublicAddrs[1]);
1544
1545 // Use only local ports for simplicity.
1546 SetAllocatorFlags(0, kOnlyLocalPorts);
1547 SetAllocatorFlags(1, kOnlyLocalPorts);
1548
1549 // Create channels and let them go writable, as usual.
1550 CreateChannels(1);
1551 // Make the receiving timeout shorter for testing.
1552 ep1_ch1()->SetReceivingTimeout(1000);
1553 ep2_ch1()->SetReceivingTimeout(1000);
1554 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1555 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1556 1000);
1557 EXPECT_TRUE(
1558 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
1559 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
1560 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
1561
1562 // Blackhole any traffic to or from the public addrs.
1563 LOG(LS_INFO) << "Failing over...";
1564 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]);
1565 // The best connections will switch, so keep references to them.
1566 const cricket::Connection* best_connection1 = ep1_ch1()->best_connection();
1567 const cricket::Connection* best_connection2 = ep2_ch1()->best_connection();
1568 // We should detect loss of receiving within 1 second or so.
1569 EXPECT_TRUE_WAIT(
1570 !best_connection1->receiving() && !best_connection2->receiving(), 3000);
1571
1572 // We should switch over to use the alternate addr immediately on both sides
1573 // when we are not receiving.
1574 EXPECT_TRUE_WAIT(
1575 ep1_ch1()->best_connection()->receiving() &&
1576 ep2_ch1()->best_connection()->receiving(), 1000);
1577 EXPECT_TRUE(
1578 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]));
1579 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
1580 EXPECT_TRUE(
1581 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0]));
1582
1583 DestroyChannels();
1584 }
1524 1585
1525 /* 1586 /*
1526 1587
1527 TODO(pthatcher): Once have a way to handle network interfaces changes 1588 TODO(pthatcher): Once have a way to handle network interfaces changes
1528 without signalling an ICE restart, put a test like this back. In the 1589 without signalling an ICE restart, put a test like this back. In the
1529 mean time, this test only worked for GICE. With ICE, it's currently 1590 mean time, this test only worked for GICE. With ICE, it's currently
1530 not possible without an ICE restart. 1591 not possible without an ICE restart.
1531 1592
1532 // Test that we can switch links in a coordinated fashion. 1593 // Test that we can switch links in a coordinated fashion.
1533 TEST_F(P2PTransportChannelMultihomedTest, TestDrain) { 1594 TEST_F(P2PTransportChannelMultihomedTest, TestDrain) {
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 conn3->ReceivedPingResponse(); // Become writable. 1985 conn3->ReceivedPingResponse(); // Become writable.
1925 EXPECT_EQ(conn3, ch.best_connection()); 1986 EXPECT_EQ(conn3, ch.best_connection());
1926 1987
1927 // Now another data packet will not switch the best connection because the 1988 // Now another data packet will not switch the best connection because the
1928 // best connection was nominated by the controlling side. 1989 // best connection was nominated by the controlling side.
1929 conn2->ReceivedPing(); 1990 conn2->ReceivedPing();
1930 conn2->ReceivedPingResponse(); 1991 conn2->ReceivedPingResponse();
1931 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); 1992 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
1932 EXPECT_EQ(conn3, ch.best_connection()); 1993 EXPECT_EQ(conn3, ch.best_connection());
1933 } 1994 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698