blob: e4f9f91384c8bed081fa06c212ff5da78c8c3dff [file] [log] [blame]
Victor Boivie5f4ac672021-04-03 17:32:381/*
2 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10#include "net/dcsctp/testing/data_generator.h"
11
12#include <cstdint>
13#include <string>
14#include <utility>
15#include <vector>
16
17#include "absl/strings/string_view.h"
18#include "net/dcsctp/packet/data.h"
19#include "net/dcsctp/public/types.h"
20
21namespace dcsctp {
22constexpr PPID kPpid = PPID(53);
23
24Data DataGenerator::Ordered(std::vector<uint8_t> payload,
25 absl::string_view flags,
26 const DataGeneratorOptions opts) {
27 Data::IsBeginning is_beginning(flags.find('B') != std::string::npos);
28 Data::IsEnd is_end(flags.find('E') != std::string::npos);
29
30 if (is_beginning) {
31 fsn_ = FSN(0);
32 } else {
33 fsn_ = FSN(*fsn_ + 1);
34 }
35 MID message_id = opts.message_id.value_or(message_id_);
36 Data ret = Data(opts.stream_id, SSN(static_cast<uint16_t>(*message_id)),
Victor Boivie4b7024b2021-12-01 18:57:2237 message_id, fsn_, opts.ppid, std::move(payload), is_beginning,
38 is_end, IsUnordered(false));
Victor Boivie5f4ac672021-04-03 17:32:3839
40 if (is_end) {
41 message_id_ = MID(*message_id + 1);
42 }
43 return ret;
44}
45
46Data DataGenerator::Unordered(std::vector<uint8_t> payload,
47 absl::string_view flags,
48 const DataGeneratorOptions opts) {
49 Data::IsBeginning is_beginning(flags.find('B') != std::string::npos);
50 Data::IsEnd is_end(flags.find('E') != std::string::npos);
51
52 if (is_beginning) {
53 fsn_ = FSN(0);
54 } else {
55 fsn_ = FSN(*fsn_ + 1);
56 }
57 MID message_id = opts.message_id.value_or(message_id_);
58 Data ret = Data(opts.stream_id, SSN(0), message_id, fsn_, kPpid,
Victor Boivie4b7024b2021-12-01 18:57:2259 std::move(payload), is_beginning, is_end, IsUnordered(true));
Victor Boivie5f4ac672021-04-03 17:32:3860 if (is_end) {
61 message_id_ = MID(*message_id + 1);
62 }
63 return ret;
64}
65} // namespace dcsctp