| Index: net/quic/core/congestion_control/simulation/quic_endpoint.h
|
| diff --git a/net/quic/core/congestion_control/simulation/quic_endpoint.h b/net/quic/core/congestion_control/simulation/quic_endpoint.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a960433b4b833544059b2b718f64404cba265709
|
| --- /dev/null
|
| +++ b/net/quic/core/congestion_control/simulation/quic_endpoint.h
|
| @@ -0,0 +1,154 @@
|
| +#ifndef NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_QUIC_ENDPOINT_H_
|
| +#define NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_QUIC_ENDPOINT_H_
|
| +
|
| +#include "net/quic/core/congestion_control/simulation/link.h"
|
| +#include "net/quic/core/congestion_control/simulation/queue.h"
|
| +#include "net/quic/core/crypto/null_decrypter.h"
|
| +#include "net/quic/core/crypto/null_encrypter.h"
|
| +#include "net/quic/core/quic_connection.h"
|
| +#include "net/quic/core/quic_default_packet_writer.h"
|
| +#include "net/quic/core/quic_protocol.h"
|
| +
|
| +namespace net {
|
| +namespace simulation {
|
| +
|
| +// Size of the TX queue used by the kernel/NIC. 1000 is the Linux
|
| +// kernel default.
|
| +const QuicByteCount kTxQueueSize = 1000;
|
| +
|
| +// Generate a random local network host-port tuple based on the name of the
|
| +// endpoint.
|
| +IPEndPoint GetAddressFromName(std::std::string name);
|
| +
|
| +// A QUIC connection endpoint. Wraps around QuicConnection. In order to
|
| +// initiate a transfer, the caller has to call AddBytesToTransfer(). The data
|
| +// transferred is always the same and is always transferred on a single stream.
|
| +// The endpoint receives all packets addressed to it, and verifies that the data
|
| +// received is what it's supposed to be.
|
| +class QuicEndpoint : public Endpoint,
|
| + public UnconstrainedPortInterface,
|
| + public Queue::ListenerInterface,
|
| + public QuicConnectionVisitorInterface {
|
| + public:
|
| + QuicEndpoint(Simulator* simulator,
|
| + std::std::string name,
|
| + std::std::string peer_name,
|
| + Perspective perspective,
|
| + QuicConnectionId connection_id);
|
| + ~QuicEndpoint() override {}
|
| +
|
| + inline QuicConnection* connection() { return &connection_; }
|
| + inline QuicByteCount bytes_to_transfer() const { return bytes_to_transfer_; }
|
| + inline QuicByteCount bytes_transferred() const { return bytes_transferred_; }
|
| + inline QuicByteCount bytes_received() {
|
| + return connection_.GetStats().stream_bytes_received;
|
| + }
|
| + inline bool wrong_data_received() const { return wrong_data_received_; }
|
| +
|
| + // Send |bytes| bytes. Initiates the transfer if one is not already in
|
| + // progress.
|
| + void AddBytesToTransfer(QuicByteCount bytes);
|
| +
|
| + // UnconstrainedPortInterface method. Called whenever the endpoint receives a
|
| + // packet.
|
| + void AcceptPacket(std::unique_ptr<Packet> packet) override;
|
| +
|
| + // Begin Endpoint implementation.
|
| + UnconstrainedPortInterface* GetRxPort() override;
|
| + void SetTxPort(ConstrainedPortInterface* port) override;
|
| + // End Endpoint implementation.
|
| +
|
| + // Actor method.
|
| + void Act() override {}
|
| +
|
| + // Queue::ListenerInterface method.
|
| + void OnPacketDequeued() override;
|
| +
|
| + // Begin QuicConnectionVisitorInterface implementation.
|
| + void OnStreamFrame(const QuicStreamFrame& frame) override;
|
| + void OnCanWrite() override;
|
| + bool WillingAndAbleToWrite() const override;
|
| + bool HasPendingHandshake() const override;
|
| + bool HasOpenDynamicStreams() const override;
|
| +
|
| + void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override {}
|
| + void OnBlockedFrame(const QuicBlockedFrame& frame) override {}
|
| + void OnRstStream(const QuicRstStreamFrame& frame) override {}
|
| + void OnGoAway(const QuicGoAwayFrame& frame) override {}
|
| + void OnConnectionClosed(QuicErrorCode error,
|
| + const std::string& error_details,
|
| + ConnectionCloseSource source) override {}
|
| + void OnWriteBlocked() override {}
|
| + void OnSuccessfulVersionNegotiation(const QuicVersion& version) override {}
|
| + void OnCongestionWindowChange(QuicTime now) override {}
|
| + void OnConnectionMigration(PeerAddressChangeType type) override {}
|
| + void OnPathDegrading() override {}
|
| + void PostProcessAfterData() override {}
|
| + // End QuicConnectionVisitorInterface implementation.
|
| +
|
| + private:
|
| + // A Writer object that writes into the |nic_tx_queue_|.
|
| + class Writer : public QuicDefaultPacketWriter {
|
| + public:
|
| + explicit Writer(QuicEndpoint* endpoint);
|
| + ~Writer() override;
|
| +
|
| + WriteResult WritePacket(const char* buffer,
|
| + size_t buf_len,
|
| + const IPAddress& self_address,
|
| + const IPEndPoint& peer_address,
|
| + PerPacketOptions* options) override;
|
| +
|
| + private:
|
| + QuicEndpoint* endpoint_;
|
| + };
|
| +
|
| + // Write stream data until |bytes_to_transfer_| is zero or the connection is
|
| + // write-blocked.
|
| + void WriteStreamData();
|
| +
|
| + std::std::string peer_name_;
|
| +
|
| + Writer writer_;
|
| + // The queue for the outgoing packets. In reality, this might be either on
|
| + // the network card, or in the kernel, but for concreteness we assume it's on
|
| + // the network card.
|
| + Queue nic_tx_queue_;
|
| + QuicConnection connection_;
|
| +
|
| + QuicByteCount bytes_to_transfer_;
|
| + QuicByteCount bytes_transferred_;
|
| +
|
| + // Set to true if the endpoint receives stream data different from what it
|
| + // expects.
|
| + bool wrong_data_received_;
|
| +
|
| + std::unique_ptr<char[]> transmission_buffer_;
|
| +};
|
| +
|
| +// Multiplexes multiple connections at the same host on the network.
|
| +class QuicEndpointMultiplexer : public Endpoint,
|
| + public UnconstrainedPortInterface {
|
| + public:
|
| + QuicEndpointMultiplexer(std::std::string name,
|
| + std::initializer_list<QuicEndpoint*> endpoints);
|
| + ~QuicEndpointMultiplexer() override {}
|
| +
|
| + // Receives a packet and passes it to the specified endpoint if that endpoint
|
| + // is one of the endpoints being multiplexed, otherwise ignores the packet.
|
| + void AcceptPacket(std::unique_ptr<Packet> packet) override;
|
| + UnconstrainedPortInterface* GetRxPort() override;
|
| +
|
| + // Sets the egress port for all the endpoints being multiplexed.
|
| + void SetTxPort(ConstrainedPortInterface* port) override;
|
| +
|
| + void Act() override{};
|
| +
|
| + private:
|
| + std::unordered_map<std::std::string, QuicEndpoint*> mapping_;
|
| +};
|
| +
|
| +} // namespace simulation
|
| +} // namespace net
|
| +
|
| +#endif // NET_QUIC_CORE_CONGESTION_CONTROL_SIMULATION_QUIC_ENDPOINT_H_
|
|
|