mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 | [diff] [blame] | 11 | #include "testing/gmock/include/gmock/gmock.h" |
| 12 | #include "testing/gtest/include/gtest/gtest.h" |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 13 | |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 | [diff] [blame] | 14 | #include "webrtc/base/scoped_ptr.h" |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 15 | #include "webrtc/call.h" |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 16 | #include "webrtc/system_wrappers/interface/tick_util.h" |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 17 | #include "webrtc/test/fake_network_pipe.h" |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 18 | |
| 19 | using ::testing::_; |
| 20 | using ::testing::AnyNumber; |
| 21 | using ::testing::Return; |
| 22 | using ::testing::Invoke; |
| 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | class MockReceiver : public PacketReceiver { |
| 27 | public: |
| 28 | MockReceiver() {} |
| 29 | virtual ~MockReceiver() {} |
| 30 | |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 31 | void IncomingPacket(const uint8_t* data, size_t length) { |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 32 | DeliverPacket(MediaType::ANY, data, length); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 33 | delete [] data; |
| 34 | } |
| 35 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 36 | MOCK_METHOD3(DeliverPacket, |
| 37 | DeliveryStatus(MediaType, const uint8_t*, size_t)); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | class FakeNetworkPipeTest : public ::testing::Test { |
| 41 | protected: |
| 42 | virtual void SetUp() { |
| 43 | TickTime::UseFakeClock(12345); |
| 44 | receiver_.reset(new MockReceiver()); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 45 | ON_CALL(*receiver_, DeliverPacket(_, _, _)) |
stefan@webrtc.org | 1ccff349 | 2014-08-06 15:41:58 | [diff] [blame] | 46 | .WillByDefault(Return(PacketReceiver::DELIVERY_OK)); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | virtual void TearDown() { |
| 50 | } |
| 51 | |
| 52 | void SendPackets(FakeNetworkPipe* pipe, int number_packets, int kPacketSize) { |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 | [diff] [blame] | 53 | rtc::scoped_ptr<uint8_t[]> packet(new uint8_t[kPacketSize]); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 54 | for (int i = 0; i < number_packets; ++i) { |
| 55 | pipe->SendPacket(packet.get(), kPacketSize); |
| 56 | } |
| 57 | } |
| 58 | |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 59 | int PacketTimeMs(int capacity_kbps, int kPacketSize) const { |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 60 | return 8 * kPacketSize / capacity_kbps; |
| 61 | } |
| 62 | |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 | [diff] [blame] | 63 | rtc::scoped_ptr<MockReceiver> receiver_; |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | void DeleteMemory(uint8_t* data, int length) { delete [] data; } |
| 67 | |
| 68 | // Test the capacity link and verify we get as many packets as we expect. |
| 69 | TEST_F(FakeNetworkPipeTest, CapacityTest) { |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 70 | FakeNetworkPipe::Config config; |
stefan@webrtc.org | b8e9e44 | 2014-07-09 11:29:06 | [diff] [blame] | 71 | config.queue_length_packets = 20; |
mflodman@webrtc.org | 7acb65a | 2012-12-13 15:53:11 | [diff] [blame] | 72 | config.link_capacity_kbps = 80; |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 | [diff] [blame] | 73 | rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 74 | pipe->SetReceiver(receiver_.get()); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 75 | |
| 76 | // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to |
| 77 | // get through the pipe. |
| 78 | const int kNumPackets = 10; |
| 79 | const int kPacketSize = 1000; |
| 80 | SendPackets(pipe.get(), kNumPackets , kPacketSize); |
| 81 | |
| 82 | // Time to get one packet through the link. |
mflodman@webrtc.org | 7acb65a | 2012-12-13 15:53:11 | [diff] [blame] | 83 | const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
| 84 | kPacketSize); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 85 | |
| 86 | // Time haven't increased yet, so we souldn't get any packets. |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 87 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 88 | .Times(0); |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 89 | pipe->Process(); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 90 | |
| 91 | // Advance enough time to release one packet. |
| 92 | TickTime::AdvanceFakeClock(kPacketTimeMs); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 93 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 94 | .Times(1); |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 95 | pipe->Process(); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 96 | |
| 97 | // Release all but one packet |
| 98 | TickTime::AdvanceFakeClock(9 * kPacketTimeMs - 1); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 99 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 100 | .Times(8); |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 101 | pipe->Process(); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 102 | |
| 103 | // And the last one. |
| 104 | TickTime::AdvanceFakeClock(1); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 105 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 106 | .Times(1); |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 107 | pipe->Process(); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | // Test the extra network delay. |
| 111 | TEST_F(FakeNetworkPipeTest, ExtraDelayTest) { |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 112 | FakeNetworkPipe::Config config; |
stefan@webrtc.org | b8e9e44 | 2014-07-09 11:29:06 | [diff] [blame] | 113 | config.queue_length_packets = 20; |
mflodman@webrtc.org | 7acb65a | 2012-12-13 15:53:11 | [diff] [blame] | 114 | config.queue_delay_ms = 100; |
| 115 | config.link_capacity_kbps = 80; |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 | [diff] [blame] | 116 | rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 117 | pipe->SetReceiver(receiver_.get()); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 118 | |
| 119 | const int kNumPackets = 2; |
| 120 | const int kPacketSize = 1000; |
| 121 | SendPackets(pipe.get(), kNumPackets , kPacketSize); |
| 122 | |
| 123 | // Time to get one packet through the link. |
mflodman@webrtc.org | 7acb65a | 2012-12-13 15:53:11 | [diff] [blame] | 124 | const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
| 125 | kPacketSize); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 126 | |
| 127 | // Increase more than kPacketTimeMs, but not more than the extra delay. |
| 128 | TickTime::AdvanceFakeClock(kPacketTimeMs); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 129 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 130 | .Times(0); |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 131 | pipe->Process(); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 132 | |
| 133 | // Advance the network delay to get the first packet. |
mflodman@webrtc.org | 7acb65a | 2012-12-13 15:53:11 | [diff] [blame] | 134 | TickTime::AdvanceFakeClock(config.queue_delay_ms); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 135 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 136 | .Times(1); |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 137 | pipe->Process(); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 138 | |
| 139 | // Advance one more kPacketTimeMs to get the last packet. |
| 140 | TickTime::AdvanceFakeClock(kPacketTimeMs); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 141 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 142 | .Times(1); |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 143 | pipe->Process(); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | // Test the number of buffers and packets are dropped when sending too many |
| 147 | // packets too quickly. |
| 148 | TEST_F(FakeNetworkPipeTest, QueueLengthTest) { |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 149 | FakeNetworkPipe::Config config; |
stefan@webrtc.org | b8e9e44 | 2014-07-09 11:29:06 | [diff] [blame] | 150 | config.queue_length_packets = 2; |
mflodman@webrtc.org | 7acb65a | 2012-12-13 15:53:11 | [diff] [blame] | 151 | config.link_capacity_kbps = 80; |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 | [diff] [blame] | 152 | rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 153 | pipe->SetReceiver(receiver_.get()); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 154 | |
| 155 | const int kPacketSize = 1000; |
mflodman@webrtc.org | 7acb65a | 2012-12-13 15:53:11 | [diff] [blame] | 156 | const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
| 157 | kPacketSize); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 158 | |
| 159 | // Send three packets and verify only 2 are delivered. |
| 160 | SendPackets(pipe.get(), 3, kPacketSize); |
| 161 | |
| 162 | // Increase time enough to deliver all three packets, verify only two are |
| 163 | // delivered. |
| 164 | TickTime::AdvanceFakeClock(3 * kPacketTimeMs); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 165 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 166 | .Times(2); |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 167 | pipe->Process(); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | // Test we get statistics as expected. |
| 171 | TEST_F(FakeNetworkPipeTest, StatisticsTest) { |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 172 | FakeNetworkPipe::Config config; |
stefan@webrtc.org | b8e9e44 | 2014-07-09 11:29:06 | [diff] [blame] | 173 | config.queue_length_packets = 2; |
mflodman@webrtc.org | 7acb65a | 2012-12-13 15:53:11 | [diff] [blame] | 174 | config.queue_delay_ms = 20; |
| 175 | config.link_capacity_kbps = 80; |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 | [diff] [blame] | 176 | rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 177 | pipe->SetReceiver(receiver_.get()); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 178 | |
| 179 | const int kPacketSize = 1000; |
mflodman@webrtc.org | 7acb65a | 2012-12-13 15:53:11 | [diff] [blame] | 180 | const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, |
| 181 | kPacketSize); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 182 | |
| 183 | // Send three packets and verify only 2 are delivered. |
| 184 | SendPackets(pipe.get(), 3, kPacketSize); |
mflodman@webrtc.org | 7acb65a | 2012-12-13 15:53:11 | [diff] [blame] | 185 | TickTime::AdvanceFakeClock(3 * kPacketTimeMs + config.queue_delay_ms); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 186 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 187 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)) |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 188 | .Times(2); |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 189 | pipe->Process(); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 190 | |
mflodman@webrtc.org | 7acb65a | 2012-12-13 15:53:11 | [diff] [blame] | 191 | // Packet 1: kPacketTimeMs + config.queue_delay_ms, |
| 192 | // packet 2: 2 * kPacketTimeMs + config.queue_delay_ms => 170 ms average. |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 193 | EXPECT_EQ(pipe->AverageDelay(), 170); |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 | [diff] [blame] | 194 | EXPECT_EQ(pipe->sent_packets(), 2u); |
| 195 | EXPECT_EQ(pipe->dropped_packets(), 1u); |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 196 | EXPECT_EQ(pipe->PercentageLoss(), 1/3.f); |
| 197 | } |
| 198 | |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 199 | // Change the link capacity half-way through the test and verify that the |
| 200 | // delivery times change accordingly. |
| 201 | TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) { |
| 202 | FakeNetworkPipe::Config config; |
stefan@webrtc.org | b8e9e44 | 2014-07-09 11:29:06 | [diff] [blame] | 203 | config.queue_length_packets = 20; |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 204 | config.link_capacity_kbps = 80; |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 | [diff] [blame] | 205 | rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 206 | pipe->SetReceiver(receiver_.get()); |
| 207 | |
| 208 | // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to |
| 209 | // get through the pipe. |
| 210 | const int kNumPackets = 10; |
| 211 | const int kPacketSize = 1000; |
| 212 | SendPackets(pipe.get(), kNumPackets, kPacketSize); |
| 213 | |
| 214 | // Time to get one packet through the link. |
| 215 | int packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
| 216 | |
| 217 | // Time hasn't increased yet, so we souldn't get any packets. |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 218 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(0); |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 219 | pipe->Process(); |
| 220 | |
| 221 | // Advance time in steps to release one packet at a time. |
| 222 | for (int i = 0; i < kNumPackets; ++i) { |
| 223 | TickTime::AdvanceFakeClock(packet_time_ms); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 224 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(1); |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 225 | pipe->Process(); |
| 226 | } |
| 227 | |
| 228 | // Change the capacity. |
| 229 | config.link_capacity_kbps /= 2; // Reduce to 50%. |
| 230 | pipe->SetConfig(config); |
| 231 | |
| 232 | // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two |
| 233 | // seconds to get them through the pipe. |
| 234 | SendPackets(pipe.get(), kNumPackets, kPacketSize); |
| 235 | |
| 236 | // Time to get one packet through the link. |
| 237 | packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
| 238 | |
| 239 | // Time hasn't increased yet, so we souldn't get any packets. |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 240 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(0); |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 241 | pipe->Process(); |
| 242 | |
| 243 | // Advance time in steps to release one packet at a time. |
| 244 | for (int i = 0; i < kNumPackets; ++i) { |
| 245 | TickTime::AdvanceFakeClock(packet_time_ms); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 246 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(1); |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 247 | pipe->Process(); |
| 248 | } |
| 249 | |
| 250 | // Check that all the packets were sent. |
| 251 | EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets()); |
| 252 | TickTime::AdvanceFakeClock(pipe->TimeUntilNextProcess()); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 253 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(0); |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 254 | pipe->Process(); |
| 255 | } |
| 256 | |
| 257 | // Change the link capacity half-way through the test and verify that the |
| 258 | // delivery times change accordingly. |
| 259 | TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) { |
| 260 | FakeNetworkPipe::Config config; |
stefan@webrtc.org | b8e9e44 | 2014-07-09 11:29:06 | [diff] [blame] | 261 | config.queue_length_packets = 20; |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 262 | config.link_capacity_kbps = 80; |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 | [diff] [blame] | 263 | rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 264 | pipe->SetReceiver(receiver_.get()); |
| 265 | |
| 266 | // Add 10 packets of 1000 bytes, = 80 kb. |
| 267 | const int kNumPackets = 10; |
| 268 | const int kPacketSize = 1000; |
| 269 | SendPackets(pipe.get(), kNumPackets, kPacketSize); |
| 270 | |
| 271 | // Time to get one packet through the link at the initial speed. |
| 272 | int packet_time_1_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
| 273 | |
| 274 | // Change the capacity. |
| 275 | config.link_capacity_kbps *= 2; // Double the capacity. |
| 276 | pipe->SetConfig(config); |
| 277 | |
| 278 | // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two |
| 279 | // seconds to get them through the pipe. |
| 280 | SendPackets(pipe.get(), kNumPackets, kPacketSize); |
| 281 | |
| 282 | // Time to get one packet through the link at the new capacity. |
| 283 | int packet_time_2_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); |
| 284 | |
| 285 | // Time hasn't increased yet, so we souldn't get any packets. |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 286 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(0); |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 287 | pipe->Process(); |
| 288 | |
| 289 | // Advance time in steps to release one packet at a time. |
| 290 | for (int i = 0; i < kNumPackets; ++i) { |
| 291 | TickTime::AdvanceFakeClock(packet_time_1_ms); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 292 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(1); |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 293 | pipe->Process(); |
| 294 | } |
| 295 | |
| 296 | // Advance time in steps to release one packet at a time. |
| 297 | for (int i = 0; i < kNumPackets; ++i) { |
| 298 | TickTime::AdvanceFakeClock(packet_time_2_ms); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 299 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(1); |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 300 | pipe->Process(); |
| 301 | } |
| 302 | |
| 303 | // Check that all the packets were sent. |
| 304 | EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets()); |
| 305 | TickTime::AdvanceFakeClock(pipe->TimeUntilNextProcess()); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 306 | EXPECT_CALL(*receiver_, DeliverPacket(_, _, _)).Times(0); |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 307 | pipe->Process(); |
| 308 | } |
mflodman@webrtc.org | eaf7cf2 | 2012-12-11 11:47:22 | [diff] [blame] | 309 | } // namespace webrtc |