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

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

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

Powered by Google App Engine
This is Rietveld 408576698