| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/nqe/network_quality_estimator.h" | 5 #include "net/nqe/network_quality_estimator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 const base::TimeDelta old_url_rtt = base::TimeDelta::FromMilliseconds(1); | 944 const base::TimeDelta old_url_rtt = base::TimeDelta::FromMilliseconds(1); |
| 945 const base::TimeDelta old_tcp_rtt = base::TimeDelta::FromMilliseconds(10); | 945 const base::TimeDelta old_tcp_rtt = base::TimeDelta::FromMilliseconds(10); |
| 946 | 946 |
| 947 DCHECK_LT(old_url_rtt, rtt_threshold_3g); | 947 DCHECK_LT(old_url_rtt, rtt_threshold_3g); |
| 948 DCHECK_LT(old_tcp_rtt, rtt_threshold_3g); | 948 DCHECK_LT(old_tcp_rtt, rtt_threshold_3g); |
| 949 | 949 |
| 950 // First sample has very old timestamp. | 950 // First sample has very old timestamp. |
| 951 for (size_t i = 0; i < 2; ++i) { | 951 for (size_t i = 0; i < 2; ++i) { |
| 952 estimator.downstream_throughput_kbps_observations_.AddObservation( | 952 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 953 NetworkQualityEstimator::ThroughputObservation( | 953 NetworkQualityEstimator::ThroughputObservation( |
| 954 old_downlink_kbps, old, | 954 old_downlink_kbps, old, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP)); |
| 955 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | |
| 956 estimator.rtt_observations_.AddObservation( | 955 estimator.rtt_observations_.AddObservation( |
| 957 NetworkQualityEstimator::RttObservation( | 956 NetworkQualityEstimator::RttObservation( |
| 958 old_url_rtt, old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 957 old_url_rtt, old, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP)); |
| 959 estimator.rtt_observations_.AddObservation( | 958 estimator.rtt_observations_.AddObservation( |
| 960 NetworkQualityEstimator::RttObservation( | 959 NetworkQualityEstimator::RttObservation( |
| 961 old_tcp_rtt, old, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); | 960 old_tcp_rtt, old, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); |
| 962 } | 961 } |
| 963 | 962 |
| 964 const int32_t new_downlink_kbps = 100; | 963 const int32_t new_downlink_kbps = 100; |
| 965 const base::TimeDelta new_url_rtt = base::TimeDelta::FromMilliseconds(100); | 964 const base::TimeDelta new_url_rtt = base::TimeDelta::FromMilliseconds(100); |
| 966 const base::TimeDelta new_tcp_rtt = base::TimeDelta::FromMilliseconds(1000); | 965 const base::TimeDelta new_tcp_rtt = base::TimeDelta::FromMilliseconds(1000); |
| 967 | 966 |
| 968 DCHECK_NE(old_downlink_kbps, new_downlink_kbps); | 967 DCHECK_NE(old_downlink_kbps, new_downlink_kbps); |
| 969 DCHECK_NE(old_url_rtt, new_url_rtt); | 968 DCHECK_NE(old_url_rtt, new_url_rtt); |
| 970 DCHECK_NE(old_tcp_rtt, new_tcp_rtt); | 969 DCHECK_NE(old_tcp_rtt, new_tcp_rtt); |
| 971 DCHECK_GT(new_url_rtt, rtt_threshold_3g); | 970 DCHECK_GT(new_url_rtt, rtt_threshold_3g); |
| 972 DCHECK_GT(new_tcp_rtt, rtt_threshold_3g); | 971 DCHECK_GT(new_tcp_rtt, rtt_threshold_3g); |
| 973 DCHECK_GT(new_url_rtt, rtt_threshold_4g); | 972 DCHECK_GT(new_url_rtt, rtt_threshold_4g); |
| 974 DCHECK_GT(new_tcp_rtt, rtt_threshold_4g); | 973 DCHECK_GT(new_tcp_rtt, rtt_threshold_4g); |
| 975 | 974 |
| 976 estimator.downstream_throughput_kbps_observations_.AddObservation( | 975 estimator.downstream_throughput_kbps_observations_.AddObservation( |
| 977 NetworkQualityEstimator::ThroughputObservation( | 976 NetworkQualityEstimator::ThroughputObservation( |
| 978 new_downlink_kbps, now, | 977 new_downlink_kbps, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP)); |
| 979 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | |
| 980 estimator.rtt_observations_.AddObservation( | 978 estimator.rtt_observations_.AddObservation( |
| 981 NetworkQualityEstimator::RttObservation( | 979 NetworkQualityEstimator::RttObservation( |
| 982 new_url_rtt, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 980 new_url_rtt, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP)); |
| 983 estimator.rtt_observations_.AddObservation( | 981 estimator.rtt_observations_.AddObservation( |
| 984 NetworkQualityEstimator::RttObservation( | 982 NetworkQualityEstimator::RttObservation( |
| 985 new_tcp_rtt, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); | 983 new_tcp_rtt, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); |
| 986 | 984 |
| 987 const struct { | 985 const struct { |
| 988 base::TimeTicks start_timestamp; | 986 base::TimeTicks start_timestamp; |
| 989 bool expect_network_quality_available; | 987 bool expect_network_quality_available; |
| 990 base::TimeDelta expected_http_rtt; | 988 base::TimeDelta expected_http_rtt; |
| 991 base::TimeDelta expected_transport_rtt; | 989 base::TimeDelta expected_transport_rtt; |
| 992 int32_t expected_downstream_throughput; | 990 int32_t expected_downstream_throughput; |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 estimator.set_recent_effective_connection_type( | 1468 estimator.set_recent_effective_connection_type( |
| 1471 EFFECTIVE_CONNECTION_TYPE_UNKNOWN); | 1469 EFFECTIVE_CONNECTION_TYPE_UNKNOWN); |
| 1472 // Run one main frame request to force recomputation of effective connection | 1470 // Run one main frame request to force recomputation of effective connection |
| 1473 // type. | 1471 // type. |
| 1474 estimator.RunOneRequest(); | 1472 estimator.RunOneRequest(); |
| 1475 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, | 1473 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, |
| 1476 "test"); | 1474 "test"); |
| 1477 | 1475 |
| 1478 NetworkQualityEstimator::RttObservation rtt_observation( | 1476 NetworkQualityEstimator::RttObservation rtt_observation( |
| 1479 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), | 1477 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), |
| 1480 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST); | 1478 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); |
| 1481 | 1479 |
| 1482 for (size_t i = 0; i < 10; ++i) { | 1480 for (size_t i = 0; i < 10; ++i) { |
| 1483 estimator.NotifyObserversOfRTT(rtt_observation); | 1481 estimator.NotifyObserversOfRTT(rtt_observation); |
| 1484 EXPECT_EQ(expected_effective_connection_type_notifications, | 1482 EXPECT_EQ(expected_effective_connection_type_notifications, |
| 1485 observer.effective_connection_types().size()); | 1483 observer.effective_connection_types().size()); |
| 1486 } | 1484 } |
| 1487 estimator.set_recent_effective_connection_type( | 1485 estimator.set_recent_effective_connection_type( |
| 1488 EFFECTIVE_CONNECTION_TYPE_SLOW_2G); | 1486 EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
| 1489 // Even though there are 10 RTT samples already available, the addition of one | 1487 // Even though there are 10 RTT samples already available, the addition of one |
| 1490 // more RTT sample should trigger recomputation of the effective connection | 1488 // more RTT sample should trigger recomputation of the effective connection |
| 1491 // type since the last computed effective connection type was unknown. | 1489 // type since the last computed effective connection type was unknown. |
| 1492 estimator.NotifyObserversOfRTT(NetworkQualityEstimator::RttObservation( | 1490 estimator.NotifyObserversOfRTT(NetworkQualityEstimator::RttObservation( |
| 1493 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), | 1491 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), |
| 1494 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 1492 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP)); |
| 1495 ++expected_effective_connection_type_notifications; | 1493 ++expected_effective_connection_type_notifications; |
| 1496 EXPECT_EQ(expected_effective_connection_type_notifications, | 1494 EXPECT_EQ(expected_effective_connection_type_notifications, |
| 1497 observer.effective_connection_types().size()); | 1495 observer.effective_connection_types().size()); |
| 1498 } | 1496 } |
| 1499 | 1497 |
| 1500 // Tests that the effective connection type is computed regularly depending | 1498 // Tests that the effective connection type is computed regularly depending |
| 1501 // on the number of RTT and bandwidth samples. | 1499 // on the number of RTT and bandwidth samples. |
| 1502 TEST(NetworkQualityEstimatorTest, | 1500 TEST(NetworkQualityEstimatorTest, |
| 1503 AdaptiveRecomputationEffectiveConnectionType) { | 1501 AdaptiveRecomputationEffectiveConnectionType) { |
| 1504 base::HistogramTester histogram_tester; | 1502 base::HistogramTester histogram_tester; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1557 EFFECTIVE_CONNECTION_TYPE_3G); | 1555 EFFECTIVE_CONNECTION_TYPE_3G); |
| 1558 } | 1556 } |
| 1559 size_t rtt_observations_count = estimator.rtt_observations_.Size() * 0.5; | 1557 size_t rtt_observations_count = estimator.rtt_observations_.Size() * 0.5; |
| 1560 // Increase the number of RTT observations to more than twice the number | 1558 // Increase the number of RTT observations to more than twice the number |
| 1561 // of current observations. This should trigger recomputation of | 1559 // of current observations. This should trigger recomputation of |
| 1562 // effective connection type. | 1560 // effective connection type. |
| 1563 for (size_t i = 0; i < rtt_observations_count + 1; ++i) { | 1561 for (size_t i = 0; i < rtt_observations_count + 1; ++i) { |
| 1564 estimator.rtt_observations_.AddObservation( | 1562 estimator.rtt_observations_.AddObservation( |
| 1565 NetworkQualityEstimator::RttObservation( | 1563 NetworkQualityEstimator::RttObservation( |
| 1566 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), | 1564 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), |
| 1567 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 1565 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP)); |
| 1568 | 1566 |
| 1569 estimator.NotifyObserversOfRTT(NetworkQualityEstimator::RttObservation( | 1567 estimator.NotifyObserversOfRTT(NetworkQualityEstimator::RttObservation( |
| 1570 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), | 1568 base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), |
| 1571 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 1569 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP)); |
| 1572 | 1570 |
| 1573 if (i == rtt_observations_count) { | 1571 if (i == rtt_observations_count) { |
| 1574 // Effective connection type must be recomputed since the number of RTT | 1572 // Effective connection type must be recomputed since the number of RTT |
| 1575 // samples are now more than twice the number of RTT samples that were | 1573 // samples are now more than twice the number of RTT samples that were |
| 1576 // available when effective connection type was last computed. | 1574 // available when effective connection type was last computed. |
| 1577 ++expected_effective_connection_type_notifications; | 1575 ++expected_effective_connection_type_notifications; |
| 1578 } | 1576 } |
| 1579 EXPECT_EQ(expected_effective_connection_type_notifications, | 1577 EXPECT_EQ(expected_effective_connection_type_notifications, |
| 1580 observer.effective_connection_types().size()); | 1578 observer.effective_connection_types().size()); |
| 1581 } | 1579 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1616 EXPECT_TRUE(estimator.GetHttpRTT(&rtt)); | 1614 EXPECT_TRUE(estimator.GetHttpRTT(&rtt)); |
| 1617 | 1615 |
| 1618 int32_t throughput; | 1616 int32_t throughput; |
| 1619 EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&throughput)); | 1617 EXPECT_TRUE(estimator.GetDownlinkThroughputKbps(&throughput)); |
| 1620 | 1618 |
| 1621 EXPECT_EQ(2U, rtt_observer.observations().size()); | 1619 EXPECT_EQ(2U, rtt_observer.observations().size()); |
| 1622 EXPECT_EQ(2U, throughput_observer.observations().size()); | 1620 EXPECT_EQ(2U, throughput_observer.observations().size()); |
| 1623 for (const auto& observation : rtt_observer.observations()) { | 1621 for (const auto& observation : rtt_observer.observations()) { |
| 1624 EXPECT_LE(0, observation.rtt_ms); | 1622 EXPECT_LE(0, observation.rtt_ms); |
| 1625 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); | 1623 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); |
| 1626 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST, | 1624 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, observation.source); |
| 1627 observation.source); | |
| 1628 } | 1625 } |
| 1629 for (const auto& observation : throughput_observer.observations()) { | 1626 for (const auto& observation : throughput_observer.observations()) { |
| 1630 EXPECT_LE(0, observation.throughput_kbps); | 1627 EXPECT_LE(0, observation.throughput_kbps); |
| 1631 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); | 1628 EXPECT_LE(0, (observation.timestamp - then).InMilliseconds()); |
| 1632 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST, | 1629 EXPECT_EQ(NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, observation.source); |
| 1633 observation.source); | |
| 1634 } | 1630 } |
| 1635 | 1631 |
| 1636 EXPECT_FALSE(estimator.GetTransportRTT(&rtt)); | 1632 EXPECT_FALSE(estimator.GetTransportRTT(&rtt)); |
| 1637 | 1633 |
| 1638 // Verify that observations from TCP and QUIC are passed on to the observers. | 1634 // Verify that observations from TCP and QUIC are passed on to the observers. |
| 1639 base::TimeDelta tcp_rtt(base::TimeDelta::FromMilliseconds(1)); | 1635 base::TimeDelta tcp_rtt(base::TimeDelta::FromMilliseconds(1)); |
| 1640 base::TimeDelta quic_rtt(base::TimeDelta::FromMilliseconds(2)); | 1636 base::TimeDelta quic_rtt(base::TimeDelta::FromMilliseconds(2)); |
| 1641 | 1637 |
| 1642 std::unique_ptr<SocketPerformanceWatcher> tcp_watcher = | 1638 std::unique_ptr<SocketPerformanceWatcher> tcp_watcher = |
| 1643 estimator.GetSocketPerformanceWatcherFactory() | 1639 estimator.GetSocketPerformanceWatcherFactory() |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2205 if (expected_count == 1) { | 2201 if (expected_count == 1) { |
| 2206 EffectiveConnectionType last_notified_type = | 2202 EffectiveConnectionType last_notified_type = |
| 2207 observer.effective_connection_types().at( | 2203 observer.effective_connection_types().at( |
| 2208 observer.effective_connection_types().size() - 1); | 2204 observer.effective_connection_types().size() - 1); |
| 2209 EXPECT_EQ(i, last_notified_type); | 2205 EXPECT_EQ(i, last_notified_type); |
| 2210 } | 2206 } |
| 2211 } | 2207 } |
| 2212 } | 2208 } |
| 2213 | 2209 |
| 2214 } // namespace net | 2210 } // namespace net |
| OLD | NEW |