blob: 859450b1c37e4fd431d3cc5cdd15d93e1479d1c1 [file] [log] [blame]
Victor Boivie5f4ac672021-04-03 19:32:38 +02001/*
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#ifndef NET_DCSCTP_TESTING_DATA_GENERATOR_H_
11#define NET_DCSCTP_TESTING_DATA_GENERATOR_H_
12
13#include <cstdint>
14#include <vector>
15
16#include "absl/strings/string_view.h"
17#include "absl/types/optional.h"
18#include "api/array_view.h"
19#include "net/dcsctp/common/internal_types.h"
20#include "net/dcsctp/packet/data.h"
21
22namespace dcsctp {
23
24struct DataGeneratorOptions {
25 StreamID stream_id = StreamID(1);
26 absl::optional<MID> message_id = absl::nullopt;
27 PPID ppid = PPID(53);
28};
29
30// Generates Data with correct sequence numbers, and used only in unit tests.
31class DataGenerator {
32 public:
33 explicit DataGenerator(MID start_message_id = MID(0))
34 : message_id_(start_message_id) {}
35
36 // Generates ordered "data" with the provided `payload` and flags, which can
37 // contain "B" for setting the "is_beginning" flag, and/or "E" for setting the
38 // "is_end" flag.
39 Data Ordered(std::vector<uint8_t> payload,
40 absl::string_view flags = "",
41 const DataGeneratorOptions opts = {});
42
43 // Generates unordered "data" with the provided `payload` and flags, which can
44 // contain "B" for setting the "is_beginning" flag, and/or "E" for setting the
45 // "is_end" flag.
46 Data Unordered(std::vector<uint8_t> payload,
47 absl::string_view flags = "",
48 const DataGeneratorOptions opts = {});
49
50 // Resets the Message ID identifier - simulating a "stream reset".
51 void ResetStream() { message_id_ = MID(0); }
52
53 private:
54 MID message_id_;
55 FSN fsn_ = FSN(0);
56};
57} // namespace dcsctp
58
59#endif // NET_DCSCTP_TESTING_DATA_GENERATOR_H_