File: sack_chunk_test.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (84 lines) | stat: -rw-r--r-- 3,021 bytes parent folder | download | duplicates (32)
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
/*
 *  Copyright (c) 2021 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 "net/dcsctp/packet/chunk/sack_chunk.h"

#include <cstdint>
#include <type_traits>
#include <vector>

#include "api/array_view.h"
#include "net/dcsctp/testing/testing_macros.h"
#include "rtc_base/gunit.h"
#include "test/gmock.h"

namespace dcsctp {
namespace {
using ::testing::ElementsAre;

TEST(SackChunkTest, FromCapture) {
  /*
  SACK chunk (Cumulative TSN: 916312075, a_rwnd: 126323,
    gaps: 2, duplicate TSNs: 1)
      Chunk type: SACK (3)
      Chunk flags: 0x00
      Chunk length: 28
      Cumulative TSN ACK: 916312075
      Advertised receiver window credit (a_rwnd): 126323
      Number of gap acknowledgement blocks: 2
      Number of duplicated TSNs: 1
      Gap Acknowledgement for TSN 916312077 to 916312081
      Gap Acknowledgement for TSN 916312083 to 916312083
      [Number of TSNs in gap acknowledgement blocks: 6]
      Duplicate TSN: 916312081

  */

  uint8_t data[] = {0x03, 0x00, 0x00, 0x1c, 0x36, 0x9d, 0xd0, 0x0b, 0x00, 0x01,
                    0xed, 0x73, 0x00, 0x02, 0x00, 0x01, 0x00, 0x02, 0x00, 0x06,
                    0x00, 0x08, 0x00, 0x08, 0x36, 0x9d, 0xd0, 0x11};

  ASSERT_HAS_VALUE_AND_ASSIGN(SackChunk chunk, SackChunk::Parse(data));

  TSN cum_ack_tsn(916312075);
  EXPECT_EQ(chunk.cumulative_tsn_ack(), cum_ack_tsn);
  EXPECT_EQ(chunk.a_rwnd(), 126323u);
  EXPECT_THAT(
      chunk.gap_ack_blocks(),
      ElementsAre(SackChunk::GapAckBlock(
                      static_cast<uint16_t>(916312077 - *cum_ack_tsn),
                      static_cast<uint16_t>(916312081 - *cum_ack_tsn)),
                  SackChunk::GapAckBlock(
                      static_cast<uint16_t>(916312083 - *cum_ack_tsn),
                      static_cast<uint16_t>(916312083 - *cum_ack_tsn))));
  EXPECT_THAT(chunk.duplicate_tsns(), ElementsAre(TSN(916312081)));
}

TEST(SackChunkTest, SerializeAndDeserialize) {
  SackChunk chunk(TSN(123), /*a_rwnd=*/456, {SackChunk::GapAckBlock(2, 3)},
                  {TSN(1), TSN(2), TSN(3)});
  std::vector<uint8_t> serialized;
  chunk.SerializeTo(serialized);

  ASSERT_HAS_VALUE_AND_ASSIGN(SackChunk deserialized,
                              SackChunk::Parse(serialized));

  EXPECT_EQ(*deserialized.cumulative_tsn_ack(), 123u);
  EXPECT_EQ(deserialized.a_rwnd(), 456u);
  EXPECT_THAT(deserialized.gap_ack_blocks(),
              ElementsAre(SackChunk::GapAckBlock(2, 3)));
  EXPECT_THAT(deserialized.duplicate_tsns(),
              ElementsAre(TSN(1), TSN(2), TSN(3)));

  EXPECT_EQ(deserialized.ToString(),
            "SACK, cum_ack_tsn=123, a_rwnd=456, gap=125--126, dup_tsns=1,2,3");
}

}  // namespace
}  // namespace dcsctp