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

Side by Side Diff: net/quic/quic_connection_test.cc

Issue 648933003: Land Recent QUIC Changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with TOT Created 6 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
« no previous file with comments | « net/quic/quic_connection_logger.cc ('k') | net/quic/quic_crypto_client_stream_test.cc » ('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 "net/quic/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 2398 matching lines...) Expand 10 before | Expand all | Expand 10 after
2409 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2409 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2410 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2410 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2411 2411
2412 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr); 2412 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr);
2413 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2413 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2414 2414
2415 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); 2415 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION);
2416 } 2416 }
2417 2417
2418 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { 2418 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) {
2419 // SetFromConfig is always called after construction from InitializeSession.
2420 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
2421 QuicConfig config;
2422 connection_.SetFromConfig(config);
2419 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2423 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2420 use_tagging_decrypter(); 2424 use_tagging_decrypter();
2421 2425
2422 const uint8 tag = 0x07; 2426 const uint8 tag = 0x07;
2423 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2427 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2424 2428
2425 // Process an encrypted packet which can not yet be decrypted 2429 // Process an encrypted packet which can not yet be decrypted which should
2426 // which should result in the packet being buffered. 2430 // result in the packet being buffered.
2427 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2431 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2428 2432
2429 // Transition to the new encryption state and process another 2433 // Transition to the new encryption state and process another encrypted packet
2430 // encrypted packet which should result in the original packet being 2434 // which should result in the original packet being processed.
2431 // processed.
2432 connection_.SetDecrypter(new StrictTaggingDecrypter(tag), 2435 connection_.SetDecrypter(new StrictTaggingDecrypter(tag),
2433 ENCRYPTION_INITIAL); 2436 ENCRYPTION_INITIAL);
2434 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2437 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2435 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2438 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2436 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2); 2439 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2);
2437 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2440 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2438 2441
2439 // Finally, process a third packet and note that we do not 2442 // Finally, process a third packet and note that we do not reprocess the
2440 // reprocess the buffered packet. 2443 // buffered packet.
2441 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 2444 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
2442 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2445 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2443 } 2446 }
2444 2447
2448 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) {
2449 // SetFromConfig is always called after construction from InitializeSession.
2450 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
2451 QuicConfig config;
2452 config.set_max_undecryptable_packets(100);
2453 connection_.SetFromConfig(config);
2454 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2455 use_tagging_decrypter();
2456
2457 const uint8 tag = 0x07;
2458 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2459
2460 // Process an encrypted packet which can not yet be decrypted which should
2461 // result in the packet being buffered.
2462 for (QuicPacketSequenceNumber i = 1; i <= 100; ++i) {
2463 ProcessDataPacketAtLevel(i, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2464 }
2465
2466 // Transition to the new encryption state and process another encrypted packet
2467 // which should result in the original packets being processed.
2468 connection_.SetDecrypter(new StrictTaggingDecrypter(tag), ENCRYPTION_INITIAL);
2469 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2470 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2471 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(101);
2472 ProcessDataPacketAtLevel(101, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2473
2474 // Finally, process a third packet and note that we do not reprocess the
2475 // buffered packet.
2476 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
2477 ProcessDataPacketAtLevel(102, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2478 }
2479
2445 TEST_P(QuicConnectionTest, TestRetransmitOrder) { 2480 TEST_P(QuicConnectionTest, TestRetransmitOrder) {
2446 QuicByteCount first_packet_size; 2481 QuicByteCount first_packet_size;
2447 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( 2482 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce(
2448 DoAll(SaveArg<3>(&first_packet_size), Return(true))); 2483 DoAll(SaveArg<3>(&first_packet_size), Return(true)));
2449 2484
2450 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); 2485 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr);
2451 QuicByteCount second_packet_size; 2486 QuicByteCount second_packet_size;
2452 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( 2487 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce(
2453 DoAll(SaveArg<3>(&second_packet_size), Return(true))); 2488 DoAll(SaveArg<3>(&second_packet_size), Return(true)));
2454 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, nullptr); 2489 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, nullptr);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2675 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 2710 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2676 return; 2711 return;
2677 } 2712 }
2678 EXPECT_TRUE(connection_.connected()); 2713 EXPECT_TRUE(connection_.connected());
2679 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); 2714 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
2680 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2715 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2681 2716
2682 // SetFromConfig sets the initial timeouts before negotiation. 2717 // SetFromConfig sets the initial timeouts before negotiation.
2683 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 2718 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
2684 QuicConfig config; 2719 QuicConfig config;
2685 config.SetDefaults();
2686 connection_.SetFromConfig(config); 2720 connection_.SetFromConfig(config);
2687 // Subtract a second from the idle timeout on the client side. 2721 // Subtract a second from the idle timeout on the client side.
2688 QuicTime default_timeout = clock_.ApproximateNow().Add( 2722 QuicTime default_timeout = clock_.ApproximateNow().Add(
2689 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); 2723 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1));
2690 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 2724 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
2691 2725
2692 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); 2726 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false));
2693 // Simulate the timeout alarm firing. 2727 // Simulate the timeout alarm firing.
2694 clock_.AdvanceTime( 2728 clock_.AdvanceTime(
2695 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); 2729 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1));
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2828 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), 2862 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)),
2829 clock_.ApproximateNow()); 2863 clock_.ApproximateNow());
2830 connection_.GetTimeoutAlarm()->Fire(); 2864 connection_.GetTimeoutAlarm()->Fire();
2831 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2865 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2832 EXPECT_FALSE(connection_.connected()); 2866 EXPECT_FALSE(connection_.connected());
2833 return; 2867 return;
2834 } 2868 }
2835 EXPECT_TRUE(connection_.connected()); 2869 EXPECT_TRUE(connection_.connected());
2836 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 2870 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
2837 QuicConfig config; 2871 QuicConfig config;
2838 config.SetDefaults();
2839 connection_.SetFromConfig(config); 2872 connection_.SetFromConfig(config);
2840 2873
2841 const QuicTime::Delta initial_idle_timeout = 2874 const QuicTime::Delta initial_idle_timeout =
2842 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); 2875 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
2843 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 2876 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
2844 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout); 2877 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout);
2845 2878
2846 // When we send a packet, the timeout will change to 5ms + 2879 // When we send a packet, the timeout will change to 5ms +
2847 // kInitialIdleTimeoutSecs. 2880 // kInitialIdleTimeoutSecs.
2848 clock_.AdvanceTime(five_ms); 2881 clock_.AdvanceTime(five_ms);
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
3917 EXPECT_LT(max_packets_per_fec_group, creator->max_packets_per_fec_group()); 3950 EXPECT_LT(max_packets_per_fec_group, creator->max_packets_per_fec_group());
3918 } 3951 }
3919 3952
3920 class MockQuicConnectionDebugVisitor 3953 class MockQuicConnectionDebugVisitor
3921 : public QuicConnectionDebugVisitor { 3954 : public QuicConnectionDebugVisitor {
3922 public: 3955 public:
3923 MOCK_METHOD1(OnFrameAddedToPacket, 3956 MOCK_METHOD1(OnFrameAddedToPacket,
3924 void(const QuicFrame&)); 3957 void(const QuicFrame&));
3925 3958
3926 MOCK_METHOD6(OnPacketSent, 3959 MOCK_METHOD6(OnPacketSent,
3927 void(QuicPacketSequenceNumber, 3960 void(const SerializedPacket&,
3928 QuicPacketSequenceNumber, 3961 QuicPacketSequenceNumber,
3929 EncryptionLevel, 3962 EncryptionLevel,
3930 TransmissionType, 3963 TransmissionType,
3931 const QuicEncryptedPacket&, 3964 const QuicEncryptedPacket&,
3932 WriteResult)); 3965 QuicTime));
3933 3966
3934 MOCK_METHOD3(OnPacketReceived, 3967 MOCK_METHOD3(OnPacketReceived,
3935 void(const IPEndPoint&, 3968 void(const IPEndPoint&,
3936 const IPEndPoint&, 3969 const IPEndPoint&,
3937 const QuicEncryptedPacket&)); 3970 const QuicEncryptedPacket&));
3938 3971
3939 MOCK_METHOD1(OnProtocolVersionMismatch, 3972 MOCK_METHOD1(OnProtocolVersionMismatch,
3940 void(QuicVersion)); 3973 void(QuicVersion));
3941 3974
3942 MOCK_METHOD1(OnPacketHeader, 3975 MOCK_METHOD1(OnPacketHeader,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
4008 QuicBlockedFrame blocked; 4041 QuicBlockedFrame blocked;
4009 blocked.stream_id = 3; 4042 blocked.stream_id = 3;
4010 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 4043 EXPECT_CALL(visitor_, OnBlockedFrames(_));
4011 ProcessFramePacket(QuicFrame(&blocked)); 4044 ProcessFramePacket(QuicFrame(&blocked));
4012 EXPECT_TRUE(ack_alarm->IsSet()); 4045 EXPECT_TRUE(ack_alarm->IsSet());
4013 } 4046 }
4014 4047
4015 } // namespace 4048 } // namespace
4016 } // namespace test 4049 } // namespace test
4017 } // namespace net 4050 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection_logger.cc ('k') | net/quic/quic_crypto_client_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698