blob: 45f978edeaae25b119a2ac268e509e55e5ab08e3 [file] [log] [blame]
QUICHE team65f778f2019-04-17 14:28:20 -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#ifndef QUICHE_QUIC_QUARTC_TEST_RANDOM_DELAY_LINK_H_
6#define QUICHE_QUIC_QUARTC_TEST_RANDOM_DELAY_LINK_H_
7
8#include "net/third_party/quiche/src/quic/core/crypto/quic_random.h"
9#include "net/third_party/quiche/src/quic/core/quic_bandwidth.h"
10#include "net/third_party/quiche/src/quic/core/quic_time.h"
11#include "net/third_party/quiche/src/quic/test_tools/simulator/link.h"
12#include "net/third_party/quiche/src/quic/test_tools/simulator/port.h"
13#include "net/third_party/quiche/src/quic/test_tools/simulator/simulator.h"
14
15namespace quic {
16namespace simulator {
17
18// A reliable simplex link between two endpoints with constrained bandwidth. A
19// random delay is added to each packet. The random values are chosen
20// separately for each packet, following an exponential distribution.
21class RandomDelayLink : public OneWayLink {
22 public:
23 RandomDelayLink(Simulator* simulator,
24 std::string name,
25 UnconstrainedPortInterface* sink,
26 QuicBandwidth bandwidth,
27 QuicTime::Delta propagation_delay);
28 RandomDelayLink(const RandomDelayLink&) = delete;
29 RandomDelayLink& operator=(const RandomDelayLink&) = delete;
30 ~RandomDelayLink() override;
31
32 // Sets the median value of the random delay introduced by this link. Random
33 // delays are chosen according to an exponential distribution, clipped and
34 // scaled to reach this as a median value.
35 inline void set_median_random_delay(QuicTime::Delta delta) {
36 median_random_delay_ = delta;
37 }
38
39 protected:
40 QuicTime::Delta GetRandomDelay(QuicTime::Delta transfer_time) override;
41
42 private:
43 QuicTime::Delta median_random_delay_;
44};
45
46// A full-duplex link between two endpoints, functionally equivalent to two
47// RandomDelayLink objects tied together.
48class SymmetricRandomDelayLink {
49 public:
50 SymmetricRandomDelayLink(Simulator* simulator,
51 std::string name,
52 UnconstrainedPortInterface* sink_a,
53 UnconstrainedPortInterface* sink_b,
54 QuicBandwidth bandwidth,
55 QuicTime::Delta propagation_delay);
56 SymmetricRandomDelayLink(Endpoint* endpoint_a,
57 Endpoint* endpoint_b,
58 QuicBandwidth bandwidth,
59 QuicTime::Delta propagation_delay);
60 SymmetricRandomDelayLink(const SymmetricRandomDelayLink&) = delete;
61 SymmetricRandomDelayLink& operator=(const SymmetricRandomDelayLink&) = delete;
62
63 inline QuicBandwidth bandwidth() { return a_to_b_link_.bandwidth(); }
64
65 inline void set_median_random_delay(QuicTime::Delta delay) {
66 a_to_b_link_.set_median_random_delay(delay);
67 b_to_a_link_.set_median_random_delay(delay);
68 }
69
70 private:
71 RandomDelayLink a_to_b_link_;
72 RandomDelayLink b_to_a_link_;
73};
74
75} // namespace simulator
76} // namespace quic
77
78#endif // QUICHE_QUIC_QUARTC_TEST_RANDOM_DELAY_LINK_H_