blob: 53a2c3f9c01ef8de0decd70c3cbeb8725a7722e7 [file] [log] [blame]
wubf975eac2019-08-19 19:41:01 -07001// Copyright (c) 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "net/third_party/quiche/src/quic/qbone/platform/tcp_packet.h"
6
7#include <netinet/ip6.h>
8
9#include <cstdint>
10
11#include "net/third_party/quiche/src/quic/platform/api/quic_test.h"
12#include "net/third_party/quiche/src/quic/platform/api/quic_text_utils.h"
13
14namespace quic {
15namespace {
16
17// clang-format off
18constexpr uint8_t kReferenceTCPSYNPacket[] = {
19 // START IPv6 Header
20 // IPv6 with zero ToS and flow label
21 0x60, 0x00, 0x00, 0x00,
22 // Payload is 40 bytes
23 0x00, 0x28,
24 // Next header is TCP (6)
25 0x06,
26 // Hop limit is 64
27 0x40,
28 // Source address of ::1
29 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
31 // Destination address of ::1
32 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
34 // END IPv6 Header
35 // START TCPv6 Header
36 // Source port
37 0xac, 0x1e,
38 // Destination port
39 0x27, 0x0f,
40 // Sequence number
41 0x4b, 0x01, 0xe8, 0x99,
42 // Acknowledgement Sequence number,
43 0x00, 0x00, 0x00, 0x00,
44 // Offset
45 0xa0,
46 // Flags
47 0x02,
48 // Window
49 0xaa, 0xaa,
50 // Checksum
51 0x2e, 0x21,
52 // Urgent
53 0x00, 0x00,
54 // END TCPv6 Header
55 // Options
56 0x02, 0x04, 0xff, 0xc4, 0x04, 0x02, 0x08, 0x0a,
57 0x1b, 0xb8, 0x52, 0xa1, 0x00, 0x00, 0x00, 0x00,
58 0x01, 0x03, 0x03, 0x07,
59};
60
61constexpr uint8_t kReferenceTCPRSTPacket[] = {
62 // START IPv6 Header
63 // IPv6 with zero ToS and flow label
64 0x60, 0x00, 0x00, 0x00,
65 // Payload is 20 bytes
66 0x00, 0x14,
67 // Next header is TCP (6)
68 0x06,
69 // Hop limit is 64
70 0x40,
71 // Source address of ::1
72 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
74 // Destination address of ::1
75 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
76 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
77 // END IPv6 Header
78 // START TCPv6 Header
79 // Source port
80 0x27, 0x0f,
81 // Destination port
82 0xac, 0x1e,
83 // Sequence number
84 0x00, 0x00, 0x00, 0x00,
85 // Acknowledgement Sequence number,
86 0x4b, 0x01, 0xe8, 0x9a,
87 // Offset
88 0x50,
89 // Flags
90 0x14,
91 // Window
92 0x00, 0x00,
93 // Checksum
94 0xa9, 0x05,
95 // Urgent
96 0x00, 0x00,
97 // END TCPv6 Header
98};
99// clang-format on
100
101} // namespace
102
103TEST(TcpPacketTest, CreatedPacketMatchesReference) {
104 QuicStringPiece syn =
105 QuicStringPiece(reinterpret_cast<const char*>(kReferenceTCPSYNPacket),
106 sizeof(kReferenceTCPSYNPacket));
107 QuicStringPiece expected_packet =
108 QuicStringPiece(reinterpret_cast<const char*>(kReferenceTCPRSTPacket),
109 sizeof(kReferenceTCPRSTPacket));
110 CreateTcpResetPacket(syn, [&expected_packet](QuicStringPiece packet) {
111 QUIC_LOG(INFO) << QuicTextUtils::HexDump(packet);
112 ASSERT_EQ(packet, expected_packet);
113 });
114}
115
116} // namespace quic