OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_LINK_H_ |
| 6 #define NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_LINK_H_ |
| 7 |
| 8 #include <queue> |
| 9 #include <utility> |
| 10 |
| 11 #include "net/quic/core/congestion_control/simulation/actor.h" |
| 12 #include "net/quic/core/congestion_control/simulation/port.h" |
| 13 #include "net/quic/core/crypto/quic_random.h" |
| 14 |
| 15 namespace net { |
| 16 namespace simulation { |
| 17 |
| 18 // A reliable simplex link between two endpoints with constrained bandwidth. A |
| 19 // few microseconds of random delay are added for every packet to avoid |
| 20 // synchronization issues. |
| 21 class OneWayLink : public Actor, public ConstrainedPortInterface { |
| 22 public: |
| 23 OneWayLink(Simulator* simulator, |
| 24 std::string name, |
| 25 UnconstrainedPortInterface* sink, |
| 26 QuicBandwidth bandwidth, |
| 27 QuicTime::Delta propagation_delay); |
| 28 ~OneWayLink() override; |
| 29 |
| 30 void AcceptPacket(std::unique_ptr<Packet> packet) override; |
| 31 QuicTime::Delta TimeUntilAvailable() override; |
| 32 void Act() override; |
| 33 |
| 34 inline QuicBandwidth bandwidth() const { return bandwidth_; } |
| 35 inline QuicTime::Delta propagation_delay() const { |
| 36 return propagation_delay_; |
| 37 } |
| 38 |
| 39 private: |
| 40 struct QueuedPacket { |
| 41 std::unique_ptr<Packet> packet; |
| 42 QuicTime dequeue_time; |
| 43 |
| 44 QueuedPacket(std::unique_ptr<Packet> packet, QuicTime dequeue_time); |
| 45 ~QueuedPacket(); |
| 46 }; |
| 47 |
| 48 // Schedule the next packet to be egressed out of the link if there are |
| 49 // packets on the link. |
| 50 void ScheduleNextPacketDeparture(); |
| 51 |
| 52 // Get the value of a random delay imposed on each packet in order to avoid |
| 53 // artifical synchronization artifacts during the simulation. |
| 54 QuicTime::Delta GetRandomDelay(QuicTime::Delta transfer_time); |
| 55 |
| 56 UnconstrainedPortInterface* sink_; |
| 57 std::queue<QueuedPacket> packets_in_transit_; |
| 58 |
| 59 const QuicBandwidth bandwidth_; |
| 60 const QuicTime::Delta propagation_delay_; |
| 61 |
| 62 QuicTime next_write_at_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(OneWayLink); |
| 65 }; |
| 66 |
| 67 // A full-duplex link between two endpoints, functionally equivalent to two |
| 68 // OneWayLink objects tied together. |
| 69 class SymmetricLink { |
| 70 public: |
| 71 SymmetricLink(Simulator* simulator, |
| 72 std::string name, |
| 73 UnconstrainedPortInterface* sink_a, |
| 74 UnconstrainedPortInterface* sink_b, |
| 75 QuicBandwidth bandwidth, |
| 76 QuicTime::Delta propagation_delay); |
| 77 SymmetricLink(Endpoint* endpoint_a, |
| 78 Endpoint* endpoint_b, |
| 79 QuicBandwidth bandwidth, |
| 80 QuicTime::Delta propagation_delay); |
| 81 |
| 82 inline ConstrainedPortInterface* GetTxPortForA() { return &a_to_b_link_; } |
| 83 inline ConstrainedPortInterface* GetTxPortForB() { return &b_to_a_link_; } |
| 84 |
| 85 inline QuicBandwidth bandwidth() { return a_to_b_link_.bandwidth(); } |
| 86 inline QuicTime::Delta propagation_delay() { |
| 87 return a_to_b_link_.propagation_delay(); |
| 88 } |
| 89 |
| 90 private: |
| 91 OneWayLink a_to_b_link_; |
| 92 OneWayLink b_to_a_link_; |
| 93 |
| 94 DISALLOW_COPY_AND_ASSIGN(SymmetricLink); |
| 95 }; |
| 96 |
| 97 } // namespace simulation |
| 98 } // namespace net |
| 99 |
| 100 #endif // NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_LINK_H_ |
OLD | NEW |