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

Side by Side Diff: content/browser/renderer_host/p2p/socket_host_udp_unittest.cc

Issue 22381012: Allow p2p UDP packages to set DSCP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win fix Created 7 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host_udp.cc ('k') | content/common/p2p_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/p2p/socket_host_udp.h" 5 #include "content/browser/renderer_host/p2p/socket_host_udp.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 virtual int SetMulticastTimeToLive(int time_to_live) OVERRIDE { 143 virtual int SetMulticastTimeToLive(int time_to_live) OVERRIDE {
144 NOTIMPLEMENTED(); 144 NOTIMPLEMENTED();
145 return net::ERR_NOT_IMPLEMENTED; 145 return net::ERR_NOT_IMPLEMENTED;
146 } 146 }
147 147
148 virtual int SetMulticastLoopbackMode(bool loopback) OVERRIDE { 148 virtual int SetMulticastLoopbackMode(bool loopback) OVERRIDE {
149 NOTIMPLEMENTED(); 149 NOTIMPLEMENTED();
150 return net::ERR_NOT_IMPLEMENTED; 150 return net::ERR_NOT_IMPLEMENTED;
151 } 151 }
152 152
153 virtual int SetDiffServCodePoint(net::DiffServCodePoint dscp) OVERRIDE {
154 NOTIMPLEMENTED();
155 return net::ERR_NOT_IMPLEMENTED;
156 }
157
153 private: 158 private:
154 net::IPEndPoint address_; 159 net::IPEndPoint address_;
155 std::deque<UDPPacket>* sent_packets_; 160 std::deque<UDPPacket>* sent_packets_;
156 std::deque<UDPPacket> incoming_packets_; 161 std::deque<UDPPacket> incoming_packets_;
157 net::BoundNetLog net_log_; 162 net::BoundNetLog net_log_;
158 163
159 scoped_refptr<net::IOBuffer> recv_buffer_; 164 scoped_refptr<net::IOBuffer> recv_buffer_;
160 net::IPEndPoint* recv_address_; 165 net::IPEndPoint* recv_address_;
161 int recv_size_; 166 int recv_size_;
162 net::CompletionCallback recv_callback_; 167 net::CompletionCallback recv_callback_;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // Verify that we can send STUN messages before we receive anything 207 // Verify that we can send STUN messages before we receive anything
203 // from the other side. 208 // from the other side.
204 TEST_F(P2PSocketHostUdpTest, SendStunNoAuth) { 209 TEST_F(P2PSocketHostUdpTest, SendStunNoAuth) {
205 EXPECT_CALL(sender_, Send( 210 EXPECT_CALL(sender_, Send(
206 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 211 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
207 .Times(3) 212 .Times(3)
208 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 213 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
209 214
210 std::vector<char> packet1; 215 std::vector<char> packet1;
211 CreateStunRequest(&packet1); 216 CreateStunRequest(&packet1);
212 socket_host_->Send(dest1_, packet1, 0); 217 socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
213 218
214 std::vector<char> packet2; 219 std::vector<char> packet2;
215 CreateStunResponse(&packet2); 220 CreateStunResponse(&packet2);
216 socket_host_->Send(dest1_, packet2, 0); 221 socket_host_->Send(dest1_, packet2, net::DSCP_NO_CHANGE, 0);
217 222
218 std::vector<char> packet3; 223 std::vector<char> packet3;
219 CreateStunError(&packet3); 224 CreateStunError(&packet3);
220 socket_host_->Send(dest1_, packet3, 0); 225 socket_host_->Send(dest1_, packet3, net::DSCP_NO_CHANGE, 0);
221 226
222 ASSERT_EQ(sent_packets_.size(), 3U); 227 ASSERT_EQ(sent_packets_.size(), 3U);
223 ASSERT_EQ(sent_packets_[0].second, packet1); 228 ASSERT_EQ(sent_packets_[0].second, packet1);
224 ASSERT_EQ(sent_packets_[1].second, packet2); 229 ASSERT_EQ(sent_packets_[1].second, packet2);
225 ASSERT_EQ(sent_packets_[2].second, packet3); 230 ASSERT_EQ(sent_packets_[2].second, packet3);
226 } 231 }
227 232
228 // Verify that no data packets can be sent before STUN binding has 233 // Verify that no data packets can be sent before STUN binding has
229 // finished. 234 // finished.
230 TEST_F(P2PSocketHostUdpTest, SendDataNoAuth) { 235 TEST_F(P2PSocketHostUdpTest, SendDataNoAuth) {
231 EXPECT_CALL(sender_, Send( 236 EXPECT_CALL(sender_, Send(
232 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID)))) 237 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID))))
233 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 238 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
234 239
235 std::vector<char> packet; 240 std::vector<char> packet;
236 CreateRandomPacket(&packet); 241 CreateRandomPacket(&packet);
237 socket_host_->Send(dest1_, packet, 0); 242 socket_host_->Send(dest1_, packet, net::DSCP_NO_CHANGE, 0);
238 243
239 ASSERT_EQ(sent_packets_.size(), 0U); 244 ASSERT_EQ(sent_packets_.size(), 0U);
240 } 245 }
241 246
242 // Verify that we can send data after we've received STUN request 247 // Verify that we can send data after we've received STUN request
243 // from the other side. 248 // from the other side.
244 TEST_F(P2PSocketHostUdpTest, SendAfterStunRequest) { 249 TEST_F(P2PSocketHostUdpTest, SendAfterStunRequest) {
245 // Receive packet from |dest1_|. 250 // Receive packet from |dest1_|.
246 std::vector<char> request_packet; 251 std::vector<char> request_packet;
247 CreateStunRequest(&request_packet); 252 CreateStunRequest(&request_packet);
248 253
249 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet))) 254 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet)))
250 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 255 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
251 socket_->ReceivePacket(dest1_, request_packet); 256 socket_->ReceivePacket(dest1_, request_packet);
252 257
253 // Now we should be able to send any data to |dest1_|. 258 // Now we should be able to send any data to |dest1_|.
254 EXPECT_CALL(sender_, Send( 259 EXPECT_CALL(sender_, Send(
255 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 260 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
256 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 261 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
257 std::vector<char> packet; 262 std::vector<char> packet;
258 CreateRandomPacket(&packet); 263 CreateRandomPacket(&packet);
259 socket_host_->Send(dest1_, packet, 0); 264 socket_host_->Send(dest1_, packet, net::DSCP_NO_CHANGE, 0);
260 265
261 ASSERT_EQ(1U, sent_packets_.size()); 266 ASSERT_EQ(1U, sent_packets_.size());
262 ASSERT_EQ(dest1_, sent_packets_[0].first); 267 ASSERT_EQ(dest1_, sent_packets_[0].first);
263 } 268 }
264 269
265 // Verify that we can send data after we've received STUN response 270 // Verify that we can send data after we've received STUN response
266 // from the other side. 271 // from the other side.
267 TEST_F(P2PSocketHostUdpTest, SendAfterStunResponse) { 272 TEST_F(P2PSocketHostUdpTest, SendAfterStunResponse) {
268 // Receive packet from |dest1_|. 273 // Receive packet from |dest1_|.
269 std::vector<char> request_packet; 274 std::vector<char> request_packet;
270 CreateStunRequest(&request_packet); 275 CreateStunRequest(&request_packet);
271 276
272 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet))) 277 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet)))
273 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 278 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
274 socket_->ReceivePacket(dest1_, request_packet); 279 socket_->ReceivePacket(dest1_, request_packet);
275 280
276 // Now we should be able to send any data to |dest1_|. 281 // Now we should be able to send any data to |dest1_|.
277 EXPECT_CALL(sender_, Send( 282 EXPECT_CALL(sender_, Send(
278 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 283 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
279 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 284 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
280 std::vector<char> packet; 285 std::vector<char> packet;
281 CreateRandomPacket(&packet); 286 CreateRandomPacket(&packet);
282 socket_host_->Send(dest1_, packet, 0); 287 socket_host_->Send(dest1_, packet, net::DSCP_NO_CHANGE, 0);
283 288
284 ASSERT_EQ(1U, sent_packets_.size()); 289 ASSERT_EQ(1U, sent_packets_.size());
285 ASSERT_EQ(dest1_, sent_packets_[0].first); 290 ASSERT_EQ(dest1_, sent_packets_[0].first);
286 } 291 }
287 292
288 // Verify messages still cannot be sent to an unathorized host after 293 // Verify messages still cannot be sent to an unathorized host after
289 // successful binding with different host. 294 // successful binding with different host.
290 TEST_F(P2PSocketHostUdpTest, SendAfterStunResponseDifferentHost) { 295 TEST_F(P2PSocketHostUdpTest, SendAfterStunResponseDifferentHost) {
291 // Receive packet from |dest1_|. 296 // Receive packet from |dest1_|.
292 std::vector<char> request_packet; 297 std::vector<char> request_packet;
293 CreateStunRequest(&request_packet); 298 CreateStunRequest(&request_packet);
294 299
295 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet))) 300 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet)))
296 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 301 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
297 socket_->ReceivePacket(dest1_, request_packet); 302 socket_->ReceivePacket(dest1_, request_packet);
298 303
299 // Should fail when trying to send the same packet to |dest2_|. 304 // Should fail when trying to send the same packet to |dest2_|.
300 std::vector<char> packet; 305 std::vector<char> packet;
301 CreateRandomPacket(&packet); 306 CreateRandomPacket(&packet);
302 EXPECT_CALL(sender_, Send( 307 EXPECT_CALL(sender_, Send(
303 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID)))) 308 MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID))))
304 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 309 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
305 socket_host_->Send(dest2_, packet, 0); 310 socket_host_->Send(dest2_, packet, net::DSCP_NO_CHANGE, 0);
306 } 311 }
307 312
308 // Verify throttler not allowing unlimited sending of ICE messages to 313 // Verify throttler not allowing unlimited sending of ICE messages to
309 // any destination. 314 // any destination.
310 TEST_F(P2PSocketHostUdpTest, ThrottleAfterLimit) { 315 TEST_F(P2PSocketHostUdpTest, ThrottleAfterLimit) {
311 EXPECT_CALL(sender_, Send( 316 EXPECT_CALL(sender_, Send(
312 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 317 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
313 .Times(2) 318 .Times(2)
314 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 319 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
315 320
316 std::vector<char> packet1; 321 std::vector<char> packet1;
317 CreateStunRequest(&packet1); 322 CreateStunRequest(&packet1);
318 throttler_.SetSendIceBandwidth(packet1.size() * 2); 323 throttler_.SetSendIceBandwidth(packet1.size() * 2);
319 socket_host_->Send(dest1_, packet1, 0); 324 socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
320 socket_host_->Send(dest2_, packet1, 0); 325 socket_host_->Send(dest2_, packet1, net::DSCP_NO_CHANGE, 0);
321 326
322 net::IPEndPoint dest3 = ParseAddress(kTestIpAddress1, 2222); 327 net::IPEndPoint dest3 = ParseAddress(kTestIpAddress1, 2222);
323 // This packet must be dropped by the throttler. 328 // This packet must be dropped by the throttler.
324 socket_host_->Send(dest3, packet1, 0); 329 socket_host_->Send(dest3, packet1, net::DSCP_NO_CHANGE, 0);
325 ASSERT_EQ(sent_packets_.size(), 2U); 330 ASSERT_EQ(sent_packets_.size(), 2U);
326 } 331 }
327 332
328 // Verify we can send packets to a known destination when ICE throttling is 333 // Verify we can send packets to a known destination when ICE throttling is
329 // active. 334 // active.
330 TEST_F(P2PSocketHostUdpTest, ThrottleAfterLimitAfterReceive) { 335 TEST_F(P2PSocketHostUdpTest, ThrottleAfterLimitAfterReceive) {
331 // Receive packet from |dest1_|. 336 // Receive packet from |dest1_|.
332 std::vector<char> request_packet; 337 std::vector<char> request_packet;
333 CreateStunRequest(&request_packet); 338 CreateStunRequest(&request_packet);
334 339
335 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet))) 340 EXPECT_CALL(sender_, Send(MatchPacketMessage(request_packet)))
336 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 341 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
337 socket_->ReceivePacket(dest1_, request_packet); 342 socket_->ReceivePacket(dest1_, request_packet);
338 343
339 EXPECT_CALL(sender_, Send( 344 EXPECT_CALL(sender_, Send(
340 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID)))) 345 MatchMessage(static_cast<uint32>(P2PMsg_OnSendComplete::ID))))
341 .Times(4) 346 .Times(4)
342 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true))); 347 .WillRepeatedly(DoAll(DeleteArg<0>(), Return(true)));
343 348
344 std::vector<char> packet1; 349 std::vector<char> packet1;
345 CreateStunRequest(&packet1); 350 CreateStunRequest(&packet1);
346 throttler_.SetSendIceBandwidth(packet1.size()); 351 throttler_.SetSendIceBandwidth(packet1.size());
347 // |dest1_| is known address, throttling will not be applied. 352 // |dest1_| is known address, throttling will not be applied.
348 socket_host_->Send(dest1_, packet1, 0); 353 socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
349 // Trying to send the packet to dest1_ in the same window. It should go. 354 // Trying to send the packet to dest1_ in the same window. It should go.
350 socket_host_->Send(dest1_, packet1, 0); 355 socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
351 356
352 // Throttler should allow this packet to go through. 357 // Throttler should allow this packet to go through.
353 socket_host_->Send(dest2_, packet1, 0); 358 socket_host_->Send(dest2_, packet1, net::DSCP_NO_CHANGE, 0);
354 359
355 net::IPEndPoint dest3 = ParseAddress(kTestIpAddress1, 2223); 360 net::IPEndPoint dest3 = ParseAddress(kTestIpAddress1, 2223);
356 // This packet will be dropped, as limit only for a single packet. 361 // This packet will be dropped, as limit only for a single packet.
357 socket_host_->Send(dest3, packet1, 0); 362 socket_host_->Send(dest3, packet1, net::DSCP_NO_CHANGE, 0);
358 net::IPEndPoint dest4 = ParseAddress(kTestIpAddress1, 2224); 363 net::IPEndPoint dest4 = ParseAddress(kTestIpAddress1, 2224);
359 // This packet should also be dropped. 364 // This packet should also be dropped.
360 socket_host_->Send(dest4, packet1, 0); 365 socket_host_->Send(dest4, packet1, net::DSCP_NO_CHANGE, 0);
361 // |dest1| is known, we can send as many packets to it. 366 // |dest1| is known, we can send as many packets to it.
362 socket_host_->Send(dest1_, packet1, 0); 367 socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
363 ASSERT_EQ(sent_packets_.size(), 4U); 368 ASSERT_EQ(sent_packets_.size(), 4U);
364 } 369 }
365 370
366 } // namespace content 371 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host_udp.cc ('k') | content/common/p2p_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698