1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/rtp_rtcp/source/packet_loss_stats.h"
#include "test/gtest.h"
namespace webrtc {
class PacketLossStatsTest : public ::testing::Test {
protected:
PacketLossStats stats_;
};
// Add a lost packet as every other packet, they should all count as single
// losses.
TEST_F(PacketLossStatsTest, EveryOtherPacket) {
for (int i = 0; i < 1000; i += 2) {
stats_.AddLostPacket(i);
}
EXPECT_EQ(500, stats_.GetSingleLossCount());
EXPECT_EQ(0, stats_.GetMultipleLossEventCount());
EXPECT_EQ(0, stats_.GetMultipleLossPacketCount());
}
// Add a lost packet as every other packet, but such that the sequence numbers
// will wrap around while they are being added.
TEST_F(PacketLossStatsTest, EveryOtherPacketWrapped) {
for (int i = 65500; i < 66500; i += 2) {
stats_.AddLostPacket(i & 0xFFFF);
}
EXPECT_EQ(500, stats_.GetSingleLossCount());
EXPECT_EQ(0, stats_.GetMultipleLossEventCount());
EXPECT_EQ(0, stats_.GetMultipleLossPacketCount());
}
// Add a lost packet as every other packet, but such that the sequence numbers
// will wrap around close to the very end, such that the buffer contains packets
// on either side of the wrapping.
TEST_F(PacketLossStatsTest, EveryOtherPacketWrappedAtEnd) {
for (int i = 64600; i < 65600; i += 2) {
stats_.AddLostPacket(i & 0xFFFF);
}
EXPECT_EQ(500, stats_.GetSingleLossCount());
EXPECT_EQ(0, stats_.GetMultipleLossEventCount());
EXPECT_EQ(0, stats_.GetMultipleLossPacketCount());
}
// Add a lost packet as the first three of every eight packets. Each set of
// three should count as a multiple loss event and three multiple loss packets.
TEST_F(PacketLossStatsTest, FirstThreeOfEight) {
for (int i = 0; i < 1000; ++i) {
if ((i & 7) < 3) {
stats_.AddLostPacket(i);
}
}
EXPECT_EQ(0, stats_.GetSingleLossCount());
EXPECT_EQ(125, stats_.GetMultipleLossEventCount());
EXPECT_EQ(375, stats_.GetMultipleLossPacketCount());
}
// Add a lost packet as the first three of every eight packets such that the
// sequence numbers wrap in the middle of adding them.
TEST_F(PacketLossStatsTest, FirstThreeOfEightWrapped) {
for (int i = 65500; i < 66500; ++i) {
if ((i & 7) < 3) {
stats_.AddLostPacket(i & 0xFFFF);
}
}
EXPECT_EQ(0, stats_.GetSingleLossCount());
EXPECT_EQ(125, stats_.GetMultipleLossEventCount());
EXPECT_EQ(375, stats_.GetMultipleLossPacketCount());
}
// Add a lost packet as the first three of every eight packets such that the
// sequence numbers wrap near the end of adding them and there are still numbers
// in the buffer from before the wrapping.
TEST_F(PacketLossStatsTest, FirstThreeOfEightWrappedAtEnd) {
for (int i = 64600; i < 65600; ++i) {
if ((i & 7) < 3) {
stats_.AddLostPacket(i & 0xFFFF);
}
}
EXPECT_EQ(0, stats_.GetSingleLossCount());
EXPECT_EQ(125, stats_.GetMultipleLossEventCount());
EXPECT_EQ(375, stats_.GetMultipleLossPacketCount());
}
// Add loss packets as the first three and the fifth of every eight packets. The
// set of three should be multiple loss and the fifth should be single loss.
TEST_F(PacketLossStatsTest, FirstThreeAndFifthOfEight) {
for (int i = 0; i < 1000; ++i) {
if ((i & 7) < 3 || (i & 7) == 4) {
stats_.AddLostPacket(i);
}
}
EXPECT_EQ(125, stats_.GetSingleLossCount());
EXPECT_EQ(125, stats_.GetMultipleLossEventCount());
EXPECT_EQ(375, stats_.GetMultipleLossPacketCount());
}
// Add loss packets as the first three and the fifth of every eight packets such
// that the sequence numbers wrap in the middle of adding them.
TEST_F(PacketLossStatsTest, FirstThreeAndFifthOfEightWrapped) {
for (int i = 65500; i < 66500; ++i) {
if ((i & 7) < 3 || (i & 7) == 4) {
stats_.AddLostPacket(i & 0xFFFF);
}
}
EXPECT_EQ(125, stats_.GetSingleLossCount());
EXPECT_EQ(125, stats_.GetMultipleLossEventCount());
EXPECT_EQ(375, stats_.GetMultipleLossPacketCount());
}
// Add loss packets as the first three and the fifth of every eight packets such
// that the sequence numbers wrap near the end of adding them and there are
// packets from before the wrapping still in the buffer.
TEST_F(PacketLossStatsTest, FirstThreeAndFifthOfEightWrappedAtEnd) {
for (int i = 64600; i < 65600; ++i) {
if ((i & 7) < 3 || (i & 7) == 4) {
stats_.AddLostPacket(i & 0xFFFF);
}
}
EXPECT_EQ(125, stats_.GetSingleLossCount());
EXPECT_EQ(125, stats_.GetMultipleLossEventCount());
EXPECT_EQ(375, stats_.GetMultipleLossPacketCount());
}
// Add loss packets such that there is a multiple loss event that continues
// around the wrapping of sequence numbers.
TEST_F(PacketLossStatsTest, MultipleLossEventWrapped) {
for (int i = 60000; i < 60500; i += 2) {
stats_.AddLostPacket(i);
}
for (int i = 65530; i < 65540; ++i) {
stats_.AddLostPacket(i & 0xFFFF);
}
EXPECT_EQ(250, stats_.GetSingleLossCount());
EXPECT_EQ(1, stats_.GetMultipleLossEventCount());
EXPECT_EQ(10, stats_.GetMultipleLossPacketCount());
}
// Add loss packets such that there is a multiple loss event that continues
// around the wrapping of sequence numbers and then is pushed out of the buffer.
TEST_F(PacketLossStatsTest, MultipleLossEventWrappedPushedOut) {
for (int i = 60000; i < 60500; i += 2) {
stats_.AddLostPacket(i);
}
for (int i = 65530; i < 65540; ++i) {
stats_.AddLostPacket(i & 0xFFFF);
}
for (int i = 1000; i < 1500; i += 2) {
stats_.AddLostPacket(i);
}
EXPECT_EQ(500, stats_.GetSingleLossCount());
EXPECT_EQ(1, stats_.GetMultipleLossEventCount());
EXPECT_EQ(10, stats_.GetMultipleLossPacketCount());
}
// Add loss packets out of order and ensure that they still get counted
// correctly as single or multiple loss events.
TEST_F(PacketLossStatsTest, OutOfOrder) {
for (int i = 0; i < 1000; i += 10) {
stats_.AddLostPacket(i + 5);
stats_.AddLostPacket(i + 7);
stats_.AddLostPacket(i + 4);
stats_.AddLostPacket(i + 1);
stats_.AddLostPacket(i + 2);
}
EXPECT_EQ(100, stats_.GetSingleLossCount());
EXPECT_EQ(200, stats_.GetMultipleLossEventCount());
EXPECT_EQ(400, stats_.GetMultipleLossPacketCount());
}
// Add loss packets out of order and ensure that they still get counted
// correctly as single or multiple loss events, and wrap in the middle of
// adding.
TEST_F(PacketLossStatsTest, OutOfOrderWrapped) {
for (int i = 65000; i < 66000; i += 10) {
stats_.AddLostPacket((i + 5) & 0xFFFF);
stats_.AddLostPacket((i + 7) & 0xFFFF);
stats_.AddLostPacket((i + 4) & 0xFFFF);
stats_.AddLostPacket((i + 1) & 0xFFFF);
stats_.AddLostPacket((i + 2) & 0xFFFF);
}
EXPECT_EQ(100, stats_.GetSingleLossCount());
EXPECT_EQ(200, stats_.GetMultipleLossEventCount());
EXPECT_EQ(400, stats_.GetMultipleLossPacketCount());
}
} // namespace webrtc
|