Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: net/quic/core/congestion_control/simulation/quic_endpoint.h

Issue 2322233004: Landing Recent QUIC changes until Sun Sep 4 03:41:00 (Closed)
Patch Set: Remove simulation files from the build. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_QUIC_ENDPOINT_H_
6 #define NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_QUIC_ENDPOINT_H_
7
8 #include "net/quic/core/congestion_control/simulation/link.h"
9 #include "net/quic/core/congestion_control/simulation/queue.h"
10 #include "net/quic/core/crypto/null_decrypter.h"
11 #include "net/quic/core/crypto/null_encrypter.h"
12 #include "net/quic/core/quic_connection.h"
13 #include "net/quic/core/quic_protocol.h"
14 #include "net/tools/quic/quic_default_packet_writer.h"
15
16 namespace net {
17 namespace simulation {
18
19 // Size of the TX queue used by the kernel/NIC. 1000 is the Linux
20 // kernel default.
21 const QuicByteCount kTxQueueSize = 1000;
22
23 // Generate a random local network host-port tuple based on the name of the
24 // endpoint.
25 IPEndPoint GetAddressFromName(std::string name);
26
27 // A QUIC connection endpoint. Wraps around QuicConnection. In order to
28 // initiate a transfer, the caller has to call AddBytesToTransfer(). The data
29 // transferred is always the same and is always transferred on a single stream.
30 // The endpoint receives all packets addressed to it, and verifies that the data
31 // received is what it's supposed to be.
32 class QuicEndpoint : public Endpoint,
33 public UnconstrainedPortInterface,
34 public Queue::ListenerInterface,
35 public QuicConnectionVisitorInterface {
36 public:
37 QuicEndpoint(Simulator* simulator,
38 std::string name,
39 std::string peer_name,
40 Perspective perspective,
41 QuicConnectionId connection_id);
42 ~QuicEndpoint() override;
43
44 inline QuicConnection* connection() { return &connection_; }
45 inline QuicByteCount bytes_to_transfer() const { return bytes_to_transfer_; }
46 inline QuicByteCount bytes_transferred() const { return bytes_transferred_; }
47 inline QuicByteCount bytes_received() {
48 return connection_.GetStats().stream_bytes_received;
49 }
50 inline bool wrong_data_received() const { return wrong_data_received_; }
51
52 // Send |bytes| bytes. Initiates the transfer if one is not already in
53 // progress.
54 void AddBytesToTransfer(QuicByteCount bytes);
55
56 // UnconstrainedPortInterface method. Called whenever the endpoint receives a
57 // packet.
58 void AcceptPacket(std::unique_ptr<Packet> packet) override;
59
60 // Begin Endpoint implementation.
61 UnconstrainedPortInterface* GetRxPort() override;
62 void SetTxPort(ConstrainedPortInterface* port) override;
63 // End Endpoint implementation.
64
65 // Actor method.
66 void Act() override {}
67
68 // Queue::ListenerInterface method.
69 void OnPacketDequeued() override;
70
71 // Begin QuicConnectionVisitorInterface implementation.
72 void OnStreamFrame(const QuicStreamFrame& frame) override;
73 void OnCanWrite() override;
74 bool WillingAndAbleToWrite() const override;
75 bool HasPendingHandshake() const override;
76 bool HasOpenDynamicStreams() const override;
77
78 void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override {}
79 void OnBlockedFrame(const QuicBlockedFrame& frame) override {}
80 void OnRstStream(const QuicRstStreamFrame& frame) override {}
81 void OnGoAway(const QuicGoAwayFrame& frame) override {}
82 void OnConnectionClosed(QuicErrorCode error,
83 const std::string& error_details,
84 ConnectionCloseSource source) override {}
85 void OnWriteBlocked() override {}
86 void OnSuccessfulVersionNegotiation(const QuicVersion& version) override {}
87 void OnCongestionWindowChange(QuicTime now) override {}
88 void OnConnectionMigration(PeerAddressChangeType type) override {}
89 void OnPathDegrading() override {}
90 void PostProcessAfterData() override {}
91 // End QuicConnectionVisitorInterface implementation.
92
93 private:
94 // A Writer object that writes into the |nic_tx_queue_|.
95 class Writer : public QuicDefaultPacketWriter {
96 public:
97 explicit Writer(QuicEndpoint* endpoint);
98 ~Writer() override;
99
100 WriteResult WritePacket(const char* buffer,
101 size_t buf_len,
102 const IPAddress& self_address,
103 const IPEndPoint& peer_address,
104 PerPacketOptions* options) override;
105
106 private:
107 QuicEndpoint* endpoint_;
108 };
109
110 // Write stream data until |bytes_to_transfer_| is zero or the connection is
111 // write-blocked.
112 void WriteStreamData();
113
114 std::string peer_name_;
115
116 Writer writer_;
117 // The queue for the outgoing packets. In reality, this might be either on
118 // the network card, or in the kernel, but for concreteness we assume it's on
119 // the network card.
120 Queue nic_tx_queue_;
121 QuicConnection connection_;
122
123 QuicByteCount bytes_to_transfer_;
124 QuicByteCount bytes_transferred_;
125
126 // Set to true if the endpoint receives stream data different from what it
127 // expects.
128 bool wrong_data_received_;
129
130 std::unique_ptr<char[]> transmission_buffer_;
131 };
132
133 // Multiplexes multiple connections at the same host on the network.
134 class QuicEndpointMultiplexer : public Endpoint,
135 public UnconstrainedPortInterface {
136 public:
137 QuicEndpointMultiplexer(std::string name,
138 std::initializer_list<QuicEndpoint*> endpoints);
139 ~QuicEndpointMultiplexer() override;
140
141 // Receives a packet and passes it to the specified endpoint if that endpoint
142 // is one of the endpoints being multiplexed, otherwise ignores the packet.
143 void AcceptPacket(std::unique_ptr<Packet> packet) override;
144 UnconstrainedPortInterface* GetRxPort() override;
145
146 // Sets the egress port for all the endpoints being multiplexed.
147 void SetTxPort(ConstrainedPortInterface* port) override;
148
149 void Act() override{};
150
151 private:
152 std::unordered_map<std::string, QuicEndpoint*> mapping_;
153 };
154
155 } // namespace simulation
156 } // namespace net
157
158 #endif // NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_QUIC_ENDPOINT_H_
OLDNEW
« no previous file with comments | « net/quic/core/congestion_control/simulation/queue.cc ('k') | net/quic/core/congestion_control/simulation/quic_endpoint.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698