| OLD | NEW |
| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <map> | 6 #include <map> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 namespace test { | 35 namespace test { |
| 36 | 36 |
| 37 const QuicPacketSequenceNumber kEpoch = GG_UINT64_C(1) << 48; | 37 const QuicPacketSequenceNumber kEpoch = GG_UINT64_C(1) << 48; |
| 38 const QuicPacketSequenceNumber kMask = kEpoch - 1; | 38 const QuicPacketSequenceNumber kMask = kEpoch - 1; |
| 39 | 39 |
| 40 // Index into the guid offset in the header. | 40 // Index into the guid offset in the header. |
| 41 const size_t kGuidOffset = kPublicFlagsSize; | 41 const size_t kGuidOffset = kPublicFlagsSize; |
| 42 // Index into the version string in the header. (if present). | 42 // Index into the version string in the header. (if present). |
| 43 const size_t kVersionOffset = kGuidOffset + PACKET_8BYTE_GUID; | 43 const size_t kVersionOffset = kGuidOffset + PACKET_8BYTE_GUID; |
| 44 | 44 |
| 45 // Size in bytes of the stream frame fields for an arbitrary StreamID and |
| 46 // offset and the last frame in a packet. |
| 47 size_t GetMinStreamFrameSize(QuicVersion version) { |
| 48 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize; |
| 49 } |
| 50 |
| 45 // Index into the sequence number offset in the header. | 51 // Index into the sequence number offset in the header. |
| 46 size_t GetSequenceNumberOffset(QuicGuidLength guid_length, | 52 size_t GetSequenceNumberOffset(QuicGuidLength guid_length, |
| 47 bool include_version) { | 53 bool include_version) { |
| 48 return kGuidOffset + guid_length + | 54 return kGuidOffset + guid_length + |
| 49 (include_version ? kQuicVersionSize : 0); | 55 (include_version ? kQuicVersionSize : 0); |
| 50 } | 56 } |
| 51 | 57 |
| 52 size_t GetSequenceNumberOffset(bool include_version) { | 58 size_t GetSequenceNumberOffset(bool include_version) { |
| 53 return GetSequenceNumberOffset(PACKET_8BYTE_GUID, include_version); | 59 return GetSequenceNumberOffset(PACKET_8BYTE_GUID, include_version); |
| 54 } | 60 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 199 } |
| 194 | 200 |
| 195 virtual ~TestQuicVisitor() { | 201 virtual ~TestQuicVisitor() { |
| 196 STLDeleteElements(&stream_frames_); | 202 STLDeleteElements(&stream_frames_); |
| 197 STLDeleteElements(&ack_frames_); | 203 STLDeleteElements(&ack_frames_); |
| 198 STLDeleteElements(&congestion_feedback_frames_); | 204 STLDeleteElements(&congestion_feedback_frames_); |
| 199 STLDeleteElements(&fec_data_); | 205 STLDeleteElements(&fec_data_); |
| 200 } | 206 } |
| 201 | 207 |
| 202 virtual void OnError(QuicFramer* f) OVERRIDE { | 208 virtual void OnError(QuicFramer* f) OVERRIDE { |
| 203 DLOG(INFO) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error()) | 209 DVLOG(1) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error()) |
| 204 << " (" << f->error() << ")"; | 210 << " (" << f->error() << ")"; |
| 205 error_count_++; | 211 error_count_++; |
| 206 } | 212 } |
| 207 | 213 |
| 208 virtual void OnPacket() OVERRIDE {} | 214 virtual void OnPacket() OVERRIDE {} |
| 209 | 215 |
| 210 virtual void OnPublicResetPacket( | 216 virtual void OnPublicResetPacket( |
| 211 const QuicPublicResetPacket& packet) OVERRIDE { | 217 const QuicPublicResetPacket& packet) OVERRIDE { |
| 212 public_reset_packet_.reset(new QuicPublicResetPacket(packet)); | 218 public_reset_packet_.reset(new QuicPublicResetPacket(packet)); |
| 213 } | 219 } |
| 214 | 220 |
| 215 virtual void OnVersionNegotiationPacket( | 221 virtual void OnVersionNegotiationPacket( |
| 216 const QuicVersionNegotiationPacket& packet) OVERRIDE { | 222 const QuicVersionNegotiationPacket& packet) OVERRIDE { |
| 217 version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(packet)); | 223 version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(packet)); |
| 218 } | 224 } |
| 219 | 225 |
| 220 virtual void OnRevivedPacket() OVERRIDE { | 226 virtual void OnRevivedPacket() OVERRIDE { |
| 221 revived_packets_++; | 227 revived_packets_++; |
| 222 } | 228 } |
| 223 | 229 |
| 224 virtual bool OnProtocolVersionMismatch(QuicVersion version) OVERRIDE { | 230 virtual bool OnProtocolVersionMismatch(QuicVersion version) OVERRIDE { |
| 225 DLOG(INFO) << "QuicFramer Version Mismatch, version: " << version; | 231 DVLOG(1) << "QuicFramer Version Mismatch, version: " << version; |
| 226 version_mismatch_++; | 232 version_mismatch_++; |
| 227 return true; | 233 return true; |
| 228 } | 234 } |
| 229 | 235 |
| 230 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE { | |
| 231 packet_count_++; | |
| 232 header_.reset(new QuicPacketHeader(header)); | |
| 233 return accept_packet_; | |
| 234 } | |
| 235 | |
| 236 virtual bool OnUnauthenticatedPublicHeader( | 236 virtual bool OnUnauthenticatedPublicHeader( |
| 237 const QuicPacketPublicHeader& header) OVERRIDE { | 237 const QuicPacketPublicHeader& header) OVERRIDE { |
| 238 public_header_.reset(new QuicPacketPublicHeader(header)); | 238 public_header_.reset(new QuicPacketPublicHeader(header)); |
| 239 return accept_public_header_; | 239 return accept_public_header_; |
| 240 } | 240 } |
| 241 | 241 |
| 242 virtual bool OnUnauthenticatedHeader( | 242 virtual bool OnUnauthenticatedHeader( |
| 243 const QuicPacketHeader& header) OVERRIDE { | 243 const QuicPacketHeader& header) OVERRIDE { |
| 244 return true; | 244 return true; |
| 245 } | 245 } |
| 246 | 246 |
| 247 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE { |
| 248 packet_count_++; |
| 249 header_.reset(new QuicPacketHeader(header)); |
| 250 return accept_packet_; |
| 251 } |
| 252 |
| 247 virtual bool OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE { | 253 virtual bool OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE { |
| 248 frame_count_++; | 254 frame_count_++; |
| 249 stream_frames_.push_back(new QuicStreamFrame(frame)); | 255 stream_frames_.push_back(new QuicStreamFrame(frame)); |
| 250 return true; | 256 return true; |
| 251 } | 257 } |
| 252 | 258 |
| 253 virtual void OnFecProtectedPayload(StringPiece payload) OVERRIDE { | 259 virtual void OnFecProtectedPayload(StringPiece payload) OVERRIDE { |
| 254 fec_protected_payload_ = payload.as_string(); | 260 fec_protected_payload_ = payload.as_string(); |
| 255 } | 261 } |
| 256 | 262 |
| (...skipping 2038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2295 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); | 2301 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); |
| 2296 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); | 2302 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); |
| 2297 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789), | 2303 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789), |
| 2298 visitor_.public_reset_packet_->nonce_proof); | 2304 visitor_.public_reset_packet_->nonce_proof); |
| 2299 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), | 2305 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), |
| 2300 visitor_.public_reset_packet_->rejected_sequence_number); | 2306 visitor_.public_reset_packet_->rejected_sequence_number); |
| 2301 | 2307 |
| 2302 // Now test framing boundaries | 2308 // Now test framing boundaries |
| 2303 for (size_t i = 0; i < GetPublicResetPacketSize(); ++i) { | 2309 for (size_t i = 0; i < GetPublicResetPacketSize(); ++i) { |
| 2304 string expected_error; | 2310 string expected_error; |
| 2305 DLOG(INFO) << "iteration: " << i; | 2311 DVLOG(1) << "iteration: " << i; |
| 2306 if (i < kGuidOffset) { | 2312 if (i < kGuidOffset) { |
| 2307 expected_error = "Unable to read public flags."; | 2313 expected_error = "Unable to read public flags."; |
| 2308 CheckProcessingFails(packet, i, expected_error, | 2314 CheckProcessingFails(packet, i, expected_error, |
| 2309 QUIC_INVALID_PACKET_HEADER); | 2315 QUIC_INVALID_PACKET_HEADER); |
| 2310 } else if (i < kPublicResetPacketNonceProofOffset) { | 2316 } else if (i < kPublicResetPacketNonceProofOffset) { |
| 2311 expected_error = "Unable to read GUID."; | 2317 expected_error = "Unable to read GUID."; |
| 2312 CheckProcessingFails(packet, i, expected_error, | 2318 CheckProcessingFails(packet, i, expected_error, |
| 2313 QUIC_INVALID_PACKET_HEADER); | 2319 QUIC_INVALID_PACKET_HEADER); |
| 2314 } else if (i < kPublicResetPacketRejectedSequenceNumberOffset) { | 2320 } else if (i < kPublicResetPacketRejectedSequenceNumberOffset) { |
| 2315 expected_error = "Unable to read nonce proof."; | 2321 expected_error = "Unable to read nonce proof."; |
| (...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3274 QuicPacket::NewDataPacket(AsChars(packet), arraysize(packet), false, | 3280 QuicPacket::NewDataPacket(AsChars(packet), arraysize(packet), false, |
| 3275 PACKET_8BYTE_GUID, kIncludeVersion, | 3281 PACKET_8BYTE_GUID, kIncludeVersion, |
| 3276 PACKET_6BYTE_SEQUENCE_NUMBER)); | 3282 PACKET_6BYTE_SEQUENCE_NUMBER)); |
| 3277 scoped_ptr<QuicEncryptedPacket> encrypted( | 3283 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 3278 framer_.EncryptPacket(ENCRYPTION_NONE, sequence_number, *raw)); | 3284 framer_.EncryptPacket(ENCRYPTION_NONE, sequence_number, *raw)); |
| 3279 | 3285 |
| 3280 ASSERT_TRUE(encrypted.get() != NULL); | 3286 ASSERT_TRUE(encrypted.get() != NULL); |
| 3281 EXPECT_TRUE(CheckEncryption(sequence_number, raw.get())); | 3287 EXPECT_TRUE(CheckEncryption(sequence_number, raw.get())); |
| 3282 } | 3288 } |
| 3283 | 3289 |
| 3284 // TODO(rch) enable after landing the revised truncation CL. | 3290 TEST_P(QuicFramerTest, Truncation) { |
| 3285 TEST_P(QuicFramerTest, DISABLED_Truncation) { | |
| 3286 QuicPacketHeader header; | 3291 QuicPacketHeader header; |
| 3287 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 3292 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 3288 header.public_header.reset_flag = false; | 3293 header.public_header.reset_flag = false; |
| 3289 header.public_header.version_flag = false; | 3294 header.public_header.version_flag = false; |
| 3290 header.fec_flag = false; | 3295 header.fec_flag = false; |
| 3291 header.entropy_flag = false; | 3296 header.entropy_flag = false; |
| 3292 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 3297 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 3293 header.fec_group = 0; | 3298 header.fec_group = 0; |
| 3294 | 3299 |
| 3295 QuicAckFrame ack_frame; | 3300 QuicAckFrame ack_frame; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3507 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0); | 3512 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0); |
| 3508 EXPECT_CALL(visitor, OnPacketComplete()); | 3513 EXPECT_CALL(visitor, OnPacketComplete()); |
| 3509 | 3514 |
| 3510 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 3515 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 3511 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 3516 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 3512 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 3517 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 3513 } | 3518 } |
| 3514 | 3519 |
| 3515 } // namespace test | 3520 } // namespace test |
| 3516 } // namespace net | 3521 } // namespace net |
| OLD | NEW |