minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include <limits> |
| 12 | #include <memory> |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 13 | #include <numeric> |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
elad.alon | a6a45e6 | 2017-03-21 14:31:35 | [diff] [blame] | 16 | #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 17 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
Edward Lemur | 76de83e | 2017-07-06 17:44:34 | [diff] [blame] | 18 | #include "webrtc/rtc_base/checks.h" |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 19 | #include "webrtc/test/gmock.h" |
| 20 | #include "webrtc/test/gtest.h" |
| 21 | #include "webrtc/voice_engine/transport_feedback_packet_loss_tracker.h" |
| 22 | |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 23 | namespace webrtc { |
| 24 | |
| 25 | namespace { |
| 26 | |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 27 | constexpr int64_t kDefaultSendIntervalMs = 10; |
| 28 | constexpr int64_t kDefaultMaxWindowSizeMs = 500 * kDefaultSendIntervalMs; |
| 29 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 30 | class TransportFeedbackPacketLossTrackerTest |
| 31 | : public ::testing::TestWithParam<uint16_t> { |
| 32 | public: |
| 33 | TransportFeedbackPacketLossTrackerTest() = default; |
| 34 | virtual ~TransportFeedbackPacketLossTrackerTest() = default; |
| 35 | |
| 36 | protected: |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 37 | void SendPackets(TransportFeedbackPacketLossTracker* tracker, |
| 38 | const std::vector<uint16_t>& sequence_numbers, |
| 39 | int64_t send_time_interval_ms, |
| 40 | bool validate_all = true) { |
| 41 | RTC_CHECK_GE(send_time_interval_ms, 0); |
| 42 | for (uint16_t sequence_number : sequence_numbers) { |
| 43 | tracker->OnPacketAdded(sequence_number, time_ms_); |
| 44 | if (validate_all) { |
| 45 | tracker->Validate(); |
| 46 | } |
| 47 | time_ms_ += send_time_interval_ms; |
| 48 | } |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 49 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 50 | // We've either validated after each packet, or, for making sure the UT |
| 51 | // doesn't run too long, we might validate only at the end of the range. |
| 52 | if (!validate_all) { |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 53 | tracker->Validate(); |
| 54 | } |
| 55 | } |
| 56 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 57 | void SendPackets(TransportFeedbackPacketLossTracker* tracker, |
| 58 | uint16_t first_seq_num, |
| 59 | size_t num_of_packets, |
| 60 | int64_t send_time_interval_ms, |
| 61 | bool validate_all = true) { |
| 62 | RTC_CHECK_GE(send_time_interval_ms, 0); |
| 63 | std::vector<uint16_t> sequence_numbers(num_of_packets); |
| 64 | std::iota(sequence_numbers.begin(), sequence_numbers.end(), first_seq_num); |
| 65 | SendPackets(tracker, sequence_numbers, send_time_interval_ms, validate_all); |
| 66 | } |
| 67 | |
| 68 | void AdvanceClock(int64_t time_delta_ms) { |
| 69 | RTC_CHECK_GT(time_delta_ms, 0); |
| 70 | time_ms_ += time_delta_ms; |
| 71 | } |
| 72 | |
| 73 | void AddTransportFeedbackAndValidate( |
| 74 | TransportFeedbackPacketLossTracker* tracker, |
| 75 | uint16_t base_sequence_num, |
| 76 | const std::vector<bool>& reception_status_vec) { |
elad.alon | a6a45e6 | 2017-03-21 14:31:35 | [diff] [blame] | 77 | // Any positive integer signals reception. kNotReceived signals loss. |
| 78 | // Other values are just illegal. |
| 79 | constexpr int64_t kArrivalTimeMs = 1234; |
| 80 | |
| 81 | std::vector<PacketFeedback> packet_feedback_vector; |
| 82 | uint16_t seq_num = base_sequence_num; |
| 83 | for (bool received : reception_status_vec) { |
| 84 | packet_feedback_vector.emplace_back(PacketFeedback( |
| 85 | received ? kArrivalTimeMs : PacketFeedback::kNotReceived, seq_num)); |
| 86 | ++seq_num; |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 87 | } |
| 88 | |
elad.alon | 49d1987 | 2017-03-23 18:04:48 | [diff] [blame] | 89 | tracker->OnPacketFeedbackVector(packet_feedback_vector); |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 90 | tracker->Validate(); |
| 91 | } |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 92 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 93 | // Checks that validty is as expected. If valid, checks also that |
| 94 | // value is as expected. |
| 95 | void ValidatePacketLossStatistics( |
| 96 | const TransportFeedbackPacketLossTracker& tracker, |
| 97 | rtc::Optional<float> expected_plr, |
| 98 | rtc::Optional<float> expected_rplr) { |
eladalon | b11cc61 | 2017-05-25 07:15:35 | [diff] [blame] | 99 | // TODO(eladalon): Comparing the rtc::Optional<float> directly would have |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 100 | // given concise code, but less readable error messages. If we modify |
| 101 | // the way rtc::Optional is printed, we can get rid of this. |
| 102 | rtc::Optional<float> plr = tracker.GetPacketLossRate(); |
| 103 | EXPECT_EQ(static_cast<bool>(expected_plr), static_cast<bool>(plr)); |
| 104 | if (expected_plr && plr) { |
| 105 | EXPECT_EQ(*expected_plr, *plr); |
| 106 | } |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 107 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 108 | rtc::Optional<float> rplr = tracker.GetRecoverablePacketLossRate(); |
| 109 | EXPECT_EQ(static_cast<bool>(expected_rplr), static_cast<bool>(rplr)); |
| 110 | if (expected_rplr && rplr) { |
| 111 | EXPECT_EQ(*expected_rplr, *rplr); |
| 112 | } |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 113 | } |
elad.alon | d35e102 | 2017-02-01 16:36:09 | [diff] [blame] | 114 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 115 | // Convenience function for when both are valid, and explicitly stating |
| 116 | // the rtc::Optional<float> constructor is just cumbersome. |
| 117 | void ValidatePacketLossStatistics( |
| 118 | const TransportFeedbackPacketLossTracker& tracker, |
| 119 | float expected_plr, |
| 120 | float expected_rplr) { |
| 121 | ValidatePacketLossStatistics(tracker, rtc::Optional<float>(expected_plr), |
| 122 | rtc::Optional<float>(expected_rplr)); |
elad.alon | d35e102 | 2017-02-01 16:36:09 | [diff] [blame] | 123 | } |
| 124 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 125 | uint16_t base_{GetParam()}; |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 126 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 127 | private: |
| 128 | int64_t time_ms_{0}; |
elad.alon | d35e102 | 2017-02-01 16:36:09 | [diff] [blame] | 129 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 130 | RTC_DISALLOW_COPY_AND_ASSIGN(TransportFeedbackPacketLossTrackerTest); |
| 131 | }; |
elad.alon | d35e102 | 2017-02-01 16:36:09 | [diff] [blame] | 132 | |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 133 | } // namespace |
| 134 | |
| 135 | // Sanity check on an empty window. |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 136 | TEST_P(TransportFeedbackPacketLossTrackerTest, EmptyWindow) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 137 | TransportFeedbackPacketLossTracker tracker(kDefaultMaxWindowSizeMs, 5, 5); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 138 | |
elad.alon | d35e102 | 2017-02-01 16:36:09 | [diff] [blame] | 139 | // PLR and RPLR reported as unknown before reception of first feedback. |
| 140 | ValidatePacketLossStatistics(tracker, |
| 141 | rtc::Optional<float>(), |
| 142 | rtc::Optional<float>()); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 143 | } |
| 144 | |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 145 | // A feedback received for an empty window has no effect. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 146 | TEST_P(TransportFeedbackPacketLossTrackerTest, EmptyWindowFeedback) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 147 | TransportFeedbackPacketLossTracker tracker(kDefaultMaxWindowSizeMs, 3, 2); |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 148 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 149 | // Feedback doesn't correspond to any packets - ignored. |
| 150 | AddTransportFeedbackAndValidate(&tracker, base_, {true, false, true}); |
| 151 | ValidatePacketLossStatistics(tracker, |
| 152 | rtc::Optional<float>(), |
| 153 | rtc::Optional<float>()); |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 154 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 155 | // After the packets are transmitted, acking them would have an effect. |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 156 | SendPackets(&tracker, base_, 3, kDefaultSendIntervalMs); |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 157 | AddTransportFeedbackAndValidate(&tracker, base_, {true, false, true}); |
| 158 | ValidatePacketLossStatistics(tracker, 1.0f / 3.0f, 0.5f); |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 159 | } |
| 160 | |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 161 | // Sanity check on partially filled window. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 162 | TEST_P(TransportFeedbackPacketLossTrackerTest, PartiallyFilledWindow) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 163 | TransportFeedbackPacketLossTracker tracker(kDefaultMaxWindowSizeMs, 5, 4); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 164 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 165 | // PLR unknown before minimum window size reached. |
| 166 | // RPLR unknown before minimum pairs reached. |
| 167 | // Expected window contents: [] -> [1001]. |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 168 | SendPackets(&tracker, base_, 3, kDefaultSendIntervalMs); |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 169 | AddTransportFeedbackAndValidate(&tracker, base_, {true, false, false, true}); |
| 170 | ValidatePacketLossStatistics(tracker, |
| 171 | rtc::Optional<float>(), |
| 172 | rtc::Optional<float>()); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 173 | } |
| 174 | |
elad.alon | d35e102 | 2017-02-01 16:36:09 | [diff] [blame] | 175 | // Sanity check on minimum filled window - PLR known, RPLR unknown. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 176 | TEST_P(TransportFeedbackPacketLossTrackerTest, PlrMinimumFilledWindow) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 177 | TransportFeedbackPacketLossTracker tracker(kDefaultMaxWindowSizeMs, 5, 5); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 178 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 179 | // PLR correctly calculated after minimum window size reached. |
| 180 | // RPLR not necessarily known at that time (not if min-pairs not reached). |
| 181 | // Expected window contents: [] -> [10011]. |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 182 | SendPackets(&tracker, base_, 5, kDefaultSendIntervalMs); |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 183 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 184 | {true, false, false, true, true}); |
| 185 | ValidatePacketLossStatistics(tracker, |
| 186 | rtc::Optional<float>(2.0f / 5.0f), |
| 187 | rtc::Optional<float>()); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 188 | } |
| 189 | |
elad.alon | d35e102 | 2017-02-01 16:36:09 | [diff] [blame] | 190 | // Sanity check on minimum filled window - PLR unknown, RPLR known. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 191 | TEST_P(TransportFeedbackPacketLossTrackerTest, RplrMinimumFilledWindow) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 192 | TransportFeedbackPacketLossTracker tracker(kDefaultMaxWindowSizeMs, 6, 4); |
elad.alon | d35e102 | 2017-02-01 16:36:09 | [diff] [blame] | 193 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 194 | // RPLR correctly calculated after minimum pairs reached. |
| 195 | // PLR not necessarily known at that time (not if min window not reached). |
| 196 | // Expected window contents: [] -> [10011]. |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 197 | SendPackets(&tracker, base_, 5, kDefaultSendIntervalMs); |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 198 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 199 | {true, false, false, true, true}); |
| 200 | ValidatePacketLossStatistics(tracker, |
| 201 | rtc::Optional<float>(), |
| 202 | rtc::Optional<float>(1.0f / 4.0f)); |
elad.alon | d35e102 | 2017-02-01 16:36:09 | [diff] [blame] | 203 | } |
| 204 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 205 | // If packets are sent close enough together that the clock reading for both |
| 206 | // is the same, that's handled properly. |
| 207 | TEST_P(TransportFeedbackPacketLossTrackerTest, SameSentTime) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 208 | TransportFeedbackPacketLossTracker tracker(kDefaultMaxWindowSizeMs, 3, 2); |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 209 | |
| 210 | // Expected window contents: [] -> [101]. |
| 211 | SendPackets(&tracker, base_, 3, 0); // Note: time interval = 0ms. |
| 212 | AddTransportFeedbackAndValidate(&tracker, base_, {true, false, true}); |
| 213 | |
| 214 | ValidatePacketLossStatistics(tracker, 1.0f / 3.0f, 0.5f); |
| 215 | } |
| 216 | |
elad.alon | d35e102 | 2017-02-01 16:36:09 | [diff] [blame] | 217 | // Additional reports update PLR and RPLR. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 218 | TEST_P(TransportFeedbackPacketLossTrackerTest, ExtendWindow) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 219 | TransportFeedbackPacketLossTracker tracker(kDefaultMaxWindowSizeMs, 5, 5); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 220 | |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 221 | SendPackets(&tracker, base_, 25, kDefaultSendIntervalMs); |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 222 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 223 | // Expected window contents: [] -> [10011]. |
| 224 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 225 | {true, false, false, true, true}); |
| 226 | ValidatePacketLossStatistics(tracker, |
| 227 | rtc::Optional<float>(2.0f / 5.0f), |
| 228 | rtc::Optional<float>()); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 229 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 230 | // Expected window contents: [10011] -> [1001110101]. |
| 231 | AddTransportFeedbackAndValidate(&tracker, base_ + 5, |
| 232 | {true, false, true, false, true}); |
| 233 | ValidatePacketLossStatistics(tracker, 4.0f / 10.0f, 3.0f / 9.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 234 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 235 | // Expected window contents: [1001110101] -> [1001110101-GAP-10001]. |
| 236 | AddTransportFeedbackAndValidate(&tracker, base_ + 20, |
| 237 | {true, false, false, false, true}); |
| 238 | ValidatePacketLossStatistics(tracker, 7.0f / 15.0f, 4.0f / 13.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 239 | } |
| 240 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 241 | // Correct calculation with different packet lengths. |
| 242 | TEST_P(TransportFeedbackPacketLossTrackerTest, DifferentSentIntervals) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 243 | TransportFeedbackPacketLossTracker tracker(kDefaultMaxWindowSizeMs, 5, 4); |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 244 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 245 | int64_t frames[] = {20, 60, 120, 20, 60}; |
| 246 | for (size_t i = 0; i < sizeof(frames) / sizeof(frames[0]); i++) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 247 | SendPackets(&tracker, {static_cast<uint16_t>(base_ + i)}, frames[i]); |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | // Expected window contents: [] -> [10011]. |
| 251 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 252 | {true, false, false, true, true}); |
| 253 | ValidatePacketLossStatistics(tracker, 2.0f / 5.0f, 1.0f / 4.0f); |
| 254 | } |
| 255 | |
| 256 | // The window retains information up to sent times that exceed the the max |
| 257 | // window size. The oldest packets get shifted out of window to make room |
| 258 | // for the newer ones. |
| 259 | TEST_P(TransportFeedbackPacketLossTrackerTest, MaxWindowSize) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 260 | TransportFeedbackPacketLossTracker tracker(4 * kDefaultSendIntervalMs, 5, 1); |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 261 | |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 262 | SendPackets(&tracker, base_, 6, kDefaultSendIntervalMs, true); |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 263 | |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 264 | // Up to the maximum time-span retained (first + 4 * kDefaultSendIntervalMs). |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 265 | // Expected window contents: [] -> [01001]. |
| 266 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 267 | {false, true, false, false, true}); |
| 268 | ValidatePacketLossStatistics(tracker, 3.0f / 5.0f, 2.0f / 4.0f); |
| 269 | |
| 270 | // After the maximum time-span, older entries are discarded to accommodate |
| 271 | // newer ones. |
| 272 | // Expected window contents: [01001] -> [10011]. |
| 273 | AddTransportFeedbackAndValidate(&tracker, base_ + 5, {true}); |
| 274 | ValidatePacketLossStatistics(tracker, 2.0f / 5.0f, 1.0f / 4.0f); |
| 275 | } |
| 276 | |
| 277 | // All packets received. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 278 | TEST_P(TransportFeedbackPacketLossTrackerTest, AllReceived) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 279 | TransportFeedbackPacketLossTracker tracker(kDefaultMaxWindowSizeMs, 5, 4); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 280 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 281 | // Expected window contents: [] -> [11111]. |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 282 | SendPackets(&tracker, base_, 5, kDefaultSendIntervalMs); |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 283 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 284 | {true, true, true, true, true}); |
| 285 | ValidatePacketLossStatistics(tracker, 0.0f, 0.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 286 | } |
| 287 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 288 | // All packets lost. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 289 | TEST_P(TransportFeedbackPacketLossTrackerTest, AllLost) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 290 | TransportFeedbackPacketLossTracker tracker(kDefaultMaxWindowSizeMs, 5, 4); |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 291 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 292 | // Note: The last packet in the feedback does not belong to the stream. |
| 293 | // It's only there because we're not allowed to end a feedback with a loss. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 294 | // Expected window contents: [] -> [00000]. |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 295 | SendPackets(&tracker, base_, 5, kDefaultSendIntervalMs); |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 296 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 297 | {false, false, false, false, false, true}); |
| 298 | ValidatePacketLossStatistics(tracker, 1.0f, 0.0f); |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 299 | } |
| 300 | |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 301 | // Repeated reports are ignored. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 302 | TEST_P(TransportFeedbackPacketLossTrackerTest, ReportRepetition) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 303 | TransportFeedbackPacketLossTracker tracker(kDefaultMaxWindowSizeMs, 5, 4); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 304 | |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 305 | SendPackets(&tracker, base_, 5, kDefaultSendIntervalMs); |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 306 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 307 | // Expected window contents: [] -> [10011]. |
| 308 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 309 | {true, false, false, true, true}); |
| 310 | ValidatePacketLossStatistics(tracker, 2.0f / 5.0f, 1.0f / 4.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 311 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 312 | // Repeat entire previous feedback |
| 313 | // Expected window contents: [10011] -> [10011]. |
| 314 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 315 | {true, false, false, true, true}); |
| 316 | ValidatePacketLossStatistics(tracker, 2.0f / 5.0f, 1.0f / 4.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | // Report overlap. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 320 | TEST_P(TransportFeedbackPacketLossTrackerTest, ReportOverlap) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 321 | TransportFeedbackPacketLossTracker tracker(kDefaultMaxWindowSizeMs, 5, 1); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 322 | |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 323 | SendPackets(&tracker, base_, 15, kDefaultSendIntervalMs); |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 324 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 325 | // Expected window contents: [] -> [10011]. |
| 326 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 327 | {true, false, false, true, true}); |
| 328 | ValidatePacketLossStatistics(tracker, 2.0f / 5.0f, 1.0f / 4.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 329 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 330 | // Expected window contents: [10011] -> [1001101]. |
| 331 | AddTransportFeedbackAndValidate(&tracker, base_ + 3, |
| 332 | {true, true, false, true}); |
| 333 | ValidatePacketLossStatistics(tracker, 3.0f / 7.0f, 2.0f / 6.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | // Report conflict. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 337 | TEST_P(TransportFeedbackPacketLossTrackerTest, ReportConflict) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 338 | TransportFeedbackPacketLossTracker tracker(kDefaultMaxWindowSizeMs, 5, 4); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 339 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 340 | SendPackets(&tracker, base_, 15, 10); |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 341 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 342 | // Expected window contents: [] -> [01001]. |
| 343 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 344 | {false, true, false, false, true}); |
| 345 | ValidatePacketLossStatistics(tracker, 3.0f / 5.0f, 2.0f / 4.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 346 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 347 | // Expected window contents: [01001] -> [11101]. |
| 348 | // While false->true will be applied, true -> false will be ignored. |
| 349 | AddTransportFeedbackAndValidate(&tracker, base_, {true, false, true}); |
| 350 | ValidatePacketLossStatistics(tracker, 1.0f / 5.0f, 1.0f / 4.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | // Skipped packets treated as unknown (not lost). |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 354 | TEST_P(TransportFeedbackPacketLossTrackerTest, SkippedPackets) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 355 | TransportFeedbackPacketLossTracker tracker(200 * kDefaultSendIntervalMs, 5, |
| 356 | 1); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 357 | |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 358 | SendPackets(&tracker, base_, 200, kDefaultSendIntervalMs); |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 359 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 360 | // Expected window contents: [] -> [10011]. |
| 361 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 362 | {true, false, false, true, true}); |
| 363 | ValidatePacketLossStatistics(tracker, 2.0f / 5.0f, 1.0f / 4.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 364 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 365 | // Expected window contents: [10011] -> [10011-GAP-101]. |
| 366 | AddTransportFeedbackAndValidate(&tracker, base_ + 100, {true, false, true}); |
| 367 | ValidatePacketLossStatistics(tracker, 3.0f / 8.0f, 2.0f / 6.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 368 | } |
| 369 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 370 | // Moving a window, if it excludes some old acked messages, can leave |
| 371 | // in-window unacked messages intact, and ready to be used later. |
| 372 | TEST_P(TransportFeedbackPacketLossTrackerTest, MovedWindowRetainsRelevantInfo) { |
| 373 | constexpr int64_t max_window_size_ms = 100; |
| 374 | TransportFeedbackPacketLossTracker tracker(max_window_size_ms, 5, 1); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 375 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 376 | // Note: All messages in this test are sent 1ms apart from each other. |
| 377 | // Therefore, the delta in sequence numbers equals the timestamps delta. |
| 378 | SendPackets(&tracker, base_, 4 * max_window_size_ms, 1); |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 379 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 380 | // Expected window contents: [] -> [10101]. |
| 381 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 382 | {true, false, true, false, true}); |
| 383 | ValidatePacketLossStatistics(tracker, 2.0f / 5.0f, 2.0f / 4.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 384 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 385 | // Expected window contents: [10101] -> [100011]. |
| 386 | const int64_t moved_oldest_acked = base_ + 2 * max_window_size_ms; |
| 387 | const std::vector<bool> feedback = {true, false, false, false, true, true}; |
| 388 | AddTransportFeedbackAndValidate(&tracker, moved_oldest_acked, feedback); |
| 389 | ValidatePacketLossStatistics(tracker, 3.0f / 6.0f, 1.0f / 5.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 390 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 391 | // Having acked |feedback.size()| starting with |moved_oldest_acked|, the |
| 392 | // newest of the acked ones is now: |
| 393 | const int64_t moved_newest_acked = moved_oldest_acked + feedback.size() - 1; |
| 394 | |
| 395 | // Messages that *are* more than the span-limit away from the newest |
| 396 | // acked message *are* too old. Acking them would have no effect. |
| 397 | AddTransportFeedbackAndValidate( |
| 398 | &tracker, moved_newest_acked - max_window_size_ms - 1, {true}); |
| 399 | ValidatePacketLossStatistics(tracker, 3.0f / 6.0f, 1.0f / 5.0f); |
| 400 | |
| 401 | // Messages that are *not* more than the span-limit away from the newest |
| 402 | // acked message are *not* too old. Acking them would have an effect. |
| 403 | AddTransportFeedbackAndValidate( |
| 404 | &tracker, moved_newest_acked - max_window_size_ms, {true}); |
| 405 | ValidatePacketLossStatistics(tracker, 3.0f / 7.0f, 1.0f / 5.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 406 | } |
| 407 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 408 | // Inserting feedback into the middle of a window works correctly - can |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 409 | // complete two pairs. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 410 | TEST_P(TransportFeedbackPacketLossTrackerTest, InsertionCompletesTwoPairs) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 411 | TransportFeedbackPacketLossTracker tracker(150 * kDefaultSendIntervalMs, 5, |
| 412 | 1); |
elad.alon | d35e102 | 2017-02-01 16:36:09 | [diff] [blame] | 413 | |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 414 | SendPackets(&tracker, base_, 15, kDefaultSendIntervalMs); |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 415 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 416 | // Expected window contents: [] -> [10111]. |
| 417 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 418 | {true, false, true, true, true}); |
| 419 | ValidatePacketLossStatistics(tracker, 1.0f / 5.0f, 1.0f / 4.0f); |
elad.alon | d35e102 | 2017-02-01 16:36:09 | [diff] [blame] | 420 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 421 | // Expected window contents: [10111] -> [10111-GAP-10101]. |
| 422 | AddTransportFeedbackAndValidate(&tracker, base_ + 7, |
| 423 | {true, false, true, false, true}); |
| 424 | ValidatePacketLossStatistics(tracker, 3.0f / 10.0f, 3.0f / 8.0f); |
elad.alon | d35e102 | 2017-02-01 16:36:09 | [diff] [blame] | 425 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 426 | // Insert in between, closing the gap completely. |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 427 | // Expected window contents: [10111-GAP-10101] -> [101110110101]. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 428 | AddTransportFeedbackAndValidate(&tracker, base_ + 5, {false, true}); |
| 429 | ValidatePacketLossStatistics(tracker, 4.0f / 12.0f, 4.0f / 11.0f); |
elad.alon | d35e102 | 2017-02-01 16:36:09 | [diff] [blame] | 430 | } |
| 431 | |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 432 | // Sequence number gaps are not gaps in reception. However, gaps in reception |
| 433 | // are still possible, if a packet which WAS sent on the stream is not acked. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 434 | TEST_P(TransportFeedbackPacketLossTrackerTest, SanityGapsInSequenceNumbers) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 435 | TransportFeedbackPacketLossTracker tracker(50 * kDefaultSendIntervalMs, 5, 1); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 436 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 437 | SendPackets(&tracker, |
| 438 | {static_cast<uint16_t>(base_), |
| 439 | static_cast<uint16_t>(base_ + 2), |
| 440 | static_cast<uint16_t>(base_ + 4), |
| 441 | static_cast<uint16_t>(base_ + 6), |
| 442 | static_cast<uint16_t>(base_ + 8)}, |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 443 | kDefaultSendIntervalMs); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 444 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 445 | // Gaps in sequence numbers not considered as gaps in window, because only |
| 446 | // those sequence numbers which were associated with the stream count. |
| 447 | // Expected window contents: [] -> [11011]. |
| 448 | AddTransportFeedbackAndValidate( |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 449 | // Note: Left packets belong to this stream, right ones ignored. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 450 | &tracker, base_, {true, false, |
| 451 | true, false, |
| 452 | false, false, |
| 453 | true, false, |
| 454 | true, true}); |
| 455 | ValidatePacketLossStatistics(tracker, 1.0f / 5.0f, 1.0f / 4.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 456 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 457 | // Create gap by sending [base + 10] but not acking it. |
| 458 | // Note: Acks for [base + 11] and [base + 13] ignored (other stream). |
| 459 | // Expected window contents: [11011] -> [11011-GAP-01]. |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 460 | SendPackets(&tracker, |
| 461 | {static_cast<uint16_t>(base_ + 10), |
| 462 | static_cast<uint16_t>(base_ + 12), |
| 463 | static_cast<uint16_t>(base_ + 14)}, |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 464 | kDefaultSendIntervalMs); |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 465 | AddTransportFeedbackAndValidate(&tracker, base_ + 11, |
| 466 | {false, false, false, true, true}); |
| 467 | ValidatePacketLossStatistics(tracker, 2.0f / 7.0f, 2.0f / 5.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 468 | } |
| 469 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 470 | // The window cannot span more than 0x8000 in sequence numbers, regardless |
| 471 | // of time stamps and ack/unacked status. |
| 472 | TEST_P(TransportFeedbackPacketLossTrackerTest, MaxUnackedPackets) { |
| 473 | TransportFeedbackPacketLossTracker tracker(0x10000, 4, 1); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 474 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 475 | SendPackets(&tracker, base_, 0x2000, 1, false); |
| 476 | |
| 477 | // Expected window contents: [] -> [10011]. |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 478 | AddTransportFeedbackAndValidate(&tracker, base_, |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 479 | {true, false, false, true, true}); |
| 480 | ValidatePacketLossStatistics(tracker, 2.0f / 5.0f, 1.0f / 4.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 481 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 482 | // Sending more unacked packets, up to 0x7fff from the base, does not |
| 483 | // move the window or discard any information. |
| 484 | SendPackets(&tracker, static_cast<uint16_t>(base_ + 0x8000 - 0x2000), 0x2000, |
| 485 | 1, false); |
| 486 | ValidatePacketLossStatistics(tracker, 2.0f / 5.0f, 1.0f / 4.0f); |
| 487 | |
| 488 | // Sending more unacked packets, up to 0x7fff from the base, does not |
| 489 | // move the window or discard any information. |
| 490 | // Expected window contents: [10011] -> [0011]. |
| 491 | SendPackets(&tracker, static_cast<uint16_t>(base_ + 0x8000), 1, 1); |
| 492 | ValidatePacketLossStatistics(tracker, 2.0f / 4.0f, 1.0f / 3.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 493 | } |
| 494 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 495 | // The window holds acked packets up until the difference in timestamps between |
| 496 | // the oldest and newest reaches the configured maximum. Once this maximum |
| 497 | // is exceeded, old packets are shifted out of window until the maximum is |
| 498 | // once again observed. |
| 499 | TEST_P(TransportFeedbackPacketLossTrackerTest, TimeDifferenceMaximumObserved) { |
| 500 | constexpr int64_t max_window_size_ms = 500; |
| 501 | TransportFeedbackPacketLossTracker tracker(max_window_size_ms, 3, 1); |
| 502 | |
| 503 | // Note: All messages in this test are sent 1ms apart from each other. |
| 504 | // Therefore, the delta in sequence numbers equals the timestamps delta. |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 505 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 506 | // Baseline - window has acked messages. |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 507 | // Expected window contents: [] -> [01101]. |
| 508 | const std::vector<bool> feedback = {false, true, true, false, true}; |
| 509 | SendPackets(&tracker, base_, feedback.size(), 1); |
| 510 | AddTransportFeedbackAndValidate(&tracker, base_, feedback); |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 511 | ValidatePacketLossStatistics(tracker, 2.0f / 5.0f, 2.0f / 4.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 512 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 513 | // Test - window base not moved. |
| 514 | // Expected window contents: [01101] -> [011011]. |
| 515 | AdvanceClock(max_window_size_ms - feedback.size()); |
| 516 | SendPackets(&tracker, static_cast<uint16_t>(base_ + feedback.size()), 1, 1); |
| 517 | AddTransportFeedbackAndValidate( |
| 518 | &tracker, static_cast<uint16_t>(base_ + feedback.size()), {true}); |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 519 | ValidatePacketLossStatistics(tracker, 2.0f / 6.0f, 2.0f / 5.0f); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 520 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 521 | // Another packet, sent 1ms later, would already be too late. The window will |
| 522 | // be moved, but only after the ACK is received. |
| 523 | const uint16_t new_packet_seq_num = |
| 524 | static_cast<uint16_t>(base_ + feedback.size() + 1); |
| 525 | SendPackets(&tracker, {new_packet_seq_num}, 1); |
| 526 | ValidatePacketLossStatistics(tracker, 2.0f / 6.0f, 2.0f / 5.0f); |
| 527 | // Expected window contents: [011011] -> [110111]. |
| 528 | AddTransportFeedbackAndValidate(&tracker, new_packet_seq_num, {true}); |
| 529 | ValidatePacketLossStatistics(tracker, 1.0f / 6.0f, 1.0f / 5.0f); |
| 530 | } |
elad.alon | 5f25489 | 2017-03-03 18:51:35 | [diff] [blame] | 531 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 532 | TEST_P(TransportFeedbackPacketLossTrackerTest, RepeatedSeqNumResetsWindow) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 533 | TransportFeedbackPacketLossTracker tracker(50 * kDefaultSendIntervalMs, 2, 1); |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 534 | |
| 535 | // Baseline - window has acked messages. |
| 536 | // Expected window contents: [] -> [01101]. |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 537 | SendPackets(&tracker, base_, 5, kDefaultSendIntervalMs); |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 538 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 539 | {false, true, true, false, true}); |
| 540 | ValidatePacketLossStatistics(tracker, 2.0f / 5.0f, 2.0f / 4.0f); |
| 541 | |
| 542 | // A reset occurs. |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 543 | SendPackets(&tracker, {static_cast<uint16_t>(base_ + 2)}, |
| 544 | kDefaultSendIntervalMs); |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 545 | ValidatePacketLossStatistics(tracker, |
| 546 | rtc::Optional<float>(), |
| 547 | rtc::Optional<float>()); |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 548 | } |
| 549 | |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 550 | // The window is reset by the sending of a packet which is 0x8000 or more |
| 551 | // away from the newest packet acked/unacked packet. |
| 552 | TEST_P(TransportFeedbackPacketLossTrackerTest, |
| 553 | SendAfterLongSuspensionResetsWindow) { |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 554 | TransportFeedbackPacketLossTracker tracker(50 * kDefaultSendIntervalMs, 2, 1); |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 555 | |
| 556 | // Baseline - window has acked messages. |
| 557 | // Expected window contents: [] -> [01101]. |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 558 | SendPackets(&tracker, base_, 5, kDefaultSendIntervalMs); |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 559 | AddTransportFeedbackAndValidate(&tracker, base_, |
| 560 | {false, true, true, false, true}); |
| 561 | ValidatePacketLossStatistics(tracker, 2.0f / 5.0f, 2.0f / 4.0f); |
| 562 | |
| 563 | // A reset occurs. |
elad.alon | 8132e17 | 2017-03-21 12:58:04 | [diff] [blame] | 564 | SendPackets(&tracker, {static_cast<uint16_t>(base_ + 5 + 0x8000)}, |
| 565 | kDefaultSendIntervalMs); |
elad.alon | de1cc66 | 2017-03-15 14:38:13 | [diff] [blame] | 566 | ValidatePacketLossStatistics(tracker, |
| 567 | rtc::Optional<float>(), |
| 568 | rtc::Optional<float>()); |
| 569 | } |
| 570 | |
| 571 | #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| 572 | TEST(TransportFeedbackPacketLossTrackerTest, InvalidConfigMaxWindowSize) { |
| 573 | EXPECT_DEATH(TransportFeedbackPacketLossTracker tracker(0, 20, 10), ""); |
| 574 | } |
| 575 | |
| 576 | TEST(TransportFeedbackPacketLossTrackerTest, InvalidConfigPlrMinAcked) { |
| 577 | EXPECT_DEATH(TransportFeedbackPacketLossTracker tracker(5000, 0, 10), ""); |
| 578 | } |
| 579 | |
| 580 | TEST(TransportFeedbackPacketLossTrackerTest, InvalidConfigRplrMinPairs) { |
| 581 | EXPECT_DEATH(TransportFeedbackPacketLossTracker tracker(5000, 20, 0), ""); |
| 582 | } |
| 583 | |
| 584 | TEST(TransportFeedbackPacketLossTrackerTest, TimeCantFlowBackwards) { |
| 585 | TransportFeedbackPacketLossTracker tracker(5000, 2, 1); |
| 586 | tracker.OnPacketAdded(100, 0); |
| 587 | tracker.OnPacketAdded(101, 2); |
| 588 | EXPECT_DEATH(tracker.OnPacketAdded(102, 1), ""); |
| 589 | } |
| 590 | #endif |
| 591 | |
elad.alon | d24531a | 2017-03-03 19:11:06 | [diff] [blame] | 592 | // All tests are run multiple times with various baseline sequence number, |
| 593 | // to weed out potential bugs with wrap-around handling. |
| 594 | constexpr uint16_t kBases[] = {0x0000, 0x3456, 0xc032, 0xfffe}; |
| 595 | |
| 596 | INSTANTIATE_TEST_CASE_P(_, |
| 597 | TransportFeedbackPacketLossTrackerTest, |
| 598 | testing::ValuesIn(kBases)); |
| 599 | |
minyue | 022a283 | 2017-01-23 16:07:05 | [diff] [blame] | 600 | } // namespace webrtc |